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

The following examples show how to use net.minecraftforge.event.entity.player.PlayerInteractEvent.Action. 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: 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 #2
Source File: ProtectionHandlers.java    From MyTown2 with The Unlicense 6 votes vote down vote up
@SubscribeEvent
public void onEntityInteract(EntityInteractEvent ev) {
    if(ev.entity.worldObj.isRemote || ev.isCanceled()) {
        return;
    }
    int x = (int) Math.floor(ev.target.posX);
    int y = (int) Math.floor(ev.target.posY);
    int z = (int) Math.floor(ev.target.posZ);

    Resident res = MyTownUniverse.instance.getOrMakeResident(ev.entityPlayer);
    ProtectionManager.checkInteraction(ev.target, res, ev);
    if(!ev.isCanceled() && ev.entityPlayer.getHeldItem() != null) {
        BlockPos bp = new BlockPos(x, y, z, ev.target.dimension);
        ProtectionManager.checkUsage(ev.entityPlayer.getHeldItem(), res, PlayerInteractEvent.Action.RIGHT_CLICK_AIR, bp, -1, ev);
    }
}
 
Example #3
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 #4
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 #5
Source File: ProtectionHandlers.java    From MyTown2 with The Unlicense 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onAE2PartPlace(AE2PartPlaceEvent ev) {
    if (ev.world.isRemote || ev.isCanceled()) {
        return;
    }

    Resident res = MyTownUniverse.instance.getOrMakeResident(ev.player);
    if(ev.player.getHeldItem() != null) {
        ProtectionManager.checkUsage(ev.player.getHeldItem(), res, Action.RIGHT_CLICK_BLOCK, new BlockPos(ev.x, ev.y, ev.z, ev.world.provider.dimensionId), ev.face, ev);
    }
}
 
Example #6
Source File: ProtectionHandlers.java    From MyTown2 with The Unlicense 5 votes vote down vote up
private BlockPos createBlockPos(PlayerInteractEvent ev) {
    int x, y, z;

    if (ev.action == PlayerInteractEvent.Action.RIGHT_CLICK_AIR) {
        x = (int) Math.floor(ev.entityPlayer.posX);
        y = (int) Math.floor(ev.entityPlayer.posY);
        z = (int) Math.floor(ev.entityPlayer.posZ);
    } else {
        x = ev.x;
        y = ev.y;
        z = ev.z;
    }
    return new BlockPos(x, y, z, ev.world.provider.dimensionId);
}
 
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: MainCommand.java    From mobycraft with Apache License 2.0 4 votes vote down vote up
@SubscribeEvent
public void containerWand(PlayerInteractEvent event) {
	EntityPlayer player = event.entityPlayer;

	if (!event.action.equals(Action.RIGHT_CLICK_BLOCK)
			&& !event.action.equals(Action.LEFT_CLICK_BLOCK)) {
		return;
	}

	if (player.getHeldItem() == null
			|| player.getHeldItem().getItem() != Mobycraft.container_wand) {
		return;
	}

	sender = player;
	World world = event.world;
	BlockPos pos = event.pos;

	if (world.getBlockState(pos).getBlock() != Blocks.wall_sign
			&& world.getBlockState(pos).getBlock() != Blocks.standing_sign) {
		return;
	}

	TileEntitySign sign = (TileEntitySign) world.getTileEntity(pos);

	if (!sign.signText[0].getUnformattedText().contains("Name:")) {
		return;
	}

	String name = sign.signText[1].getUnformattedText().concat(
			sign.signText[2].getUnformattedText().concat(
					sign.signText[3].getUnformattedText()));


	Container container = listCommands.getWithName(name);

	if (container == null) {
		return;
	}

	lifecycleCommands.removeContainer(container.getId());
	sendConfirmMessage("Removed container with name \"" + name + "\"");

	buildCommands.updateContainers(false);
}
 
Example #9
Source File: DroneAIBlockInteract.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
private boolean rightClick(ChunkPosition pos){
    int xCoord = pos.chunkPosX;
    int yCoord = pos.chunkPosY;
    int zCoord = pos.chunkPosZ;

    ForgeDirection faceDir = ProgWidgetPlace.getDirForSides(((ISidedWidget)widget).getSides());
    EntityPlayer player = drone.getFakePlayer();
    World worldObj = drone.getWorld();
    int dx = faceDir.offsetX;
    int dy = faceDir.offsetY;
    int dz = faceDir.offsetZ;
    int x = xCoord /*+ dx*/;
    int y = yCoord /*+ dy*/;
    int z = zCoord /*+ dz*/;

    player.setPosition(x + 0.5, y + 0.5 - player.eyeHeight, z + 0.5);
    player.rotationPitch = faceDir.offsetY * -90;
    switch(faceDir){
        case NORTH:
            player.rotationYaw = 180;
            break;
        case SOUTH:
            player.rotationYaw = 0;
            break;
        case WEST:
            player.rotationYaw = 90;
            break;
        case EAST:
            player.rotationYaw = -90;
    }

    try {
        PlayerInteractEvent event = ForgeEventFactory.onPlayerInteract(player, Action.RIGHT_CLICK_AIR, x, y, z, faceDir.ordinal(), worldObj);
        if(event.isCanceled()) return false;

        Block block = worldObj.getBlock(x, y, z);

        ItemStack stack = player.getCurrentEquippedItem();
        if(stack != null && stack.getItem().onItemUseFirst(stack, player, worldObj, x, y, z, faceDir.ordinal(), dx, dy, dz)) return false;

        if(!worldObj.isAirBlock(x, y, z) && block.onBlockActivated(worldObj, x, y, z, player, faceDir.ordinal(), dx, dy, dz)) return false;

        if(stack != null) {
            boolean isGoingToShift = false;
            if(stack.getItem() instanceof ItemReed || stack.getItem() instanceof ItemRedstone) {
                isGoingToShift = true;
            }
            int useX = isGoingToShift ? xCoord : x;
            int useY = isGoingToShift ? yCoord : y;
            int useZ = isGoingToShift ? zCoord : z;
            if(stack.getItem().onItemUse(stack, player, worldObj, useX, useY, useZ, faceDir.ordinal(), dx, dy, dz)) return false;

            ItemStack copy = stack.copy();
            player.setCurrentItemOrArmor(0, stack.getItem().onItemRightClick(stack, worldObj, player));
            if(!copy.isItemEqual(stack)) return true;
        }
        return false;
    } catch(Throwable e) {
        Log.error("DroneAIBlockInteract crashed! Stacktrace: ");
        e.printStackTrace();
        return false;
    }
}