diff --git a/src/main/java/com/glodblock/github/crossmod/extracells/EC2ProxyBlock.java b/src/main/java/com/glodblock/github/crossmod/extracells/EC2ProxyBlock.java deleted file mode 100644 index 8c7c93f7..00000000 --- a/src/main/java/com/glodblock/github/crossmod/extracells/EC2ProxyBlock.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.glodblock.github.crossmod.extracells; - -import cpw.mods.fml.common.registry.GameRegistry; -import net.minecraft.block.Block; -import net.minecraft.block.material.Material; -import net.minecraft.item.ItemBlock; - -public class EC2ProxyBlock extends Block { - - protected final String name; - protected final int meta; - protected final Block replacement; - protected final int metaReplacement; - - public EC2ProxyBlock(String ec2itemName, int meta, Block replacement, int metaReplacement) { - super(Material.air); //??? - this.name = ec2itemName; - this.meta = meta; - this.replacement = replacement; - this.metaReplacement = metaReplacement; - } - - void register() { - GameRegistry.registerBlock(this, EC2ProxyItemBlock.class, "ec2placeholder." + name); - } - - public static class EC2ProxyItemBlock extends ItemBlock { - - public EC2ProxyItemBlock(Block block) { - super(block); - } - } -} diff --git a/src/main/java/com/glodblock/github/crossmod/extracells/EC2Replacer.java b/src/main/java/com/glodblock/github/crossmod/extracells/EC2Replacer.java index fa16dc41..afa62f2c 100644 --- a/src/main/java/com/glodblock/github/crossmod/extracells/EC2Replacer.java +++ b/src/main/java/com/glodblock/github/crossmod/extracells/EC2Replacer.java @@ -1,45 +1,30 @@ package com.glodblock.github.crossmod.extracells; import cpw.mods.fml.common.event.FMLMissingMappingsEvent; -import net.minecraft.block.Block; +import cpw.mods.fml.common.registry.GameRegistry; import net.minecraft.item.Item; -import java.util.HashMap; import java.util.List; -import java.util.Map; public class EC2Replacer { - private static Map blocks; /** * Should be called if and only if replaceEC2 config is true and EC2 not present. Registers proxy * items for the entire EC2 mod. After running this once, you should set replaceEC2 back to false. */ public static void initReplacer() { - blocks = new HashMap<>(23); ItemReplacements.init(); } - private static void deprecateBlock(String name, int meta, Block replacement) { - deprecateBlock(name, meta, replacement, 0); - } - - private static void deprecateBlock(String name, int meta, Block replacement, int metaReplacement) { - EC2ProxyBlock block = new EC2ProxyBlock(name, meta, replacement, metaReplacement); - blocks.put("extracells:" + name, block); - block.register(); - } - public static void replaceExtraCells(FMLMissingMappingsEvent event) { List mappings = event.getAll(); for (FMLMissingMappingsEvent.MissingMapping m : mappings) { - if (ItemReplacements.registry.containsKey(m.name)) { + if (m.type == GameRegistry.Type.ITEM && ItemReplacements.registry.containsKey(m.name)) { Item toRemap = ItemReplacements.registry.get(m.name); m.remap(toRemap); - } else if (blocks.containsKey(m.name)) { - Block toRemap = blocks.get(m.name); - m.remap(toRemap); + } else { + m.warn(); } } } diff --git a/src/main/java/com/glodblock/github/crossmod/extracells/EC2TileEntity.java b/src/main/java/com/glodblock/github/crossmod/extracells/EC2TileEntity.java deleted file mode 100644 index 84b90b44..00000000 --- a/src/main/java/com/glodblock/github/crossmod/extracells/EC2TileEntity.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.glodblock.github.crossmod.extracells; - -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; - -public abstract class EC2TileEntity extends TileEntity { - - private Object oldTile; - private Class newTile; - public EC2TileEntity(String name, T oldTE, Class newTE) { - this.oldTile = oldTE; - this.newTile = newTE; - } - - abstract TileEntity remap(); - -} 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 62f7f15f..acb8d209 100644 --- a/src/main/java/com/glodblock/github/crossmod/extracells/ItemReplacements.java +++ b/src/main/java/com/glodblock/github/crossmod/extracells/ItemReplacements.java @@ -2,10 +2,11 @@ package com.glodblock.github.crossmod.extracells; 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.ProxyFluidStorageCell; import com.glodblock.github.loader.ItemAndBlockHolder; import net.minecraft.item.Item; -import net.minecraft.nbt.NBTTagCompound; import java.util.HashMap; import java.util.Map; @@ -16,7 +17,7 @@ import java.util.function.Function; */ public class ItemReplacements { - protected static Map registry; + protected static Map registry; static void init() { registry = new HashMap<>(23); @@ -28,14 +29,22 @@ public class ItemReplacements { * Register proxy items (non-parts) */ static void proxyItems() { - deprecateFluidStorage("storage.fluid", 0, ItemAndBlockHolder.CELL1KM); - deprecateFluidStorage("storage.fluid", 1, ItemAndBlockHolder.CELL4KM); - deprecateFluidStorage("storage.fluid", 3, ItemAndBlockHolder.CELL64KM); - deprecateFluidStorage("storage.fluid", 4, ItemAndBlockHolder.CELL256KM); - deprecateFluidStorage("storage.fluid", 2, ItemAndBlockHolder.CELL16KM); - deprecateFluidStorage("storage.fluid", 5, ItemAndBlockHolder.CELL1024KM); - deprecateFluidStorage("storage.fluid", 6, ItemAndBlockHolder.CELL4096KM); - deprecateFluidStorage("storage.fluid", 7, ItemAndBlockHolder.CELL16384KM); + deprecateFluidStorage("storage.fluid", 0, ItemAndBlockHolder.CELL1KM, + 1, 8, 0.5); + deprecateFluidStorage("storage.fluid", 1, ItemAndBlockHolder.CELL4KM, + 4, 32, 1.0); + deprecateFluidStorage("storage.fluid", 2, ItemAndBlockHolder.CELL16KM, + 16, 128, 1.5); + deprecateFluidStorage("storage.fluid", 3, ItemAndBlockHolder.CELL64KM, + 64, 512, 2.0); + deprecateFluidStorage("storage.fluid", 4, ItemAndBlockHolder.CELL256KM, + 256, 2048, 2.5); + deprecateFluidStorage("storage.fluid", 5, ItemAndBlockHolder.CELL1024KM, + 1024, 8192, 3.0); + deprecateFluidStorage("storage.fluid", 6, ItemAndBlockHolder.CELL4096KM, + 4096, 32768, 3.5); + 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()); @@ -67,7 +76,6 @@ public class ItemReplacements { deprecateItem("storage.component", 9, ItemAndBlockHolder.CELL_PART, 5); deprecateItem("storage.component", 10, ItemAndBlockHolder.CELL_PART, 6); deprecateItem("terminal.universal.wireless", ItemAndBlockHolder.WIRELESS_ULTRA_TERM); - } /** @@ -86,7 +94,7 @@ public class ItemReplacements { private static ProxyItem getOrBuildItem(String srcName) { final String fullName = "extracells:" + srcName; - ProxyItem proxy = registry.get(fullName); + ProxyItem proxy = (ProxyItem) registry.get(fullName); if (proxy == null) { proxy = new ProxyItem(srcName); registry.put(fullName, proxy); @@ -95,6 +103,17 @@ public class ItemReplacements { return proxy; } + private static ProxyFluidStorageCell getOrBuildFluidStorage(String srcName) { + final String fullName = "extracells:" + srcName; + ProxyFluidStorageCell proxy = (ProxyFluidStorageCell) registry.get(fullName); + if (proxy == null) { + proxy = new ProxyFluidStorageCell(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 @@ -106,6 +125,10 @@ public class ItemReplacements { getOrBuildItem(srcName).addMetaReplacement(srcMeta, replacement, targetMeta); } + static void deprecateItemBlock(String srcName, int srcMeta, Item replacement, int targetMeta) { + getOrBuildItem("itemBlock." + srcName).addMetaReplacement(srcMeta, replacement, targetMeta); + } + private static void deprecateItem(String srcName, Item replacement) { deprecateItem(srcName, 0, replacement, 0); } @@ -130,12 +153,12 @@ public class ItemReplacements { } /** - * Deprecate a storage item. + * Deprecate a fluid storage item. Note that we can't access the properties directly, so we need to do this */ - private static void deprecateFluidStorage(String srcName, int srcMeta, Item replacement) { - ProxyItem item = getOrBuildItem(srcName); - ProxyItem.ProxyReplacement storage = new FluidStorageReplacement(replacement, 0); - item.addMetaReplacement(srcMeta, storage); + 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.addMetaReplacement(srcMeta, entry); } /** @@ -145,33 +168,13 @@ public class ItemReplacements { private static void deprecateItemStorage(String srcName, int srcMeta, IItemDefinition replacement) { if (replacement.isEnabled()) { ProxyItem item = getOrBuildItem(srcName); - ProxyItem.ProxyReplacement storage = new ItemStorageReplacement( + ProxyItem.ProxyItemEntry storage = new ProxyItem.ItemStorageEntry( replacement.maybeItem().get(), replacement.maybeStack(1).get().getItemDamage()); item.addMetaReplacement(srcMeta, storage); } } } -class FluidStorageReplacement extends ProxyItem.ProxyReplacement { - FluidStorageReplacement(Item replacement, int replacementMeta) { - super(replacement, replacementMeta); - } - @Override - NBTTagCompound replaceNBT(NBTTagCompound compound) { - System.out.println(compound); - return compound; - } -} -class ItemStorageReplacement extends ProxyItem.ProxyReplacement { - ItemStorageReplacement(Item replacement, int replacementMeta) { - super(replacement, replacementMeta); - } - @Override - NBTTagCompound replaceNBT(NBTTagCompound compound) { - System.out.println(compound); - return compound; - } -} 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 92e9ce7c..815cc4b7 100644 --- a/src/main/java/com/glodblock/github/crossmod/extracells/ProxyItem.java +++ b/src/main/java/com/glodblock/github/crossmod/extracells/ProxyItem.java @@ -2,6 +2,7 @@ package com.glodblock.github.crossmod.extracells; import com.glodblock.github.FluidCraft; import com.glodblock.github.common.item.FCBaseItem; +import com.glodblock.github.common.item.ItemMultiFluidStorageCell; import cpw.mods.fml.common.registry.GameRegistry; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; @@ -24,7 +25,7 @@ public class ProxyItem extends FCBaseItem { /** * Maps a metadata value to a replacement. */ - protected final Map replacements; + protected final Map replacements; public ProxyItem(String ec2itemName) { this.name = ec2itemName; this.replacements = new HashMap<>(); @@ -37,10 +38,10 @@ public class ProxyItem extends FCBaseItem { } protected void addMetaReplacement(int srcMeta, Item replacement, int targetMeta) { - this.replacements.put(srcMeta, new ProxyReplacement(replacement, targetMeta)); + this.replacements.put(srcMeta, new ProxyItemEntry(replacement, targetMeta)); } - protected void addMetaReplacement(int srcMeta, ProxyReplacement replacement) { + protected void addMetaReplacement(int srcMeta, ProxyItemEntry replacement) { this.replacements.put(srcMeta, replacement); } @@ -51,7 +52,7 @@ public class ProxyItem extends FCBaseItem { @Override public void addInformation(ItemStack stack, EntityPlayer player, List info, boolean p_77624_4_) { - info.add("§7With Extra Cells gone, this is what remains..."); + info.add("§7(Extra Cells Placeholder): " + name); info.add("§7Put in your inventory to get a replacement (or disappear if incompatible)"); } @@ -63,7 +64,7 @@ public class ProxyItem extends FCBaseItem { ItemStack s = player.inventory.getStackInSlot(i); if (s == stack) { int meta = stack.getItemDamage(); - ProxyReplacement r = replacements.get(meta); + ProxyItemEntry r = replacements.get(meta); if (r == null) { player.inventory.setInventorySlotContents(i, null); } else { @@ -80,10 +81,10 @@ public class ProxyItem extends FCBaseItem { /** * Base class for a mapping from source (Item, meta) -> replacement (Item, meta). - * Optionally, override the {@link ProxyReplacement#replaceNBT(NBTTagCompound)} + * Optionally, override the {@link ProxyItemEntry#replaceNBT(NBTTagCompound)} * method for custom NBT migration. */ - protected static class ProxyReplacement { + protected static class ProxyItemEntry { protected final Item replacement; protected final int replacementMeta; @@ -93,7 +94,7 @@ public class ProxyItem extends FCBaseItem { * @param replacement Item that will replace the other. * @param replacementMeta Metadata/damage value of the replacement */ - ProxyReplacement(Item replacement, int replacementMeta) { + protected ProxyItemEntry(Item replacement, int replacementMeta) { this.replacement = replacement; this.replacementMeta = replacementMeta; } @@ -102,4 +103,34 @@ public class ProxyItem extends FCBaseItem { 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 { + public final long maxBytes; + public final int bytesPerType; + public final double idleDrain; + protected ProxyFluidStorageEntry(ItemMultiFluidStorageCell replacement, long kilobytes, int bytesPerType, double idleDrain) { + super(replacement, 0); + this.maxBytes = kilobytes * 1024; + this.bytesPerType = bytesPerType; + this.idleDrain = idleDrain; + } + + @Override + NBTTagCompound replaceNBT(NBTTagCompound compound) { + System.out.println(compound); + return compound; + } + } } diff --git a/src/main/java/com/glodblock/github/crossmod/extracells/ProxyPart.java b/src/main/java/com/glodblock/github/crossmod/extracells/ProxyPart.java index 993445c0..d4d83ff4 100644 --- a/src/main/java/com/glodblock/github/crossmod/extracells/ProxyPart.java +++ b/src/main/java/com/glodblock/github/crossmod/extracells/ProxyPart.java @@ -179,7 +179,7 @@ public class ProxyPart implements IPart, IPartDeprecated { if (item.get() == null) { throw new NullPointerException("Umm, this wasn't supposed to happen. The ref item " + name + " was GC'd."); } - ProxyItem.ProxyReplacement r = item.get().replacements.get(meta); + ProxyItem.ProxyItemEntry r = item.get().replacements.get(meta); def.setInteger("id", Item.getIdFromItem(r.replacement)); def.setShort("Damage", (short) r.replacementMeta); return def; diff --git a/src/main/java/com/glodblock/github/crossmod/extracells/ProxyPartItem.java b/src/main/java/com/glodblock/github/crossmod/extracells/ProxyPartItem.java index 8e5db34a..56b5113c 100644 --- a/src/main/java/com/glodblock/github/crossmod/extracells/ProxyPartItem.java +++ b/src/main/java/com/glodblock/github/crossmod/extracells/ProxyPartItem.java @@ -44,7 +44,7 @@ public class ProxyPartItem extends ProxyItem implements IPartItem { /** * Item replacement entry for ItemParts. All targets replace into 0. */ -class PartReplacement extends ProxyItem.ProxyReplacement { +class PartReplacement extends ProxyItem.ProxyItemEntry { Function proxyPart;