Search in sources :

Example 1 with BlockSilverfish

use of net.minecraft.block.BlockSilverfish in project minecolonies by Minecolonies.

the class EventHandler method onPlayerInteract.

/**
     * Event when a player right clicks a block, or right clicks with an item.
     * Event gets cancelled when player has no permission. Event gets cancelled
     * when the player has no permission to place a hut, and tried it.
     *
     * @param event {@link PlayerInteractEvent.RightClickBlock}
     */
@SubscribeEvent
public void onPlayerInteract(@NotNull final PlayerInteractEvent.RightClickBlock event) {
    final EntityPlayer player = event.getEntityPlayer();
    final World world = event.getWorld();
    //Only execute for the main hand our colony events.
    if (event.getHand() == EnumHand.MAIN_HAND && !(event.getWorld().isRemote)) {
        // and uses that return value, but I didn't want to call it twice
        if (playerRightClickInteract(player, world, event.getPos()) && world.getBlockState(event.getPos()).getBlock() instanceof AbstractBlockHut) {
            final IColony colony = ColonyManager.getIColony(world, event.getPos());
            if (colony != null && !colony.getPermissions().hasPermission(player, Action.ACCESS_HUTS)) {
                event.setCanceled(true);
            }
            return;
        } else if (event.getEntityPlayer() != null && "pmardle".equalsIgnoreCase(event.getEntityPlayer().getName()) && event.getItemStack() != null && Block.getBlockFromItem(event.getItemStack().getItem()) instanceof BlockSilverfish) {
            LanguageHandler.sendPlayerMessage(event.getEntityPlayer(), "Stop that you twat!!!");
            event.setCanceled(true);
        }
        if (player.getHeldItemMainhand() == null || player.getHeldItemMainhand().getItem() == null) {
            return;
        }
        handleEventCancellation(event, player);
    }
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) IColony(com.minecolonies.coremod.colony.IColony) BlockSilverfish(net.minecraft.block.BlockSilverfish) World(net.minecraft.world.World) AbstractBlockHut(com.minecolonies.coremod.blocks.AbstractBlockHut) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

AbstractBlockHut (com.minecolonies.coremod.blocks.AbstractBlockHut)1 IColony (com.minecolonies.coremod.colony.IColony)1 BlockSilverfish (net.minecraft.block.BlockSilverfish)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 World (net.minecraft.world.World)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1