Wrench can rotate buttons/levers only on sneak
This commit is contained in:
parent
bc08a47090
commit
5f0f47c327
1 changed files with 21 additions and 11 deletions
|
@ -4,34 +4,44 @@ import buildcraft.api.tools.IToolWrench;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockButton;
|
||||
import net.minecraft.block.BlockLever;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
public class ItemWrench extends ItemBuildCraft implements IToolWrench {
|
||||
|
||||
private final Set<Block> bannedRotations = new HashSet<Block>();
|
||||
|
||||
private final Set<Class<? extends Block>> shiftRotations = new HashSet<Class<? extends Block>>();
|
||||
|
||||
public ItemWrench(int i) {
|
||||
super(i);
|
||||
setFull3D();
|
||||
bannedRotations.add(Block.lever);
|
||||
bannedRotations.add(Block.stoneButton);
|
||||
bannedRotations.add(Block.woodenButton);
|
||||
shiftRotations.add(BlockLever.class);
|
||||
shiftRotations.add(BlockButton.class);
|
||||
}
|
||||
|
||||
private boolean isShiftRotation(Class<? extends Block> cls) {
|
||||
for (Class<? extends Block> shift : shiftRotations) {
|
||||
if (shift.isAssignableFrom(cls))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
|
||||
if(player.isSneaking())
|
||||
return false;
|
||||
|
||||
int blockId = world.getBlockId(x, y, z);
|
||||
Block block = Block.blocksList[blockId];
|
||||
if(bannedRotations.contains(block))
|
||||
return false;
|
||||
|
||||
if (block != null && block.rotateBlock(world, x, y, z, ForgeDirection.getOrientation(side))) {
|
||||
if(block == null)
|
||||
return false;
|
||||
|
||||
if (player.isSneaking() != isShiftRotation(block.getClass()))
|
||||
return false;
|
||||
|
||||
if (block.rotateBlock(world, x, y, z, ForgeDirection.getOrientation(side))) {
|
||||
player.swingItem();
|
||||
return !world.isRemote;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue