|
| 1 | +package gregtech.common.items.tool; |
| 2 | + |
| 3 | +import gregtech.api.items.toolitem.behavior.IToolBehavior; |
| 4 | +import gregtech.api.metatileentity.MetaTileEntityHolder; |
| 5 | +import net.minecraft.block.Block; |
| 6 | +import net.minecraft.block.BlockRailBase; |
| 7 | +import net.minecraft.entity.player.EntityPlayer; |
| 8 | +import net.minecraft.tileentity.TileEntity; |
| 9 | +import net.minecraft.util.EnumActionResult; |
| 10 | +import net.minecraft.util.EnumFacing; |
| 11 | +import net.minecraft.util.EnumHand; |
| 12 | +import net.minecraft.util.math.BlockPos; |
| 13 | +import net.minecraft.world.World; |
| 14 | +import net.minecraftforge.fml.common.FMLCommonHandler; |
| 15 | + |
| 16 | +public class BlockRotatingBehavior implements IToolBehavior { |
| 17 | + @Override |
| 18 | + public EnumActionResult onItemUseFirst(final EntityPlayer player, final World world, final BlockPos pos, final EnumFacing side, final float hitX, final float hitY, final float hitZ, final EnumHand hand) { |
| 19 | + TileEntity te = world.getTileEntity(pos); |
| 20 | + //MTEs have special handling on rotation |
| 21 | + if (te instanceof MetaTileEntityHolder) { |
| 22 | + return EnumActionResult.PASS; |
| 23 | + } |
| 24 | + final Block b = world.getBlockState(pos).getBlock(); |
| 25 | + //leave rail rotation to Crowbar only |
| 26 | + if (b instanceof BlockRailBase) { |
| 27 | + return EnumActionResult.FAIL; |
| 28 | + } |
| 29 | + if (!player.isSneaking() && world.canMineBlockBody(player, pos)) { |
| 30 | + if (FMLCommonHandler.instance().getEffectiveSide().isClient()) { |
| 31 | + return !world.isRemote ? EnumActionResult.SUCCESS : EnumActionResult.PASS; |
| 32 | + } |
| 33 | + |
| 34 | + if (b.rotateBlock(world, pos, side)) { |
| 35 | + player.swingArm(hand); |
| 36 | + return !world.isRemote ? EnumActionResult.SUCCESS : EnumActionResult.FAIL; |
| 37 | + } |
| 38 | + } |
| 39 | + return EnumActionResult.PASS; |
| 40 | + } |
| 41 | +} |
0 commit comments