diff --git a/src/resonantinduction/ClientProxy.java b/src/resonantinduction/ClientProxy.java index 9f6870956..2b017c3cc 100644 --- a/src/resonantinduction/ClientProxy.java +++ b/src/resonantinduction/ClientProxy.java @@ -6,11 +6,13 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; import resonantinduction.base.Vector3; +import resonantinduction.battery.TileEntityBattery; import resonantinduction.contractor.TileEntityEMContractor; import resonantinduction.fx.FXElectricBolt; import resonantinduction.multimeter.GuiMultimeter; import resonantinduction.multimeter.TileEntityMultimeter; import resonantinduction.render.BlockRenderingHandler; +import resonantinduction.render.RenderBattery; import resonantinduction.render.RenderEMContractor; import resonantinduction.render.RenderMultimeter; import resonantinduction.render.RenderTesla; @@ -38,6 +40,7 @@ public class ClientProxy extends CommonProxy ClientRegistry.bindTileEntitySpecialRenderer(TileEntityTesla.class, new RenderTesla()); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityMultimeter.class, new RenderMultimeter()); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityEMContractor.class, new RenderEMContractor()); + ClientRegistry.bindTileEntitySpecialRenderer(TileEntityBattery.class, new RenderBattery()); } @Override diff --git a/src/resonantinduction/base/SetUtil.java b/src/resonantinduction/base/SetUtil.java index a1f0cd429..724fc5542 100644 --- a/src/resonantinduction/base/SetUtil.java +++ b/src/resonantinduction/base/SetUtil.java @@ -5,6 +5,8 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import net.minecraft.item.ItemStack; + public class SetUtil { public static Set inverse(Set set) @@ -19,4 +21,31 @@ public class SetUtil return toReturn; } + + public static Set cap(Set set, int cap) + { + Set toReturn = new HashSet(); + + if(set.size() <= cap) + { + toReturn = set; + } + else { + int count = 0; + + for(V obj : set) + { + count++; + + toReturn.add(obj); + + if(count == cap) + { + break; + } + } + } + + return toReturn; + } } diff --git a/src/resonantinduction/battery/BatteryUpdateProtocol.java b/src/resonantinduction/battery/BatteryUpdateProtocol.java index ef747dd67..7c7ac1097 100644 --- a/src/resonantinduction/battery/BatteryUpdateProtocol.java +++ b/src/resonantinduction/battery/BatteryUpdateProtocol.java @@ -7,6 +7,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; +import resonantinduction.base.SetUtil; import resonantinduction.base.Vector3; import resonantinduction.battery.BatteryManager.BatteryCache; @@ -249,27 +250,7 @@ public class BatteryUpdateProtocol idFound = BatteryManager.getUniqueInventoryID(); } - Set newInventory = new HashSet(); - - if(cache.inventory.size() <= structureFound.getMaxCells()) - { - newInventory = cache.inventory; - } - else { - int count = 0; - - for(ItemStack itemStack : cache.inventory) - { - count++; - - newInventory.add(itemStack); - - if(count == structureFound.getMaxCells()) - { - break; - } - } - } + Set newInventory = SetUtil.cap(cache.inventory, structureFound.getMaxCells()); structureFound.inventory = newInventory; diff --git a/src/resonantinduction/battery/BlockBattery.java b/src/resonantinduction/battery/BlockBattery.java index 183eebd99..5ecdd0bbe 100644 --- a/src/resonantinduction/battery/BlockBattery.java +++ b/src/resonantinduction/battery/BlockBattery.java @@ -5,16 +5,16 @@ package resonantinduction.battery; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.material.Material; -import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.Icon; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; -import resonantinduction.ResonantInduction; import resonantinduction.base.BlockBase; +import resonantinduction.render.BlockRenderingHandler; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; /** * A block that detects power. @@ -24,31 +24,11 @@ import resonantinduction.base.BlockBase; */ public class BlockBattery extends BlockBase implements ITileEntityProvider { - private Icon machineIcon; - public BlockBattery(int id) { super("battery", id, Material.iron); } - @Override - public Icon getIcon(int side, int metadata) - { - if (side == metadata) - { - return this.blockIcon; - } - - return this.machineIcon; - } - - @Override - public void registerIcons(IconRegister iconRegister) - { - super.registerIcons(iconRegister); - this.machineIcon = iconRegister.registerIcon(ResonantInduction.PREFIX + "machine"); - } - @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float par7, float par8, float par9) { @@ -94,6 +74,19 @@ public class BlockBattery extends BlockBase implements ITileEntityProvider { return false; } + + @Override + public boolean isOpaqueCube() + { + return false; + } + + @Override + @SideOnly(Side.CLIENT) + public int getRenderType() + { + return BlockRenderingHandler.INSTANCE.getRenderId(); + } @Override public TileEntity createNewTileEntity(World world) diff --git a/src/resonantinduction/render/BlockRenderingHandler.java b/src/resonantinduction/render/BlockRenderingHandler.java index 7157f227b..49e36e8f6 100644 --- a/src/resonantinduction/render/BlockRenderingHandler.java +++ b/src/resonantinduction/render/BlockRenderingHandler.java @@ -9,6 +9,7 @@ import net.minecraft.world.IBlockAccess; import org.lwjgl.opengl.GL11; +import resonantinduction.battery.BlockBattery; import resonantinduction.contractor.BlockEMContractor; import resonantinduction.model.ModelEMContractor; import resonantinduction.tesla.BlockTesla; @@ -50,6 +51,15 @@ public class BlockRenderingHandler implements ISimpleBlockRenderingHandler MODEL_CONTRACTOR.render(0.0625f, false); GL11.glPopMatrix(); } + else if (block instanceof BlockBattery) + { + GL11.glPushMatrix(); + GL11.glTranslated(0.5, 1.5, 0.5); + GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F); + FMLClientHandler.instance().getClient().renderEngine.func_110577_a(RenderBattery.TEXTURE); + RenderBattery.MODEL.render(0.0625f); + GL11.glPopMatrix(); + } } @Override