net.minecraftforge.event.entity.player.PlayerInteractEvent Java Examples

The following examples show how to use net.minecraftforge.event.entity.player.PlayerInteractEvent. 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: EventHandlerWorld.java    From Gadomancy with GNU Lesser General Public License v3.0 6 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
            && isStickyJar(e.entityPlayer.getHeldItem())) {
        if (interacts == null) {
            interacts = new HashMap<EntityPlayer, Integer>();
        }
        interacts.put(e.entityPlayer, e.face);
    }

    if (e.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) {
        ItemStack i = e.entityPlayer.getHeldItem();
        if (i != null && (i.getItem() instanceof ItemWandCasting)) {
            WandHandler.handleWandInteract(e.world, e.x, e.y, e.z, e.entityPlayer, i);
        }
    }
}
 
Example #2
Source File: TileEntityUniversalSensor.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
public void onEvent(Event event){
    ISensorSetting sensor = SensorHandler.instance().getSensorFromPath(sensorSetting);
    if(sensor != null && sensor instanceof IEventSensorSetting && getPressure(ForgeDirection.UNKNOWN) > PneumaticValues.MIN_PRESSURE_UNIVERSAL_SENSOR) {
        int newRedstoneStrength = ((IEventSensorSetting)sensor).emitRedstoneOnEvent(event, this, getRange(), sensorGuiText);
        if(newRedstoneStrength != 0) eventTimer = ((IEventSensorSetting)sensor).getRedstonePulseLength();
        if(invertedRedstone) newRedstoneStrength = 15 - newRedstoneStrength;
        if(eventTimer > 0 && ThirdPartyManager.computerCraftLoaded) {
            if(event instanceof PlayerInteractEvent) {
                PlayerInteractEvent e = (PlayerInteractEvent)event;
                notifyComputers(newRedstoneStrength, e.x, e.y, e.z);
            } else {
                notifyComputers(newRedstoneStrength);
            }
        }
        if(newRedstoneStrength != redstoneStrength) {
            redstoneStrength = newRedstoneStrength;
            updateNeighbours();
        }
    }
}
 
Example #3
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 #4
Source File: GrassPath.java    From Et-Futurum with The Unlicense 6 votes vote down vote up
public static void onPlayerInteract(PlayerInteractEvent event) {
	if (EtFuturum.enableGrassPath)
		if (event.entityPlayer != null) {
			World world = event.entityPlayer.worldObj;
			if (event.action == Action.RIGHT_CLICK_BLOCK)
				if (world.getBlock(event.x, event.y, event.z) == Blocks.grass) {
					ItemStack stack = event.entityPlayer.getCurrentEquippedItem();
					if (stack != null && (stack.getItem() instanceof ItemSpade || isTinkersShovel(stack))) {
						world.setBlock(event.x, event.y, event.z, ModBlocks.grass_path);
						event.entityPlayer.swingItem();
						stack.damageItem(1, event.entityPlayer);
						world.playSoundEffect(event.x + 0.5F, event.y + 0.5F, event.z + 0.5F, Block.soundTypeGravel.getStepResourcePath(), 1.0F, 0.8F);
					}
				}
		}
}
 
Example #5
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 #6
Source File: CoordTrackUpgradeHandler.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@SubscribeEvent
public boolean onPlayerInteract(PlayerInteractEvent event){
    if(event.action == Action.RIGHT_CLICK_BLOCK && isListeningToCoordTrackerSetting) {
        isListeningToCoordTrackerSetting = false;
        ForgeDirection dir = ForgeDirection.getOrientation(event.face);
        reset();
        ItemStack stack = event.entityPlayer.getCurrentArmor(3);
        if(stack != null) {
            NBTTagCompound tag = NBTUtil.getCompoundTag(stack, "CoordTracker");
            tag.setInteger("dimID", event.entity.worldObj.provider.dimensionId);
            tag.setInteger("x", event.x + dir.offsetX);
            tag.setInteger("y", event.y + dir.offsetY);
            tag.setInteger("z", event.z + dir.offsetZ);
        }
        NetworkHandler.sendToServer(new PacketCoordTrackUpdate(event.entity.worldObj, event.x + dir.offsetX, event.y + dir.offsetY, event.z + dir.offsetZ));
    }
    return false;
}
 
Example #7
Source File: ProtectionManager.java    From MyTown2 with The Unlicense 6 votes vote down vote up
public static void checkBlockInteraction(Resident res, BlockPos bp, PlayerInteractEvent.Action action, Event ev) {
    if(!ev.isCancelable()) {
        return;
    }

    World world = MinecraftServer.getServer().worldServerForDimension(bp.getDim());
    Block block = world.getBlock(bp.getX(), bp.getY(), bp.getZ());

    // Bypass for SellSign
    if (block instanceof BlockSign) {
        TileEntity te = world.getTileEntity(bp.getX(), bp.getY(), bp.getZ());
        if(te instanceof TileEntitySign && SellSign.SellSignType.instance.isTileValid((TileEntitySign) te)) {
            return;
        }
    }

    for(SegmentBlock segment : segmentsBlock.get(block.getClass())) {
        if(!segment.shouldInteract(res, bp, action)) {
            ev.setCanceled(true);
        }
    }
}
 
Example #8
Source File: SegmentBlock.java    From MyTown2 with The Unlicense 6 votes vote down vote up
public boolean shouldInteract(Resident res, BlockPos bp, PlayerInteractEvent.Action action) {
    if(meta != -1 && meta != MinecraftServer.getServer().worldServerForDimension(bp.getDim()).getBlockMetadata(bp.getX(), bp.getY(), bp.getZ())) {
        return true;
    }

    if((action == PlayerInteractEvent.Action.LEFT_CLICK_BLOCK && !types.contains(BlockType.LEFT_CLICK)
            || action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK && !types.contains(BlockType.RIGHT_CLICK))
            && !types.contains(BlockType.ANY_CLICK)) {
        return true;
    }

    if (!hasPermissionAtLocation(res, bp.getDim(), bp.getX(), bp.getY(), bp.getZ())) {
        if(clientUpdate != null) {
            clientUpdate.send(bp, (EntityPlayerMP) res.getPlayer());
        }
        return false;
    }

    return true;
}
 
Example #9
Source File: ProtectionManager.java    From MyTown2 with The Unlicense 5 votes vote down vote up
public static void checkUsage(ItemStack stack, Resident res, PlayerInteractEvent.Action action, BlockPos bp, int face, Event ev) {
    if(!ev.isCancelable()) {
        return;
    }

    for(SegmentItem segment : segmentsItem.get(stack.getItem().getClass())) {
        if(!segment.shouldInteract(stack, res, action, bp, face)) {
            ev.setCanceled(true);
        }
    }
}
 
Example #10
Source File: HandlerEvents.java    From burlapcraft with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void placeBlockEvent(PlayerInteractEvent event) {
	EntityPlayer p = event.entityPlayer;
    if(event.action == Action.RIGHT_CLICK_BLOCK) {
    	Block clickedBlock = HelperActions.getBlock(event.x, event.y, event.z);
    	if (HelperActions.blockIsOneOf(clickedBlock, HelperActions.unbreakableBlocks) && event.y < p.posY) {
    		List<HelperPos> blockPoss = new ArrayList<HelperPos>();
    		blockPoss.add(new HelperPos(event.x, event.y + 1, event.z));
    		blockPoss.add(new HelperPos(event.x, event.y, event.z + 1));
    		blockPoss.add(new HelperPos(event.x, event.y, event.z - 1));
    		blockPoss.add(new HelperPos(event.x + 1, event.y, event.z));
    		blockPoss.add(new HelperPos(event.x - 1, event.y, event.z));
    		
    		for (HelperPos pos : blockPoss) {
    			String key = pos.x + "," + pos.y + "," + pos.z;
    			if (HelperActions.blockIsOneOf(HelperActions.getBlock(pos), HelperActions.mineableBlocks) && 
    					!MinecraftStateGeneratorHelper.blockNameMap.containsKey(key)) {
    				int blockID = HelperActions.getBlockId(pos.x, pos.y, pos.z);
    				ArrayList<String> blockNames = MinecraftStateGeneratorHelper.invBlockNameMap.get(blockID);
    				if (blockNames != null && blockNames.size() == 1) {
    					MinecraftStateGeneratorHelper.blockNameMap.put(key, blockNames.get(0));
    					MinecraftStateGeneratorHelper.invBlockNameMap.remove(blockID);
    				}
    				else {
						if(blockNames != null) {
							MinecraftStateGeneratorHelper.blockNameMap.put(key, blockNames.get(0));
							blockNames.remove(0);
						}
    				}
    				break;
    			}
    		}
    	}
    }
}
 
Example #11
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 #12
Source File: PlanetEventHandler.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@SubscribeEvent
public void blockPlaceEvent(RightClickBlock event) {
	EnumFacing direction = event.getFace();
	if(!event.getWorld().isRemote && direction != null  && event.getEntityPlayer() != null  && AtmosphereHandler.getOxygenHandler(event.getWorld().provider.getDimension()) != null &&
			!AtmosphereHandler.getOxygenHandler(event.getWorld().provider.getDimension()).getAtmosphereType(event.getPos().offset(direction)).allowsCombustion()) {

		if(event.getEntityPlayer().getHeldItem(event.getHand()) != null) {
			if(event.getEntityPlayer().getHeldItem(event.getHand()).getItem() == Item.getItemFromBlock(Blocks.TORCH) && 
					event.getWorld().getBlockState(event.getPos()).isSideSolid(event.getWorld(), event.getPos(), direction)) {
				event.setCanceled(true);
				event.getWorld().setBlockState(event.getPos().offset(direction), AdvancedRocketryBlocks.blockUnlitTorch.getDefaultState().withProperty(BlockTorch.FACING, direction));
			}
			else if(zmaster587.advancedRocketry.api.Configuration.torchBlocks.contains(Block.getBlockFromItem(event.getEntityPlayer().getHeldItem(event.getHand()).getItem())) )
				event.setCanceled(true);
			else if(event.getEntityPlayer().getHeldItem(event.getHand()).getItem() == Items.FLINT_AND_STEEL || event.getEntityPlayer().getHeldItem(event.getHand()).getItem() == Items.FIRE_CHARGE|| event.getEntityPlayer().getHeldItem(event.getHand()).getItem() == Items.BLAZE_POWDER || event.getEntityPlayer().getHeldItem(event.getHand()).getItem() == Items.BLAZE_ROD || event.getEntityPlayer().getHeldItem(event.getHand()).getItem() == Items.LAVA_BUCKET)
				event.setCanceled(true);
		}
	}

	if(!event.getWorld().isRemote && event.getItemStack() != null && event instanceof PlayerInteractEvent.RightClickBlock && event.getItemStack().getItem() == Items.BED && event.getWorld().provider instanceof WorldProviderPlanet) {
		AdvancedRocketryItems.itemAstroBed.onItemUse( event.getEntityPlayer(),  event.getEntityPlayer().world, event.getPos(), event.getHand(), event.getFace(), 0, 0, 0);
		event.setCanceled(true);
	}

	if(!event.getWorld().isRemote && event.getItemStack() != null && event.getItemStack().getItem() == Item.getItemFromBlock(AdvancedRocketryBlocks.blockGenericSeat) && event.getWorld().getBlockState(event.getPos()).getBlock() == Blocks.TNT) {
		ARAchivements.BEER.trigger((EntityPlayerMP) event.getEntityPlayer());
	}
}
 
Example #13
Source File: DrinkWaterHandler.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void onRightClick(PlayerInteractEvent.RightClickBlock event)
{
	if(event.getSide() == Side.CLIENT)
	{
		/*if(event.getHitVec() == null || event.getItemStack() != null)
		{
			return;
		}
		BlockPos blockpos = event.getPos().offset(event.getFace());
		IBlockState state = event.getWorld().getBlockState(blockpos);
		if(state.getBlock() == Blocks.WATER && Core.isFreshWater(event.getWorld(), blockpos))
		{
			Minecraft.getMinecraft().playerController.processRightClickBlock((EntityPlayerSP)event.getEntityPlayer(), 
					(WorldClient)event.getWorld(), event.getItemStack(), blockpos, event.getFace(), event.getHitVec(), event.getHand());
		}*/
	}
	else
	{
		BlockPos blockpos = event.getPos().offset(event.getFace());
		IBlockState state = event.getWorld().getBlockState(blockpos);
		if((state.getBlock() == Blocks.WATER || state.getBlock() == Blocks.FLOWING_WATER) && Core.isFreshWater(event.getWorld(), blockpos))
		{
			if(event.getEntityPlayer().getHeldItem(event.getHand()) == ItemStack.EMPTY)
			{
				IFoodStatsTFC food = (IFoodStatsTFC)event.getEntityPlayer().getFoodStats();
				food.setWaterLevel((Math.min(food.getWaterLevel()+0.1f, 20)));
				TFC.network.sendTo(new CFoodPacket(food), (EntityPlayerMP) event.getEntityPlayer());
			}
			else if(ItemPotteryJug.IsCeramicJug(event.getEntityPlayer().getHeldItem(event.getHand())))
			{
				event.getEntityPlayer().getHeldItem(event.getHand()).setItemDamage(2);
			}
		}
	}
}
 
Example #14
Source File: PlayerInteractEventHandler.java    From AgriCraft with MIT License 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void waterPadCreation(PlayerInteractEvent.RightClickBlock event) {
    // Fetch held item.
    final ItemStack stack = event.getItemStack();

    // Check if holding shovel.
    if (!StackHelper.isValid(stack, ItemSpade.class)) {
        return;
    }

    // Fetch world information.
    final BlockPos pos = event.getPos();
    final World world = event.getWorld();
    final IBlockState state = world.getBlockState(pos);

    // Fetch the block at the location.
    final Block block = state.getBlock();

    // Test that clicked block was farmland.
    if (block != Blocks.FARMLAND) {
        return;
    }

    // Deny the event.
    event.setUseBlock(Event.Result.DENY);
    event.setUseItem(Event.Result.DENY);
    event.setResult(Event.Result.DENY);

    // If we are on the client side we are done.
    if (event.getSide().isClient()) {
        return;
    }

    // Fetch the player.
    final EntityPlayer player = event.getEntityPlayer();

    // Create the new block on the server side.
    world.setBlockState(pos, AgriBlocks.getInstance().WATER_PAD.getDefaultState(), 3);

    // Damage player's tool if not in creative.
    if (!player.capabilities.isCreativeMode) {
        stack.damageItem(1, player);
    }
}
 
Example #15
Source File: PlayerInteractEventHandler.java    From AgriCraft with MIT License 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void applyVinesToGrate(PlayerInteractEvent.RightClickBlock event) {
    // Fetch the ItemStack
    final ItemStack stack = event.getItemStack();

    // If the stack is null, or otherwise invalid, who cares?
    if (!StackHelper.isValid(stack)) {
        return;
    }

    // If the player is not holding a stack of vines, who cares?
    if (stack.getItem() != Item.getItemFromBlock(Blocks.VINE)) {
        return;
    }

    // Fetch world information.
    final BlockPos pos = event.getPos();
    final World world = event.getWorld();
    final IBlockState state = world.getBlockState(pos);

    // Fetch the block at the location.
    final Block block = state.getBlock();

    // If the player isn't clicking a grate, who cares?
    if (!(block instanceof BlockGrate)) {
        return;
    }

    // The player is trying to place vines! Scandalous!
    // We better deny the event!
    event.setUseItem(Event.Result.DENY);
}
 
Example #16
Source File: PlayerInteractEventHandler.java    From AgriCraft with MIT License 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void denyBonemeal(PlayerInteractEvent.RightClickBlock event) {
    if (!event.getEntityPlayer().isSneaking()) {
        return;
    }
    ItemStack heldItem = event.getEntityPlayer().getActiveItemStack();
    if (!heldItem.isEmpty() && heldItem.getItem() == Items.DYE && heldItem.getItemDamage() == 15) {
        TileEntity te = event.getWorld().getTileEntity(event.getPos());
        if (te != null && (te instanceof TileEntityCrop)) {
            event.setUseItem(Event.Result.DENY);
        }
    }
}
 
Example #17
Source File: PlayerEventHandler.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void onRightClickAir(PlayerInteractEvent.RightClickItem event)
{
    if (event.getSide() == Side.CLIENT)
    {
        ItemStack stack = EntityUtils.getHeldItemOfType(event.getEntityPlayer(), EnderUtilitiesItems.BUILDERS_WAND);

        if (stack.isEmpty() == false && EnderUtilities.proxy.isControlKeyDown())
        {
            PacketHandler.INSTANCE.sendToServer(new MessageKeyPressed(HotKeys.KEYCODE_CUSTOM_1));
        }
    }
}
 
Example #18
Source File: NewAnvil.java    From Et-Futurum with The Unlicense 5 votes vote down vote up
public static void onPlayerInteract(PlayerInteractEvent event) {
	if (!EtFuturum.enableAnvil)
		return;

	World world = event.world;
	int x = event.x;
	int y = event.y;
	int z = event.z;

	if (world == null || world.isRemote)
		return;
	if (world.getBlock(x, y, z) == Blocks.anvil)
		world.setBlock(x, y, z, ModBlocks.anvil, world.getBlockMetadata(x, y, z), 3);
}
 
Example #19
Source File: ProxyCommon.java    From WearableBackpacks with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onPlayerInteractBlock(PlayerInteractEvent.RightClickBlock event) {

	// This event is fired twice, once for each hand. Unfortunately there
	// is no way to set the result of the main hand interaction to SUCCESS
	// so the off hand one will be skipped. So: Hacky code!

	if (cancelOffHand) {
		cancelOffHand = false;
		if (event.getHand() == EnumHand.OFF_HAND)
			{ event.setCanceled(true); return; }
	}

	// When players sneak-right-click the ground with an
	// empty hand, place down their equipped backpack.

	EntityPlayer player = event.getEntityPlayer();
	World world = event.getWorld();
	if (!player.isSneaking() || (event.getHand() != EnumHand.MAIN_HAND) ||
	    !player.getHeldItem(EnumHand.MAIN_HAND).isEmpty()) return;

	IBackpack backpack = BackpackHelper.getBackpack(player);
	if (backpack == null) return;

	// Try place the equipped backpack on the ground by using it. Also takes
	// care of setting the tile entity stack and data as well as unequipping.
	// See ItemBackpack.onItemUse.
	player.inventory.mainInventory.set(player.inventory.currentItem, backpack.getStack());
	if (backpack.getStack().onItemUse(
			player, world, event.getPos(), EnumHand.MAIN_HAND,
			event.getFace(), 0.5F, 0.5F, 0.5F) == EnumActionResult.SUCCESS) {

		player.swingArm(EnumHand.MAIN_HAND);
		event.setCanceled(true);
		cancelOffHand = true;

	} else player.inventory.mainInventory.set(player.inventory.currentItem, ItemStack.EMPTY);

}
 
Example #20
Source File: ProxyCommon.java    From WearableBackpacks with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onEntityInteract(PlayerInteractEvent.EntityInteract event) {

	// When players right-click equipped backpacks, interact with them.

	if (!WearableBackpacks.CONFIG.enableEquippedInteraction.get() ||
	    !(event.getTarget() instanceof EntityLivingBase)) return;
	EntityPlayer player = event.getEntityPlayer();
	EntityLivingBase target = (EntityLivingBase)event.getTarget();

	BackpackCapability backpack = (BackpackCapability)target.getCapability(IBackpack.CAPABILITY, null);
	if ((backpack == null) || !BackpackHelper.canInteractWithEquippedBackpack(player, target)) return;

	IBackpackType type = backpack.getType();
	if (type == null) {
		WearableBackpacks.LOG.error("Backpack type was null when accessing equipped backpack");
		return;
	}
	if (!player.world.isRemote && (backpack.getData() == null)) {
		IBackpackData data = type.createBackpackData(backpack.getStack());
		if (data != null) {
			// Only show this error message if the backpack type is supposed to have backpack data.
			// Some backpacks might not need any to function, for example an ender backpack.
			WearableBackpacks.LOG.error("Backpack data was null when accessing equipped backpack");
			backpack.setData(data);
		}
	}
	type.onEquippedInteract(player, target, backpack);

}
 
Example #21
Source File: DyeWashingHandler.java    From WearableBackpacks with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onPlayerInteractBlock(PlayerInteractEvent.RightClickBlock event) {
	
	if (event.getWorld().isRemote ||
	    event.getEntityPlayer().isSneaking()) return;
	
	// Check if item is washable and currently dyed.
	ItemStack stack = event.getItemStack();
	if (!(stack.getItem() instanceof IDyeableItem) ||
	    !((IDyeableItem)stack.getItem()).canWash(stack) ||
	    !NbtUtils.has(stack, "display", "color")) return;
	
	// Check if block is a cauldron.
	IBlockState state = event.getWorld().getBlockState(event.getPos());
	if (!(state.getBlock() instanceof BlockCauldron)) return;
	BlockCauldron block = (BlockCauldron)state.getBlock();
	
	// Check if water is in the cauldron.
	int level = state.getValue(BlockCauldron.LEVEL);
	if (level <= 0) return;
	
	// Remove the color from the item!
	NbtUtils.remove(stack, "display", "color");
	// Use up some water from the cauldron!
	block.setWaterLevel(event.getWorld(), event.getPos(), state, level - 1);
	// Increase "armor cleaned" statistic! Wheee!
	event.getEntityPlayer().addStat(StatList.ARMOR_CLEANED);
	
	// Cancel the event, as the item / cauldron was used.
	event.setCanceled(true);
	
}
 
Example #22
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 #23
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 #24
Source File: BlockInteractSensor.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int emitRedstoneOnEvent(Event event, TileEntity sensor, int range, Set<ChunkPosition> positions){
    if(event instanceof PlayerInteractEvent) {
        PlayerInteractEvent interactEvent = (PlayerInteractEvent)event;
        return positions.contains(new ChunkPosition(interactEvent.x, interactEvent.y, interactEvent.z)) ? 15 : 0;
    }
    return 0;
}
 
Example #25
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);
                }
            }
        }
    }
}
 
Example #26
Source File: ServerEventHandler.java    From HoloInventory with MIT License 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onRightClick(PlayerInteractEvent.RightClickBlock event)
{
    if (catchNext == Type.NONE) return;
    boolean ban = catchNext == Type.BAN;
    catchNext = Type.NONE;
    event.setCanceled(true);

    TileEntity te = event.getWorld().getTileEntity(event.getPos());

    if (te == null)
    {
        event.getEntityPlayer().sendMessage(new TextComponentString("That block does not have a TileEntity.").setStyle(new Style().setColor(TextFormatting.RED)));
        return;
    }

    if (ban)
    {
        if (Helper.banned.add(te.getClass().getCanonicalName()))
            event.getEntityPlayer().sendMessage(new TextComponentString("Banned " + te.getClass().getCanonicalName()).setStyle(new Style().setColor(TextFormatting.GREEN)));
        else
            event.getEntityPlayer().sendMessage(new TextComponentString(te.getClass().getCanonicalName() + " is already banned.").setStyle(new Style().setColor(TextFormatting.RED)));
    }
    else
    {
        boolean wasBanned = Helper.banned.remove(te.getClass().getCanonicalName());
        if (wasBanned)
            event.getEntityPlayer().sendMessage(new TextComponentString("Unbanned " + te.getClass().getCanonicalName()).setStyle(new Style().setColor(TextFormatting.GREEN)));
        else
            event.getEntityPlayer().sendMessage(new TextComponentString(te.getClass().getCanonicalName() + " is not banned. Perhaps it is banned on the " + (FMLCommonHandler.instance().getSide().isClient() ? "server" : "client") + "?").setStyle(new Style().setColor(TextFormatting.RED)));
    }

    HoloInventory.getInstance().saveBanned();
}
 
Example #27
Source File: ArtifactServerEventHandler.java    From Artifacts with MIT License 5 votes vote down vote up
@SubscribeEvent
public void interactEvent(PlayerInteractEvent event) {
	World world = event.entityPlayer.worldObj;
	if(!world.isRemote) {
		if(world.getBlock(event.x, event.y, event.z) == Blocks.enchanting_table) {
			ArtifactTickHandler.instance.readyTickHandler(world, event.entityPlayer);
		}
	}
}
 
Example #28
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 #29
Source File: WillsAssortedThingsEventHandler.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SubscribeEvent
public static void onPlayerRightClick(PlayerInteractEvent.EntityInteract event) {
    EntityPlayer player = event.getEntityPlayer();
    if (event.getEntityPlayer().getHeldItemMainhand().getItem() == Items.ARROW) {
        if (event.getTarget() instanceof EntityChicken) {
            event.getWorld().playSound(player.posX, player.posY, player.posZ, SoundEvents.ENTITY_CHICKEN_HURT, SoundCategory.VOICE, 2.0f, 1.3f, false);
            player.getHeldItemMainhand().setCount(player.getHeldItemMainhand().getCount()-1);
            player.inventory.addItemStackToInventory(new ItemStack(ModItems.CHICKEN_ARROW));
        }
    }
}
 
Example #30
Source File: ModGenuinePeoplePersonalities.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void onBlockHit(PlayerInteractEvent.LeftClickBlock event) {
    EventData data = new EventData(event);
    if (data.getPlayer() == null || data.getPlayer().world.isRemote) return;
    if (data.getHand() != EnumHand.MAIN_HAND) return;
    if (!testCooldown(data.getPlayer())) return;
    if (generateComplaint(StringType.ATTACK, data.getPlayer(), data.getBlock(), data)) {
        resetCooldown(data.getPlayer());
    }
}