Search in sources :

Example 1 with IDungeonKeyable

use of stevekung.mods.moreplanets.utils.items.IDungeonKeyable 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));
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityTreasureChestMP(stevekung.mods.moreplanets.utils.tileentity.TileEntityTreasureChestMP) ItemSpade(net.minecraft.item.ItemSpade) IDungeonKey(stevekung.mods.moreplanets.utils.items.IDungeonKey) IDungeonKeyable(stevekung.mods.moreplanets.utils.items.IDungeonKeyable) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemSpade (net.minecraft.item.ItemSpade)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 IDungeonKey (stevekung.mods.moreplanets.utils.items.IDungeonKey)1 IDungeonKeyable (stevekung.mods.moreplanets.utils.items.IDungeonKeyable)1 TileEntityTreasureChestMP (stevekung.mods.moreplanets.utils.tileentity.TileEntityTreasureChestMP)1