use of lumien.randomthings.block.BlockContactButton in project Random-Things by lumien231.
the class RTEventHandler method playerInteract.
@SubscribeEvent
public void playerInteract(PlayerInteractEvent event) {
if (event instanceof RightClickBlock) {
ItemStack equipped = event.getEntityPlayer().getHeldItem(event.getHand());
if (!equipped.isEmpty() && equipped.getItem() instanceof ItemSpade) {
RightClickBlock rcEvent = (RightClickBlock) event;
IBlockState targetState = event.getWorld().getBlockState(event.getPos());
if (targetState.getBlock() == Blocks.SLIME_BLOCK) {
event.getEntityPlayer().swingArm(event.getHand());
if (!event.getWorld().isRemote) {
if (!event.getWorld().isRemote) {
event.getWorld().setBlockState(event.getPos(), ModBlocks.compressedSlimeBlock.getDefaultState());
event.getWorld().playSound(null, event.getPos().getX(), event.getPos().getY(), event.getPos().getZ(), Blocks.SLIME_BLOCK.getSoundType().getPlaceSound(), SoundCategory.PLAYERS, 1, 0.8f);
equipped.damageItem(1, event.getEntityPlayer());
}
}
} else if (targetState.getBlock() == ModBlocks.compressedSlimeBlock) {
int currentCompression = targetState.getValue(BlockCompressedSlimeBlock.COMPRESSION);
event.getEntityPlayer().swingArm(event.getHand());
if (!event.getWorld().isRemote) {
if (currentCompression < 2) {
rcEvent.getWorld().setBlockState(rcEvent.getPos(), targetState.withProperty(BlockCompressedSlimeBlock.COMPRESSION, currentCompression + 1));
event.getWorld().playSound(null, event.getPos().getX(), event.getPos().getY(), event.getPos().getZ(), Blocks.SLIME_BLOCK.getSoundType().getPlaceSound(), SoundCategory.PLAYERS, 1, 0.8f - ((currentCompression + 1) * 0.2f));
equipped.damageItem(1, event.getEntityPlayer());
}
}
}
}
if (!event.getWorld().isRemote && !equipped.isEmpty() && equipped.getItem() == Items.PAPER) {
RightClickBlock rcEvent = (RightClickBlock) event;
IBlockState targetState = event.getWorld().getBlockState(event.getPos());
if (targetState.getBlock() == ModBlocks.runeBase) {
TileEntityRuneBase te = (TileEntityRuneBase) event.getWorld().getTileEntity(rcEvent.getPos());
int[][] runeData = te.getRuneData();
int[] savedData = new int[16];
int counter = 0;
for (int y = 0; y < runeData[0].length; y++) {
for (int x = 0; x < runeData.length; x++) {
savedData[counter] = runeData[x][y];
counter++;
}
}
ItemStack patternStack = new ItemStack(ModItems.runePattern);
patternStack.setTagCompound(new NBTTagCompound());
patternStack.getTagCompound().setIntArray("runeData", savedData);
((RightClickBlock) event).setUseItem(Result.ALLOW);
if (equipped.getCount() == 1) {
int slot;
if (event.getHand() == EnumHand.MAIN_HAND) {
slot = event.getEntityPlayer().inventory.currentItem;
} else {
slot = 40;
}
event.getEntityPlayer().inventory.setInventorySlotContents(slot, patternStack);
} else {
equipped.shrink(1);
event.getEntityPlayer().inventory.addItemStackToInventory(patternStack);
}
}
}
if (!event.getWorld().isRemote && event.getHand() == EnumHand.MAIN_HAND) {
for (EnumFacing facing : EnumFacing.values()) {
BlockPos pos = event.getPos().offset(facing);
IBlockState state = event.getWorld().getBlockState(pos);
if (state.getBlock() == ModBlocks.contactButton) {
if (state.getValue(BlockContactButton.FACING).getOpposite() == facing) {
((BlockContactButton) state.getBlock()).activate(event.getWorld(), event.getPos().offset(facing), facing.getOpposite());
break;
}
} else if (state.getBlock() == ModBlocks.contactLever) {
if (state.getValue(BlockContactLever.FACING).getOpposite() == facing) {
((BlockContactLever) state.getBlock()).activate(event.getWorld(), event.getPos().offset(facing), facing.getOpposite());
break;
}
}
}
}
}
}
Aggregations