mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-19 19:59:58 +00:00
Added 'snapshot' feature to new filter.
This commit is contained in:
1 parent
135877c1be
commit
bc55ccc40a
7 files changed
+230
-42
No files matched your search
@@ -25,6 +25,7 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.api.tools.IToolWrench;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.network.IGuiHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import crazypants.enderio.BlockEio;
|
||||
@@ -37,6 +38,7 @@ import crazypants.enderio.conduit.gui.ExternalConnectionContainer;
|
||||
import crazypants.enderio.conduit.gui.GuiExternalConnection;
|
||||
import crazypants.enderio.conduit.gui.GuiExternalConnectionSelector;
|
||||
import crazypants.enderio.conduit.gui.PacketOpenConduitUI;
|
||||
import crazypants.enderio.conduit.gui.item.PacketExistingItemFilterSnapshot;
|
||||
import crazypants.enderio.conduit.liquid.PacketFluidLevel;
|
||||
import crazypants.enderio.conduit.packet.PacketConnectionMode;
|
||||
import crazypants.enderio.conduit.packet.PacketExtractMode;
|
||||
@@ -60,7 +62,8 @@ public class BlockConduitBundle extends BlockEio implements IGuiHandler {
|
||||
PacketHandler.INSTANCE.registerMessage(PacketFluidLevel.class, PacketFluidLevel.class, PacketHandler.nextID(), Side.CLIENT);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketExtractMode.class, PacketExtractMode.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketConnectionMode.class, PacketConnectionMode.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketItemConduitFilter.class, PacketItemConduitFilter.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketItemConduitFilter.class, PacketItemConduitFilter.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketExistingItemFilterSnapshot.class, PacketExistingItemFilterSnapshot.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketRedstoneConduitSignalColor.class, PacketRedstoneConduitSignalColor.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketOpenConduitUI.class, PacketOpenConduitUI.class, PacketHandler.nextID(), Side.SERVER);
|
||||
|
||||
|
||||
@@ -21,6 +21,10 @@ public class ExistingItemFilterGui implements IItemFilterGui {
|
||||
private static final int ID_META = GuiExternalConnection.nextButtonId();
|
||||
private static final int ID_ORE_DICT = GuiExternalConnection.nextButtonId();
|
||||
private static final int ID_STICKY = GuiExternalConnection.nextButtonId();
|
||||
|
||||
private static final int ID_SNAPSHOT = GuiExternalConnection.nextButtonId();
|
||||
private static final int ID_CLEAR = GuiExternalConnection.nextButtonId();
|
||||
|
||||
|
||||
private IItemConduit itemConduit;
|
||||
private GuiExternalConnection gui;
|
||||
@@ -29,6 +33,9 @@ public class ExistingItemFilterGui implements IItemFilterGui {
|
||||
private ToggleButtonEIO useNbtB;
|
||||
private ToggleButtonEIO useOreDictB;
|
||||
private ToggleButtonEIO stickyB;
|
||||
|
||||
private GuiButton snapshotB;
|
||||
private GuiButton clearB;
|
||||
|
||||
boolean isInput;
|
||||
|
||||
@@ -75,6 +82,9 @@ public class ExistingItemFilterGui implements IItemFilterGui {
|
||||
useOreDictB.setSelectedToolTip(Lang.localize("gui.conduit.item.oreDicEnabled"));
|
||||
useOreDictB.setUnselectedToolTip(Lang.localize("gui.conduit.item.oreDicDisabled"));
|
||||
useOreDictB.setPaintSelectedBorder(false);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void updateButtons() {
|
||||
@@ -94,6 +104,19 @@ public class ExistingItemFilterGui implements IItemFilterGui {
|
||||
|
||||
useMetaB.onGuiInit();
|
||||
useMetaB.setSelected(activeFilter.isMatchMeta());
|
||||
|
||||
int x = gui.getGuiLeft() + 80;
|
||||
int y = 77;
|
||||
snapshotB = new GuiButton(ID_SNAPSHOT, x, y, 60, 20, "Snapshot");
|
||||
|
||||
|
||||
y += 22;
|
||||
clearB = new GuiButton(ID_CLEAR, x, y, 60, 20, "Clear");
|
||||
gui.addButton(snapshotB);
|
||||
gui.addButton(clearB);
|
||||
|
||||
clearB.enabled = filter.getSnapshot() != null;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -111,13 +134,20 @@ public class ExistingItemFilterGui implements IItemFilterGui {
|
||||
} else if(guiButton.id == ID_ORE_DICT) {
|
||||
filter.setUseOreDict(useOreDictB.isSelected());
|
||||
sendFilterChange();
|
||||
}
|
||||
} else if(guiButton.id == ID_SNAPSHOT) {
|
||||
sendSnapshotPacket(false);
|
||||
} else if(guiButton.id == ID_CLEAR) {
|
||||
sendSnapshotPacket(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendSnapshotPacket(boolean isClear) {
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketExistingItemFilterSnapshot(itemConduit, gui.getDir(),isInput,isClear));
|
||||
}
|
||||
|
||||
private void sendFilterChange() {
|
||||
updateButtons();
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketItemConduitFilter(itemConduit, gui.getDir()));
|
||||
System.out.println("ExistingItemFilterGui.enclosing_method: ");
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketItemConduitFilter(itemConduit, gui.getDir()));
|
||||
}
|
||||
|
||||
public void deactivate() {
|
||||
@@ -125,6 +155,8 @@ public class ExistingItemFilterGui implements IItemFilterGui {
|
||||
useMetaB.detach();
|
||||
useOreDictB.detach();
|
||||
stickyB.detach();
|
||||
gui.removeButton(snapshotB);
|
||||
gui.removeButton(clearB);
|
||||
}
|
||||
|
||||
public void renderCustomOptions(int top, float par1, int par2, int par3) {
|
||||
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
package crazypants.enderio.conduit.gui.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import crazypants.enderio.conduit.item.IItemConduit;
|
||||
import crazypants.enderio.conduit.item.ItemConduitNetwork;
|
||||
import crazypants.enderio.conduit.item.NetworkedInventory;
|
||||
import crazypants.enderio.conduit.item.filter.ExistingItemFilter;
|
||||
import crazypants.enderio.conduit.packet.AbstractConduitPacket;
|
||||
import crazypants.enderio.conduit.packet.ConTypeEnum;
|
||||
|
||||
public class PacketExistingItemFilterSnapshot extends AbstractConduitPacket<IItemConduit> implements IMessageHandler<PacketExistingItemFilterSnapshot, IMessage> {
|
||||
|
||||
private ForgeDirection dir;
|
||||
private boolean isClear;
|
||||
private boolean isInput;
|
||||
|
||||
public PacketExistingItemFilterSnapshot() {
|
||||
}
|
||||
|
||||
public PacketExistingItemFilterSnapshot(IItemConduit con, ForgeDirection dir, boolean isInput, boolean isClear) {
|
||||
super(con.getBundle().getEntity(), ConTypeEnum.ITEM);
|
||||
this.dir = dir;
|
||||
this.isInput= isInput;
|
||||
this.isClear = isClear;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
super.fromBytes(buf);
|
||||
dir = ForgeDirection.values()[buf.readShort()];
|
||||
isInput = buf.readBoolean();
|
||||
isClear = buf.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
super.toBytes(buf);
|
||||
buf.writeShort(dir.ordinal());
|
||||
buf.writeBoolean(isInput);
|
||||
buf.writeBoolean(isClear);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketExistingItemFilterSnapshot onMessage(PacketExistingItemFilterSnapshot message, MessageContext ctx) {
|
||||
IItemConduit conduit = message.getTileCasted(ctx);
|
||||
if(conduit == null) {
|
||||
return null;
|
||||
}
|
||||
ExistingItemFilter filter;
|
||||
if(message.isInput) {
|
||||
filter = (ExistingItemFilter)conduit.getInputFilter(message.dir);
|
||||
} else {
|
||||
filter = (ExistingItemFilter)conduit.getOutputFilter(message.dir);
|
||||
}
|
||||
|
||||
if(message.isClear) {
|
||||
filter.setSnapshot((List<ItemStack>)null);
|
||||
System.out.println("PacketExistingItemFilterSnapshot.onMessage: Cleared snapshot");
|
||||
} else {
|
||||
ItemConduitNetwork icn = (ItemConduitNetwork)conduit.getNetwork();
|
||||
NetworkedInventory inv = icn.getInventory(conduit, message.dir);
|
||||
filter.setSnapshot(inv);
|
||||
}
|
||||
|
||||
if(message.isInput) {
|
||||
conduit.setInputFilter(message.dir, filter);
|
||||
} else {
|
||||
conduit.setOutputFilter(message.dir, filter);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -67,6 +67,15 @@ public class ItemConduitNetwork extends AbstractConduitNetwork<IItemConduit, IIt
|
||||
getOrCreate(bc).add(inv);
|
||||
requiresSort = true;
|
||||
}
|
||||
|
||||
public NetworkedInventory getInventory(IItemConduit conduit, ForgeDirection dir) {
|
||||
for(NetworkedInventory inv : inventories) {
|
||||
if(inv.con == conduit && inv.conDir == dir) {
|
||||
return inv;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<NetworkedInventory> getOrCreate(BlockCoord bc) {
|
||||
List<NetworkedInventory> res = invMap.get(bc);
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
package crazypants.enderio.conduit.item.filter;
|
||||
|
||||
import io.netty.util.NetUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import crazypants.enderio.conduit.item.NetworkedInventory;
|
||||
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import crazypants.enderio.conduit.item.NetworkedInventory;
|
||||
|
||||
public class ExistingItemFilter implements IItemFilter {
|
||||
|
||||
@@ -18,70 +21,65 @@ public class ExistingItemFilter implements IItemFilter {
|
||||
boolean convertOreDict = false;
|
||||
boolean matchNBT = false;
|
||||
boolean sticky = false;
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbtRoot) {
|
||||
matchMeta = nbtRoot.getBoolean("matchMeta");
|
||||
matchNBT = nbtRoot.getBoolean("matchNBT");
|
||||
useOreDict = nbtRoot.getBoolean("useOreDict");
|
||||
sticky = nbtRoot.getBoolean("sticky");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbtRoot) {
|
||||
nbtRoot.setBoolean("matchMeta", matchMeta);
|
||||
nbtRoot.setBoolean("matchNBT", matchNBT);
|
||||
nbtRoot.setBoolean("useOreDict", useOreDict);
|
||||
nbtRoot.setBoolean("sticky", sticky);
|
||||
}
|
||||
List<ItemStack> snapshot = null;
|
||||
|
||||
@Override
|
||||
public boolean doesItemPassFilter(NetworkedInventory ni, ItemStack item) {
|
||||
if(item == null) {
|
||||
return false;
|
||||
}
|
||||
int[] slots = ni.getInventory().getAccessibleSlotsFromSide(ni.getInventorySide());
|
||||
for(int i=0;i<slots.length;i++) {
|
||||
ItemStack stack = ni.getInventory().getStackInSlot(i);
|
||||
if(stackEqual(item, stack)) {
|
||||
return true;
|
||||
}
|
||||
if(snapshot == null) {
|
||||
int[] slots = ni.getInventory().getAccessibleSlotsFromSide(ni.getInventorySide());
|
||||
for (int i = 0; i < slots.length; i++) {
|
||||
ItemStack stack = ni.getInventory().getStackInSlot(i);
|
||||
if(stackEqual(item, stack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(ItemStack stack : snapshot) {
|
||||
if(stackEqual(item, stack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean stackEqual(ItemStack toInsert, ItemStack existing) {
|
||||
if(toInsert == null || existing == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
boolean matched = false;
|
||||
if(useOreDict) {
|
||||
int existingId = OreDictionary.getOreID(existing);
|
||||
matched = existingId != -1 && existingId == OreDictionary.getOreID(toInsert);
|
||||
}
|
||||
if(!matched) {
|
||||
matched = Item.getIdFromItem(toInsert.getItem()) == Item.getIdFromItem(existing.getItem());
|
||||
matched = existingId != -1 && existingId == OreDictionary.getOreID(toInsert);
|
||||
}
|
||||
if(!matched) {
|
||||
matched = Item.getIdFromItem(toInsert.getItem()) == Item.getIdFromItem(existing.getItem());
|
||||
if(matched && matchMeta) {
|
||||
matched = toInsert.getItemDamage() == existing.getItemDamage();
|
||||
matched = toInsert.getItemDamage() == existing.getItemDamage();
|
||||
}
|
||||
if(matched && matchNBT) {
|
||||
if(matched && matchNBT) {
|
||||
matched = ItemStack.areItemStackTagsEqual(toInsert, existing);
|
||||
}
|
||||
}
|
||||
}
|
||||
return matched;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesFilterCaptureStack(NetworkedInventory inv, ItemStack item) {
|
||||
return sticky && doesItemPassFilter(inv, item);
|
||||
boolean res = sticky && doesItemPassFilter(inv, item);
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Slot> getSlots() {
|
||||
return Collections.emptyList();
|
||||
@@ -92,7 +90,25 @@ public class ExistingItemFilter implements IItemFilter {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
public void setSnapshot(NetworkedInventory ni) {
|
||||
snapshot = new ArrayList<ItemStack>();
|
||||
int[] slots = ni.getInventory().getAccessibleSlotsFromSide(ni.getInventorySide());
|
||||
for (int i = 0; i < slots.length; i++) {
|
||||
ItemStack stack = ni.getInventory().getStackInSlot(i);
|
||||
if(stack != null) {
|
||||
snapshot.add(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<ItemStack> getSnapshot() {
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
public void setSnapshot(List<ItemStack> snapshot) {
|
||||
this.snapshot = snapshot;
|
||||
}
|
||||
|
||||
public boolean isMatchMeta() {
|
||||
return matchMeta;
|
||||
}
|
||||
@@ -125,5 +141,52 @@ public class ExistingItemFilter implements IItemFilter {
|
||||
public void setSticky(boolean sticky) {
|
||||
this.sticky = sticky;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbtRoot) {
|
||||
matchMeta = nbtRoot.getBoolean("matchMeta");
|
||||
matchNBT = nbtRoot.getBoolean("matchNBT");
|
||||
useOreDict = nbtRoot.getBoolean("useOreDict");
|
||||
sticky = nbtRoot.getBoolean("sticky");
|
||||
|
||||
if(nbtRoot.hasKey("snapshot")) {
|
||||
snapshot = new ArrayList<ItemStack>();
|
||||
NBTTagList itemList = (NBTTagList)nbtRoot.getTag("snapshot");
|
||||
for(int i=0;i<itemList.tagCount();i++) {
|
||||
NBTTagCompound itemTag = itemList.getCompoundTagAt(i);
|
||||
ItemStack itemStack = ItemStack.loadItemStackFromNBT(itemTag);
|
||||
if(itemStack != null) {
|
||||
snapshot.add(itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
snapshot = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbtRoot) {
|
||||
nbtRoot.setBoolean("matchMeta", matchMeta);
|
||||
nbtRoot.setBoolean("matchNBT", matchNBT);
|
||||
nbtRoot.setBoolean("useOreDict", useOreDict);
|
||||
nbtRoot.setBoolean("sticky", sticky);
|
||||
|
||||
if(snapshot != null) {
|
||||
|
||||
NBTTagList itemList = new NBTTagList();
|
||||
int i = 0;
|
||||
for (ItemStack item : snapshot) {
|
||||
if(item != null) {
|
||||
NBTTagCompound itemTag = new NBTTagCompound();
|
||||
item.writeToNBT(itemTag);
|
||||
itemList.appendTag(itemTag);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
nbtRoot.setTag("snapshot", itemList);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import crazypants.enderio.conduit.liquid.ILiquidConduit;
|
||||
import crazypants.enderio.conduit.power.IPowerConduit;
|
||||
import crazypants.enderio.conduit.redstone.IRedstoneConduit;
|
||||
|
||||
enum ConTypeEnum {
|
||||
public enum ConTypeEnum {
|
||||
|
||||
POWER(IPowerConduit.class),
|
||||
FLUID(ILiquidConduit.class),
|
||||
|
||||
Reference in new issue
Block a user