当前位置: 首页>>代码示例>>Java>>正文


Java PlayerInteractEvent.isCanceled方法代码示例

本文整理汇总了Java中net.minecraftforge.event.entity.player.PlayerInteractEvent.isCanceled方法的典型用法代码示例。如果您正苦于以下问题:Java PlayerInteractEvent.isCanceled方法的具体用法?Java PlayerInteractEvent.isCanceled怎么用?Java PlayerInteractEvent.isCanceled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.minecraftforge.event.entity.player.PlayerInteractEvent的用法示例。


在下文中一共展示了PlayerInteractEvent.isCanceled方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: placeAnything

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
public void placeAnything(PlayerInteractEvent event)
{
    // Server side and on block only.
    if (event.isCanceled() || event.world.isRemote || event.action != RIGHT_CLICK_BLOCK) return;
    ItemStack heldItem = event.entityPlayer.inventory.getCurrentItem();
    // Only tools, not null
    if (heldItem == null || !(heldItem.getItem() instanceof ItemTool)) return;
    if (event.world.getTileEntity(event.x, event.y, event.z) != null) return;
    // old slot
    int oldSlot = event.entityPlayer.inventory.currentItem;
    // Avoid invalid array indexes
    if (oldSlot < 0 || oldSlot > 8) return;
    // new slot
    int newSlot = slots[oldSlot];
    // Avoid invalid slots indexes
    if (newSlot < 0 || newSlot > 8) return;
    // Get new item
    ItemStack slotStack = event.entityPlayer.inventory.getStackInSlot(newSlot);
    // No null please
    if (slotStack == null) return;
    // Set current slot to new slot to fool Minecraft
    event.entityPlayer.inventory.currentItem = newSlot;
    // Place block
    boolean b = ((EntityPlayerMP) event.entityPlayer).theItemInWorldManager.activateBlockOrUseItem(event.entityPlayer, event.world, slotStack, event.x, event.y, event.z, event.face, 0.5f, 0.5f, 0.5f);
    // Remove empty stacks
    if (slotStack.stackSize <= 0) slotStack = null;
    // Set old slot back properly
    event.entityPlayer.inventory.currentItem = oldSlot;
    // Update client
    event.entityPlayer.inventory.setInventorySlotContents(newSlot, slotStack);
    ((EntityPlayerMP) event.entityPlayer).playerNetServerHandler.sendPacket(new S2FPacketSetSlot(0, newSlot + 36, slotStack));
    // Prevent derpy doors
    event.setCanceled(true);
}
 
开发者ID:gigabit101,项目名称:Torchieeeeness,代码行数:35,代码来源:TorchEventHandler.java

示例2: onPlayerInteract

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void onPlayerInteract(PlayerInteractEvent event) {
	if (event.world.isRemote) {
		if (!event.isCanceled())
			if (event.entityPlayer.getCurrentEquippedItem() != null)
				if (event.entityPlayer.getCurrentEquippedItem().getItem() instanceof ITransmutationItem) {
					double posX = event.entityPlayer.posX;
					double posY = event.entityPlayer.posY + event.entityPlayer.getEyeHeight();
					double posZ = event.entityPlayer.posZ;
					double xIncr = -MathHelper.sin(event.entityPlayer.rotationYaw/180.0F*3.141593F) *
							MathHelper.cos(event.entityPlayer.rotationPitch/180.0F*3.141593F);
					double yIncr = -MathHelper.sin(event.entityPlayer.rotationPitch/180.0F*3.141593F);
					double zIncr = MathHelper.cos(event.entityPlayer.rotationYaw/180.0F*3.141593F) *
							MathHelper.cos(event.entityPlayer.rotationPitch/180.0F*3.141593F);
					for (int i = 0; i < 17; i++) {
						AxisAlignedBB boundingBox = AxisAlignedBB.getBoundingBox(posX-.5, posY-.5, posZ-.5, 
								posX+.5, posY+.5, posZ+.5);
						EntityItem entityItem = (EntityItem) event.world.findNearestEntityWithinAABB(EntityItem.class, boundingBox, event.entityPlayer);
						if (entityItem != null) {
							DartCraft2.NETWORK.sendToServer(new TransmutePacket(entityItem, event.entityPlayer));
							event.setCanceled(true);
							return;
						}
						posX += xIncr;
						posY += yIncr;
						posZ += zIncr;
					}
					if (event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) {
						DartCraft2.NETWORK.sendToServer(new TransmutePacket(event.world, event.x, event.y, event.z, event.entityPlayer));
						event.setCanceled(true);
					}
				}
	}
}
 
开发者ID:austinv11,项目名称:DartCraft2,代码行数:35,代码来源:TransmutationHandler.java

示例3: onPlayerInteract

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void onPlayerInteract(PlayerInteractEvent event) {
	if (!event.isCanceled())
		if (event.action == PlayerInteractEvent.Action.RIGHT_CLICK_AIR || event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK)
			if (event.useItem != Event.Result.DENY)
				if (event.entityPlayer.getCurrentEquippedItem() != null)
					if (event.entityPlayer.getCurrentEquippedItem().getItem() instanceof ItemPocketComputer)
						event.setCanceled(rightClick(event.world, event.entityPlayer, event.entityPlayer.getCurrentEquippedItem()));
}
 
开发者ID:austinv11,项目名称:PeripheralsPlusPlus,代码行数:10,代码来源:ComputerCraftHooks.java

示例4: onPlayerInteract

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void onPlayerInteract(PlayerInteractEvent event) {
	if (!Config.enableMotionDetector)
		return;
	if (computer == null)
		return;
	if (!event.isCanceled())
		if (event.entityPlayer.getCurrentEquippedItem() != null)
			if (event.entityPlayer.getCurrentEquippedItem().getItem() instanceof ItemPocketComputer)
				if (NBTHelper.hasTag(event.entityPlayer.getCurrentEquippedItem(), "upgrade")) {
					int upgrade = -1;
					if (NBTHelper.hasTag(event.entityPlayer.getCurrentEquippedItem(), "upgrades")) {
						NBTTagList list = NBTHelper.getList(event.entityPlayer.getCurrentEquippedItem(), "upgrades", Constants.NBT.TAG_FLOAT);
						for (int i = 0; i < list.tagCount(); i++)
							if ((int)list.func_150308_e(i) == Reference.MOTION_DETECTOR) {
								upgrade = (int) list.func_150308_e(i);
								break;
							}
					} else {
						upgrade = (int)NBTHelper.getShort(event.entityPlayer.getCurrentEquippedItem(), "upgrade");
					}
					if (upgrade == Reference.MOTION_DETECTOR) {
						if (event.action == PlayerInteractEvent.Action.LEFT_CLICK_BLOCK)
							computer.queueEvent("blockHit", new Object[0]);
						else
							computer.queueEvent("rightClick", new Object[0]);
					}
				}
}
 
开发者ID:austinv11,项目名称:PeripheralsPlusPlus,代码行数:30,代码来源:PeripheralMotionDetector.java

示例5: onPlayerTriesToStartFires

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void onPlayerTriesToStartFires(PlayerInteractEvent e) {
	if (e.action != PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK)
		return;
	if (e.entityPlayer.dimension == IaSFlags.dim_nyx_id && !e.entityPlayer.capabilities.isCreativeMode) {

		boolean flaque = false;
		if (e.entityPlayer.getEquipmentInSlot(0) == null)
			return;

		Object id = e.entityPlayer.getEquipmentInSlot(0).getItem();
		if (id == Items.flint_and_steel) {
			flaque = true;
		} else if (id == Items.fire_charge) {
			flaque = true;
		} else if (id instanceof ItemBlock) {
			id = ((ItemBlock) id).field_150939_a;
			if (id == Blocks.fire) {
				flaque = true;
			} else if (id == Blocks.torch) {
				flaque = true;
			}
		}

		// DO NOT SIMPLIFY!
		if (flaque && !e.isCanceled()) {
			e.setCanceled(true);
			if (id == Blocks.torch) {
				IaSPlayerHelper.messagePlayer(e.entityPlayer, "It's far too cold to light a torch in Nyx.");
			} else {
				IaSPlayerHelper.messagePlayer(e.entityPlayer, "It's far too cold to start a fire that way in Nyx.");
			}
		}
	}

}
 
开发者ID:TheDaemoness,项目名称:IceAndShadow2,代码行数:37,代码来源:NyxEventHandlerCold.java

示例6: onTryToPlant

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void onTryToPlant(PlayerInteractEvent e) {
	if (e.action != PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK)
		return;
	if (e.entity.dimension == IaSFlags.dim_nyx_id && !e.entityPlayer.capabilities.isCreativeMode) {
		boolean isplant = false;
		final ItemStack ite = e.entityPlayer.getEquipmentInSlot(0);
		if (ite == null)
			return;
		if (ite.getItem() instanceof IPlantable) {
			isplant = true;
		} else if (ite.getItem() instanceof ItemBlock)
			if (((ItemBlock) ite.getItem()).field_150939_a instanceof IPlantable) {
				isplant = true;
			}

		// DO NOT SIMPLIFY!
		if (isplant && !e.isCanceled()) {
			final boolean dirt = e.world.getBlock(e.x, e.y, e.z) == NyxBlocks.dirt;
			ForgeDirection.getOrientation(e.face);
			e.setCanceled(!dirt);
			if (!dirt) {
				IaSPlayerHelper.messagePlayer(e.entityPlayer, "There's no way that this will grow in this realm.");
			}
		}
	}
}
 
开发者ID:TheDaemoness,项目名称:IceAndShadow2,代码行数:28,代码来源:NyxEventHandlerCold.java

示例7: onPlayerClick

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@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);
    }
}
 
开发者ID:MineMaarten,项目名称:PneumaticCraft,代码行数:35,代码来源:EventHandlerPneumaticCraft.java

示例8: onPlayerClick

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
    public void onPlayerClick(PlayerInteractEvent event) {
        if (event instanceof PlayerInteractEvent.RightClickEmpty) return;

        ItemStack heldItem = event.getEntityPlayer().getHeldItem(event.getHand());

        IBlockState interactedBlockState = event.getWorld().getBlockState(event.getPos());
        Block interactedBlock = interactedBlockState.getBlock();
        if (!event.getEntityPlayer().capabilities.isCreativeMode || !event.getEntityPlayer().canUseCommand(2, "securityStation")) {
            if (event.getWorld() != null && !event.getWorld().isRemote) {
                if (interactedBlock != Blockss.SECURITY_STATION || event instanceof PlayerInteractEvent.LeftClickBlock) {
                    boolean tryingToPlaceSecurityStation = heldItem.getItem() instanceof ItemBlock && ((ItemBlock) heldItem.getItem()).getBlock() == Blockss.SECURITY_STATION;
                    int blockingStations = PneumaticCraftUtils.getProtectingSecurityStations(event.getWorld(), event.getPos(), event.getEntityPlayer(), true, tryingToPlaceSecurityStation);
                    if (blockingStations > 0) {
                        event.setCanceled(true);
                        event.getEntityPlayer().sendStatusMessage(
                                new TextComponentTranslation(
                                        tryingToPlaceSecurityStation ? "message.securityStation.stationPlacementPrevented" : "message.securityStation.accessPrevented",
                                        blockingStations), false);
                    }
                }
            }
        }

        if (!event.isCanceled() && event instanceof PlayerInteractEvent.RightClickBlock && !event.getWorld().isRemote) {
            if (event.getEntityPlayer().isSneaking() && (interactedBlock == Blockss.ELEVATOR_CALLER || interactedBlock == Blockss.CHARGING_STATION)) {
                // work around the fact that Block#onBlockActivated doesn't get called server-side when sneaking
                event.setCanceled(interactedBlock.onBlockActivated(event.getWorld(), event.getPos(), interactedBlockState, event.getEntityPlayer(), event.getHand(), event.getFace(), 0, 0, 0));
            } else if (ModInteractionUtilImplementation.getInstance().isModdedWrench(heldItem)) {
                // when player clicks with a modded wrench, enforce our rotation behaviour and cancel default behaviour
                // (which is probably to call the "vanilla" rotateBlock(), which doesn't get any player information)
                if (interactedBlock instanceof IPneumaticWrenchable) {
                    ((IPneumaticWrenchable) interactedBlock).rotateBlock(event.getWorld(), event.getEntityPlayer(), event.getPos(), event.getFace());
                    event.setCanceled(true);
                }
            }
        }

//        if (!event.isCanceled() && interactedBlock == Blocks.COBBLESTONE) {
//            AdvancementUtils.checkFor9x9(event.getEntityPlayer(), event.getPos());
//        }
    }
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:43,代码来源:EventHandlerPneumaticCraft.java

示例9: attack

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void attack(final PlayerInteractEvent event) {
    if (event.action != PlayerInteractEvent.Action.LEFT_CLICK_BLOCK) {
        return;
    }
    final EntityPlayer player = event.entityPlayer;
    if (event.world == null || event.world.isRemote) {
        return;
    }
    if (player == null || !(player instanceof EntityPlayerMP)) {
        return;
    }
    final ItemStack heldItem = player.getHeldItem();
    if (heldItem == null || heldItem.getItem() != this) {
        return;
    }
    if (heldItem.getItemDamage() == 32767) {
        heldItem.stackSize = 0;
        return;
    }
    final int i = player.inventory.currentItem;
    if (i >= 9 || i < 0) {
        return;
    }
    event.setCanceled(true);
    final ItemStack item = heldItem.copy();
    heldItem.setItemDamage(32767);
    player.inventory.setInventorySlotContents(i, (ItemStack)null);
    final int x = event.x;
    final int y = event.y;
    final int z = event.z;
    final int side = event.face;
    try {
        final PlayerInteractEvent e = ForgeEventFactory.onPlayerInteract(player, PlayerInteractEvent.Action.LEFT_CLICK_BLOCK, x, y, z, side, player.worldObj);
        final boolean result = !e.isCanceled() && event.useBlock != Event.Result.DENY;
        if (result) {
            final Block block = event.world.getBlock(x, y, z);
            block.onBlockClicked(event.world, x, y, z, player);
        }
    }
    catch (Exception err) {
        for (int j = 0; j < player.inventory.getSizeInventory(); ++j) {
            final ItemStack stackInSlot = player.inventory.getStackInSlot(i);
            if (stackInSlot != null) {
                if (stackInSlot.getItem() == this) {
                    if (stackInSlot.getItemDamage() == 32767) {
                        player.inventory.setInventorySlotContents(j, (ItemStack)null);
                    }
                }
            }
        }
        if (player.inventory.getStackInSlot(i) == null) {
            player.inventory.setInventorySlotContents(i, item);
        }
        else if (!player.inventory.addItemStackToInventory(item)) {
            player.dropPlayerItemWithRandomChoice(item, false);
        }
        throw Throwables.propagate((Throwable)err);
    }
    ((EntityPlayerMP)player).playerNetServerHandler.sendPacket((Packet)new S23PacketBlockChange(x, y, z, event.world));
    final ItemStack newItem = player.inventory.getStackInSlot(i);
    player.inventory.setInventorySlotContents(i, item);
    if (newItem != null && !player.inventory.addItemStackToInventory(newItem.copy())) {
        player.dropPlayerItemWithRandomChoice(newItem.copy(), false);
    }
    ((EntityPlayerMP)player).mcServer.getConfigurationManager().syncPlayerInventory((EntityPlayerMP)player);
}
 
开发者ID:sameer,项目名称:ExtraUtilities,代码行数:68,代码来源:ItemGlove.java

示例10: onItemUseFirst

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
public boolean onItemUseFirst(final ItemStack stack, final EntityPlayer player, final World world, final int x, final int y, final int z, final int side, final float hitX, final float hitY, final float hitZ) {
    if (player == null) {
        return false;
    }
    final ItemStack heldItem = player.getHeldItem();
    if (heldItem == null || heldItem.getItem() != this) {
        return false;
    }
    if (ExtraUtilsMod.proxy.isAltSneaking()) {
        if (world.isRemote) {
            ExtraUtilsMod.proxy.sendAltUsePacket(x, y, z, side, stack, hitX, hitY, hitZ);
            return true;
        }
        return false;
    }
    else {
        if (heldItem.getItemDamage() == 32767) {
            heldItem.stackSize = 0;
            return true;
        }
        final int i = player.inventory.currentItem;
        if (i >= 9 || i < 0) {
            return false;
        }
        final ItemStack item = heldItem.copy();
        heldItem.setItemDamage(32767);
        player.inventory.setInventorySlotContents(i, (ItemStack)null);
        try {
            final PlayerInteractEvent event = ForgeEventFactory.onPlayerInteract(player, PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK, x, y, z, side, player.worldObj);
            final boolean result = !event.isCanceled() && event.useBlock != Event.Result.DENY;
            if (result) {
                final Block block = world.getBlock(x, y, z);
                block.onBlockActivated(world, x, y, z, player, side, hitX, hitY, hitZ);
            }
        }
        catch (Exception err) {
            for (int j = 0; j < player.inventory.getSizeInventory(); ++j) {
                final ItemStack stackInSlot = player.inventory.getStackInSlot(i);
                if (stackInSlot != null) {
                    if (stackInSlot.getItem() == this) {
                        if (stackInSlot.getItemDamage() == 32767) {
                            player.inventory.setInventorySlotContents(j, (ItemStack)null);
                        }
                    }
                }
            }
            if (player.inventory.getStackInSlot(i) == null) {
                player.inventory.setInventorySlotContents(i, item);
            }
            else if (!player.inventory.addItemStackToInventory(item)) {
                player.dropPlayerItemWithRandomChoice(item, false);
            }
            throw Throwables.propagate((Throwable)err);
        }
        final ItemStack newItem = player.inventory.getStackInSlot(i);
        player.inventory.setInventorySlotContents(i, item);
        if (newItem != null && !player.inventory.addItemStackToInventory(newItem.copy())) {
            player.dropPlayerItemWithRandomChoice(newItem.copy(), false);
        }
        if (player.worldObj.isRemote) {
            ExtraUtilsMod.proxy.sendUsePacket(x, y, z, side, item, hitX, hitY, hitZ);
        }
        else {
            if (player instanceof EntityPlayerMP) {
                ((EntityPlayerMP)player).mcServer.getConfigurationManager().syncPlayerInventory((EntityPlayerMP)player);
            }
            player.openContainer.detectAndSendChanges();
        }
        return true;
    }
}
 
开发者ID:sameer,项目名称:ExtraUtilities,代码行数:72,代码来源:ItemGlove.java

示例11: tickEnd

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void tickEnd(ServerTickEvent tick) {
    if (tick.phase != Phase.END) return;
    if (shroomQueue.isEmpty()) return;
    EnumFacing[] HORIZONTALS = new EnumFacing[] { EnumFacing.NORTH, EnumFacing.SOUTH, EnumFacing.EAST, EnumFacing.WEST };
    for (PlayerInteractEvent event : shroomQueue) {
        if (event.isCanceled()) continue;
        Coord at = new Coord(event.entityPlayer.worldObj, event.pos).add(event.face);
        if (event.entityPlayer.isSneaking()) {
            // Stalk
            if (event.face.getAxis() == EnumFacing.Axis.Y) {
                at.setMd(15); // Vertical stalk
            } else {
                at.setMd(10); // All-sides stalk
            }
            continue;
        }
        Block shroom = at.getBlock();
        int flag = 0;
        for (int i = 0; i < HORIZONTALS.length; i++) {
            EnumFacing fd = HORIZONTALS[i];
            if (at.add(fd).getBlock() == shroom) {
                flag |= 1 << i;
            }
        }
        int md = 14;
        // Alone & Surounded
        if (flag == 0) md = 14;
        if (flag == 15) {
            md = 0;
            if (at.add(EnumFacing.UP).getBlock() != shroom) {
                md = 9;
            }
        }
        
        // Edges
        if (flag == 13) md = 8;
        if (flag == 14) md = 2;
        if (flag == 7) md = 4;
        if (flag == 11) md = 6;
        
        // Corners
        if (flag == 6) md = 1;
        if (flag == 10) md = 3;
        if (flag == 5) md = 7;
        if (flag == 9) md = 9;
        
        // All other layouts (spikes & bridges) don't have a state.
        at.setMd(md);
    }
    shroomQueue.clear();
}
 
开发者ID:purpleposeidon,项目名称:Factorization,代码行数:53,代码来源:Mushroomalizer.java

示例12: playerInteractEventHandler

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
/**
 * This method is the mod. Everything else is extra
 */
@SubscribeEvent
public void playerInteractEventHandler(PlayerInteractEvent event)
{
    // Server side and on block only.
    if (event.isCanceled() || event.world.isRemote || event.action != RIGHT_CLICK_BLOCK) return;
    ItemStack heldItem = event.entityPlayer.inventory.getCurrentItem();
    // Only tools, not null
    if (heldItem == null || !(heldItem.getItem() instanceof ItemTool)) return;
    // disableTE code
    if (disableTE && event.world.getTileEntity(event.x, event.y, event.z) != null) return;
    // Save old slot id
    int oldSlot = event.entityPlayer.inventory.currentItem;
    // Avoid invalid array indexes
    if (oldSlot < 0 || oldSlot > 8) return;
    // Get the new slot id
    int newSlot = slots[oldSlot];
    // Avoid invalid slots indexes
    if (newSlot < 0 || newSlot > 8) return;
    // Get new item
    ItemStack slotStack = event.entityPlayer.inventory.getStackInSlot(newSlot);
    // No null please
    if (slotStack == null) return;
    // Set current slot to new slot to fool Minecraft
    event.entityPlayer.inventory.currentItem = newSlot;
    // Debug info
    if (D3Core.debug()) logger.info("Player: " + event.entityPlayer.getDisplayName() + "\tOldSlot: " + oldSlot + "\tOldStack: " + slotStack);
    // Fake right click                                                                                                                                                   Oh look fake values :p
    boolean b = ((EntityPlayerMP) event.entityPlayer).theItemInWorldManager.activateBlockOrUseItem(event.entityPlayer, event.world, slotStack, event.x, event.y, event.z, event.face, 0.5f, 0.5f, 0.5f);
    // Remove empty stacks
    if (slotStack.stackSize <= 0) slotStack = null;
    // Debug info
    if (D3Core.debug()) logger.info("Player: " + event.entityPlayer.getDisplayName() + "\tNewSlot: " + newSlot + "\tNewStack: " + slotStack + "\tResult: " + b);
    // Set old slot back properly
    event.entityPlayer.inventory.currentItem = oldSlot;
    // Update client
    event.entityPlayer.inventory.setInventorySlotContents(newSlot, slotStack);
    ((EntityPlayerMP) event.entityPlayer).playerNetServerHandler.sendPacket(new S2FPacketSetSlot(0, newSlot + 36, slotStack));
    // Prevent derpy doors
    event.setCanceled(true);
}
 
开发者ID:DoubleDoorDevelopment,项目名称:TorchTools,代码行数:44,代码来源:TorchTools.java

示例13: onPlayerInteractEvent

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onPlayerInteractEvent(PlayerInteractEvent event)
{
    if (event.isCanceled())
    { // Serverside
        return;
    }

    if (event.action != Action.RIGHT_CLICK_BLOCK)
    { // Right clicking only (and on a block)
        return;
    }

    ItemStack current = event.entityPlayer.inventory.getCurrentItem();
    if (current != null && current.getItem() instanceof ItemTool && checkIfCanPlace(current))
    {
        EntityPlayer player = event.entityPlayer;

        int currentSlot = player.inventory.currentItem;
        int newSlot = (currentSlot == 0) ? 8 : currentSlot + 1; // Loops over the top.

        if (newSlot > 8 || player.inventory.getStackInSlot(newSlot) == null)
        {
            return;
        }

        player.inventory.currentItem = newSlot;
        ItemStack useStack = player.inventory.getStackInSlot(newSlot);

        if (!event.world.isRemote)
        {
            // Inspiration from TiC and TorchTools here
            EntityPlayerMP playerMP = (EntityPlayerMP) event.entityPlayer;
            
            
            // Use item
            if (canUseItem(useStack))
            {
                playerMP.theItemInWorldManager.activateBlockOrUseItem(player, event.world, useStack, event.x, event.y, event.z, event.face, 0.5F, 0.5F, 0.5F); // Assume looking halfway at block //
                                                                                                                                                               // until // ray tracing
            }
            if (useStack.stackSize <= 0)
            {
                useStack = null;
            }

            // And update (TorchTools)
            playerMP.playerNetServerHandler.sendPacket(new S2FPacketSetSlot(0, newSlot + 36, useStack));

            // And end
            event.setCanceled(true);
        }
        else if (canUseItem(useStack))
        {
            player.swingItem();
        }

        player.inventory.currentItem = currentSlot;

    }
}
 
开发者ID:wyldmods,项目名称:ToolUtilities,代码行数:62,代码来源:PlaceItem.java

示例14: onBlockClicked

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
public void onBlockClicked(int p_73074_1_, int p_73074_2_, int p_73074_3_, int p_73074_4_)
{
    if (!this.gameType.isAdventure() || this.thisPlayerMP.isCurrentToolAdventureModeExempt(p_73074_1_, p_73074_2_, p_73074_3_))
    {
        PlayerInteractEvent event = ForgeEventFactory.onPlayerInteract(thisPlayerMP, Action.LEFT_CLICK_BLOCK, p_73074_1_, p_73074_2_, p_73074_3_, p_73074_4_, theWorld);
        if (event.isCanceled())
        {
            thisPlayerMP.playerNetServerHandler.sendPacket(new S23PacketBlockChange(p_73074_1_, p_73074_2_, p_73074_3_, theWorld));
            return;
        }

        if (this.isCreative())
        {
            if (!this.theWorld.extinguishFire((EntityPlayer)null, p_73074_1_, p_73074_2_, p_73074_3_, p_73074_4_))
            {
                this.tryHarvestBlock(p_73074_1_, p_73074_2_, p_73074_3_);
            }
        }
        else
        {
            this.initialDamage = this.curblockDamage;
            float f = 1.0F;
            Block block = this.theWorld.getBlock(p_73074_1_, p_73074_2_, p_73074_3_);


            if (!block.isAir(theWorld, p_73074_1_, p_73074_2_, p_73074_3_))
            {
                if (event.useBlock != Event.Result.DENY)
                {
                    block.onBlockClicked(theWorld, p_73074_1_, p_73074_2_, p_73074_3_, thisPlayerMP);
                    theWorld.extinguishFire(null, p_73074_1_, p_73074_2_, p_73074_3_, p_73074_4_);
                }
                else
                {
                    thisPlayerMP.playerNetServerHandler.sendPacket(new S23PacketBlockChange(p_73074_1_, p_73074_2_, p_73074_3_, theWorld));
                }
                f = block.getPlayerRelativeBlockHardness(thisPlayerMP, thisPlayerMP.worldObj, p_73074_1_, p_73074_2_, p_73074_3_);
            }

            if (event.useItem == Event.Result.DENY)
            {
                if (f >= 1.0f)
                {
                    thisPlayerMP.playerNetServerHandler.sendPacket(new S23PacketBlockChange(p_73074_1_, p_73074_2_, p_73074_3_, theWorld));
                }
                return;
            }

            if (!block.isAir(theWorld, p_73074_1_, p_73074_2_, p_73074_3_) && f >= 1.0F)
            {
                this.tryHarvestBlock(p_73074_1_, p_73074_2_, p_73074_3_);
            }
            else
            {
                this.isDestroyingBlock = true;
                this.partiallyDestroyedBlockX = p_73074_1_;
                this.partiallyDestroyedBlockY = p_73074_2_;
                this.partiallyDestroyedBlockZ = p_73074_3_;
                int i1 = (int)(f * 10.0F);
                this.theWorld.destroyBlockInWorldPartially(this.thisPlayerMP.getEntityId(), p_73074_1_, p_73074_2_, p_73074_3_, i1);
                this.durabilityRemainingOnBlock = i1;
            }
        }
    }
}
 
开发者ID:xtrafrancyz,项目名称:Cauldron,代码行数:66,代码来源:ItemInWorldManager.java

示例15: activateBlockOrUseItem

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
public boolean activateBlockOrUseItem(EntityPlayer p_73078_1_, World p_73078_2_, ItemStack p_73078_3_, int p_73078_4_, int p_73078_5_, int p_73078_6_, int p_73078_7_, float p_73078_8_, float p_73078_9_, float p_73078_10_)
{
    PlayerInteractEvent event = ForgeEventFactory.onPlayerInteract(p_73078_1_, Action.RIGHT_CLICK_BLOCK, p_73078_4_, p_73078_5_, p_73078_6_, p_73078_7_, p_73078_2_);
    if (event.isCanceled())
    {
        thisPlayerMP.playerNetServerHandler.sendPacket(new S23PacketBlockChange(p_73078_4_, p_73078_5_, p_73078_6_, theWorld));
        return false;
    }

    if (p_73078_3_ != null && p_73078_3_.getItem().onItemUseFirst(p_73078_3_, p_73078_1_, p_73078_2_, p_73078_4_, p_73078_5_, p_73078_6_, p_73078_7_, p_73078_8_, p_73078_9_, p_73078_10_))
    {
        if (p_73078_3_.stackSize <= 0) ForgeEventFactory.onPlayerDestroyItem(thisPlayerMP, p_73078_3_);
        return true;
    }

    Block block = p_73078_2_.getBlock(p_73078_4_, p_73078_5_, p_73078_6_);
    boolean isAir = block.isAir(p_73078_2_, p_73078_4_, p_73078_5_, p_73078_6_);
    boolean useBlock = !p_73078_1_.isSneaking() || p_73078_1_.getHeldItem() == null;
    if (!useBlock) useBlock = p_73078_1_.getHeldItem().getItem().doesSneakBypassUse(p_73078_2_, p_73078_4_, p_73078_5_, p_73078_6_, p_73078_1_);
    boolean result = false;

    if (useBlock)
    {
        if (event.useBlock != Event.Result.DENY)
        {
            result = block.onBlockActivated(p_73078_2_, p_73078_4_, p_73078_5_, p_73078_6_, p_73078_1_, p_73078_7_, p_73078_8_, p_73078_9_, p_73078_10_);
        }
        else
        {
            thisPlayerMP.playerNetServerHandler.sendPacket(new S23PacketBlockChange(p_73078_4_, p_73078_5_, p_73078_6_, theWorld));
            result = event.useItem != Event.Result.ALLOW;
        }
    }

    if (p_73078_3_ != null && !result && event.useItem != Event.Result.DENY)
    {
        int meta = p_73078_3_.getItemDamage();
        int size = p_73078_3_.stackSize;
        result = p_73078_3_.tryPlaceItemIntoWorld(p_73078_1_, p_73078_2_, p_73078_4_, p_73078_5_, p_73078_6_, p_73078_7_, p_73078_8_, p_73078_9_, p_73078_10_);
        if (isCreative())
        {
            p_73078_3_.setItemDamage(meta);
            p_73078_3_.stackSize = size;
        }
        if (p_73078_3_.stackSize <= 0) ForgeEventFactory.onPlayerDestroyItem(thisPlayerMP, p_73078_3_);
    }

    /* Re-enable if this causes bukkit incompatibility, or re-write client side to only send a single packet per right click.
    if (par3ItemStack != null && ((!result && event.useItem != Event.Result.DENY) || event.useItem == Event.Result.ALLOW))
    {
        this.tryUseItem(thisPlayerMP, par2World, par3ItemStack);
    }*/
    return result;
}
 
开发者ID:xtrafrancyz,项目名称:Cauldron,代码行数:55,代码来源:ItemInWorldManager.java


注:本文中的net.minecraftforge.event.entity.player.PlayerInteractEvent.isCanceled方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。