From 1500bfe9292be38498312439f06202fd7a0ef770 Mon Sep 17 00:00:00 2001 From: "Aidan C. Brady" Date: Sat, 8 Mar 2014 17:47:39 -0500 Subject: [PATCH] Filter Cards, all done --- common/mekanism/api/IFilterAccess.java | 12 ++ .../common/IAdvancedBoundingBlock.java | 3 +- common/mekanism/common/Mekanism.java | 7 ++ .../mekanism/common/item/ItemFilterCard.java | 119 ++++++++++++++++++ .../tile/TileEntityAdvancedBoundingBlock.java | 37 +++++- .../common/tile/TileEntityDigitalMiner.java | 66 ++++++++++ .../tile/TileEntityLogisticalSorter.java | 67 +++++++++- resources/assets/mekanism/lang/en_US.lang | 8 ++ .../mekanism/textures/items/FilterCard.png | Bin 0 -> 1487 bytes 9 files changed, 316 insertions(+), 3 deletions(-) create mode 100644 common/mekanism/api/IFilterAccess.java create mode 100644 common/mekanism/common/item/ItemFilterCard.java create mode 100644 resources/assets/mekanism/textures/items/FilterCard.png diff --git a/common/mekanism/api/IFilterAccess.java b/common/mekanism/api/IFilterAccess.java new file mode 100644 index 000000000..2b74bbb9c --- /dev/null +++ b/common/mekanism/api/IFilterAccess.java @@ -0,0 +1,12 @@ +package mekanism.api; + +import net.minecraft.nbt.NBTTagCompound; + +public interface IFilterAccess +{ + public NBTTagCompound getFilterData(NBTTagCompound nbtTags); + + public void setFilterData(NBTTagCompound nbtTags); + + public String getDataType(); +} diff --git a/common/mekanism/common/IAdvancedBoundingBlock.java b/common/mekanism/common/IAdvancedBoundingBlock.java index f11ce2635..5943c8ccc 100644 --- a/common/mekanism/common/IAdvancedBoundingBlock.java +++ b/common/mekanism/common/IAdvancedBoundingBlock.java @@ -3,6 +3,7 @@ package mekanism.common; import ic2.api.energy.tile.IEnergySink; import ic2.api.energy.tile.IEnergyTile; import mekanism.api.Coord4D; +import mekanism.api.IFilterAccess; import mekanism.api.energy.IStrictEnergyAcceptor; import mekanism.api.energy.IStrictEnergyStorage; import net.minecraft.inventory.ISidedInventory; @@ -11,7 +12,7 @@ import buildcraft.api.power.IPowerReceptor; import cofh.api.energy.IEnergyHandler; import dan200.computer.api.IPeripheral; -public interface IAdvancedBoundingBlock extends IBoundingBlock, ISidedInventory, IEnergySink, IStrictEnergyAcceptor, IPowerReceptor, IEnergyTile, IStrictEnergyStorage, IEnergyHandler, IPeripheral +public interface IAdvancedBoundingBlock extends IBoundingBlock, ISidedInventory, IEnergySink, IStrictEnergyAcceptor, IPowerReceptor, IEnergyTile, IStrictEnergyStorage, IEnergyHandler, IPeripheral, IFilterAccess { public int[] getBoundSlots(Coord4D location, int side); diff --git a/common/mekanism/common/Mekanism.java b/common/mekanism/common/Mekanism.java index 04c3be369..a727a5422 100644 --- a/common/mekanism/common/Mekanism.java +++ b/common/mekanism/common/Mekanism.java @@ -66,6 +66,7 @@ import mekanism.common.item.ItemDirtyDust; import mekanism.common.item.ItemDust; import mekanism.common.item.ItemElectricBow; import mekanism.common.item.ItemEnergized; +import mekanism.common.item.ItemFilterCard; import mekanism.common.item.ItemFreeRunners; import mekanism.common.item.ItemGasMask; import mekanism.common.item.ItemIngot; @@ -260,6 +261,7 @@ public class Mekanism public static Item BrineBucket; public static Item FreeRunners; public static ItemJetpack ArmoredJetpack; + public static Item FilterCard; //Blocks public static Block BasicBlock; @@ -573,6 +575,9 @@ public class Mekanism CraftingManager.getInstance().getRecipeList().add(new MekanismRecipe(ArmoredJetpack.getEmptyItem(), new Object[] { "D D", "BSB", " J ", Character.valueOf('D'), "dustDiamond", Character.valueOf('B'), "ingotBronze", Character.valueOf('S'), "blockSteel", Character.valueOf('J'), Jetpack.getEmptyItem() })); + CraftingManager.getInstance().getRecipeList().add(new MekanismRecipe(new ItemStack(FilterCard), new Object[] { + " A ", "ACA", " A ", Character.valueOf('A'), EnrichedAlloy, Character.valueOf('C'), "circuitBasic" + })); for(RecipeType type : RecipeType.values()) { @@ -794,6 +799,7 @@ public class Mekanism EnergyUpgrade = new ItemMachineUpgrade(configuration.getItem("EnergyUpgrade", ITEM_ID++).getInt()).setUnlocalizedName("EnergyUpgrade"); EnergyTablet = (ItemEnergized)new ItemEnergized(configuration.getItem("EnergyTablet", ITEM_ID++).getInt(), 1000000, 120).setUnlocalizedName("EnergyTablet"); Dictionary = new ItemDictionary(configuration.getItem("Dictionary", ITEM_ID++).getInt()).setUnlocalizedName("Dictionary"); + FilterCard = new ItemFilterCard(configuration.getItem("FilterCard", ITEM_ID++).getInt()).setUnlocalizedName("FilterCard"); ElectricBow = (ItemElectricBow)new ItemElectricBow(configuration.getItem("ElectricBow", ITEM_ID++).getInt()).setUnlocalizedName("ElectricBow"); PortableTeleporter = new ItemPortableTeleporter(configuration.getItem("PortableTeleporter", ITEM_ID++).getInt()).setUnlocalizedName("PortableTeleporter"); Configurator = new ItemConfigurator(configuration.getItem("Configurator", ITEM_ID++).getInt()).setUnlocalizedName("Configurator"); @@ -859,6 +865,7 @@ public class Mekanism GameRegistry.registerItem(Crystal, "Crystal"); GameRegistry.registerItem(FreeRunners, "FrictionBoots"); GameRegistry.registerItem(ArmoredJetpack, "ArmoredJetpack"); + GameRegistry.registerItem(FilterCard, "FilterCard"); } /** diff --git a/common/mekanism/common/item/ItemFilterCard.java b/common/mekanism/common/item/ItemFilterCard.java new file mode 100644 index 000000000..6c7ecf7f2 --- /dev/null +++ b/common/mekanism/common/item/ItemFilterCard.java @@ -0,0 +1,119 @@ +package mekanism.common.item; + +import java.util.List; + +import mekanism.api.EnumColor; +import mekanism.api.IFilterAccess; +import mekanism.common.util.MekanismUtils; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ChatMessageComponent; +import net.minecraft.world.World; + +public class ItemFilterCard extends ItemMekanism +{ + public ItemFilterCard(int id) + { + super(id); + + setMaxStackSize(1); + } + + @Override + public void addInformation(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag) + { + super.addInformation(itemstack, entityplayer, list, flag); + + list.add(EnumColor.GREY + MekanismUtils.localize("gui.data") + ": " + EnumColor.INDIGO + MekanismUtils.localize(getDataType(itemstack))); + } + + @Override + public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) + { + if(!world.isRemote) + { + TileEntity tileEntity = world.getBlockTileEntity(x, y, z); + + if(tileEntity instanceof IFilterAccess) + { + if(player.isSneaking()) + { + NBTTagCompound data = ((IFilterAccess)tileEntity).getFilterData(new NBTTagCompound()); + + if(data != null) + { + data.setString("dataType", ((IFilterAccess)tileEntity).getDataType()); + setData(stack, data); + player.addChatMessage(EnumColor.DARK_BLUE + "[Mekanism] " + EnumColor.GREY + MekanismUtils.localize("tooltip.filterCard.got") + " " + EnumColor.INDIGO + MekanismUtils.localize(data.getString("dataType"))); + } + + return true; + } + else if(getData(stack) != null) + { + if(((IFilterAccess)tileEntity).getDataType().equals(getDataType(stack))) + { + ((IFilterAccess)tileEntity).setFilterData(getData(stack)); + player.addChatMessage(EnumColor.DARK_BLUE + "[Mekanism] " + EnumColor.DARK_GREEN + MekanismUtils.localize("tooltip.filterCard.set") + " " + EnumColor.INDIGO + MekanismUtils.localize(getDataType(stack))); + setData(stack, null); + } + else { + player.addChatMessage(EnumColor.DARK_BLUE + "[Mekanism] " + EnumColor.RED + MekanismUtils.localize("tooltip.filterCard.unequal") + "."); + } + + return true; + } + } + } + + return false; + } + + public void setData(ItemStack itemstack, NBTTagCompound data) + { + if(itemstack.stackTagCompound == null) + { + itemstack.setTagCompound(new NBTTagCompound()); + } + + if(data != null) + { + itemstack.stackTagCompound.setCompoundTag("data", data); + } + else { + itemstack.stackTagCompound.removeTag("data"); + } + } + + public NBTTagCompound getData(ItemStack itemstack) + { + if(itemstack.stackTagCompound == null) + { + return null; + } + + NBTTagCompound data = itemstack.stackTagCompound.getCompoundTag("data"); + + if(data.hasNoTags()) + { + return null; + } + else { + return itemstack.stackTagCompound.getCompoundTag("data"); + } + } + + public String getDataType(ItemStack itemstack) + { + NBTTagCompound data = getData(itemstack); + + if(data != null) + { + return data.getString("dataType"); + } + + return "gui.none"; + } +} diff --git a/common/mekanism/common/tile/TileEntityAdvancedBoundingBlock.java b/common/mekanism/common/tile/TileEntityAdvancedBoundingBlock.java index a7396e0e7..19f4114e2 100644 --- a/common/mekanism/common/tile/TileEntityAdvancedBoundingBlock.java +++ b/common/mekanism/common/tile/TileEntityAdvancedBoundingBlock.java @@ -3,6 +3,7 @@ package mekanism.common.tile; import ic2.api.energy.tile.IEnergySink; import ic2.api.energy.tile.IEnergyTile; import mekanism.api.Coord4D; +import mekanism.api.IFilterAccess; import mekanism.api.energy.IStrictEnergyAcceptor; import mekanism.api.energy.IStrictEnergyStorage; import mekanism.common.IAdvancedBoundingBlock; @@ -10,6 +11,7 @@ import mekanism.common.util.InventoryUtils; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; @@ -21,7 +23,7 @@ import dan200.computer.api.IComputerAccess; import dan200.computer.api.ILuaContext; import dan200.computer.api.IPeripheral; -public class TileEntityAdvancedBoundingBlock extends TileEntityBoundingBlock implements ISidedInventory, IEnergySink, IStrictEnergyAcceptor, IPowerReceptor, IEnergyTile, IStrictEnergyStorage, IEnergyHandler, IPeripheral +public class TileEntityAdvancedBoundingBlock extends TileEntityBoundingBlock implements ISidedInventory, IEnergySink, IStrictEnergyAcceptor, IPowerReceptor, IEnergyTile, IStrictEnergyStorage, IEnergyHandler, IPeripheral, IFilterAccess { @Override public int getSizeInventory() @@ -470,4 +472,37 @@ public class TileEntityAdvancedBoundingBlock extends TileEntityBoundingBlock imp getInv().detach(computer); } + + @Override + public NBTTagCompound getFilterData(NBTTagCompound nbtTags) + { + if(getInv() == null) + { + return null; + } + + return getInv().getFilterData(nbtTags); + } + + @Override + public void setFilterData(NBTTagCompound nbtTags) + { + if(getInv() == null) + { + return; + } + + getInv().setFilterData(nbtTags); + } + + @Override + public String getDataType() + { + if(getInv() == null) + { + return "null"; + } + + return getInv().getDataType(); + } } diff --git a/common/mekanism/common/tile/TileEntityDigitalMiner.java b/common/mekanism/common/tile/TileEntityDigitalMiner.java index 184acedb2..44cb33b1b 100644 --- a/common/mekanism/common/tile/TileEntityDigitalMiner.java +++ b/common/mekanism/common/tile/TileEntityDigitalMiner.java @@ -1293,4 +1293,70 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I @Override public void detach(IComputerAccess computer) {} + + @Override + public NBTTagCompound getFilterData(NBTTagCompound nbtTags) + { + nbtTags.setInteger("radius", radius); + nbtTags.setInteger("minY", minY); + nbtTags.setInteger("maxY", maxY); + nbtTags.setBoolean("doEject", doEject); + nbtTags.setBoolean("doPull", doPull); + nbtTags.setBoolean("silkTouch", silkTouch); + nbtTags.setInteger("controlType", controlType.ordinal()); + nbtTags.setBoolean("inverse", inverse); + + if(replaceStack != null) + { + nbtTags.setCompoundTag("replaceStack", replaceStack.writeToNBT(new NBTTagCompound())); + } + + NBTTagList filterTags = new NBTTagList(); + + for(MinerFilter filter : filters) + { + filterTags.appendTag(filter.write(new NBTTagCompound())); + } + + if(filterTags.tagCount() != 0) + { + nbtTags.setTag("filters", filterTags); + } + + return nbtTags; + } + + @Override + public void setFilterData(NBTTagCompound nbtTags) + { + radius = nbtTags.getInteger("radius"); + minY = nbtTags.getInteger("minY"); + maxY = nbtTags.getInteger("maxY"); + doEject = nbtTags.getBoolean("doEject"); + doPull = nbtTags.getBoolean("doPull"); + silkTouch = nbtTags.getBoolean("silkTouch"); + controlType = RedstoneControl.values()[nbtTags.getInteger("controlType")]; + inverse = nbtTags.getBoolean("inverse"); + + if(nbtTags.hasKey("replaceStack")) + { + replaceStack = ItemStack.loadItemStackFromNBT(nbtTags.getCompoundTag("replaceStack")); + } + + if(nbtTags.hasKey("filters")) + { + NBTTagList tagList = nbtTags.getTagList("filters"); + + for(int i = 0; i < tagList.tagCount(); i++) + { + filters.add(MinerFilter.readFromNBT((NBTTagCompound)tagList.tagAt(i))); + } + } + } + + @Override + public String getDataType() + { + return "tooltip.filterCard.digitalMiner"; + } } diff --git a/common/mekanism/common/tile/TileEntityLogisticalSorter.java b/common/mekanism/common/tile/TileEntityLogisticalSorter.java index d0f21a889..321e4657d 100644 --- a/common/mekanism/common/tile/TileEntityLogisticalSorter.java +++ b/common/mekanism/common/tile/TileEntityLogisticalSorter.java @@ -5,6 +5,7 @@ import java.util.EnumSet; import mekanism.api.Coord4D; import mekanism.api.EnumColor; +import mekanism.api.IFilterAccess; import mekanism.common.HashList; import mekanism.common.IActiveState; import mekanism.common.ILogisticalTransporter; @@ -31,7 +32,7 @@ import net.minecraftforge.common.ForgeDirection; import com.google.common.io.ByteArrayDataInput; -public class TileEntityLogisticalSorter extends TileEntityElectricBlock implements IRedstoneControl, IActiveState +public class TileEntityLogisticalSorter extends TileEntityElectricBlock implements IRedstoneControl, IActiveState, IFilterAccess { public HashList filters = new HashList(); @@ -540,4 +541,68 @@ public class TileEntityLogisticalSorter extends TileEntityElectricBlock implemen { return true; } + + @Override + public NBTTagCompound getFilterData(NBTTagCompound nbtTags) + { + nbtTags.setInteger("controlType", controlType.ordinal()); + + if(color != null) + { + nbtTags.setInteger("color", TransporterUtils.colors.indexOf(color)); + } + + nbtTags.setBoolean("autoEject", autoEject); + nbtTags.setBoolean("roundRobin", roundRobin); + + nbtTags.setInteger("rrIndex", rrIndex); + + NBTTagList filterTags = new NBTTagList(); + + for(TransporterFilter filter : filters) + { + NBTTagCompound tagCompound = new NBTTagCompound(); + filter.write(tagCompound); + filterTags.appendTag(tagCompound); + } + + if(filterTags.tagCount() != 0) + { + nbtTags.setTag("filters", filterTags); + } + + return nbtTags; + } + + @Override + public void setFilterData(NBTTagCompound nbtTags) + { + controlType = RedstoneControl.values()[nbtTags.getInteger("controlType")]; + + if(nbtTags.hasKey("color")) + { + color = TransporterUtils.colors.get(nbtTags.getInteger("color")); + } + + autoEject = nbtTags.getBoolean("autoEject"); + roundRobin = nbtTags.getBoolean("roundRobin"); + + rrIndex = nbtTags.getInteger("rrIndex"); + + if(nbtTags.hasKey("filters")) + { + NBTTagList tagList = nbtTags.getTagList("filters"); + + for(int i = 0; i < tagList.tagCount(); i++) + { + filters.add(TransporterFilter.readFromNBT((NBTTagCompound)tagList.tagAt(i))); + } + } + } + + @Override + public String getDataType() + { + return "tooltip.filterCard.logisticalSorter"; + } } diff --git a/resources/assets/mekanism/lang/en_US.lang b/resources/assets/mekanism/lang/en_US.lang index d299ac255..92f864af2 100644 --- a/resources/assets/mekanism/lang/en_US.lang +++ b/resources/assets/mekanism/lang/en_US.lang @@ -33,6 +33,7 @@ item.Salt.name=Salt item.BrineBucket.name=Brine Bucket item.FreeRunners.name=Free Runners item.ArmoredJetpack.name=Armored Jetpack +item.FilterCard.name=Filter Card //Gas Tank tile.GasTank.GasTank.name=Gas Tank @@ -266,6 +267,7 @@ gui.on=On gui.off=Off gui.filters=Filters gui.idle=Idle +gui.data=Data gui.chemicalInfuser.short=C. Infuser gui.chemicalDissolutionChamber.short=C. Dissolution Chamber @@ -356,6 +358,12 @@ tooltip.configurator.noLink=No link tooltip.configurator.linkMsg=Bound to tooltip.configurator.dim=dimension +tooltip.filterCard.got=Retrieved filter data from +tooltip.filterCard.set=Injected filter data of type +tooltip.filterCard.unequal=Unequal filter data formats +tooltip.filterCard.logisticalSorter=Logistical Sorter +tooltip.filterCard.digitalMiner=Digital Miner + tooltip.balloon=Balloon tooltip.jetpack.regular=Regular diff --git a/resources/assets/mekanism/textures/items/FilterCard.png b/resources/assets/mekanism/textures/items/FilterCard.png new file mode 100644 index 0000000000000000000000000000000000000000..5370ea6e9c5b7036b03b4508e4365a0f34dd8ee5 GIT binary patch literal 1487 zcmV;=1u*)FP)4Tx05}naRo`#hR1`jmZ&IWdKOk5~hl<6oRa0BJ8yc;~21%2p?MfD<>DVeH z9(p*dx19w`~g7O0}n_%Aq@s%d)fBDv`JHkDym6Hd+5XuAtvnwRpGmK zVkc9?T=n|PIo~X-eVh__(Z?q}P9Z-Dj?gOW6|D%o20XmjW-qs4UjrD(li^iv8@eK9k+ZFm zVRFymFOPAzG5-%Pn|1W;U4vNroTa&AxDScmEA~{ri9gr1^c?U@uwSpaNnw8l_>cP1 zd;)kMQS_;jeRSUEM_*s96y65j1$)tOrwdK{YIQMt92l|D^(E_=$Rjw{b!QT@q!)ni zR`|5oW9X5n$Wv+HVc@|^eX5yXnsHX8PF3UX~a6)MwxDE0HaPjyrlI!;jX{6Kvuh*8ej?;85ekN$?5uuCiS zBTvvVG+XTxAO{m@bvM#Jr)z6J><&E22D|vq?Y?Vkbo_DijopiF$2PET#mZ8eu=y$(ArYkv7@Ex`GL?QCc!_*KFrd&;n1r7 zqW-CFs9&fT)ZaU5gc&=gBz-DaCw(vdOp0__x+47~U6sC(E(JNe@4cTT*n6*E zVH4eoU1-&7pEV~_PRe`a7v+@vy!^5}8?Y3)UmlaER0004INklk4BR_ikq4y82WWT&Uxnso@y?Q3`7zdP{84M>vY zi{~M6*L5K<57RUa@lpWfS(bS~D{0%-f~e1{s&XjeT}1>G*OJTDAF=>>Q50I4YI&Z! zvMecI62Mu$Q~>}uR(Fo0_%l6Ge7NWs0*K&o{XUD2W(9B}1j}7(C^0f0$I%VLK;>Bh zmIKmC>i8l6a=B&&SPrb6fiz7$4YL9)2cXOSeDRuD$?0~TKqdn4=VdtnowSA%2BY8! zK=P3LwJ_R!Yg$Oa(pT!HGf>wxiH+mfK@K}C9&a)O$Ses_6xIRv<1--1AxA>o5hG_H z^v>}-?lc2f2;DcG0T3ZA=XZ}HH=6-Y#)a@0MEvRu03n|P`AUW7YZiSG!Qm*1f