From e60a78b9e01c0bdecd09c248a36497e4bef4b9e2 Mon Sep 17 00:00:00 2001 From: DarkGuardsman Date: Wed, 23 Oct 2013 13:16:48 -0400 Subject: [PATCH] Toyed with wrench --- .../prefab/block/BlockRotatable.java | 111 ++++++++++-------- .../prefab/block/IRotatableBlock.java | 17 +++ src/dark/core/common/items/ItemWrench.java | 23 +--- 3 files changed, 86 insertions(+), 65 deletions(-) create mode 100644 APIs/universalelectricity/prefab/block/IRotatableBlock.java diff --git a/APIs/universalelectricity/prefab/block/BlockRotatable.java b/APIs/universalelectricity/prefab/block/BlockRotatable.java index 5d19fdd97..3475f33da 100644 --- a/APIs/universalelectricity/prefab/block/BlockRotatable.java +++ b/APIs/universalelectricity/prefab/block/BlockRotatable.java @@ -8,61 +8,76 @@ import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; -/** - * A block that can rotate based on placed position and wrenching. - * - * @author Calclavia - * - */ -public abstract class BlockRotatable extends BlockTile +/** A block that can rotate based on placed position and wrenching. + * + * @author Calclavia */ +public abstract class BlockRotatable extends BlockTile implements IRotatableBlock { - public BlockRotatable(int id, Material material) - { - super(id, material); - } + public BlockRotatable(int id, Material material) + { + super(id, material); + } - @Override - public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack) - { - int angle = MathHelper.floor_double((entityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; - int change = 3; + @Override + public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack) + { + int angle = MathHelper.floor_double((entityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; + int change = 3; - switch (angle) - { - case 0: - change = 2; - break; + switch (angle) + { + case 0: + change = 2; + break; - case 1: - change = 5; - break; + case 1: + change = 5; + break; - case 2: - change = 3; - break; + case 2: + change = 3; + break; - case 3: - change = 4; - break; - } + case 3: + change = 4; + break; + } - world.setBlockMetadataWithNotify(x, y, z, change, 3); - } + world.setBlockMetadataWithNotify(x, y, z, change, 3); + } - @Override - public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ) - { - this.rotateBlock(world, x, y, z, ForgeDirection.getOrientation(side)); - return true; - } + @Override + public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ) + { + this.rotateBlock(world, x, y, z, ForgeDirection.getOrientation(side)); + return true; + } - public static boolean rotateBlock(World worldObj, int x, int y, int z, ForgeDirection axis, int mask) - { - int rotMeta = worldObj.getBlockMetadata(x, y, z); - int masked = rotMeta & ~mask; - ForgeDirection orientation = ForgeDirection.getOrientation(rotMeta & mask); - ForgeDirection rotated = orientation.getRotation(axis); - worldObj.setBlockMetadataWithNotify(x, y, z, rotated.ordinal() & mask | masked, 3); - return true; - } + public static boolean rotateBlock(World worldObj, int x, int y, int z, ForgeDirection axis, int mask) + { + int rotMeta = worldObj.getBlockMetadata(x, y, z); + int masked = rotMeta & ~mask; + ForgeDirection orientation = ForgeDirection.getOrientation(rotMeta & mask); + ForgeDirection rotated = orientation.getRotation(axis); + worldObj.setBlockMetadataWithNotify(x, y, z, rotated.ordinal() & mask | masked, 3); + return true; + } + + @Override + public boolean onSneakMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) + { + return false; + } + + @Override + public ForgeDirection getDirection(World world, int x, int y, int z) + { + return ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z)); + } + + @Override + public void setDirection(World world, int x, int y, int z, ForgeDirection direction) + { + world.setBlockMetadataWithNotify(x, y, z, direction.ordinal(), 3); + } } \ No newline at end of file diff --git a/APIs/universalelectricity/prefab/block/IRotatableBlock.java b/APIs/universalelectricity/prefab/block/IRotatableBlock.java new file mode 100644 index 000000000..6e6128095 --- /dev/null +++ b/APIs/universalelectricity/prefab/block/IRotatableBlock.java @@ -0,0 +1,17 @@ +package universalelectricity.prefab.block; + +import net.minecraft.world.World; +import net.minecraftforge.common.ForgeDirection; + +/** The interface is applied to Blocks that can rotate. + * + * @author DarkGuardsman */ + +public interface IRotatableBlock +{ + /** @return Gets the facing direction. Always returns the front side of the block. */ + public ForgeDirection getDirection(World world, int x, int y, int z); + + /** @param Sets the facing direction. */ + public void setDirection(World world, int x, int y, int z, ForgeDirection direection); +} diff --git a/src/dark/core/common/items/ItemWrench.java b/src/dark/core/common/items/ItemWrench.java index 3656db268..a2f18dfce 100644 --- a/src/dark/core/common/items/ItemWrench.java +++ b/src/dark/core/common/items/ItemWrench.java @@ -4,10 +4,13 @@ import net.minecraft.block.Block; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.common.Configuration; import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.oredict.OreDictionary; +import universalelectricity.prefab.block.IRotatableBlock; +import universalelectricity.prefab.tile.IRotatable; import buildcraft.api.tools.IToolWrench; import dark.core.common.DarkMain; import dark.core.prefab.IExtraInfo.IExtraItemInfo; @@ -28,27 +31,13 @@ public class ItemWrench extends ItemBasic implements IToolWrench, IExtraItemInfo } @Override - public boolean onItemUseFirst(ItemStack stack, EntityPlayer entityPlayer, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) + public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { - int blockID = world.getBlockId(x, y, z); - - if (blockID == Block.furnaceIdle.blockID || blockID == Block.furnaceBurning.blockID || blockID == Block.dropper.blockID || blockID == Block.hopperBlock.blockID || blockID == Block.dispenser.blockID || blockID == Block.pistonBase.blockID || blockID == Block.pistonStickyBase.blockID) + if (Block.blocksList[world.getBlockId(x, y, z)].rotateBlock(world, x, y, z, ForgeDirection.getOrientation(side))) { - int metadata = world.getBlockMetadata(x, y, z); - - int[] rotationMatrix = { 1, 2, 3, 4, 5, 0 }; - - if (blockID == Block.furnaceIdle.blockID || blockID == Block.furnaceBurning.blockID) - { - rotationMatrix = ForgeDirection.ROTATION_MATRIX[0]; - } - - world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.getOrientation(rotationMatrix[metadata]).ordinal(), 3); - this.wrenchUsed(entityPlayer, x, y, z); - + this.wrenchUsed(player, x, y, z); return true; } - return false; }