Toyed with wrench

This commit is contained in:
DarkGuardsman 2013-10-23 13:16:48 -04:00
parent c38354b890
commit e60a78b9e0
3 changed files with 86 additions and 65 deletions

View file

@ -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);
}
}

View file

@ -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);
}

View file

@ -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;
}