mirror of
https://github.com/GTNewHorizons/Binnie.git
synced 2026-11-26 23:12:58 +00:00
Localization and refactoring (#77)
* Some refactoring for bee production * Code cleanup * Code cleanup * Added some localization * Fix wrong dropped class * Added some localization * Added some localization * Added some localization * Fix wrong import
This commit is contained in:
1 parent
68bbe7710c
commit
1ea7b62e5f
157 files changed
+3240
-5045
No files matched your search
@@ -0,0 +1,24 @@
|
||||
package binnie.genetics.machine.splicer;
|
||||
|
||||
import binnie.Binnie;
|
||||
import binnie.core.machines.inventory.SlotValidator;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.ISpeciesRoot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class IndividualInoculateValidator extends SlotValidator {
|
||||
public IndividualInoculateValidator() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(ItemStack object) {
|
||||
ISpeciesRoot root = AlleleManager.alleleRegistry.getSpeciesRoot(object);
|
||||
return root != null && Binnie.Genetics.getSystem(root).isDNAManipulable(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
return "Splicable Individual";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package binnie.genetics.machine.splicer;
|
||||
|
||||
import binnie.core.machines.inventory.SlotValidator;
|
||||
import binnie.genetics.api.IItemSerum;
|
||||
import binnie.genetics.machine.ModuleMachine;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
class SerumSlotValidator extends SlotValidator {
|
||||
public SerumSlotValidator() {
|
||||
super(ModuleMachine.IconSerum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(ItemStack itemStack) {
|
||||
return itemStack.getItem() instanceof IItemSerum;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
return "Serum Vials & Arrays";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package binnie.genetics.machine.splicer;
|
||||
|
||||
import binnie.genetics.api.IGene;
|
||||
import forestry.api.apiculture.EnumBeeChromosome;
|
||||
import forestry.api.apiculture.IBeeRoot;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
public class Splicer {
|
||||
public static final int SLOT_SERUM_VIAL = 0;
|
||||
public static final int[] SLOT_SERUM_RESERVE = new int[]{1, 2};
|
||||
public static final int[] SLOT_SERUM_EXPENDED = new int[]{3, 4};
|
||||
public static final int[] SLOT_RESERVE = new int[]{5, 6, 7, 8, 9};
|
||||
public static final int SLOT_TARGET = 9;
|
||||
public static final int[] SLOT_FINISHED = new int[]{10, 11, 12, 13};
|
||||
|
||||
public static void setGene(IGene gene, ItemStack target, int chromoN) {
|
||||
int chromosomeID = gene.getChromosome().ordinal();
|
||||
if (chromosomeID >= EnumBeeChromosome.HUMIDITY.ordinal() && gene.getSpeciesRoot() instanceof IBeeRoot) {
|
||||
chromosomeID--;
|
||||
}
|
||||
|
||||
Class<? extends IAllele> cls = gene.getChromosome().getAlleleClass();
|
||||
if (!cls.isInstance(gene.getAllele())) {
|
||||
return;
|
||||
}
|
||||
|
||||
NBTTagCompound beeNBT = target.getTagCompound();
|
||||
NBTTagCompound genomeNBT = beeNBT.getCompoundTag("Genome");
|
||||
NBTTagList chromosomes = genomeNBT.getTagList("Chromosomes", 10);
|
||||
NBTTagCompound chromosomeNBT = chromosomes.getCompoundTagAt(chromosomeID);
|
||||
chromosomeNBT.setString("UID" + chromoN, gene.getAllele().getUID());
|
||||
target.setTagCompound(beeNBT);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package binnie.genetics.machine.splicer;
|
||||
|
||||
import binnie.core.BinnieCore;
|
||||
import binnie.core.machines.IMachine;
|
||||
import binnie.core.machines.MachineComponent;
|
||||
import binnie.core.machines.component.IRender;
|
||||
import binnie.core.machines.network.INetwork;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.particle.EntityFX;
|
||||
import net.minecraft.client.renderer.entity.RenderItem;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class SplicerComponentFX extends MachineComponent implements
|
||||
IRender.RandomDisplayTick,
|
||||
IRender.DisplayTick,
|
||||
IRender.Render,
|
||||
INetwork.TilePacketSync {
|
||||
private EntityItem dummyEntityItem;
|
||||
|
||||
public SplicerComponentFX(IMachine machine) {
|
||||
super(machine);
|
||||
dummyEntityItem = new EntityItem(null);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void onRandomDisplayTick(World world, int x, int y, int z, Random rand) {
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void onDisplayTick(World world, int x, int y, int z, Random rand) {
|
||||
int tick = (int) (world.getTotalWorldTime() % 3L);
|
||||
if (tick != 0 || !getUtil().getProcess().isInProgress()) {
|
||||
return;
|
||||
}
|
||||
|
||||
BinnieCore.proxy.getMinecraftInstance().effectRenderer.addEffect(new EntityFX(world, x + 0.5, y + 1.5, z + 0.5, 0.0, 0.0, 0.0) {
|
||||
double axisX = posX;
|
||||
double axisZ = posZ;
|
||||
double angle = (int) (worldObj.getTotalWorldTime() % 4L) * 0.5 * 3.1415;
|
||||
|
||||
{
|
||||
axisX = 0.0;
|
||||
axisZ = 0.0;
|
||||
angle = 0.0;
|
||||
motionX = 0.0;
|
||||
motionZ = 0.0;
|
||||
motionY = (rand.nextDouble() - 0.5) * 0.02;
|
||||
particleMaxAge = 240;
|
||||
particleGravity = 0.0f;
|
||||
noClip = true;
|
||||
setRBGColorF(0.3f + rand.nextFloat() * 0.5f, 0.3f + rand.nextFloat() * 0.5f, 0.0f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate() {
|
||||
super.onUpdate();
|
||||
double speed = 0.04;
|
||||
angle -= speed;
|
||||
double dist = 0.25 + 0.2 * Math.sin(particleAge / 50.0f);
|
||||
setPosition(axisX + dist * Math.sin(angle), posY, axisZ + dist * Math.cos(angle));
|
||||
setAlphaF((float) Math.cos(1.57 * particleAge / particleMaxAge));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFXLayer() {
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void renderInWorld(RenderItem renderItem, double x, double y, double z) {
|
||||
if (!getUtil().getProcess().isInProgress()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack stack = getUtil().getStack(Splicer.SLOT_TARGET);
|
||||
dummyEntityItem.worldObj = getMachine().getWorld();
|
||||
dummyEntityItem.setEntityItemStack(stack);
|
||||
EntityItem dummyEntityItem = this.dummyEntityItem;
|
||||
dummyEntityItem.age++;
|
||||
this.dummyEntityItem.hoverStart = 0.0f;
|
||||
if (stack == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glRotatef(180.0f, 0.0f, 0.0f, 1.0f);
|
||||
GL11.glTranslatef(0.0f, -0.25f, 0.0f);
|
||||
renderItem.doRender(this.dummyEntityItem, 0.0, 0.0, 0.0, 0.0f, 0.0f);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void syncToNBT(NBTTagCompound nbt) {
|
||||
NBTTagCompound item = new NBTTagCompound();
|
||||
ItemStack stack = getUtil().getStack(Splicer.SLOT_TARGET);
|
||||
if (stack != null) {
|
||||
stack.writeToNBT(item);
|
||||
nbt.setTag("item", item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void syncFromNBT(NBTTagCompound nbt) {
|
||||
if (nbt.hasKey("item")) {
|
||||
getUtil().setStack(Splicer.SLOT_TARGET, ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("item")));
|
||||
} else {
|
||||
getUtil().setStack(Splicer.SLOT_TARGET, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInventoryUpdate() {
|
||||
if (!getUtil().isServer()) {
|
||||
return;
|
||||
}
|
||||
getUtil().refreshBlock();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
package binnie.genetics.machine.splicer;
|
||||
|
||||
import binnie.core.machines.Machine;
|
||||
import binnie.core.machines.power.ComponentProcessSetCost;
|
||||
import binnie.core.machines.power.ErrorState;
|
||||
import binnie.core.machines.power.IProcess;
|
||||
import binnie.genetics.api.IGene;
|
||||
import binnie.genetics.api.IItemSerum;
|
||||
import binnie.genetics.genetics.Engineering;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IChromosomeType;
|
||||
import forestry.api.genetics.IGenome;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class SplicerComponentLogic extends ComponentProcessSetCost implements IProcess {
|
||||
public int nOfGenes;
|
||||
|
||||
public SplicerComponentLogic(Machine machine) {
|
||||
super(machine, 12000000, 1200);
|
||||
nOfGenes = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProcessLength() {
|
||||
float n = getNumberOfGenes();
|
||||
if (n > 1.0f) {
|
||||
n = 1.0f + (n - 1.0f) * 0.5f;
|
||||
}
|
||||
// Fix for / by 0
|
||||
int temp = (int) (super.getProcessLength() * n);
|
||||
return temp != 0 ? temp : 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProcessEnergy() {
|
||||
float n = getNumberOfGenes();
|
||||
if (n > 1.0f) {
|
||||
n = 1.0f + (n - 1.0f) * 0.5f;
|
||||
}
|
||||
return (int) (super.getProcessEnergy() * n);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInventoryUpdate() {
|
||||
super.onInventoryUpdate();
|
||||
nOfGenes = getGenesToUse();
|
||||
}
|
||||
|
||||
protected int getGenesToUse() {
|
||||
ItemStack serum = getUtil().getStack(Splicer.SLOT_SERUM_VIAL);
|
||||
ItemStack target = getUtil().getStack(Splicer.SLOT_TARGET);
|
||||
if (serum == null || target == null) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
IIndividual ind = AlleleManager.alleleRegistry.getIndividual(target);
|
||||
IGene[] genes = ((IItemSerum) serum.getItem()).getGenes(serum);
|
||||
if (ind.getGenome().getSpeciesRoot() != ((IItemSerum) serum.getItem()).getSpeciesRoot(serum)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for (IGene gene : genes) {
|
||||
if (ind.getGenome().getActiveAllele(gene.getChromosome()) != gene.getAllele() || ind.getGenome().getInactiveAllele(gene.getChromosome()) != gene.getAllele()) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return (i < 1) ? 1 : i;
|
||||
}
|
||||
|
||||
private int getFullNumberOfGenes() {
|
||||
ItemStack serum = getUtil().getStack(Splicer.SLOT_SERUM_VIAL);
|
||||
if (serum == null) {
|
||||
return 1;
|
||||
}
|
||||
return Engineering.getGenes(serum).length;
|
||||
}
|
||||
|
||||
private int getNumberOfGenes() {
|
||||
return nOfGenes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
int n = getNumberOfGenes();
|
||||
int f = getFullNumberOfGenes();
|
||||
return "Splicing in " + n + ((f > 1) ? ("/" + f) : "") + " gene" + ((n > 1) ? "s" : "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorState canWork() {
|
||||
if (getUtil().isSlotEmpty(Splicer.SLOT_TARGET)) {
|
||||
return new ErrorState.NoItem("No Individual to Splice", Splicer.SLOT_TARGET);
|
||||
}
|
||||
if (getUtil().isSlotEmpty(Splicer.SLOT_SERUM_VIAL)) {
|
||||
return new ErrorState.NoItem("No Serum", Splicer.SLOT_SERUM_VIAL);
|
||||
}
|
||||
|
||||
ErrorState state = isValidSerum();
|
||||
if (state != null) {
|
||||
return state;
|
||||
}
|
||||
|
||||
if (getUtil().getStack(0) != null && Engineering.getCharges(getUtil().getStack(Splicer.SLOT_SERUM_VIAL)) == 0) {
|
||||
return new ErrorState("Empty Serum", "Serum is empty");
|
||||
}
|
||||
return super.canWork();
|
||||
}
|
||||
|
||||
public ErrorState isValidSerum() {
|
||||
ItemStack serum = getUtil().getStack(Splicer.SLOT_SERUM_VIAL);
|
||||
ItemStack target = getUtil().getStack(Splicer.SLOT_TARGET);
|
||||
IGene[] genes = Engineering.getGenes(serum);
|
||||
if (genes.length == 0) {
|
||||
return new ErrorState("Invalid Serum", "Serum does not hold any genes");
|
||||
}
|
||||
if (!genes[0].getSpeciesRoot().isMember(target)) {
|
||||
return new ErrorState("Invalid Serum", "Mismatch of Serum Type and Target");
|
||||
}
|
||||
|
||||
IIndividual individual = genes[0].getSpeciesRoot().getMember(target);
|
||||
boolean hasAll = true;
|
||||
for (IGene gene : genes) {
|
||||
if (hasAll) {
|
||||
IGenome genome = individual.getGenome();
|
||||
IChromosomeType chromosome = gene.getChromosome();
|
||||
String geneAlleleUID = gene.getAllele().getUID();
|
||||
IAllele a = genome.getActiveAllele(chromosome);
|
||||
IAllele b = genome.getInactiveAllele(chromosome);
|
||||
hasAll = a.getUID().equals(geneAlleleUID)
|
||||
&& b.getUID().equals(geneAlleleUID);
|
||||
}
|
||||
}
|
||||
|
||||
if (hasAll) {
|
||||
return new ErrorState("Defunct Serum", "Individual already possesses this allele");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorState canProgress() {
|
||||
return super.canProgress();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinishTask() {
|
||||
super.onFinishTask();
|
||||
ItemStack serum = getUtil().getStack(Splicer.SLOT_SERUM_VIAL);
|
||||
ItemStack target = getUtil().getStack(Splicer.SLOT_TARGET);
|
||||
IIndividual ind = AlleleManager.alleleRegistry.getIndividual(target);
|
||||
if (!ind.isAnalyzed()) {
|
||||
ind.analyze();
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
ind.writeToNBT(nbttagcompound);
|
||||
target.setTagCompound(nbttagcompound);
|
||||
}
|
||||
|
||||
IGene[] genes = ((IItemSerum) serum.getItem()).getGenes(serum);
|
||||
for (IGene gene : genes) {
|
||||
Splicer.setGene(gene, target, 0);
|
||||
Splicer.setGene(gene, target, 1);
|
||||
}
|
||||
getUtil().damageItem(Splicer.SLOT_SERUM_VIAL, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTickTask() {
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package binnie.genetics.machine.splicer;
|
||||
|
||||
import binnie.core.craftgui.minecraft.IMachineInformation;
|
||||
import binnie.core.machines.Machine;
|
||||
import binnie.core.machines.TileEntityMachine;
|
||||
import binnie.core.machines.inventory.ComponentInventorySlots;
|
||||
import binnie.core.machines.inventory.ComponentInventoryTransfer;
|
||||
import binnie.core.machines.inventory.InventorySlot;
|
||||
import binnie.core.machines.inventory.SlotValidator;
|
||||
import binnie.core.machines.power.ComponentPowerReceptor;
|
||||
import binnie.genetics.core.GeneticsGUI;
|
||||
import binnie.genetics.core.GeneticsTexture;
|
||||
import binnie.genetics.genetics.Engineering;
|
||||
import binnie.genetics.machine.AdvGeneticMachine;
|
||||
import binnie.genetics.machine.ComponentGeneticGUI;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public class SplicerPackage extends AdvGeneticMachine.PackageAdvGeneticBase implements IMachineInformation {
|
||||
public SplicerPackage() {
|
||||
super("splicer", GeneticsTexture.Splicer, 0xe22235, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createMachine(Machine machine) {
|
||||
new ComponentGeneticGUI(machine, GeneticsGUI.Splicer);
|
||||
ComponentInventorySlots inventory = new ComponentInventorySlots(machine);
|
||||
SlotValidator serumValid = new SerumSlotValidator();
|
||||
|
||||
InventorySlot serumSlot = inventory.addSlot(Splicer.SLOT_SERUM_VIAL, "serum.active");
|
||||
serumSlot.forbidInteraction();
|
||||
serumSlot.setReadOnly();
|
||||
serumSlot.setValidator(serumValid);
|
||||
|
||||
inventory.addSlotArray(Splicer.SLOT_SERUM_RESERVE, "serum.input");
|
||||
for (InventorySlot slot : inventory.getSlots(Splicer.SLOT_SERUM_RESERVE)) {
|
||||
slot.setValidator(serumValid);
|
||||
slot.forbidExtraction();
|
||||
}
|
||||
|
||||
inventory.addSlotArray(Splicer.SLOT_SERUM_EXPENDED, "serum.output");
|
||||
for (InventorySlot slot : inventory.getSlots(Splicer.SLOT_SERUM_EXPENDED)) {
|
||||
slot.setValidator(serumValid);
|
||||
slot.setReadOnly();
|
||||
}
|
||||
|
||||
inventory.addSlotArray(Splicer.SLOT_RESERVE, "input");
|
||||
for (InventorySlot slot : inventory.getSlots(Splicer.SLOT_RESERVE)) {
|
||||
slot.forbidExtraction();
|
||||
slot.setValidator(new IndividualInoculateValidator());
|
||||
}
|
||||
|
||||
InventorySlot targetSlot = inventory.addSlot(Splicer.SLOT_TARGET, "process");
|
||||
targetSlot.setValidator(new IndividualInoculateValidator());
|
||||
targetSlot.setReadOnly();
|
||||
targetSlot.forbidInteraction();
|
||||
|
||||
inventory.addSlotArray(Splicer.SLOT_FINISHED, "output");
|
||||
for (InventorySlot slot : inventory.getSlots(Splicer.SLOT_FINISHED)) {
|
||||
slot.setReadOnly();
|
||||
slot.forbidInsertion();
|
||||
slot.setValidator(new IndividualInoculateValidator());
|
||||
}
|
||||
|
||||
ComponentInventoryTransfer transfer = new ComponentInventoryTransfer(machine);
|
||||
transfer.addRestock(Splicer.SLOT_RESERVE, Splicer.SLOT_TARGET, 1);
|
||||
transfer.addRestock(Splicer.SLOT_SERUM_RESERVE, Splicer.SLOT_SERUM_VIAL);
|
||||
transfer.addStorage(Splicer.SLOT_SERUM_VIAL, Splicer.SLOT_SERUM_EXPENDED, new ComponentInventoryTransfer.Condition() {
|
||||
@Override
|
||||
public boolean fufilled(ItemStack stack) {
|
||||
return Engineering.getCharges(stack) == 0;
|
||||
}
|
||||
});
|
||||
transfer.addStorage(Splicer.SLOT_TARGET, Splicer.SLOT_FINISHED, new ComponentInventoryTransfer.Condition() {
|
||||
@Override
|
||||
public boolean fufilled(ItemStack stack) {
|
||||
return stack != null
|
||||
&& transfer.getMachine().getMachineUtil().getStack(Splicer.SLOT_SERUM_VIAL) != null
|
||||
&& transfer.getMachine().getInterface(SplicerComponentLogic.class).isValidSerum() != null;
|
||||
}
|
||||
});
|
||||
|
||||
new ComponentPowerReceptor(machine, 20000);
|
||||
new SplicerComponentLogic(machine);
|
||||
new SplicerComponentFX(machine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity() {
|
||||
return new TileEntityMachine(this);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user