diff --git a/src/main/java/mekanism/client/gui/GuiOredictionificator.java b/src/main/java/mekanism/client/gui/GuiOredictionificator.java index f93d8d330..970ff54f0 100644 --- a/src/main/java/mekanism/client/gui/GuiOredictionificator.java +++ b/src/main/java/mekanism/client/gui/GuiOredictionificator.java @@ -3,10 +3,13 @@ package mekanism.client.gui; import mekanism.client.gui.element.GuiProgress; import mekanism.client.gui.element.GuiProgress.IProgressInfoHandler; import mekanism.client.gui.element.GuiProgress.ProgressBar; +import mekanism.client.gui.element.GuiSlot; +import mekanism.client.gui.element.GuiSlot.SlotType; import mekanism.common.inventory.container.ContainerOredictionificator; import mekanism.common.tile.TileEntityOredictionificator; import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils.ResourceType; +import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.InventoryPlayer; import org.lwjgl.opengl.GL11; @@ -19,6 +22,12 @@ public class GuiOredictionificator extends GuiMekanism { public TileEntityOredictionificator tileEntity; + public boolean isDragging = false; + + public int dragOffset = 0; + + public float scroll; + public GuiOredictionificator(InventoryPlayer inventory, TileEntityOredictionificator tentity) { super(tentity, new ContainerOredictionificator(inventory, tentity)); @@ -32,6 +41,38 @@ public class GuiOredictionificator extends GuiMekanism return 1;//tileEntity.isActive ? 1 : 0; } }, ProgressBar.LARGE_RIGHT, this, MekanismUtils.getResource(ResourceType.GUI, "GuiOredictionificator.png"), 62, 118)); + guiElements.add(new GuiSlot(SlotType.NORMAL, this, MekanismUtils.getResource(ResourceType.GUI, "GuiOredictionificator.png"), 25, 114)); + guiElements.add(new GuiSlot(SlotType.NORMAL, this, MekanismUtils.getResource(ResourceType.GUI, "GuiOredictionificator.png"), 133, 114)); + + ySize+=64; + } + + public int getScroll() + { + return Math.max(Math.min((int)(scroll*88), 88), 0); + } + + @Override + public void initGui() + { + super.initGui(); + + int guiWidth = (width - xSize) / 2; + int guiHeight = (height - ySize) / 2; + + buttonList.clear(); + buttonList.add(new GuiButton(0, guiWidth + 10, guiHeight + 86, 142, 20, MekanismUtils.localize("gui.newFilter"))); + } + + @Override + protected void actionPerformed(GuiButton guibutton) + { + super.actionPerformed(guibutton); + + if(guibutton.id == 0) + { + + } } @Override @@ -57,6 +98,8 @@ public class GuiOredictionificator extends GuiMekanism int xAxis = mouseX - guiWidth; int yAxis = mouseY - guiHeight; + + drawTexturedModalRect(guiWidth + 154, guiHeight + 18 + getScroll(), 232, 0, 12, 15); super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY); } diff --git a/src/main/java/mekanism/common/inventory/container/ContainerOredictionificator.java b/src/main/java/mekanism/common/inventory/container/ContainerOredictionificator.java index 9a2fc12a8..bcf2c2c54 100644 --- a/src/main/java/mekanism/common/inventory/container/ContainerOredictionificator.java +++ b/src/main/java/mekanism/common/inventory/container/ContainerOredictionificator.java @@ -1,14 +1,53 @@ package mekanism.common.inventory.container; +import mekanism.common.inventory.slot.SlotOutput; import mekanism.common.tile.TileEntityOredictionificator; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.Slot; -public class ContainerOredictionificator extends ContainerNull//TODO +public class ContainerOredictionificator extends Container { private TileEntityOredictionificator tileEntity; public ContainerOredictionificator(InventoryPlayer inventory, TileEntityOredictionificator tentity) { + tileEntity = tentity; + addSlotToContainer(new Slot(tentity, 0, 26, 115)); + addSlotToContainer(new SlotOutput(tentity, 1, 134, 115)); + int slotX; + + for(slotX = 0; slotX < 3; slotX++) + { + for(int slotY = 0; slotY < 9; slotY++) + { + addSlotToContainer(new Slot(inventory, slotY + slotX * 9 + 9, 8 + slotY * 18, 148 + slotX * 18)); + } + } + + for(slotX = 0; slotX < 9; slotX++) + { + addSlotToContainer(new Slot(inventory, slotX, 8 + slotX * 18, 206)); + } + + tileEntity.open(inventory.player); + tileEntity.openInventory(); + } + + @Override + public void onContainerClosed(EntityPlayer entityplayer) + { + super.onContainerClosed(entityplayer); + + tileEntity.close(entityplayer); + tileEntity.closeInventory(); + } + + @Override + public boolean canInteractWith(EntityPlayer entityplayer) + { + return tileEntity.isUseableByPlayer(entityplayer); } } diff --git a/src/main/java/mekanism/common/network/PacketEditFilter.java b/src/main/java/mekanism/common/network/PacketEditFilter.java index 49280a708..23c12a26f 100644 --- a/src/main/java/mekanism/common/network/PacketEditFilter.java +++ b/src/main/java/mekanism/common/network/PacketEditFilter.java @@ -1,5 +1,7 @@ package mekanism.common.network; +import io.netty.buffer.ByteBuf; + import java.util.ArrayList; import mekanism.api.Coord4D; @@ -11,7 +13,8 @@ import mekanism.common.network.PacketEditFilter.EditFilterMessage; import mekanism.common.network.PacketTileEntity.TileEntityMessage; import mekanism.common.tile.TileEntityDigitalMiner; import mekanism.common.tile.TileEntityLogisticalSorter; - +import mekanism.common.tile.TileEntityOredictionificator; +import mekanism.common.tile.TileEntityOredictionificator.OredictionificatorFilter; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.world.World; @@ -20,8 +23,6 @@ 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; - public class PacketEditFilter implements IMessageHandler { @Override @@ -77,6 +78,29 @@ public class PacketEditFilter implements IMessageHandler { @Override @@ -53,6 +54,17 @@ public class PacketNewFilter implements IMessageHandler filters = new HashList(); + + public RedstoneControl controlType = RedstoneControl.DISABLED; + public TileEntityOredictionificator() { super(MachineType.OREDICTIONIFICATOR.name); + + inventory = new ItemStack[2]; + doAutoSync = false; } @Override public void onUpdate() { + if(!worldObj.isRemote) + { + if(playersUsing.size() > 0) + { + for(EntityPlayer player : playersUsing) + { + Mekanism.packetHandler.sendTo(new TileEntityMessage(Coord4D.get(this), getGenericPacket(new ArrayList())), (EntityPlayerMP)player); + } + } + } + } + + @Override + public void writeToNBT(NBTTagCompound nbtTags) + { + super.writeToNBT(nbtTags); + + nbtTags.setInteger("controlType", controlType.ordinal()); + + NBTTagList filterTags = new NBTTagList(); + + for(OredictionificatorFilter filter : filters) + { + NBTTagCompound tagCompound = new NBTTagCompound(); + filter.write(tagCompound); + filterTags.appendTag(tagCompound); + } + + if(filterTags.tagCount() != 0) + { + nbtTags.setTag("filters", filterTags); + } + } + + @Override + public void readFromNBT(NBTTagCompound nbtTags) + { + super.readFromNBT(nbtTags); + + controlType = RedstoneControl.values()[nbtTags.getInteger("controlType")]; + + if(nbtTags.hasKey("filters")) + { + NBTTagList tagList = nbtTags.getTagList("filters", NBT.TAG_COMPOUND); + + for(int i = 0; i < tagList.tagCount(); i++) + { + filters.add(OredictionificatorFilter.readFromNBT((NBTTagCompound)tagList.getCompoundTagAt(i))); + } + } + } + + @Override + public void handlePacketData(ByteBuf dataStream) + { + super.handlePacketData(dataStream); + + int type = dataStream.readInt(); + + if(type == 0) + { + controlType = RedstoneControl.values()[dataStream.readInt()]; + + filters.clear(); + + int amount = dataStream.readInt(); + + for(int i = 0; i < amount; i++) + { + filters.add(OredictionificatorFilter.readFromPacket(dataStream)); + } + } + else if(type == 1) + { + controlType = RedstoneControl.values()[dataStream.readInt()]; + } + else if(type == 2) + { + filters.clear(); + + int amount = dataStream.readInt(); + + for(int i = 0; i < amount; i++) + { + filters.add(OredictionificatorFilter.readFromPacket(dataStream)); + } + } + } + + @Override + public ArrayList getNetworkedData(ArrayList data) + { + super.getNetworkedData(data); + + data.add(0); + + data.add(controlType.ordinal()); + + data.add(filters.size()); + + for(OredictionificatorFilter filter : filters) + { + filter.write(data); + } + + return data; + } + + public ArrayList getGenericPacket(ArrayList data) + { + super.getNetworkedData(data); + + data.add(1); + + data.add(controlType.ordinal()); + + return data; + + } + + public ArrayList getFilterPacket(ArrayList data) + { + super.getNetworkedData(data); + + data.add(2); + + data.add(filters.size()); + + for(OredictionificatorFilter filter : filters) + { + filter.write(data); + } + + return data; + } + + @Override + public void openInventory() + { + if(!worldObj.isRemote) + { + Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(this), getFilterPacket(new ArrayList())), new Range4D(Coord4D.get(this))); + } + } + + @Override + public NBTTagCompound getFilterData(NBTTagCompound nbtTags) + { + nbtTags.setInteger("controlType", controlType.ordinal()); + + NBTTagList filterTags = new NBTTagList(); + + for(OredictionificatorFilter filter : filters) + { + NBTTagCompound tagCompound = new NBTTagCompound(); + filter.write(tagCompound); + filterTags.appendTag(tagCompound); + } + + if(filterTags.tagCount() != 0) + { + nbtTags.setTag("filters", filterTags); + } + return nbtTags; + } + + @Override + public void setFilterData(NBTTagCompound nbtTags) + { + controlType = RedstoneControl.values()[nbtTags.getInteger("controlType")]; + + if(nbtTags.hasKey("filters")) + { + NBTTagList tagList = nbtTags.getTagList("filters", NBT.TAG_COMPOUND); + + for(int i = 0; i < tagList.tagCount(); i++) + { + filters.add(OredictionificatorFilter.readFromNBT((NBTTagCompound)tagList.getCompoundTagAt(i))); + } + } + } + + @Override + public String getDataType() + { + return "tooltip.filterCard.oredictionificator"; + } + + @Override + public void writeSustainedData(ItemStack itemStack) + { + itemStack.stackTagCompound.setBoolean("hasOredictionificatorConfig", true); + + NBTTagList filterTags = new NBTTagList(); + + for(OredictionificatorFilter filter : filters) + { + NBTTagCompound tagCompound = new NBTTagCompound(); + filter.write(tagCompound); + filterTags.appendTag(tagCompound); + } + + if(filterTags.tagCount() != 0) + { + itemStack.stackTagCompound.setTag("filters", filterTags); + } + } + + @Override + public void readSustainedData(ItemStack itemStack) + { + if(itemStack.stackTagCompound.hasKey("hasOredictionificatorConfig")) + { + if(itemStack.stackTagCompound.hasKey("filters")) + { + NBTTagList tagList = itemStack.stackTagCompound.getTagList("filters", NBT.TAG_COMPOUND); + + for(int i = 0; i < tagList.tagCount(); i++) + { + filters.add(OredictionificatorFilter.readFromNBT((NBTTagCompound)tagList.getCompoundTagAt(i))); + } + } + } + } + + @Override + public RedstoneControl getControlType() + { + return controlType; + } + + @Override + public void setControlType(RedstoneControl type) + { + controlType = type; + } + + @Override + public boolean canPulse() + { + return true; + } + + public static class OredictionificatorFilter + { + public String filter; + public int index; + + public void write(NBTTagCompound nbtTags) + { + nbtTags.setString("filter", filter); + nbtTags.setInteger("index", index); + } + + protected void read(NBTTagCompound nbtTags) + { + filter = nbtTags.getString("filter"); + index = nbtTags.getInteger("index"); + } + + public void write(ArrayList data) + { + data.add(filter); + data.add(index); + } + + protected void read(ByteBuf dataStream) + { + filter = PacketHandler.readString(dataStream); + index = dataStream.readInt(); + } + + public static OredictionificatorFilter readFromNBT(NBTTagCompound nbtTags) + { + OredictionificatorFilter filter = new OredictionificatorFilter(); + + filter.read(nbtTags); + + return filter; + } + + public static OredictionificatorFilter readFromPacket(ByteBuf dataStream) + { + OredictionificatorFilter filter = new OredictionificatorFilter(); + + filter.read(dataStream); + + return filter; + } + + @Override + public int hashCode() + { + int code = 1; + code = 31 * code + filter.hashCode(); + return code; + } + + @Override + public boolean equals(Object filter) + { + return filter instanceof OredictionificatorFilter && ((OredictionificatorFilter)filter).filter.equals(filter); + } } } diff --git a/src/main/resources/assets/mekanism/gui/GuiOredictionificator.png b/src/main/resources/assets/mekanism/gui/GuiOredictionificator.png index 01a8eaa67..bd127f56b 100644 Binary files a/src/main/resources/assets/mekanism/gui/GuiOredictionificator.png and b/src/main/resources/assets/mekanism/gui/GuiOredictionificator.png differ diff --git a/src/main/resources/assets/mekanism/gui/GuiOredictionificatorFilter.png b/src/main/resources/assets/mekanism/gui/GuiOredictionificatorFilter.png new file mode 100644 index 000000000..96df168d0 Binary files /dev/null and b/src/main/resources/assets/mekanism/gui/GuiOredictionificatorFilter.png differ diff --git a/src/main/resources/assets/mekanism/lang/en_US.lang b/src/main/resources/assets/mekanism/lang/en_US.lang index 59bd5a43b..eb5849eba 100644 --- a/src/main/resources/assets/mekanism/lang/en_US.lang +++ b/src/main/resources/assets/mekanism/lang/en_US.lang @@ -629,6 +629,7 @@ tooltip.filterCard.set=Injected filter data of type %s tooltip.filterCard.unequal=Unequal filter data formats tooltip.filterCard.logisticalSorter=Logistical Sorter tooltip.filterCard.digitalMiner=Digital Miner +tooltip.filterCard.oredictionificator=Oredictionificator tooltip.balloon=Balloon