diff --git a/common/mekanism/client/ClientProxy.java b/common/mekanism/client/ClientProxy.java index 7ae76e5fb..c98191d08 100644 --- a/common/mekanism/client/ClientProxy.java +++ b/common/mekanism/client/ClientProxy.java @@ -17,8 +17,10 @@ import mekanism.client.gui.GuiEnergyCube; import mekanism.client.gui.GuiEnrichmentChamber; import mekanism.client.gui.GuiFactory; import mekanism.client.gui.GuiGasTank; +import mekanism.client.gui.GuiItemStackFilter; import mekanism.client.gui.GuiLogisticalSorter; import mekanism.client.gui.GuiMetallurgicInfuser; +import mekanism.client.gui.GuiOreDictFilter; import mekanism.client.gui.GuiOsmiumCompressor; import mekanism.client.gui.GuiPasswordEnter; import mekanism.client.gui.GuiPasswordModify; @@ -352,6 +354,10 @@ public class ClientProxy extends CommonProxy return new GuiRobitRepair(player.inventory, world, x); case 26: return new GuiLogisticalSorter(player, (TileEntityLogisticalSorter)tileEntity); + case 27: + return new GuiItemStackFilter(player, (TileEntityLogisticalSorter)tileEntity); + case 28: + return new GuiOreDictFilter(player, (TileEntityLogisticalSorter)tileEntity); } return null; diff --git a/common/mekanism/client/gui/GuiItemStackFilter.java b/common/mekanism/client/gui/GuiItemStackFilter.java index e5607d6fd..4d1bf2882 100644 --- a/common/mekanism/client/gui/GuiItemStackFilter.java +++ b/common/mekanism/client/gui/GuiItemStackFilter.java @@ -1,5 +1,223 @@ package mekanism.client.gui; -public class GuiItemStackFilter { +import mekanism.api.EnumColor; +import mekanism.api.Object3D; +import mekanism.client.render.MekanismRenderer; +import mekanism.common.Mekanism; +import mekanism.common.PacketHandler; +import mekanism.common.PacketHandler.Transmission; +import mekanism.common.inventory.container.ContainerFilter; +import mekanism.common.network.PacketLogisticalSorterGui; +import mekanism.common.network.PacketNewFilter; +import mekanism.common.network.PacketRobit; +import mekanism.common.network.PacketRobit.RobitPacketType; +import mekanism.common.tileentity.TileEntityLogisticalSorter; +import mekanism.common.transporter.ItemStackFilter; +import mekanism.common.util.MekanismUtils; +import mekanism.common.util.MekanismUtils.ResourceType; +import mekanism.common.util.TransporterUtils; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; + +public class GuiItemStackFilter extends GuiMekanism +{ + public TileEntityLogisticalSorter tileEntity; + + public boolean isNew = false; + + public ItemStackFilter filter = new ItemStackFilter(); + + public String status = EnumColor.DARK_GREEN + "All OK"; + + public int ticker; + + public GuiItemStackFilter(EntityPlayer player, TileEntityLogisticalSorter tentity, int index) + { + super(new ContainerFilter(player.inventory)); + tileEntity = tentity; + + filter = (ItemStackFilter)tileEntity.filters.get(index); + } + + public GuiItemStackFilter(EntityPlayer player, TileEntityLogisticalSorter tentity) + { + super(new ContainerFilter(player.inventory)); + tileEntity = tentity; + + isNew = true; + + filter.color = TransporterUtils.colors.get(0); + } + + @Override + public boolean doesGuiPauseGame() + { + return false; + } + + @Override + public void initGui() + { + super.initGui(); + + int guiWidth = (width - xSize) / 2; + int guiHeight = (height - ySize) / 2; + + buttonList.clear(); + buttonList.add(new GuiButton(0, guiWidth + 58, guiHeight + 63, 60, 18, "Save")); + } + + @Override + protected void actionPerformed(GuiButton guibutton) + { + super.actionPerformed(guibutton); + + if(guibutton.id == 0) + { + if(filter.itemType != null) + { + PacketHandler.sendPacket(Transmission.SERVER, new PacketNewFilter().setParams(Object3D.get(tileEntity), filter)); + PacketHandler.sendPacket(Transmission.SERVER, new PacketLogisticalSorterGui().setParams(Object3D.get(tileEntity), 0)); + mc.thePlayer.openGui(Mekanism.instance, 26, mc.theWorld, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord); + } + else { + status = EnumColor.DARK_RED + "No item"; + ticker = 20; + } + } + } + + @Override + protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) + { + int xAxis = (mouseX - (width - xSize) / 2); + int yAxis = (mouseY - (height - ySize) / 2); + + fontRenderer.drawString((isNew ? "New" : "Edit") + " ItemStack Filter", 43, 6, 0x404040); + fontRenderer.drawString("Status: " + status, 35, 20, 0x00CD00); + fontRenderer.drawString("ItemStack Details:", 35, 32, 0x00CD00); + + if(filter.itemType != null) + { + fontRenderer.drawString("ID: " + filter.itemType.itemID + ", meta: " + filter.itemType.getItemDamage(), 35, 41, 0x00CD00); + } + + if(filter.itemType != null) + { + GL11.glPushMatrix(); + GL11.glEnable(GL11.GL_LIGHTING); + itemRenderer.renderItemIntoGUI(fontRenderer, mc.getTextureManager(), filter.itemType, 12, 19); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glPopMatrix(); + } + + GL11.glPushMatrix(); + GL11.glColor4f(1, 1, 1, 1); + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + + mc.getTextureManager().bindTexture(MekanismRenderer.getColorResource(filter.color)); + itemRenderer.renderIcon(12, 45, MekanismRenderer.getColorIcon(filter.color), 16, 16); + + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glPopMatrix(); + + if(xAxis >= 12 && xAxis <= 28 && yAxis >= 45 && yAxis <= 61) + { + drawCreativeTabHoveringText(filter.color.getName(), xAxis, yAxis); + } + + super.drawGuiContainerForegroundLayer(mouseX, mouseY); + } + + @Override + public void updateScreen() + { + super.updateScreen(); + + if(ticker > 0) + { + ticker--; + } + else { + status = EnumColor.DARK_GREEN + "All OK"; + } + } + + @Override + protected void drawGuiContainerBackgroundLayer(float partialTick, int mouseX, int mouseY) + { + super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY); + + mc.renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.GUI, "GuiItemStackFilter.png")); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + 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 >= 5 && xAxis <= 16 && yAxis >= 5 && yAxis <= 16) + { + drawTexturedModalRect(guiWidth + 5, guiHeight + 5, 176, 0, 11, 11); + } + else { + drawTexturedModalRect(guiWidth + 5, guiHeight + 5, 176, 11, 11, 11); + } + + if(xAxis >= 12 && xAxis <= 28 && yAxis >= 19 && yAxis <= 35) + { + GL11.glPushMatrix(); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glDisable(GL11.GL_DEPTH_TEST); + + int x = guiWidth + 12; + int y = guiHeight + 19; + drawGradientRect(x, y, x + 16, y + 16, -2130706433, -2130706433); + + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_DEPTH_TEST); + GL11.glPopMatrix(); + } + } + + @Override + protected void mouseClicked(int mouseX, int mouseY, int button) + { + 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) + { + mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F); + PacketHandler.sendPacket(Transmission.SERVER, new PacketLogisticalSorterGui().setParams(Object3D.get(tileEntity), 0)); + mc.thePlayer.openGui(Mekanism.instance, 26, mc.theWorld, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord); + } + + if(xAxis >= 12 && xAxis <= 28 && yAxis >= 19 && yAxis <= 35) + { + ItemStack stack = mc.thePlayer.inventory.getItemStack(); + + if(stack != null) + { + filter.itemType = stack.copy(); + filter.itemType.stackSize = 1; + } + } + + if(xAxis >= 12 && xAxis <= 28 && yAxis >= 45 && yAxis <= 61) + { + filter.color = TransporterUtils.increment(filter.color); + } + } + } } diff --git a/common/mekanism/client/gui/GuiLogisticalSorter.java b/common/mekanism/client/gui/GuiLogisticalSorter.java index 467285568..384ba0aa9 100644 --- a/common/mekanism/client/gui/GuiLogisticalSorter.java +++ b/common/mekanism/client/gui/GuiLogisticalSorter.java @@ -1,7 +1,16 @@ package mekanism.client.gui; +import java.util.ArrayList; + +import mekanism.api.Object3D; +import mekanism.common.PacketHandler; +import mekanism.common.PacketHandler.Transmission; import mekanism.common.inventory.container.ContainerNull; +import mekanism.common.network.PacketLogisticalSorterGui; import mekanism.common.tileentity.TileEntityLogisticalSorter; +import mekanism.common.transporter.ItemStackFilter; +import mekanism.common.transporter.OreDictFilter; +import mekanism.common.transporter.TransporterFilter; import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils.ResourceType; import net.minecraft.client.gui.GuiButton; @@ -50,11 +59,13 @@ public class GuiLogisticalSorter extends GuiMekanism if(guibutton.id == 0) { - + PacketHandler.sendPacket(Transmission.SERVER, new PacketLogisticalSorterGui().setParams(Object3D.get(tileEntity), 1)); + mc.displayGuiScreen(new GuiItemStackFilter(mc.thePlayer, tileEntity)); } else if(guibutton.id == 1) { - + PacketHandler.sendPacket(Transmission.SERVER, new PacketLogisticalSorterGui().setParams(Object3D.get(tileEntity), 2)); + mc.displayGuiScreen(new GuiOreDictFilter(mc.thePlayer, tileEntity)); } } @@ -66,7 +77,9 @@ public class GuiLogisticalSorter extends GuiMekanism fontRenderer.drawString("Logistical Sorter", 43, 6, 0x404040); fontRenderer.drawString("Filters:", 11, 17, 0x00CD00); - fontRenderer.drawString("- " + tileEntity.filters.size(), 11, 26, 0x00CD00); + fontRenderer.drawString("T: " + tileEntity.filters.size(), 11, 26, 0x00CD00); + fontRenderer.drawString("IS: " + getItemStackFilters().size(), 11, 35, 0x00CD00); + fontRenderer.drawString("OD: " + getOreDictFilters().size(), 11, 44, 0x00CD00); super.drawGuiContainerForegroundLayer(mouseX, mouseY); } @@ -82,4 +95,34 @@ public class GuiLogisticalSorter extends GuiMekanism int guiHeight = (height - ySize) / 2; drawTexturedModalRect(guiWidth, guiHeight, 0, 0, xSize, ySize); } + + public ArrayList getItemStackFilters() + { + ArrayList list = new ArrayList(); + + for(TransporterFilter filter : tileEntity.filters) + { + if(filter instanceof ItemStackFilter) + { + list.add(filter); + } + } + + return list; + } + + public ArrayList getOreDictFilters() + { + ArrayList list = new ArrayList(); + + for(TransporterFilter filter : tileEntity.filters) + { + if(filter instanceof OreDictFilter) + { + list.add(filter); + } + } + + return list; + } } \ No newline at end of file diff --git a/common/mekanism/client/gui/GuiOreDictFilter.java b/common/mekanism/client/gui/GuiOreDictFilter.java index f1e887039..b0a9cd9e8 100644 --- a/common/mekanism/client/gui/GuiOreDictFilter.java +++ b/common/mekanism/client/gui/GuiOreDictFilter.java @@ -1,9 +1,346 @@ package mekanism.client.gui; -import mekanism.common.tileentity.TileEntityLogisticalTransporter; -import net.minecraft.client.gui.GuiScreen; +import java.util.ArrayList; +import java.util.List; -public class GuiOreDictFilter extends GuiScreen +import mekanism.api.EnumColor; +import mekanism.api.Object3D; +import mekanism.client.render.MekanismRenderer; +import mekanism.common.Mekanism; +import mekanism.common.PacketHandler; +import mekanism.common.PacketHandler.Transmission; +import mekanism.common.inventory.container.ContainerFilter; +import mekanism.common.network.PacketLogisticalSorterGui; +import mekanism.common.network.PacketNewFilter; +import mekanism.common.tileentity.TileEntityLogisticalSorter; +import mekanism.common.transporter.OreDictFilter; +import mekanism.common.util.MekanismUtils; +import mekanism.common.util.MekanismUtils.ResourceType; +import mekanism.common.util.TransporterUtils; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiTextField; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.OreDictionary; + +import org.lwjgl.input.Keyboard; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; + +public class GuiOreDictFilter extends GuiMekanism { - public TileEntityLogisticalTransporter tileEntity; + public TileEntityLogisticalSorter tileEntity; + + public boolean isNew = false; + + public OreDictFilter filter = new OreDictFilter(); + + private GuiTextField oreDictText; + + public ItemStack renderStack; + + public int ticker = 0; + + public int stackSwitch = 0; + + public int stackIndex = 0; + + public List iterStacks; + + public String status = EnumColor.DARK_GREEN + "All OK"; + + public GuiOreDictFilter(EntityPlayer player, TileEntityLogisticalSorter tentity, int index) + { + super(new ContainerFilter(player.inventory)); + tileEntity = tentity; + + filter = (OreDictFilter)tentity.filters.get(index); + } + + public GuiOreDictFilter(EntityPlayer player, TileEntityLogisticalSorter tentity) + { + super(new ContainerFilter(player.inventory)); + tileEntity = tentity; + + isNew = true; + + filter.color = TransporterUtils.colors.get(0); + } + + @Override + public boolean doesGuiPauseGame() + { + return false; + } + + @Override + public void initGui() + { + super.initGui(); + + int guiWidth = (width - xSize) / 2; + int guiHeight = (height - ySize) / 2; + + buttonList.clear(); + buttonList.add(new GuiButton(0, guiWidth + 58, guiHeight + 63, 60, 18, "Save")); + + oreDictText = new GuiTextField(fontRenderer, guiWidth + 35, guiHeight + 48, 95, 12); + oreDictText.setMaxStringLength(12); + oreDictText.setFocused(true); + } + + @Override + public void keyTyped(char c, int i) + { + if(i == Keyboard.KEY_E) + { + oreDictText.textboxKeyTyped(c, i); + return; + } + + super.keyTyped(c, i); + + if(oreDictText.isFocused() && i == Keyboard.KEY_RETURN) + { + setOreDictKey(); + return; + } + + if(Character.isLetter(c) || Character.isDigit(c) || c == '*' || i == Keyboard.KEY_BACK || i == Keyboard.KEY_DELETE) + { + oreDictText.textboxKeyTyped(c, i); + } + } + + @Override + protected void actionPerformed(GuiButton guibutton) + { + super.actionPerformed(guibutton); + + if(guibutton.id == 0) + { + if(filter.oreDictName != null && !filter.oreDictName.isEmpty()) + { + PacketHandler.sendPacket(Transmission.SERVER, new PacketNewFilter().setParams(Object3D.get(tileEntity), filter)); + PacketHandler.sendPacket(Transmission.SERVER, new PacketLogisticalSorterGui().setParams(Object3D.get(tileEntity), 0)); + mc.thePlayer.openGui(Mekanism.instance, 26, mc.theWorld, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord); + } + else { + status = EnumColor.DARK_RED + "No key"; + ticker = 20; + } + } + } + + @Override + protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) + { + int xAxis = (mouseX - (width - xSize) / 2); + int yAxis = (mouseY - (height - ySize) / 2); + + fontRenderer.drawString((isNew ? "New" : "Edit") + " OreDict Filter", 43, 6, 0x404040); + fontRenderer.drawString("Status: " + status, 35, 20, 0x00CD00); + fontRenderer.drawString("Key: " + filter.oreDictName, 35, 32, 0x00CD00); + + if(renderStack != null) + { + GL11.glPushMatrix(); + GL11.glEnable(GL11.GL_LIGHTING); + itemRenderer.renderItemIntoGUI(fontRenderer, mc.getTextureManager(), renderStack, 12, 19); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glPopMatrix(); + } + + GL11.glPushMatrix(); + GL11.glColor4f(1, 1, 1, 1); + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + + mc.getTextureManager().bindTexture(MekanismRenderer.getColorResource(filter.color)); + itemRenderer.renderIcon(12, 45, MekanismRenderer.getColorIcon(filter.color), 16, 16); + + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glPopMatrix(); + + if(xAxis >= 12 && xAxis <= 28 && yAxis >= 45 && yAxis <= 61) + { + drawCreativeTabHoveringText(filter.color.getName(), xAxis, yAxis); + } + + super.drawGuiContainerForegroundLayer(mouseX, mouseY); + } + + @Override + protected void drawGuiContainerBackgroundLayer(float partialTick, int mouseX, int mouseY) + { + super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY); + + mc.renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.GUI, "GuiOreDictFilter.png")); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + 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 >= 5 && xAxis <= 16 && yAxis >= 5 && yAxis <= 16) + { + drawTexturedModalRect(guiWidth + 5, guiHeight + 5, 176, 0, 11, 11); + } + else { + drawTexturedModalRect(guiWidth + 5, guiHeight + 5, 176, 11, 11, 11); + } + + if(xAxis >= 131 && xAxis <= 143 && yAxis >= 48 && yAxis <= 60) + { + drawTexturedModalRect(guiWidth + 131, guiHeight + 48, 176 + 11, 0, 12, 12); + } + else { + drawTexturedModalRect(guiWidth + 131, guiHeight + 48, 176 + 11, 12, 12, 12); + } + + oreDictText.drawTextBox(); + } + + @Override + public void updateScreen() + { + super.updateScreen(); + + oreDictText.updateCursorCounter(); + + if(ticker > 0) + { + ticker--; + } + else { + status = EnumColor.DARK_GREEN + "All OK"; + } + + if(stackSwitch > 0) + { + stackSwitch--; + } + + if(stackSwitch == 0 && iterStacks != null && iterStacks.size() > 0) + { + stackSwitch = 20; + + if(stackIndex == -1 || stackIndex == iterStacks.size()-1) + { + stackIndex = 0; + } + else if(stackIndex < iterStacks.size()-1) + { + stackIndex++; + } + + renderStack = iterStacks.get(stackIndex); + } + else if(iterStacks != null && iterStacks.size() == 0) + { + renderStack = null; + } + } + + @Override + protected void mouseClicked(int mouseX, int mouseY, int button) + { + super.mouseClicked(mouseX, mouseY, button); + + oreDictText.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) + { + mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F); + PacketHandler.sendPacket(Transmission.SERVER, new PacketLogisticalSorterGui().setParams(Object3D.get(tileEntity), 0)); + mc.thePlayer.openGui(Mekanism.instance, 26, mc.theWorld, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord); + } + + if(xAxis >= 12 && xAxis <= 28 && yAxis >= 45 && yAxis <= 61) + { + filter.color = TransporterUtils.increment(filter.color); + } + } + } + + private void setOreDictKey() + { + String oreName = oreDictText.getText(); + + if(oreName == null || oreName.isEmpty()) + { + status = EnumColor.DARK_RED + "No key entered"; + return; + } + else if(oreName.equals(filter.oreDictName)) + { + status = EnumColor.DARK_RED + "Same key"; + return; + } + + if(iterStacks == null) + { + iterStacks = new ArrayList(); + } + else { + iterStacks.clear(); + } + + List keys = new ArrayList(); + + for(String s : OreDictionary.getOreNames()) + { + if(oreName.equals(s)) + { + keys.add(s); + } + else if(oreName.endsWith("*") && !oreName.startsWith("*")) + { + if(s.startsWith(oreName.substring(0, oreName.length()-1))) + { + keys.add(s); + } + } + else if(oreName.startsWith("*") && !oreName.endsWith("*")) + { + if(s.endsWith(oreName.substring(1))) + { + keys.add(s); + } + } + else if(oreName.startsWith("*") && oreName.endsWith("*")) + { + if(s.contains(oreName.substring(1, oreName.length()-1))) + { + keys.add(s); + } + } + } + + for(String key : keys) + { + for(ItemStack stack : OreDictionary.getOres(key)) + { + ItemStack toAdd = stack.copy(); + + if(!iterStacks.contains(stack)) + { + iterStacks.add(stack.copy()); + } + } + } + + filter.oreDictName = oreName; + oreDictText.setText(""); + + stackSwitch = 0; + stackIndex = -1; + } } diff --git a/common/mekanism/client/render/MekanismRenderer.java b/common/mekanism/client/render/MekanismRenderer.java index c37e932a9..0aa291ae8 100644 --- a/common/mekanism/client/render/MekanismRenderer.java +++ b/common/mekanism/client/render/MekanismRenderer.java @@ -3,9 +3,11 @@ package mekanism.client.render; import java.util.Arrays; import java.util.List; +import mekanism.api.EnumColor; import mekanism.common.ISpecialBounds; import mekanism.common.ObfuscatedNames; import mekanism.common.util.MekanismUtils; +import mekanism.common.util.MekanismUtils.ResourceType; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GLAllocation; @@ -34,6 +36,8 @@ public class MekanismRenderer { private static RenderBlocks renderBlocks = new RenderBlocks(); + public static Icon[] colors = new Icon[256]; + private static float lightmapLastX; private static float lightmapLastY; private static boolean optifineBreak = false; @@ -148,6 +152,21 @@ public class MekanismRenderer } } + public static ResourceLocation getColorResource(EnumColor color) + { + return MekanismUtils.getResource(ResourceType.TEXTURE_BLOCKS, "Overlay" + color.friendlyName.replace(" ", "") + ".png"); + } + + public static Icon getColorIcon(EnumColor color) + { + if(colors[color.ordinal()] == null) + { + colors[color.ordinal()] = getTextureMap(0).registerIcon("mekanism:Overlay" + color.getName()); + } + + return colors[color.ordinal()]; + } + public static void glowOn() { GL11.glPushAttrib(GL11.GL_LIGHTING_BIT); diff --git a/common/mekanism/client/render/tileentity/RenderConfigurableMachine.java b/common/mekanism/client/render/tileentity/RenderConfigurableMachine.java index 86cad1609..d6a1d3bc9 100644 --- a/common/mekanism/client/render/tileentity/RenderConfigurableMachine.java +++ b/common/mekanism/client/render/tileentity/RenderConfigurableMachine.java @@ -34,39 +34,10 @@ import cpw.mods.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class RenderConfigurableMachine extends TileEntitySpecialRenderer { - private static Icon[] coloredOverlays; - private Minecraft mc = FMLClientHandler.instance().getClient(); private HashMap> cachedOverlays = new HashMap>(); - public RenderConfigurableMachine() - { - if(coloredOverlays == null) - { - coloredOverlays = new Icon[16]; - - TextureMap registrar = MekanismRenderer.getTextureMap(0); - - coloredOverlays[0] = registrar.registerIcon("mekanism:OverlayBlack"); - coloredOverlays[1] = registrar.registerIcon("mekanism:OverlayDarkBlue"); - coloredOverlays[2] = registrar.registerIcon("mekanism:OverlayDarkGreen"); - coloredOverlays[3] = registrar.registerIcon("mekanism:OverlayDarkAqua"); - coloredOverlays[4] = registrar.registerIcon("mekanism:OverlayDarkRed"); - coloredOverlays[5] = registrar.registerIcon("mekanism:OverlayPurple"); - coloredOverlays[6] = registrar.registerIcon("mekanism:OverlayOrange"); - coloredOverlays[7] = registrar.registerIcon("mekanism:OverlayGrey"); - coloredOverlays[8] = registrar.registerIcon("mekanism:OverlayDarkGrey"); - coloredOverlays[9] = registrar.registerIcon("mekanism:OverlayIndigo"); - coloredOverlays[10] = registrar.registerIcon("mekanism:OverlayBrightGreen"); - coloredOverlays[11] = registrar.registerIcon("mekanism:OverlayAqua"); - coloredOverlays[12] = registrar.registerIcon("mekanism:OverlayRed"); - coloredOverlays[13] = registrar.registerIcon("mekanism:OverlayPink"); - coloredOverlays[14] = registrar.registerIcon("mekanism:OverlayYellow"); - coloredOverlays[15] = registrar.registerIcon("mekanism:OverlayWhite"); - } - } - @Override public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float partialTick) { @@ -133,7 +104,7 @@ public class RenderConfigurableMachine extends TileEntitySpecialRenderer Model3D toReturn = new Model3D(); toReturn.baseBlock = Block.stone; - toReturn.setTexture(coloredOverlays[color.ordinal()]); + toReturn.setTexture(MekanismRenderer.getColorIcon(color)); DisplayInteger display = new DisplayInteger(); diff --git a/common/mekanism/common/HashList.java b/common/mekanism/common/HashList.java new file mode 100644 index 000000000..dbb4e3e65 --- /dev/null +++ b/common/mekanism/common/HashList.java @@ -0,0 +1,56 @@ +package mekanism.common; + +import java.util.ArrayList; +import java.util.Iterator; + +public class HashList implements Iterable +{ + private ArrayList list = new ArrayList(); + + public boolean contains(T obj) + { + return list.contains(obj); + } + + public void clear() + { + list.clear(); + } + + public T get(int index) + { + return list.get(index); + } + + public void add(T obj) + { + if(!list.contains(obj)) + { + list.add(obj); + } + } + + public void add(int index, T obj) + { + if(!list.contains(obj)) + { + list.add(index, obj); + } + } + + public int indexOf(T obj) + { + return list.indexOf(obj); + } + + public int size() + { + return list.size(); + } + + @Override + public Iterator iterator() + { + return list.iterator(); + } +} diff --git a/common/mekanism/common/Mekanism.java b/common/mekanism/common/Mekanism.java index 272a0c3e7..499a67e75 100644 --- a/common/mekanism/common/Mekanism.java +++ b/common/mekanism/common/Mekanism.java @@ -59,6 +59,7 @@ import mekanism.common.network.PacketDataRequest; import mekanism.common.network.PacketDigitUpdate; import mekanism.common.network.PacketElectricBowState; import mekanism.common.network.PacketElectricChest; +import mekanism.common.network.PacketNewFilter; import mekanism.common.network.PacketLogisticalSorterGui; import mekanism.common.network.PacketPortableTeleport; import mekanism.common.network.PacketPortalFX; @@ -1138,6 +1139,7 @@ public class Mekanism PacketHandler.registerPacket(PacketRedstoneControl.class); PacketHandler.registerPacket(PacketWalkieTalkieState.class); PacketHandler.registerPacket(PacketLogisticalSorterGui.class); + PacketHandler.registerPacket(PacketNewFilter.class); //Donators donators.add("mrgreaper"); diff --git a/common/mekanism/common/network/PacketLogisticalSorterGui.java b/common/mekanism/common/network/PacketLogisticalSorterGui.java index 304117adc..2e5ae7eb8 100644 --- a/common/mekanism/common/network/PacketLogisticalSorterGui.java +++ b/common/mekanism/common/network/PacketLogisticalSorterGui.java @@ -3,10 +3,9 @@ package mekanism.common.network; import java.io.DataOutputStream; import mekanism.api.Object3D; -import mekanism.common.ITileNetwork; import mekanism.common.Mekanism; +import mekanism.common.tileentity.TileEntityLogisticalSorter; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import com.google.common.io.ByteArrayDataInput; @@ -47,18 +46,9 @@ public class PacketLogisticalSorterGui implements IMekanismPacket World worldServer = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(id); - if(worldServer != null && worldServer.getBlockTileEntity(x, y, z) instanceof ITileNetwork) + if(worldServer != null && worldServer.getBlockTileEntity(x, y, z) instanceof TileEntityLogisticalSorter) { - TileEntity tileEntity = worldServer.getBlockTileEntity(x, y, z); - - if(type == 0) - { - player.openGui(Mekanism.instance, 27, worldServer, x, y, z); - } - else if(type == 1) - { - player.openGui(Mekanism.instance, 28, worldServer, x, y, z); - } + player.openGui(Mekanism.instance, 26+type, worldServer, x, y, z); } } diff --git a/common/mekanism/common/network/PacketNewFilter.java b/common/mekanism/common/network/PacketNewFilter.java new file mode 100644 index 000000000..bd6b69efd --- /dev/null +++ b/common/mekanism/common/network/PacketNewFilter.java @@ -0,0 +1,78 @@ +package mekanism.common.network; + +import java.io.DataOutputStream; +import java.util.ArrayList; + +import mekanism.api.Object3D; +import mekanism.common.PacketHandler; +import mekanism.common.PacketHandler.Transmission; +import mekanism.common.tileentity.TileEntityLogisticalSorter; +import mekanism.common.transporter.TransporterFilter; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; + +import com.google.common.io.ByteArrayDataInput; + +import cpw.mods.fml.common.FMLCommonHandler; + +public class PacketNewFilter implements IMekanismPacket +{ + public Object3D object3D; + + public int type; + + public TransporterFilter filter; + + @Override + public String getName() + { + return "FilterUpdate"; + } + + @Override + public IMekanismPacket setParams(Object... data) + { + object3D = (Object3D)data[0]; + filter = (TransporterFilter)data[1]; + + return this; + } + + @Override + public void read(ByteArrayDataInput dataStream, EntityPlayer player, World world) throws Exception + { + int x = dataStream.readInt(); + int y = dataStream.readInt(); + int z = dataStream.readInt(); + + int id = dataStream.readInt(); + + int type = dataStream.readInt(); + + World worldServer = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(id); + + if(worldServer != null && worldServer.getBlockTileEntity(x, y, z) instanceof TileEntityLogisticalSorter) + { + TileEntityLogisticalSorter sorter = (TileEntityLogisticalSorter)worldServer.getBlockTileEntity(x, y, z); + TransporterFilter filter = TransporterFilter.readFromPacket(dataStream); + + sorter.filters.add(filter); + + PacketHandler.sendPacket(Transmission.SINGLE_CLIENT, new PacketTileEntity().setParams(Object3D.get(sorter), sorter.getFilterPacket(new ArrayList())), player); + } + } + + @Override + public void write(DataOutputStream dataStream) throws Exception + { + dataStream.writeInt(object3D.xCoord); + dataStream.writeInt(object3D.yCoord); + dataStream.writeInt(object3D.zCoord); + + dataStream.writeInt(object3D.dimensionId); + + ArrayList data = new ArrayList(); + filter.write(data); + PacketHandler.encode(data.toArray(), dataStream); + } +} diff --git a/common/mekanism/common/tileentity/TileEntityBasicBlock.java b/common/mekanism/common/tileentity/TileEntityBasicBlock.java index 0d40b6252..3be9cbb63 100644 --- a/common/mekanism/common/tileentity/TileEntityBasicBlock.java +++ b/common/mekanism/common/tileentity/TileEntityBasicBlock.java @@ -31,6 +31,8 @@ public abstract class TileEntityBasicBlock extends TileEntity implements IWrench /** A timer used to send packets to clients. */ public int packetTick; + public boolean doAutoSync = true; + public Set components = new HashSet(); @Override @@ -45,7 +47,7 @@ public abstract class TileEntityBasicBlock extends TileEntity implements IWrench if(!worldObj.isRemote) { - if(playersUsing.size() > 0) + if(doAutoSync && playersUsing.size() > 0) { PacketHandler.sendPacket(Transmission.CLIENTS_RANGE, new PacketTileEntity().setParams(Object3D.get(this), getNetworkedData(new ArrayList())), Object3D.get(this), 50D); } diff --git a/common/mekanism/common/tileentity/TileEntityLogisticalSorter.java b/common/mekanism/common/tileentity/TileEntityLogisticalSorter.java index 77bbb37ab..ead1687c5 100644 --- a/common/mekanism/common/tileentity/TileEntityLogisticalSorter.java +++ b/common/mekanism/common/tileentity/TileEntityLogisticalSorter.java @@ -1,11 +1,10 @@ package mekanism.common.tileentity; import java.util.ArrayList; -import java.util.HashSet; -import java.util.Set; import mekanism.api.EnumColor; import mekanism.api.Object3D; +import mekanism.common.HashList; import mekanism.common.IActiveState; import mekanism.common.IRedstoneControl; import mekanism.common.PacketHandler; @@ -27,7 +26,7 @@ import com.google.common.io.ByteArrayDataInput; public class TileEntityLogisticalSorter extends TileEntityElectricBlock implements IRedstoneControl, IActiveState { - public Set filters = new HashSet(); + public HashList filters = new HashList(); public RedstoneControl controlType = RedstoneControl.DISABLED; @@ -43,6 +42,7 @@ public class TileEntityLogisticalSorter extends TileEntityElectricBlock implemen { super("LogisticalSorter", MachineType.LOGISTICAL_SORTER.baseEnergy); inventory = new ItemStack[1]; + doAutoSync = false; } @Override @@ -97,6 +97,11 @@ public class TileEntityLogisticalSorter extends TileEntityElectricBlock implemen delayTicks = 10; } } + + if(playersUsing.size() > 0) + { + PacketHandler.sendPacket(Transmission.CLIENTS_RANGE, new PacketTileEntity().setParams(Object3D.get(this), getGenericPacket(new ArrayList())), Object3D.get(this), 50D); + } } } @@ -145,19 +150,42 @@ public class TileEntityLogisticalSorter extends TileEntityElectricBlock implemen { super.handlePacketData(dataStream); - isActive = dataStream.readBoolean(); - controlType = RedstoneControl.values()[dataStream.readInt()]; + int type = dataStream.readInt(); - filters.clear(); - - int amount = dataStream.readInt(); - - for(int i = 0; i < amount; i++) + if(type == 0) { - filters.add(TransporterFilter.readFromPacket(dataStream)); + isActive = dataStream.readBoolean(); + controlType = RedstoneControl.values()[dataStream.readInt()]; + + filters.clear(); + + int amount = dataStream.readInt(); + + for(int i = 0; i < amount; i++) + { + filters.add(TransporterFilter.readFromPacket(dataStream)); + } + + MekanismUtils.updateBlock(worldObj, xCoord, yCoord, zCoord); + } + else if(type == 1) + { + isActive = dataStream.readBoolean(); + controlType = RedstoneControl.values()[dataStream.readInt()]; + + MekanismUtils.updateBlock(worldObj, xCoord, yCoord, zCoord); + } + else if(type == 2) + { + filters.clear(); + + int amount = dataStream.readInt(); + + for(int i = 0; i < amount; i++) + { + filters.add(TransporterFilter.readFromPacket(dataStream)); + } } - - MekanismUtils.updateBlock(worldObj, xCoord, yCoord, zCoord); } @Override @@ -165,8 +193,40 @@ public class TileEntityLogisticalSorter extends TileEntityElectricBlock implemen { super.getNetworkedData(data); + data.add(0); + data.add(isActive); data.add(controlType.ordinal()); + + data.add(filters.size()); + + for(TransporterFilter filter : filters) + { + filter.write(data); + } + + return data; + } + + public ArrayList getGenericPacket(ArrayList data) + { + super.getNetworkedData(data); + + data.add(1); + + data.add(isActive); + data.add(controlType.ordinal()); + + return data; + + } + + public ArrayList getFilterPacket(ArrayList data) + { + super.getNetworkedData(data); + + data.add(2); + data.add(filters.size()); for(TransporterFilter filter : filters) @@ -201,7 +261,15 @@ public class TileEntityLogisticalSorter extends TileEntityElectricBlock implemen return new int[] {0}; } - + @Override + public void openChest() + { + if(!worldObj.isRemote) + { + PacketHandler.sendPacket(Transmission.CLIENTS_RANGE, new PacketTileEntity().setParams(Object3D.get(this), getFilterPacket(new ArrayList())), Object3D.get(this), 50D); + } + } + @Override public RedstoneControl getControlType() { diff --git a/common/mekanism/common/transporter/ItemStackFilter.java b/common/mekanism/common/transporter/ItemStackFilter.java index 48425a81d..9843a1c2c 100644 --- a/common/mekanism/common/transporter/ItemStackFilter.java +++ b/common/mekanism/common/transporter/ItemStackFilter.java @@ -23,11 +23,12 @@ public class ItemStackFilter extends TransporterFilter { super.write(nbtTags); + nbtTags.setInteger("type", 0); itemType.writeToNBT(nbtTags); } @Override - public void read(NBTTagCompound nbtTags) + protected void read(NBTTagCompound nbtTags) { super.read(nbtTags); @@ -37,6 +38,8 @@ public class ItemStackFilter extends TransporterFilter @Override public void write(ArrayList data) { + data.add(0); + super.write(data); data.add(itemType.itemID); @@ -45,7 +48,7 @@ public class ItemStackFilter extends TransporterFilter } @Override - public void read(ByteArrayDataInput dataStream) + protected void read(ByteArrayDataInput dataStream) { super.read(dataStream); diff --git a/common/mekanism/common/transporter/OreDictFilter.java b/common/mekanism/common/transporter/OreDictFilter.java index 4b4058a22..d50823f47 100644 --- a/common/mekanism/common/transporter/OreDictFilter.java +++ b/common/mekanism/common/transporter/OreDictFilter.java @@ -16,7 +16,40 @@ public class OreDictFilter extends TransporterFilter @Override public boolean canFilter(ItemStack itemStack) { - return MekanismUtils.oreDictCheck(itemStack, oreDictName); + String oreKey = MekanismUtils.getOreDictName(itemStack); + + if(oreKey == null) + { + return false; + } + + if(oreDictName.equals(oreKey)) + { + return true; + } + else if(oreDictName.endsWith("*") && !oreDictName.startsWith("*")) + { + if(oreKey.startsWith(oreDictName.substring(0, oreDictName.length()-1))) + { + return true; + } + } + else if(oreDictName.startsWith("*") && !oreDictName.endsWith("*")) + { + if(oreKey.endsWith(oreDictName.substring(1))) + { + return true; + } + } + else if(oreDictName.startsWith("*") && oreDictName.endsWith("*")) + { + if(oreKey.contains(oreDictName.substring(1, oreDictName.length()-1))) + { + return true; + } + } + + return false; } @Override @@ -24,11 +57,12 @@ public class OreDictFilter extends TransporterFilter { super.write(nbtTags); + nbtTags.setInteger("type", 1); nbtTags.setString("oreDictName", oreDictName); } @Override - public void read(NBTTagCompound nbtTags) + protected void read(NBTTagCompound nbtTags) { super.read(nbtTags); @@ -38,13 +72,15 @@ public class OreDictFilter extends TransporterFilter @Override public void write(ArrayList data) { + data.add(1); + super.write(data); data.add(oreDictName); } @Override - public void read(ByteArrayDataInput dataStream) + protected void read(ByteArrayDataInput dataStream) { super.read(dataStream); diff --git a/common/mekanism/common/transporter/TransporterFilter.java b/common/mekanism/common/transporter/TransporterFilter.java index 5caa5e963..fe1b8e5d7 100644 --- a/common/mekanism/common/transporter/TransporterFilter.java +++ b/common/mekanism/common/transporter/TransporterFilter.java @@ -3,7 +3,6 @@ package mekanism.common.transporter; import java.util.ArrayList; import mekanism.api.EnumColor; -import mekanism.common.Teleporter.Code; import mekanism.common.util.TransporterUtils; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -24,7 +23,7 @@ public class TransporterFilter nbtTags.setInteger("color", TransporterUtils.colors.indexOf(color)); } - public void read(NBTTagCompound nbtTags) + protected void read(NBTTagCompound nbtTags) { color = TransporterUtils.colors.get(nbtTags.getInteger("color")); } @@ -34,14 +33,25 @@ public class TransporterFilter data.add(TransporterUtils.colors.indexOf(color)); } - public void read(ByteArrayDataInput dataStream) + protected void read(ByteArrayDataInput dataStream) { color = TransporterUtils.colors.get(dataStream.readInt()); } public static TransporterFilter readFromNBT(NBTTagCompound nbtTags) { - TransporterFilter filter = new TransporterFilter(); + int type = nbtTags.getInteger("type"); + + TransporterFilter filter = null; + + if(type == 0) + { + filter = new ItemStackFilter(); + } + else { + filter = new OreDictFilter(); + } + filter.read(nbtTags); return filter; @@ -49,7 +59,19 @@ public class TransporterFilter public static TransporterFilter readFromPacket(ByteArrayDataInput dataStream) { - TransporterFilter filter = new TransporterFilter(); + int type = dataStream.readInt(); + + TransporterFilter filter = null; + + if(type == 0) + { + filter = new ItemStackFilter(); + } + else if(type == 1) + { + filter = new OreDictFilter(); + } + filter.read(dataStream); return filter; diff --git a/common/mekanism/common/util/MekanismUtils.java b/common/mekanism/common/util/MekanismUtils.java index 6299ab878..24c579be5 100644 --- a/common/mekanism/common/util/MekanismUtils.java +++ b/common/mekanism/common/util/MekanismUtils.java @@ -1,7 +1,5 @@ package mekanism.common.util; -import ic2.api.Direction; - import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; @@ -10,7 +8,9 @@ import java.lang.reflect.Method; import java.net.HttpURLConnection; import java.net.URL; import java.util.ArrayList; +import java.util.HashMap; import java.util.Iterator; +import java.util.Map; import mekanism.api.EnumColor; import mekanism.api.IConfigurable; @@ -36,7 +36,6 @@ import mekanism.common.network.PacketElectricChest.ElectricChestPacketType; import mekanism.common.tileentity.TileEntityBoundingBlock; import mekanism.common.tileentity.TileEntityDynamicTank; import mekanism.common.tileentity.TileEntityElectricChest; -import mekanism.common.tileentity.TileEntityLogisticalTransporter; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; @@ -453,6 +452,37 @@ public final class MekanismUtils return hasResource; } + public static String getOreDictName(ItemStack check) + { + HashMap> oreStacks = (HashMap>)MekanismUtils.getPrivateValue(null, OreDictionary.class, new String[] {"oreStacks"}); + + int idFound = -1; + + for(Map.Entry> entry : oreStacks.entrySet()) + { + for(ItemStack stack : entry.getValue()) + { + if(stack.isItemEqual(check)) + { + idFound = entry.getKey(); + break; + } + } + + if(idFound != -1) + { + break; + } + } + + if(idFound == -1) + { + return null; + } + + return OreDictionary.getOreName(idFound); + } + /** * Returns an integer facing that converts a world-based orientation to a machine-based oriention. * @param side - world based diff --git a/common/mekanism/common/util/TransporterUtils.java b/common/mekanism/common/util/TransporterUtils.java index 1bf4c9844..7a59e9429 100644 --- a/common/mekanism/common/util/TransporterUtils.java +++ b/common/mekanism/common/util/TransporterUtils.java @@ -353,6 +353,16 @@ public final class TransporterUtils return null; } + public static EnumColor increment(EnumColor color) + { + if(colors.indexOf(color) == colors.size()-1) + { + return colors.get(0); + } + + return colors.get(colors.indexOf(color)+1); + } + public static void incrementColor(TileEntityLogisticalTransporter tileEntity) { if(tileEntity.color == null) diff --git a/resources/assets/mekanism/gui/GuiItemStackFilter.png b/resources/assets/mekanism/gui/GuiItemStackFilter.png index 82347eff9..e7a715d26 100644 Binary files a/resources/assets/mekanism/gui/GuiItemStackFilter.png and b/resources/assets/mekanism/gui/GuiItemStackFilter.png differ diff --git a/resources/assets/mekanism/gui/GuiOreDictFilter.png b/resources/assets/mekanism/gui/GuiOreDictFilter.png index 82347eff9..ff64b4b62 100644 Binary files a/resources/assets/mekanism/gui/GuiOreDictFilter.png and b/resources/assets/mekanism/gui/GuiOreDictFilter.png differ diff --git a/resources/assets/mekanism/gui/GuiRobitRepair.png b/resources/assets/mekanism/gui/GuiRobitRepair.png index e71a612ff..0f756159b 100644 Binary files a/resources/assets/mekanism/gui/GuiRobitRepair.png and b/resources/assets/mekanism/gui/GuiRobitRepair.png differ