diff --git a/src/main/java/com/glodblock/github/common/storage/FluidCellInventory.java b/src/main/java/com/glodblock/github/common/storage/FluidCellInventory.java index bcc81542..1b1beb98 100644 --- a/src/main/java/com/glodblock/github/common/storage/FluidCellInventory.java +++ b/src/main/java/com/glodblock/github/common/storage/FluidCellInventory.java @@ -3,7 +3,6 @@ package com.glodblock.github.common.storage; import java.util.ArrayList; import java.util.List; -import com.glodblock.github.crossmod.extracells.storage.ProxyFluidCellInvHandler; import com.glodblock.github.crossmod.extracells.storage.ProxyFluidCellInventory; import com.glodblock.github.crossmod.extracells.storage.ProxyFluidStorageCell; import net.minecraft.inventory.IInventory; diff --git a/src/main/java/com/glodblock/github/crossmod/extracells/ItemReplacements.java b/src/main/java/com/glodblock/github/crossmod/extracells/ItemReplacements.java index acb8d209..0c1c37f9 100644 --- a/src/main/java/com/glodblock/github/crossmod/extracells/ItemReplacements.java +++ b/src/main/java/com/glodblock/github/crossmod/extracells/ItemReplacements.java @@ -4,7 +4,10 @@ import appeng.api.AEApi; import appeng.api.definitions.IItemDefinition; import com.glodblock.github.common.item.ItemMultiFluidStorageCell; import com.glodblock.github.crossmod.extracells.parts.*; +import com.glodblock.github.crossmod.extracells.storage.ProxyExtremeStorageCell; import com.glodblock.github.crossmod.extracells.storage.ProxyFluidStorageCell; +import com.glodblock.github.crossmod.extracells.storage.ProxyItemCellHandler; +import com.glodblock.github.crossmod.extracells.storage.ProxyItemStorageCell; import com.glodblock.github.loader.ItemAndBlockHolder; import net.minecraft.item.Item; @@ -46,17 +49,17 @@ public class ItemReplacements { deprecateFluidStorage("storage.fluid", 7, ItemAndBlockHolder.CELL16384KM, 16384, 131072, 4.0); // Thanks, AEApi. - deprecateItemStorage("storage.physical", 0, AEApi.instance().definitions().items().cell256k()); - deprecateItemStorage("storage.physical", 1, AEApi.instance().definitions().items().cell1024k()); - deprecateItemStorage("storage.physical", 2, AEApi.instance().definitions().items().cell4096k()); - deprecateItemStorage("storage.physical", 3, AEApi.instance().definitions().items().cell16384k()); - deprecateItemStorage("storage.physical", 4, AEApi.instance().definitions().items().cellContainer()); - deprecateItemStorage("storage.physical.advanced.singularity", 0, - AEApi.instance().definitions().items().cellSingularity()); - deprecateItemStorage("storage.physical.advanced.quantum", 0, - AEApi.instance().definitions().items().cellQuantum()); - deprecateItemStorage("storage.physical.void", 0, - AEApi.instance().definitions().items().cellVoid()); + AEApi.instance().registries().cell().addCellHandler(new ProxyItemCellHandler()); + deprecateItemStorage(0, AEApi.instance().definitions().items().cell256k(), 256, 2048, 2.5); + deprecateItemStorage(1, AEApi.instance().definitions().items().cell1024k(), 1024, 8192, 3.0); + deprecateItemStorage(2, AEApi.instance().definitions().items().cell4096k(), 4096, 32768, 3.5); + deprecateItemStorage(3, AEApi.instance().definitions().items().cell16384k(), 16384, 131072, 4.0); + deprecateItemStorage(4, AEApi.instance().definitions().items().cellContainer(), 65536, 8, 2.0, 1); + deprecateExtremeStorage("storage.physical.advanced.quantum", 0, + AEApi.instance().definitions().items().cellQuantum(), Integer.MAX_VALUE / 16, 4096, 1000.0); + deprecateExtremeStorage("storage.physical.advanced.singularity", 0, + AEApi.instance().definitions().items().cellSingularity(), Long.MAX_VALUE / 16, 4096, 15000.0); + deprecateItem("storage.physical.void", 0, AEApi.instance().definitions().items().cellVoid()); deprecateItem("pattern.fluid", ItemAndBlockHolder.PATTERN); deprecateItem("terminal.fluid.wireless", ItemAndBlockHolder.WIRELESS_FLUID_TERM); /* Storage casings */ @@ -114,6 +117,28 @@ public class ItemReplacements { return proxy; } + private static ProxyItemStorageCell getOrBuildItemStorage() { + final String fullName = "extracells:storage.physical"; + ProxyItemStorageCell proxy = (ProxyItemStorageCell) registry.get(fullName); + if (proxy == null) { + proxy = new ProxyItemStorageCell("storage.physical"); + registry.put(fullName, proxy); + proxy.register(); + } + return proxy; + } + + private static ProxyExtremeStorageCell getOrBuildItemStorage(String srcName) { + final String fullName = "extracells:" + srcName; + ProxyExtremeStorageCell proxy = (ProxyExtremeStorageCell) registry.get(fullName); + if (proxy == null) { + proxy = new ProxyExtremeStorageCell(srcName); + registry.put(fullName, proxy); + proxy.register(); + } + return proxy; + } + /** * Deprecate a simple item. * @param srcName name of the to-be-replaced item without the mod id prefix @@ -157,7 +182,7 @@ public class ItemReplacements { */ private static void deprecateFluidStorage(String srcName, int srcMeta, ItemMultiFluidStorageCell replacement, long kilobytes, int bytesPerType, double idleDrain) { ProxyFluidStorageCell proxyItem = getOrBuildFluidStorage(srcName); - ProxyItem.ProxyFluidStorageEntry entry = new ProxyItem.ProxyFluidStorageEntry(replacement, kilobytes, bytesPerType, idleDrain); + ProxyItem.ProxyStorageEntry entry = new ProxyItem.ProxyStorageEntry(replacement, kilobytes, bytesPerType, idleDrain); proxyItem.addMetaReplacement(srcMeta, entry); } @@ -165,11 +190,36 @@ public class ItemReplacements { * Deprecate a storage item. This goes through AEAPI, as AE2FC doesn't have any item cells. * If the item is disabled in AEAPI, the replacement will not be registered! */ - private static void deprecateItemStorage(String srcName, int srcMeta, IItemDefinition replacement) { + private static void deprecateItemStorage(int srcMeta, IItemDefinition replacement, long kilobytes, int bytesPerType, double idleDrain) { if (replacement.isEnabled()) { - ProxyItem item = getOrBuildItem(srcName); - ProxyItem.ProxyItemEntry storage = new ProxyItem.ItemStorageEntry( - replacement.maybeItem().get(), replacement.maybeStack(1).get().getItemDamage()); + ProxyItemStorageCell item = getOrBuildItemStorage(); + int meta = replacement.maybeStack(1).get().getItemDamage(); + ProxyItem.ProxyItemEntry storage = new ProxyItem.ProxyStorageEntry( + replacement.maybeItem().get(), kilobytes, bytesPerType, idleDrain); + item.addMetaReplacement(srcMeta, storage); + } + } + + /** + * Deprecate a storage item. This goes through AEAPI, as AE2FC doesn't have any item cells. + * If the item is disabled in AEAPI, the replacement will not be registered! + */ + private static void deprecateItemStorage(int srcMeta, IItemDefinition replacement, long kilobytes, int bytesPerType, double idleDrain, int types) { + if (replacement.isEnabled()) { + ProxyItemStorageCell item = getOrBuildItemStorage(); + int meta = replacement.maybeStack(1).get().getItemDamage(); + ProxyItem.ProxyItemEntry storage = new ProxyItem.ProxyStorageEntry( + replacement.maybeItem().get(), kilobytes, bytesPerType, idleDrain, types); + item.addMetaReplacement(srcMeta, storage); + } + } + + private static void deprecateExtremeStorage(String srcName, int srcMeta, IItemDefinition replacement, long bytes, int bytesPerType, double idleDrain) { + if (replacement.isEnabled()) { + ProxyExtremeStorageCell item = getOrBuildItemStorage(srcName); + int meta = replacement.maybeStack(1).get().getItemDamage(); + ProxyItem.ProxyItemEntry storage = new ProxyItem.ProxyStorageEntry( + replacement.maybeItem().get(), bytes / 1024, bytesPerType, idleDrain); item.addMetaReplacement(srcMeta, storage); } } diff --git a/src/main/java/com/glodblock/github/crossmod/extracells/ProxyItem.java b/src/main/java/com/glodblock/github/crossmod/extracells/ProxyItem.java index 19c53631..3cc4538e 100644 --- a/src/main/java/com/glodblock/github/crossmod/extracells/ProxyItem.java +++ b/src/main/java/com/glodblock/github/crossmod/extracells/ProxyItem.java @@ -99,34 +99,32 @@ public class ProxyItem extends FCBaseItem { this.replacementMeta = replacementMeta; } - NBTTagCompound replaceNBT(NBTTagCompound compound) { - return compound; - } - } - - protected static class ItemStorageEntry extends ProxyItemEntry { - ItemStorageEntry(Item replacement, int replacementMeta) { - super(replacement, replacementMeta); - } - - @Override NBTTagCompound replaceNBT(NBTTagCompound compound) { System.out.println(compound); return compound; } } - protected static class ProxyFluidStorageEntry extends ProxyItemEntry { + protected static class ProxyStorageEntry extends ProxyItemEntry { public final long maxBytes; public final int bytesPerType; public final double idleDrain; - protected ProxyFluidStorageEntry(ItemMultiFluidStorageCell replacement, long kilobytes, int bytesPerType, double idleDrain) { + public final int types; + protected ProxyStorageEntry(Item replacement, long kilobytes, int bytesPerType, double idleDrain) { super(replacement, 0); this.maxBytes = kilobytes * 1024; this.bytesPerType = bytesPerType; this.idleDrain = idleDrain; + this.types = 63; } + protected ProxyStorageEntry(Item replacement, long kilobytes, int bytesPerType, double idleDrain, int types) { + super(replacement, 0); + this.maxBytes = kilobytes * 1024; + this.bytesPerType = bytesPerType; + this.idleDrain = idleDrain; + this.types = types; + } @Override NBTTagCompound replaceNBT(NBTTagCompound compound) { if (compound != null && compound.hasKey("ecc")) { diff --git a/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyExtremeStorageCell.java b/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyExtremeStorageCell.java new file mode 100644 index 00000000..14ed2496 --- /dev/null +++ b/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyExtremeStorageCell.java @@ -0,0 +1,14 @@ +package com.glodblock.github.crossmod.extracells.storage; + +import net.minecraft.item.ItemStack; + +public class ProxyExtremeStorageCell extends ProxyItemStorageCell { + public ProxyExtremeStorageCell(String ec2itemName) { + super(ec2itemName); + } + + @Override + public int getTotalTypes(ItemStack cellItem) { + return 1; + } +} diff --git a/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyFluidCellInvHandler.java b/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyFluidCellInvHandler.java deleted file mode 100644 index 235fd42c..00000000 --- a/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyFluidCellInvHandler.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.glodblock.github.crossmod.extracells.storage; - -import com.glodblock.github.common.storage.*; - - -public class ProxyFluidCellInvHandler extends FluidCellInventoryHandler { - - public ProxyFluidCellInvHandler(FluidCellInventory inv) { - super(inv); - } -} diff --git a/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyFluidStorageCell.java b/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyFluidStorageCell.java index efca5ef6..9c1839cf 100644 --- a/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyFluidStorageCell.java +++ b/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyFluidStorageCell.java @@ -6,13 +6,11 @@ import appeng.items.contents.CellConfig; import appeng.items.contents.CellUpgrades; import appeng.util.Platform; import com.glodblock.github.common.Config; -import com.glodblock.github.common.item.ItemMultiFluidStorageCell; import com.glodblock.github.common.storage.IStorageFluidCell; import com.glodblock.github.crossmod.extracells.ProxyItem; import com.glodblock.github.util.ModAndClassUtil; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; public class ProxyFluidStorageCell extends ProxyItem implements IStorageFluidCell { @@ -25,8 +23,8 @@ public class ProxyFluidStorageCell extends ProxyItem implements IStorageFluidCel int meta = cellItem.getItemDamage(); if (replacements.containsKey(meta)) { ProxyItemEntry entry = replacements.get(meta); - if (entry instanceof ProxyFluidStorageEntry) { - return ((ProxyFluidStorageEntry) entry).maxBytes; + if (entry instanceof ProxyStorageEntry) { + return ((ProxyStorageEntry) entry).maxBytes; } } return 0; @@ -37,8 +35,8 @@ public class ProxyFluidStorageCell extends ProxyItem implements IStorageFluidCel int meta = cellItem.getItemDamage(); if (replacements.containsKey(meta)) { ProxyItemEntry entry = replacements.get(meta); - if (entry instanceof ProxyFluidStorageEntry) { - return ((ProxyFluidStorageEntry) entry).bytesPerType; + if (entry instanceof ProxyStorageEntry) { + return ((ProxyStorageEntry) entry).bytesPerType; } } return 0; @@ -67,8 +65,8 @@ public class ProxyFluidStorageCell extends ProxyItem implements IStorageFluidCel int meta = is.getItemDamage(); if (replacements.containsKey(meta)) { ProxyItemEntry entry = replacements.get(meta); - if (entry instanceof ProxyFluidStorageEntry) { - return ((ProxyFluidStorageEntry) entry).idleDrain; + if (entry instanceof ProxyStorageEntry) { + return ((ProxyStorageEntry) entry).idleDrain; } } return 0; diff --git a/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyItemCellHandler.java b/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyItemCellHandler.java new file mode 100644 index 00000000..2644ca1e --- /dev/null +++ b/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyItemCellHandler.java @@ -0,0 +1,12 @@ +package com.glodblock.github.crossmod.extracells.storage; + +import appeng.core.features.registries.entries.BasicCellHandler; +import net.minecraft.item.ItemStack; + +public class ProxyItemCellHandler extends BasicCellHandler { + + @Override + public boolean isCell(ItemStack is) { + return is != null && is.getItem() != null && is.getItem() instanceof ProxyItemStorageCell; + } +} diff --git a/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyItemStorageCell.java b/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyItemStorageCell.java new file mode 100644 index 00000000..f947d5ce --- /dev/null +++ b/src/main/java/com/glodblock/github/crossmod/extracells/storage/ProxyItemStorageCell.java @@ -0,0 +1,159 @@ +package com.glodblock.github.crossmod.extracells.storage; + +import appeng.api.config.FuzzyMode; +import appeng.api.implementations.items.IStorageCell; +import appeng.api.storage.data.IAEItemStack; +import appeng.items.contents.CellConfig; +import appeng.items.contents.CellUpgrades; +import appeng.util.Platform; +import com.glodblock.github.crossmod.extracells.ProxyItem; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; + +import javax.annotation.Nullable; + +/** + * Proxy Item Storage. 256K, 1024K, etc. -> AE2's version. + * For now its just mirroring AE2's version, will need to transition to something better. + */ +public class ProxyItemStorageCell extends ProxyItem implements IStorageCell { + + public ProxyItemStorageCell(String ec2itemName) { + super(ec2itemName); + } + + @Override + public int getBytes(ItemStack cellItem) { + if (cellItem == null) { + return 0; + } + int meta = cellItem.getItemDamage(); + if (replacements.containsKey(meta)) { + ProxyItemEntry entry = replacements.get(meta); + if (entry instanceof ProxyStorageEntry) { + return (int) ((ProxyStorageEntry) entry).maxBytes; + } + } + return 0; + } + + @Override + public int BytePerType(ItemStack cellItem) { + if (cellItem == null) { + return 0; + } + int meta = cellItem.getItemDamage(); + if (replacements.containsKey(meta)) { + ProxyItemEntry entry = replacements.get(meta); + if (entry instanceof ProxyStorageEntry) { + return ((ProxyStorageEntry) entry).bytesPerType; + } + } + return 0; + } + + @Override + public int getBytesPerType(ItemStack cellItem) { + if (cellItem == null) { + return 0; + } + int meta = cellItem.getItemDamage(); + if (replacements.containsKey(meta)) { + ProxyItemEntry entry = replacements.get(meta); + if (entry instanceof ProxyStorageEntry) { + return ((ProxyStorageEntry) entry).bytesPerType; + } + } + return 0; + } + + @Override + public long getBytesLong(ItemStack cellItem) { + if (cellItem == null) { + return 0; + } + int meta = cellItem.getItemDamage(); + if (replacements.containsKey(meta)) { + ProxyItemEntry entry = replacements.get(meta); + if (entry instanceof ProxyStorageEntry) { + return ((ProxyStorageEntry) entry).maxBytes; + } + } + return 0; + } + + @Override + public int getTotalTypes(ItemStack cellItem) { + return 63; + } + + @Override + public boolean isBlackListed(ItemStack cellItem, IAEItemStack requestedAddition) { + return false; + } + + @Override + public boolean storableInStorageCell() { + return false; + } + + @Override + public boolean isStorageCell(ItemStack i) { + return true; + } + + @Override + public double getIdleDrain(@Nullable ItemStack cellItem) { + if (cellItem == null) { + return 0.0; + } + int meta = cellItem.getItemDamage(); + if (replacements.containsKey(meta)) { + ProxyItemEntry entry = replacements.get(meta); + if (entry instanceof ProxyStorageEntry) { + return ((ProxyStorageEntry) entry).bytesPerType; + } + } + return 0; + } + + @Override + public double getIdleDrain() { + return 0; + } + + @Override + public boolean isEditable(ItemStack is) { + return true; + } + + @Override + public IInventory getUpgradesInventory(ItemStack is) { + return new CellUpgrades(is, 2); + } + + @Override + public IInventory getConfigInventory(ItemStack is) { + return new CellConfig(is); + } + + @Override + public FuzzyMode getFuzzyMode(ItemStack is) { + final String fz = Platform.openNbtData(is).getString("FuzzyMode"); + try { + return FuzzyMode.valueOf(fz); + } catch (final Throwable t) { + return FuzzyMode.IGNORE_ALL; + } + } + + @Override + public void setFuzzyMode(ItemStack is, FuzzyMode fzMode) { + Platform.openNbtData(is).setString("FuzzyMode", fzMode.name()); + } + + @Override + public String getOreFilter(ItemStack is) { + return Platform.openNbtData(is).getString("OreFilter"); + } +}