More work on getting the Alchemical Tome working properly

This commit is contained in:
Pahimar 2015-02-17 21:10:41 -05:00
parent 051fc7f929
commit 88b7c26756
9 changed files with 46 additions and 26 deletions

View file

@ -1,8 +1,9 @@
package com.pahimar.ee3.client.gui.inventory;
import com.pahimar.ee3.inventory.ContainerAlchemicalTome;
import com.pahimar.ee3.network.PacketHandler;
import com.pahimar.ee3.network.message.MessageGuiElementClicked;
import com.pahimar.ee3.reference.Textures;
import com.pahimar.ee3.util.LogHelper;
import com.pahimar.repackage.cofh.lib.gui.GuiBase;
import com.pahimar.repackage.cofh.lib.gui.element.ElementButton;
import cpw.mods.fml.relauncher.Side;
@ -21,10 +22,8 @@ public class GuiAlchemicalTome extends GuiBase
public GuiAlchemicalTome(EntityPlayer entityPlayer)
{
super(new ContainerAlchemicalTome(entityPlayer.inventory), Textures.Gui.ALCHEMICAL_TOME);
LogHelper.info(this.inventorySlots instanceof ContainerAlchemicalTome);
super(new ContainerAlchemicalTome(entityPlayer), Textures.Gui.ALCHEMICAL_TOME);
ContainerAlchemicalTome containerAlchemicalTome = (ContainerAlchemicalTome) this.inventorySlots;
LogHelper.info(containerAlchemicalTome.getInventorySize());
xSize = 256;
ySize = 226;
}
@ -65,11 +64,7 @@ public class GuiAlchemicalTome extends GuiBase
@Override
protected void updateElementInformation()
{
if (((ContainerAlchemicalTome) this.inventorySlots).getInventorySize() < 80)
{
prevPageButton.setDisabled();
nextPageButton.setDisabled();
}
}
@Override
@ -81,6 +76,6 @@ public class GuiAlchemicalTome extends GuiBase
@Override
public void handleElementButtonClick(String buttonName, int mouseButton)
{
LogHelper.info(String.format("%s %s", buttonName, mouseButton));
PacketHandler.INSTANCE.sendToServer(new MessageGuiElementClicked(buttonName, mouseButton));
}
}

View file

@ -30,7 +30,7 @@ public class ConfigurationHandler
Settings.General.syncThreshold = configuration.getInt(Messages.Configuration.GENERAL_SYNC_THRESHOLD, Configuration.CATEGORY_GENERAL, 5, 0, Short.MAX_VALUE, StatCollector.translateToLocal(Messages.Configuration.GENERAL_SYNC_THRESHOLD_COMMENT), Messages.Configuration.GENERAL_SYNC_THRESHOLD_LABEL);
Settings.Sounds.soundMode = ConfigurationHelper.getString(configuration, Messages.Configuration.SOUND_MODE, Configuration.CATEGORY_GENERAL, "All", StatCollector.translateToLocal(Messages.Configuration.SOUND_MODE_COMMENT), new String[]{"All", "Self", "None"}, Messages.Configuration.SOUND_MODE_LABEL);
Settings.Abilities.onlyLoadFile = configuration.getBoolean(Messages.Configuration.ABILITIES_ONLY_LOAD_FILE, Configuration.CATEGORY_GENERAL, false, StatCollector.translateToLocal(Messages.Configuration.ABILITIES_ONLY_LOAD_FILE_COMMENT), Messages.Configuration.ABILITIES_ONLY_LOAD_FILE_LABEL);
Settings.DynamicEnergyValueGeneration.regenerateEnergyValuesWhen = ConfigurationHelper.getString(configuration, Messages.Configuration.REGENERATE_ENERGYVALUES_WHEN, Configuration.CATEGORY_GENERAL, "Never", StatCollector.translateToLocal(Messages.Configuration.REGENERATE_ENERGYVALUES_WHEN_COMMENT), new String[]{"Never", "When Mods Change"}, Messages.Configuration.REGENERATE_ENERGYVALUES_WHEN_LABEL);
Settings.DynamicEnergyValueGeneration.regenerateEnergyValuesWhen = ConfigurationHelper.getString(configuration, Messages.Configuration.REGENERATE_ENERGYVALUES_WHEN, Configuration.CATEGORY_GENERAL, "When Mods Change", StatCollector.translateToLocal(Messages.Configuration.REGENERATE_ENERGYVALUES_WHEN_COMMENT), new String[]{"Never", "When Mods Change"}, Messages.Configuration.REGENERATE_ENERGYVALUES_WHEN_LABEL);
if (configuration.hasChanged())
{

View file

@ -29,8 +29,7 @@ public class GuiHandler implements IGuiHandler
}
else if (id == GUIs.ALCHEMICAL_TOME.ordinal())
{
// return new ContainerAlchemicalTome(new InventoryAlchemicalTome(entityPlayer.getHeldItem()));
return new ContainerAlchemicalTome(entityPlayer.inventory);
return new ContainerAlchemicalTome(entityPlayer);
}
else if (id == GUIs.CALCINATOR.ordinal())
{
@ -79,7 +78,6 @@ public class GuiHandler implements IGuiHandler
}
else if (id == GUIs.ALCHEMICAL_TOME.ordinal())
{
// return new GuiAlchemicalTome(new InventoryAlchemicalTome(entityPlayer.getHeldItem()));
return new GuiAlchemicalTome(entityPlayer);
}
else if (id == GUIs.CALCINATOR.ordinal())

View file

@ -4,7 +4,6 @@ import com.pahimar.ee3.knowledge.TransmutationKnowledgeRegistry;
import com.pahimar.ee3.util.ItemHelper;
import com.pahimar.repackage.cofh.lib.gui.slot.SlotViewOnly;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import java.util.TreeSet;
@ -17,10 +16,10 @@ public class ContainerAlchemicalTome extends ContainerEE
private final static int MAX_ROW_INDEX = 8;
private final static int MAX_COLUMN_INDEX = 5;
public ContainerAlchemicalTome(InventoryPlayer inventoryPlayer)
public ContainerAlchemicalTome(EntityPlayer entityPlayer)
{
TreeSet<ItemStack> knownTransmutations = new TreeSet<ItemStack>(ItemHelper.displayNameComparator);
knownTransmutations.addAll(TransmutationKnowledgeRegistry.getInstance().getPlayersKnownTransmutations(inventoryPlayer.player.getUniqueID()));
knownTransmutations.addAll(TransmutationKnowledgeRegistry.getInstance().getPlayersKnownTransmutations(entityPlayer.getUniqueID()));
inventoryTransmutationKnowledge = new InventoryTransmutationKnowledge(knownTransmutations);
pageOffset = 0;
@ -55,4 +54,10 @@ public class ContainerAlchemicalTome extends ContainerEE
{
return inventoryTransmutationKnowledge.getSizeInventory();
}
@Override
public void handleElementButtonClick(String buttonName, int mouseButton)
{
}
}

View file

@ -87,4 +87,9 @@ public abstract class ContainerEE extends Container
return slotFound;
}
public void handleElementButtonClick(String buttonName, int mouseButton)
{
// NOOP
}
}

View file

@ -98,7 +98,10 @@ public class ItemAlchemicalBag extends ItemEE implements IOwnable
if (!world.isRemote)
{
// Set the owner
ItemHelper.setOwner(itemStack, entityPlayer);
if (!ItemHelper.hasOwner(itemStack))
{
ItemHelper.setOwner(itemStack, entityPlayer);
}
// Set a UUID on the Alchemical Bag, if one doesn't exist already
NBTHelper.setUUID(itemStack);

View file

@ -33,9 +33,7 @@ public class ItemAlchemicalTome extends ItemEE implements IOwnable
{
ItemHelper.setOwner(itemStack, entityPlayer);
}
}
else
{
entityPlayer.openGui(EquivalentExchange3.instance, GUIs.ALCHEMICAL_TOME.ordinal(), entityPlayer.worldObj, (int) entityPlayer.posX, (int) entityPlayer.posY, (int) entityPlayer.posZ);
}

View file

@ -20,5 +20,6 @@ public class PacketHandler
INSTANCE.registerMessage(MessageSoundEvent.class, MessageSoundEvent.class, 5, Side.CLIENT);
INSTANCE.registerMessage(MessageSyncEnergyValues.class, MessageSyncEnergyValues.class, 6, Side.CLIENT);
INSTANCE.registerMessage(MessageSetEnergyValue.class, MessageSetEnergyValue.class, 7, Side.CLIENT);
INSTANCE.registerMessage(MessageGuiElementClicked.class, MessageGuiElementClicked.class, 8, Side.SERVER);
}
}

View file

@ -1,13 +1,14 @@
package com.pahimar.ee3.network.message;
import com.pahimar.ee3.inventory.ContainerEE;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
public class MessageGuiElementClicked implements IMessage, IMessageHandler<MessageGuiElementClicked, IMessage>
{
public int guiId;
public String elementName;
public int buttonPressed;
@ -16,27 +17,41 @@ public class MessageGuiElementClicked implements IMessage, IMessageHandler<Messa
}
public MessageGuiElementClicked(int guiId, String elementName, int buttonPressed)
public MessageGuiElementClicked(String elementName, int buttonPressed)
{
this.elementName = elementName;
this.buttonPressed = buttonPressed;
}
@Override
public void fromBytes(ByteBuf buf)
{
int elementNameLength = buf.readInt();
this.elementName = new String(buf.readBytes(elementNameLength).array());
this.buttonPressed = buf.readInt();
}
@Override
public void toBytes(ByteBuf buf)
{
buf.writeInt(guiId);
buf.writeInt(elementName.length());
buf.writeBytes(elementName.getBytes());
buf.writeInt(buttonPressed);
}
@Override
public IMessage onMessage(MessageGuiElementClicked message, MessageContext ctx)
{
EntityPlayer entityPlayer = ctx.getServerHandler().playerEntity;
if (entityPlayer != null)
{
if (entityPlayer.openContainer instanceof ContainerEE)
{
((ContainerEE) entityPlayer.openContainer).handleElementButtonClick(message.elementName, message.buttonPressed);
}
}
return null;
}
}