Java Code Examples for net.minecraftforge.event.entity.player.PlayerInteractEvent#setCanceled()

The following examples show how to use net.minecraftforge.event.entity.player.PlayerInteractEvent#setCanceled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ForgeEventHandler.java    From NOVA-Core with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SubscribeEvent
public void playerInteractEvent(PlayerInteractEvent event) {
	if (event.getWorld() != null) {
		nova.core.event.PlayerEvent.Interact evt = new nova.core.event.PlayerEvent.Interact(
			WorldConverter.instance().toNova(event.getWorld()),
			VectorConverter.instance().toNova(event.getPos()),
			EntityConverter.instance().toNova(event.getEntityPlayer()),
			nova.core.event.PlayerEvent.Interact.Action.values()[toNovaInteractOrdinal(event)]
		);

		Game.events().publish(evt);

		if (event instanceof RightClickBlock) {
			((RightClickBlock)event).setUseBlock(Event.Result.values()[evt.useBlock.ordinal()]);
			((RightClickBlock)event).setUseItem(Event.Result.values()[evt.useItem.ordinal()]);
		} else if (event instanceof LeftClickBlock) {
			((LeftClickBlock)event).setUseBlock(Event.Result.values()[evt.useBlock.ordinal()]);
			((LeftClickBlock)event).setUseItem(Event.Result.values()[evt.useItem.ordinal()]);
		}
		if (event.isCancelable()) event.setCanceled(evt.isCanceled());
	}
}
 
Example 2
Source File: ForgeEventHandler.java    From NOVA-Core with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SubscribeEvent
public void playerInteractEvent(PlayerInteractEvent event) {
	if (event.world != null && event.pos != null) {
		nova.core.event.PlayerEvent.Interact evt = new nova.core.event.PlayerEvent.Interact(
			WorldConverter.instance().toNova(event.world),
			VectorConverter.instance().toNova(event.pos),
			EntityConverter.instance().toNova(event.entityPlayer),
			nova.core.event.PlayerEvent.Interact.Action.values()[event.action.ordinal()]
		);

		Game.events().publish(evt);

		event.useBlock = Event.Result.values()[evt.useBlock.ordinal()];
		event.useItem = Event.Result.values()[evt.useItem.ordinal()];
		event.setCanceled(evt.isCanceled());
	}
}
 
Example 3
Source File: PlayerListener.java    From SkyblockAddons with MIT License 5 votes vote down vote up
/**
 * This blocks interaction with Ember Rods on your island, to avoid blowing up chests, and placing enchanted items
 * such as enchanted gold blocks.
 */
@SubscribeEvent()
public void onInteract(PlayerInteractEvent e) {
    Minecraft mc = Minecraft.getMinecraft();
    ItemStack heldItem = e.entityPlayer.getHeldItem();

    if (main.getUtils().isOnSkyblock() && e.entityPlayer == mc.thePlayer && heldItem != null) {
        if (heldItem.getItem() == Items.skull) {
            Backpack backpack = BackpackManager.getFromItem(heldItem);
            if (backpack != null) {
                BackpackManager.setOpenedBackpackColor(backpack.getBackpackColor());
            }
        }

        // Update fishing status
        if (heldItem.getItem().equals(Items.fishing_rod)
                && (e.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK || e.action == PlayerInteractEvent.Action.RIGHT_CLICK_AIR)) {
            if (main.getConfigValues().isEnabled(Feature.FISHING_SOUND_INDICATOR)) {
                oldBobberIsInWater = false;
                lastBobberEnteredWater = Long.MAX_VALUE;
                oldBobberPosY = 0;
            }
            if (main.getConfigValues().isEnabled(Feature.SHOW_ITEM_COOLDOWNS) && mc.thePlayer.fishEntity != null) {
                CooldownManager.put(mc.thePlayer.getHeldItem());
            }
        } else if (EnchantedItemBlacklist.shouldBlockUsage(heldItem, e.action)) {
            e.setCanceled(true);
        }
    }
}
 
Example 4
Source File: BuildBattleDecoratorImplementation.java    From malmo with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onPlayerInteract(PlayerInteractEvent event)
{
    // Disallow creating or destroying events in the player structure:
    if (event instanceof PlayerInteractEvent.LeftClickBlock)
    {
        // Destroy block
        if (blockInBounds(event.getPos(), this.sourceBounds))
            event.setCanceled(true);
    }
    else if (event instanceof PlayerInteractEvent.RightClickBlock)
    {
        // Place block - need to work out *where* the block would be placed.
        // This code was cribbed from ItemBlock.onItemUse()
        IBlockState iblockstate = event.getWorld().getBlockState(event.getPos());
        Block block = iblockstate.getBlock();
        EnumFacing side = event.getFace();
        BlockPos pos = event.getPos();
        if (block == Blocks.SNOW_LAYER && ((Integer)iblockstate.getValue(BlockSnow.LAYERS)).intValue() < 1)
        {
            side = EnumFacing.UP;
        }
        else if (!block.isReplaceable(event.getWorld(), pos))
        {
            pos = pos.offset(side);
        }
        if (blockInBounds(pos, this.sourceBounds))
            event.setCanceled(true);
    }
}
 
Example 5
Source File: ForgeEventHandler.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void playerInteractEvent(PlayerInteractEvent event) {
	nova.core.event.PlayerEvent.Interact evt = new nova.core.event.PlayerEvent.Interact(
		WorldConverter.instance().toNova(event.world),
		new Vector3D(event.x, event.y, event.z),
		EntityConverter.instance().toNova(event.entityPlayer),
		nova.core.event.PlayerEvent.Interact.Action.values()[event.action.ordinal()]
	);

	Game.events().publish(evt);

	event.useBlock = Event.Result.values()[evt.useBlock.ordinal()];
	event.useItem = Event.Result.values()[evt.useItem.ordinal()];
	event.setCanceled(evt.isCanceled());
}
 
Example 6
Source File: EventHandlerGolem.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.LOWEST)
public void on(PlayerInteractEvent e) {
    if(!e.world.isRemote && e.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) {
        ItemStack itemInHand = e.entityPlayer.getHeldItem();
        if(itemInHand != null && (itemInHand.getItem() instanceof ItemGolemPlacer
                || itemInHand.getItem() instanceof ItemAdditionalGolemPlacer)) {
            int entityId = Entity.nextEntityID;
            if(itemInHand.getItem().onItemUseFirst(itemInHand, e.entityPlayer, e.world, e.x, e.y, e.z, e.face, 0, 0, 0)) {
                e.setCanceled(true);
                Entity entity = e.world.getEntityByID(entityId);
                if(entity != null && entity instanceof EntityGolemBase) {
                    EntityGolemBase golem = (EntityGolemBase) entity;

                    //move persistent data to entity
                    golem.getEntityData().setTag(Gadomancy.MODID, NBTHelper.getPersistentData(itemInHand).copy());

                    MinecraftForge.EVENT_BUS.post(new PlacerCreateGolemEvent(e.entityPlayer, golem, itemInHand));

                    ExtendedGolemProperties props = (ExtendedGolemProperties) golem.getExtendedProperties(Gadomancy.MODID);
                    if(props != null) {
                        props.updateGolemCore();
                        props.updateGolem();
                    }

                    //update runic shielding
                    if(RegisteredGolemStuff.upgradeRunicShield.hasUpgrade(golem)) {
                        RegisteredGolemStuff.upgradeRunicShield.getCharge(golem);
                    }
                }
            }
        }
    }
}
 
Example 7
Source File: FMPPlacementListener.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.LOW)
public void playerInteract(PlayerInteractEvent event){
    if(!Config.convertMultipartsToBlocks && event.action == Action.RIGHT_CLICK_BLOCK && event.entityPlayer.worldObj.isRemote) {
        if(placing.get() != null) return;//for mods that do dumb stuff and call this event like MFR
        placing.set(event);
        if(place(event.entityPlayer, event.entityPlayer.worldObj)) event.setCanceled(true);
        placing.set(null);
    }
}
 
Example 8
Source File: EventHandlerPneumaticCraft.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void onPlayerClick(PlayerInteractEvent event){
    Block interactedBlock = event.world.getBlock(event.x, event.y, event.z);
    if(!event.entityPlayer.capabilities.isCreativeMode || !event.entityPlayer.canCommandSenderUseCommand(2, "securityStation")) {
        if(event.action != PlayerInteractEvent.Action.RIGHT_CLICK_AIR && event.world != null && !event.world.isRemote) {
            if(interactedBlock != Blockss.securityStation || event.action == PlayerInteractEvent.Action.LEFT_CLICK_BLOCK) {
                ItemStack heldItem = event.entityPlayer.getCurrentEquippedItem();
                boolean tryingToPlaceSecurityStation = heldItem != null && heldItem.getItem() instanceof ItemBlock && ((ItemBlock)heldItem.getItem()).field_150939_a == Blockss.securityStation;
                int blockingStations = PneumaticCraftUtils.getProtectingSecurityStations(event.entity.worldObj, event.x, event.y, event.z, event.entityPlayer, true, tryingToPlaceSecurityStation);
                if(blockingStations > 0) {
                    event.setCanceled(true);
                    event.entityPlayer.addChatComponentMessage(new ChatComponentText(StatCollector.translateToLocalFormatted(tryingToPlaceSecurityStation ? "message.securityStation.stationPlacementPrevented" : "message.securityStation.accessPrevented", blockingStations)));
                }
            }
        }
    }

    /**
     * Due to some weird quirk that causes Block#onBlockActivated not getting called on the server when the player is sneaking, this is a workaround.
     */
    if(!event.isCanceled() && event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK && !event.world.isRemote) {
        if(event.entityPlayer.isSneaking() && (interactedBlock == Blockss.elevatorCaller || interactedBlock == Blockss.chargingStation)) {
            event.setCanceled(interactedBlock.onBlockActivated(event.world, event.x, event.y, event.z, event.entityPlayer, event.face, 0, 0, 0));
        } else if(event.entityPlayer.getCurrentEquippedItem() != null && ModInteractionUtilImplementation.getInstance().isModdedWrench(event.entityPlayer.getCurrentEquippedItem().getItem())) {
            if(interactedBlock instanceof IPneumaticWrenchable) {
                ((IPneumaticWrenchable)interactedBlock).rotateBlock(event.world, event.entityPlayer, event.x, event.y, event.z, ForgeDirection.getOrientation(event.face));
            }
        }
    }

    if(!event.isCanceled() && interactedBlock == Blocks.cobblestone) {
        AchievementHandler.checkFor9x9(event.entityPlayer, event.x, event.y, event.z);
    }
}
 
Example 9
Source File: SemiBlockManager.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void onInteraction(PlayerInteractEvent event){
    if(!event.world.isRemote && event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) {
        ItemStack curItem = event.entityPlayer.getCurrentEquippedItem();
        if(curItem != null && curItem.getItem() instanceof ISemiBlockItem) {
            if(getSemiBlock(event.world, event.x, event.y, event.z) != null) {
                if(event.entityPlayer.capabilities.isCreativeMode) {
                    setSemiBlock(event.world, event.x, event.y, event.z, null);
                } else {
                    breakSemiBlock(event.world, event.x, event.y, event.z, event.entityPlayer);
                }
                event.setCanceled(true);
            } else {
                ISemiBlock newBlock = ((ISemiBlockItem)curItem.getItem()).getSemiBlock(event.world, event.x, event.y, event.z, curItem);
                newBlock.initialize(event.world, new ChunkPosition(event.x, event.y, event.z));
                if(newBlock.canPlace()) {
                    setSemiBlock(event.world, event.x, event.y, event.z, newBlock);
                    newBlock.onPlaced(event.entityPlayer, curItem);
                    event.world.playSoundEffect(event.x + 0.5, event.y + 0.5, event.z + 0.5, Block.soundTypeGlass.func_150496_b(), (Block.soundTypeGlass.getVolume() + 1.0F) / 2.0F, Block.soundTypeGlass.getPitch() * 0.8F);
                    if(!event.entityPlayer.capabilities.isCreativeMode) {
                        curItem.stackSize--;
                        if(curItem.stackSize <= 0) event.entityPlayer.setCurrentItemOrArmor(0, null);
                    }
                    event.setCanceled(true);
                }
            }
        }
    }
}