本文整理汇总了Java中net.minecraftforge.event.entity.player.EntityItemPickupEvent.setCanceled方法的典型用法代码示例。如果您正苦于以下问题:Java EntityItemPickupEvent.setCanceled方法的具体用法?Java EntityItemPickupEvent.setCanceled怎么用?Java EntityItemPickupEvent.setCanceled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraftforge.event.entity.player.EntityItemPickupEvent
的用法示例。
在下文中一共展示了EntityItemPickupEvent.setCanceled方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: itemPickup
import net.minecraftforge.event.entity.player.EntityItemPickupEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void itemPickup(EntityItemPickupEvent event){
EntityItem ent = event.getItem();
if(ent == null)return;
if(!ItemStackTools.isValid(ent.getEntityItem()))return;
EntityPlayer player = event.getEntityPlayer();
if(player !=null && player.isEntityAlive()){
ItemStack backpack = BackpackUtil.getBackpackOnBack(player);
if(ItemStackTools.isValid(backpack)){
IBackpack backpackType = BackpackUtil.getType(backpack);
if(backpackType !=null && backpackType.handleItemPickup(event, player, backpack)){
event.setCanceled(true);
}
}
}
}
示例2: onPickup
import net.minecraftforge.event.entity.player.EntityItemPickupEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void onPickup(EntityItemPickupEvent event){
ItemStack item = event.item.getEntityItem();
if(item == null)
return;
if(isSoulbound(item)){
String fidelis = getFidelisID(item);
String id = getID(event.entityPlayer);
if(!fidelis.equals("") && !fidelis.equals(id))
{
event.setCanceled(true);
if(event.entityPlayer.ticksExisted % 40 == 0)
event.entityPlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.DARK_RED + "This item is not yours. it belongs to " + getOwner(item)));
return;
}
}
}
示例3: onItemPickup
import net.minecraftforge.event.entity.player.EntityItemPickupEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void onItemPickup(EntityItemPickupEvent event) {
ItemStack stack = event.item.getEntityItem();
EntityPlayer player = event.entityPlayer;
if (stack != null && stack.getItem() instanceof IHandlePickup) {
int size = stack.stackSize;
if (((IHandlePickup) stack.getItem()).onPickupItem(stack, player)) {
if (stack.stackSize < size) {
FMLCommonHandler.instance().firePlayerItemPickupEvent(player, event.item);
event.item.playSound(Sounds.POP, 0.2F, ((event.item.worldObj.rand.nextFloat()
- event.item.worldObj.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
player.onItemPickup(event.item, size - stack.stackSize);
}
if (stack.stackSize <= 0) {
event.item.setDead();
event.setCanceled(true);
}
} else {
event.setCanceled(true);
}
}
}
示例4: onItemPickupAttempt
import net.minecraftforge.event.entity.player.EntityItemPickupEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void onItemPickupAttempt(EntityItemPickupEvent event){
if (event.entityPlayer.worldObj.isRemote)
return;
if (!ClaimsList.For(event.entity.worldObj).actionIsTrusted(event.entityPlayer, PermissionsMutex.PICKUP_ITEMS, event.item.posX, event.item.posY, event.item.posZ))
event.setCanceled(true);
else
GriefGuardian._dal.logAction(
(EntityPlayerMP)event.entityPlayer,
Actions.ITEM_PICKUP,
(int)Math.floor(event.entity.posX),
(int)Math.floor(event.entity.posY),
(int)Math.floor(event.entity.posZ),
event.item.getEntityItem(),
"");
}
示例5: unstableIngotDestroyer
import net.minecraftforge.event.entity.player.EntityItemPickupEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void unstableIngotDestroyer(final EntityItemPickupEvent event) {
if (ExtraUtils.unstableIngot != null && event.item.getEntityItem().getItem() == ExtraUtils.unstableIngot && event.item.getEntityItem().hasTagCompound() && (event.item.getEntityItem().getTagCompound().hasKey("crafting") || event.item.getEntityItem().getTagCompound().hasKey("time"))) {
event.item.setDead();
event.setCanceled(true);
}
}
示例6: onItemPickedUp
import net.minecraftforge.event.entity.player.EntityItemPickupEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void onItemPickedUp (EntityItemPickupEvent event) {
// Null Charm
final List<ItemStack> charms = itemNullCharm.getItem(event.getEntityPlayer());
for (final ItemStack charm : charms) {
if (ItemNullCharm.isBlackListed(event.getItem().getItem(), charm)) {
event.getItem().setDead();
event.setCanceled(true);
return;
}
}
}
示例7: finishSeeds
import net.minecraftforge.event.entity.player.EntityItemPickupEvent; //导入方法依赖的package包/类
private static void finishSeeds(EntityItemPickupEvent event, EntityItem entity, EntityPlayer player, @Nonnull ItemStack leftover) {
entity.setDead();
event.setCanceled(true);
player.world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, ((player.world.rand.nextFloat() - player.world.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
if (!leftover.isEmpty()) {
ItemHandlerHelper.giveItemToPlayer(player, leftover);
}
}
示例8: onEvent
import net.minecraftforge.event.entity.player.EntityItemPickupEvent; //导入方法依赖的package包/类
@Override
public void onEvent(EntityItemPickupEvent event) {
if (event.getEntityPlayer() instanceof EntityPlayerMP) {
if (getPlayerSettings((EntityPlayerMP) event.getEntityPlayer()).disablePickups.contains(event.getItem().getItem().getItem()))
event.setCanceled(true);
}
}
示例9: onPickupGold
import net.minecraftforge.event.entity.player.EntityItemPickupEvent; //导入方法依赖的package包/类
/**
* Code for handling gold coin items. If it is ever used again, it must be
* changed to account for reliable and unreliabale gold.
*/
public void onPickupGold(EntityItemPickupEvent event) {
ItemStack stack = event.item.getEntityItem();
if (stack.itemID == Config.goldCoin.getID()) {
event.entityLiving.worldObj.playSoundAtEntity(event.entity, Sound.COINS.getName(), 0.8f, 1f);
EntityStats stats = Dota2Items.stats.getOrCreateEntityStats(event.entityLiving);
stats.addGold(stack.stackSize, 0);
if (!event.entityLiving.worldObj.isRemote) {
stats.sendSyncPacketToClient((EntityPlayer)event.entityLiving);
}
event.item.setDead();
event.setCanceled(true);
}
}
示例10: pickupItem
import net.minecraftforge.event.entity.player.EntityItemPickupEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void pickupItem(EntityItemPickupEvent event) {
for (int i = 0; i < event.getEntityPlayer().inventory.getSizeInventory() && !event.getItem().getItem().isEmpty(); i++) {
IUpgradableBlock chest = UpgradeHelper.INSTANCE.getInventory(event.getEntityPlayer().inventory.getStackInSlot(i), event.getEntity());
if (chest != null) {
if (!hasUpgradeOperationCost(chest)) {
continue;
}
for (ItemStack upgrade : chest.getActiveUpgrades()) {
if (upgrade.getItem() == BlocksItemsBetterChests.upgrade && BlocksItemsBetterChests.upgrade.getType(upgrade) == UpgradeType.COLLECTOR) {
IBetterChest inv = (IBetterChest) chest;
IFilter filter = ((IBetterChest) chest).getFilterFor(upgrade);
if (filter.matchesStack(event.getItem().getItem())) {
ItemStack prev = event.getItem().getItem();
event.getItem().setItem(InvUtil.putStackInInventoryInternal(event.getItem().getItem(), inv, false));
if (prev.getCount() != event.getItem().getItem().getCount()) {
event.setCanceled(true);
drawUpgradeOperationCode(chest);
((IBetterChest) chest).markDirty();
}
}
break;
}
}
}
}
}
示例11: pickAmmo
import net.minecraftforge.event.entity.player.EntityItemPickupEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void pickAmmo(EntityItemPickupEvent event) {
ItemStack stack = event.getItem().getItem();
if (event.getItem().getEntityData().getBoolean("Fake")) {
event.setResult(Result.ALLOW);
return;
}
if (WeaponsCapability.get(event.getEntity()).isInvisible()) {
event.setResult(Result.DENY);
event.setCanceled(true);
return;
}
if (stack.getItem() instanceof ItemAmmoPackage){
ItemStack weapon=event.getEntityPlayer().getHeldItemMainhand();
if(!weapon.isEmpty() && weapon.getItem() instanceof ItemFromData && ItemFromData.getData(weapon).getInt(PropertyType.AMMO_TYPE)!=0)
stack.setItemDamage(ItemFromData.getData(weapon).getInt(PropertyType.AMMO_TYPE));
stack=ItemAmmoPackage.convertPackage(stack, event.getEntityPlayer());
event.getItem().setItem(stack);
event.setResult(Result.DENY);
event.setCanceled(true);
return;
}
/*if (!(stack.getItem() instanceof ItemCrate) && stack.hasTagCompound() && stack.getTagCompound().getBoolean("DropFrom")) {
event.getEntityPlayer().addStat(TF2Achievements.SPOILS_WAR);
}*/
if (stack.getItem() instanceof ItemAmmo && event.getEntityLiving().hasCapability(TF2weapons.INVENTORY_CAP, null) ) {
if (!event.getEntityLiving().getCapability(TF2weapons.INVENTORY_CAP, null).getStackInSlot(3).isEmpty()) {
IItemHandler inv = event.getEntityLiving().getCapability(TF2weapons.INVENTORY_CAP, null).getStackInSlot(3)
.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
ItemStack orig=stack.copy();
orig.setCount(0);
stack=ItemHandlerHelper.insertItemStacked(inv, stack, false);
if(stack.isEmpty()){
event.getItem().setItem(orig);
}
if(!event.getEntityPlayer().getHeldItemMainhand().isEmpty() && event.getEntityPlayer().getHeldItemMainhand().getItem() instanceof ItemWeapon)
TF2weapons.network.sendTo(new TF2Message.UseMessage(event.getEntityPlayer().getHeldItemMainhand().getItemDamage(), false,
ItemAmmo.getAmmoAmount(event.getEntityPlayer(), event.getEntityPlayer().getHeldItemMainhand()), EnumHand.MAIN_HAND),(EntityPlayerMP) event.getEntityPlayer());
/*for (int i = 0; i < inv.getSlots(); i++) {
ItemStack inSlot = inv.getStackInSlot(i);
if (inSlot == null) {fg
inv.insertItem(i, stack.copy(),false);v
stack.setCount( 0;
} else if (stack.isItemEqual(inSlot) && ItemStack.areItemStackTagsEqual(stack, inSlot)) {
int size = stack.getCount() + inSlot.getCount();
if (size > stack.getMaxStackSize()) {
stack.setCount( size - inSlot.getMaxStackSize();
inSlot.setCount( stack.getMaxStackSize();
} else {
inSlot.setCount( size;
stack.setCount( 0;
}
}
if (stack.getCount() <= 0) {
break;
}
}*/
}
if (stack.isEmpty()) {
event.setResult(Result.ALLOW);
return;
}
}
event.setResult(Result.DEFAULT);
}
示例12: onTryPickupItem
import net.minecraftforge.event.entity.player.EntityItemPickupEvent; //导入方法依赖的package包/类
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onTryPickupItem(EntityItemPickupEvent event)
{
if (!SettingsFlags.instance.enableCustomInventory)
{
return;
}
if (event.getItem() != null && !event.getItem().getItem().isEmpty() && !event.getItem().isDead && !event.getEntityPlayer().world.isRemote)
{
int i = PlayerInventoryHelper.findFirstAvailableSlotFor(event.getItem().getItem(), Optional.empty(), event.getEntityPlayer());
if (i == -1)
{
event.setCanceled(true);
}
else
{
if (i < Short.MAX_VALUE)
{
event.getEntityPlayer().inventory.setInventorySlotContents(i, event.getItem().getItem().copy());
net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerItemPickupEvent(event.getEntityPlayer(), event.getItem());
event.getEntityPlayer().onItemPickup(event.getItem(), event.getItem().getItem().getCount());
event.getEntityPlayer().addStat(StatList.getObjectsPickedUpStats(event.getItem().getItem().getItem()), event.getItem().getItem().getCount());
event.getItem().setDead();
event.setCanceled(true);
}
else
{
int slotID = i - Short.MAX_VALUE;
ItemStack toIncrement = event.getEntityPlayer().inventory.getStackInSlot(slotID);
Optional<Slot> s = Optional.ofNullable(event.getEntityPlayer().openContainer != null ? event.getEntityPlayer().openContainer.getSlot(slotID) : null);
int max = Math.min(toIncrement.getMaxStackSize(), s.map(slot -> slot.getItemStackLimit(toIncrement)).orElseGet(() -> event.getEntityPlayer().inventory.getInventoryStackLimit()));
int current = toIncrement.getCount();
final int added = Math.min(event.getItem().getItem().getCount(), max - current);
net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerItemPickupEvent(event.getEntityPlayer(), event.getItem());
event.getEntityPlayer().addStat(StatList.getObjectsPickedUpStats(event.getItem().getItem().getItem()), added);
event.getItem().getItem().shrink(added);
toIncrement.grow(added);
event.getEntityPlayer().world.playSound(null, event.getEntityPlayer().getPosition(), SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, (event.getEntityPlayer().world.rand.nextFloat() - event.getEntityPlayer().world.rand.nextFloat()) * 1.4F + 2.0F);
if (toIncrement.isEmpty())
{
event.getItem().setDead();
}
event.setCanceled(true);
}
}
}
}
示例13: onEntityItemPickupEvent
import net.minecraftforge.event.entity.player.EntityItemPickupEvent; //导入方法依赖的package包/类
/**
* Tries to first fill the matching stacks in the player's inventory,
* and then depending on the bag's mode, tries to add the remaining items
* to the bag's inventory.
* @param event
* @return true if all items were handled and further processing of the event should not occur
*/
public static boolean onEntityItemPickupEvent(EntityItemPickupEvent event)
{
EntityItem entityItem = event.getItem();
ItemStack stack = entityItem.getItem();
EntityPlayer player = event.getEntityPlayer();
if (player.getEntityWorld().isRemote || entityItem.isDead || stack.isEmpty())
{
return true;
}
ItemStack origStack = ItemStack.EMPTY;
final int origStackSize = stack.getCount();
int stackSizeLast = origStackSize;
boolean ret = false;
IItemHandler playerInv = player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
// Not all the items could fit into existing stacks in the player's inventory, move them directly to the bag
List<Integer> slots = InventoryUtils.getSlotNumbersOfMatchingItems(playerInv, EnderUtilitiesItems.HANDY_BAG);
for (int slot : slots)
{
ItemStack bagStack = playerInv.getStackInSlot(slot);
// Bag is not locked
if (bagStack.isEmpty() == false && bagStack.getItem() == EnderUtilitiesItems.HANDY_BAG && ItemHandyBag.bagIsOpenable(bagStack))
{
// Delayed the stack copying until we know if there is a valid bag,
// so check if the stack was copied already or not.
if (origStack == ItemStack.EMPTY)
{
origStack = stack.copy();
}
stack = handleItems(stack, bagStack, player);
if (stack.isEmpty() || stack.getCount() != stackSizeLast)
{
if (stack.isEmpty())
{
entityItem.setDead();
event.setCanceled(true);
ret = true;
break;
}
ItemStack pickedUpStack = origStack.copy();
pickedUpStack.setCount(stackSizeLast - stack.getCount());
FMLCommonHandler.instance().firePlayerItemPickupEvent(player, entityItem, pickedUpStack);
player.onItemPickup(entityItem, origStackSize);
}
stackSizeLast = stack.getCount();
}
}
// Not everything was handled, update the stack
if (entityItem.isDead == false && stack.getCount() != origStackSize)
{
entityItem.setItem(stack);
}
// At least some items were picked up
if (entityItem.isSilent() == false && (entityItem.isDead || stack.getCount() != origStackSize))
{
player.getEntityWorld().playSound(null, player.getPosition(), SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.MASTER,
0.2F, ((itemRand.nextFloat() - itemRand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
}
return ret;
}
示例14: onEntityItemPickupEvent
import net.minecraftforge.event.entity.player.EntityItemPickupEvent; //导入方法依赖的package包/类
/**
* Tries to first fill the matching stacks in the player's inventory,
* and then depending on the bag's mode, tries to add the remaining items
* to the bag's inventory.
* @param event
* @return true if all items were handled and further processing of the event should not occur
*/
public static boolean onEntityItemPickupEvent(EntityItemPickupEvent event)
{
EntityItem entityItem = event.getItem();
ItemStack stack = entityItem.getItem();
EntityPlayer player = event.getEntityPlayer();
if (player.getEntityWorld().isRemote || entityItem.isDead || stack.isEmpty())
{
return true;
}
ItemStack origStack = ItemStack.EMPTY;
final int origStackSize = stack.getCount();
int stackSizeLast = origStackSize;
boolean ret = false;
IItemHandler playerInv = player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
// Not all the items could fit into existing stacks in the player's inventory, move them directly to the nullifier
List<Integer> slots = InventoryUtils.getSlotNumbersOfMatchingItems(playerInv, EnderUtilitiesItems.NULLIFIER);
for (int slot : slots)
{
ItemStack nullifierStack = playerInv.getStackInSlot(slot);
// Nullifier is not disabled
if (nullifierStack.isEmpty() == false && isNullifierEnabled(nullifierStack))
{
// Delayed the stack copying until we know if there is a valid bag,
// so check if the stack was copied already or not.
if (origStack == ItemStack.EMPTY)
{
origStack = stack.copy();
}
stack = handleItems(stack, nullifierStack, player);
if (stack.isEmpty() || stack.getCount() != stackSizeLast)
{
if (stack.isEmpty())
{
entityItem.setDead();
event.setCanceled(true);
ret = true;
break;
}
ItemStack pickedUpStack = origStack.copy();
pickedUpStack.setCount(stackSizeLast - stack.getCount());
FMLCommonHandler.instance().firePlayerItemPickupEvent(player, entityItem, pickedUpStack);
player.onItemPickup(entityItem, origStackSize);
}
stackSizeLast = stack.getCount();
}
}
// Not everything was handled, update the stack
if (entityItem.isDead == false && stack.getCount() != origStackSize)
{
entityItem.setItem(stack);
}
// At least some items were picked up
if (entityItem.isSilent() == false && (entityItem.isDead || stack.getCount() != origStackSize))
{
player.getEntityWorld().playSound(null, player.getPosition(), SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.MASTER,
0.2F, ((itemRand.nextFloat() - itemRand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
}
return ret;
}
示例15: playerItemPickup
import net.minecraftforge.event.entity.player.EntityItemPickupEvent; //导入方法依赖的package包/类
/** Alters behaviour when player picks up an item. */
@SubscribeEvent
public void playerItemPickup(EntityItemPickupEvent event) {
EntityPlayer player = event.getEntityPlayer();
ItemStack stack = event.getItem().getEntityItem();
Item item = stack.getItem();
// Special case for laid eggs
if (item instanceof ItemEgg) {
int count = stack.getCount();
stack = ItemSimple.newStack(GeoItems.EGG, count, player.world);
}
if (player.getCapability(GeoCaps.CAP_PLAYER, null).canPickup(item)) {
stack = ContainerInventory.add(player, stack);
}
if (stack.isEmpty()) {
event.getItem().setDead();
} else {
event.getItem().setEntityItemStack(stack);
}
event.setCanceled(true);
}