From 7d69639a8a24f729ca67c82123e49f3d37037769 Mon Sep 17 00:00:00 2001 From: "Aidan C. Brady" Date: Wed, 15 Jan 2014 17:36:38 -0500 Subject: [PATCH] A few bug fixes --- common/mekanism/common/Tier.java | 23 +++++++++++ .../common/item/ItemBlockCardboardBox.java | 38 ++++++++++--------- .../common/multipart/ItemPartTransmitter.java | 7 ++-- .../common/multipart/MultipartMekanism.java | 14 +++---- .../common/multipart/PartSidedPipe.java | 11 +++--- .../common/multipart/PartUniversalCable.java | 24 ++---------- 6 files changed, 65 insertions(+), 52 deletions(-) diff --git a/common/mekanism/common/Tier.java b/common/mekanism/common/Tier.java index 2ffb9c2d4..9498330e3 100644 --- a/common/mekanism/common/Tier.java +++ b/common/mekanism/common/Tier.java @@ -1,6 +1,7 @@ package mekanism.common; import mekanism.api.EnumColor; +import mekanism.common.multipart.TransmitterType; import net.minecraft.util.ResourceLocation; /** @@ -86,4 +87,26 @@ public final class Tier guiLocation = gui; } } + + /** + * The tiers used by Universal Cables and their corresponding values. + * @author aidancbrady + * + */ + public static enum CableTier + { + BASIC(500, TransmitterType.UNIVERSAL_CABLE_BASIC), + ADVANCED(2000, TransmitterType.UNIVERSAL_CABLE_ADVANCED), + ELITE(8000, TransmitterType.UNIVERSAL_CABLE_ELITE), + ULTIMATE(32000, TransmitterType.UNIVERSAL_CABLE_ULTIMATE); + + public int cableCapacity; + public TransmitterType type; + + private CableTier(int capacity, TransmitterType transmitterType) + { + cableCapacity = capacity; + type = transmitterType; + } + } } diff --git a/common/mekanism/common/item/ItemBlockCardboardBox.java b/common/mekanism/common/item/ItemBlockCardboardBox.java index 19868e059..8e28149df 100644 --- a/common/mekanism/common/item/ItemBlockCardboardBox.java +++ b/common/mekanism/common/item/ItemBlockCardboardBox.java @@ -9,20 +9,24 @@ import mekanism.common.Mekanism; import mekanism.common.block.BlockCardboardBox.BlockData; import mekanism.common.tile.TileEntityCardboardBox; import net.minecraft.block.Block; +import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Icon; import net.minecraft.world.World; -import powercrystals.minefactoryreloaded.api.IDeepStorageUnit; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.ForgeSubscribe; +import net.minecraftforge.event.entity.EntityJoinWorldEvent; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class ItemBlockCardboardBox extends ItemBlock { + private static boolean isMonitoring; + public Block metaBlock; public ItemBlockCardboardBox(int id, Block block) @@ -30,6 +34,8 @@ public class ItemBlockCardboardBox extends ItemBlock super(id); setMaxStackSize(1); metaBlock = block; + + MinecraftForge.EVENT_BUS.register(this); } @Override @@ -76,6 +82,8 @@ public class ItemBlockCardboardBox extends ItemBlock data.id = id; data.meta = meta; + isMonitoring = true; + if(world.getBlockTileEntity(x, y, z) != null) { TileEntity tile = world.getBlockTileEntity(x, y, z); @@ -83,21 +91,6 @@ public class ItemBlockCardboardBox extends ItemBlock tile.writeToNBT(tag); data.tileTag = tag; - - if(tile instanceof IInventory) - { - IInventory inv = (IInventory)tile; - - for(int i = 0; i < inv.getSizeInventory(); i++) - { - inv.setInventorySlotContents(i, null); - } - } - - if(tile instanceof IDeepStorageUnit) - { - ((IDeepStorageUnit)tile).setStoredItemCount(0); - } } if(!player.capabilities.isCreativeMode) @@ -107,6 +100,8 @@ public class ItemBlockCardboardBox extends ItemBlock world.setBlock(x, y, z, Mekanism.cardboardBoxID, 1, 3); + isMonitoring = false; + TileEntityCardboardBox tileEntity = (TileEntityCardboardBox)world.getBlockTileEntity(x, y, z); if(tileEntity != null) @@ -163,4 +158,13 @@ public class ItemBlockCardboardBox extends ItemBlock return BlockData.read(itemstack.stackTagCompound.getCompoundTag("blockData")); } + + @ForgeSubscribe + public void onEntitySpawn(EntityJoinWorldEvent event) + { + if(event.entity instanceof EntityItem && isMonitoring) + { + event.setCanceled(true); + } + } } diff --git a/common/mekanism/common/multipart/ItemPartTransmitter.java b/common/mekanism/common/multipart/ItemPartTransmitter.java index 85ec84607..30c28dd25 100644 --- a/common/mekanism/common/multipart/ItemPartTransmitter.java +++ b/common/mekanism/common/multipart/ItemPartTransmitter.java @@ -9,7 +9,8 @@ import mekanism.api.transmitters.IGridTransmitter; import mekanism.api.transmitters.ITransmitterNetwork; import mekanism.api.transmitters.TransmissionType; import mekanism.common.Mekanism; -import mekanism.common.multipart.PartUniversalCable.CableTier; +import mekanism.common.Tier; +import mekanism.common.Tier.CableTier; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; @@ -85,9 +86,9 @@ public class ItemPartTransmitter extends JItemMultiPart { if(!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { - if(itemstack.getItemDamage() < CableTier.values().length) + if(itemstack.getItemDamage() < Tier.CableTier.values().length) { - list.add(EnumColor.INDIGO + "Capacity: " + EnumColor.GREY + CableTier.values()[itemstack.getItemDamage()].cableCapacity + "J/t"); + list.add(EnumColor.INDIGO + "Capacity: " + EnumColor.GREY + Tier.CableTier.values()[itemstack.getItemDamage()].cableCapacity + "J/t"); } list.add("Hold " + EnumColor.AQUA + "shift" + EnumColor.GREY + " for details."); diff --git a/common/mekanism/common/multipart/MultipartMekanism.java b/common/mekanism/common/multipart/MultipartMekanism.java index 73441d472..3e956e42f 100644 --- a/common/mekanism/common/multipart/MultipartMekanism.java +++ b/common/mekanism/common/multipart/MultipartMekanism.java @@ -1,7 +1,7 @@ package mekanism.common.multipart; -import mekanism.common.multipart.PartUniversalCable.CableTier; - +import mekanism.common.Tier; +import mekanism.common.Tier.CableTier; import codechicken.multipart.MultiPartRegistry; import codechicken.multipart.MultiPartRegistry.IPartFactory; import codechicken.multipart.MultipartGenerator; @@ -40,23 +40,23 @@ public class MultipartMekanism implements IPartFactory { if(name.equals("mekanism:universal_cable")) { - return new PartUniversalCable(CableTier.BASIC); + return new PartUniversalCable(Tier.CableTier.BASIC); } else if(name.equals("mekanism:universal_cable_basic")) { - return new PartUniversalCable(CableTier.BASIC); + return new PartUniversalCable(Tier.CableTier.BASIC); } else if(name.equals("mekanism:universal_cable_advanced")) { - return new PartUniversalCable(CableTier.ADVANCED); + return new PartUniversalCable(Tier.CableTier.ADVANCED); } else if(name.equals("mekanism:universal_cable_elite")) { - return new PartUniversalCable(CableTier.ELITE); + return new PartUniversalCable(Tier.CableTier.ELITE); } else if(name.equals("mekanism:universal_cable_ultimate")) { - return new PartUniversalCable(CableTier.ULTIMATE); + return new PartUniversalCable(Tier.CableTier.ULTIMATE); } else if(name.equals("mekanism:mechanical_pipe")) { diff --git a/common/mekanism/common/multipart/PartSidedPipe.java b/common/mekanism/common/multipart/PartSidedPipe.java index dae441cdc..04698c74a 100644 --- a/common/mekanism/common/multipart/PartSidedPipe.java +++ b/common/mekanism/common/multipart/PartSidedPipe.java @@ -18,8 +18,9 @@ import mekanism.client.render.RenderPartTransmitter; import mekanism.common.IConfigurable; import mekanism.common.ITileNetwork; import mekanism.common.Mekanism; +import mekanism.common.Tier; +import mekanism.common.Tier.CableTier; import mekanism.common.item.ItemConfigurator; -import mekanism.common.multipart.PartUniversalCable.CableTier; import mekanism.common.multipart.TransmitterType.Size; import net.minecraft.client.particle.EffectRenderer; import net.minecraft.entity.player.EntityPlayer; @@ -97,13 +98,13 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart, switch(type) { case UNIVERSAL_CABLE_BASIC: - return new PartUniversalCable(CableTier.BASIC); + return new PartUniversalCable(Tier.CableTier.BASIC); case UNIVERSAL_CABLE_ADVANCED: - return new PartUniversalCable(CableTier.ADVANCED); + return new PartUniversalCable(Tier.CableTier.ADVANCED); case UNIVERSAL_CABLE_ELITE: - return new PartUniversalCable(CableTier.ELITE); + return new PartUniversalCable(Tier.CableTier.ELITE); case UNIVERSAL_CABLE_ULTIMATE: - return new PartUniversalCable(CableTier.ULTIMATE); + return new PartUniversalCable(Tier.CableTier.ULTIMATE); case MECHANICAL_PIPE: return new PartMechanicalPipe(); case PRESSURIZED_TUBE: diff --git a/common/mekanism/common/multipart/PartUniversalCable.java b/common/mekanism/common/multipart/PartUniversalCable.java index 94aa47795..8b4718c93 100644 --- a/common/mekanism/common/multipart/PartUniversalCable.java +++ b/common/mekanism/common/multipart/PartUniversalCable.java @@ -14,6 +14,7 @@ import mekanism.api.transmitters.TransmissionType; import mekanism.client.render.RenderPartTransmitter; import mekanism.common.EnergyNetwork; import mekanism.common.Mekanism; +import mekanism.common.Tier; import mekanism.common.util.CableUtils; import mekanism.common.util.MekanismUtils; import net.minecraft.client.renderer.texture.IconRegister; @@ -33,7 +34,7 @@ import cpw.mods.fml.relauncher.SideOnly; public class PartUniversalCable extends PartTransmitter implements IStrictEnergyAcceptor, IEnergySink, IEnergyHandler, IPowerReceptor { - public CableTier tier; + public Tier.CableTier tier; /** A fake power handler used to initiate energy transfer calculations. */ public PowerHandler powerHandler; @@ -45,7 +46,7 @@ public class PartUniversalCable extends PartTransmitter implement public double cacheEnergy = 0; public double lastWrite = 0; - public PartUniversalCable(CableTier cableTier) + public PartUniversalCable(Tier.CableTier cableTier) { tier = cableTier; powerHandler = new PowerHandler(this, PowerHandler.Type.STORAGE); @@ -96,7 +97,7 @@ public class PartUniversalCable extends PartTransmitter implement super.load(nbtTags); cacheEnergy = nbtTags.getDouble("cacheEnergy"); - tier = CableTier.values()[nbtTags.getInteger("tier")]; + tier = Tier.CableTier.values()[nbtTags.getInteger("tier")]; } @Override @@ -396,21 +397,4 @@ public class PartUniversalCable extends PartTransmitter implement reconfigure(); } } - - public static enum CableTier - { - BASIC(500, TransmitterType.UNIVERSAL_CABLE_BASIC), - ADVANCED(2000, TransmitterType.UNIVERSAL_CABLE_ADVANCED), - ELITE(8000, TransmitterType.UNIVERSAL_CABLE_ELITE), - ULTIMATE(32000, TransmitterType.UNIVERSAL_CABLE_ULTIMATE); - - int cableCapacity; - TransmitterType type; - - private CableTier(int capacity, TransmitterType transmitterType) - { - cableCapacity = capacity; - type = transmitterType; - } - } }