diff --git a/common/mekanism/api/transmitters/TransmitterNetworkRegistry.java b/common/mekanism/api/transmitters/TransmitterNetworkRegistry.java index 2b8a328c5..342c4714f 100644 --- a/common/mekanism/api/transmitters/TransmitterNetworkRegistry.java +++ b/common/mekanism/api/transmitters/TransmitterNetworkRegistry.java @@ -1,9 +1,12 @@ package mekanism.api.transmitters; import java.util.EnumSet; +import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.Map; import java.util.Set; + import net.minecraft.tileentity.TileEntity; import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.IChunkProvider; @@ -135,7 +138,9 @@ public class TransmitterNetworkRegistry implements ITickHandler try { if(c != null) { - for(Object obj : c.chunkTileEntityMap.values()) + Map copy = (Map)((HashMap)c.chunkTileEntityMap).clone(); + + for(Object obj : copy.values()) { if(obj instanceof TileEntity) { diff --git a/common/mekanism/client/ClientPlayerTickHandler.java b/common/mekanism/client/ClientPlayerTickHandler.java index 34ae17139..ada9b494f 100644 --- a/common/mekanism/client/ClientPlayerTickHandler.java +++ b/common/mekanism/client/ClientPlayerTickHandler.java @@ -1,8 +1,11 @@ package mekanism.client; import java.util.EnumSet; +import java.util.HashSet; +import java.util.Set; import mekanism.api.EnumColor; +import mekanism.api.Object3D; import mekanism.common.PacketHandler; import mekanism.common.PacketHandler.Transmission; import mekanism.common.item.ItemConfigurator; @@ -11,12 +14,11 @@ import mekanism.common.item.ItemWalkieTalkie; import mekanism.common.network.PacketConfiguratorState; import mekanism.common.network.PacketElectricBowState; import mekanism.common.network.PacketWalkieTalkieState; +import mekanism.common.tileentity.TileEntityUniversalCable; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ChatMessageComponent; - -import org.lwjgl.input.Keyboard; - import cpw.mods.fml.common.ITickHandler; import cpw.mods.fml.common.TickType; import cpw.mods.fml.relauncher.Side; @@ -24,7 +26,7 @@ import cpw.mods.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class ClientPlayerTickHandler implements ITickHandler -{ +{ public boolean lastTickUpdate = false; @Override @@ -37,6 +39,24 @@ public class ClientPlayerTickHandler implements ITickHandler { EntityPlayer entityPlayer = (EntityPlayer)tickData[0]; + Set toRemove = new HashSet(); + + for(UpdateQueueData data : MekanismClient.cableUpdateQueue) + { + TileEntity tile = data.object3D.getTileEntity(entityPlayer.worldObj); + + if(tile instanceof TileEntityUniversalCable) + { + new EnergyClientUpdate(tile, data.energy).clientUpdate(); + toRemove.add(data); + } + } + + for(UpdateQueueData rem : toRemove) + { + MekanismClient.cableUpdateQueue.remove(rem); + } + if(entityPlayer.getCurrentEquippedItem() != null) { ItemStack stack = entityPlayer.getCurrentEquippedItem(); @@ -113,4 +133,16 @@ public class ClientPlayerTickHandler implements ITickHandler { return "MekanismClientPlayer"; } + + public static class UpdateQueueData + { + public Object3D object3D; + public double energy; + + public UpdateQueueData(Object3D obj, double d) + { + object3D = obj; + energy = d; + } + } } diff --git a/common/mekanism/client/MekanismClient.java b/common/mekanism/client/MekanismClient.java index 1e58a499f..bd2c070bb 100644 --- a/common/mekanism/client/MekanismClient.java +++ b/common/mekanism/client/MekanismClient.java @@ -1,9 +1,13 @@ package mekanism.client; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; +import java.util.ArrayList; +import java.util.List; + +import mekanism.client.ClientPlayerTickHandler.UpdateQueueData; import mekanism.client.sound.SoundHandler; import mekanism.common.Mekanism; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; public class MekanismClient extends Mekanism { @@ -11,6 +15,8 @@ public class MekanismClient extends Mekanism /** The main SoundHandler instance that is used by all audio sources */ public static SoundHandler audioHandler; + public static List cableUpdateQueue = new ArrayList(); + //General Configuration public static boolean enableSounds = true; public static boolean fancyUniversalCableRender = true; diff --git a/common/mekanism/client/render/entity/RenderObsidianTNTPrimed.java b/common/mekanism/client/render/entity/RenderObsidianTNTPrimed.java index 1901424dc..a77e1a2e7 100644 --- a/common/mekanism/client/render/entity/RenderObsidianTNTPrimed.java +++ b/common/mekanism/client/render/entity/RenderObsidianTNTPrimed.java @@ -39,6 +39,7 @@ public class RenderObsidianTNTPrimed extends Render GL11.glPushMatrix(); GL11.glTranslatef((float)x, (float)y-1.2f, (float)z); GL11.glScalef(0.8F, 0.8F, 0.8F); + GL11.glRotatef(180, 1, 0, 0); if((entityobsidiantnt.fuse - f1) + 1.0F < 10F) { diff --git a/common/mekanism/client/render/tileentity/RenderUniversalCable.java b/common/mekanism/client/render/tileentity/RenderUniversalCable.java index 24b1e769a..af3e10ca4 100644 --- a/common/mekanism/client/render/tileentity/RenderUniversalCable.java +++ b/common/mekanism/client/render/tileentity/RenderUniversalCable.java @@ -223,7 +223,6 @@ public class RenderUniversalCable extends TileEntitySpecialRenderer private DisplayInteger getDisplayList(ForgeDirection side) { - DisplayInteger newDisplayList; Model3D toRender = energy[side.ordinal()]; diff --git a/common/mekanism/common/EnergyNetwork.java b/common/mekanism/common/EnergyNetwork.java index b2229054b..8ffce7c99 100644 --- a/common/mekanism/common/EnergyNetwork.java +++ b/common/mekanism/common/EnergyNetwork.java @@ -31,10 +31,12 @@ import cpw.mods.fml.common.FMLCommonHandler; public class EnergyNetwork extends DynamicNetwork { - private double lastPowerScale = 0; + private double lastPowerScale = -1; private double joulesTransmitted = 0; private double joulesLastTick = 0; + private boolean needsUpdate = false; + public EnergyNetwork(ITransmitter... varCables) { transmitters.addAll(Arrays.asList(varCables)); @@ -238,14 +240,7 @@ public class EnergyNetwork extends DynamicNetwork } } - double currentPowerScale = getPowerScale(); - - if(FMLCommonHandler.instance().getEffectiveSide().isServer()) - { - lastPowerScale = currentPowerScale; - - MinecraftForge.EVENT_BUS.post(new EnergyTransferEvent(this, currentPowerScale)); - } + needsUpdate = true; } @Override @@ -289,11 +284,20 @@ public class EnergyNetwork extends DynamicNetwork double currentPowerScale = getPowerScale(); - if(currentPowerScale != lastPowerScale && FMLCommonHandler.instance().getEffectiveSide().isServer()) + if(FMLCommonHandler.instance().getEffectiveSide().isServer()) { + if(currentPowerScale != lastPowerScale) + { + needsUpdate = true; + } + lastPowerScale = currentPowerScale; - MinecraftForge.EVENT_BUS.post(new EnergyTransferEvent(this, currentPowerScale)); + if(needsUpdate) + { + MinecraftForge.EVENT_BUS.post(new EnergyTransferEvent(this, currentPowerScale)); + needsUpdate = false; + } } } diff --git a/common/mekanism/common/Mekanism.java b/common/mekanism/common/Mekanism.java index 6d69a9f64..5bdabacc7 100644 --- a/common/mekanism/common/Mekanism.java +++ b/common/mekanism/common/Mekanism.java @@ -6,8 +6,10 @@ import ic2.api.recipe.Recipes; import java.io.File; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.logging.Logger; import mekanism.api.Object3D; @@ -34,6 +36,7 @@ import mekanism.common.block.BlockTransmitter; import mekanism.common.item.ItemAtomicDisassembler; import mekanism.common.item.ItemBlockBasic; import mekanism.common.item.ItemBlockEnergyCube; +import mekanism.common.item.ItemBlockGasTank; import mekanism.common.item.ItemBlockMachine; import mekanism.common.item.ItemBlockOre; import mekanism.common.item.ItemBlockTransmitter; @@ -49,7 +52,6 @@ import mekanism.common.item.ItemMekanism; import mekanism.common.item.ItemNetworkReader; import mekanism.common.item.ItemPortableTeleporter; import mekanism.common.item.ItemRobit; -import mekanism.common.item.ItemStorageTank; import mekanism.common.item.ItemWalkieTalkie; import mekanism.common.network.PacketConfigurationUpdate; import mekanism.common.network.PacketConfiguratorState; @@ -72,9 +74,7 @@ import mekanism.common.network.PacketTransmitterTransferUpdate; import mekanism.common.network.PacketTransmitterTransferUpdate.TransmitterTransferType; import mekanism.common.network.PacketWalkieTalkieState; import mekanism.common.tileentity.TileEntityBoundingBlock; -import mekanism.common.tileentity.TileEntityEnergyCube; -import mekanism.common.tileentity.TileEntityGasTank; -import mekanism.common.tileentity.TileEntityLogisticalSorter; +import mekanism.common.tileentity.TileEntityElectricBlock; import mekanism.common.tileentity.TileEntityTeleporter; import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils.ResourceType; @@ -84,9 +84,11 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; import net.minecraft.item.crafting.FurnaceRecipes; +import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.Configuration; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.ForgeSubscribe; +import net.minecraftforge.event.world.ChunkEvent; import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.ShapelessOreRecipe; import rebelkeithy.mods.metallurgy.api.IOreInfo; @@ -161,6 +163,8 @@ public class Mekanism /** A list of the usernames of players who have donated to Mekanism. */ public static List donators = new ArrayList(); + + public static Set ic2Registered = new HashSet(); //Block IDs public static int basicBlockID = 3000; @@ -181,7 +185,6 @@ public class Mekanism public static ItemRobit Robit; public static ItemAtomicDisassembler AtomicDisassembler; public static Item AtomicCore; - public static ItemStorageTank StorageTank; public static Item ControlCircuit; public static Item EnrichedIron; public static Item CompressedCarbon; @@ -316,9 +319,6 @@ public class Mekanism CraftingManager.getInstance().getRecipeList().add(new MekanismRecipe(AtomicDisassembler.getUnchargedItem(), new Object[] { "AEA", "ACA", " O ", Character.valueOf('A'), EnrichedAlloy, Character.valueOf('E'), EnergyTablet.getUnchargedItem(), Character.valueOf('C'), AtomicCore, Character.valueOf('O'), "ingotRefinedObsidian" })); - CraftingManager.getInstance().getRecipeList().add(new MekanismRecipe(StorageTank.getEmptyItem(), new Object[] { - "III", "IDI", "III", Character.valueOf('I'), Item.ingotIron, Character.valueOf('D'), "dustIron" - })); CraftingManager.getInstance().getRecipeList().add(new MekanismRecipe(new ItemStack(GasTank), new Object[] { "PPP", "PDP", "PPP", Character.valueOf('P'), "ingotOsmium", Character.valueOf('D'), "dustIron" })); @@ -513,7 +513,7 @@ public class Mekanism AtomicDisassembler = (ItemAtomicDisassembler) new ItemAtomicDisassembler(configuration.getItem("AtomicDisassembler", 11210).getInt()).setUnlocalizedName("AtomicDisassembler"); AtomicCore = new ItemMekanism(configuration.getItem("AtomicCore", 11211).getInt()).setUnlocalizedName("AtomicCore"); EnrichedAlloy = new ItemMekanism(configuration.getItem("EnrichedAlloy", 11212).getInt()).setUnlocalizedName("EnrichedAlloy"); - StorageTank = (ItemStorageTank) new ItemStorageTank(configuration.getItem("StorageTank", 11213).getInt(), 1600, 16).setUnlocalizedName("StorageTank"); + //OPEN 11213 ControlCircuit = new ItemMekanism(configuration.getItem("ControlCircuit", 11214).getInt()).setUnlocalizedName("ControlCircuit"); EnrichedIron = new ItemMekanism(configuration.getItem("EnrichedIron", 11215).getInt()).setUnlocalizedName("EnrichedIron"); CompressedCarbon = new ItemMekanism(configuration.getItem("CompressedCarbon", 11216).getInt()).setUnlocalizedName("CompressedCarbon"); @@ -538,7 +538,6 @@ public class Mekanism GameRegistry.registerItem(AtomicDisassembler, "AtomicDisassembler"); GameRegistry.registerItem(AtomicCore, "AtomicCore"); GameRegistry.registerItem(EnrichedAlloy, "EnrichedAlloy"); - GameRegistry.registerItem(StorageTank, "StorageTank"); GameRegistry.registerItem(ControlCircuit, "ControlCircuit"); GameRegistry.registerItem(EnrichedIron, "EnrichedIron"); GameRegistry.registerItem(CompressedCarbon, "CompressedCarbon"); @@ -577,6 +576,7 @@ public class Mekanism Item.itemsList[machineBlockID] = new ItemBlockMachine(machineBlockID - 256, MachineBlock).setUnlocalizedName("MachineBlock"); Item.itemsList[oreBlockID] = new ItemBlockOre(oreBlockID - 256, OreBlock).setUnlocalizedName("OreBlock"); Item.itemsList[energyCubeID] = new ItemBlockEnergyCube(energyCubeID - 256, EnergyCube).setUnlocalizedName("EnergyCube"); + Item.itemsList[gasTankID] = new ItemBlockGasTank(gasTankID - 256, GasTank).setUnlocalizedName("GasTank"); Item.itemsList[transmitterID] = new ItemBlockTransmitter(transmitterID - 256, Transmitter).setUnlocalizedName("Transmitter"); } @@ -1163,4 +1163,26 @@ public class Mekanism PacketHandler.sendPacket(Transmission.ALL_CLIENTS, new PacketTransmitterTransferUpdate().setParams(TransmitterTransferType.FLUID, event.fluidNetwork.transmitters.iterator().next(), event.fluidSent)); } catch(Exception e) {} } + + @ForgeSubscribe + public void onChunkLoad(ChunkEvent.Load event) + { + if(event.getChunk() != null) + { + Map copy = (Map)((HashMap)event.getChunk().chunkTileEntityMap).clone(); + + for(Object obj : copy.values()) + { + if(obj instanceof TileEntity) + { + TileEntity tileEntity = (TileEntity)obj; + + if(tileEntity instanceof TileEntityElectricBlock) + { + ((TileEntityElectricBlock)tileEntity).register(); + } + } + } + } + } } diff --git a/common/mekanism/common/block/BlockEnergyCube.java b/common/mekanism/common/block/BlockEnergyCube.java index fd0889847..3c04467ff 100644 --- a/common/mekanism/common/block/BlockEnergyCube.java +++ b/common/mekanism/common/block/BlockEnergyCube.java @@ -7,6 +7,7 @@ import java.util.List; import java.util.Random; import mekanism.api.energy.IEnergizedItem; +import mekanism.api.transmitters.ITransmitter; import mekanism.client.ClientProxy; import mekanism.common.IEnergyCube; import mekanism.common.ISustainedInventory; @@ -14,6 +15,7 @@ import mekanism.common.Mekanism; import mekanism.common.Tier.EnergyCubeTier; import mekanism.common.item.ItemBlockEnergyCube; import mekanism.common.tileentity.TileEntityBasicBlock; +import mekanism.common.tileentity.TileEntityElectricBlock; import mekanism.common.tileentity.TileEntityEnergyCube; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; @@ -192,8 +194,6 @@ public class BlockEnergyCube extends BlockContainer { if(!player.capabilities.isCreativeMode && !world.isRemote && canHarvestBlock(player, world.getBlockMetadata(x, y, z))) { - TileEntityEnergyCube tileEntity = (TileEntityEnergyCube)world.getBlockTileEntity(x, y, z); - float motion = 0.7F; double motionX = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D; double motionY = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D; @@ -248,6 +248,17 @@ public class BlockEnergyCube extends BlockContainer return itemStack; } + + @Override + public void onBlockAdded(World world, int x, int y, int z) + { + TileEntity tileEntity = world.getBlockTileEntity(x, y, z); + + if(!world.isRemote) + { + ((TileEntityElectricBlock)tileEntity).register(); + } + } public ItemStack dismantleBlock(World world, int x, int y, int z, boolean returnBlock) { diff --git a/common/mekanism/common/block/BlockGasTank.java b/common/mekanism/common/block/BlockGasTank.java index db322b0b7..cd6ccaeac 100644 --- a/common/mekanism/common/block/BlockGasTank.java +++ b/common/mekanism/common/block/BlockGasTank.java @@ -2,9 +2,10 @@ package mekanism.common.block; import java.util.Random; +import mekanism.api.IStorageTank; +import mekanism.common.ISustainedInventory; import mekanism.common.Mekanism; import mekanism.common.tileentity.TileEntityBasicBlock; -import mekanism.common.tileentity.TileEntityContainerBlock; import mekanism.common.tileentity.TileEntityElectricBlock; import mekanism.common.tileentity.TileEntityGasTank; import net.minecraft.block.BlockContainer; @@ -15,12 +16,9 @@ import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.Icon; import net.minecraft.util.MathHelper; import net.minecraft.util.MovingObjectPosition; -import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import buildcraft.api.tools.IToolWrench; import cpw.mods.fml.relauncher.Side; @@ -62,55 +60,6 @@ public class BlockGasTank extends BlockContainer tileEntity.setFacing((short)change); } - @Override - public void breakBlock(World world, int x, int y, int z, int i1, int i2) - { - TileEntityContainerBlock tileEntity = (TileEntityContainerBlock)world.getBlockTileEntity(x, y, z); - - if(tileEntity != null) - { - for(int i = 0; i < tileEntity.getSizeInventory(); ++i) - { - ItemStack slotStack = tileEntity.getStackInSlot(i); - - if(slotStack != null) - { - float xRandom = machineRand.nextFloat() * 0.8F + 0.1F; - float yRandom = machineRand.nextFloat() * 0.8F + 0.1F; - float zRandom = machineRand.nextFloat() * 0.8F + 0.1F; - - while(slotStack.stackSize > 0) - { - int j = machineRand.nextInt(21) + 10; - - if(j > slotStack.stackSize) - { - j = slotStack.stackSize; - } - - slotStack.stackSize -= j; - EntityItem item = new EntityItem(world, (double)((float)x + xRandom), (double)((float)y + yRandom), (double)((float)z + zRandom), new ItemStack(slotStack.itemID, j, slotStack.getItemDamage())); - - if(slotStack.hasTagCompound()) - { - item.getEntityItem().setTagCompound((NBTTagCompound)slotStack.getTagCompound().copy()); - } - - float k = 0.05F; - item.motionX = (double)((float)machineRand.nextGaussian() * k); - item.motionY = (double)((float)machineRand.nextGaussian() * k + 0.2F); - item.motionZ = (double)((float)machineRand.nextGaussian() * k); - world.spawnEntityInWorld(item); - } - } - } - - tileEntity.invalidate(); - } - - super.breakBlock(world, x, y, z, i1, i2); - } - @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int facing, float playerX, float playerY, float playerZ) { @@ -174,6 +123,24 @@ public class BlockGasTank extends BlockContainer return false; } + @Override + public boolean removeBlockByPlayer(World world, EntityPlayer player, int x, int y, int z) + { + if(!player.capabilities.isCreativeMode && !world.isRemote && canHarvestBlock(player, world.getBlockMetadata(x, y, z))) + { + float motion = 0.7F; + double motionX = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D; + double motionY = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D; + double motionZ = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D; + + EntityItem entityItem = new EntityItem(world, x + motionX, y + motionY, z + motionZ, getPickBlock(null, world, x, y, z)); + + world.spawnEntityInWorld(entityItem); + } + + return world.setBlockToAir(x, y, z); + } + public ItemStack dismantleBlock(World world, int x, int y, int z, boolean returnBlock) { TileEntityElectricBlock tileEntity = (TileEntityElectricBlock)world.getBlockTileEntity(x, y, z); @@ -196,6 +163,18 @@ public class BlockGasTank extends BlockContainer return itemStack; } + @Override + public int quantityDropped(Random random) + { + return 0; + } + + @Override + public int idDropped(int i, Random random, int j) + { + return 0; + } + @Override public boolean renderAsNormalBlock() { @@ -223,6 +202,16 @@ public class BlockGasTank extends BlockContainer @Override public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) { - return new ItemStack(blockID, 1, world.getBlockMetadata(x, y, z)); + TileEntityGasTank tileEntity = (TileEntityGasTank)world.getBlockTileEntity(x, y, z); + ItemStack itemStack = new ItemStack(Mekanism.GasTank); + + IStorageTank storageTank = (IStorageTank)itemStack.getItem(); + storageTank.setGasType(itemStack, tileEntity.gasType); + storageTank.setGas(tileEntity.gasType, tileEntity.gasStored, itemStack); + + ISustainedInventory inventory = (ISustainedInventory)itemStack.getItem(); + inventory.setInventory(((ISustainedInventory)tileEntity).getInventory(), itemStack); + + return itemStack; } } diff --git a/common/mekanism/common/block/BlockMachine.java b/common/mekanism/common/block/BlockMachine.java index b3379cb0f..93611589c 100644 --- a/common/mekanism/common/block/BlockMachine.java +++ b/common/mekanism/common/block/BlockMachine.java @@ -195,23 +195,30 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds float zRandom = (float)z + 0.5F; float iRandom = 0.52F; float jRandom = random.nextFloat() * 0.6F - 0.3F; + + int side = tileEntity.facing; + + if(tileEntity instanceof TileEntityMetallurgicInfuser) + { + side = ForgeDirection.getOrientation(side).getOpposite().ordinal(); + } - if(tileEntity.facing == 4) + if(side == 4) { world.spawnParticle("smoke", (double)(xRandom - iRandom), (double)yRandom, (double)(zRandom + jRandom), 0.0D, 0.0D, 0.0D); world.spawnParticle("reddust", (double)(xRandom - iRandom), (double)yRandom, (double)(zRandom + jRandom), 0.0D, 0.0D, 0.0D); } - else if(tileEntity.facing == 5) + else if(side == 5) { world.spawnParticle("smoke", (double)(xRandom + iRandom), (double)yRandom, (double)(zRandom + jRandom), 0.0D, 0.0D, 0.0D); world.spawnParticle("reddust", (double)(xRandom + iRandom), (double)yRandom, (double)(zRandom + jRandom), 0.0D, 0.0D, 0.0D); } - else if(tileEntity.facing == 2) + else if(side == 2) { world.spawnParticle("smoke", (double)(xRandom + jRandom), (double)yRandom, (double)(zRandom - iRandom), 0.0D, 0.0D, 0.0D); world.spawnParticle("reddust", (double)(xRandom + jRandom), (double)yRandom, (double)(zRandom - iRandom), 0.0D, 0.0D, 0.0D); } - else if(tileEntity.facing == 3) + else if(side == 3) { world.spawnParticle("smoke", (double)(xRandom + jRandom), (double)yRandom, (double)(zRandom + iRandom), 0.0D, 0.0D, 0.0D); world.spawnParticle("reddust", (double)(xRandom + jRandom), (double)yRandom, (double)(zRandom + iRandom), 0.0D, 0.0D, 0.0D); @@ -852,6 +859,17 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds return false; } + + @Override + public void onBlockAdded(World world, int x, int y, int z) + { + TileEntity tileEntity = world.getBlockTileEntity(x, y, z); + + if(!world.isRemote) + { + ((TileEntityElectricBlock)tileEntity).register(); + } + } public static enum MachineType { diff --git a/common/mekanism/common/block/BlockTransmitter.java b/common/mekanism/common/block/BlockTransmitter.java index 1ee0866f6..14aed0967 100644 --- a/common/mekanism/common/block/BlockTransmitter.java +++ b/common/mekanism/common/block/BlockTransmitter.java @@ -1,8 +1,5 @@ package mekanism.common.block; -import ic2.api.energy.event.EnergyTileLoadEvent; -import ic2.api.energy.tile.IEnergyTile; - import java.util.Arrays; import java.util.List; @@ -33,7 +30,6 @@ import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; -import net.minecraftforge.common.MinecraftForge; import buildcraft.api.tools.IToolWrench; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -326,6 +322,11 @@ public class BlockTransmitter extends Block if(tileEntity instanceof ITransmitter) { ((ITransmitter)tileEntity).refreshTransmitterNetwork(); + + if(tileEntity instanceof TileEntityUniversalCable) + { + ((TileEntityUniversalCable)tileEntity).register(); + } } } } diff --git a/common/mekanism/common/item/ItemStorageTank.java b/common/mekanism/common/item/ItemBlockGasTank.java similarity index 66% rename from common/mekanism/common/item/ItemStorageTank.java rename to common/mekanism/common/item/ItemBlockGasTank.java index 2530f8d7f..4518653a7 100644 --- a/common/mekanism/common/item/ItemStorageTank.java +++ b/common/mekanism/common/item/ItemBlockGasTank.java @@ -2,35 +2,76 @@ package mekanism.common.item; import java.util.List; +import mekanism.api.EnumColor; import mekanism.api.IStorageTank; import mekanism.api.gas.EnumGas; +import mekanism.common.IEnergyCube; +import mekanism.common.ISustainedInventory; import mekanism.common.Mekanism; +import mekanism.common.tileentity.TileEntityGasTank; +import net.minecraft.block.Block; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.Icon; import net.minecraft.world.World; -public class ItemStorageTank extends ItemMekanism implements IStorageTank +import org.lwjgl.input.Keyboard; + +public class ItemBlockGasTank extends ItemBlock implements IStorageTank, ISustainedInventory { + public Block metaBlock; + /** The maximum amount of gas this tank can hold. */ - public int MAX_GAS; + public int MAX_GAS = 96000; /** How fast this tank can transfer gas. */ - public int TRANSFER_RATE; + public int TRANSFER_RATE = 16; - public ItemStorageTank(int id, int maxGas, int transferRate) + public ItemBlockGasTank(int id, Block block) { super(id); - MAX_GAS = maxGas; - TRANSFER_RATE = transferRate; + metaBlock = block; + setHasSubtypes(true); setMaxStackSize(1); setMaxDamage(100); setNoRepair(); setCreativeTab(Mekanism.tabMekanism); } + @Override + public int getMetadata(int i) + { + return i; + } + + @Override + public Icon getIconFromDamage(int i) + { + return metaBlock.getIcon(2, i); + } + + @Override + public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata) + { + boolean place = super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata); + + if(place) + { + TileEntityGasTank tileEntity = (TileEntityGasTank)world.getBlockTileEntity(x, y, z); + tileEntity.gasType = getGasType(stack); + tileEntity.gasStored = getGas(getGasType(stack), stack); + + ((ISustainedInventory)tileEntity).setInventory(getInventory(stack)); + } + + return place; + } + @Override public void addInformation(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag) { @@ -43,6 +84,14 @@ public class ItemStorageTank extends ItemMekanism implements IStorageTank else { list.add("Stored " + getGasType(itemstack).name + ": " + gas); } + + if(!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) + { + list.add("Hold " + EnumColor.AQUA + "shift" + EnumColor.GREY + " for more details."); + } + else { + list.add(EnumColor.AQUA + "Inventory: " + EnumColor.GREY + (getInventory(itemstack) != null && getInventory(itemstack).tagCount() != 0)); + } } @Override @@ -81,7 +130,7 @@ public class ItemStorageTank extends ItemMekanism implements IStorageTank stored = itemstack.stackTagCompound.getInteger("gas"); } - itemstack.setItemDamage((int)(Math.abs((((float)stored/MAX_GAS)*100)-100))); + itemstack.setItemDamage((int)Math.max(1, (Math.abs((((float)stored/MAX_GAS)*100)-100)))); return stored; } } @@ -110,7 +159,7 @@ public class ItemStorageTank extends ItemMekanism implements IStorageTank { int stored = Math.max(Math.min(amount, MAX_GAS), 0); itemstack.stackTagCompound.setInteger("gas", stored); - itemstack.setItemDamage((int)(Math.abs((((float)stored/MAX_GAS)*100)-100))); + itemstack.setItemDamage((int)Math.max(1, (Math.abs((((float)stored/MAX_GAS)*100)-100)))); } if(getGas(getGasType(itemstack), itemstack) == 0) @@ -235,4 +284,38 @@ public class ItemStorageTank extends ItemMekanism implements IStorageTank itemstack.stackTagCompound.setString("gasType", type.name); } + + @Override + public void setInventory(NBTTagList nbtTags, Object... data) + { + if(data[0] instanceof ItemStack) + { + ItemStack itemStack = (ItemStack)data[0]; + + if(itemStack.stackTagCompound == null) + { + itemStack.setTagCompound(new NBTTagCompound()); + } + + itemStack.stackTagCompound.setTag("Items", nbtTags); + } + } + + @Override + public NBTTagList getInventory(Object... data) + { + if(data[0] instanceof ItemStack) + { + ItemStack itemStack = (ItemStack)data[0]; + + if(itemStack.stackTagCompound == null) + { + return null; + } + + return itemStack.stackTagCompound.getTagList("Items"); + } + + return null; + } } diff --git a/common/mekanism/common/item/ItemBlockOre.java b/common/mekanism/common/item/ItemBlockOre.java index 2bbe83b48..18174650f 100644 --- a/common/mekanism/common/item/ItemBlockOre.java +++ b/common/mekanism/common/item/ItemBlockOre.java @@ -65,6 +65,7 @@ public class ItemBlockOre extends ItemBlock public String getUnlocalizedName(ItemStack itemstack) { String name = ""; + switch(itemstack.getItemDamage()) { case 0: @@ -74,6 +75,7 @@ public class ItemBlockOre extends ItemBlock name = "Unknown"; break; } + return getUnlocalizedName() + "." + name; } } diff --git a/common/mekanism/common/network/PacketTransmitterTransferUpdate.java b/common/mekanism/common/network/PacketTransmitterTransferUpdate.java index cf23ef904..4d8b55280 100644 --- a/common/mekanism/common/network/PacketTransmitterTransferUpdate.java +++ b/common/mekanism/common/network/PacketTransmitterTransferUpdate.java @@ -2,10 +2,13 @@ package mekanism.common.network; import java.io.DataOutputStream; +import mekanism.api.Object3D; import mekanism.api.gas.EnumGas; +import mekanism.client.ClientPlayerTickHandler.UpdateQueueData; import mekanism.client.EnergyClientUpdate; -import mekanism.client.GasClientUpdate; import mekanism.client.FluidClientUpdate; +import mekanism.client.GasClientUpdate; +import mekanism.client.MekanismClient; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; @@ -13,6 +16,9 @@ import net.minecraftforge.fluids.FluidStack; import com.google.common.io.ByteArrayDataInput; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + public class PacketTransmitterTransferUpdate implements IMekanismPacket { public TransmitterTransferType activeType; @@ -72,6 +78,11 @@ public class PacketTransmitterTransferUpdate implements IMekanismPacket { new EnergyClientUpdate(tileEntity, powerLevel).clientUpdate(); } + else { + try { + appendToQueue(Object3D.get(tileEntity), powerLevel); + } catch(Exception e) {} + } } else if(transmitterType == 1) { @@ -95,6 +106,12 @@ public class PacketTransmitterTransferUpdate implements IMekanismPacket } } } + + @SideOnly(Side.CLIENT) + public void appendToQueue(Object3D obj, double energy) throws Exception + { + MekanismClient.cableUpdateQueue.add(new UpdateQueueData(obj, energy)); + } @Override public void write(DataOutputStream dataStream) throws Exception diff --git a/common/mekanism/common/tileentity/TileEntityCrusher.java b/common/mekanism/common/tileentity/TileEntityCrusher.java index 4d89c92d3..85731cad2 100644 --- a/common/mekanism/common/tileentity/TileEntityCrusher.java +++ b/common/mekanism/common/tileentity/TileEntityCrusher.java @@ -1,11 +1,13 @@ package mekanism.common.tileentity; +import java.util.EnumSet; import java.util.Map; -import net.minecraft.util.ResourceLocation; import mekanism.common.Mekanism; import mekanism.common.RecipeHandler.Recipe; import mekanism.common.block.BlockMachine.MachineType; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.common.ForgeDirection; public class TileEntityCrusher extends TileEntityElectricMachine { @@ -46,6 +48,12 @@ public class TileEntityCrusher extends TileEntityElectricMachine } } + @Override + protected EnumSet getConsumingSides() + { + return EnumSet.of(ForgeDirection.getOrientation(0)); + } + @Override public Map getRecipes() { diff --git a/common/mekanism/common/tileentity/TileEntityElectricBlock.java b/common/mekanism/common/tileentity/TileEntityElectricBlock.java index 138f614fb..633f19f04 100644 --- a/common/mekanism/common/tileentity/TileEntityElectricBlock.java +++ b/common/mekanism/common/tileentity/TileEntityElectricBlock.java @@ -8,6 +8,7 @@ import ic2.api.tile.IWrenchable; import java.util.ArrayList; import java.util.EnumSet; +import mekanism.api.Object3D; import mekanism.api.energy.IStrictEnergyStorage; import mekanism.common.ITileNetwork; import mekanism.common.Mekanism; @@ -51,16 +52,23 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i powerHandler.configure(0, 100, 0, (int)(maxEnergy*Mekanism.TO_BC)); } + public void register() + { + if(!worldObj.isRemote) + { + if(!Mekanism.ic2Registered.contains(Object3D.get(this))) + { + Mekanism.ic2Registered.add(Object3D.get(this)); + MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this)); + } + } + } + @Override public void onUpdate() { if(!worldObj.isRemote) { - if(packetTick == 0) - { - MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this)); - } - if(getEnergy() < getMaxEnergy() && powerHandler.getEnergyStored() > 0) { setEnergy(getEnergy() + powerHandler.useEnergy(0, (float)((getMaxEnergy()-getEnergy())*Mekanism.TO_BC), true)*Mekanism.FROM_BC); @@ -129,17 +137,15 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i } @Override - public void invalidate() + public void onChunkUnload() { if(!worldObj.isRemote) { - if(Mekanism.hooks.IC2Loaded) - { - MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this)); - } + Mekanism.ic2Registered.remove(Object3D.get(this)); + MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this)); } - super.invalidate(); + super.onChunkUnload(); } @Override diff --git a/common/mekanism/common/tileentity/TileEntityUniversalCable.java b/common/mekanism/common/tileentity/TileEntityUniversalCable.java index 46674ce23..d8d5dc8db 100644 --- a/common/mekanism/common/tileentity/TileEntityUniversalCable.java +++ b/common/mekanism/common/tileentity/TileEntityUniversalCable.java @@ -37,8 +37,6 @@ public class TileEntityUniversalCable extends TileEntityTransmitter