diff --git a/src/main/java/mekanism/client/ClientProxy.java b/src/main/java/mekanism/client/ClientProxy.java index 445751cc5..a1fde3dd0 100644 --- a/src/main/java/mekanism/client/ClientProxy.java +++ b/src/main/java/mekanism/client/ClientProxy.java @@ -52,11 +52,11 @@ import mekanism.client.gui.GuiPrecisionSawmill; import mekanism.client.gui.GuiPurificationChamber; import mekanism.client.gui.GuiQuantumEntangloporter; import mekanism.client.gui.GuiResistiveHeater; -import mekanism.client.gui.GuiRobitCrafting; -import mekanism.client.gui.GuiRobitInventory; -import mekanism.client.gui.GuiRobitMain; -import mekanism.client.gui.GuiRobitRepair; -import mekanism.client.gui.GuiRobitSmelting; +import mekanism.client.gui.robit.GuiRobitCrafting; +import mekanism.client.gui.robit.GuiRobitInventory; +import mekanism.client.gui.robit.GuiRobitMain; +import mekanism.client.gui.robit.GuiRobitRepair; +import mekanism.client.gui.robit.GuiRobitSmelting; import mekanism.client.gui.GuiRotaryCondensentrator; import mekanism.client.gui.GuiSecurityDesk; import mekanism.client.gui.GuiSeismicReader; diff --git a/src/main/java/mekanism/client/gui/GuiMFilterSelect.java b/src/main/java/mekanism/client/gui/GuiMFilterSelect.java index f55f13bee..504a21507 100644 --- a/src/main/java/mekanism/client/gui/GuiMFilterSelect.java +++ b/src/main/java/mekanism/client/gui/GuiMFilterSelect.java @@ -24,14 +24,14 @@ import org.lwjgl.opengl.GL11; public class GuiMFilterSelect extends GuiMekanism { public TileEntityDigitalMiner tileEntity; - + public GuiMFilterSelect(EntityPlayer player, TileEntityDigitalMiner tentity) { super(tentity, new ContainerNull(player, tentity)); - + tileEntity = tentity; } - + @Override public void initGui() { @@ -39,14 +39,14 @@ public class GuiMFilterSelect extends GuiMekanism int guiWidth = (width - xSize) / 2; int guiHeight = (height - ySize) / 2; - + buttonList.clear(); buttonList.add(new GuiButton(0, guiWidth + 24, guiHeight + 32, 128, 20, LangUtils.localize("gui.itemstack"))); buttonList.add(new GuiButton(1, guiWidth + 24, guiHeight + 52, 128, 20, LangUtils.localize("gui.oredict"))); buttonList.add(new GuiButton(2, guiWidth + 24, guiHeight + 72, 128, 20, LangUtils.localize("gui.material"))); buttonList.add(new GuiButton(3, guiWidth + 24, guiHeight + 92, 128, 20, LangUtils.localize("gui.modID"))); } - + @Override protected void actionPerformed(GuiButton guibutton) throws IOException { @@ -69,7 +69,7 @@ public class GuiMFilterSelect extends GuiMekanism Mekanism.packetHandler.sendToServer(new DigitalMinerGuiMessage(MinerGuiPacket.SERVER, Coord4D.get(tileEntity), 6, 0, 0)); } } - + @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { @@ -77,10 +77,10 @@ public class GuiMFilterSelect extends GuiMekanism int yAxis = (mouseY - (height - ySize) / 2); fontRenderer.drawString(LangUtils.localize("gui.filterSelect.title"), 43, 6, 0x404040); - + super.drawGuiContainerForegroundLayer(mouseX, mouseY); } - + @Override protected void drawGuiContainerBackgroundLayer(float partialTick, int mouseX, int mouseY) { @@ -100,25 +100,25 @@ public class GuiMFilterSelect extends GuiMekanism else { drawTexturedModalRect(guiWidth + 5, guiHeight + 5, 176, 11, 11, 11); } - + super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY); } - + @Override public void mouseClicked(int mouseX, int mouseY, int button) throws IOException { super.mouseClicked(mouseX, mouseY, button); - + if(button == 0) { int xAxis = (mouseX - (width - xSize) / 2); int yAxis = (mouseY - (height - ySize) / 2); - + if(xAxis >= 5 && xAxis <= 16 && yAxis >= 5 && yAxis <= 16) { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); + SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); Mekanism.packetHandler.sendToServer(new DigitalMinerGuiMessage(MinerGuiPacket.SERVER, Coord4D.get(tileEntity), 0, 0, 0)); } } } -} +} \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/GuiMItemStackFilter.java b/src/main/java/mekanism/client/gui/GuiMItemStackFilter.java index faeb3695e..2582e4ab1 100644 --- a/src/main/java/mekanism/client/gui/GuiMItemStackFilter.java +++ b/src/main/java/mekanism/client/gui/GuiMItemStackFilter.java @@ -131,7 +131,7 @@ public class GuiMItemStackFilter extends GuiMekanism RenderHelper.disableStandardItemLighting(); GlStateManager.popMatrix(); } - + if(!filter.replaceStack.isEmpty()) { GlStateManager.pushMatrix(); @@ -140,12 +140,12 @@ public class GuiMItemStackFilter extends GuiMekanism RenderHelper.disableStandardItemLighting(); GlStateManager.popMatrix(); } - + if(xAxis >= 148 && xAxis <= 162 && yAxis >= 45 && yAxis <= 59) { drawHoveringText(LangUtils.localize("gui.digitalMiner.requireReplace") + ": " + LangUtils.transYesNo(filter.requireStack), xAxis, yAxis); } - + if(xAxis >= 15 && xAxis <= 29 && yAxis >= 45 && yAxis <= 59) { drawHoveringText(LangUtils.localize("gui.digitalMiner.fuzzyMode") + ": " + LangUtils.transYesNo(filter.fuzzy), xAxis, yAxis); @@ -187,7 +187,7 @@ public class GuiMItemStackFilter extends GuiMekanism else { drawTexturedModalRect(guiWidth + 5, guiHeight + 5, 176, 11, 11, 11); } - + if(xAxis >= 148 && xAxis <= 162 && yAxis >= 45 && yAxis <= 59) { drawTexturedModalRect(guiWidth + 148, guiHeight + 45, 176 + 23, 0, 14, 14); @@ -195,7 +195,7 @@ public class GuiMItemStackFilter extends GuiMekanism else { drawTexturedModalRect(guiWidth + 148, guiHeight + 45, 176 + 23, 14, 14, 14); } - + if(xAxis >= 15 && xAxis <= 29 && yAxis >= 45 && yAxis <= 59) { drawTexturedModalRect(guiWidth + 15, guiHeight + 45, 176 + 37, 0, 14, 14); @@ -220,7 +220,7 @@ public class GuiMItemStackFilter extends GuiMekanism GlStateManager.enableDepth(); GlStateManager.popMatrix(); } - + if(xAxis >= 149 && xAxis <= 165 && yAxis >= 19 && yAxis <= 35) { GlStateManager.pushMatrix(); @@ -237,7 +237,7 @@ public class GuiMItemStackFilter extends GuiMekanism GlStateManager.enableDepth(); GlStateManager.popMatrix(); } - + super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY); } @@ -253,16 +253,16 @@ public class GuiMItemStackFilter extends GuiMekanism if(xAxis >= 5 && xAxis <= 16 && yAxis >= 5 && yAxis <= 16) { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); + SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); Mekanism.packetHandler.sendToServer(new DigitalMinerGuiMessage(MinerGuiPacket.SERVER, Coord4D.get(tileEntity), isNew ? 5 : 0, 0, 0)); } - + if(xAxis >= 148 && xAxis <= 162 && yAxis >= 45 && yAxis <= 59) { SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); filter.requireStack = !filter.requireStack; } - + if(xAxis >= 15 && xAxis <= 29 && yAxis >= 45 && yAxis <= 59) { SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); @@ -289,9 +289,9 @@ public class GuiMItemStackFilter extends GuiMekanism filter.itemType = ItemStack.EMPTY; } - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); + SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); } - + if(xAxis >= 149 && xAxis <= 165 && yAxis >= 19 && yAxis <= 35) { boolean doNull = false; @@ -319,8 +319,8 @@ public class GuiMItemStackFilter extends GuiMekanism filter.replaceStack = toUse; } - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); + SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); } } } -} +} \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/GuiMMaterialFilter.java b/src/main/java/mekanism/client/gui/GuiMMaterialFilter.java index fb615e6b0..3262785b9 100644 --- a/src/main/java/mekanism/client/gui/GuiMMaterialFilter.java +++ b/src/main/java/mekanism/client/gui/GuiMMaterialFilter.java @@ -131,7 +131,7 @@ public class GuiMMaterialFilter extends GuiMekanism RenderHelper.disableStandardItemLighting(); GlStateManager.popMatrix(); } - + if(!filter.replaceStack.isEmpty()) { GlStateManager.pushMatrix(); @@ -140,7 +140,7 @@ public class GuiMMaterialFilter extends GuiMekanism RenderHelper.disableStandardItemLighting(); GlStateManager.popMatrix(); } - + if(xAxis >= 148 && xAxis <= 162 && yAxis >= 45 && yAxis <= 59) { drawHoveringText(LangUtils.localize("gui.digitalMiner.requireReplace") + ": " + LangUtils.transYesNo(filter.requireStack), xAxis, yAxis); @@ -182,7 +182,7 @@ public class GuiMMaterialFilter extends GuiMekanism else { drawTexturedModalRect(guiWidth + 5, guiHeight + 5, 176, 11, 11, 11); } - + if(xAxis >= 148 && xAxis <= 162 && yAxis >= 45 && yAxis <= 59) { drawTexturedModalRect(guiWidth + 148, guiHeight + 45, 176 + 23, 0, 14, 14); @@ -207,7 +207,7 @@ public class GuiMMaterialFilter extends GuiMekanism GlStateManager.enableDepth(); GlStateManager.popMatrix(); } - + if(xAxis >= 149 && xAxis <= 165 && yAxis >= 19 && yAxis <= 35) { GlStateManager.pushMatrix(); @@ -224,7 +224,7 @@ public class GuiMMaterialFilter extends GuiMekanism GlStateManager.enableDepth(); GlStateManager.popMatrix(); } - + super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY); } @@ -240,10 +240,10 @@ public class GuiMMaterialFilter extends GuiMekanism if(xAxis >= 5 && xAxis <= 16 && yAxis >= 5 && yAxis <= 16) { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); + SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); Mekanism.packetHandler.sendToServer(new DigitalMinerGuiMessage(MinerGuiPacket.SERVER, Coord4D.get(tileEntity), isNew ? 5 : 0, 0, 0)); } - + if(xAxis >= 148 && xAxis <= 162 && yAxis >= 45 && yAxis <= 59) { SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); @@ -270,9 +270,9 @@ public class GuiMMaterialFilter extends GuiMekanism filter.materialItem = ItemStack.EMPTY; } - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); + SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); } - + if(xAxis >= 149 && xAxis <= 165 && yAxis >= 19 && yAxis <= 35) { boolean doNull = false; @@ -300,8 +300,8 @@ public class GuiMMaterialFilter extends GuiMekanism filter.replaceStack = toUse; } - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); + SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); } } } -} +} \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/GuiMModIDFilter.java b/src/main/java/mekanism/client/gui/GuiMModIDFilter.java index 59e47d39d..7ea817e25 100644 --- a/src/main/java/mekanism/client/gui/GuiMModIDFilter.java +++ b/src/main/java/mekanism/client/gui/GuiMModIDFilter.java @@ -177,7 +177,7 @@ public class GuiMModIDFilter extends GuiMekanism GlStateManager.popMatrix(); } catch(Exception ignored) {} } - + if(!filter.replaceStack.isEmpty()) { GlStateManager.pushMatrix(); @@ -186,7 +186,7 @@ public class GuiMModIDFilter extends GuiMekanism RenderHelper.disableStandardItemLighting(); GlStateManager.popMatrix(); } - + if(xAxis >= 148 && xAxis <= 162 && yAxis >= 45 && yAxis <= 59) { drawHoveringText(LangUtils.localize("gui.digitalMiner.requireReplace") + ": " + LangUtils.transYesNo(filter.requireStack), xAxis, yAxis); @@ -222,7 +222,7 @@ public class GuiMModIDFilter extends GuiMekanism else { drawTexturedModalRect(guiWidth + 131, guiHeight + 47, 176 + 11, 12, 12, 12); } - + if(xAxis >= 148 && xAxis <= 162 && yAxis >= 45 && yAxis <= 59) { drawTexturedModalRect(guiWidth + 148, guiHeight + 45, 176 + 23, 0, 14, 14); @@ -230,9 +230,9 @@ public class GuiMModIDFilter extends GuiMekanism else { drawTexturedModalRect(guiWidth + 148, guiHeight + 45, 176 + 23, 14, 14, 14); } - + modIDText.drawTextBox(); - + if(xAxis >= 149 && xAxis <= 165 && yAxis >= 19 && yAxis <= 35) { GlStateManager.pushMatrix(); @@ -249,7 +249,7 @@ public class GuiMModIDFilter extends GuiMekanism GlStateManager.enableDepth(); GlStateManager.popMatrix(); } - + super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY); } @@ -308,22 +308,22 @@ public class GuiMModIDFilter extends GuiMekanism if(xAxis >= 5 && xAxis <= 16 && yAxis >= 5 && yAxis <= 16) { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); + SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); Mekanism.packetHandler.sendToServer(new DigitalMinerGuiMessage(MinerGuiPacket.SERVER, Coord4D.get(tileEntity), isNew ? 5 : 0, 0, 0)); } if(xAxis >= 131 && xAxis <= 143 && yAxis >= 47 && yAxis <= 59) { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); + SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); setModID(); } - + if(xAxis >= 148 && xAxis <= 162 && yAxis >= 45 && yAxis <= 59) { SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); filter.requireStack = !filter.requireStack; } - + if(xAxis >= 149 && xAxis <= 165 && yAxis >= 19 && yAxis <= 35) { boolean doNull = false; @@ -351,7 +351,7 @@ public class GuiMModIDFilter extends GuiMekanism filter.replaceStack = toUse; } - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); + SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); } } } @@ -384,4 +384,4 @@ public class GuiMModIDFilter extends GuiMekanism filter.modID = modName; modIDText.setText(""); } -} +} \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/GuiMOreDictFilter.java b/src/main/java/mekanism/client/gui/GuiMOreDictFilter.java index 97e1727c5..b032ba396 100644 --- a/src/main/java/mekanism/client/gui/GuiMOreDictFilter.java +++ b/src/main/java/mekanism/client/gui/GuiMOreDictFilter.java @@ -177,7 +177,7 @@ public class GuiMOreDictFilter extends GuiMekanism GlStateManager.popMatrix(); } catch(Exception ignored) {} } - + if(!filter.replaceStack.isEmpty()) { GlStateManager.pushMatrix(); @@ -186,7 +186,7 @@ public class GuiMOreDictFilter extends GuiMekanism RenderHelper.disableStandardItemLighting(); GlStateManager.popMatrix(); } - + if(xAxis >= 148 && xAxis <= 162 && yAxis >= 45 && yAxis <= 59) { drawHoveringText(LangUtils.localize("gui.digitalMiner.requireReplace") + ": " + LangUtils.transYesNo(filter.requireStack), xAxis, yAxis); @@ -222,7 +222,7 @@ public class GuiMOreDictFilter extends GuiMekanism else { drawTexturedModalRect(guiWidth + 131, guiHeight + 47, 176 + 11, 12, 12, 12); } - + if(xAxis >= 148 && xAxis <= 162 && yAxis >= 45 && yAxis <= 59) { drawTexturedModalRect(guiWidth + 148, guiHeight + 45, 176 + 23, 0, 14, 14); @@ -230,9 +230,9 @@ public class GuiMOreDictFilter extends GuiMekanism else { drawTexturedModalRect(guiWidth + 148, guiHeight + 45, 176 + 23, 14, 14, 14); } - + oreDictText.drawTextBox(); - + if(xAxis >= 149 && xAxis <= 165 && yAxis >= 19 && yAxis <= 35) { GlStateManager.pushMatrix(); @@ -249,7 +249,7 @@ public class GuiMOreDictFilter extends GuiMekanism GlStateManager.enableDepth(); GlStateManager.popMatrix(); } - + super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY); } @@ -308,22 +308,22 @@ public class GuiMOreDictFilter extends GuiMekanism if(xAxis >= 5 && xAxis <= 16 && yAxis >= 5 && yAxis <= 16) { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); + SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); Mekanism.packetHandler.sendToServer(new DigitalMinerGuiMessage(MinerGuiPacket.SERVER, Coord4D.get(tileEntity), isNew ? 5 : 0, 0, 0)); } if(xAxis >= 131 && xAxis <= 143 && yAxis >= 47 && yAxis <= 59) { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); + SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); setOreDictKey(); } - + if(xAxis >= 148 && xAxis <= 162 && yAxis >= 45 && yAxis <= 59) { SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); filter.requireStack = !filter.requireStack; } - + if(xAxis >= 149 && xAxis <= 165 && yAxis >= 19 && yAxis <= 35) { boolean doNull = false; @@ -351,7 +351,7 @@ public class GuiMOreDictFilter extends GuiMekanism filter.replaceStack = toUse; } - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); + SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); } } } @@ -384,4 +384,4 @@ public class GuiMOreDictFilter extends GuiMekanism filter.oreDictName = oreName; oreDictText.setText(""); } -} +} \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/GuiOredictionificatorFilter.java b/src/main/java/mekanism/client/gui/GuiOredictionificatorFilter.java index 0e64ae744..514ed656b 100644 --- a/src/main/java/mekanism/client/gui/GuiOredictionificatorFilter.java +++ b/src/main/java/mekanism/client/gui/GuiOredictionificatorFilter.java @@ -34,41 +34,41 @@ import org.lwjgl.opengl.GL11; public class GuiOredictionificatorFilter extends GuiMekanism { public TileEntityOredictionificator tileEntity; - + public OredictionificatorFilter origFilter; public OredictionificatorFilter filter = new OredictionificatorFilter(); - + public GuiTextField filterText; - + public boolean isNew; - + public ItemStack renderStack = ItemStack.EMPTY; - + public GuiOredictionificatorFilter(EntityPlayer player, TileEntityOredictionificator tentity, int index) { super(tentity, new ContainerFilter(player.inventory, tentity)); tileEntity = tentity; - + origFilter = tileEntity.filters.get(index); filter = tentity.filters.get(index).clone(); - + updateRenderStack(); } - + public GuiOredictionificatorFilter(EntityPlayer player, TileEntityOredictionificator tentity) { super(tentity, new ContainerFilter(player.inventory, tentity)); tileEntity = tentity; - + isNew = true; } - + public void setFilter() { String newFilter = filterText.getText(); boolean has = false; - + for(String s : TileEntityOredictionificator.possibleFilters) { if(newFilter.startsWith(s)) @@ -77,19 +77,19 @@ public class GuiOredictionificatorFilter extends GuiMekanism break; } } - + if(has) { filter.filter = newFilter; filter.index = 0; filterText.setText(""); - + updateRenderStack(); } - + updateButtons(); } - + public void updateButtons() { if(filter.filter != null && !filter.filter.isEmpty()) @@ -99,7 +99,7 @@ public class GuiOredictionificatorFilter extends GuiMekanism else { buttonList.get(0).enabled = false; } - + if(!isNew) { buttonList.get(1).enabled = true; @@ -108,7 +108,7 @@ public class GuiOredictionificatorFilter extends GuiMekanism buttonList.get(1).enabled = false; } } - + @Override public void initGui() { @@ -129,10 +129,10 @@ public class GuiOredictionificatorFilter extends GuiMekanism filterText = new GuiTextField(2, fontRenderer, guiWidth + 33, guiHeight + 48, 96, 12); filterText.setMaxStringLength(TileEntityOredictionificator.MAX_LENGTH); filterText.setFocused(true); - + updateButtons(); } - + @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { @@ -141,9 +141,9 @@ public class GuiOredictionificatorFilter extends GuiMekanism String text = (isNew ? LangUtils.localize("gui.new") : LangUtils.localize("gui.edit")) + " " + LangUtils.localize("gui.filter"); fontRenderer.drawString(text, (xSize/2)-(fontRenderer.getStringWidth(text)/2), 6, 0x404040); - + fontRenderer.drawString(LangUtils.localize("gui.index") + ": " + filter.index, 79, 23, 0x404040); - + if(filter.filter != null) { renderScaledText(filter.filter, 32, 38, 0x404040, 111); @@ -159,29 +159,29 @@ public class GuiOredictionificatorFilter extends GuiMekanism GlStateManager.popMatrix(); } catch(Exception ignored) {} } - + if(xAxis >= 31 && xAxis <= 43 && yAxis >= 21 && yAxis <= 33) { drawHoveringText(LangUtils.localize("gui.lastItem"), xAxis, yAxis); } - + if(xAxis >= 63 && xAxis <= 75 && yAxis >= 21 && yAxis <= 33) { drawHoveringText(LangUtils.localize("gui.nextItem"), xAxis, yAxis); } - + if(xAxis >= 33 && xAxis <= 129 && yAxis >= 48 && yAxis <= 60) { drawHoveringText(LangUtils.localize("gui.oreDictCompat"), xAxis, yAxis); } - + if(xAxis >= 45 && xAxis <= 61 && yAxis >= 19 && yAxis <= 35) { if(!renderStack.isEmpty()) { String name = ItemRegistryUtils.getMod(renderStack); String extra = name.equals("null") ? "" : " (" + name + ")"; - + drawHoveringText(renderStack.getDisplayName() + extra, xAxis, yAxis); } } @@ -218,7 +218,7 @@ public class GuiOredictionificatorFilter extends GuiMekanism else { drawTexturedModalRect(guiWidth + 31, guiHeight + 21, 176 + 24, 12, 12, 12); } - + if(xAxis >= 63 && xAxis <= 75 && yAxis >= 21 && yAxis <= 33) { drawTexturedModalRect(guiWidth + 63, guiHeight + 21, 176 + 12, 0, 12, 12); @@ -226,7 +226,7 @@ public class GuiOredictionificatorFilter extends GuiMekanism else { drawTexturedModalRect(guiWidth + 63, guiHeight + 21, 176 + 12, 12, 12, 12); } - + if(xAxis >= 130 && xAxis <= 142 && yAxis >= 48 && yAxis <= 60) { drawTexturedModalRect(guiWidth + 130, guiHeight + 48, 176, 0, 12, 12); @@ -237,7 +237,7 @@ public class GuiOredictionificatorFilter extends GuiMekanism filterText.drawTextBox(); } - + @Override public void keyTyped(char c, int i) throws IOException { @@ -257,12 +257,12 @@ public class GuiOredictionificatorFilter extends GuiMekanism filterText.textboxKeyTyped(c, i); } } - + @Override protected void actionPerformed(GuiButton guibutton) throws IOException { super.actionPerformed(guibutton); - + if(guibutton.id == 0) { if(!filterText.getText().isEmpty()) @@ -289,7 +289,7 @@ public class GuiOredictionificatorFilter extends GuiMekanism Mekanism.packetHandler.sendToServer(new SimpleGuiMessage(Coord4D.get(tileEntity), 0, 52)); } } - + @Override public void updateScreen() { @@ -297,14 +297,14 @@ public class GuiOredictionificatorFilter extends GuiMekanism filterText.updateCursorCounter(); } - + @Override protected void mouseClicked(int mouseX, int mouseY, int button) throws IOException { super.mouseClicked(mouseX, mouseY, button); filterText.mouseClicked(mouseX, mouseY, button); - + if(button == 0) { int xAxis = (mouseX - (width - xSize) / 2); @@ -312,24 +312,24 @@ public class GuiOredictionificatorFilter extends GuiMekanism if(xAxis >= 5 && xAxis <= 16 && yAxis >= 5 && yAxis <= 16) { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); + SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); Mekanism.packetHandler.sendToServer(new SimpleGuiMessage(Coord4D.get(tileEntity), 0, 52)); } - + if(xAxis >= 130 && xAxis <= 142 && yAxis >= 48 && yAxis <= 60) { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); + SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); setFilter(); } if(xAxis >= 31 && xAxis <= 43 && yAxis >= 21 && yAxis <= 33) { SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); - + if(filter.filter != null) { List ores = OreDictionary.getOres(filter.filter); - + if(filter.index > 0) { filter.index--; @@ -337,19 +337,19 @@ public class GuiOredictionificatorFilter extends GuiMekanism else { filter.index = ores.size()-1; } - + updateRenderStack(); } } - + if(xAxis >= 63 && xAxis <= 75 && yAxis >= 21 && yAxis <= 33) { SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); - + if(filter.filter != null) { List ores = OreDictionary.getOres(filter.filter); - + if(filter.index < ores.size()-1) { filter.index++; @@ -357,13 +357,13 @@ public class GuiOredictionificatorFilter extends GuiMekanism else { filter.index = 0; } - + updateRenderStack(); } } } } - + public void updateRenderStack() { if(filter.filter == null || filter.filter.isEmpty()) @@ -371,15 +371,15 @@ public class GuiOredictionificatorFilter extends GuiMekanism renderStack = ItemStack.EMPTY; return; } - + List stacks = OreDictionary.getOres(filter.filter); - + if(stacks.isEmpty()) { renderStack = ItemStack.EMPTY; return; } - + if(stacks.size()-1 >= filter.index) { renderStack = stacks.get(filter.index).copy(); @@ -389,4 +389,4 @@ public class GuiOredictionificatorFilter extends GuiMekanism return; } } -} +} \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/GuiRobitCrafting.java b/src/main/java/mekanism/client/gui/GuiRobitCrafting.java deleted file mode 100644 index 2fdc0d65a..000000000 --- a/src/main/java/mekanism/client/gui/GuiRobitCrafting.java +++ /dev/null @@ -1,137 +0,0 @@ -package mekanism.client.gui; - -import java.io.IOException; - -import mekanism.client.sound.SoundHandler; -import mekanism.common.Mekanism; -import mekanism.common.entity.EntityRobit; -import mekanism.common.inventory.container.ContainerRobitCrafting; -import mekanism.common.network.PacketRobit.RobitMessage; -import mekanism.common.network.PacketRobit.RobitPacketType; -import mekanism.common.util.LangUtils; -import mekanism.common.util.MekanismUtils; -import mekanism.common.util.MekanismUtils.ResourceType; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.init.SoundEvents; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - -import org.lwjgl.opengl.GL11; - -@SideOnly(Side.CLIENT) -public class GuiRobitCrafting extends GuiMekanism -{ - public EntityRobit robit; - - public GuiRobitCrafting(InventoryPlayer inventory, EntityRobit entity) - { - super(new ContainerRobitCrafting(inventory, entity)); - robit = entity; - xSize += 25; - } - - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) - { - fontRenderer.drawString(LangUtils.localize("gui.robit.crafting"), 8, 6, 0x404040); - fontRenderer.drawString(LangUtils.localize("container.inventory"), 8, ySize - 96 + 3, 0x404040); - - super.drawGuiContainerForegroundLayer(mouseX, mouseY); - } - - @Override - protected void drawGuiContainerBackgroundLayer(float partialTick, int mouseX, int mouseY) - { - super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY); - - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - mc.renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.GUI, "GuiRobitCrafting.png")); - int guiWidth = (width - xSize) / 2; - int guiHeight = (height - ySize) / 2; - drawTexturedModalRect(guiWidth, guiHeight, 0, 0, xSize, ySize); - - int xAxis = (mouseX - (width - xSize) / 2); - int yAxis = (mouseY - (height - ySize) / 2); - - if(xAxis >= 179 && xAxis <= 197 && yAxis >= 10 && yAxis <= 28) - { - drawTexturedModalRect(guiWidth + 179, guiHeight + 10, 176 + 25, 0, 18, 18); - } - else { - drawTexturedModalRect(guiWidth + 179, guiHeight + 10, 176 + 25, 18, 18, 18); - } - - if(xAxis >= 179 && xAxis <= 197 && yAxis >= 30 && yAxis <= 48) - { - drawTexturedModalRect(guiWidth + 179, guiHeight + 30, 176 + 25, 36, 18, 18); - } - else { - drawTexturedModalRect(guiWidth + 179, guiHeight + 30, 176 + 25, 54, 18, 18); - } - - if(xAxis >= 179 && xAxis <= 197 && yAxis >= 50 && yAxis <= 68) - { - drawTexturedModalRect(guiWidth + 179, guiHeight + 50, 176 + 25, 72, 18, 18); - } - else { - drawTexturedModalRect(guiWidth + 179, guiHeight + 50, 176 + 25, 90, 18, 18); - } - - if(xAxis >= 179 && xAxis <= 197 && yAxis >= 70 && yAxis <= 88) - { - drawTexturedModalRect(guiWidth + 179, guiHeight + 70, 176 + 25, 108, 18, 18); - } - else { - drawTexturedModalRect(guiWidth + 179, guiHeight + 70, 176 + 25, 126, 18, 18); - } - - if(xAxis >= 179 && xAxis <= 197 && yAxis >= 90 && yAxis <= 108) - { - drawTexturedModalRect(guiWidth + 179, guiHeight + 90, 176 + 25, 144, 18, 18); - } - else { - drawTexturedModalRect(guiWidth + 179, guiHeight + 90, 176 + 25, 162, 18, 18); - } - } - - @Override - protected void mouseClicked(int mouseX, int mouseY, int button) throws IOException - { - super.mouseClicked(mouseX, mouseY, button); - - if(button == 0) - { - int xAxis = (mouseX - (width - xSize) / 2); - int yAxis = (mouseY - (height - ySize) / 2); - - if(xAxis >= 179 && xAxis <= 197 && yAxis >= 10 && yAxis <= 28) - { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); - Mekanism.packetHandler.sendToServer(new RobitMessage(RobitPacketType.GUI, 0, robit.getEntityId(), null)); - mc.player.openGui(Mekanism.instance, 21, mc.world, robit.getEntityId(), 0, 0); - } - else if(xAxis >= 179 && xAxis <= 197 && yAxis >= 30 && yAxis <= 48) - { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); - } - else if(xAxis >= 179 && xAxis <= 197 && yAxis >= 50 && yAxis <= 68) - { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); - Mekanism.packetHandler.sendToServer(new RobitMessage(RobitPacketType.GUI, 2, robit.getEntityId(), null)); - mc.player.openGui(Mekanism.instance, 23, mc.world, robit.getEntityId(), 0, 0); - } - else if(xAxis >= 179 && xAxis <= 197 && yAxis >= 70 && yAxis <= 88) - { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); - Mekanism.packetHandler.sendToServer(new RobitMessage(RobitPacketType.GUI, 3, robit.getEntityId(), null)); - mc.player.openGui(Mekanism.instance, 24, mc.world, robit.getEntityId(), 0, 0); - } - else if(xAxis >= 179 && xAxis <= 197 && yAxis >= 90 && yAxis <= 108) - { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); - Mekanism.packetHandler.sendToServer(new RobitMessage(RobitPacketType.GUI, 4, robit.getEntityId(), null)); - mc.player.openGui(Mekanism.instance, 25, mc.world, robit.getEntityId(), 0, 0); - } - } - } -} diff --git a/src/main/java/mekanism/client/gui/GuiRobitInventory.java b/src/main/java/mekanism/client/gui/GuiRobitInventory.java deleted file mode 100644 index 6aaf741db..000000000 --- a/src/main/java/mekanism/client/gui/GuiRobitInventory.java +++ /dev/null @@ -1,137 +0,0 @@ -package mekanism.client.gui; - -import java.io.IOException; - -import mekanism.client.sound.SoundHandler; -import mekanism.common.Mekanism; -import mekanism.common.entity.EntityRobit; -import mekanism.common.inventory.container.ContainerRobitInventory; -import mekanism.common.network.PacketRobit.RobitMessage; -import mekanism.common.network.PacketRobit.RobitPacketType; -import mekanism.common.util.LangUtils; -import mekanism.common.util.MekanismUtils; -import mekanism.common.util.MekanismUtils.ResourceType; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.init.SoundEvents; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - -import org.lwjgl.opengl.GL11; - -@SideOnly(Side.CLIENT) -public class GuiRobitInventory extends GuiMekanism -{ - public EntityRobit robit; - - public GuiRobitInventory(InventoryPlayer inventory, EntityRobit entity) - { - super(new ContainerRobitInventory(inventory, entity)); - xSize += 25; - robit = entity; - } - - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) - { - fontRenderer.drawString(LangUtils.localize("gui.robit.inventory"), 8, 6, 0x404040); - fontRenderer.drawString(LangUtils.localize("container.inventory"), 8, ySize - 96 + 3, 0x404040); - - super.drawGuiContainerForegroundLayer(mouseX, mouseY); - } - - @Override - protected void drawGuiContainerBackgroundLayer(float partialTick, int mouseX, int mouseY) - { - super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY); - - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - mc.renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.GUI, "GuiRobitInventory.png")); - int guiWidth = (width - xSize) / 2; - int guiHeight = (height - ySize) / 2; - drawTexturedModalRect(guiWidth, guiHeight, 0, 0, xSize, ySize); - - int xAxis = (mouseX - (width - xSize) / 2); - int yAxis = (mouseY - (height - ySize) / 2); - - if(xAxis >= 179 && xAxis <= 197 && yAxis >= 10 && yAxis <= 28) - { - drawTexturedModalRect(guiWidth + 179, guiHeight + 10, 176 + 25, 0, 18, 18); - } - else { - drawTexturedModalRect(guiWidth + 179, guiHeight + 10, 176 + 25, 18, 18, 18); - } - - if(xAxis >= 179 && xAxis <= 197 && yAxis >= 30 && yAxis <= 48) - { - drawTexturedModalRect(guiWidth + 179, guiHeight + 30, 176 + 25, 36, 18, 18); - } - else { - drawTexturedModalRect(guiWidth + 179, guiHeight + 30, 176 + 25, 54, 18, 18); - } - - if(xAxis >= 179 && xAxis <= 197 && yAxis >= 50 && yAxis <= 68) - { - drawTexturedModalRect(guiWidth + 179, guiHeight + 50, 176 + 25, 72, 18, 18); - } - else { - drawTexturedModalRect(guiWidth + 179, guiHeight + 50, 176 + 25, 90, 18, 18); - } - - if(xAxis >= 179 && xAxis <= 197 && yAxis >= 70 && yAxis <= 88) - { - drawTexturedModalRect(guiWidth + 179, guiHeight + 70, 176 + 25, 108, 18, 18); - } - else { - drawTexturedModalRect(guiWidth + 179, guiHeight + 70, 176 + 25, 126, 18, 18); - } - - if(xAxis >= 179 && xAxis <= 197 && yAxis >= 90 && yAxis <= 108) - { - drawTexturedModalRect(guiWidth + 179, guiHeight + 90, 176 + 25, 144, 18, 18); - } - else { - drawTexturedModalRect(guiWidth + 179, guiHeight + 90, 176 + 25, 162, 18, 18); - } - } - - @Override - protected void mouseClicked(int mouseX, int mouseY, int button) throws IOException - { - super.mouseClicked(mouseX, mouseY, button); - - if(button == 0) - { - int xAxis = (mouseX - (width - xSize) / 2); - int yAxis = (mouseY - (height - ySize) / 2); - - if(xAxis >= 179 && xAxis <= 197 && yAxis >= 10 && yAxis <= 28) - { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); - Mekanism.packetHandler.sendToServer(new RobitMessage(RobitPacketType.GUI, 0, robit.getEntityId(), null)); - mc.player.openGui(Mekanism.instance, 21, mc.world, robit.getEntityId(), 0, 0); - } - else if(xAxis >= 179 && xAxis <= 197 && yAxis >= 30 && yAxis <= 48) - { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); - Mekanism.packetHandler.sendToServer(new RobitMessage(RobitPacketType.GUI, 1, robit.getEntityId(), null)); - mc.player.openGui(Mekanism.instance, 22, mc.world, robit.getEntityId(), 0, 0); - } - else if(xAxis >= 179 && xAxis <= 197 && yAxis >= 50 && yAxis <= 68) - { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); - } - else if(xAxis >= 179 && xAxis <= 197 && yAxis >= 70 && yAxis <= 88) - { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); - Mekanism.packetHandler.sendToServer(new RobitMessage(RobitPacketType.GUI, 3, robit.getEntityId(), null)); - mc.player.openGui(Mekanism.instance, 24, mc.world, robit.getEntityId(), 0, 0); - } - else if(xAxis >= 179 && xAxis <= 197 && yAxis >= 90 && yAxis <= 108) - { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); - Mekanism.packetHandler.sendToServer(new RobitMessage(RobitPacketType.GUI, 4, robit.getEntityId(), null)); - mc.player.openGui(Mekanism.instance, 25, mc.world, robit.getEntityId(), 0, 0); - } - } - } -} diff --git a/src/main/java/mekanism/client/gui/GuiRobitRepair.java b/src/main/java/mekanism/client/gui/GuiRobitRepair.java deleted file mode 100644 index 88e493dd2..000000000 --- a/src/main/java/mekanism/client/gui/GuiRobitRepair.java +++ /dev/null @@ -1,285 +0,0 @@ -package mekanism.client.gui; - -import io.netty.buffer.Unpooled; - -import java.io.IOException; - -import mekanism.client.sound.SoundHandler; -import mekanism.common.Mekanism; -import mekanism.common.entity.EntityRobit; -import mekanism.common.inventory.container.ContainerRobitRepair; -import mekanism.common.network.PacketRobit.RobitMessage; -import mekanism.common.network.PacketRobit.RobitPacketType; -import mekanism.common.util.LangUtils; -import mekanism.common.util.MekanismUtils; -import mekanism.common.util.MekanismUtils.ResourceType; -import net.minecraft.client.gui.GuiTextField; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.init.SoundEvents; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.ContainerRepair; -import net.minecraft.inventory.IContainerListener; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.network.PacketBuffer; -import net.minecraft.network.play.client.CPacketCustomPayload; -import net.minecraft.util.NonNullList; -import net.minecraft.util.text.translation.I18n; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - -import org.lwjgl.input.Keyboard; -import org.lwjgl.opengl.GL11; - -import javax.annotation.Nonnull; - -@SideOnly(Side.CLIENT) -public class GuiRobitRepair extends GuiMekanism implements IContainerListener -{ - private EntityRobit robit; - private ContainerRepair repairContainer; - private GuiTextField itemNameField; - private InventoryPlayer playerInventory; - - public GuiRobitRepair(InventoryPlayer inventory, EntityRobit entity) - { - super(new ContainerRobitRepair(inventory, entity)); - robit = entity; - xSize += 25; - playerInventory = inventory; - repairContainer = (ContainerRobitRepair)inventorySlots; - } - - @Override - public void initGui() - { - super.initGui(); - Keyboard.enableRepeatEvents(true); - - int i = (width - xSize) / 2; - int j = (height - ySize) / 2; - - itemNameField = new GuiTextField(0, fontRenderer, i + 62, j + 24, 103, 12); - itemNameField.setTextColor(-1); - itemNameField.setDisabledTextColour(-1); - itemNameField.setEnableBackgroundDrawing(false); - itemNameField.setMaxStringLength(30); - inventorySlots.removeListener(this); - inventorySlots.addListener(this); - } - - @Override - public void onGuiClosed() - { - super.onGuiClosed(); - Keyboard.enableRepeatEvents(false); - inventorySlots.removeListener(this); - } - - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) - { - GL11.glDisable(GL11.GL_LIGHTING); - fontRenderer.drawString(LangUtils.localize("container.repair"), 60, 6, 4210752); - - if(repairContainer.maximumCost > 0) - { - int k = 8453920; - boolean flag = true; - String s = I18n.translateToLocalFormatted("container.repair.cost", repairContainer.maximumCost); - - if(repairContainer.maximumCost >= 40 && !mc.player.capabilities.isCreativeMode) - { - s = LangUtils.localize("container.repair.expensive"); - k = 16736352; - } - else if(!repairContainer.getSlot(2).getHasStack()) - { - flag = false; - } - else if(!repairContainer.getSlot(2).canTakeStack(playerInventory.player)) - { - k = 16736352; - } - - if(flag) - { - int l = -16777216 | (k & 16579836) >> 2 | k & -16777216; - int i1 = (xSize - 25) - 8 - fontRenderer.getStringWidth(s); - byte b0 = 67; - - if(fontRenderer.getUnicodeFlag()) - { - drawRect(i1 - 3, b0 - 2, (xSize - 25) - 7, b0 + 10, -16777216); - drawRect(i1 - 2, b0 - 1, (xSize - 25) - 8, b0 + 9, -12895429); - } - else { - fontRenderer.drawString(s, i1, b0 + 1, l); - fontRenderer.drawString(s, i1 + 1, b0, l); - fontRenderer.drawString(s, i1 + 1, b0 + 1, l); - } - - fontRenderer.drawString(s, i1, b0, k); - } - } - - GL11.glEnable(GL11.GL_LIGHTING); - - super.drawGuiContainerForegroundLayer(mouseX, mouseY); - } - - @Override - protected void keyTyped(char c, int i) throws IOException - { - if(itemNameField.textboxKeyTyped(c, i)) - { - repairContainer.updateItemName(itemNameField.getText()); - mc.player.connection.sendPacket(new CPacketCustomPayload("MC|ItemName", (new PacketBuffer(Unpooled.buffer())).writeString(itemNameField.getText()))); - } - else { - super.keyTyped(c, i); - } - } - - @Override - protected void mouseClicked(int mouseX, int mouseY, int button) throws IOException - { - super.mouseClicked(mouseX, mouseY, button); - - itemNameField.mouseClicked(mouseX, mouseY, button); - - if(button == 0) - { - int xAxis = (mouseX - (width - xSize) / 2); - int yAxis = (mouseY - (height - ySize) / 2); - - if(xAxis >= 179 && xAxis <= 197 && yAxis >= 10 && yAxis <= 28) - { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); - Mekanism.packetHandler.sendToServer(new RobitMessage(RobitPacketType.GUI, 0, robit.getEntityId(), null)); - mc.player.openGui(Mekanism.instance, 21, mc.world, robit.getEntityId(), 0, 0); - } - else if(xAxis >= 179 && xAxis <= 197 && yAxis >= 30 && yAxis <= 48) - { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); - Mekanism.packetHandler.sendToServer(new RobitMessage(RobitPacketType.GUI, 1, robit.getEntityId(), null)); - mc.player.openGui(Mekanism.instance, 22, mc.world, robit.getEntityId(), 0, 0); - } - else if(xAxis >= 179 && xAxis <= 197 && yAxis >= 50 && yAxis <= 68) - { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); - Mekanism.packetHandler.sendToServer(new RobitMessage(RobitPacketType.GUI, 2, robit.getEntityId(), null)); - mc.player.openGui(Mekanism.instance, 23, mc.world, robit.getEntityId(), 0, 0); - } - else if(xAxis >= 179 && xAxis <= 197 && yAxis >= 70 && yAxis <= 88) - { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); - Mekanism.packetHandler.sendToServer(new RobitMessage(RobitPacketType.GUI, 3, robit.getEntityId(), null)); - mc.player.openGui(Mekanism.instance, 24, mc.world, robit.getEntityId(), 0, 0); - } - else if(xAxis >= 179 && xAxis <= 197 && yAxis >= 90 && yAxis <= 108) - { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); - } - } - } - - @Override - public void drawScreen(int mouseX, int mouseY, float partialTick) - { - super.drawScreen(mouseX, mouseY, partialTick); - - GL11.glDisable(GL11.GL_LIGHTING); - itemNameField.drawTextBox(); - } - - @Override - protected void drawGuiContainerBackgroundLayer(float partialTick, int mouseX, int mouseY) - { - super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY); - - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - mc.renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.GUI, "GuiRobitRepair.png")); - int guiWidth = (width - xSize) / 2; - int guiHeight = (height - ySize) / 2; - drawTexturedModalRect(guiWidth, guiHeight, 0, 0, xSize, ySize); - - int xAxis = (mouseX - (width - xSize) / 2); - int yAxis = (mouseY - (height - ySize) / 2); - - if(xAxis >= 179 && xAxis <= 197 && yAxis >= 10 && yAxis <= 28) - { - drawTexturedModalRect(guiWidth + 179, guiHeight + 10, 176 + 25, 0, 18, 18); - } - else { - drawTexturedModalRect(guiWidth + 179, guiHeight + 10, 176 + 25, 18, 18, 18); - } - - if(xAxis >= 179 && xAxis <= 197 && yAxis >= 30 && yAxis <= 48) - { - drawTexturedModalRect(guiWidth + 179, guiHeight + 30, 176 + 25, 36, 18, 18); - } - else { - drawTexturedModalRect(guiWidth + 179, guiHeight + 30, 176 + 25, 54, 18, 18); - } - - if(xAxis >= 179 && xAxis <= 197 && yAxis >= 50 && yAxis <= 68) - { - drawTexturedModalRect(guiWidth + 179, guiHeight + 50, 176 + 25, 72, 18, 18); - } - else { - drawTexturedModalRect(guiWidth + 179, guiHeight + 50, 176 + 25, 90, 18, 18); - } - - if(xAxis >= 179 && xAxis <= 197 && yAxis >= 70 && yAxis <= 88) - { - drawTexturedModalRect(guiWidth + 179, guiHeight + 70, 176 + 25, 108, 18, 18); - } - else { - drawTexturedModalRect(guiWidth + 179, guiHeight + 70, 176 + 25, 126, 18, 18); - } - - if(xAxis >= 179 && xAxis <= 197 && yAxis >= 90 && yAxis <= 108) - { - drawTexturedModalRect(guiWidth + 179, guiHeight + 90, 176 + 25, 144, 18, 18); - } - else { - drawTexturedModalRect(guiWidth + 179, guiHeight + 90, 176 + 25, 162, 18, 18); - } - - drawTexturedModalRect(guiWidth + 59, guiHeight + 20, 0, ySize + (repairContainer.getSlot(0).getHasStack() ? 0 : 16), 110, 16); - - if((repairContainer.getSlot(0).getHasStack() || repairContainer.getSlot(1).getHasStack()) && !repairContainer.getSlot(2).getHasStack()) - { - drawTexturedModalRect(guiWidth + 99, guiHeight + 45, xSize + 18, 36, 28, 21); - } - } - - @Override - public void sendAllContents(@Nonnull Container container, @Nonnull NonNullList list) - { - sendSlotContents(container, 0, container.getSlot(0).getStack()); - } - - @Override - public void sendSlotContents(@Nonnull Container container, int slotID, @Nonnull ItemStack itemstack) - { - if(slotID == 0) - { - itemNameField.setText(itemstack.isEmpty() ? "" : itemstack.getDisplayName()); - itemNameField.setEnabled(!itemstack.isEmpty()); - - if(!itemstack.isEmpty()) - { - repairContainer.updateItemName(itemNameField.getText()); - mc.player.connection.sendPacket(new CPacketCustomPayload("MC|ItemName", (new PacketBuffer(Unpooled.buffer())).writeString(itemNameField.getText()))); - } - } - } - - @Override - public void sendWindowProperty(@Nonnull Container par1Container, int par2, int par3) {} - - @Override - public void sendAllWindowProperties(@Nonnull Container p_175173_1_, @Nonnull IInventory p_175173_2_) {} -} diff --git a/src/main/java/mekanism/client/gui/GuiRobitSmelting.java b/src/main/java/mekanism/client/gui/GuiRobitSmelting.java deleted file mode 100644 index 47789112e..000000000 --- a/src/main/java/mekanism/client/gui/GuiRobitSmelting.java +++ /dev/null @@ -1,160 +0,0 @@ -package mekanism.client.gui; - -import java.io.IOException; - -import mekanism.client.sound.SoundHandler; -import mekanism.common.Mekanism; -import mekanism.common.entity.EntityRobit; -import mekanism.common.inventory.container.ContainerRobitSmelting; -import mekanism.common.network.PacketRobit.RobitMessage; -import mekanism.common.network.PacketRobit.RobitPacketType; -import mekanism.common.util.LangUtils; -import mekanism.common.util.MekanismUtils; -import mekanism.common.util.MekanismUtils.ResourceType; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.init.SoundEvents; - -import org.lwjgl.opengl.GL11; - -public class GuiRobitSmelting extends GuiMekanism -{ - public EntityRobit robit; - - public GuiRobitSmelting(InventoryPlayer inventory, EntityRobit entity) - { - super(new ContainerRobitSmelting(inventory, entity)); - robit = entity; - xSize += 25; - } - - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) - { - fontRenderer.drawString(LangUtils.localize("gui.robit.smelting"), 8, 6, 0x404040); - fontRenderer.drawString(LangUtils.localize("container.inventory"), 8, ySize - 96 + 3, 0x404040); - - super.drawGuiContainerForegroundLayer(mouseX, mouseY); - } - - @Override - protected void drawGuiContainerBackgroundLayer(float partialTick, int mouseX, int mouseY) - { - super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY); - - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - mc.renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.GUI, "GuiRobitSmelting.png")); - int guiWidth = (width - xSize) / 2; - int guiHeight = (height - ySize) / 2; - drawTexturedModalRect(guiWidth, guiHeight, 0, 0, xSize, ySize); - - int xAxis = (mouseX - (width - xSize) / 2); - int yAxis = (mouseY - (height - ySize) / 2); - - if(xAxis >= 179 && xAxis <= 197 && yAxis >= 10 && yAxis <= 28) - { - drawTexturedModalRect(guiWidth + 179, guiHeight + 10, 176 + 25, 0, 18, 18); - } - else { - drawTexturedModalRect(guiWidth + 179, guiHeight + 10, 176 + 25, 18, 18, 18); - } - - if(xAxis >= 179 && xAxis <= 197 && yAxis >= 30 && yAxis <= 48) - { - drawTexturedModalRect(guiWidth + 179, guiHeight + 30, 176 + 25, 36, 18, 18); - } - else { - drawTexturedModalRect(guiWidth + 179, guiHeight + 30, 176 + 25, 54, 18, 18); - } - - if(xAxis >= 179 && xAxis <= 197 && yAxis >= 50 && yAxis <= 68) - { - drawTexturedModalRect(guiWidth + 179, guiHeight + 50, 176 + 25, 72, 18, 18); - } - else { - drawTexturedModalRect(guiWidth + 179, guiHeight + 50, 176 + 25, 90, 18, 18); - } - - if(xAxis >= 179 && xAxis <= 197 && yAxis >= 70 && yAxis <= 88) - { - drawTexturedModalRect(guiWidth + 179, guiHeight + 70, 176 + 25, 108, 18, 18); - } - else { - drawTexturedModalRect(guiWidth + 179, guiHeight + 70, 176 + 25, 126, 18, 18); - } - - if(xAxis >= 179 && xAxis <= 197 && yAxis >= 90 && yAxis <= 108) - { - drawTexturedModalRect(guiWidth + 179, guiHeight + 90, 176 + 25, 144, 18, 18); - } - else { - drawTexturedModalRect(guiWidth + 179, guiHeight + 90, 176 + 25, 162, 18, 18); - } - - int displayInt; - - if(robit.furnaceBurnTime > 0) - { - displayInt = getBurnTimeRemainingScaled(12); - drawTexturedModalRect(guiWidth + 56, guiHeight + 36 + 12 - displayInt, 176 + 25 + 18, 36 + 12 - displayInt, 14, displayInt + 2); - } - - displayInt = getCookProgressScaled(24); - drawTexturedModalRect(guiWidth + 79, guiHeight + 34, 176 + 25 + 18, 36 + 14, displayInt + 1, 16); - } - - @Override - protected void mouseClicked(int mouseX, int mouseY, int button) throws IOException - { - super.mouseClicked(mouseX, mouseY, button); - - if(button == 0) - { - int xAxis = (mouseX - (width - xSize) / 2); - int yAxis = (mouseY - (height - ySize) / 2); - - if(xAxis >= 179 && xAxis <= 197 && yAxis >= 10 && yAxis <= 28) - { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); - Mekanism.packetHandler.sendToServer(new RobitMessage(RobitPacketType.GUI, 0, robit.getEntityId(), null)); - mc.player.openGui(Mekanism.instance, 21, mc.world, robit.getEntityId(), 0, 0); - } - else if(xAxis >= 179 && xAxis <= 197 && yAxis >= 30 && yAxis <= 48) - { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); - Mekanism.packetHandler.sendToServer(new RobitMessage(RobitPacketType.GUI, 1, robit.getEntityId(), null)); - mc.player.openGui(Mekanism.instance, 22, mc.world, robit.getEntityId(), 0, 0); - } - else if(xAxis >= 179 && xAxis <= 197 && yAxis >= 50 && yAxis <= 68) - { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); - Mekanism.packetHandler.sendToServer(new RobitMessage(RobitPacketType.GUI, 2, robit.getEntityId(), null)); - mc.player.openGui(Mekanism.instance, 23, mc.world, robit.getEntityId(), 0, 0); - } - else if(xAxis >= 179 && xAxis <= 197 && yAxis >= 70 && yAxis <= 88) - { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); - } - else if(xAxis >= 179 && xAxis <= 197 && yAxis >= 90 && yAxis <= 108) - { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); - Mekanism.packetHandler.sendToServer(new RobitMessage(RobitPacketType.GUI, 4, robit.getEntityId(), null)); - mc.player.openGui(Mekanism.instance, 25, mc.world, robit.getEntityId(), 0, 0); - } - } - } - - private int getCookProgressScaled(int i) - { - return robit.furnaceCookTime * i / 200; - } - - private int getBurnTimeRemainingScaled(int i) - { - if(robit.currentItemBurnTime == 0) - { - robit.currentItemBurnTime = 200; - } - - return robit.furnaceBurnTime * i / robit.currentItemBurnTime; - } -} diff --git a/src/main/java/mekanism/client/gui/GuiTFilterSelect.java b/src/main/java/mekanism/client/gui/GuiTFilterSelect.java index 8fcb789c6..98b39d52e 100644 --- a/src/main/java/mekanism/client/gui/GuiTFilterSelect.java +++ b/src/main/java/mekanism/client/gui/GuiTFilterSelect.java @@ -24,14 +24,14 @@ import org.lwjgl.opengl.GL11; public class GuiTFilterSelect extends GuiMekanism { public TileEntityLogisticalSorter tileEntity; - + public GuiTFilterSelect(EntityPlayer player, TileEntityLogisticalSorter tentity) { super(tentity, new ContainerNull(player, tentity)); - + tileEntity = tentity; } - + @Override public void initGui() { @@ -39,14 +39,14 @@ public class GuiTFilterSelect extends GuiMekanism int guiWidth = (width - xSize) / 2; int guiHeight = (height - ySize) / 2; - + buttonList.clear(); buttonList.add(new GuiButton(0, guiWidth + 24, guiHeight + 32, 128, 20, LangUtils.localize("gui.itemstack"))); buttonList.add(new GuiButton(1, guiWidth + 24, guiHeight + 52, 128, 20, LangUtils.localize("gui.oredict"))); buttonList.add(new GuiButton(2, guiWidth + 24, guiHeight + 72, 128, 20, LangUtils.localize("gui.material"))); buttonList.add(new GuiButton(3, guiWidth + 24, guiHeight + 92, 128, 20, LangUtils.localize("gui.modID"))); } - + @Override protected void actionPerformed(GuiButton guibutton) throws IOException { @@ -69,7 +69,7 @@ public class GuiTFilterSelect extends GuiMekanism Mekanism.packetHandler.sendToServer(new LogisticalSorterGuiMessage(SorterGuiPacket.SERVER, Coord4D.get(tileEntity), 5, 0, 0)); } } - + @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { @@ -77,10 +77,10 @@ public class GuiTFilterSelect extends GuiMekanism int yAxis = (mouseY - (height - ySize) / 2); fontRenderer.drawString(LangUtils.localize("gui.filterSelect.title"), 43, 6, 0x404040); - + super.drawGuiContainerForegroundLayer(mouseX, mouseY); } - + @Override protected void drawGuiContainerBackgroundLayer(float partialTick, int mouseX, int mouseY) { @@ -103,22 +103,22 @@ public class GuiTFilterSelect extends GuiMekanism drawTexturedModalRect(guiWidth + 5, guiHeight + 5, 176, 11, 11, 11); } } - + @Override public void mouseClicked(int mouseX, int mouseY, int button) throws IOException { super.mouseClicked(mouseX, mouseY, button); - + if(button == 0) { int xAxis = (mouseX - (width - xSize) / 2); int yAxis = (mouseY - (height - ySize) / 2); - + if(xAxis >= 5 && xAxis <= 16 && yAxis >= 5 && yAxis <= 16) { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); + SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); Mekanism.packetHandler.sendToServer(new LogisticalSorterGuiMessage(SorterGuiPacket.SERVER, Coord4D.get(tileEntity), 0, 0, 0)); } } } -} +} \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/GuiTItemStackFilter.java b/src/main/java/mekanism/client/gui/GuiTItemStackFilter.java index e333338a9..f42c9eda3 100644 --- a/src/main/java/mekanism/client/gui/GuiTItemStackFilter.java +++ b/src/main/java/mekanism/client/gui/GuiTItemStackFilter.java @@ -203,12 +203,12 @@ public class GuiTItemStackFilter extends GuiMekanism GL11.glDisable(GL11.GL_LIGHTING); GlStateManager.popMatrix(); } - + if(xAxis >= 128 && xAxis <= 139 && yAxis >= 44 && yAxis <= 55) { drawHoveringText(LangUtils.localize("gui.sizeMode"), xAxis, yAxis); } - + if(xAxis >= 11 && xAxis <= 22 && yAxis >= 64 && yAxis <= 75) { drawHoveringText(LangUtils.localize("gui.allowDefault"), xAxis, yAxis); @@ -272,7 +272,7 @@ public class GuiTItemStackFilter extends GuiMekanism else { drawTexturedModalRect(guiWidth + 128, guiHeight + 44, 187, 11, 11, 11); } - + if(xAxis >= 11 && xAxis <= 22 && yAxis >= 64 && yAxis <= 75) { drawTexturedModalRect(guiWidth + 11, guiHeight + 64, 198, 0, 11, 11); @@ -300,7 +300,7 @@ public class GuiTItemStackFilter extends GuiMekanism GlStateManager.enableDepth(); GlStateManager.popMatrix(); } - + super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY); } @@ -319,7 +319,7 @@ public class GuiTItemStackFilter extends GuiMekanism { if(xAxis >= 5 && xAxis <= 16 && yAxis >= 5 && yAxis <= 16) { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); + SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); Mekanism.packetHandler.sendToServer(new LogisticalSorterGuiMessage(SorterGuiPacket.SERVER, Coord4D.get(tileEntity), isNew ? 4 : 0, 0, 0)); } @@ -337,15 +337,15 @@ public class GuiTItemStackFilter extends GuiMekanism filter.itemType = ItemStack.EMPTY; } - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); + SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); } if(xAxis >= 128 && xAxis <= 139 && yAxis >= 44 && yAxis <= 55) { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); + SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); filter.sizeMode = !filter.sizeMode; } - + if(xAxis >= 11 && xAxis <= 22 && yAxis >= 64 && yAxis <= 75) { SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); @@ -376,4 +376,4 @@ public class GuiTItemStackFilter extends GuiMekanism } } } -} +} \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/GuiTMaterialFilter.java b/src/main/java/mekanism/client/gui/GuiTMaterialFilter.java index 3cd9b5e5a..bfa05e411 100644 --- a/src/main/java/mekanism/client/gui/GuiTMaterialFilter.java +++ b/src/main/java/mekanism/client/gui/GuiTMaterialFilter.java @@ -137,7 +137,7 @@ public class GuiTMaterialFilter extends GuiMekanism RenderHelper.disableStandardItemLighting(); GlStateManager.popMatrix(); } - + if(filter.color != null) { GlStateManager.pushMatrix(); @@ -156,7 +156,7 @@ public class GuiTMaterialFilter extends GuiMekanism { drawHoveringText(LangUtils.localize("gui.allowDefault"), xAxis, yAxis); } - + if(xAxis >= 12 && xAxis <= 28 && yAxis >= 44 && yAxis <= 60) { if(filter.color != null) @@ -204,7 +204,7 @@ public class GuiTMaterialFilter extends GuiMekanism else { drawTexturedModalRect(guiWidth + 5, guiHeight + 5, 176, 11, 11, 11); } - + if(xAxis >= 11 && xAxis <= 22 && yAxis >= 64 && yAxis <= 75) { drawTexturedModalRect(guiWidth + 11, guiHeight + 64, 198, 0, 11, 11); @@ -229,7 +229,7 @@ public class GuiTMaterialFilter extends GuiMekanism GlStateManager.enableDepth(); GlStateManager.popMatrix(); } - + super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY); } @@ -237,7 +237,7 @@ public class GuiTMaterialFilter extends GuiMekanism protected void mouseClicked(int mouseX, int mouseY, int button) throws IOException { super.mouseClicked(mouseX, mouseY, button); - + int xAxis = (mouseX - (width - xSize) / 2); int yAxis = (mouseY - (height - ySize) / 2); @@ -245,7 +245,7 @@ public class GuiTMaterialFilter extends GuiMekanism { if(xAxis >= 5 && xAxis <= 16 && yAxis >= 5 && yAxis <= 16) { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); + SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); Mekanism.packetHandler.sendToServer(new LogisticalSorterGuiMessage(SorterGuiPacket.SERVER, Coord4D.get(tileEntity), isNew ? 4 : 0, 0, 0)); } @@ -269,16 +269,16 @@ public class GuiTMaterialFilter extends GuiMekanism filter.materialItem = ItemStack.EMPTY; } - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); + SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); } - + if(xAxis >= 11 && xAxis <= 22 && yAxis >= 64 && yAxis <= 75) { SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); filter.allowDefault = !filter.allowDefault; } } - + if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) && button == 0) { button = 2; @@ -302,4 +302,4 @@ public class GuiTMaterialFilter extends GuiMekanism } } } -} +} \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/GuiTModIDFilter.java b/src/main/java/mekanism/client/gui/GuiTModIDFilter.java index 0a9fbbac4..5890657d4 100644 --- a/src/main/java/mekanism/client/gui/GuiTModIDFilter.java +++ b/src/main/java/mekanism/client/gui/GuiTModIDFilter.java @@ -193,7 +193,7 @@ public class GuiTModIDFilter extends GuiMekanism GL11.glDisable(GL11.GL_LIGHTING); GlStateManager.popMatrix(); } - + if(xAxis >= 11 && xAxis <= 22 && yAxis >= 64 && yAxis <= 75) { drawHoveringText(LangUtils.localize("gui.allowDefault"), xAxis, yAxis); @@ -240,7 +240,7 @@ public class GuiTModIDFilter extends GuiMekanism else { drawTexturedModalRect(guiWidth + 131, guiHeight + 47, 176 + 11, 12, 12, 12); } - + if(xAxis >= 11 && xAxis <= 22 && yAxis >= 64 && yAxis <= 75) { drawTexturedModalRect(guiWidth + 11, guiHeight + 64, 199, 0, 11, 11); @@ -250,7 +250,7 @@ public class GuiTModIDFilter extends GuiMekanism } modIDText.drawTextBox(); - + super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY); } @@ -309,16 +309,16 @@ public class GuiTModIDFilter extends GuiMekanism { if(xAxis >= 5 && xAxis <= 16 && yAxis >= 5 && yAxis <= 16) { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); + SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); Mekanism.packetHandler.sendToServer(new LogisticalSorterGuiMessage(SorterGuiPacket.SERVER, Coord4D.get(tileEntity), isNew ? 4 : 0, 0, 0)); } if(xAxis >= 131 && xAxis <= 143 && yAxis >= 47 && yAxis <= 59) { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); + SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); setModID(); } - + if(xAxis >= 11 && xAxis <= 22 && yAxis >= 64 && yAxis <= 75) { SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); @@ -378,4 +378,4 @@ public class GuiTModIDFilter extends GuiMekanism filter.modID = modName; modIDText.setText(""); } -} +} \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/GuiTOreDictFilter.java b/src/main/java/mekanism/client/gui/GuiTOreDictFilter.java index 3bce9d49a..373242054 100644 --- a/src/main/java/mekanism/client/gui/GuiTOreDictFilter.java +++ b/src/main/java/mekanism/client/gui/GuiTOreDictFilter.java @@ -193,7 +193,7 @@ public class GuiTOreDictFilter extends GuiMekanism GL11.glDisable(GL11.GL_LIGHTING); GlStateManager.popMatrix(); } - + if(xAxis >= 11 && xAxis <= 22 && yAxis >= 64 && yAxis <= 75) { drawHoveringText(LangUtils.localize("gui.allowDefault"), xAxis, yAxis); @@ -240,7 +240,7 @@ public class GuiTOreDictFilter extends GuiMekanism else { drawTexturedModalRect(guiWidth + 131, guiHeight + 47, 176 + 11, 12, 12, 12); } - + if(xAxis >= 11 && xAxis <= 22 && yAxis >= 64 && yAxis <= 75) { drawTexturedModalRect(guiWidth + 11, guiHeight + 64, 199, 0, 11, 11); @@ -250,7 +250,7 @@ public class GuiTOreDictFilter extends GuiMekanism } oreDictText.drawTextBox(); - + super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY); } @@ -309,16 +309,16 @@ public class GuiTOreDictFilter extends GuiMekanism { if(xAxis >= 5 && xAxis <= 16 && yAxis >= 5 && yAxis <= 16) { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); + SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); Mekanism.packetHandler.sendToServer(new LogisticalSorterGuiMessage(SorterGuiPacket.SERVER, Coord4D.get(tileEntity), isNew ? 4 : 0, 0, 0)); } if(xAxis >= 131 && xAxis <= 143 && yAxis >= 47 && yAxis <= 59) { - SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); + SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); setOreDictKey(); } - + if(xAxis >= 11 && xAxis <= 22 && yAxis >= 64 && yAxis <= 75) { SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); @@ -378,4 +378,4 @@ public class GuiTOreDictFilter extends GuiMekanism filter.oreDictName = oreName; oreDictText.setText(""); } -} +} \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/robit/GuiRobit.java b/src/main/java/mekanism/client/gui/robit/GuiRobit.java new file mode 100644 index 000000000..af9908301 --- /dev/null +++ b/src/main/java/mekanism/client/gui/robit/GuiRobit.java @@ -0,0 +1,85 @@ +package mekanism.client.gui.robit; + +import mekanism.client.gui.GuiMekanism; +import mekanism.client.sound.SoundHandler; +import mekanism.common.Mekanism; +import mekanism.common.entity.EntityRobit; +import mekanism.common.network.PacketRobit; +import mekanism.common.util.MekanismUtils; +import net.minecraft.init.SoundEvents; +import net.minecraft.inventory.Container; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import org.lwjgl.opengl.GL11; + +import java.io.IOException; + +@SideOnly(Side.CLIENT) +public abstract class GuiRobit extends GuiMekanism { + public EntityRobit robit; + + protected GuiRobit(EntityRobit robit, Container container) { + super(container); + this.robit = robit; + xSize += 25; + } + + protected abstract String getBackgroundImage(); + + @Override + protected void drawGuiContainerBackgroundLayer(float partialTick, int mouseX, int mouseY) { + super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + mc.renderEngine.bindTexture(MekanismUtils.getResource(MekanismUtils.ResourceType.GUI, getBackgroundImage())); + int guiWidth = (width - xSize) / 2; + int guiHeight = (height - ySize) / 2; + drawTexturedModalRect(guiWidth, guiHeight, 0, 0, xSize, ySize); + int xAxis = (mouseX - (width - xSize) / 2); + int yAxis = (mouseY - (height - ySize) / 2); + boolean correctX = xAxis >= 179 && xAxis <= 197; + drawRect(correctX, yAxis, guiWidth, guiHeight, 10, 0); + drawRect(correctX, yAxis, guiWidth, guiHeight, 30, 36); + drawRect(correctX, yAxis, guiWidth, guiHeight, 50, 72); + drawRect(correctX, yAxis, guiWidth, guiHeight, 70, 108); + drawRect(correctX, yAxis, guiWidth, guiHeight, 90, 144); + } + + private void drawRect(boolean correctX, int yAxis, int guiWidth, int guiHeight, int heightBonus, int textureY) { + int yBonus = correctX && yAxis >= heightBonus && yAxis <= heightBonus + 18 ? 0 : 18; + drawTexturedModalRect(guiWidth + 179, guiHeight + heightBonus, 201, textureY + yBonus, 18, 18); + } + + protected void buttonClicked(int id) { + SoundHandler.playSound(SoundEvents.UI_BUTTON_CLICK); + if (openGui(id)) { + Mekanism.packetHandler.sendToServer(new PacketRobit.RobitMessage(PacketRobit.RobitPacketType.GUI, id, robit.getEntityId(), null)); + mc.player.openGui(Mekanism.instance, 21 + id, mc.world, robit.getEntityId(), 0, 0); + } + } + + protected abstract boolean openGui(int id); + + protected void extraClickListeners(int mouseX, int mouseY, int button) { + } + + @Override + protected void mouseClicked(int mouseX, int mouseY, int button) throws IOException { + super.mouseClicked(mouseX, mouseY, button); + extraClickListeners(mouseX, mouseY, button); + if (button == 0) { + int xAxis = (mouseX - (width - xSize) / 2); + int yAxis = (mouseY - (height - ySize) / 2); + if (xAxis >= 179 && xAxis <= 197 && yAxis >= 10 && yAxis <= 28) { + buttonClicked(0); + } else if (xAxis >= 179 && xAxis <= 197 && yAxis >= 30 && yAxis <= 48) { + buttonClicked(1); + } else if (xAxis >= 179 && xAxis <= 197 && yAxis >= 50 && yAxis <= 68) { + buttonClicked(2); + } else if (xAxis >= 179 && xAxis <= 197 && yAxis >= 70 && yAxis <= 88) { + buttonClicked(3); + } else if (xAxis >= 179 && xAxis <= 197 && yAxis >= 90 && yAxis <= 108) { + buttonClicked(4); + } + } + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/robit/GuiRobitCrafting.java b/src/main/java/mekanism/client/gui/robit/GuiRobitCrafting.java new file mode 100644 index 000000000..c8bef0f41 --- /dev/null +++ b/src/main/java/mekanism/client/gui/robit/GuiRobitCrafting.java @@ -0,0 +1,32 @@ +package mekanism.client.gui.robit; + +import mekanism.common.entity.EntityRobit; +import mekanism.common.inventory.container.ContainerRobitCrafting; +import mekanism.common.util.LangUtils; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class GuiRobitCrafting extends GuiRobit { + public GuiRobitCrafting(InventoryPlayer inventory, EntityRobit entity) { + super(entity, new ContainerRobitCrafting(inventory, entity)); + } + + @Override + protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { + fontRenderer.drawString(LangUtils.localize("gui.robit.crafting"), 8, 6, 0x404040); + fontRenderer.drawString(LangUtils.localize("container.inventory"), 8, ySize - 93, 0x404040); + super.drawGuiContainerForegroundLayer(mouseX, mouseY); + } + + @Override + protected String getBackgroundImage() { + return "GuiRobitCrafting.png"; + } + + @Override + protected boolean openGui(int id) { + return id != 1; + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/robit/GuiRobitInventory.java b/src/main/java/mekanism/client/gui/robit/GuiRobitInventory.java new file mode 100644 index 000000000..c9ac7f1ce --- /dev/null +++ b/src/main/java/mekanism/client/gui/robit/GuiRobitInventory.java @@ -0,0 +1,32 @@ +package mekanism.client.gui.robit; + +import mekanism.common.entity.EntityRobit; +import mekanism.common.inventory.container.ContainerRobitInventory; +import mekanism.common.util.LangUtils; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class GuiRobitInventory extends GuiRobit { + public GuiRobitInventory(InventoryPlayer inventory, EntityRobit entity) { + super(entity, new ContainerRobitInventory(inventory, entity)); + } + + @Override + protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { + fontRenderer.drawString(LangUtils.localize("gui.robit.inventory"), 8, 6, 0x404040); + fontRenderer.drawString(LangUtils.localize("container.inventory"), 8, ySize - 93, 0x404040); + super.drawGuiContainerForegroundLayer(mouseX, mouseY); + } + + @Override + protected String getBackgroundImage() { + return "GuiRobitInventory.png"; + } + + @Override + protected boolean openGui(int id) { + return id != 2; + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/GuiRobitMain.java b/src/main/java/mekanism/client/gui/robit/GuiRobitMain.java similarity index 99% rename from src/main/java/mekanism/client/gui/GuiRobitMain.java rename to src/main/java/mekanism/client/gui/robit/GuiRobitMain.java index c8bc160d4..8a4cb0715 100644 --- a/src/main/java/mekanism/client/gui/GuiRobitMain.java +++ b/src/main/java/mekanism/client/gui/robit/GuiRobitMain.java @@ -1,7 +1,8 @@ -package mekanism.client.gui; +package mekanism.client.gui.robit; import java.io.IOException; +import mekanism.client.gui.GuiMekanism; import mekanism.client.sound.SoundHandler; import mekanism.common.Mekanism; import mekanism.common.entity.EntityRobit; diff --git a/src/main/java/mekanism/client/gui/robit/GuiRobitRepair.java b/src/main/java/mekanism/client/gui/robit/GuiRobitRepair.java new file mode 100644 index 000000000..85df8e1b7 --- /dev/null +++ b/src/main/java/mekanism/client/gui/robit/GuiRobitRepair.java @@ -0,0 +1,169 @@ +package mekanism.client.gui.robit; + +import io.netty.buffer.Unpooled; +import mekanism.common.entity.EntityRobit; +import mekanism.common.inventory.container.ContainerRobitRepair; +import mekanism.common.util.LangUtils; +import net.minecraft.client.gui.GuiTextField; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.ContainerRepair; +import net.minecraft.inventory.IContainerListener; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.network.PacketBuffer; +import net.minecraft.network.play.client.CPacketCustomPayload; +import net.minecraft.util.NonNullList; +import net.minecraft.util.text.translation.I18n; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import org.lwjgl.input.Keyboard; +import org.lwjgl.opengl.GL11; + +import javax.annotation.Nonnull; +import java.io.IOException; + +@SideOnly(Side.CLIENT) +public class GuiRobitRepair extends GuiRobit implements IContainerListener { + private ContainerRepair repairContainer; + private GuiTextField itemNameField; + private InventoryPlayer playerInventory; + + public GuiRobitRepair(InventoryPlayer inventory, EntityRobit entity) { + super(entity, new ContainerRobitRepair(inventory, entity)); + playerInventory = inventory; + repairContainer = (ContainerRobitRepair) inventorySlots; + } + + @Override + public void initGui() { + super.initGui(); + Keyboard.enableRepeatEvents(true); + int i = (width - xSize) / 2; + int j = (height - ySize) / 2; + itemNameField = new GuiTextField(0, fontRenderer, i + 62, j + 24, 103, 12); + itemNameField.setTextColor(-1); + itemNameField.setDisabledTextColour(-1); + itemNameField.setEnableBackgroundDrawing(false); + itemNameField.setMaxStringLength(30); + inventorySlots.removeListener(this); + inventorySlots.addListener(this); + } + + @Override + public void onGuiClosed() { + super.onGuiClosed(); + Keyboard.enableRepeatEvents(false); + inventorySlots.removeListener(this); + } + + @Override + protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { + GL11.glDisable(GL11.GL_LIGHTING); + fontRenderer.drawString(LangUtils.localize("container.repair"), 60, 6, 0x404040); + + if (repairContainer.maximumCost > 0) { + int k = 8453920; + boolean flag = true; + String s = I18n.translateToLocalFormatted("container.repair.cost", repairContainer.maximumCost); + + if (repairContainer.maximumCost >= 40 && !mc.player.capabilities.isCreativeMode) { + s = LangUtils.localize("container.repair.expensive"); + k = 16736352; + } else if (!repairContainer.getSlot(2).getHasStack()) { + flag = false; + } else if (!repairContainer.getSlot(2).canTakeStack(playerInventory.player)) { + k = 16736352; + } + + if (flag) { + int l = -16777216 | (k & 16579836) >> 2 | k & -16777216; + int i1 = (xSize - 25) - 8 - fontRenderer.getStringWidth(s); + byte b0 = 67; + + if (fontRenderer.getUnicodeFlag()) { + drawRect(i1 - 3, b0 - 2, (xSize - 25) - 7, b0 + 10, -16777216); + drawRect(i1 - 2, b0 - 1, (xSize - 25) - 8, b0 + 9, -12895429); + } else { + fontRenderer.drawString(s, i1, b0 + 1, l); + fontRenderer.drawString(s, i1 + 1, b0, l); + fontRenderer.drawString(s, i1 + 1, b0 + 1, l); + } + + fontRenderer.drawString(s, i1, b0, k); + } + } + + GL11.glEnable(GL11.GL_LIGHTING); + + super.drawGuiContainerForegroundLayer(mouseX, mouseY); + } + + @Override + protected void keyTyped(char c, int i) throws IOException { + if (itemNameField.textboxKeyTyped(c, i)) { + repairContainer.updateItemName(itemNameField.getText()); + mc.player.connection.sendPacket(new CPacketCustomPayload("MC|ItemName", (new PacketBuffer(Unpooled.buffer())).writeString(itemNameField.getText()))); + } else { + super.keyTyped(c, i); + } + } + + @Override + protected void extraClickListeners(int mouseX, int mouseY, int button) { + itemNameField.mouseClicked(mouseX, mouseY, button); + } + + @Override + protected boolean openGui(int id) { + return id != 4; + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTick) { + super.drawScreen(mouseX, mouseY, partialTick); + GL11.glDisable(GL11.GL_LIGHTING); + itemNameField.drawTextBox(); + } + + @Override + protected String getBackgroundImage() { + return "GuiRobitRepair.png"; + } + + @Override + protected void drawGuiContainerBackgroundLayer(float partialTick, int mouseX, int mouseY) { + super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY); + int guiWidth = (width - xSize) / 2; + int guiHeight = (height - ySize) / 2; + drawTexturedModalRect(guiWidth + 59, guiHeight + 20, 0, ySize + (repairContainer.getSlot(0).getHasStack() ? 0 : 16), 110, 16); + if ((repairContainer.getSlot(0).getHasStack() || repairContainer.getSlot(1).getHasStack()) && !repairContainer.getSlot(2).getHasStack()) { + drawTexturedModalRect(guiWidth + 99, guiHeight + 45, xSize + 18, 36, 28, 21); + } + } + + @Override + public void sendAllContents(@Nonnull Container container, @Nonnull NonNullList list) { + sendSlotContents(container, 0, container.getSlot(0).getStack()); + } + + @Override + public void sendSlotContents(@Nonnull Container container, int slotID, @Nonnull ItemStack itemstack) { + if (slotID == 0) { + itemNameField.setText(itemstack.isEmpty() ? "" : itemstack.getDisplayName()); + itemNameField.setEnabled(!itemstack.isEmpty()); + if (!itemstack.isEmpty()) { + repairContainer.updateItemName(itemNameField.getText()); + mc.player.connection.sendPacket(new CPacketCustomPayload("MC|ItemName", new PacketBuffer(Unpooled.buffer()).writeString(itemNameField.getText()))); + } + } + } + + @Override + public void sendWindowProperty(@Nonnull Container containerIn, int varToUpdate, int newValue) { + } + + @Override + public void sendAllWindowProperties(@Nonnull Container containerIn, @Nonnull IInventory inventory) { + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/robit/GuiRobitSmelting.java b/src/main/java/mekanism/client/gui/robit/GuiRobitSmelting.java new file mode 100644 index 000000000..f067952a2 --- /dev/null +++ b/src/main/java/mekanism/client/gui/robit/GuiRobitSmelting.java @@ -0,0 +1,57 @@ +package mekanism.client.gui.robit; + +import mekanism.common.entity.EntityRobit; +import mekanism.common.inventory.container.ContainerRobitSmelting; +import mekanism.common.util.LangUtils; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class GuiRobitSmelting extends GuiRobit { + public GuiRobitSmelting(InventoryPlayer inventory, EntityRobit entity) { + super(entity, new ContainerRobitSmelting(inventory, entity)); + } + + @Override + protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { + fontRenderer.drawString(LangUtils.localize("gui.robit.smelting"), 8, 6, 0x404040); + fontRenderer.drawString(LangUtils.localize("container.inventory"), 8, ySize - 93, 0x404040); + super.drawGuiContainerForegroundLayer(mouseX, mouseY); + } + + @Override + protected String getBackgroundImage() { + return "GuiRobitSmelting.png"; + } + + @Override + protected void drawGuiContainerBackgroundLayer(float partialTick, int mouseX, int mouseY) { + super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY); + int guiWidth = (width - xSize) / 2; + int guiHeight = (height - ySize) / 2; + int displayInt; + if (robit.furnaceBurnTime > 0) { + displayInt = getBurnTimeRemainingScaled(12); + drawTexturedModalRect(guiWidth + 56, guiHeight + 36 + 12 - displayInt, 176 + 25 + 18, 36 + 12 - displayInt, 14, displayInt + 2); + } + displayInt = getCookProgressScaled(24); + drawTexturedModalRect(guiWidth + 79, guiHeight + 34, 176 + 25 + 18, 36 + 14, displayInt + 1, 16); + } + + @Override + protected boolean openGui(int id) { + return id != 3; + } + + private int getCookProgressScaled(int i) { + return robit.furnaceCookTime * i / 200; + } + + private int getBurnTimeRemainingScaled(int i) { + if (robit.currentItemBurnTime == 0) { + robit.currentItemBurnTime = 200; + } + return robit.furnaceBurnTime * i / robit.currentItemBurnTime; + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/common/inventory/container/ContainerDynamicTank.java b/src/main/java/mekanism/common/inventory/container/ContainerDynamicTank.java index d2948ed19..41b7214e4 100644 --- a/src/main/java/mekanism/common/inventory/container/ContainerDynamicTank.java +++ b/src/main/java/mekanism/common/inventory/container/ContainerDynamicTank.java @@ -1,127 +1,10 @@ package mekanism.common.inventory.container; -import mekanism.common.inventory.slot.SlotOutput; import mekanism.common.tile.TileEntityDynamicTank; -import mekanism.common.util.FluidContainerUtils; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import javax.annotation.Nonnull; - -public class ContainerDynamicTank extends Container -{ - private TileEntityDynamicTank tileEntity; - - public ContainerDynamicTank(InventoryPlayer inventory, TileEntityDynamicTank tentity) - { - tileEntity = tentity; - addSlotToContainer(new Slot(tentity, 0, 146, 20)); - addSlotToContainer(new SlotOutput(tentity, 1, 146, 51)); - - int slotY; - - for(slotY = 0; slotY < 3; slotY++) - { - for(int slotX = 0; slotX < 9; slotX++) - { - addSlotToContainer(new Slot(inventory, slotX + slotY * 9 + 9, 8 + slotX * 18, 84 + slotY * 18)); - } - } - - for(slotY = 0; slotY < 9; slotY++) - { - addSlotToContainer(new Slot(inventory, slotY, 8 + slotY * 18, 142)); - } - - tileEntity.open(inventory.player); - tileEntity.openInventory(inventory.player); - } - - @Override - public void onContainerClosed(EntityPlayer entityplayer) - { - super.onContainerClosed(entityplayer); - - tileEntity.close(entityplayer); - tileEntity.closeInventory(entityplayer); - } - - @Override - public boolean canInteractWith(@Nonnull EntityPlayer entityplayer) - { - return tileEntity.isUsableByPlayer(entityplayer); - } - - @Nonnull - @Override - public ItemStack transferStackInSlot(EntityPlayer player, int slotID) - { - ItemStack stack = ItemStack.EMPTY; - Slot currentSlot = inventorySlots.get(slotID); - - if(currentSlot != null && currentSlot.getHasStack()) - { - ItemStack slotStack = currentSlot.getStack(); - stack = slotStack.copy(); - - if(FluidContainerUtils.isFluidContainer(slotStack)) - { - if(slotID != 0 && slotID != 1) - { - if(!mergeItemStack(slotStack, 0, 1, false)) - { - return ItemStack.EMPTY; - } - } - else { - if(!mergeItemStack(slotStack, 2, inventorySlots.size(), true)) - { - return ItemStack.EMPTY; - } - } - } - else { - if(slotID >= 2 && slotID <= 28) - { - if(!mergeItemStack(slotStack, 29, inventorySlots.size(), false)) - { - return ItemStack.EMPTY; - } - } - else if(slotID > 28) - { - if(!mergeItemStack(slotStack, 2, 28, false)) - { - return ItemStack.EMPTY; - } - } - else { - if(!mergeItemStack(slotStack, 2, inventorySlots.size(), true)) - { - return ItemStack.EMPTY; - } - } - } - - if(slotStack.getCount() == 0) - { - currentSlot.putStack(ItemStack.EMPTY); - } - else { - currentSlot.onSlotChanged(); - } - - if(slotStack.getCount() == stack.getCount()) - { - return ItemStack.EMPTY; - } - - currentSlot.onTake(player, slotStack); - } - - return stack; - } -} +public class ContainerDynamicTank extends ContainerFluidStorage { + public ContainerDynamicTank(InventoryPlayer inventory, TileEntityDynamicTank tank) { + super(inventory, tank, 20); + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/common/inventory/container/ContainerEnergyCube.java b/src/main/java/mekanism/common/inventory/container/ContainerEnergyCube.java index d1e247a60..897059836 100644 --- a/src/main/java/mekanism/common/inventory/container/ContainerEnergyCube.java +++ b/src/main/java/mekanism/common/inventory/container/ContainerEnergyCube.java @@ -1,191 +1,18 @@ package mekanism.common.inventory.container; -import ic2.api.item.IElectricItem; import mekanism.common.inventory.slot.SlotEnergy.SlotCharge; import mekanism.common.inventory.slot.SlotEnergy.SlotDischarge; import mekanism.common.tile.TileEntityEnergyCube; -import mekanism.common.util.ChargeUtils; -import mekanism.common.util.MekanismUtils; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.init.Items; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import javax.annotation.Nonnull; +public class ContainerEnergyCube extends ContainerEnergyStorage { + public ContainerEnergyCube(InventoryPlayer inventory, TileEntityEnergyCube energyCube) { + super(inventory, energyCube); + } -public class ContainerEnergyCube extends Container -{ - private TileEntityEnergyCube tileEntity; - - public ContainerEnergyCube(InventoryPlayer inventory, TileEntityEnergyCube unit) - { - tileEntity = unit; - - addSlotToContainer(new SlotCharge(unit, 0, 143, 35)); - addSlotToContainer(new SlotDischarge(unit, 1, 17, 35)); - - int slotY; - - for(slotY = 0; slotY < 3; slotY++) - { - for(int slotX = 0; slotX < 9; slotX++) - { - addSlotToContainer(new Slot(inventory, slotX + slotY * 9 + 9, 8 + slotX * 18, 84 + slotY * 18)); - } - } - - for(slotY = 0; slotY < 9; slotY++) - { - addSlotToContainer(new Slot(inventory, slotY, 8 + slotY * 18, 142)); - } - - tileEntity.open(inventory.player); - tileEntity.openInventory(inventory.player); - } - - @Override - public void onContainerClosed(EntityPlayer entityplayer) - { - super.onContainerClosed(entityplayer); - - tileEntity.close(entityplayer); - tileEntity.closeInventory(entityplayer); - } - - @Override - public boolean canInteractWith(@Nonnull EntityPlayer entityplayer) - { - return tileEntity.isUsableByPlayer(entityplayer); - } - - @Nonnull - @Override - public ItemStack transferStackInSlot(EntityPlayer player, int slotID) - { - ItemStack stack = ItemStack.EMPTY; - Slot currentSlot = inventorySlots.get(slotID); - - if(currentSlot != null && currentSlot.getHasStack()) - { - ItemStack slotStack = currentSlot.getStack(); - stack = slotStack.copy(); - - if(ChargeUtils.canBeCharged(slotStack) || ChargeUtils.canBeDischarged(slotStack)) - { - if(slotStack.getItem() == Items.REDSTONE) - { - if(slotID != 1) - { - if(!mergeItemStack(slotStack, 1, 2, false)) - { - return ItemStack.EMPTY; - } - } - else { - if(!mergeItemStack(slotStack, 2, inventorySlots.size(), true)) - { - return ItemStack.EMPTY; - } - } - } - else { - if(slotID != 1 && slotID != 0) - { - if(ChargeUtils.canBeDischarged(slotStack)) - { - if(!mergeItemStack(slotStack, 1, 2, false)) - { - if(canTransfer(slotStack)) - { - if(!mergeItemStack(slotStack, 0, 1, false)) - { - return ItemStack.EMPTY; - } - } - } - } - else if(canTransfer(slotStack)) - { - if(!mergeItemStack(slotStack, 0, 1, false)) - { - return ItemStack.EMPTY; - } - } - } - else if(slotID == 1) - { - if(canTransfer(slotStack)) - { - if(!mergeItemStack(slotStack, 0, 1, false)) - { - if(!mergeItemStack(slotStack, 2, inventorySlots.size(), true)) - { - return ItemStack.EMPTY; - } - } - } - else { - if(!mergeItemStack(slotStack, 2, inventorySlots.size(), true)) - { - return ItemStack.EMPTY; - } - } - } - else - { - if(!mergeItemStack(slotStack, 2, inventorySlots.size(), true)) - { - return ItemStack.EMPTY; - } - } - } - } - else { - if(slotID >= 2 && slotID <= 28) - { - if(!mergeItemStack(slotStack, 29, inventorySlots.size(), false)) - { - return ItemStack.EMPTY; - } - } - else if(slotID > 28) - { - if(!mergeItemStack(slotStack, 2, 28, false)) - { - return ItemStack.EMPTY; - } - } - else { - if(!mergeItemStack(slotStack, 2, inventorySlots.size(), true)) - { - return ItemStack.EMPTY; - } - } - } - - if(slotStack.getCount() == 0) - { - currentSlot.putStack(ItemStack.EMPTY); - } - else { - currentSlot.onSlotChanged(); - } - - if(slotStack.getCount() == stack.getCount()) - { - return ItemStack.EMPTY; - } - - currentSlot.onTake(player, slotStack); - } - - return stack; - } - - private boolean canTransfer(ItemStack slotStack) - { - return MekanismUtils.useIC2() && slotStack.getItem() instanceof IElectricItem; - } -} + @Override + protected void addSlots() { + addSlotToContainer(new SlotCharge(tileEntity, 0, 143, 35)); + addSlotToContainer(new SlotDischarge(tileEntity, 1, 17, 35)); + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/common/inventory/container/ContainerEnergyStorage.java b/src/main/java/mekanism/common/inventory/container/ContainerEnergyStorage.java new file mode 100644 index 000000000..471bf7ef7 --- /dev/null +++ b/src/main/java/mekanism/common/inventory/container/ContainerEnergyStorage.java @@ -0,0 +1,143 @@ +package mekanism.common.inventory.container; + +import ic2.api.item.IElectricItem; +import mekanism.common.tile.prefab.TileEntityContainerBlock; +import mekanism.common.util.ChargeUtils; +import mekanism.common.util.MekanismUtils; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.init.Items; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +import javax.annotation.Nonnull; + +public abstract class ContainerEnergyStorage extends Container { + protected TileEntityContainerBlock tileEntity; + + protected ContainerEnergyStorage(InventoryPlayer inventory, TileEntityContainerBlock tileEntity) { + this.tileEntity = tileEntity; + addSlots(); + + int slotY; + + for (slotY = 0; slotY < 3; slotY++) { + for (int slotX = 0; slotX < 9; slotX++) { + addSlotToContainer(new Slot(inventory, slotX + slotY * 9 + 9, 8 + slotX * 18, 84 + slotY * 18)); + } + } + + for (slotY = 0; slotY < 9; slotY++) { + addSlotToContainer(new Slot(inventory, slotY, 8 + slotY * 18, 142)); + } + + tileEntity.open(inventory.player); + tileEntity.openInventory(inventory.player); + } + + @Nonnull + @Override + public ItemStack transferStackInSlot(EntityPlayer player, int slotID) { + ItemStack stack = ItemStack.EMPTY; + Slot currentSlot = inventorySlots.get(slotID); + + if (currentSlot != null && currentSlot.getHasStack()) { + ItemStack slotStack = currentSlot.getStack(); + stack = slotStack.copy(); + + if (ChargeUtils.canBeCharged(slotStack) || ChargeUtils.canBeDischarged(slotStack)) { + if (slotStack.getItem() == Items.REDSTONE) { + if (slotID != 1) { + if (!mergeItemStack(slotStack, 1, 2, false)) { + return ItemStack.EMPTY; + } + } else { + if (!mergeItemStack(slotStack, 2, inventorySlots.size(), true)) { + return ItemStack.EMPTY; + } + } + } else { + if (slotID != 1 && slotID != 0) { + if (ChargeUtils.canBeDischarged(slotStack)) { + if (!mergeItemStack(slotStack, 1, 2, false)) { + if (canTransfer(slotStack)) { + if (!mergeItemStack(slotStack, 0, 1, false)) { + return ItemStack.EMPTY; + } + } + } + } else if (canTransfer(slotStack)) { + if (!mergeItemStack(slotStack, 0, 1, false)) { + return ItemStack.EMPTY; + } + } + } else if (slotID == 1) { + if (canTransfer(slotStack)) { + if (!mergeItemStack(slotStack, 0, 1, false)) { + if (!mergeItemStack(slotStack, 2, inventorySlots.size(), true)) { + return ItemStack.EMPTY; + } + } + } else { + if (!mergeItemStack(slotStack, 2, inventorySlots.size(), true)) { + return ItemStack.EMPTY; + } + } + } else { + if (!mergeItemStack(slotStack, 2, inventorySlots.size(), true)) { + return ItemStack.EMPTY; + } + } + } + } else { + if (slotID >= 2 && slotID <= 28) { + if (!mergeItemStack(slotStack, 29, inventorySlots.size(), false)) { + return ItemStack.EMPTY; + } + } else if (slotID > 28) { + if (!mergeItemStack(slotStack, 2, 28, false)) { + return ItemStack.EMPTY; + } + } else { + if (!mergeItemStack(slotStack, 2, inventorySlots.size(), true)) { + return ItemStack.EMPTY; + } + } + } + + if (slotStack.getCount() == 0) { + currentSlot.putStack(ItemStack.EMPTY); + } else { + currentSlot.onSlotChanged(); + } + + if (slotStack.getCount() == stack.getCount()) { + return ItemStack.EMPTY; + } + + currentSlot.onTake(player, slotStack); + } + + return stack; + } + + private boolean canTransfer(ItemStack slotStack) { + return MekanismUtils.useIC2() && slotStack.getItem() instanceof IElectricItem; + } + + @Override + public void onContainerClosed(EntityPlayer entityplayer) { + super.onContainerClosed(entityplayer); + + tileEntity.close(entityplayer); + tileEntity.closeInventory(entityplayer); + } + + @Override + public boolean canInteractWith(@Nonnull EntityPlayer entityplayer) { + return tileEntity.isUsableByPlayer(entityplayer); + } + + protected abstract void addSlots(); +} \ No newline at end of file diff --git a/src/main/java/mekanism/common/inventory/container/ContainerFluidStorage.java b/src/main/java/mekanism/common/inventory/container/ContainerFluidStorage.java new file mode 100644 index 000000000..05e93a65a --- /dev/null +++ b/src/main/java/mekanism/common/inventory/container/ContainerFluidStorage.java @@ -0,0 +1,103 @@ +package mekanism.common.inventory.container; + +import mekanism.common.inventory.slot.SlotOutput; +import mekanism.common.tile.prefab.TileEntityContainerBlock; +import mekanism.common.util.FluidContainerUtils; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +import javax.annotation.Nonnull; + +public abstract class ContainerFluidStorage extends Container { + protected TileEntityContainerBlock tileEntity; + + protected ContainerFluidStorage(InventoryPlayer inventory, TileEntityContainerBlock tank, int yPos) { + tileEntity = tank; + + addSlotToContainer(new Slot(tank, 0, 146, yPos)); + addSlotToContainer(new SlotOutput(tileEntity, 1, 146, 51)); + + int slotY; + + for (slotY = 0; slotY < 3; slotY++) { + for (int slotX = 0; slotX < 9; slotX++) { + addSlotToContainer(new Slot(inventory, slotX + slotY * 9 + 9, 8 + slotX * 18, 84 + slotY * 18)); + } + } + + for (slotY = 0; slotY < 9; slotY++) { + addSlotToContainer(new Slot(inventory, slotY, 8 + slotY * 18, 142)); + } + + tileEntity.open(inventory.player); + tileEntity.openInventory(inventory.player); + } + + @Nonnull + @Override + public ItemStack transferStackInSlot(EntityPlayer player, int slotID) { + ItemStack stack = ItemStack.EMPTY; + Slot currentSlot = inventorySlots.get(slotID); + + if (currentSlot != null && currentSlot.getHasStack()) { + ItemStack slotStack = currentSlot.getStack(); + stack = slotStack.copy(); + + if (FluidContainerUtils.isFluidContainer(slotStack)) { + if (slotID != 0 && slotID != 1) { + if (!mergeItemStack(slotStack, 0, 1, false)) { + return ItemStack.EMPTY; + } + } else { + if (!mergeItemStack(slotStack, 2, inventorySlots.size(), true)) { + return ItemStack.EMPTY; + } + } + } else { + if (slotID >= 2 && slotID <= 28) { + if (!mergeItemStack(slotStack, 29, inventorySlots.size(), false)) { + return ItemStack.EMPTY; + } + } else if (slotID > 28) { + if (!mergeItemStack(slotStack, 2, 28, false)) { + return ItemStack.EMPTY; + } + } else { + if (!mergeItemStack(slotStack, 2, inventorySlots.size(), true)) { + return ItemStack.EMPTY; + } + } + } + + if (slotStack.getCount() == 0) { + currentSlot.putStack(ItemStack.EMPTY); + } else { + currentSlot.onSlotChanged(); + } + + if (slotStack.getCount() == stack.getCount()) { + return ItemStack.EMPTY; + } + + currentSlot.onTake(player, slotStack); + } + + return stack; + } + + @Override + public void onContainerClosed(EntityPlayer entityplayer) { + super.onContainerClosed(entityplayer); + + tileEntity.close(entityplayer); + tileEntity.closeInventory(entityplayer); + } + + @Override + public boolean canInteractWith(@Nonnull EntityPlayer entityplayer) { + return tileEntity.isUsableByPlayer(entityplayer); + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/common/inventory/container/ContainerFluidTank.java b/src/main/java/mekanism/common/inventory/container/ContainerFluidTank.java index b3e16e203..290a9b7e4 100644 --- a/src/main/java/mekanism/common/inventory/container/ContainerFluidTank.java +++ b/src/main/java/mekanism/common/inventory/container/ContainerFluidTank.java @@ -1,127 +1,10 @@ package mekanism.common.inventory.container; -import mekanism.common.inventory.slot.SlotOutput; import mekanism.common.tile.TileEntityFluidTank; -import mekanism.common.util.FluidContainerUtils; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import javax.annotation.Nonnull; - -public class ContainerFluidTank extends Container -{ - private TileEntityFluidTank tileEntity; - - public ContainerFluidTank(InventoryPlayer inventory, TileEntityFluidTank tentity) - { - tileEntity = tentity; - addSlotToContainer(new Slot(tentity, 0, 146, 19)); - addSlotToContainer(new SlotOutput(tentity, 1, 146, 51)); - - int slotY; - - for(slotY = 0; slotY < 3; slotY++) - { - for(int slotX = 0; slotX < 9; slotX++) - { - addSlotToContainer(new Slot(inventory, slotX + slotY * 9 + 9, 8 + slotX * 18, 84 + slotY * 18)); - } - } - - for(slotY = 0; slotY < 9; slotY++) - { - addSlotToContainer(new Slot(inventory, slotY, 8 + slotY * 18, 142)); - } - - tileEntity.open(inventory.player); - tileEntity.openInventory(inventory.player); - } - - @Override - public void onContainerClosed(EntityPlayer entityplayer) - { - super.onContainerClosed(entityplayer); - - tileEntity.close(entityplayer); - tileEntity.closeInventory(entityplayer); - } - - @Override - public boolean canInteractWith(@Nonnull EntityPlayer entityplayer) - { - return tileEntity.isUsableByPlayer(entityplayer); - } - - @Nonnull - @Override - public ItemStack transferStackInSlot(EntityPlayer player, int slotID) - { - ItemStack stack = ItemStack.EMPTY; - Slot currentSlot = inventorySlots.get(slotID); - - if(currentSlot != null && currentSlot.getHasStack()) - { - ItemStack slotStack = currentSlot.getStack(); - stack = slotStack.copy(); - - if(FluidContainerUtils.isFluidContainer(slotStack)) - { - if(slotID != 0 && slotID != 1) - { - if(!mergeItemStack(slotStack, 0, 1, false)) - { - return ItemStack.EMPTY; - } - } - else { - if(!mergeItemStack(slotStack, 2, inventorySlots.size(), true)) - { - return ItemStack.EMPTY; - } - } - } - else { - if(slotID >= 2 && slotID <= 28) - { - if(!mergeItemStack(slotStack, 29, inventorySlots.size(), false)) - { - return ItemStack.EMPTY; - } - } - else if(slotID > 28) - { - if(!mergeItemStack(slotStack, 2, 28, false)) - { - return ItemStack.EMPTY; - } - } - else { - if(!mergeItemStack(slotStack, 2, inventorySlots.size(), true)) - { - return ItemStack.EMPTY; - } - } - } - - if(slotStack.getCount() == 0) - { - currentSlot.putStack(ItemStack.EMPTY); - } - else { - currentSlot.onSlotChanged(); - } - - if(slotStack.getCount() == stack.getCount()) - { - return ItemStack.EMPTY; - } - - currentSlot.onTake(player, slotStack); - } - - return stack; - } -} +public class ContainerFluidTank extends ContainerFluidStorage { + public ContainerFluidTank(InventoryPlayer inventory, TileEntityFluidTank tank) { + super(inventory, tank, 19); + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/common/inventory/container/ContainerInductionMatrix.java b/src/main/java/mekanism/common/inventory/container/ContainerInductionMatrix.java index eacbc8bc7..66ce4a421 100644 --- a/src/main/java/mekanism/common/inventory/container/ContainerInductionMatrix.java +++ b/src/main/java/mekanism/common/inventory/container/ContainerInductionMatrix.java @@ -1,190 +1,18 @@ package mekanism.common.inventory.container; -import ic2.api.item.IElectricItem; import mekanism.common.inventory.slot.SlotEnergy.SlotCharge; import mekanism.common.inventory.slot.SlotEnergy.SlotDischarge; import mekanism.common.tile.TileEntityInductionCasing; -import mekanism.common.util.ChargeUtils; -import mekanism.common.util.MekanismUtils; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.init.Items; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import javax.annotation.Nonnull; +public class ContainerInductionMatrix extends ContainerEnergyStorage { + public ContainerInductionMatrix(InventoryPlayer inventory, TileEntityInductionCasing inductionCasing) { + super(inventory, inductionCasing); + } -public class ContainerInductionMatrix extends Container -{ - private TileEntityInductionCasing tileEntity; - - public ContainerInductionMatrix(InventoryPlayer inventory, TileEntityInductionCasing tentity) - { - tileEntity = tentity; - addSlotToContainer(new SlotCharge(tentity, 0, 146, 20)); - addSlotToContainer(new SlotDischarge(tentity, 1, 146, 51)); - - int slotY; - - for(slotY = 0; slotY < 3; slotY++) - { - for(int slotX = 0; slotX < 9; slotX++) - { - addSlotToContainer(new Slot(inventory, slotX + slotY * 9 + 9, 8 + slotX * 18, 84 + slotY * 18)); - } - } - - for(slotY = 0; slotY < 9; slotY++) - { - addSlotToContainer(new Slot(inventory, slotY, 8 + slotY * 18, 142)); - } - - tileEntity.open(inventory.player); - tileEntity.openInventory(inventory.player); - } - - @Override - public void onContainerClosed(EntityPlayer entityplayer) - { - super.onContainerClosed(entityplayer); - - tileEntity.close(entityplayer); - tileEntity.closeInventory(entityplayer); - } - - @Override - public boolean canInteractWith(@Nonnull EntityPlayer entityplayer) - { - return tileEntity.isUsableByPlayer(entityplayer); - } - - @Nonnull - @Override - public ItemStack transferStackInSlot(EntityPlayer player, int slotID) - { - ItemStack stack = ItemStack.EMPTY; - Slot currentSlot = inventorySlots.get(slotID); - - if(currentSlot != null && currentSlot.getHasStack()) - { - ItemStack slotStack = currentSlot.getStack(); - stack = slotStack.copy(); - - if(ChargeUtils.canBeCharged(slotStack) || ChargeUtils.canBeDischarged(slotStack)) - { - if(slotStack.getItem() == Items.REDSTONE) - { - if(slotID != 1) - { - if(!mergeItemStack(slotStack, 1, 2, false)) - { - return ItemStack.EMPTY; - } - } - else { - if(!mergeItemStack(slotStack, 2, inventorySlots.size(), true)) - { - return ItemStack.EMPTY; - } - } - } - else { - if(slotID != 1 && slotID != 0) - { - if(ChargeUtils.canBeDischarged(slotStack)) - { - if(!mergeItemStack(slotStack, 1, 2, false)) - { - if(canTransfer(slotStack)) - { - if(!mergeItemStack(slotStack, 0, 1, false)) - { - return ItemStack.EMPTY; - } - } - } - } - else if(canTransfer(slotStack)) - { - if(!mergeItemStack(slotStack, 0, 1, false)) - { - return ItemStack.EMPTY; - } - } - } - else if(slotID == 1) - { - if(canTransfer(slotStack)) - { - if(!mergeItemStack(slotStack, 0, 1, false)) - { - if(!mergeItemStack(slotStack, 2, inventorySlots.size(), true)) - { - return ItemStack.EMPTY; - } - } - } - else { - if(!mergeItemStack(slotStack, 2, inventorySlots.size(), true)) - { - return ItemStack.EMPTY; - } - } - } - else - { - if(!mergeItemStack(slotStack, 2, inventorySlots.size(), true)) - { - return ItemStack.EMPTY; - } - } - } - } - else { - if(slotID >= 2 && slotID <= 28) - { - if(!mergeItemStack(slotStack, 29, inventorySlots.size(), false)) - { - return ItemStack.EMPTY; - } - } - else if(slotID > 28) - { - if(!mergeItemStack(slotStack, 2, 28, false)) - { - return ItemStack.EMPTY; - } - } - else { - if(!mergeItemStack(slotStack, 2, inventorySlots.size(), true)) - { - return ItemStack.EMPTY; - } - } - } - - if(slotStack.getCount() == 0) - { - currentSlot.putStack(ItemStack.EMPTY); - } - else { - currentSlot.onSlotChanged(); - } - - if(slotStack.getCount() == stack.getCount()) - { - return ItemStack.EMPTY; - } - - currentSlot.onTake(player, slotStack); - } - - return stack; - } - - private boolean canTransfer(ItemStack slotStack) - { - return MekanismUtils.useIC2() && slotStack.getItem() instanceof IElectricItem; - } -} + @Override + protected void addSlots() { + addSlotToContainer(new SlotCharge(tileEntity, 0, 146, 20)); + addSlotToContainer(new SlotDischarge(tileEntity, 1, 146, 51)); + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/common/tile/TileEntityChemicalCrystallizer.java b/src/main/java/mekanism/common/tile/TileEntityChemicalCrystallizer.java index da18ffa28..3c61ffc7b 100644 --- a/src/main/java/mekanism/common/tile/TileEntityChemicalCrystallizer.java +++ b/src/main/java/mekanism/common/tile/TileEntityChemicalCrystallizer.java @@ -5,7 +5,6 @@ import io.netty.buffer.ByteBuf; import mekanism.api.EnumColor; import mekanism.api.IConfigCardAccess; import mekanism.api.gas.Gas; -import mekanism.api.gas.GasRegistry; import mekanism.api.gas.GasStack; import mekanism.api.gas.GasTank; import mekanism.api.gas.GasTankInfo; @@ -27,8 +26,8 @@ import mekanism.common.recipe.machines.CrystallizerRecipe; import mekanism.common.tile.component.TileComponentConfig; import mekanism.common.tile.component.TileComponentEjector; import mekanism.common.tile.prefab.TileEntityOperationalMachine; +import mekanism.common.util.TileUtils; import mekanism.common.util.ChargeUtils; -import mekanism.common.util.GasUtils; import mekanism.common.util.InventoryUtils; import mekanism.common.util.ItemDataUtils; import mekanism.common.util.MekanismUtils; @@ -85,12 +84,7 @@ public class TileEntityChemicalCrystallizer extends TileEntityOperationalMachine if(!world.isRemote) { ChargeUtils.discharge(2, this); - - if(!inventory.get(0).isEmpty() && (inputTank.getGas() == null || inputTank.getStored() < inputTank.getMaxGas())) - { - inputTank.receive(GasUtils.removeGas(inventory.get(0), inputTank.getGasType(), inputTank.getNeeded()), true); - } - + TileUtils.receiveGas(inventory.get(0), inputTank); CrystallizerRecipe recipe = getRecipe(); if(canOperate(recipe) && MekanismUtils.canFunction(this) && getEnergy() >= energyPerTick) @@ -161,13 +155,7 @@ public class TileEntityChemicalCrystallizer extends TileEntityOperationalMachine if(FMLCommonHandler.instance().getEffectiveSide().isClient()) { - if(dataStream.readBoolean()) - { - inputTank.setGas(new GasStack(GasRegistry.getGas(dataStream.readInt()), dataStream.readInt())); - } - else { - inputTank.setGas(null); - } + TileUtils.readTankData(dataStream, inputTank); } } @@ -175,17 +163,7 @@ public class TileEntityChemicalCrystallizer extends TileEntityOperationalMachine public TileNetworkList getNetworkedData(TileNetworkList data) { super.getNetworkedData(data); - - if(inputTank.getGas() != null) - { - data.add(true); - data.add(inputTank.getGas().getGas().getID()); - data.add(inputTank.getStored()); - } - else { - data.add(false); - } - + TileUtils.addTankData(data, inputTank); return data; } diff --git a/src/main/java/mekanism/common/tile/TileEntityChemicalDissolutionChamber.java b/src/main/java/mekanism/common/tile/TileEntityChemicalDissolutionChamber.java index e85253865..40559143c 100644 --- a/src/main/java/mekanism/common/tile/TileEntityChemicalDissolutionChamber.java +++ b/src/main/java/mekanism/common/tile/TileEntityChemicalDissolutionChamber.java @@ -3,7 +3,6 @@ package mekanism.common.tile; import io.netty.buffer.ByteBuf; import mekanism.api.gas.Gas; -import mekanism.api.gas.GasRegistry; import mekanism.api.gas.GasStack; import mekanism.api.gas.GasTank; import mekanism.api.gas.GasTankInfo; @@ -23,11 +22,11 @@ import mekanism.common.recipe.inputs.ItemStackInput; import mekanism.common.recipe.machines.DissolutionRecipe; import mekanism.common.tile.component.TileComponentUpgrade; import mekanism.common.tile.prefab.TileEntityMachine; +import mekanism.common.util.TileUtils; import mekanism.common.util.ChargeUtils; import mekanism.common.util.GasUtils; import mekanism.common.util.InventoryUtils; import mekanism.common.util.ItemDataUtils; -import mekanism.common.util.ListUtils; import mekanism.common.util.MekanismUtils; import mekanism.common.util.StatUtils; import net.minecraft.item.ItemStack; @@ -83,10 +82,7 @@ public class TileEntityChemicalDissolutionChamber extends TileEntityMachine impl injectTank.receive(GasUtils.removeGas(inventory.get(0), MekanismFluids.SulfuricAcid, injectTank.getNeeded()), true); } - if(!inventory.get(2).isEmpty() && outputTank.getGas() != null) - { - outputTank.draw(GasUtils.addGas(inventory.get(2), outputTank.getGas()), true); - } + TileUtils.drawGas(inventory.get(2), outputTank); boolean changed = false; @@ -124,11 +120,7 @@ public class TileEntityChemicalDissolutionChamber extends TileEntityMachine impl prevEnergy = getEnergy(); - if(outputTank.getGas() != null) - { - GasStack toSend = new GasStack(outputTank.getGas().getGas(), Math.min(outputTank.getStored(), gasOutput)); - outputTank.draw(GasUtils.emit(toSend, this, ListUtils.asList(MekanismUtils.getRight(facing))), true); - } + TileUtils.emitGas(this, outputTank, gasOutput); } } @@ -225,22 +217,8 @@ public class TileEntityChemicalDissolutionChamber extends TileEntityMachine impl if(FMLCommonHandler.instance().getEffectiveSide().isClient()) { operatingTicks = dataStream.readInt(); - - if(dataStream.readBoolean()) - { - injectTank.setGas(new GasStack(GasRegistry.getGas(dataStream.readInt()), dataStream.readInt())); - } - else { - injectTank.setGas(null); - } - - if(dataStream.readBoolean()) - { - outputTank.setGas(new GasStack(GasRegistry.getGas(dataStream.readInt()), dataStream.readInt())); - } - else { - outputTank.setGas(null); - } + TileUtils.readTankData(dataStream, injectTank); + TileUtils.readTankData(dataStream, outputTank); } } @@ -248,29 +226,9 @@ public class TileEntityChemicalDissolutionChamber extends TileEntityMachine impl public TileNetworkList getNetworkedData(TileNetworkList data) { super.getNetworkedData(data); - data.add(operatingTicks); - - if(injectTank.getGas() != null) - { - data.add(true); - data.add(injectTank.getGas().getGas().getID()); - data.add(injectTank.getStored()); - } - else { - data.add(false); - } - - if(outputTank.getGas() != null) - { - data.add(true); - data.add(outputTank.getGas().getGas().getID()); - data.add(outputTank.getStored()); - } - else { - data.add(false); - } - + TileUtils.addTankData(data, injectTank); + TileUtils.addTankData(data, outputTank); return data; } diff --git a/src/main/java/mekanism/common/tile/TileEntityChemicalInfuser.java b/src/main/java/mekanism/common/tile/TileEntityChemicalInfuser.java index 3394ad97b..3e775e419 100644 --- a/src/main/java/mekanism/common/tile/TileEntityChemicalInfuser.java +++ b/src/main/java/mekanism/common/tile/TileEntityChemicalInfuser.java @@ -5,7 +5,6 @@ import io.netty.buffer.ByteBuf; import java.util.List; import mekanism.api.gas.Gas; -import mekanism.api.gas.GasRegistry; import mekanism.api.gas.GasStack; import mekanism.api.gas.GasTank; import mekanism.api.gas.GasTankInfo; @@ -27,11 +26,10 @@ import mekanism.common.recipe.inputs.ChemicalPairInput; import mekanism.common.recipe.machines.ChemicalInfuserRecipe; import mekanism.common.security.ISecurityTile; import mekanism.common.tile.prefab.TileEntityMachine; +import mekanism.common.util.TileUtils; import mekanism.common.util.ChargeUtils; -import mekanism.common.util.GasUtils; import mekanism.common.util.InventoryUtils; import mekanism.common.util.ItemDataUtils; -import mekanism.common.util.ListUtils; import mekanism.common.util.MekanismUtils; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -72,21 +70,9 @@ public class TileEntityChemicalInfuser extends TileEntityMachine implements IGas if(!world.isRemote) { ChargeUtils.discharge(3, this); - - if(!inventory.get(0).isEmpty() && (leftTank.getGas() == null || leftTank.getStored() < leftTank.getMaxGas())) - { - leftTank.receive(GasUtils.removeGas(inventory.get(0), leftTank.getGasType(), leftTank.getNeeded()), true); - } - - if(!inventory.get(1).isEmpty() && (rightTank.getGas() == null || rightTank.getStored() < rightTank.getMaxGas())) - { - rightTank.receive(GasUtils.removeGas(inventory.get(1), rightTank.getGasType(), rightTank.getNeeded()), true); - } - - if(!inventory.get(2).isEmpty() && centerTank.getGas() != null) - { - centerTank.draw(GasUtils.addGas(inventory.get(2), centerTank.getGas()), true); - } + TileUtils.receiveGas(inventory.get(0), leftTank); + TileUtils.receiveGas(inventory.get(1), rightTank); + TileUtils.drawGas(inventory.get(2), centerTank); ChemicalInfuserRecipe recipe = getRecipe(); @@ -106,13 +92,7 @@ public class TileEntityChemicalInfuser extends TileEntityMachine implements IGas setActive(false); } } - - if(centerTank.getGas() != null) - { - GasStack toSend = new GasStack(centerTank.getGas().getGas(), Math.min(centerTank.getStored(), gasOutput)); - centerTank.draw(GasUtils.emit(toSend, this, ListUtils.asList(facing)), true); - } - + TileUtils.emitGas(this, centerTank, gasOutput, facing); prevEnergy = getEnergy(); } } @@ -177,30 +157,9 @@ public class TileEntityChemicalInfuser extends TileEntityMachine implements IGas if(FMLCommonHandler.instance().getEffectiveSide().isClient()) { clientEnergyUsed = dataStream.readDouble(); - - if(dataStream.readBoolean()) - { - leftTank.setGas(new GasStack(GasRegistry.getGas(dataStream.readInt()), dataStream.readInt())); - } - else { - leftTank.setGas(null); - } - - if(dataStream.readBoolean()) - { - rightTank.setGas(new GasStack(GasRegistry.getGas(dataStream.readInt()), dataStream.readInt())); - } - else { - rightTank.setGas(null); - } - - if(dataStream.readBoolean()) - { - centerTank.setGas(new GasStack(GasRegistry.getGas(dataStream.readInt()), dataStream.readInt())); - } - else { - centerTank.setGas(null); - } + TileUtils.readTankData(dataStream, leftTank); + TileUtils.readTankData(dataStream, rightTank); + TileUtils.readTankData(dataStream, centerTank); } } @@ -208,39 +167,10 @@ public class TileEntityChemicalInfuser extends TileEntityMachine implements IGas public TileNetworkList getNetworkedData(TileNetworkList data) { super.getNetworkedData(data); - data.add(clientEnergyUsed); - - if(leftTank.getGas() != null) - { - data.add(true); - data.add(leftTank.getGas().getGas().getID()); - data.add(leftTank.getStored()); - } - else { - data.add(false); - } - - if(rightTank.getGas() != null) - { - data.add(true); - data.add(rightTank.getGas().getGas().getID()); - data.add(rightTank.getStored()); - } - else { - data.add(false); - } - - if(centerTank.getGas() != null) - { - data.add(true); - data.add(centerTank.getGas().getGas().getID()); - data.add(centerTank.getStored()); - } - else { - data.add(false); - } - + TileUtils.addTankData(data, leftTank); + TileUtils.addTankData(data, rightTank); + TileUtils.addTankData(data, centerTank); return data; } diff --git a/src/main/java/mekanism/common/tile/TileEntityChemicalOxidizer.java b/src/main/java/mekanism/common/tile/TileEntityChemicalOxidizer.java index d30bd1e09..2fcb4c1d0 100644 --- a/src/main/java/mekanism/common/tile/TileEntityChemicalOxidizer.java +++ b/src/main/java/mekanism/common/tile/TileEntityChemicalOxidizer.java @@ -2,7 +2,6 @@ package mekanism.common.tile; import io.netty.buffer.ByteBuf; -import mekanism.api.gas.GasRegistry; import mekanism.api.gas.GasStack; import mekanism.api.gas.GasTank; import mekanism.api.gas.IGasItem; @@ -17,11 +16,10 @@ import mekanism.common.recipe.RecipeHandler; import mekanism.common.recipe.inputs.ItemStackInput; import mekanism.common.recipe.machines.OxidationRecipe; import mekanism.common.tile.prefab.TileEntityOperationalMachine; +import mekanism.common.util.TileUtils; import mekanism.common.util.ChargeUtils; -import mekanism.common.util.GasUtils; import mekanism.common.util.InventoryUtils; import mekanism.common.util.ItemDataUtils; -import mekanism.common.util.ListUtils; import mekanism.common.util.MekanismUtils; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -58,11 +56,7 @@ public class TileEntityChemicalOxidizer extends TileEntityOperationalMachine imp if(!world.isRemote) { ChargeUtils.discharge(1, this); - - if(!inventory.get(2).isEmpty() && gasTank.getGas() != null) - { - gasTank.draw(GasUtils.addGas(inventory.get(2), gasTank.getGas()), true); - } + TileUtils.drawGas(inventory.get(2), gasTank); OxidationRecipe recipe = getRecipe(); @@ -91,11 +85,7 @@ public class TileEntityChemicalOxidizer extends TileEntityOperationalMachine imp prevEnergy = getEnergy(); - if(gasTank.getGas() != null) - { - GasStack toSend = new GasStack(gasTank.getGas().getGas(), Math.min(gasTank.getStored(), gasOutput)); - gasTank.draw(GasUtils.emit(toSend, this, ListUtils.asList(MekanismUtils.getRight(facing))), true); - } + TileUtils.emitGas(this, gasTank, gasOutput); } } @@ -181,13 +171,7 @@ public class TileEntityChemicalOxidizer extends TileEntityOperationalMachine imp if(FMLCommonHandler.instance().getEffectiveSide().isClient()) { - if(dataStream.readBoolean()) - { - gasTank.setGas(new GasStack(GasRegistry.getGas(dataStream.readInt()), dataStream.readInt())); - } - else { - gasTank.setGas(null); - } + TileUtils.readTankData(dataStream, gasTank); } } @@ -195,17 +179,7 @@ public class TileEntityChemicalOxidizer extends TileEntityOperationalMachine imp public TileNetworkList getNetworkedData(TileNetworkList data) { super.getNetworkedData(data); - - if(gasTank.getGas() != null) - { - data.add(true); - data.add(gasTank.getGas().getGas().getID()); - data.add(gasTank.getStored()); - } - else { - data.add(false); - } - + TileUtils.addTankData(data, gasTank); return data; } diff --git a/src/main/java/mekanism/common/tile/TileEntityChemicalWasher.java b/src/main/java/mekanism/common/tile/TileEntityChemicalWasher.java index 2660a0a73..d2db5802c 100644 --- a/src/main/java/mekanism/common/tile/TileEntityChemicalWasher.java +++ b/src/main/java/mekanism/common/tile/TileEntityChemicalWasher.java @@ -5,14 +5,12 @@ import io.netty.buffer.ByteBuf; import java.util.List; import mekanism.api.gas.Gas; -import mekanism.api.gas.GasRegistry; import mekanism.api.gas.GasStack; import mekanism.api.gas.GasTank; import mekanism.api.gas.GasTankInfo; import mekanism.api.gas.IGasHandler; import mekanism.api.gas.IGasItem; import mekanism.api.gas.ITubeConnection; -import mekanism.common.PacketHandler; import mekanism.common.Upgrade; import mekanism.common.Upgrade.IUpgradeInfoHandler; import mekanism.common.base.FluidHandlerWrapper; @@ -28,13 +26,12 @@ import mekanism.common.recipe.RecipeHandler; import mekanism.common.recipe.inputs.GasInput; import mekanism.common.recipe.machines.WasherRecipe; import mekanism.common.tile.prefab.TileEntityMachine; +import mekanism.common.util.TileUtils; import mekanism.common.util.ChargeUtils; import mekanism.common.util.FluidContainerUtils; import mekanism.common.util.FluidContainerUtils.FluidChecker; -import mekanism.common.util.GasUtils; import mekanism.common.util.InventoryUtils; import mekanism.common.util.ItemDataUtils; -import mekanism.common.util.ListUtils; import mekanism.common.util.MekanismUtils; import mekanism.common.util.PipeUtils; import net.minecraft.item.ItemStack; @@ -87,11 +84,7 @@ public class TileEntityChemicalWasher extends TileEntityMachine implements IGasH { ChargeUtils.discharge(3, this); manageBuckets(); - - if(!inventory.get(2).isEmpty() && outputTank.getGas() != null) - { - outputTank.draw(GasUtils.addGas(inventory.get(2), outputTank.getGas()), true); - } + TileUtils.drawGas(inventory.get(2), outputTank); WasherRecipe recipe = getRecipe(); @@ -112,11 +105,7 @@ public class TileEntityChemicalWasher extends TileEntityMachine implements IGasH } } - if(outputTank.getGas() != null) - { - GasStack toSend = new GasStack(outputTank.getGas().getGas(), Math.min(outputTank.getStored(), gasOutput)); - outputTank.draw(GasUtils.emit(toSend, this, ListUtils.asList(MekanismUtils.getRight(facing))), true); - } + TileUtils.emitGas(this, outputTank, gasOutput); prevEnergy = getEnergy(); } @@ -178,30 +167,9 @@ public class TileEntityChemicalWasher extends TileEntityMachine implements IGasH if(FMLCommonHandler.instance().getEffectiveSide().isClient()) { clientEnergyUsed = dataStream.readDouble(); - - if(dataStream.readBoolean()) - { - fluidTank.setFluid(new FluidStack(FluidRegistry.getFluid(PacketHandler.readString(dataStream)), dataStream.readInt())); - } - else { - fluidTank.setFluid(null); - } - - if(dataStream.readBoolean()) - { - inputTank.setGas(new GasStack(GasRegistry.getGas(dataStream.readInt()), dataStream.readInt())); - } - else { - inputTank.setGas(null); - } - - if(dataStream.readBoolean()) - { - outputTank.setGas(new GasStack(GasRegistry.getGas(dataStream.readInt()), dataStream.readInt())); - } - else { - outputTank.setGas(null); - } + TileUtils.readTankData(dataStream, fluidTank); + TileUtils.readTankData(dataStream, inputTank); + TileUtils.readTankData(dataStream, outputTank); if(updateDelay == 0 && clientActive != isActive) { @@ -218,37 +186,9 @@ public class TileEntityChemicalWasher extends TileEntityMachine implements IGasH super.getNetworkedData(data); data.add(clientEnergyUsed); - - if(fluidTank.getFluid() != null) - { - data.add(true); - data.add(FluidRegistry.getFluidName(fluidTank.getFluid())); - data.add(fluidTank.getFluidAmount()); - } - else { - data.add(false); - } - - if(inputTank.getGas() != null) - { - data.add(true); - data.add(inputTank.getGas().getGas().getID()); - data.add(inputTank.getStored()); - } - else { - data.add(false); - } - - if(outputTank.getGas() != null) - { - data.add(true); - data.add(outputTank.getGas().getGas().getID()); - data.add(outputTank.getStored()); - } - else { - data.add(false); - } - + TileUtils.addTankData(data, fluidTank); + TileUtils.addTankData(data, inputTank); + TileUtils.addTankData(data, outputTank); return data; } diff --git a/src/main/java/mekanism/common/tile/TileEntityDigitalMiner.java b/src/main/java/mekanism/common/tile/TileEntityDigitalMiner.java index 974def9d2..fd4000744 100644 --- a/src/main/java/mekanism/common/tile/TileEntityDigitalMiner.java +++ b/src/main/java/mekanism/common/tile/TileEntityDigitalMiner.java @@ -650,29 +650,13 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I { super.readFromNBT(nbtTags); - radius = nbtTags.getInteger("radius"); - minY = nbtTags.getInteger("minY"); - maxY = nbtTags.getInteger("maxY"); - doEject = nbtTags.getBoolean("doEject"); - doPull = nbtTags.getBoolean("doPull"); isActive = nbtTags.getBoolean("isActive"); running = nbtTags.getBoolean("running"); delay = nbtTags.getInteger("delay"); - silkTouch = nbtTags.getBoolean("silkTouch"); numPowering = nbtTags.getInteger("numPowering"); searcher.state = State.values()[nbtTags.getInteger("state")]; controlType = RedstoneControl.values()[nbtTags.getInteger("controlType")]; - inverse = nbtTags.getBoolean("inverse"); - - if(nbtTags.hasKey("filters")) - { - NBTTagList tagList = nbtTags.getTagList("filters", NBT.TAG_COMPOUND); - - for(int i = 0; i < tagList.tagCount(); i++) - { - filters.add(MinerFilter.readFromNBT(tagList.getCompoundTagAt(i))); - } - } + setConfigurationData(nbtTags); } @Nonnull @@ -686,33 +670,37 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I reset(); } - nbtTags.setInteger("radius", radius); - nbtTags.setInteger("minY", minY); - nbtTags.setInteger("maxY", maxY); - nbtTags.setBoolean("doEject", doEject); - nbtTags.setBoolean("doPull", doPull); nbtTags.setBoolean("isActive", isActive); nbtTags.setBoolean("running", running); nbtTags.setInteger("delay", delay); - nbtTags.setBoolean("silkTouch", silkTouch); nbtTags.setInteger("numPowering", numPowering); nbtTags.setInteger("state", searcher.state.ordinal()); nbtTags.setInteger("controlType", controlType.ordinal()); - nbtTags.setBoolean("inverse", inverse); + return getConfigurationData(nbtTags); + } - NBTTagList filterTags = new NBTTagList(); + private void readBasicData(ByteBuf dataStream) { + radius = dataStream.readInt(); + minY = dataStream.readInt(); + maxY = dataStream.readInt(); + doEject = dataStream.readBoolean(); + doPull = dataStream.readBoolean(); + clientActive = dataStream.readBoolean(); + running = dataStream.readBoolean(); + silkTouch = dataStream.readBoolean(); + numPowering = dataStream.readInt(); + searcher.state = State.values()[dataStream.readInt()]; + clientToMine = dataStream.readInt(); + controlType = RedstoneControl.values()[dataStream.readInt()]; + inverse = dataStream.readBoolean(); - for(MinerFilter filter : filters) + if(dataStream.readBoolean()) { - filterTags.appendTag(filter.write(new NBTTagCompound())); + missingStack = new ItemStack(Item.getItemById(dataStream.readInt()), 1, dataStream.readInt()); } - - if(filterTags.tagCount() != 0) - { - nbtTags.setTag("filters", filterTags); + else { + missingStack = ItemStack.EMPTY; } - - return nbtTags; } @Override @@ -800,27 +788,7 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I if(type == 0) { - radius = dataStream.readInt(); - minY = dataStream.readInt(); - maxY = dataStream.readInt(); - doEject = dataStream.readBoolean(); - doPull = dataStream.readBoolean(); - clientActive = dataStream.readBoolean(); - running = dataStream.readBoolean(); - silkTouch = dataStream.readBoolean(); - numPowering = dataStream.readInt(); - searcher.state = State.values()[dataStream.readInt()]; - clientToMine = dataStream.readInt(); - controlType = RedstoneControl.values()[dataStream.readInt()]; - inverse = dataStream.readBoolean(); - - if(dataStream.readBoolean()) - { - missingStack = new ItemStack(Item.getItemById(dataStream.readInt()), 1, dataStream.readInt()); - } - else { - missingStack = ItemStack.EMPTY; - } + readBasicData(dataStream); filters.clear(); @@ -833,27 +801,7 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I } else if(type == 1) { - radius = dataStream.readInt(); - minY = dataStream.readInt(); - maxY = dataStream.readInt(); - doEject = dataStream.readBoolean(); - doPull = dataStream.readBoolean(); - clientActive = dataStream.readBoolean(); - running = dataStream.readBoolean(); - silkTouch = dataStream.readBoolean(); - numPowering = dataStream.readInt(); - searcher.state = State.values()[dataStream.readInt()]; - clientToMine = dataStream.readInt(); - controlType = RedstoneControl.values()[dataStream.readInt()]; - inverse = dataStream.readBoolean(); - - if(dataStream.readBoolean()) - { - missingStack = new ItemStack(Item.getItemById(dataStream.readInt()), 1, dataStream.readInt()); - } - else { - missingStack = ItemStack.EMPTY; - } + readBasicData(dataStream); } else if(type == 2) { @@ -889,13 +837,7 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I } } - @Override - public TileNetworkList getNetworkedData(TileNetworkList data) - { - super.getNetworkedData(data); - - data.add(0); - + private void addBasicData(TileNetworkList data) { data.add(radius); data.add(minY); data.add(maxY); @@ -906,7 +848,7 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I data.add(silkTouch); data.add(numPowering); data.add(searcher.state.ordinal()); - + if(searcher.state == State.SEARCHING) { data.add(searcher.found); @@ -917,7 +859,7 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I data.add(controlType.ordinal()); data.add(inverse); - + if(!missingStack.isEmpty()) { data.add(true); @@ -927,7 +869,14 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I else { data.add(false); } + } + @Override + public TileNetworkList getNetworkedData(TileNetworkList data) + { + super.getNetworkedData(data); + data.add(0); + addBasicData(data); data.add(filters.size()); for(MinerFilter filter : filters) @@ -971,41 +920,8 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I public TileNetworkList getGenericPacket(TileNetworkList data) { super.getNetworkedData(data); - data.add(1); - - data.add(radius); - data.add(minY); - data.add(maxY); - data.add(doEject); - data.add(doPull); - data.add(isActive); - data.add(running); - data.add(silkTouch); - data.add(numPowering); - data.add(searcher.state.ordinal()); - - if(searcher.state == State.SEARCHING) - { - data.add(searcher.found); - } - else { - data.add(getSize()); - } - - data.add(controlType.ordinal()); - data.add(inverse); - - if(!missingStack.isEmpty()) - { - data.add(true); - data.add(MekanismUtils.getID(missingStack)); - data.add(missingStack.getItemDamage()); - } - else { - data.add(false); - } - + addBasicData(data); return data; } diff --git a/src/main/java/mekanism/common/tile/TileEntityElectrolyticSeparator.java b/src/main/java/mekanism/common/tile/TileEntityElectrolyticSeparator.java index bf838cab2..42247014e 100644 --- a/src/main/java/mekanism/common/tile/TileEntityElectrolyticSeparator.java +++ b/src/main/java/mekanism/common/tile/TileEntityElectrolyticSeparator.java @@ -5,7 +5,6 @@ import io.netty.buffer.ByteBuf; import java.util.List; import mekanism.api.gas.Gas; -import mekanism.api.gas.GasRegistry; import mekanism.api.gas.GasStack; import mekanism.api.gas.GasTank; import mekanism.api.gas.GasTankInfo; @@ -31,6 +30,7 @@ import mekanism.common.recipe.outputs.ChemicalPairOutput; import mekanism.common.tile.TileEntityGasTank.GasMode; import mekanism.common.tile.component.TileComponentSecurity; import mekanism.common.tile.prefab.TileEntityMachine; +import mekanism.common.util.TileUtils; import mekanism.common.util.ChargeUtils; import mekanism.common.util.FluidContainerUtils; import mekanism.common.util.GasUtils; @@ -44,14 +44,12 @@ import net.minecraft.util.EnumFacing; import net.minecraft.util.NonNullList; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTank; import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.FluidUtil; import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import net.minecraftforge.fml.common.FMLCommonHandler; -import net.minecraftforge.fml.common.network.ByteBufUtils; import javax.annotation.Nonnull; @@ -154,44 +152,26 @@ public class TileEntityElectrolyticSeparator extends TileEntityMachine implement } int dumpAmount = 8*(int)Math.pow(2, upgradeComponent.getUpgrades(Upgrade.SPEED)); - - if(leftTank.getGas() != null) - { - if(dumpLeft != GasMode.DUMPING) - { - GasStack toSend = new GasStack(leftTank.getGas().getGas(), Math.min(leftTank.getStored(), output)); - leftTank.draw(GasUtils.emit(toSend, this, ListUtils.asList(MekanismUtils.getLeft(facing))), true); - } - else { - leftTank.draw(dumpAmount, true); - } - - if(dumpLeft == GasMode.DUMPING_EXCESS && leftTank.getNeeded() < output) - { - leftTank.draw(output-leftTank.getNeeded(), true); - } - } - - if(rightTank.getGas() != null) - { - if(dumpRight != GasMode.DUMPING) - { - GasStack toSend = new GasStack(rightTank.getGas().getGas(), Math.min(rightTank.getStored(), output)); - rightTank.draw(GasUtils.emit(toSend, this, ListUtils.asList(MekanismUtils.getRight(facing))), true); - } - else { - rightTank.draw(dumpAmount, true); - } - - if(dumpRight == GasMode.DUMPING_EXCESS && rightTank.getNeeded() < output) - { - rightTank.draw(output-rightTank.getNeeded(), true); - } - } - + handleTank(leftTank, dumpLeft, MekanismUtils.getLeft(facing), dumpAmount); + handleTank(rightTank, dumpRight, MekanismUtils.getRight(facing), dumpAmount); prevEnergy = getEnergy(); } } + + private void handleTank(GasTank tank, GasMode mode, EnumFacing side, int dumpAmount) { + if(tank.getGas() != null) { + if (mode != GasMode.DUMPING) { + GasStack toSend = new GasStack(tank.getGas().getGas(), Math.min(tank.getStored(), output)); + tank.draw(GasUtils.emit(toSend, this, ListUtils.asList(side)), true); + } else { + tank.draw(dumpAmount, true); + } + + if (mode == GasMode.DUMPING_EXCESS && tank.getNeeded() < output) { + tank.draw(output - tank.getNeeded(), true); + } + } + } public int getUpgradedUsage(SeparatorRecipe recipe) { @@ -332,30 +312,9 @@ public class TileEntityElectrolyticSeparator extends TileEntityMachine implement if(FMLCommonHandler.instance().getEffectiveSide().isClient()) { - if(dataStream.readBoolean()) - { - fluidTank.setFluid(new FluidStack(FluidRegistry.getFluid(ByteBufUtils.readUTF8String(dataStream)), dataStream.readInt())); - } - else { - fluidTank.setFluid(null); - } - - if(dataStream.readBoolean()) - { - leftTank.setGas(new GasStack(GasRegistry.getGas(dataStream.readInt()), dataStream.readInt())); - } - else { - leftTank.setGas(null); - } - - if(dataStream.readBoolean()) - { - rightTank.setGas(new GasStack(GasRegistry.getGas(dataStream.readInt()), dataStream.readInt())); - } - else { - rightTank.setGas(null); - } - + TileUtils.readTankData(dataStream, fluidTank); + TileUtils.readTankData(dataStream, leftTank); + TileUtils.readTankData(dataStream, rightTank); dumpLeft = GasMode.values()[dataStream.readInt()]; dumpRight = GasMode.values()[dataStream.readInt()]; clientEnergyUsed = dataStream.readDouble(); @@ -366,36 +325,9 @@ public class TileEntityElectrolyticSeparator extends TileEntityMachine implement public TileNetworkList getNetworkedData(TileNetworkList data) { super.getNetworkedData(data); - - if(fluidTank.getFluid() != null) - { - data.add(true); - data.add(FluidRegistry.getFluidName(fluidTank.getFluid())); - data.add(fluidTank.getFluidAmount()); - } - else { - data.add(false); - } - - if(leftTank.getGas() != null) - { - data.add(true); - data.add(leftTank.getGas().getGas().getID()); - data.add(leftTank.getStored()); - } - else { - data.add(false); - } - - if(rightTank.getGas() != null) - { - data.add(true); - data.add(rightTank.getGas().getGas().getID()); - data.add(rightTank.getStored()); - } - else { - data.add(false); - } + TileUtils.addTankData(data, fluidTank); + TileUtils.addTankData(data, leftTank); + TileUtils.addTankData(data, rightTank); data.add(dumpLeft.ordinal()); data.add(dumpRight.ordinal()); diff --git a/src/main/java/mekanism/common/tile/TileEntityFactory.java b/src/main/java/mekanism/common/tile/TileEntityFactory.java index 38dc937d2..f02cdbea8 100644 --- a/src/main/java/mekanism/common/tile/TileEntityFactory.java +++ b/src/main/java/mekanism/common/tile/TileEntityFactory.java @@ -50,6 +50,7 @@ import mekanism.common.tile.component.TileComponentConfig; import mekanism.common.tile.component.TileComponentEjector; import mekanism.common.tile.prefab.TileEntityAdvancedElectricMachine; import mekanism.common.tile.prefab.TileEntityMachine; +import mekanism.common.util.TileUtils; import mekanism.common.util.ChargeUtils; import mekanism.common.util.GasUtils; import mekanism.common.util.InventoryUtils; @@ -793,15 +794,8 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt { progress[i] = dataStream.readInt(); } - - if(dataStream.readBoolean()) - { - gasTank.setGas(new GasStack(dataStream.readInt(), dataStream.readInt())); - } - else { - gasTank.setGas(null); - } - + + TileUtils.readTankData(dataStream, gasTank); if(upgraded) { markDirty(); @@ -881,16 +875,7 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt } data.add(progress); - - if(gasTank.getGas() != null) - { - data.add(true); - data.add(gasTank.getGas().getGas().getID()); - data.add(gasTank.getStored()); - } - else { - data.add(false); - } + TileUtils.addTankData(data, gasTank); upgraded = false; diff --git a/src/main/java/mekanism/common/tile/TileEntityGasTank.java b/src/main/java/mekanism/common/tile/TileEntityGasTank.java index 22cc1409a..d790c52d6 100644 --- a/src/main/java/mekanism/common/tile/TileEntityGasTank.java +++ b/src/main/java/mekanism/common/tile/TileEntityGasTank.java @@ -6,7 +6,6 @@ import mekanism.api.Coord4D; import mekanism.api.EnumColor; import mekanism.api.Range4D; import mekanism.api.gas.Gas; -import mekanism.api.gas.GasRegistry; import mekanism.api.gas.GasStack; import mekanism.api.gas.GasTank; import mekanism.api.gas.GasTankInfo; @@ -30,6 +29,7 @@ import mekanism.common.tile.component.TileComponentConfig; import mekanism.common.tile.component.TileComponentEjector; import mekanism.common.tile.component.TileComponentSecurity; import mekanism.common.tile.prefab.TileEntityContainerBlock; +import mekanism.common.util.TileUtils; import mekanism.common.util.GasUtils; import mekanism.common.util.InventoryUtils; import mekanism.common.util.LangUtils; @@ -104,19 +104,10 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasH { if(!world.isRemote) { - if(!inventory.get(0).isEmpty() && gasTank.getGas() != null) - { - gasTank.draw(GasUtils.addGas(inventory.get(0), gasTank.getGas()), tier != GasTankTier.CREATIVE); - } + TileUtils.drawGas(inventory.get(0), gasTank, tier != GasTankTier.CREATIVE); - if(!inventory.get(1).isEmpty() && (gasTank.getGas() == null || gasTank.getGas().amount < gasTank.getMaxGas())) - { - gasTank.receive(GasUtils.removeGas(inventory.get(1), gasTank.getGasType(), gasTank.getNeeded()), true); - - if(tier == GasTankTier.CREATIVE && gasTank.getGas() != null) - { - gasTank.getGas().amount = Integer.MAX_VALUE; - } + if (TileUtils.receiveGas(inventory.get(1), gasTank) && tier == GasTankTier.CREATIVE && gasTank.getGas() != null) { + gasTank.getGas().amount = Integer.MAX_VALUE; } if(gasTank.getGas() != null && MekanismUtils.canFunction(this) && (tier == GasTankTier.CREATIVE || dumping != GasMode.DUMPING)) @@ -319,14 +310,7 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasH tier = GasTankTier.values()[dataStream.readInt()]; gasTank.setMaxGas(tier.storage); - - if(dataStream.readBoolean()) - { - gasTank.setGas(new GasStack(GasRegistry.getGas(dataStream.readInt()), dataStream.readInt())); - } - else { - gasTank.setGas(null); - } + TileUtils.readTankData(dataStream, gasTank); dumping = GasMode.values()[dataStream.readInt()]; controlType = RedstoneControl.values()[dataStream.readInt()]; @@ -370,16 +354,7 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasH super.getNetworkedData(data); data.add(tier.ordinal()); - - if(gasTank.getGas() != null) - { - data.add(true); - data.add(gasTank.getGas().getGas().getID()); - data.add(gasTank.getStored()); - } - else { - data.add(false); - } + TileUtils.addTankData(data, gasTank); data.add(dumping.ordinal()); data.add(controlType.ordinal()); diff --git a/src/main/java/mekanism/common/tile/TileEntityPRC.java b/src/main/java/mekanism/common/tile/TileEntityPRC.java index 47af10584..292efcb6e 100644 --- a/src/main/java/mekanism/common/tile/TileEntityPRC.java +++ b/src/main/java/mekanism/common/tile/TileEntityPRC.java @@ -6,14 +6,12 @@ import java.util.Map; import mekanism.api.EnumColor; import mekanism.api.gas.Gas; -import mekanism.api.gas.GasRegistry; import mekanism.api.gas.GasStack; import mekanism.api.gas.GasTank; import mekanism.api.gas.GasTankInfo; import mekanism.api.gas.IGasHandler; import mekanism.api.gas.ITubeConnection; import mekanism.api.transmitters.TransmissionType; -import mekanism.common.PacketHandler; import mekanism.common.SideData; import mekanism.common.Upgrade; import mekanism.common.base.FluidHandlerWrapper; @@ -32,6 +30,7 @@ import mekanism.common.recipe.outputs.PressurizedOutput; import mekanism.common.tile.component.TileComponentConfig; import mekanism.common.tile.component.TileComponentEjector; import mekanism.common.tile.prefab.TileEntityBasicMachine; +import mekanism.common.util.TileUtils; import mekanism.common.util.ChargeUtils; import mekanism.common.util.InventoryUtils; import mekanism.common.util.ItemDataUtils; @@ -44,7 +43,6 @@ import net.minecraft.util.NonNullList; import net.minecraft.util.ResourceLocation; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTank; import net.minecraftforge.fluids.FluidTankInfo; @@ -218,37 +216,9 @@ public class TileEntityPRC extends TileEntityBasicMachine> extends TileEntityBasicMachine implements IGasHandler, ITubeConnection, ITierUpgradeable, ISustainedData +public abstract class TileEntityAdvancedElectricMachine> extends TileEntityUpgradeableMachine implements IGasHandler, ITubeConnection, ISustainedData { /** How much secondary energy (fuel) this machine uses per tick, not including upgrades. */ public int BASE_SECONDARY_ENERGY_PER_TICK; @@ -101,51 +98,8 @@ public abstract class TileEntityAdvancedElectricMachine> extends TileEntityBasicMachine implements ITierUpgradeable +public abstract class TileEntityDoubleElectricMachine> extends TileEntityUpgradeableMachine { /** * Double Electric Machine -- a machine like this has a total of 4 slots. Input slot (0), secondary slot (1), output slot (2), @@ -60,67 +55,14 @@ public abstract class TileEntityDoubleElectricMachine> extends TileEntityBasicMachine implements ITierUpgradeable +public abstract class TileEntityElectricMachine> extends TileEntityUpgradeableMachine { /** * A simple electrical machine. This has 3 slots - the input slot (0), the energy slot (1), @@ -59,65 +59,12 @@ public abstract class TileEntityElectricMachine, OUTPUT extends MachineOutput, RECIPE extends MachineRecipe> extends TileEntityBasicMachine implements ITierUpgradeable { + /** + * The foundation of all machines - a simple tile entity with a facing, active state, initialized state, sound effect, and animated texture. + * + * @param soundPath - location of the sound effect + * @param name - full name of this machine + * @param maxEnergy - how much energy this machine can store + * @param baseEnergyUsage + * @param upgradeSlot + * @param baseTicksRequired - how many ticks it takes to run a cycle + * @param location + */ + public TileEntityUpgradeableMachine(String soundPath, String name, double maxEnergy, double baseEnergyUsage, int upgradeSlot, int baseTicksRequired, ResourceLocation location) { + super(soundPath, name, maxEnergy, baseEnergyUsage, upgradeSlot, baseTicksRequired, location); + } + + @Override + public boolean upgrade(Tier.BaseTier upgradeTier) { + if (upgradeTier != Tier.BaseTier.BASIC) { + return false; + } + + world.setBlockToAir(getPos()); + world.setBlockState(getPos(), MekanismBlocks.MachineBlock.getStateFromMeta(5), 3); + + TileEntityFactory factory = (TileEntityFactory) world.getTileEntity(getPos()); + IFactory.RecipeType type = IFactory.RecipeType.getFromMachine(getBlockType(), getBlockMetadata()); + + //Basic + factory.facing = facing; + factory.clientFacing = clientFacing; + factory.ticker = ticker; + factory.redstone = redstone; + factory.redstoneLastTick = redstoneLastTick; + factory.doAutoSync = doAutoSync; + + //Electric + factory.electricityStored = electricityStored; + + //Machine + factory.progress[0] = operatingTicks; + factory.clientActive = clientActive; + factory.isActive = isActive; + factory.updateDelay = updateDelay; + factory.controlType = controlType; + factory.prevEnergy = prevEnergy; + factory.upgradeComponent.readFrom(upgradeComponent); + factory.upgradeComponent.setUpgradeSlot(0); + factory.ejectorComponent.readFrom(ejectorComponent); + factory.ejectorComponent.setOutputData(TransmissionType.ITEM, factory.configComponent.getOutputs(TransmissionType.ITEM).get(2)); + factory.setRecipeType(type); + factory.upgradeComponent.setSupported(Upgrade.GAS, type.fuelEnergyUpgrades()); + factory.securityComponent.readFrom(securityComponent); + + for (TransmissionType transmission : configComponent.transmissions) { + factory.configComponent.setConfig(transmission, configComponent.getConfig(transmission).asByteArray()); + factory.configComponent.setEjecting(transmission, configComponent.isEjecting(transmission)); + } + + upgradeInventory(factory); + + for (Upgrade upgrade : factory.upgradeComponent.getSupportedTypes()) { + factory.recalculateUpgradables(upgrade); + } + + factory.upgraded = true; + factory.markDirty(); + + return true; + } + + protected abstract void upgradeInventory(TileEntityFactory factory); +} \ No newline at end of file diff --git a/src/main/java/mekanism/common/util/TileUtils.java b/src/main/java/mekanism/common/util/TileUtils.java new file mode 100644 index 000000000..2e88b2f28 --- /dev/null +++ b/src/main/java/mekanism/common/util/TileUtils.java @@ -0,0 +1,83 @@ +package mekanism.common.util; + +import io.netty.buffer.ByteBuf; +import mekanism.api.gas.GasRegistry; +import mekanism.api.gas.GasStack; +import mekanism.api.gas.GasTank; +import mekanism.common.base.TileNetworkList; +import mekanism.common.tile.prefab.TileEntityBasicBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumFacing; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTank; +import net.minecraftforge.fml.common.network.ByteBufUtils; + +//TODO: Move this and factor out the parts into proper classes. This is mainly just temp to make organization not as needed +public class TileUtils { + public static void addTankData(TileNetworkList data, GasTank tank) { + if (tank.getGas() != null) { + data.add(true); + data.add(tank.getGas().getGas().getID()); + data.add(tank.getStored()); + } else { + data.add(false); + } + } + + public static void addTankData(TileNetworkList data, FluidTank tank) { + if (tank.getFluid() != null) { + data.add(true); + data.add(FluidRegistry.getFluidName(tank.getFluid())); + data.add(tank.getFluidAmount()); + } else { + data.add(false); + } + } + + public static void readTankData(ByteBuf dataStream, GasTank tank) { + if (dataStream.readBoolean()) { + tank.setGas(new GasStack(GasRegistry.getGas(dataStream.readInt()), dataStream.readInt())); + } else { + tank.setGas(null); + } + } + + public static void readTankData(ByteBuf dataStream, FluidTank tank) { + if (dataStream.readBoolean()) { + tank.setFluid(new FluidStack(FluidRegistry.getFluid(ByteBufUtils.readUTF8String(dataStream)), dataStream.readInt())); + } else { + tank.setFluid(null); + } + } + + //Returns true if it entered the if statement, basically for use by TileEntityGasTank + public static boolean receiveGas(ItemStack stack, GasTank tank) { + if (!stack.isEmpty() && (tank.getGas() == null || tank.getStored() < tank.getMaxGas())) { + tank.receive(GasUtils.removeGas(stack, tank.getGasType(), tank.getNeeded()), true); + return true; + } + return false; + } + + public static void drawGas(ItemStack stack, GasTank tank) { + drawGas(stack, tank, true); + } + + public static void drawGas(ItemStack stack, GasTank tank, boolean doDraw) { + if (!stack.isEmpty() && tank.getGas() != null) { + tank.draw(GasUtils.addGas(stack, tank.getGas()), doDraw); + } + } + + public static void emitGas(TileEntityBasicBlock tile, GasTank tank, int gasOutput) { + emitGas(tile, tank, gasOutput, MekanismUtils.getRight(tile.facing)); + } + + public static void emitGas(TileEntityBasicBlock tile, GasTank tank, int gasOutput, EnumFacing facing) { + if (tank.getGas() != null) { + GasStack toSend = new GasStack(tank.getGas().getGas(), Math.min(tank.getStored(), gasOutput)); + tank.draw(GasUtils.emit(toSend, tile, ListUtils.asList(facing)), true); + } + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/generators/common/inventory/container/ContainerBioGenerator.java b/src/main/java/mekanism/generators/common/inventory/container/ContainerBioGenerator.java index 481e3e94f..793e85df7 100644 --- a/src/main/java/mekanism/generators/common/inventory/container/ContainerBioGenerator.java +++ b/src/main/java/mekanism/generators/common/inventory/container/ContainerBioGenerator.java @@ -1,155 +1,32 @@ package mekanism.generators.common.inventory.container; import mekanism.common.inventory.slot.SlotEnergy.SlotCharge; -import mekanism.common.util.ChargeUtils; import mekanism.generators.common.tile.TileEntityBioGenerator; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidUtil; -import javax.annotation.Nonnull; +public class ContainerBioGenerator extends ContainerFuelGenerator { + public ContainerBioGenerator(InventoryPlayer inventory, TileEntityBioGenerator generator) { + super(inventory, generator); + } -public class ContainerBioGenerator extends Container -{ - private TileEntityBioGenerator tileEntity; + @Override + protected void addSlots() { + addSlotToContainer(new Slot(tileEntity, 0, 17, 35)); + addSlotToContainer(new SlotCharge(tileEntity, 1, 143, 35)); + } - public ContainerBioGenerator(InventoryPlayer inventory, TileEntityBioGenerator tentity) - { - tileEntity = tentity; - addSlotToContainer(new Slot(tentity, 0, 17, 35)); - addSlotToContainer(new SlotCharge(tentity, 1, 143, 35)); - 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, 84 + slotX * 18)); - } - } - - for(slotX = 0; slotX < 9; ++slotX) - { - addSlotToContainer(new Slot(inventory, slotX, 8 + slotX * 18, 142)); - } - - tileEntity.openInventory(inventory.player); - tileEntity.open(inventory.player); - } - - @Override - public void onContainerClosed(EntityPlayer entityplayer) - { - super.onContainerClosed(entityplayer); - - tileEntity.closeInventory(entityplayer); - tileEntity.close(entityplayer); - } - - @Override - public boolean canInteractWith(@Nonnull EntityPlayer entityplayer) - { - return tileEntity.isUsableByPlayer(entityplayer); - } - - @Nonnull - @Override - public ItemStack transferStackInSlot(EntityPlayer player, int slotID) - { - ItemStack stack = ItemStack.EMPTY; - Slot currentSlot = inventorySlots.get(slotID); - - if(currentSlot != null && currentSlot.getHasStack()) - { - ItemStack slotStack = currentSlot.getStack(); - stack = slotStack.copy(); - - if(ChargeUtils.canBeCharged(slotStack)) - { - if(slotID != 1) - { - if(!mergeItemStack(slotStack, 1, 2, false)) - { - return ItemStack.EMPTY; - } - } - else - { - if(!mergeItemStack(slotStack, 2, inventorySlots.size(), false)) - { - return ItemStack.EMPTY; - } - } - } - else if(tileEntity.getFuel(slotStack) > 0 || isBiofuel(slotStack)) - { - if(slotID != 0 && slotID != 1) - { - if (!mergeItemStack(slotStack, 0, 1, false)) - { - return ItemStack.EMPTY; - } - } - else { - if(!mergeItemStack(slotStack, 2, inventorySlots.size(), true)) - { - return ItemStack.EMPTY; - } - } - } - else { - if(slotID >= 2 && slotID <= 28) - { - if(!mergeItemStack(slotStack, 29, inventorySlots.size(), false)) - { - return ItemStack.EMPTY; - } - } - else if(slotID > 28) - { - if(!mergeItemStack(slotStack, 2, 28, false)) - { - return ItemStack.EMPTY; - } - } - else { - if(!mergeItemStack(slotStack, 2, inventorySlots.size(), true)) - { - return ItemStack.EMPTY; - } - } - } - - if(slotStack.getCount() == 0) - { - currentSlot.putStack(ItemStack.EMPTY); - } - else { - currentSlot.onSlotChanged(); - } - - if(slotStack.getCount() == stack.getCount()) - { - return ItemStack.EMPTY; - } - - currentSlot.onTake(player, slotStack); - } - - return stack; - } - - private boolean isBiofuel(ItemStack itemStack) - { - if(FluidRegistry.isFluidRegistered("bioethanol")) - { - return FluidUtil.getFluidContained(itemStack) != null && FluidUtil.getFluidContained(itemStack).getFluid() == FluidRegistry.getFluid("bioethanol"); - } - - return false; - } -} + @Override + protected boolean tryFuel(ItemStack slotStack) { + if (((TileEntityBioGenerator) tileEntity).getFuel(slotStack) > 0) { + return true; + } + if (FluidRegistry.isFluidRegistered("bioethanol")) { + return FluidUtil.getFluidContained(slotStack) != null && FluidUtil.getFluidContained(slotStack).getFluid() == FluidRegistry.getFluid("bioethanol"); + } + return false; + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/generators/common/inventory/container/ContainerFuelGenerator.java b/src/main/java/mekanism/generators/common/inventory/container/ContainerFuelGenerator.java new file mode 100644 index 000000000..b1fb9ebbc --- /dev/null +++ b/src/main/java/mekanism/generators/common/inventory/container/ContainerFuelGenerator.java @@ -0,0 +1,77 @@ +package mekanism.generators.common.inventory.container; + +import mekanism.common.tile.prefab.TileEntityElectricBlock; +import mekanism.common.util.ChargeUtils; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +import javax.annotation.Nonnull; + +public abstract class ContainerFuelGenerator extends ContainerGenerator { + protected ContainerFuelGenerator(InventoryPlayer inventory, TileEntityElectricBlock generator) { + super(inventory, generator); + } + + @Nonnull + @Override + public ItemStack transferStackInSlot(EntityPlayer player, int slotID) { + ItemStack stack = ItemStack.EMPTY; + Slot currentSlot = inventorySlots.get(slotID); + + if (currentSlot != null && currentSlot.getHasStack()) { + ItemStack slotStack = currentSlot.getStack(); + stack = slotStack.copy(); + + if (ChargeUtils.canBeCharged(slotStack)) { + if (slotID != 1) { + if (!mergeItemStack(slotStack, 1, 2, false)) { + return ItemStack.EMPTY; + } + } else if (!mergeItemStack(slotStack, 2, inventorySlots.size(), false)) { + return ItemStack.EMPTY; + } + } else if (tryFuel(slotStack)) { + return handleFuel(slotStack, slotID); + } else if (slotID >= 2 && slotID <= 28) { + if (!mergeItemStack(slotStack, 29, inventorySlots.size(), false)) { + return ItemStack.EMPTY; + } + } else if (slotID > 28) { + if (!mergeItemStack(slotStack, 2, 28, false)) { + return ItemStack.EMPTY; + } + } else if (!mergeItemStack(slotStack, 2, inventorySlots.size(), true)) { + return ItemStack.EMPTY; + } + + if (slotStack.getCount() == 0) { + currentSlot.putStack(ItemStack.EMPTY); + } else { + currentSlot.onSlotChanged(); + } + + if (slotStack.getCount() == stack.getCount()) { + return ItemStack.EMPTY; + } + + currentSlot.onTake(player, slotStack); + } + + return stack; + } + + protected abstract boolean tryFuel(ItemStack slotStack); + + protected ItemStack handleFuel(ItemStack slotStack, int slotID) { + if (slotID != 0 && slotID != 1) { + if (!mergeItemStack(slotStack, 0, 1, false)) { + return ItemStack.EMPTY; + } + } else if (!mergeItemStack(slotStack, 2, inventorySlots.size(), true)) { + return ItemStack.EMPTY; + } + return slotStack; + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/generators/common/inventory/container/ContainerGasGenerator.java b/src/main/java/mekanism/generators/common/inventory/container/ContainerGasGenerator.java index e15d151b0..df60a41bd 100644 --- a/src/main/java/mekanism/generators/common/inventory/container/ContainerGasGenerator.java +++ b/src/main/java/mekanism/generators/common/inventory/container/ContainerGasGenerator.java @@ -3,145 +3,38 @@ package mekanism.generators.common.inventory.container; import mekanism.api.gas.IGasItem; import mekanism.common.MekanismFluids; import mekanism.common.inventory.slot.SlotEnergy.SlotCharge; -import mekanism.common.util.ChargeUtils; import mekanism.generators.common.tile.TileEntityGasGenerator; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -import javax.annotation.Nonnull; +public class ContainerGasGenerator extends ContainerFuelGenerator { + public ContainerGasGenerator(InventoryPlayer inventory, TileEntityGasGenerator generator) { + super(inventory, generator); + } -public class ContainerGasGenerator extends Container -{ - private TileEntityGasGenerator tileEntity; + @Override + protected void addSlots() { + addSlotToContainer(new Slot(tileEntity, 0, 17, 35)); + addSlotToContainer(new SlotCharge(tileEntity, 1, 143, 35)); + } - public ContainerGasGenerator(InventoryPlayer inventory, TileEntityGasGenerator tentity) - { - tileEntity = tentity; - addSlotToContainer(new Slot(tentity, 0, 17, 35)); - addSlotToContainer(new SlotCharge(tentity, 1, 143, 35)); - int slotX; + @Override + protected boolean tryFuel(ItemStack slotStack) { + return slotStack.getItem() instanceof IGasItem; + } - for(slotX = 0; slotX < 3; ++slotX) - { - for(int slotY = 0; slotY < 9; ++slotY) - { - addSlotToContainer(new Slot(inventory, slotY + slotX * 9 + 9, 8 + slotY * 18, 84 + slotX * 18)); - } - } - - for(slotX = 0; slotX < 9; ++slotX) - { - addSlotToContainer(new Slot(inventory, slotX, 8 + slotX * 18, 142)); - } - - tileEntity.openInventory(inventory.player); - tileEntity.open(inventory.player); - } - - @Override - public void onContainerClosed(EntityPlayer entityplayer) - { - super.onContainerClosed(entityplayer); - tileEntity.closeInventory(entityplayer); - tileEntity.close(entityplayer); - } - - @Override - public boolean canInteractWith(@Nonnull EntityPlayer entityplayer) - { - return tileEntity.isUsableByPlayer(entityplayer); - } - - @Nonnull - @Override - public ItemStack transferStackInSlot(EntityPlayer player, int slotID) - { - ItemStack stack = ItemStack.EMPTY; - Slot currentSlot = inventorySlots.get(slotID); - - if(currentSlot != null && currentSlot.getHasStack()) - { - ItemStack slotStack = currentSlot.getStack(); - stack = slotStack.copy(); - - if(ChargeUtils.canBeCharged(slotStack)) - { - if(slotID != 1) - { - if(!mergeItemStack(slotStack, 1, 2, false)) - { - return ItemStack.EMPTY; - } - } - else - { - if(!mergeItemStack(slotStack, 2, inventorySlots.size(), false)) - { - return ItemStack.EMPTY; - } - } - } - else if(slotStack.getItem() instanceof IGasItem) - { - if(slotID != 0 && slotID != 1) - { - if(((IGasItem)slotStack.getItem()).getGas(slotStack) != null && ((IGasItem)slotStack.getItem()).getGas(slotStack).getGas() == MekanismFluids.Hydrogen) - { - if(!mergeItemStack(slotStack, 0, 1, false)) - { - return ItemStack.EMPTY; - } - } - } - else { - if(!mergeItemStack(slotStack, 2, inventorySlots.size(), true)) - { - return ItemStack.EMPTY; - } - } - } - else { - if(slotID >= 2 && slotID <= 28) - { - if(!mergeItemStack(slotStack, 29, inventorySlots.size(), false)) - { - return ItemStack.EMPTY; - } - } - else if(slotID > 28) - { - if(!mergeItemStack(slotStack, 2, 28, false)) - { - return ItemStack.EMPTY; - } - } - else { - if(!mergeItemStack(slotStack, 2, inventorySlots.size(), true)) - { - return ItemStack.EMPTY; - } - } - } - - if(slotStack.getCount() == 0) - { - currentSlot.putStack(ItemStack.EMPTY); - } - else { - currentSlot.onSlotChanged(); - } - - if(slotStack.getCount() == stack.getCount()) - { - return ItemStack.EMPTY; - } - - currentSlot.onTake(player, slotStack); - } - - return stack; - } -} + @Override + protected ItemStack handleFuel(ItemStack slotStack, int slotID) { + if (slotID != 0 && slotID != 1) { + if (((IGasItem) slotStack.getItem()).getGas(slotStack) != null && ((IGasItem) slotStack.getItem()).getGas(slotStack).getGas() == MekanismFluids.Hydrogen) { + if (!mergeItemStack(slotStack, 0, 1, false)) { + return ItemStack.EMPTY; + } + } + } else if (!mergeItemStack(slotStack, 2, inventorySlots.size(), true)) { + return ItemStack.EMPTY; + } + return slotStack; + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/generators/common/inventory/container/ContainerGenerator.java b/src/main/java/mekanism/generators/common/inventory/container/ContainerGenerator.java new file mode 100644 index 000000000..df0b2bc13 --- /dev/null +++ b/src/main/java/mekanism/generators/common/inventory/container/ContainerGenerator.java @@ -0,0 +1,46 @@ +package mekanism.generators.common.inventory.container; + +import mekanism.common.tile.prefab.TileEntityElectricBlock; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.Slot; + +import javax.annotation.Nonnull; + +public abstract class ContainerGenerator extends Container { + protected TileEntityElectricBlock tileEntity; + + protected ContainerGenerator(InventoryPlayer inventory, TileEntityElectricBlock generator) { + this.tileEntity = generator; + addSlots(); + 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, 84 + slotX * 18)); + } + } + + for (slotX = 0; slotX < 9; slotX++) { + addSlotToContainer(new Slot(inventory, slotX, 8 + slotX * 18, 142)); + } + + tileEntity.openInventory(inventory.player); + tileEntity.open(inventory.player); + } + + protected abstract void addSlots(); + + @Override + public void onContainerClosed(EntityPlayer entityplayer) { + super.onContainerClosed(entityplayer); + tileEntity.closeInventory(entityplayer); + tileEntity.close(entityplayer); + } + + @Override + public boolean canInteractWith(@Nonnull EntityPlayer entityplayer) { + return tileEntity.isUsableByPlayer(entityplayer); + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/generators/common/inventory/container/ContainerHeatGenerator.java b/src/main/java/mekanism/generators/common/inventory/container/ContainerHeatGenerator.java index fc5bc5268..930fe0cb5 100644 --- a/src/main/java/mekanism/generators/common/inventory/container/ContainerHeatGenerator.java +++ b/src/main/java/mekanism/generators/common/inventory/container/ContainerHeatGenerator.java @@ -1,143 +1,24 @@ package mekanism.generators.common.inventory.container; import mekanism.common.inventory.slot.SlotEnergy.SlotCharge; -import mekanism.common.util.ChargeUtils; import mekanism.generators.common.tile.TileEntityHeatGenerator; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -import javax.annotation.Nonnull; +public class ContainerHeatGenerator extends ContainerFuelGenerator { + public ContainerHeatGenerator(InventoryPlayer inventory, TileEntityHeatGenerator generator) { + super(inventory, generator); + } -public class ContainerHeatGenerator extends Container -{ - private TileEntityHeatGenerator tileEntity; + @Override + protected void addSlots() { + addSlotToContainer(new Slot(tileEntity, 0, 17, 35)); + addSlotToContainer(new SlotCharge(tileEntity, 1, 143, 35)); + } - public ContainerHeatGenerator(InventoryPlayer inventory, TileEntityHeatGenerator tentity) - { - tileEntity = tentity; - addSlotToContainer(new Slot(tentity, 0, 17, 35)); - addSlotToContainer(new SlotCharge(tentity, 1, 143, 35)); - 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, 84 + slotX * 18)); - } - } - - for(slotX = 0; slotX < 9; ++slotX) - { - addSlotToContainer(new Slot(inventory, slotX, 8 + slotX * 18, 142)); - } - - tileEntity.openInventory(inventory.player); - tileEntity.open(inventory.player); - } - - @Override - public void onContainerClosed(EntityPlayer entityplayer) - { - super.onContainerClosed(entityplayer); - - tileEntity.closeInventory(entityplayer); - tileEntity.close(entityplayer); - } - - @Override - public boolean canInteractWith(@Nonnull EntityPlayer entityplayer) - { - return tileEntity.isUsableByPlayer(entityplayer); - } - - @Nonnull - @Override - public ItemStack transferStackInSlot(EntityPlayer player, int slotID) - { - ItemStack stack = ItemStack.EMPTY; - Slot currentSlot = inventorySlots.get(slotID); - - if(currentSlot != null && currentSlot.getHasStack()) - { - ItemStack slotStack = currentSlot.getStack(); - stack = slotStack.copy(); - - if(ChargeUtils.canBeCharged(slotStack)) - { - if(slotID != 1) - { - if(!mergeItemStack(slotStack, 1, 2, false)) - { - return ItemStack.EMPTY; - } - } - else - { - if(!mergeItemStack(slotStack, 2, inventorySlots.size(), false)) - { - return ItemStack.EMPTY; - } - } - } - else if(tileEntity.getFuel(slotStack) > 0) - { - if(slotID != 0 && slotID != 1) - { - if(!mergeItemStack(slotStack, 0, 1, false)) - { - return ItemStack.EMPTY; - } - } - else { - if(!mergeItemStack(slotStack, 2, inventorySlots.size(), true)) - { - return ItemStack.EMPTY; - } - } - } - else { - if(slotID >= 2 && slotID <= 28) - { - if(!mergeItemStack(slotStack, 29, inventorySlots.size(), false)) - { - return ItemStack.EMPTY; - } - } - else if(slotID > 28) - { - if(!mergeItemStack(slotStack, 2, 28, false)) - { - return ItemStack.EMPTY; - } - } - else { - if(!mergeItemStack(slotStack, 2, inventorySlots.size(), true)) - { - return ItemStack.EMPTY; - } - } - } - - if(slotStack.getCount() == 0) - { - currentSlot.putStack(ItemStack.EMPTY); - } - else { - currentSlot.onSlotChanged(); - } - - if(slotStack.getCount() == stack.getCount()) - { - return ItemStack.EMPTY; - } - - currentSlot.onTake(player, slotStack); - } - - return stack; - } -} + @Override + protected boolean tryFuel(ItemStack slotStack) { + return ((TileEntityHeatGenerator) tileEntity).getFuel(slotStack) > 0; + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/generators/common/inventory/container/ContainerPassiveGenerator.java b/src/main/java/mekanism/generators/common/inventory/container/ContainerPassiveGenerator.java new file mode 100644 index 000000000..59920d5d0 --- /dev/null +++ b/src/main/java/mekanism/generators/common/inventory/container/ContainerPassiveGenerator.java @@ -0,0 +1,64 @@ +package mekanism.generators.common.inventory.container; + +import mekanism.common.tile.prefab.TileEntityElectricBlock; +import mekanism.common.util.ChargeUtils; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +import javax.annotation.Nonnull; + +public abstract class ContainerPassiveGenerator extends ContainerGenerator { + protected ContainerPassiveGenerator(InventoryPlayer inventory, TileEntityElectricBlock generator) { + super(inventory, generator); + } + + @Nonnull + @Override + public ItemStack transferStackInSlot(EntityPlayer player, int slotID) { + ItemStack stack = ItemStack.EMPTY; + Slot currentSlot = inventorySlots.get(slotID); + + if (currentSlot != null && currentSlot.getHasStack()) { + ItemStack slotStack = currentSlot.getStack(); + stack = slotStack.copy(); + + if (ChargeUtils.canBeCharged(slotStack)) { + if (slotID != 0) { + if (!mergeItemStack(slotStack, 0, 1, false)) { + return ItemStack.EMPTY; + } + } else if (!mergeItemStack(slotStack, 1, inventorySlots.size(), false)) { + return ItemStack.EMPTY; + } + } else { + if (slotID >= 1 && slotID <= 27) { + if (!mergeItemStack(slotStack, 28, inventorySlots.size(), false)) { + return ItemStack.EMPTY; + } + } else if (slotID > 27) { + if (!mergeItemStack(slotStack, 1, 27, false)) { + return ItemStack.EMPTY; + } + } else if (!mergeItemStack(slotStack, 1, inventorySlots.size(), true)) { + return ItemStack.EMPTY; + } + } + + if (slotStack.getCount() == 0) { + currentSlot.putStack(ItemStack.EMPTY); + } else { + currentSlot.onSlotChanged(); + } + + if (slotStack.getCount() == stack.getCount()) { + return ItemStack.EMPTY; + } + + currentSlot.onTake(player, slotStack); + } + + return stack; + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/generators/common/inventory/container/ContainerReactorController.java b/src/main/java/mekanism/generators/common/inventory/container/ContainerReactorController.java index 84a952db1..1992bf51b 100644 --- a/src/main/java/mekanism/generators/common/inventory/container/ContainerReactorController.java +++ b/src/main/java/mekanism/generators/common/inventory/container/ContainerReactorController.java @@ -5,7 +5,6 @@ import mekanism.generators.common.item.ItemHohlraum; import mekanism.generators.common.tile.reactor.TileEntityReactorController; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; @@ -14,131 +13,72 @@ import net.minecraftforge.fml.relauncher.SideOnly; import javax.annotation.Nonnull; -public class ContainerReactorController extends Container -{ - private TileEntityReactorController tileEntity; +public class ContainerReactorController extends ContainerGenerator { + public ContainerReactorController(InventoryPlayer inventory, TileEntityReactorController generator) { + super(inventory, generator); - public ContainerReactorController(InventoryPlayer inventory, TileEntityReactorController tentity) - { - tileEntity = tentity; - addSlotToContainer(new SlotReactor(tentity, 0, 80, 39)); - 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, 84 + slotX * 18)); - } - } + @Override + protected void addSlots() { + addSlotToContainer(new SlotReactor(tileEntity, 0, 80, 39)); + } - for(slotX = 0; slotX < 9; slotX++) - { - addSlotToContainer(new Slot(inventory, slotX, 8 + slotX * 18, 142)); - } + @Nonnull + @Override + public ItemStack transferStackInSlot(EntityPlayer player, int slotID) { + ItemStack stack = ItemStack.EMPTY; + Slot currentSlot = inventorySlots.get(slotID); - tileEntity.openInventory(inventory.player); - tileEntity.open(inventory.player); - } + if (currentSlot != null && currentSlot.getHasStack()) { + ItemStack slotStack = currentSlot.getStack(); + stack = slotStack.copy(); - @Override - public void onContainerClosed(EntityPlayer entityplayer) - { - super.onContainerClosed(entityplayer); + if (slotStack.getItem() instanceof ItemHohlraum) { + if (slotID != 0) { + if (!mergeItemStack(slotStack, 0, 1, false)) { + return ItemStack.EMPTY; + } + } else if (!mergeItemStack(slotStack, 1, inventorySlots.size(), false)) { + return ItemStack.EMPTY; + } + } else if (slotID >= 1 && slotID <= 27) { + if (!mergeItemStack(slotStack, 28, inventorySlots.size(), false)) { + return ItemStack.EMPTY; + } + } else if (slotID > 27) { + if (!mergeItemStack(slotStack, 1, 27, false)) { + return ItemStack.EMPTY; + } + } else if (!mergeItemStack(slotStack, 1, inventorySlots.size(), true)) { + return ItemStack.EMPTY; + } - tileEntity.closeInventory(entityplayer); - tileEntity.close(entityplayer); - } + if (slotStack.getCount() == 0) { + currentSlot.putStack(ItemStack.EMPTY); + } else { + currentSlot.onSlotChanged(); + } - @Override - public boolean canInteractWith(@Nonnull EntityPlayer entityplayer) - { - return tileEntity.isUsableByPlayer(entityplayer); - } + if (slotStack.getCount() == stack.getCount()) { + return ItemStack.EMPTY; + } - @Nonnull - @Override - public ItemStack transferStackInSlot(EntityPlayer player, int slotID) - { - ItemStack stack = ItemStack.EMPTY; - Slot currentSlot = inventorySlots.get(slotID); + currentSlot.onTake(player, slotStack); + } - if(currentSlot != null && currentSlot.getHasStack()) - { - ItemStack slotStack = currentSlot.getStack(); - stack = slotStack.copy(); + return stack; + } - if(slotStack.getItem() instanceof ItemHohlraum) - { - if(slotID != 0) - { - if(!mergeItemStack(slotStack, 0, 1, false)) - { - return ItemStack.EMPTY; - } - } - else - { - if(!mergeItemStack(slotStack, 1, inventorySlots.size(), false)) - { - return ItemStack.EMPTY; - } - } - } - else { - if(slotID >= 1 && slotID <= 27) - { - if(!mergeItemStack(slotStack, 28, inventorySlots.size(), false)) - { - return ItemStack.EMPTY; - } - } - else if(slotID > 27) - { - if(!mergeItemStack(slotStack, 1, 27, false)) - { - return ItemStack.EMPTY; - } - } - else { - if(!mergeItemStack(slotStack, 1, inventorySlots.size(), true)) - { - return ItemStack.EMPTY; - } - } - } + public class SlotReactor extends Slot { + public SlotReactor(IInventory inventory, int index, int x, int y) { + super(inventory, index, x, y); + } - if(slotStack.getCount() == 0) - { - currentSlot.putStack(ItemStack.EMPTY); - } - else { - currentSlot.onSlotChanged(); - } - - if(slotStack.getCount() == stack.getCount()) - { - return ItemStack.EMPTY; - } - - currentSlot.onTake(player, slotStack); - } - - return stack; - } - - public class SlotReactor extends Slot - { - public SlotReactor(IInventory inventory, int index, int x, int y) - { - super(inventory, index, x, y); - } - - @Override - @SideOnly(Side.CLIENT) - public boolean isEnabled() - { - return tileEntity != null && MekanismUtils.isActive(tileEntity.getWorld(), tileEntity.getPos()); - } - } -} + @Override + @SideOnly(Side.CLIENT) + public boolean isEnabled() { + return tileEntity != null && MekanismUtils.isActive(tileEntity.getWorld(), tileEntity.getPos()); + } + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/generators/common/inventory/container/ContainerSolarGenerator.java b/src/main/java/mekanism/generators/common/inventory/container/ContainerSolarGenerator.java index 6ad806fca..6cdd1991d 100644 --- a/src/main/java/mekanism/generators/common/inventory/container/ContainerSolarGenerator.java +++ b/src/main/java/mekanism/generators/common/inventory/container/ContainerSolarGenerator.java @@ -1,126 +1,16 @@ package mekanism.generators.common.inventory.container; import mekanism.common.inventory.slot.SlotEnergy.SlotCharge; -import mekanism.common.util.ChargeUtils; import mekanism.generators.common.tile.TileEntitySolarGenerator; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import javax.annotation.Nonnull; +public class ContainerSolarGenerator extends ContainerGenerator { + public ContainerSolarGenerator(InventoryPlayer inventory, TileEntitySolarGenerator generator) { + super(inventory, generator); + } -public class ContainerSolarGenerator extends Container -{ - private TileEntitySolarGenerator tileEntity; - - public ContainerSolarGenerator(InventoryPlayer inventory, TileEntitySolarGenerator tentity) - { - tileEntity = tentity; - addSlotToContainer(new SlotCharge(tentity, 0, 143, 35)); - 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, 84 + slotX * 18)); - } - } - - for(slotX = 0; slotX < 9; ++slotX) - { - addSlotToContainer(new Slot(inventory, slotX, 8 + slotX * 18, 142)); - } - - tileEntity.openInventory(inventory.player); - tileEntity.open(inventory.player); - } - - @Override - public void onContainerClosed(EntityPlayer entityplayer) - { - super.onContainerClosed(entityplayer); - - tileEntity.closeInventory(entityplayer); - tileEntity.close(entityplayer); - } - - @Override - public boolean canInteractWith(@Nonnull EntityPlayer entityplayer) - { - return tileEntity.isUsableByPlayer(entityplayer); - } - - @Nonnull - @Override - public ItemStack transferStackInSlot(EntityPlayer player, int slotID) - { - ItemStack stack = ItemStack.EMPTY; - Slot currentSlot = inventorySlots.get(slotID); - - if(currentSlot != null && currentSlot.getHasStack()) - { - ItemStack slotStack = currentSlot.getStack(); - stack = slotStack.copy(); - - if(ChargeUtils.canBeCharged(slotStack)) - { - if(slotID != 0) - { - if(!mergeItemStack(slotStack, 0, 1, false)) - { - return ItemStack.EMPTY; - } - } - else - { - if(!mergeItemStack(slotStack, 1, inventorySlots.size(), false)) - { - return ItemStack.EMPTY; - } - } - } - else { - if(slotID >= 1 && slotID <= 27) - { - if(!mergeItemStack(slotStack, 28, inventorySlots.size(), false)) - { - return ItemStack.EMPTY; - } - } - else if(slotID > 27) - { - if(!mergeItemStack(slotStack, 1, 27, false)) - { - return ItemStack.EMPTY; - } - } - else { - if(!mergeItemStack(slotStack, 1, inventorySlots.size(), true)) - { - return ItemStack.EMPTY; - } - } - } - - if(slotStack.getCount() == 0) - { - currentSlot.putStack(ItemStack.EMPTY); - } - else { - currentSlot.onSlotChanged(); - } - - if(slotStack.getCount() == stack.getCount()) - { - return ItemStack.EMPTY; - } - - currentSlot.onTake(player, slotStack); - } - - return stack; - } -} + @Override + protected void addSlots() { + addSlotToContainer(new SlotCharge(tileEntity, 0, 143, 35)); + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/generators/common/inventory/container/ContainerWindGenerator.java b/src/main/java/mekanism/generators/common/inventory/container/ContainerWindGenerator.java index 1255e6e2a..73d83bc7f 100644 --- a/src/main/java/mekanism/generators/common/inventory/container/ContainerWindGenerator.java +++ b/src/main/java/mekanism/generators/common/inventory/container/ContainerWindGenerator.java @@ -1,126 +1,16 @@ package mekanism.generators.common.inventory.container; import mekanism.common.inventory.slot.SlotEnergy.SlotCharge; -import mekanism.common.util.ChargeUtils; import mekanism.generators.common.tile.TileEntityWindGenerator; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import javax.annotation.Nonnull; +public class ContainerWindGenerator extends ContainerGenerator { + public ContainerWindGenerator(InventoryPlayer inventory, TileEntityWindGenerator generator) { + super(inventory, generator); + } -public class ContainerWindGenerator extends Container -{ - private TileEntityWindGenerator tileEntity; - - public ContainerWindGenerator(InventoryPlayer inventory, TileEntityWindGenerator tentity) - { - tileEntity = tentity; - addSlotToContainer(new SlotCharge(tentity, 0, 143, 35)); - 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, 84 + slotX * 18)); - } - } - - for(slotX = 0; slotX < 9; ++slotX) - { - addSlotToContainer(new Slot(inventory, slotX, 8 + slotX * 18, 142)); - } - - tileEntity.openInventory(inventory.player); - tileEntity.open(inventory.player); - } - - @Override - public void onContainerClosed(EntityPlayer entityplayer) - { - super.onContainerClosed(entityplayer); - - tileEntity.closeInventory(entityplayer); - tileEntity.close(entityplayer); - } - - @Override - public boolean canInteractWith(@Nonnull EntityPlayer entityplayer) - { - return tileEntity.isUsableByPlayer(entityplayer); - } - - @Nonnull - @Override - public ItemStack transferStackInSlot(EntityPlayer player, int slotID) - { - ItemStack stack = ItemStack.EMPTY; - Slot currentSlot = inventorySlots.get(slotID); - - if(currentSlot != null && currentSlot.getHasStack()) - { - ItemStack slotStack = currentSlot.getStack(); - stack = slotStack.copy(); - - if(ChargeUtils.canBeCharged(slotStack)) - { - if(slotID != 0) - { - if(!mergeItemStack(slotStack, 0, 1, false)) - { - return ItemStack.EMPTY; - } - } - else - { - if(!mergeItemStack(slotStack, 1, inventorySlots.size(), false)) - { - return ItemStack.EMPTY; - } - } - } - else { - if(slotID >= 1 && slotID <= 27) - { - if(!mergeItemStack(slotStack, 28, inventorySlots.size(), false)) - { - return ItemStack.EMPTY; - } - } - else if(slotID > 27) - { - if(!mergeItemStack(slotStack, 1, 27, false)) - { - return ItemStack.EMPTY; - } - } - else { - if(!mergeItemStack(slotStack, 1, inventorySlots.size(), true)) - { - return ItemStack.EMPTY; - } - } - } - - if(slotStack.getCount() == 0) - { - currentSlot.putStack(ItemStack.EMPTY); - } - else { - currentSlot.onSlotChanged(); - } - - if(slotStack.getCount() == stack.getCount()) - { - return ItemStack.EMPTY; - } - - currentSlot.onTake(player, slotStack); - } - - return stack; - } -} + @Override + protected void addSlots() { + addSlotToContainer(new SlotCharge(tileEntity, 0, 143, 35)); + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/tools/common/ToolUtils.java b/src/main/java/mekanism/tools/common/ToolUtils.java new file mode 100644 index 000000000..66dad5a11 --- /dev/null +++ b/src/main/java/mekanism/tools/common/ToolUtils.java @@ -0,0 +1,53 @@ +package mekanism.tools.common; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; +import net.minecraft.item.Item.ToolMaterial; + +import javax.annotation.Nonnull; + +public class ToolUtils { + public static boolean canPickaxeHarvest(@Nonnull IBlockState state, ToolMaterial toolMaterial) { + Block block = state.getBlock(); + + if (block == Blocks.OBSIDIAN) { + return toolMaterial.getHarvestLevel() == 3; + } + + if (block == Blocks.DIAMOND_BLOCK || block == Blocks.DIAMOND_ORE) { + return toolMaterial.getHarvestLevel() >= 2; + } + + if (block == Blocks.GOLD_BLOCK || block == Blocks.GOLD_ORE) { + return toolMaterial.getHarvestLevel() >= 2; + } + + if (block == Blocks.IRON_BLOCK || block == Blocks.IRON_ORE) { + return toolMaterial.getHarvestLevel() >= 1; + } + + if (block == Blocks.LAPIS_BLOCK || block == Blocks.LAPIS_ORE) { + return toolMaterial.getHarvestLevel() >= 1; + } + + if (block == Blocks.REDSTONE_ORE || block == Blocks.LIT_REDSTONE_ORE) { + return toolMaterial.getHarvestLevel() >= 2; + } + + if (block == Blocks.ANVIL) { + return toolMaterial.getHarvestLevel() >= 0; + } + + if (state.getMaterial() == Material.ROCK) { + return true; + } + + return state.getMaterial() == Material.IRON; + } + + public static boolean canShovelHarvest(Block block) { + return block == Blocks.SNOW_LAYER || block == Blocks.SNOW; + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/tools/item/ItemMekanismPaxel.java b/src/main/java/mekanism/tools/item/ItemMekanismPaxel.java index b6f4f291a..3d6307f03 100644 --- a/src/main/java/mekanism/tools/item/ItemMekanismPaxel.java +++ b/src/main/java/mekanism/tools/item/ItemMekanismPaxel.java @@ -1,78 +1,26 @@ package mekanism.tools.item; -import java.util.HashSet; - +import mekanism.tools.common.ToolUtils; import net.minecraft.block.Block; -import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import javax.annotation.Nonnull; +import java.util.HashSet; -public class ItemMekanismPaxel extends ItemMekanismTool -{ - public ItemMekanismPaxel(ToolMaterial toolMaterial) - { - super(4, -2.4F, toolMaterial, new HashSet<>()); - } +public class ItemMekanismPaxel extends ItemMekanismTool { + public ItemMekanismPaxel(ToolMaterial toolMaterial) { + super(4, -2.4F, toolMaterial, new HashSet<>()); + } - @Override - public float getDestroySpeed(@Nonnull ItemStack stack, IBlockState blockState) - { - return blockState.getBlock() != Blocks.BEDROCK ? efficiency : 1.0F; - } + @Override + public float getDestroySpeed(@Nonnull ItemStack stack, IBlockState blockState) { + return blockState.getBlock() != Blocks.BEDROCK ? efficiency : 1.0F; + } - @Override - public boolean canHarvestBlock(@Nonnull IBlockState state, ItemStack stack) - { - Block block = state.getBlock(); - - if(block == Blocks.OBSIDIAN) - { - return toolMaterial.getHarvestLevel() == 3; - } - - if(block == Blocks.DIAMOND_BLOCK || block == Blocks.DIAMOND_ORE) - { - return toolMaterial.getHarvestLevel() >= 2; - } - - if(block == Blocks.GOLD_BLOCK || block == Blocks.GOLD_ORE) - { - return toolMaterial.getHarvestLevel() >= 2; - } - - if(block == Blocks.IRON_BLOCK || block == Blocks.IRON_ORE) - { - return toolMaterial.getHarvestLevel() >= 1; - } - - if(block == Blocks.LAPIS_BLOCK || block == Blocks.LAPIS_ORE) - { - return toolMaterial.getHarvestLevel() >= 1; - } - - if(block == Blocks.REDSTONE_ORE || block == Blocks.LIT_REDSTONE_ORE) - { - return toolMaterial.getHarvestLevel() >= 2; - } - - if(block == Blocks.ANVIL) - { - return toolMaterial.getHarvestLevel() >= 0; - } - - if(block == Blocks.SNOW || block == Blocks.SNOW_LAYER) - { - return true; - } - - if(state.getMaterial() == Material.ROCK) - { - return true; - } - - return state.getMaterial() == Material.IRON; - } -} + @Override + public boolean canHarvestBlock(@Nonnull IBlockState state, ItemStack stack) { + return ToolUtils.canShovelHarvest(state.getBlock()) || ToolUtils.canPickaxeHarvest(state, toolMaterial); + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/tools/item/ItemMekanismPickaxe.java b/src/main/java/mekanism/tools/item/ItemMekanismPickaxe.java index d6969d5e1..26f67ee46 100644 --- a/src/main/java/mekanism/tools/item/ItemMekanismPickaxe.java +++ b/src/main/java/mekanism/tools/item/ItemMekanismPickaxe.java @@ -1,83 +1,34 @@ package mekanism.tools.item; -import java.util.Set; - +import com.google.common.collect.Sets; +import mekanism.tools.common.ToolUtils; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; -import com.google.common.collect.Sets; - import javax.annotation.Nonnull; +import java.util.Set; -public class ItemMekanismPickaxe extends ItemMekanismTool -{ +public class ItemMekanismPickaxe extends ItemMekanismTool { private static final Set EFFECTIVE_ON = Sets.newHashSet(Blocks.ACTIVATOR_RAIL, Blocks.COAL_ORE, Blocks.COBBLESTONE, Blocks.DETECTOR_RAIL, Blocks.DIAMOND_BLOCK, Blocks.DIAMOND_ORE, Blocks.DOUBLE_STONE_SLAB, Blocks.GOLDEN_RAIL, Blocks.GOLD_BLOCK, Blocks.GOLD_ORE, Blocks.ICE, Blocks.IRON_BLOCK, Blocks.IRON_ORE, Blocks.LAPIS_BLOCK, Blocks.LAPIS_ORE, Blocks.LIT_REDSTONE_ORE, Blocks.MOSSY_COBBLESTONE, Blocks.NETHERRACK, Blocks.PACKED_ICE, Blocks.RAIL, Blocks.REDSTONE_ORE, Blocks.SANDSTONE, Blocks.RED_SANDSTONE, Blocks.STONE, Blocks.STONE_SLAB, Blocks.STONE_BUTTON, Blocks.STONE_PRESSURE_PLATE); - public ItemMekanismPickaxe(ToolMaterial toolMaterial) - { - super(1, -2.8F, toolMaterial, EFFECTIVE_ON); - } + public ItemMekanismPickaxe(ToolMaterial toolMaterial) { + super(1, -2.8F, toolMaterial, EFFECTIVE_ON); + } - @Override - public boolean canHarvestBlock(@Nonnull IBlockState state, ItemStack stack) - { - Block block = state.getBlock(); - - if(block == Blocks.OBSIDIAN) - { - return toolMaterial.getHarvestLevel() == 3; - } + @Override + public boolean canHarvestBlock(@Nonnull IBlockState state, ItemStack stack) { + return ToolUtils.canPickaxeHarvest(state, toolMaterial); + } - if(block == Blocks.DIAMOND_BLOCK || block == Blocks.DIAMOND_ORE) - { - return toolMaterial.getHarvestLevel() >= 2; - } - - if(block == Blocks.GOLD_BLOCK || block == Blocks.GOLD_ORE) - { - return toolMaterial.getHarvestLevel() >= 2; - } - - if(block == Blocks.IRON_BLOCK || block == Blocks.IRON_ORE) - { - return toolMaterial.getHarvestLevel() >= 1; - } - - if(block == Blocks.LAPIS_BLOCK || block == Blocks.LAPIS_ORE) - { - return toolMaterial.getHarvestLevel() >= 1; - } - - if(block == Blocks.REDSTONE_ORE || block == Blocks.LIT_REDSTONE_ORE) - { - return toolMaterial.getHarvestLevel() >= 2; - } - - if(block == Blocks.ANVIL) - { - return toolMaterial.getHarvestLevel() >= 0; - } - - if(state.getMaterial() == Material.ROCK) - { - return true; - } - - return state.getMaterial() == Material.IRON; - } - - @Override - public float getDestroySpeed(@Nonnull ItemStack itemstack, IBlockState blockState) - { - if(blockState != null && (blockState.getMaterial() == Material.IRON || blockState.getMaterial() == Material.ANVIL || blockState.getMaterial() == Material.ROCK)) - { - return efficiency; - } - else { - return super.getDestroySpeed(itemstack, blockState); - } - } -} + @Override + public float getDestroySpeed(@Nonnull ItemStack itemstack, IBlockState blockState) { + if (blockState != null && (blockState.getMaterial() == Material.IRON || blockState.getMaterial() == Material.ANVIL || blockState.getMaterial() == Material.ROCK)) { + return efficiency; + } else { + return super.getDestroySpeed(itemstack, blockState); + } + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/tools/item/ItemMekanismShovel.java b/src/main/java/mekanism/tools/item/ItemMekanismShovel.java index 095beac5e..051e87a52 100644 --- a/src/main/java/mekanism/tools/item/ItemMekanismShovel.java +++ b/src/main/java/mekanism/tools/item/ItemMekanismShovel.java @@ -2,6 +2,7 @@ package mekanism.tools.item; import java.util.Set; +import mekanism.tools.common.ToolUtils; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; @@ -32,8 +33,7 @@ public class ItemMekanismShovel extends ItemMekanismTool @Override public boolean canHarvestBlock(@Nonnull IBlockState state, ItemStack stack) { - Block block = state.getBlock(); - return block == Blocks.SNOW_LAYER || block == Blocks.SNOW; + return ToolUtils.canShovelHarvest(state.getBlock()); } @Nonnull