本文整理汇总了Java中net.minecraft.entity.player.EntityPlayer.addItemStackToInventory方法的典型用法代码示例。如果您正苦于以下问题:Java EntityPlayer.addItemStackToInventory方法的具体用法?Java EntityPlayer.addItemStackToInventory怎么用?Java EntityPlayer.addItemStackToInventory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.entity.player.EntityPlayer
的用法示例。
在下文中一共展示了EntityPlayer.addItemStackToInventory方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onFoodEaten
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@Override
public void onFoodEaten(ItemStack stack, World worldIn, EntityPlayer player) {
if (stack.getTagCompound() == null) {
stack.setTagCompound(new NBTTagCompound()); //not really supposed to happen ingame since you only get the stews with NBT values assigned but it prevents crashing
}
final FoodStats foodStats = player.getFoodStats();
foodStats.setFoodLevel(foodStats.getFoodLevel() + stack.getTagCompound().getInteger("hunger"));
foodStats.setFoodSaturationLevel(foodStats.getFoodLevel() + stack.getTagCompound().getFloat("saturation"));
player.addItemStackToInventory(new ItemStack(Items.BOWL, 1));
}
示例2: subtractFromInventory
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
public static void subtractFromInventory(EntityPlayer playerIn, float amount) {
float amountToGiveBack = getCurrencyNoWallet(playerIn) - amount;
if (amountToGiveBack >= 0) {
for (int i = 0; i < playerIn.inventory.getSizeInventory(); i++) {
if (playerIn.inventory.getStackInSlot(i) != ItemStack.EMPTY && playerIn.inventory.getStackInSlot(i).getItem() instanceof ItemMoneyBase) {
playerIn.inventory.setInventorySlotContents(i, ItemStack.EMPTY);
}
}
for (ItemStack stack : CurrencyUtils.itemMoneyAmount(amountToGiveBack)) {
playerIn.addItemStackToInventory(stack);
}
}
}
示例3: useCauldron
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@SuppressWarnings("ConstantConditions")
public boolean useCauldron(EntityPlayer player, EnumHand hand, ItemStack heldItem) {
if (!world.isRemote) {
if (heldItem.isEmpty()) {
if (!getContainer().isEmpty()) {
giveItem(player, hand, ItemStack.EMPTY, getContainer());
setContainer(ItemStack.EMPTY);
} else if (inv.isFull() && hasIngredients() && mode != Mode.RITUAL) {
itemRitualLogic();
}
return true;
}
//Held Item is not empty
if (heldItem.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, EnumFacing.UP)) {
handleLiquid(heldItem.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, EnumFacing.UP));
} else if (heldItem.getItem() == Items.POTIONITEM && PotionUtils.getEffectsFromStack(heldItem).isEmpty()) {
int level = inv.getFluidAmount();
if (level < BUCKET_VOLUME && (inv.getFluid() == null || inv.hasFluid(FluidRegistry.WATER))) {
play(SoundEvents.ITEM_BUCKET_FILL, 1F, 1F);
giveItem(player, hand, heldItem, new ItemStack(Items.GLASS_BOTTLE));
FluidStack fluidStack = new FluidStack(FluidRegistry.WATER, 250);
inv.fill(fluidStack, true);
}
} else if (heldItem.getItem() == Items.GLASS_BOTTLE) {
if (mode == Mode.POTION) {
potionRecipeLogic(player, hand, heldItem);
} else if (mode == Mode.CUSTOM) {
potionCustomLogic(player, hand, heldItem);
}
} else if (heldItem.getItem() == Items.BOWL) {
ItemStack stewToGive = new ItemStack(ModItems.stew);
int hunger = 0;
float saturation = 0f;
float multiplier = 1.0f;
for (ItemStack stack : ingredients) {
if (CauldronRegistry.getFoodValues().get(stack.getItem()) != null) {
CauldronFoodValue foodValue = CauldronRegistry.getFoodValues().get(stack.getItem());
hunger += foodValue.hunger * multiplier;
saturation += foodValue.saturation * multiplier;
multiplier *= 0.75;
}
}
NBTTagCompound nbt = new NBTTagCompound();
stewToGive.setTagCompound(nbt);
nbt.setInteger("hunger", hunger);
nbt.setFloat("saturation", saturation);
if (player.addItemStackToInventory(stewToGive)) { //if the player has enough inventory space
heldItem.setCount(heldItem.getCount() - 1);
ingredients.clear();
inv.setFluid(null);
setContainer(ItemStack.EMPTY);
}
} else if (getContainer().isEmpty()) {
ItemStack copy = heldItem.copy();
setContainer(copy);
player.setHeldItem(hand, ItemStack.EMPTY);
}
}
return true;
}
示例4: onBlockActivated
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand,
EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (world.isRemote)
{
return true;
}
TileEntity teUnchecked = world.getTileEntity(pos);
if (!(teUnchecked instanceof TileEntityAnalyzer))
{
return false;
}
TileEntityAnalyzer te = (TileEntityAnalyzer) teUnchecked;
ItemStack stack = player.getHeldItem(hand);
if (!stack.isEmpty() && !player.isSneaking())
{
ItemStack insertStack = stack.copy();
if (stack.getItem().equals(ModRegistry.BLANK_PARCHMENT))
{
List<NotebookCategory> unlockable = ArcaneMagicAPI.getAnalyzer()
.getAnalysisResults(te.getStack(0).copy());
if (!te.getStack(0).isEmpty() && unlockable.size() > 0 && te.getStack(1).isEmpty())
{
stack.shrink(1);
te.setStack(1, new ItemStack(ModRegistry.BLANK_PARCHMENT));
}
} else if (te.getStack(0).isEmpty())
{
stack.shrink(1);
insertStack.setCount(1);
player.setHeldItem(hand, stack);
te.setPlayer(player);
te.setStack(0, insertStack);
te.markDirty();
world.playSound(player, pos, SoundEvents.ENTITY_ITEMFRAME_ADD_ITEM, SoundCategory.BLOCKS, 1, 1);
}
} else if (player.isSneaking())
{
ItemStack toExtract = te.getStack(0).copy();
if (!toExtract.isEmpty())
{
if (!world.isRemote)
{
if (player.addItemStackToInventory(toExtract.copy()))
{
te.setStack(0, ItemStack.EMPTY);
te.markDirty();
}
} else
{
world.playSound(player, pos, SoundEvents.ENTITY_ITEMFRAME_REMOVE_ITEM, SoundCategory.BLOCKS, 1, 1);
}
}
}
return true;
}
示例5: onBlockActivated
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand,
EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (world.isRemote)
{
return true;
}
TileEntity te = world.getTileEntity(pos);
if (!(te instanceof TileEntityWritingDesk))
{
return false;
}
ItemStack stack = player.getHeldItem(hand);
int slot = 0;
IItemHandler cap = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
if (stack != null && !stack.isEmpty() && !player.isSneaking())
{
ItemStack insertStack = stack.copy();
ItemStack remain = cap.insertItem(slot, insertStack, false);
if (remain.getCount() != insertStack.getCount())
{
if (!world.isRemote)
{
player.setHeldItem(hand, remain);
te.markDirty();
} else
{
world.playSound(player, pos, SoundEvents.ENTITY_ITEMFRAME_ADD_ITEM, SoundCategory.BLOCKS, 1, 1);
}
}
} else if (player.isSneaking())
{
ItemStack toExtract = cap.getStackInSlot(slot);
if (toExtract != null && !toExtract.isEmpty())
{
if (!world.isRemote)
{
if (player.addItemStackToInventory(toExtract.copy()))
{
cap.getStackInSlot(slot).setCount(0);
te.markDirty();
}
} else
{
world.playSound(player, pos, SoundEvents.ENTITY_ITEMFRAME_REMOVE_ITEM, SoundCategory.BLOCKS, 1, 1);
}
}
}
return true;
}