From 7e1778098c3339319cf64ec2a1b0735f9e4ebd2c Mon Sep 17 00:00:00 2001 From: Calclavia Date: Sun, 16 Feb 2014 16:08:23 +0800 Subject: [PATCH] Added custom sized wind turbines --- .../mechanical/gear/ItemGear.java | 6 +-- .../mechanical/turbine/BlockWindTurbine.java | 41 +++++++++++++++++++ .../mechanical/turbine/RenderWindTurbine.java | 2 + .../mechanical/turbine/TileWindTurbine.java | 25 +++++++---- 4 files changed, 64 insertions(+), 10 deletions(-) diff --git a/mechanical/src/main/java/resonantinduction/mechanical/gear/ItemGear.java b/mechanical/src/main/java/resonantinduction/mechanical/gear/ItemGear.java index af0fc4adb..4b4287c77 100644 --- a/mechanical/src/main/java/resonantinduction/mechanical/gear/ItemGear.java +++ b/mechanical/src/main/java/resonantinduction/mechanical/gear/ItemGear.java @@ -37,13 +37,13 @@ public class ItemGear extends JItemMultiPart side = FacePlacementGrid$.MODULE$.getHitSlot(hit, side); TileEntity tile = world.getBlockTileEntity(pos.x, pos.y, pos.z); - + if (tile instanceof TileMultipart) { TMultiPart occupyingPart = ((TileMultipart) tile).partMap(side); TMultiPart centerPart = ((TileMultipart) tile).partMap(PartMap.CENTER.ordinal()); - boolean clickedCenter = hit.mag() < 1; - + boolean clickedCenter = hit.mag() < 0.4; + if ((clickedCenter && centerPart instanceof PartGearShaft)) { side ^= 1; diff --git a/mechanical/src/main/java/resonantinduction/mechanical/turbine/BlockWindTurbine.java b/mechanical/src/main/java/resonantinduction/mechanical/turbine/BlockWindTurbine.java index 414626e2c..4ee26da61 100644 --- a/mechanical/src/main/java/resonantinduction/mechanical/turbine/BlockWindTurbine.java +++ b/mechanical/src/main/java/resonantinduction/mechanical/turbine/BlockWindTurbine.java @@ -1,11 +1,13 @@ package resonantinduction.mechanical.turbine; import net.minecraft.block.material.Material; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import resonantinduction.core.Reference; import resonantinduction.core.render.RIBlockRenderingHandler; import calclavia.lib.prefab.turbine.BlockTurbine; +import calclavia.lib.prefab.turbine.TileTurbine; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -18,6 +20,45 @@ public class BlockWindTurbine extends BlockTurbine rotationMask = Byte.parseByte("111111", 2); } + public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) + { + if (entityPlayer.getCurrentEquippedItem() == null) + { + TileEntity tileEntity = world.getBlockTileEntity(x, y, z); + + if (tileEntity instanceof TileTurbine) + { + if (!world.isRemote && !((TileTurbine) tileEntity).getMultiBlock().isConstructed()) + { + ((TileTurbine) tileEntity).multiBlockRadius = Math.max(((TileTurbine) tileEntity).multiBlockRadius + 1, 1); + entityPlayer.addChatMessage("Turbine radius: " + ((TileTurbine) tileEntity).multiBlockRadius); + } + + return true; + } + } + + return false; + } + + public boolean onSneakMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) + { + TileEntity tileEntity = world.getBlockTileEntity(x, y, z); + + if (tileEntity instanceof TileTurbine) + { + if (!world.isRemote && !((TileTurbine) tileEntity).getMultiBlock().isConstructed()) + { + ((TileTurbine) tileEntity).multiBlockRadius = Math.max(((TileTurbine) tileEntity).multiBlockRadius - 1, 1); + entityPlayer.addChatMessage("Turbine radius: " + ((TileTurbine) tileEntity).multiBlockRadius); + } + + return true; + } + + return false; + } + @SideOnly(Side.CLIENT) @Override public int getRenderType() diff --git a/mechanical/src/main/java/resonantinduction/mechanical/turbine/RenderWindTurbine.java b/mechanical/src/main/java/resonantinduction/mechanical/turbine/RenderWindTurbine.java index 5cef5ccc7..fd56e2517 100644 --- a/mechanical/src/main/java/resonantinduction/mechanical/turbine/RenderWindTurbine.java +++ b/mechanical/src/main/java/resonantinduction/mechanical/turbine/RenderWindTurbine.java @@ -43,6 +43,8 @@ public class RenderWindTurbine extends TileEntitySpecialRenderer */ if (tile.getMultiBlock().isConstructed()) { + GL11.glScalef(0.3f, 1, 0.3f); + GL11.glScalef(tile.multiBlockRadius * 2 + 1, 1, tile.multiBlockRadius * 2 + 1); RenderUtility.bind(Reference.BLOCK_TEXTURE_DIRECTORY + "planks_oak.png"); MODEL.renderOnly("LargeBladeArm"); RenderUtility.bind(Reference.BLOCK_TEXTURE_DIRECTORY + "wool_colored_white.png"); diff --git a/mechanical/src/main/java/resonantinduction/mechanical/turbine/TileWindTurbine.java b/mechanical/src/main/java/resonantinduction/mechanical/turbine/TileWindTurbine.java index 14914352d..6abbf1aee 100644 --- a/mechanical/src/main/java/resonantinduction/mechanical/turbine/TileWindTurbine.java +++ b/mechanical/src/main/java/resonantinduction/mechanical/turbine/TileWindTurbine.java @@ -36,7 +36,7 @@ public class TileWindTurbine extends TileTurbine implements IMechanical */ if (getDirection().offsetY == 0) { - maxPower = 200; + maxPower = 120; getMultiBlock().get().power += getWindPower(); } else @@ -44,10 +44,10 @@ public class TileWindTurbine extends TileTurbine implements IMechanical maxPower = 1000; } - if (!getMultiBlock().isConstructed()) - torque = defaultTorque / 9; + if (getMultiBlock().isConstructed()) + torque = (long) (defaultTorque / (9f / multiBlockRadius)); else - torque = defaultTorque / 3; + torque = defaultTorque / 12; super.updateEntity(); } @@ -66,7 +66,7 @@ public class TileWindTurbine extends TileTurbine implements IMechanical if (!worldObj.canBlockSeeTheSky(xCoord, yCoord + 4, zCoord)) return 0; - return (long) (((((float) yCoord + 4) / 256) * maxPower) * (hasBonus ? 3 : 1)) * (worldObj.isRaining() ? 2 : 1); + return (long) (((((float) yCoord + 4) / 256) * maxPower) * (hasBonus ? 2 : 1)) * (worldObj.isRaining() ? 2 : 1); } @Override @@ -166,8 +166,19 @@ public class TileWindTurbine extends TileTurbine implements IMechanical } @Override - public boolean canConnect(ForgeDirection from, Object sourcen) + public boolean canConnect(ForgeDirection from, Object source) { - return from == getDirection().getOpposite(); + /** + * Face to face stick connection. + */ + TileEntity sourceTile = getPosition().translate(from).getTileEntity(getWorld()); + + if (sourceTile instanceof IMechanical) + { + IMechanical sourceInstance = ((IMechanical) sourceTile).getInstance(from.getOpposite()); + return sourceInstance == source && from == getDirection().getOpposite(); + } + + return false; } }