Work on sorter material filters

This commit is contained in:
Aidan C. Brady 2014-03-09 18:23:06 -04:00
parent 509d857576
commit bb0ad74295
9 changed files with 468 additions and 7 deletions

View file

@ -17,6 +17,7 @@ import mekanism.common.network.PacketLogisticalSorterGui.SorterGuiPacket;
import mekanism.common.network.PacketTileEntity;
import mekanism.common.tile.TileEntityLogisticalSorter;
import mekanism.common.transporter.TItemStackFilter;
import mekanism.common.transporter.TMaterialFilter;
import mekanism.common.transporter.TOreDictFilter;
import mekanism.common.transporter.TransporterFilter;
import mekanism.common.util.MekanismUtils;
@ -243,8 +244,7 @@ public class GuiLogisticalSorter extends GuiMekanism
int guiHeight = (height - ySize) / 2;
buttonList.clear();
buttonList.add(new GuiButton(0, guiWidth + 56, guiHeight + 136, 54, 20, MekanismUtils.localize("gui.itemstack")));
buttonList.add(new GuiButton(1, guiWidth + 110, guiHeight + 136, 43, 20, MekanismUtils.localize("gui.oredict")));
buttonList.add(new GuiButton(0, guiWidth + 56, guiHeight + 136, 96, 20, MekanismUtils.localize("gui.newFilter")));
}
@Override
@ -271,9 +271,9 @@ public class GuiLogisticalSorter extends GuiMekanism
fontRenderer.drawString(tileEntity.getInvName(), 43, 6, 0x404040);
fontRenderer.drawString(MekanismUtils.localize("gui.filters") + ":", 11, 19, 0x00CD00);
fontRenderer.drawString("T: " + tileEntity.filters.size(), 11, 28, 0x00CD00);
fontRenderer.drawString("IS: " + getItemStackFilters().size(), 11, 37, 0x00CD00);
fontRenderer.drawString("OD: " + getOreDictFilters().size(), 11, 46, 0x00CD00);
fontRenderer.drawString("IS: " + getItemStackFilters(), 11, 28, 0x00CD00);
fontRenderer.drawString("OD: " + getOreDictFilters().size(), 11, 37, 0x00CD00);
fontRenderer.drawString("M: " + getMaterialFilters().size(), 11, 46, 0x00CD00);
fontRenderer.drawString("RR:", 12, 74, 0x00CD00);
fontRenderer.drawString(MekanismUtils.localize("gui." + (tileEntity.roundRobin ? "on" : "off")), 27, 86, 0x00CD00);
@ -453,6 +453,21 @@ public class GuiLogisticalSorter extends GuiMekanism
return list;
}
public ArrayList getMaterialFilters()
{
ArrayList list = new ArrayList();
for(TransporterFilter filter : tileEntity.filters)
{
if(filter instanceof TMaterialFilter)
{
list.add(filter);
}
}
return list;
}
private void updateStackList(TOreDictFilter filter)
{
if(!oreDictStacks.containsKey(filter))

View file

@ -149,7 +149,7 @@ public class GuiMMaterialFilter extends GuiMekanism
{
super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY);
mc.renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.GUI, "GuiMMaterialFilter.png"));
mc.renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.GUI, "GuiMaterialFilter.png"));
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
int guiWidth = (width - xSize) / 2;
int guiHeight = (height - ySize) / 2;

View file

@ -0,0 +1,114 @@
package mekanism.client.gui;
import mekanism.api.Coord4D;
import mekanism.common.PacketHandler;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.inventory.container.ContainerNull;
import mekanism.common.network.PacketDigitalMinerGui;
import mekanism.common.network.PacketDigitalMinerGui.MinerGuiPacket;
import mekanism.common.network.PacketLogisticalSorterGui;
import mekanism.common.network.PacketLogisticalSorterGui.SorterGuiPacket;
import mekanism.common.tile.TileEntityLogisticalSorter;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.EntityPlayer;
import org.lwjgl.opengl.GL11;
public class GuiTFilterSelect extends GuiMekanism
{
public TileEntityLogisticalSorter tileEntity;
public GuiTFilterSelect(EntityPlayer player, TileEntityLogisticalSorter tentity)
{
super(new ContainerNull(player, tentity));
tileEntity = tentity;
}
@Override
public void initGui()
{
super.initGui();
int guiWidth = (width - xSize) / 2;
int guiHeight = (height - ySize) / 2;
buttonList.clear();
buttonList.add(new GuiButton(0, guiWidth + 24, guiHeight + 32, 128, 20, MekanismUtils.localize("gui.itemstack")));
buttonList.add(new GuiButton(1, guiWidth + 24, guiHeight + 52, 128, 20, MekanismUtils.localize("gui.oredict")));
buttonList.add(new GuiButton(2, guiWidth + 24, guiHeight + 72, 128, 20, MekanismUtils.localize("gui.material")));
}
@Override
protected void actionPerformed(GuiButton guibutton)
{
super.actionPerformed(guibutton);
if(guibutton.id == 0)
{
PacketHandler.sendPacket(Transmission.SERVER, new PacketLogisticalSorterGui().setParams(SorterGuiPacket.SERVER, Coord4D.get(tileEntity), 1));
}
else if(guibutton.id == 1)
{
PacketHandler.sendPacket(Transmission.SERVER, new PacketLogisticalSorterGui().setParams(SorterGuiPacket.SERVER, Coord4D.get(tileEntity), 2));
}
else if(guibutton.id == 2)
{
PacketHandler.sendPacket(Transmission.SERVER, new PacketLogisticalSorterGui().setParams(SorterGuiPacket.SERVER, Coord4D.get(tileEntity), 3));
}
}
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{
int xAxis = (mouseX - (width - xSize) / 2);
int yAxis = (mouseY - (height - ySize) / 2);
fontRenderer.drawString(MekanismUtils.localize("gui.filterSelect.title"), 43, 6, 0x404040);
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, "GuiFilterSelect.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);
}
}
@Override
public 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 PacketDigitalMinerGui().setParams(MinerGuiPacket.SERVER, Coord4D.get(tileEntity), 0));
}
}
}
}

View file

@ -0,0 +1,225 @@
package mekanism.client.gui;
import mekanism.api.Coord4D;
import mekanism.api.EnumColor;
import mekanism.common.PacketHandler;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.inventory.container.ContainerFilter;
import mekanism.common.network.PacketEditFilter;
import mekanism.common.network.PacketLogisticalSorterGui;
import mekanism.common.network.PacketLogisticalSorterGui.SorterGuiPacket;
import mekanism.common.network.PacketNewFilter;
import mekanism.common.tile.TileEntityLogisticalSorter;
import mekanism.common.transporter.TMaterialFilter;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType;
import net.minecraft.block.Block;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
public class GuiTMaterialFilter extends GuiMekanism
{
public TileEntityLogisticalSorter tileEntity;
public boolean isNew = false;
public TMaterialFilter origFilter;
public TMaterialFilter filter = new TMaterialFilter();
public String status = EnumColor.DARK_GREEN + MekanismUtils.localize("gui.allOK");
public int ticker;
public GuiTMaterialFilter(EntityPlayer player, TileEntityLogisticalSorter tentity, int index)
{
super(new ContainerFilter(player.inventory, tentity));
tileEntity = tentity;
origFilter = (TMaterialFilter)tileEntity.filters.get(index);
filter = ((TMaterialFilter)tileEntity.filters.get(index)).clone();
}
public GuiTMaterialFilter(EntityPlayer player, TileEntityLogisticalSorter tentity)
{
super(new ContainerFilter(player.inventory, tentity));
tileEntity = tentity;
isNew = true;
}
@Override
public void initGui()
{
super.initGui();
int guiWidth = (width - xSize) / 2;
int guiHeight = (height - ySize) / 2;
buttonList.clear();
buttonList.add(new GuiButton(0, guiWidth + 27, guiHeight + 62, 60, 20, MekanismUtils.localize("gui.save")));
buttonList.add(new GuiButton(1, guiWidth + 89, guiHeight + 62, 60, 20, MekanismUtils.localize("gui.delete")));
if(isNew)
{
((GuiButton)buttonList.get(1)).enabled = false;
}
}
@Override
protected void actionPerformed(GuiButton guibutton)
{
super.actionPerformed(guibutton);
if(guibutton.id == 0)
{
if(filter.materialItem != null)
{
if(isNew)
{
PacketHandler.sendPacket(Transmission.SERVER, new PacketNewFilter().setParams(Coord4D.get(tileEntity), filter));
}
else {
PacketHandler.sendPacket(Transmission.SERVER, new PacketEditFilter().setParams(Coord4D.get(tileEntity), false, origFilter, filter));
}
PacketHandler.sendPacket(Transmission.SERVER, new PacketLogisticalSorterGui().setParams(SorterGuiPacket.SERVER, Coord4D.get(tileEntity), 0));
}
else if(filter.materialItem == null)
{
status = EnumColor.DARK_RED + MekanismUtils.localize("gui.itemFilter.noItem");
ticker = 20;
}
}
else if(guibutton.id == 1)
{
PacketHandler.sendPacket(Transmission.SERVER, new PacketEditFilter().setParams(Coord4D.get(tileEntity), true, origFilter));
PacketHandler.sendPacket(Transmission.SERVER, new PacketLogisticalSorterGui().setParams(SorterGuiPacket.SERVER, Coord4D.get(tileEntity), 0));
}
}
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{
int xAxis = (mouseX - (width - xSize) / 2);
int yAxis = (mouseY - (height - ySize) / 2);
fontRenderer.drawString((isNew ? MekanismUtils.localize("gui.new") : MekanismUtils.localize("gui.edit")) + " " + MekanismUtils.localize("gui.materialFilter"), 43, 6, 0x404040);
fontRenderer.drawString(MekanismUtils.localize("gui.status") + ": " + status, 35, 20, 0x00CD00);
fontRenderer.drawString(MekanismUtils.localize("gui.materialFilter.details") + ":", 35, 32, 0x00CD00);
if(filter.materialItem != null)
{
fontRenderer.drawString(filter.materialItem.getDisplayName(), 35, 41, 0x00CD00);
}
if(filter.materialItem != null)
{
GL11.glPushMatrix();
GL11.glEnable(GL11.GL_LIGHTING);
itemRenderer.renderItemAndEffectIntoGUI(fontRenderer, mc.getTextureManager(), filter.materialItem, 12, 19);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glPopMatrix();
}
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
}
@Override
public void updateScreen()
{
super.updateScreen();
if(ticker > 0)
{
ticker--;
}
else {
status = EnumColor.DARK_GREEN + MekanismUtils.localize("gui.allOK");
}
}
@Override
protected void drawGuiContainerBackgroundLayer(float partialTick, int mouseX, int mouseY)
{
super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY);
mc.renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.GUI, "GuiMaterialFilter.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(SorterGuiPacket.SERVER, Coord4D.get(tileEntity), isNew ? 5 : 0));
}
if(xAxis >= 12 && xAxis <= 28 && yAxis >= 19 && yAxis <= 35)
{
ItemStack stack = mc.thePlayer.inventory.getItemStack();
if(stack != null && !Keyboard.isKeyDown(Keyboard.KEY_LSHIFT))
{
if(stack.getItem() instanceof ItemBlock)
{
if(stack.itemID != Block.bedrock.blockID)
{
filter.materialItem = stack.copy();
filter.materialItem.stackSize = 1;
}
}
}
else if(stack == null && Keyboard.isKeyDown(Keyboard.KEY_LSHIFT))
{
filter.materialItem = null;
}
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
}
}
}
}

View file

@ -0,0 +1,97 @@
package mekanism.common.transporter;
import java.util.ArrayList;
import mekanism.common.transporter.Finder.MaterialFinder;
import mekanism.common.transporter.Finder.OreDictFinder;
import mekanism.common.util.InventoryUtils;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.ForgeDirection;
import com.google.common.io.ByteArrayDataInput;
public class TMaterialFilter extends TransporterFilter
{
public ItemStack materialItem;
public Material getMaterial()
{
return Block.blocksList[materialItem.itemID].blockMaterial;
}
@Override
public boolean canFilter(ItemStack itemStack)
{
if(itemStack == null || !(itemStack.getItem() instanceof ItemBlock))
{
return false;
}
return new MaterialFinder(getMaterial()).modifies(itemStack);
}
@Override
public InvStack getStackFromInventory(IInventory inv, ForgeDirection side)
{
return InventoryUtils.takeTopStack(inv, side.ordinal(), new MaterialFinder(getMaterial()));
}
@Override
public void write(NBTTagCompound nbtTags)
{
nbtTags.setInteger("type", 2);
materialItem.writeToNBT(nbtTags);
}
@Override
protected void read(NBTTagCompound nbtTags)
{
materialItem = ItemStack.loadItemStackFromNBT(nbtTags);
}
@Override
public void write(ArrayList data)
{
data.add(2);
data.add(materialItem.itemID);
data.add(materialItem.stackSize);
data.add(materialItem.getItemDamage());
}
@Override
protected void read(ByteArrayDataInput dataStream)
{
materialItem = new ItemStack(dataStream.readInt(), dataStream.readInt(), dataStream.readInt());
}
@Override
public int hashCode()
{
int code = 1;
code = 31 * code + materialItem.itemID;
code = 31 * code + materialItem.stackSize;
code = 31 * code + materialItem.getItemDamage();
return code;
}
@Override
public boolean equals(Object filter)
{
return super.equals(filter) && filter instanceof TMaterialFilter && ((TMaterialFilter)filter).materialItem.isItemEqual(materialItem);
}
@Override
public TMaterialFilter clone()
{
TMaterialFilter filter = new TMaterialFilter();
filter.materialItem = materialItem;
return filter;
}
}

View file

@ -69,9 +69,14 @@ public abstract class TransporterFilter
{
filter = new TItemStackFilter();
}
else {
else if(type == 1)
{
filter = new TOreDictFilter();
}
else if(type == 2)
{
filter = new TMaterialFilter();
}
filter.read(nbtTags);
@ -92,6 +97,10 @@ public abstract class TransporterFilter
{
filter = new TOreDictFilter();
}
else if(type == 3)
{
filter = new TMaterialFilter();
}
filter.read(dataStream);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5 KiB

After

Width:  |  Height:  |  Size: 5.2 KiB

View file

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

View file

@ -251,6 +251,7 @@ gui.status=Status
gui.autoEject=Auto-eject
gui.itemstack=ItemStack
gui.oredict=OreDict
gui.material=Material
gui.out=Out
gui.noFluid=No fluid
gui.empty=Empty