Skip to content
Permalink
Browse files

Only update transformer rotation with an empty hand.

  • Loading branch information...
Ri5ux Ri5ux
Ri5ux authored and Ri5ux committed Jul 15, 2019
1 parent bd221ca commit 36573b547802494b0c93b62c05bae2ea1475c101
Showing with 32 additions and 29 deletions.
  1. +32 −29 src/main/java/org/avp/block/BlockTransformer.java
@@ -10,34 +10,34 @@
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;


public class BlockTransformer extends Block
{
public BlockTransformer(Material material)
{
super(material);
this.setTickRandomly(true);
}

@Override
public boolean isOpaqueCube(IBlockState state)
{
return false;
}

@Override
public EnumBlockRenderType getRenderType(IBlockState state)
{
return EnumBlockRenderType.INVISIBLE;
}

@Override
public TileEntity createTileEntity(World world, IBlockState state)
{
@@ -49,54 +49,57 @@ public boolean hasTileEntity(IBlockState state)
{
return true;
}

@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
super.breakBlock(worldIn, pos, state);
worldIn.removeTileEntity(pos);
}

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
TileEntity te = world.getTileEntity(pos);

if (te != null && te instanceof TileEntityTransformer)
{
TileEntityTransformer transformer = (TileEntityTransformer) te;

ArrayList<EnumFacing> facing = new ArrayList<EnumFacing>();

for (EnumFacing dir : EnumFacing.VALUES)
if (playerIn.getHeldItemMainhand() == ItemStack.EMPTY)
{
if (dir != EnumFacing.UP && dir != EnumFacing.DOWN)
{
facing.add(dir);
}
}
TileEntityTransformer transformer = (TileEntityTransformer) te;

if (transformer.getRotationYAxis() != null)
{
int index = facing.indexOf(transformer.getRotationYAxis());
ArrayList<EnumFacing> facing = new ArrayList<EnumFacing>();

if (index + 1 >= facing.size())
for (EnumFacing dir : EnumFacing.VALUES)
{
index = -1;
if (dir != EnumFacing.UP && dir != EnumFacing.DOWN)
{
facing.add(dir);
}
}

if (facing.get(index + 1) != null)
if (transformer.getRotationYAxis() != null)
{
transformer.setRotationYAxis(facing.get(index + 1));
}
int index = facing.indexOf(transformer.getRotationYAxis());

if (!world.isRemote)
{
AliensVsPredator.network().sendToAll(new PacketRotateRotatable(transformer.getRotationYAxis().ordinal(), transformer.getPos().getX(), transformer.getPos().getY(), transformer.getPos().getZ()));
if (index + 1 >= facing.size())
{
index = -1;
}

if (facing.get(index + 1) != null)
{
transformer.setRotationYAxis(facing.get(index + 1));
}

if (!world.isRemote)
{
AliensVsPredator.network().sendToAll(new PacketRotateRotatable(transformer.getRotationYAxis().ordinal(), transformer.getPos().getX(), transformer.getPos().getY(), transformer.getPos().getZ()));
}
}
}

transformer.getUpdatePacket();
transformer.getUpdatePacket();
}
}
return super.onBlockActivated(world, pos, state, playerIn, hand, side, hitX, hitY, hitZ);
}

0 comments on commit 36573b5

Please sign in to comment.
You can’t perform that action at this time.