From 1996bb1c5501ed744961bf59550174074c5d00bb Mon Sep 17 00:00:00 2001 From: Calclavia Date: Mon, 17 Mar 2014 22:34:52 +0800 Subject: [PATCH] Finished initial code for mechanical piston --- .../crusher/RenderMechanicalPiston.java | 5 +- .../process/crusher/TileMechanicalPiston.java | 114 ++++++++++-------- 2 files changed, 65 insertions(+), 54 deletions(-) diff --git a/mechanical/src/main/java/resonantinduction/mechanical/process/crusher/RenderMechanicalPiston.java b/mechanical/src/main/java/resonantinduction/mechanical/process/crusher/RenderMechanicalPiston.java index bd0783ed9..61b41e84a 100644 --- a/mechanical/src/main/java/resonantinduction/mechanical/process/crusher/RenderMechanicalPiston.java +++ b/mechanical/src/main/java/resonantinduction/mechanical/process/crusher/RenderMechanicalPiston.java @@ -36,7 +36,7 @@ public class RenderMechanicalPiston extends TileEntitySpecialRenderer float angle = (float) tile.mechanicalNode.angle; float radius = 0.5f; // Length of piston arm - float length = 1f; + float length = 0.8f; double beta = Math.asin((radius * Math.sin(angle)) / (length / 2)); @@ -56,7 +56,8 @@ public class RenderMechanicalPiston extends TileEntitySpecialRenderer * Render Piston Rotor */ GL11.glPushMatrix(); - GL11.glTranslated(0, 0, (0.5 * Math.sin(angle - Math.PI)) - 0.5); + // TODO: Temporary, unless new models come out. + GL11.glTranslated(0, 0, (0.06 * Math.sin(angle - Math.PI)) - 0.01); MODEL.renderOnly("PistonShaft", "PistonFace", "PistonFace2"); GL11.glPopMatrix(); diff --git a/mechanical/src/main/java/resonantinduction/mechanical/process/crusher/TileMechanicalPiston.java b/mechanical/src/main/java/resonantinduction/mechanical/process/crusher/TileMechanicalPiston.java index efd1938f4..8f57a20d3 100644 --- a/mechanical/src/main/java/resonantinduction/mechanical/process/crusher/TileMechanicalPiston.java +++ b/mechanical/src/main/java/resonantinduction/mechanical/process/crusher/TileMechanicalPiston.java @@ -2,9 +2,6 @@ package resonantinduction.mechanical.process.crusher; import java.lang.reflect.Method; -import calclavia.api.recipe.MachineRecipes; -import calclavia.api.recipe.RecipeResource; -import calclavia.lib.utility.inventory.InventoryUtility; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.item.ItemStack; @@ -15,20 +12,21 @@ import net.minecraftforge.common.ForgeDirection; import resonantinduction.core.ResonantInduction; import resonantinduction.mechanical.energy.grid.TileMechanical; import universalelectricity.api.vector.Vector3; +import calclavia.api.recipe.MachineRecipes; +import calclavia.api.recipe.RecipeResource; import calclavia.lib.config.Config; import calclavia.lib.prefab.tile.IRotatable; import calclavia.lib.utility.MovementUtility; +import calclavia.lib.utility.inventory.InventoryUtility; import cpw.mods.fml.common.Loader; import cpw.mods.fml.relauncher.ReflectionHelper; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; public class TileMechanicalPiston extends TileMechanical implements IRotatable { @Config - private static final int mechanicalPistonBreakCount = 5; + private static int mechanicalPistonBreakCount = 5; - private int copyBreakCount = mechanicalPistonBreakCount; + private int breakCount = mechanicalPistonBreakCount; public TileMechanicalPiston() { @@ -39,13 +37,17 @@ public class TileMechanicalPiston extends TileMechanical implements IRotatable @Override protected void revolve() { - if (!worldObj.isRemote) - { - Vector3 movePosition = new Vector3(TileMechanicalPiston.this).translate(getDirection()); - Vector3 moveNewPosition = movePosition.clone().translate(getDirection()); + Vector3 movePosition = new Vector3(TileMechanicalPiston.this).translate(getDirection()); - if (canMove(movePosition, moveNewPosition)) - move(movePosition, moveNewPosition); + if (!hitOreBlock(movePosition)) + { + if (!worldObj.isRemote) + { + Vector3 moveNewPosition = movePosition.clone().translate(getDirection()); + + if (canMove(movePosition, moveNewPosition)) + move(movePosition, moveNewPosition); + } } } @@ -76,13 +78,54 @@ public class TileMechanicalPiston extends TileMechanical implements IRotatable mechanicalNode.angle = 0; } - @Override - public void onRemove (int par5, int par6) - { - super.onRemove(par5, par6); - } + public boolean hitOreBlock(Vector3 blockPos) + { + Block block = Block.blocksList[blockPos.getBlockID(world())]; - public boolean canMove(Vector3 from, Vector3 to) + if (block != null) + { + ItemStack blockStack = new ItemStack(block); + RecipeResource[] resources = MachineRecipes.INSTANCE.getOutput(ResonantInduction.RecipeType.CRUSHER.name(), blockStack); + + if (resources.length > 0) + { + int breakStatus = (int) (((float) (mechanicalPistonBreakCount - breakCount) / (float) mechanicalPistonBreakCount) * 10f); + world().destroyBlockInWorldPartially(0, blockPos.intX(), blockPos.intY(), blockPos.intZ(), breakStatus); + + if (breakCount <= 0) + { + if (!world().isRemote) + { + for (RecipeResource recipe : resources) + { + if (Math.random() <= recipe.getChance()) + { + InventoryUtility.dropItemStack(world(), blockPos.clone().translate(0.5), recipe.getItemStack(), 10); + } + } + + world().setBlockToAir(blockPos.intX(), blockPos.intY(), blockPos.intZ()); + } + + breakCount = mechanicalPistonBreakCount; + } + + ResonantInduction.proxy.renderBlockParticle(worldObj, blockPos.clone().translate(0.5), new Vector3((Math.random() - 0.5f) * 3, (Math.random() - 0.5f) * 3, (Math.random() - 0.5f) * 3), block.blockID, 1); + breakCount--; + return true; + } + } + + return false; + } + + @Override + public void onRemove(int par5, int par6) + { + super.onRemove(par5, par6); + } + + public boolean canMove(Vector3 from, Vector3 to) { TileEntity tileEntity = from.getTileEntity(worldObj); @@ -204,37 +247,4 @@ public class TileMechanicalPiston extends TileMechanical implements IRotatable } } - public void hitOreBlock(Block oreBlock, Vector3 blockPos) - { - ItemStack blockStack = new ItemStack(oreBlock); - if (worldObj.isRemote) - { - spawnParticles(blockPos); - return; - } - else - { - if (this.copyBreakCount <= 0) - { - getWorldObj().setBlockToAir(blockPos.intX(), blockPos.intY(), blockPos.intZ()); - RecipeResource[] resources = MachineRecipes.INSTANCE.getOutput(ResonantInduction.RecipeType.CRUSHER.name(), blockStack); - - for (RecipeResource recipe : resources) - { - InventoryUtility.dropItemStack(getWorldObj(), blockPos, recipe.getItemStack(), 10, recipe.getChance()); - } - - this.copyBreakCount = this.mechanicalPistonBreakCount; - - } - this.copyBreakCount--; - } - - } - - @SideOnly(Side.CLIENT) - private void spawnParticles(Vector3 blockPos) - { - - } }