From a34d9d86a9011534d3c027abaa4ea1d2dd464c68 Mon Sep 17 00:00:00 2001 From: Aidan Brady Date: Sun, 4 Aug 2013 11:56:31 -0400 Subject: [PATCH] Gave the Battery a model --- src/resonantinduction/ClientProxy.java | 3 ++ src/resonantinduction/base/SetUtil.java | 29 ++++++++++++++ .../battery/BatteryUpdateProtocol.java | 23 +---------- .../battery/BlockBattery.java | 39 ++++++++----------- .../render/BlockRenderingHandler.java | 10 +++++ 5 files changed, 60 insertions(+), 44 deletions(-) diff --git a/src/resonantinduction/ClientProxy.java b/src/resonantinduction/ClientProxy.java index 9f687095..2b017c3c 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 a1f0cd42..724fc554 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 ef747dd6..7c7ac109 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 183eebd9..5ecdd0bb 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 7157f227..49e36e8f 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