use of stevekung.mods.moreplanets.utils.items.IDungeonKey in project MorePlanets by SteveKunG.
the class GeneralEventHandler method onRightClickBlock.
@SubscribeEvent
public void onRightClickBlock(PlayerInteractEvent.RightClickBlock event) {
EntityPlayer player = event.getEntityPlayer();
World world = event.getWorld();
BlockPos pos = event.getPos();
ItemStack heldItem = event.getItemStack();
// Skip events triggered from Thaumcraft Golems and other non-players
if (player == null || pos == null || world == null) {
return;
}
if (!heldItem.isEmpty() && (heldItem.getItem() instanceof ItemSpade || heldItem.getItem().getToolClasses(heldItem) == Collections.singleton("shovel"))) {
if (event.getFace() != EnumFacing.DOWN && world.getBlockState(pos.up()).getMaterial() == Material.AIR) {
if (world.getBlockState(pos).getBlock() == MPBlocks.INFECTED_GRASS_BLOCK) {
if (!world.isRemote) {
world.playSound(null, pos, SoundEvents.ITEM_SHOVEL_FLATTEN, SoundCategory.BLOCKS, 1.0F, 1.0F);
world.setBlockState(pos, MPBlocks.INFECTED_GRASS_PATH.getDefaultState(), 11);
heldItem.damageItem(1, player);
}
player.swingArm(event.getHand());
} else if (world.getBlockState(pos).getBlock() == MPBlocks.GREEN_VEIN_GRASS_BLOCK) {
if (!world.isRemote) {
world.playSound(null, pos, SoundEvents.ITEM_SHOVEL_FLATTEN, SoundCategory.BLOCKS, 1.0F, 1.0F);
world.setBlockState(pos, MPBlocks.GREEN_VEIN_GRASS_PATH.getDefaultState(), 11);
heldItem.damageItem(1, player);
}
player.swingArm(event.getHand());
}
}
}
TileEntity tile = world.getTileEntity(pos);
if (tile != null && tile instanceof TileEntityTreasureChestMP && tile instanceof IDungeonKeyable) {
TileEntityTreasureChestMP chest = (TileEntityTreasureChestMP) tile;
IDungeonKeyable keyable = (IDungeonKeyable) tile;
if (chest.locked) {
if (!heldItem.isEmpty()) {
if (heldItem.getItem() instanceof IDungeonKey) {
event.setCanceled(keyable.onActivated(player, keyable.getDungeonKey(), true));
} else if (!player.isSneaking()) {
event.setCanceled(keyable.onActivated(player, keyable.getDungeonKey(), false));
}
} else {
event.setCanceled(keyable.onActivated(player, keyable.getDungeonKey(), false));
}
}
}
}
Aggregations