mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-26 23:13:21 +00:00
#1310 Crash using existing item filter
This commit is contained in:
1 parent
d21fb9c9a2
commit
ccd589214e
7 files changed
+109
-31
No files matched your search
@@ -7,8 +7,6 @@ import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
import crazypants.enderio.Log;
|
||||
import crazypants.enderio.conduit.item.filter.IItemFilter;
|
||||
import crazypants.enderio.conduit.item.filter.IItemFilterUpgrade;
|
||||
import crazypants.enderio.conduit.item.filter.ItemFilter;
|
||||
import crazypants.enderio.network.NetworkUtil;
|
||||
|
||||
public class FilterRegister {
|
||||
|
||||
@@ -74,18 +72,18 @@ public class FilterRegister {
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateLegacyFilterNbt(NBTTagCompound filterTag, int conduitMeta) {
|
||||
if(filterTag == null) {
|
||||
return;
|
||||
}
|
||||
if(!filterTag.hasKey("filterClass")) {
|
||||
filterTag.setString("filterClass", ItemFilter.class.getName());
|
||||
}
|
||||
if(!filterTag.hasKey("isAdvanced")) {
|
||||
filterTag.setBoolean("isAdvanced", conduitMeta == 1);
|
||||
private static IItemFilter loadFilterFromByteBuf(String className, ByteBuf buf) {
|
||||
try {
|
||||
Class<?> clz = Class.forName(className);
|
||||
IItemFilter filter = (IItemFilter) clz.newInstance();
|
||||
filter.readFromByteBuf(buf);
|
||||
return filter;
|
||||
} catch (Exception e) {
|
||||
Log.error("Could not read item filter with class name: " + className + " from ByteBuf Error: " + e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void writeFilter(ByteBuf buf, IItemFilter filter) {
|
||||
if(filter == null) {
|
||||
ByteBufUtils.writeUTF8String(buf, "nullFilter");
|
||||
@@ -93,10 +91,7 @@ public class FilterRegister {
|
||||
}
|
||||
String name = filter.getClass().getName();
|
||||
ByteBufUtils.writeUTF8String(buf, name);
|
||||
|
||||
NBTTagCompound root = new NBTTagCompound();
|
||||
filter.writeToNBT(root);
|
||||
NetworkUtil.writeNBTTagCompound(root, buf);
|
||||
filter.writeToByteBuf(buf);
|
||||
}
|
||||
|
||||
public static IItemFilter readFilter(ByteBuf buf) {
|
||||
@@ -104,8 +99,7 @@ public class FilterRegister {
|
||||
if(className.equals("nullFilter")) {
|
||||
return null;
|
||||
}
|
||||
NBTTagCompound tag = NetworkUtil.readNBTTagCompound(buf);
|
||||
return loadFilterFromNbt(className, tag);
|
||||
return loadFilterFromByteBuf(className, buf);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -110,7 +110,7 @@ public class ItemConduit extends AbstractConduit implements IItemConduit {
|
||||
}
|
||||
|
||||
public ItemConduit(int itemDamage) {
|
||||
this.metaData = itemDamage;
|
||||
metaData = itemDamage;
|
||||
updateFromNonUpgradeableVersion();
|
||||
}
|
||||
|
||||
@@ -754,7 +754,6 @@ public class ItemConduit extends AbstractConduit implements IItemConduit {
|
||||
String key = "inFilts." + dir.name();
|
||||
if(nbtRoot.hasKey(key)) {
|
||||
NBTTagCompound filterTag = (NBTTagCompound) nbtRoot.getTag(key);
|
||||
FilterRegister.updateLegacyFilterNbt(filterTag, metaData);
|
||||
IItemFilter filter = FilterRegister.loadFilterFromNbt(filterTag);
|
||||
inputFilters.put(dir, filter);
|
||||
}
|
||||
@@ -783,7 +782,6 @@ public class ItemConduit extends AbstractConduit implements IItemConduit {
|
||||
key = "outFilts." + dir.name();
|
||||
if(nbtRoot.hasKey(key)) {
|
||||
NBTTagCompound filterTag = (NBTTagCompound) nbtRoot.getTag(key);
|
||||
FilterRegister.updateLegacyFilterNbt(filterTag, metaData);
|
||||
IItemFilter filter = FilterRegister.loadFilterFromNbt(filterTag);
|
||||
outputFilters.put(dir, filter);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package crazypants.enderio.conduit.item.filter;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -11,6 +13,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import crazypants.enderio.conduit.item.NetworkedInventory;
|
||||
import crazypants.enderio.network.NetworkUtil;
|
||||
|
||||
public class ExistingItemFilter implements IItemFilter {
|
||||
|
||||
@@ -142,10 +145,7 @@ public class ExistingItemFilter implements IItemFilter {
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbtRoot) {
|
||||
matchMeta = nbtRoot.getBoolean("matchMeta");
|
||||
matchNBT = nbtRoot.getBoolean("matchNBT");
|
||||
useOreDict = nbtRoot.getBoolean("useOreDict");
|
||||
sticky = nbtRoot.getBoolean("sticky");
|
||||
readSettingsFromNBT(nbtRoot);
|
||||
|
||||
if(nbtRoot.hasKey("snapshot")) {
|
||||
snapshot = new ArrayList<ItemStack>();
|
||||
@@ -163,12 +163,16 @@ public class ExistingItemFilter implements IItemFilter {
|
||||
}
|
||||
}
|
||||
|
||||
protected void readSettingsFromNBT(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);
|
||||
writeSettingToNBT(nbtRoot);
|
||||
|
||||
if(snapshot != null) {
|
||||
|
||||
@@ -187,4 +191,47 @@ public class ExistingItemFilter implements IItemFilter {
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeSettingToNBT(NBTTagCompound nbtRoot) {
|
||||
nbtRoot.setBoolean("matchMeta", matchMeta);
|
||||
nbtRoot.setBoolean("matchNBT", matchNBT);
|
||||
nbtRoot.setBoolean("useOreDict", useOreDict);
|
||||
nbtRoot.setBoolean("sticky", sticky);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToByteBuf(ByteBuf buf) {
|
||||
NBTTagCompound settingsTag = new NBTTagCompound();
|
||||
writeSettingToNBT(settingsTag);
|
||||
NetworkUtil.writeNBTTagCompound(settingsTag, buf);
|
||||
buf.writeInt(snapshot == null ? 0 : snapshot.size());
|
||||
if(snapshot == null) {
|
||||
return;
|
||||
}
|
||||
for (ItemStack item : snapshot) {
|
||||
NBTTagCompound itemRoot = new NBTTagCompound();
|
||||
item.writeToNBT(itemRoot);
|
||||
NetworkUtil.writeNBTTagCompound(itemRoot, buf);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromByteBuf(ByteBuf buf) {
|
||||
NBTTagCompound settingsTag = NetworkUtil.readNBTTagCompound(buf);
|
||||
readSettingsFromNBT(settingsTag);
|
||||
int numItems = buf.readInt();
|
||||
if(numItems == 0) {
|
||||
snapshot = null;
|
||||
return;
|
||||
}
|
||||
snapshot = new ArrayList<ItemStack>(numItems);
|
||||
for (int i = 0; i < numItems; i++) {
|
||||
NBTTagCompound itemTag = NetworkUtil.readNBTTagCompound(buf);
|
||||
ItemStack item = ItemStack.loadItemStackFromNBT(itemTag);
|
||||
if(item != null) {
|
||||
snapshot.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package crazypants.enderio.conduit.item.filter;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.inventory.Slot;
|
||||
@@ -13,6 +15,10 @@ public interface IItemFilter {
|
||||
|
||||
void writeToNBT(NBTTagCompound nbtRoot);
|
||||
|
||||
void writeToByteBuf(ByteBuf buf);
|
||||
|
||||
void readFromByteBuf(ByteBuf buf);
|
||||
|
||||
boolean doesItemPassFilter(NetworkedInventory inv, ItemStack item);
|
||||
|
||||
boolean doesFilterCaptureStack(NetworkedInventory inv, ItemStack item);
|
||||
@@ -24,5 +30,5 @@ public interface IItemFilter {
|
||||
List<Slot> getSlots(int xOffset, int yOffset);
|
||||
|
||||
int getSlotCount();
|
||||
|
||||
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package crazypants.enderio.conduit.item.filter;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -13,6 +15,7 @@ import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import crazypants.enderio.conduit.item.NetworkedInventory;
|
||||
import crazypants.enderio.network.NetworkUtil;
|
||||
import crazypants.gui.TemplateSlot;
|
||||
|
||||
public class ItemFilter implements IInventory, IItemFilter {
|
||||
@@ -232,6 +235,19 @@ public class ItemFilter implements IInventory, IItemFilter {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToByteBuf(ByteBuf buf) {
|
||||
NBTTagCompound root = new NBTTagCompound();
|
||||
writeToNBT(root);
|
||||
NetworkUtil.writeNBTTagCompound(root, buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromByteBuf(ByteBuf buf) {
|
||||
NBTTagCompound tag = NetworkUtil.readNBTTagCompound(buf);
|
||||
readFromNBT(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return items.length;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package crazypants.enderio.conduit.item.filter;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@@ -9,6 +11,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier;
|
||||
import crazypants.enderio.conduit.item.NetworkedInventory;
|
||||
import crazypants.enderio.network.NetworkUtil;
|
||||
|
||||
public class ModItemFilter implements IItemFilter {
|
||||
|
||||
@@ -121,4 +124,17 @@ public class ModItemFilter implements IItemFilter {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToByteBuf(ByteBuf buf) {
|
||||
NBTTagCompound root = new NBTTagCompound();
|
||||
writeToNBT(root);
|
||||
NetworkUtil.writeNBTTagCompound(root, buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromByteBuf(ByteBuf buf) {
|
||||
NBTTagCompound tag = NetworkUtil.readNBTTagCompound(buf);
|
||||
readFromNBT(tag);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user