diff --git a/src/main/java/forestry/core/gui/ContainerEscritoire.java b/src/main/java/forestry/core/gui/ContainerEscritoire.java index 4e2414aa8..293d25fe4 100755 --- a/src/main/java/forestry/core/gui/ContainerEscritoire.java +++ b/src/main/java/forestry/core/gui/ContainerEscritoire.java @@ -23,16 +23,11 @@ import forestry.core.tiles.EscritoireGame; import forestry.core.tiles.TileEscritoire; public class ContainerEscritoire extends ContainerTile implements IGuiSelectable { - - private final EntityPlayer player; - private long lastUpdate; public ContainerEscritoire(EntityPlayer player, TileEscritoire tile) { super(tile, player.inventory, 34, 153); - this.player = player; - // Analyze slot addSlotToContainer(new SlotFiltered(this.tile, InventoryEscritoire.SLOT_ANALYZE, 97, 67).setPickupWatcher(this.tile).setStackLimit(1)); @@ -54,7 +49,7 @@ public class ContainerEscritoire extends ContainerTile implement long gameLastUpdate = tile.getGame().getLastUpdate(); if (lastUpdate != gameLastUpdate) { lastUpdate = gameLastUpdate; - Proxies.net.sendToPlayer(new PacketGuiUpdate(tile), player); + sendPacketToListeners(new PacketGuiUpdate(tile)); } } diff --git a/src/main/java/forestry/core/gui/widgets/GameTokenWidget.java b/src/main/java/forestry/core/gui/widgets/GameTokenWidget.java index 8ffa325b8..657ea035c 100644 --- a/src/main/java/forestry/core/gui/widgets/GameTokenWidget.java +++ b/src/main/java/forestry/core/gui/widgets/GameTokenWidget.java @@ -91,6 +91,7 @@ public class GameTokenWidget extends Widget { @Override public void handleMouseClick(int mouseX, int mouseY, int mouseButton) { + game.choose(index); Proxies.net.sendToServer(new PacketGuiSelectRequest(index, 0)); } } diff --git a/src/main/java/forestry/core/tiles/EscritoireGameBoard.java b/src/main/java/forestry/core/tiles/EscritoireGameBoard.java index 974445db5..2c1c0f324 100644 --- a/src/main/java/forestry/core/tiles/EscritoireGameBoard.java +++ b/src/main/java/forestry/core/tiles/EscritoireGameBoard.java @@ -17,6 +17,7 @@ import java.util.Collections; import java.util.List; import java.util.Random; +import forestry.api.genetics.IAllele; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; @@ -72,10 +73,10 @@ public class EscritoireGameBoard implements INbtWritable, IStreamable { tokenCount = getTokenCount(genome); for (int i = 0; i < tokenCount / 2; i++) { - IIndividual token = root.templateAsIndividual(root.getRandomTemplate(rand)); - ItemStack pair = root.getMemberStack(token, root.getIconType()); - gameTokens.add(new EscritoireGameToken(pair)); - gameTokens.add(new EscritoireGameToken(pair)); + IAllele[] randomTemplate = root.getRandomTemplate(rand); + String speciesUid = randomTemplate[root.getSpeciesChromosomeType().ordinal()].getUID(); + gameTokens.add(new EscritoireGameToken(speciesUid)); + gameTokens.add(new EscritoireGameToken(speciesUid)); } Collections.shuffle(gameTokens); return true; diff --git a/src/main/java/forestry/core/tiles/EscritoireGameToken.java b/src/main/java/forestry/core/tiles/EscritoireGameToken.java index bd8908fba..a8098e9ff 100644 --- a/src/main/java/forestry/core/tiles/EscritoireGameToken.java +++ b/src/main/java/forestry/core/tiles/EscritoireGameToken.java @@ -14,17 +14,19 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.io.IOException; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - import forestry.api.core.INbtWritable; import forestry.api.genetics.AlleleManager; +import forestry.api.genetics.IAllele; +import forestry.api.genetics.IAlleleSpecies; import forestry.api.genetics.IIndividual; +import forestry.api.genetics.ISpeciesRoot; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; import forestry.core.network.IStreamable; import forestry.core.utils.ColourUtil; import forestry.core.utils.Translator; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; public class EscritoireGameToken implements INbtWritable, IStreamable { @@ -41,6 +43,8 @@ public class EscritoireGameToken implements INbtWritable, IStreamable { private static final String[] OVERLAY_FAILED = new String[]{"errors/errored"}; private static final String[] OVERLAY_SELECTED = new String[]{"errors/unknown"}; + @Nullable + private IIndividual tokenIndividual; @Nullable private ItemStack tokenStack; @Nonnull @@ -51,8 +55,8 @@ public class EscritoireGameToken implements INbtWritable, IStreamable { // required for IStreamable serialization } - public EscritoireGameToken(@Nullable ItemStack tokenStack) { - this.tokenStack = tokenStack; + public EscritoireGameToken(@Nullable String speciesUid) { + setTokenSpecies(speciesUid); } public EscritoireGameToken(@Nonnull NBTTagCompound nbttagcompound) { @@ -61,8 +65,29 @@ public class EscritoireGameToken implements INbtWritable, IStreamable { state = State.values()[stateOrdinal]; } + // legacy if (nbttagcompound.hasKey("tokenStack")) { tokenStack = ItemStack.loadItemStackFromNBT(nbttagcompound.getCompoundTag("tokenStack")); + ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(tokenStack); + tokenIndividual = speciesRoot.getMember(tokenStack); + } + + if (nbttagcompound.hasKey("tokenSpecies")) { + String speciesUid = nbttagcompound.getString("tokenSpecies"); + setTokenSpecies(speciesUid); + } + } + + private void setTokenSpecies(String speciesUid) { + IAllele allele = AlleleManager.alleleRegistry.getAllele(speciesUid); + if (allele instanceof IAlleleSpecies) { + IAlleleSpecies species = (IAlleleSpecies) allele; + ISpeciesRoot root = species.getRoot(); + IAllele[] template = root.getTemplate(speciesUid); + if (template != null) { + this.tokenIndividual = root.templateAsIndividual(template); + this.tokenStack = root.getMemberStack(this.tokenIndividual, root.getIconType()); + } } } @@ -108,12 +133,11 @@ public class EscritoireGameToken implements INbtWritable, IStreamable { } public int getTokenColour() { - if (tokenStack == null || !isVisible()) { + if (tokenIndividual == null || !isVisible()) { return 0xffffff; } - IIndividual individual = AlleleManager.alleleRegistry.getIndividual(tokenStack); - int iconColor = individual.getGenome().getPrimary().getSpriteColour(0); + int iconColor = tokenIndividual.getGenome().getPrimary().getSpriteColour(0); if (state == State.MATCHED) { return ColourUtil.multiplyRGBComponents(iconColor, 0.7f); @@ -146,10 +170,8 @@ public class EscritoireGameToken implements INbtWritable, IStreamable { public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) { nbttagcompound.setInteger("state", state.ordinal()); - if (tokenStack != null) { - NBTTagCompound stackcompound = new NBTTagCompound(); - tokenStack.writeToNBT(stackcompound); - nbttagcompound.setTag("tokenStack", stackcompound); + if (tokenIndividual != null) { + nbttagcompound.setString("tokenSpecies", tokenIndividual.getGenome().getPrimary().getUID()); } return nbttagcompound; } @@ -158,12 +180,20 @@ public class EscritoireGameToken implements INbtWritable, IStreamable { @Override public void writeData(DataOutputStreamForestry data) throws IOException { data.writeEnum(state, State.VALUES); - data.writeItemStack(tokenStack); + if (tokenIndividual != null) { + data.writeBoolean(true); + data.writeUTF(tokenIndividual.getGenome().getPrimary().getUID()); + } else { + data.writeBoolean(false); + } } @Override public void readData(DataInputStreamForestry data) throws IOException { state = data.readEnum(State.VALUES); - tokenStack = data.readItemStack(); + if (data.readBoolean()) { + String speciesUid = data.readUTF(); + setTokenSpecies(speciesUid); + } } }