本文整理汇总了Java中net.minecraft.entity.player.EntityPlayer.setHeldItem方法的典型用法代码示例。如果您正苦于以下问题:Java EntityPlayer.setHeldItem方法的具体用法?Java EntityPlayer.setHeldItem怎么用?Java EntityPlayer.setHeldItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.entity.player.EntityPlayer
的用法示例。
在下文中一共展示了EntityPlayer.setHeldItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doFluidInteraction
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
private static boolean doFluidInteraction(TileEntity te, EnumFacing face, EntityPlayer player, EnumHand hand, boolean isInserting) {
ItemStack stack = player.getHeldItem(hand);
IFluidHandlerItem stackHandler = FluidUtil.getFluidHandler(stack);
if (stackHandler != null && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, face)) {
int capacity = stackHandler.getTankProperties()[0].getCapacity();
IFluidHandler handler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, face);
PlayerInvWrapper invWrapper = new PlayerInvWrapper(player.inventory);
FluidActionResult result = isInserting ?
FluidUtil.tryEmptyContainerAndStow(player.getHeldItem(hand), handler, invWrapper, capacity, player) :
FluidUtil.tryFillContainerAndStow(player.getHeldItem(hand), handler, invWrapper, capacity, player);
if (result.isSuccess()) {
player.setHeldItem(hand, result.getResult());
return true;
}
}
return false;
}
示例2: processInteract
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@Override
public boolean processInteract(EntityPlayer player, EnumHand hand) {
if (!player.world.isRemote) {
ItemStack stack = player.getHeldItem(hand);
if (stack.getItem() == ItemGlassJar && stack.getItemDamage() == 0) {
this.setDead();
stack.setItemDamage(1);
NBTTagCompound nbt = stack.getTagCompound();
if (nbt == null) return false;
nbt.setFloat("size", faerieInformation.getSize());
nbt.setInteger("type", faerieInformation.getType());
nbt.setDouble("max_health", faerieInformation.getMaxHealth());
nbt.setInteger("level", faerieInformation.getLevel());
nbt.setInteger("current_exp", faerieInformation.getCurrentExp());
player.setHeldItem(hand, stack);
}
}
return super.processInteract(player, hand);
}
示例3: onItemUse
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (!worldIn.isRemote) {
ItemStack stack = player.getHeldItem(hand);
if (stack.getMetadata() == 1 && !(worldIn.getTileEntity(pos) instanceof TileFaerieHome)) {
NBTTagCompound nbt = stack.getTagCompound();
if (nbt == null) return EnumActionResult.FAIL;
EntityFaerie faerie = new EntityFaerie(worldIn, nbt.getDouble("max_health"), nbt.getInteger("type"), nbt.getFloat("size"), nbt.getInteger("level"), nbt.getInteger("current_exp"));
faerie.setPosition((double) pos.getX(), (double) pos.up().getY(), (double) pos.getZ());
worldIn.spawnEntity(faerie);
player.setHeldItem(hand, new ItemStack(GeneraItems.ItemGlassJar, 1, 0));
return EnumActionResult.SUCCESS;
}
}
return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
}
示例4: onItemRightClick
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
if (!world.isRemote) {
IBaublesItemHandler baubles = BaublesApi.getBaublesHandler(player);
for (int i = 0; i < baubles.getSlots(); i++)
if (baubles.getStackInSlot(i).isEmpty() && baubles.isItemValidForSlot(i, player.getHeldItem(hand), player)) {
baubles.setStackInSlot(i, player.getHeldItem(hand).copy());
if (!player.capabilities.isCreativeMode) {
player.setHeldItem(hand, ItemStack.EMPTY);
}
onEquipped(player.getHeldItem(hand), player);
break;
}
}
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, player.getHeldItem(hand));
}
示例5: fill
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
public boolean fill(EntityPlayer player, EnumHand hand, int amount)
{
boolean flag = false;
ItemStack stack = player.getHeldItem(hand);
NBTTagCompound nbt = getNBT(stack);
if(nbt.getInteger("Blood") + amount <= 50)
{
nbt.setInteger("Blood", nbt.getInteger("Blood") + amount);
flag = true;
}
stack.setItemDamage(metaChange(nbt));
stack.setTagCompound(nbt);
player.setHeldItem(hand, stack);
return flag;
}
示例6: onBlockActivated
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@Override //&& state.getValue(GENERATED)==1
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
if(heldItem == null){
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, heldItem, side, hitX, hitY, hitZ);
}
if( !worldIn.isRemote && heldItem.getItem() == Items.BOWL && side != EnumFacing.UP && side != EnumFacing.DOWN){
ItemStack itemstack1 = new ItemStack(ItemRegistry.rubber_sap);
if (--heldItem.stackSize == 0)
{
playerIn.setHeldItem(hand, itemstack1);
}
else if (!playerIn.inventory.addItemStackToInventory(itemstack1))
{
playerIn.dropItem(itemstack1, false);
}
}
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, heldItem, side, hitX, hitY, hitZ);
}
示例7: onBlockActivated
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@Override //&& state.getValue(GENERATED)==1
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack heldItem = playerIn.getHeldItem(hand);
if (heldItem.isEmpty()) {
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}
if (!worldIn.isRemote && heldItem.getItem() == Items.BOWL && facing != EnumFacing.UP && facing != EnumFacing.DOWN) {
ItemStack itemstack1 = new ItemStack(ItemRegistry.rubber_sap);
heldItem.shrink(1);
if (heldItem.isEmpty()) {
playerIn.setHeldItem(hand, itemstack1);
} else if (!playerIn.inventory.addItemStackToInventory(itemstack1)) {
playerIn.dropItem(itemstack1, false);
}
}
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}
示例8: onItemUse
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@Nonnull
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (worldIn.getBlockState(pos).getBlock() instanceof BlockCake) {
worldIn.setBlockState(pos, FoodCraftReloaded.getLoader(FruitEnumLoader.class).get().getInstanceMap(BlockFruitCake.class).get(fruitType).getDefaultState().withProperty(BlockCake.BITES, worldIn.getBlockState(pos).getValue(BlockCake.BITES)));
player.setHeldItem(hand, new ItemStack(FCRItems.GLASS_BOTTLE));
return EnumActionResult.SUCCESS;
}
return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
}
示例9: onBlockActivated
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand,
EnumFacing side, float hitX, float hitY, float hitZ) {
ItemStack handStack = player.getHeldItem(hand);
if (handStack.getItem() == GeneraItems.ItemGlassJar &&
handStack.getMetadata() == 1) {
NBTTagCompound nbt = handStack.getTagCompound();
if (nbt == null) return false;
PotionType potion;
player.getEntityData().setInteger("genera.sacrifices_made", player.getEntityData().getInteger("genera.sacrifices_made") + 1);
switch (nbt.getInteger("type")) {
case 0:
potion = PotionType.getPotionTypeForName("regeneration");
if (potion == null) return false;
player.setHeldItem(hand, PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM), potion));
return false;
case 1:
potion = PotionType.getPotionTypeForName("night_vision");
if (potion == null) return false;
player.setHeldItem(hand, PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM), potion));
return false;
case 2:
potion = PotionType.getPotionTypeForName("leaping");
if (potion == null) return false;
player.setHeldItem(hand, PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM), potion));
return false;
}
}
return false;
}
示例10: placeChest
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
private void placeChest(TransportableChest chest, ItemStack stack, EntityPlayer player, EnumHand hand, World world, BlockPos pos, EnumFacing face)
{
BlockPos chestPos = getChestCoords(world, pos, face);
if (!chest.canPlaceChest(world, chestPos, player, stack))
return;
ItemStack chestStack = chest.createChestStack(stack);
if (chestStack.isEmpty()) return;
player.setHeldItem(hand, chestStack);
EnumActionResult result = chestStack.onItemUse(player, world, pos, hand, face, 0.0f, 0.0f, 0.0f);
player.setHeldItem(hand, stack);
if (result != EnumActionResult.SUCCESS)
{
return;
}
TileEntity tile = world.getTileEntity(chestPos);
if (tile == null) return;
if (chest.copyTileEntity())
{
NBTTagCompound nbt = getTagCompound(stack).getCompoundTag("ChestTile");
nbt = chest.modifyTileCompound(nbt, world, pos, player, stack);
world.setTileEntity(chestPos, TileEntity.create(world, nbt));
} else
{
IInventory inv = (IInventory) tile;
moveItemsIntoChest(stack, inv);
}
getTagCompound(stack).removeTag("ChestType");
getTagCompound(stack).removeTag("ChestName");
chest.onChestPlaced(world, pos, player, stack);
damageItem(stack, player);
}
示例11: giveItem
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
private void giveItem(EntityPlayer player, EnumHand hand, ItemStack heldItem, ItemStack toGive) {
if (heldItem.isEmpty() || heldItem.getCount() - 1 == 0) {
player.setHeldItem(hand, toGive);
heldItem.shrink(1);
} else if (!player.inventory.addItemStackToInventory(toGive)) {
player.dropItem(toGive, false);
} else if (player instanceof EntityPlayerMP) {
((EntityPlayerMP) player).sendContainerToPlayer(player.inventoryContainer);
}
}
示例12: onItemUse
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@Nonnull
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (worldIn.getBlockState(pos).getBlock() instanceof BlockCake) {
worldIn.setBlockState(pos, FoodCraftReloaded.getLoader(VegetableEnumLoader.class).get().getInstanceMap(BlockVegetableCake.class).get(vegetableType).getDefaultState().withProperty(BlockCake.BITES, worldIn.getBlockState(pos).getValue(BlockCake.BITES)));
player.setHeldItem(hand, new ItemStack(FCRItems.GLASS_BOTTLE));
return EnumActionResult.SUCCESS;
}
return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
}
示例13: swapItem
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
private void swapItem(EntityPlayer player, EntityEquipmentSlot p_184795_2_, ItemStack p_184795_3_, EnumHand hand)
{
ItemStack itemstack = this.getItemStackFromSlot(p_184795_2_);
if (itemstack.func_190926_b() || (this.disabledSlots & 1 << p_184795_2_.getSlotIndex() + 8) == 0)
{
if (!itemstack.func_190926_b() || (this.disabledSlots & 1 << p_184795_2_.getSlotIndex() + 16) == 0)
{
if (player.capabilities.isCreativeMode && itemstack.func_190926_b() && !p_184795_3_.func_190926_b())
{
ItemStack itemstack2 = p_184795_3_.copy();
itemstack2.func_190920_e(1);
this.setItemStackToSlot(p_184795_2_, itemstack2);
}
else if (!p_184795_3_.func_190926_b() && p_184795_3_.func_190916_E() > 1)
{
if (itemstack.func_190926_b())
{
ItemStack itemstack1 = p_184795_3_.copy();
itemstack1.func_190920_e(1);
this.setItemStackToSlot(p_184795_2_, itemstack1);
p_184795_3_.func_190918_g(1);
}
}
else
{
this.setItemStackToSlot(p_184795_2_, p_184795_3_);
player.setHeldItem(hand, itemstack);
}
}
}
}
示例14: processRightClick
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
public EnumActionResult processRightClick(EntityPlayer player, World worldIn, EnumHand stack)
{
if (this.currentGameType == GameType.SPECTATOR)
{
return EnumActionResult.PASS;
}
else
{
this.syncCurrentPlayItem();
this.connection.sendPacket(new CPacketPlayerTryUseItem(stack));
ItemStack itemstack = player.getHeldItem(stack);
if (player.getCooldownTracker().hasCooldown(itemstack.getItem()))
{
return EnumActionResult.PASS;
}
else
{
int i = itemstack.func_190916_E();
ActionResult<ItemStack> actionresult = itemstack.useItemRightClick(worldIn, player, stack);
ItemStack itemstack1 = actionresult.getResult();
if (itemstack1 != itemstack || itemstack1.func_190916_E() != i)
{
player.setHeldItem(stack, itemstack1);
}
return actionresult.getType();
}
}
}
示例15: execute
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@Override
public void execute(Side side, EntityPlayer player)
{
if(Clef.config.creatableInstruments == 0)
{
return;
}
TileEntity te = player.world.getTileEntity(pos);
if(te instanceof TileEntityInstrumentPlayer)
{
TileEntityInstrumentPlayer player1 = (TileEntityInstrumentPlayer)te;
boolean full = true;
for(int i = 0; i < 9 ; i++)
{
if(player1.getStackInSlot(i) == null)
{
full = false;
break;
}
}
if(full)
{
ItemStack is1 = player.getHeldItemMainhand();
if(is1.getItem() == Items.NAME_TAG && is1.hasDisplayName())
{
Instrument ins = null;
for(Instrument instrument : InstrumentLibrary.instruments)
{
if(instrument.info.itemName.equals(instrumentName))
{
ins = instrument;
break;
}
}
if(ins == null)
{
if(Clef.config.creatableInstruments == 1 || Clef.config.creatableInstruments == 3)
{
InstrumentLibrary.requestInstrument(instrumentName, player);
}
}
else if(Clef.config.creatableInstruments < 2)
{
return;
}
for(int i = 0; i < 9; i++)
{
player1.setInventorySlotContents(i, null);
}
ItemStack is = new ItemStack(Clef.itemInstrument, 1, 0);
NBTTagCompound tag = new NBTTagCompound();
tag.setString("itemName", instrumentName);
is.setTagCompound(tag);
InventoryHelper.spawnItemStack(player.world, pos.getX() + 0.5D, pos.getY() + 1D, pos.getZ() + 0.5D, is);
player.world.playSound(null, pos.getX() + 0.5D, pos.getY() + 1D, pos.getZ() + 0.5D, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, ((player.world.rand.nextFloat() - player.world.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
player1.markDirty();
player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
player.inventory.markDirty();
player1.justCreatedInstrument = true;
}
}
}
return;
}