本文整理汇总了Java中net.minecraft.inventory.InventoryBasic.getStackInSlot方法的典型用法代码示例。如果您正苦于以下问题:Java InventoryBasic.getStackInSlot方法的具体用法?Java InventoryBasic.getStackInSlot怎么用?Java InventoryBasic.getStackInSlot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.inventory.InventoryBasic
的用法示例。
在下文中一共展示了InventoryBasic.getStackInSlot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onEntityDeath
import net.minecraft.inventory.InventoryBasic; //导入方法依赖的package包/类
@SubscribeEvent
public static void onEntityDeath(LivingDeathEvent event)
{
// if villager death drops are enabled, if the newly dead entity is a villager, and that villager was killed by a player...
if ((ModConfiguration.enableDeathDrops) && (event.getEntityLiving() instanceof EntityVillager) && (event.getSource().getTrueSource() instanceof EntityPlayerMP))
{
// iterate through the itemstacks in the villager's inventory
InventoryBasic inventory = ((EntityVillager)event.getEntityLiving()).getVillagerInventory();
for (int i = 0; i < inventory.getSizeInventory(); i++)
{
// remove the stack from the inventory and spawn it in the world
ItemStack stack = inventory.getStackInSlot(i);
if (stack != ItemStack.EMPTY)
{
event.getEntityLiving().entityDropItem(stack, 0.0F);
}
}
}
}
示例2: writeInventoryBasicToNBT
import net.minecraft.inventory.InventoryBasic; //导入方法依赖的package包/类
public static NBTTagCompound writeInventoryBasicToNBT(final NBTTagCompound tag, final InventoryBasic inventoryBasic) {
if (inventoryBasic.hasCustomInventoryName()) {
tag.setString("CustomName", inventoryBasic.getInventoryName());
}
final NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < inventoryBasic.getSizeInventory(); ++i) {
final ItemStack stackInSlot = inventoryBasic.getStackInSlot(i);
if (stackInSlot != null) {
final NBTTagCompound itemTag = new NBTTagCompound();
itemTag.setByte("Slot", (byte)i);
stackInSlot.writeToNBT(itemTag);
nbttaglist.appendTag((NBTBase)itemTag);
}
}
tag.setTag("Items", (NBTBase)nbttaglist);
return tag;
}
示例3: writeInventoryToNBT
import net.minecraft.inventory.InventoryBasic; //导入方法依赖的package包/类
/**
* Writes an inventory to an NBTTagCompound. Can be used to save an inventory in a
* TileEntity, or perhaps an ItemStack.
*
* @param tag: The NBTTagCompound to write the inventory to.
* @param inventory: The inventory to write to the NBTTagCompound.
* @return NBTTagCompound: The same NBTTagCompound that was passed to this method.
*/
public static NBTTagCompound writeInventoryToNBT (NBTTagCompound tag, InventoryBasic inventory) {
if (inventory.hasCustomName())
tag.setString("CustomName", inventory.getName());
final NBTTagList nbttaglist = new NBTTagList();
for (int slotCount = 0; slotCount < inventory.getSizeInventory(); slotCount++) {
final ItemStack stackInSlot = inventory.getStackInSlot(slotCount);
if (stackInSlot != null) {
final NBTTagCompound itemTag = new NBTTagCompound();
itemTag.setByte("Slot", (byte) slotCount);
stackInSlot.writeToNBT(itemTag);
nbttaglist.appendTag(itemTag);
}
}
tag.setTag("Items", nbttaglist);
return tag;
}
示例4: writeInventoryToNBT
import net.minecraft.inventory.InventoryBasic; //导入方法依赖的package包/类
/**
* Writes an inventory to an NBTTagCompound. Can be used to save an inventory in a
* TileEntity, or perhaps an ItemStack.
*
* @param tag: The NBTTagCompound to write the inventory to.
* @param inventory: The inventory to write to the NBTTagCompound.
* @return NBTTagCompound: The same NBTTagCompound that was passed to this method.
*/
public static NBTTagCompound writeInventoryToNBT (NBTTagCompound tag, InventoryBasic inventory) {
if (inventory.hasCustomName()) {
tag.setString("CustomName", inventory.getName());
}
final NBTTagList nbttaglist = new NBTTagList();
for (int slotCount = 0; slotCount < inventory.getSizeInventory(); slotCount++) {
final ItemStack stackInSlot = inventory.getStackInSlot(slotCount);
if (!stackInSlot.isEmpty()) {
final NBTTagCompound itemTag = new NBTTagCompound();
itemTag.setByte("Slot", (byte) slotCount);
stackInSlot.writeToNBT(itemTag);
nbttaglist.appendTag(itemTag);
}
}
tag.setTag("Items", nbttaglist);
return tag;
}
示例5: addToInventory
import net.minecraft.inventory.InventoryBasic; //导入方法依赖的package包/类
public static void addToInventory(ItemStack itemStack, InventoryBasic inventory) {
if (itemStack != null && itemStack.stackSize != 0 && itemStack.getItem() != null) {
int emptySlot = getFirstEmptyStack(inventory);
if (itemStack.isItemDamaged()) {
if (emptySlot > -1) {
inventory.setInventorySlotContents(emptySlot, itemStack);
}
}
else {
int compatibleSlot = getExistingCompatibleStack(itemStack, inventory);
if (compatibleSlot > -1) {
ItemStack existingStack = inventory.getStackInSlot(compatibleSlot);
existingStack.stackSize += itemStack.stackSize;
}
else if (emptySlot > -1) {
inventory.setInventorySlotContents(emptySlot, itemStack);
}
}
}
}
示例6: dropInventory
import net.minecraft.inventory.InventoryBasic; //导入方法依赖的package包/类
private static void dropInventory(List<EntityItem> drops, EntityVillager villager)
{
// 村人自身のインベントリの内容をドロップ
// InventoryBasicもIterableにしてくれ~
InventoryBasic inv = villager.getVillagerInventory();
final int invElements = inv.getSizeInventory();
for(int i = 0; i < invElements; i++)
{
// スロットごとにItemStackがないか確認
ItemStack stack = inv.getStackInSlot(i);
if(stack == null)
{
continue;
}
// ItemStackがあればそれをドロップアイテムとして登録
EntityItem entityDropItem = new EntityItem(villager.world, villager.posX, villager.posY + 1, villager.posZ, stack);
drops.add(entityDropItem);
}
}
示例7: getFirstEmptyStack
import net.minecraft.inventory.InventoryBasic; //导入方法依赖的package包/类
private static int getFirstEmptyStack(InventoryBasic inventory) {
for (int i = 0; i < inventory.getSizeInventory(); ++i) {
if (inventory.getStackInSlot(i) == null) {
return i;
}
}
return -1;
}
示例8: getExistingCompatibleStack
import net.minecraft.inventory.InventoryBasic; //导入方法依赖的package包/类
private static int getExistingCompatibleStack(ItemStack itemStack, InventoryBasic inventory) {
for (int i = 0; i < inventory.getSizeInventory(); ++i) {
ItemStack existingStack = inventory.getStackInSlot(i);
if (existingStack != null
&& existingStack.getItem() == itemStack.getItem()
&& existingStack.isStackable()
&& existingStack.stackSize + itemStack.stackSize <= existingStack.getMaxStackSize()
&& existingStack.stackSize < inventory.getInventoryStackLimit()
&& (!existingStack.getHasSubtypes() || existingStack.getItemDamage() == itemStack.getItemDamage())
&& ItemStack.areItemStackTagsEqual(existingStack, itemStack)) {
return i;
}
}
return -1;
}
示例9: writeToNBT
import net.minecraft.inventory.InventoryBasic; //导入方法依赖的package包/类
public static void writeToNBT(NBTTagCompound ntb, InventoryBasic inventory) {
NBTTagList nbtTagList = new NBTTagList();
for (int i = 0; i < inventory.getSizeInventory(); ++i) {
ItemStack stack = inventory.getStackInSlot(i);
if (stack != null) {
NBTTagCompound nbtItem = new NBTTagCompound();
nbtItem.setByte("Slot", (byte) i);
stack.writeToNBT(nbtItem);
nbtTagList.appendTag(nbtItem);
}
}
ntb.setTag(NTB_INVENTORY_TAG, nbtTagList);
}
示例10: onInventoryChanged
import net.minecraft.inventory.InventoryBasic; //导入方法依赖的package包/类
/**
* Called by InventoryBasic.onInventoryChanged() on a array that is never filled.
*/
@Override
public void onInventoryChanged(InventoryBasic p_76316_1_)
{
int i = this.getMountArmorValue();
boolean flag = this.isCamelSaddled();
//this.func_110232_cE();
if (this.ticksExisted > 20)
{
if (!(p_76316_1_.getStackInSlot(0) == null)) {
if (p_76316_1_.getStackInSlot(0).getItem() ==Items.saddle){
this.setSaddled(true);
this.playSound("mob.horse.leather", 0.5F, 1.0F);
}
}else
{
this.setSaddled(false);
}
if (i == 0 && i != this.getMountArmorValue())
{
this.playSound("mob.horse.armor", 0.5F, 1.0F);
}
else if (i != this.getMountArmorValue())
{
this.playSound("mob.horse.armor", 0.5F, 1.0F);
}
}
}
示例11: inventoryToTag
import net.minecraft.inventory.InventoryBasic; //导入方法依赖的package包/类
/**
* InventoryBasicをNBTに変換する
* @param inv InventoryBasic
* @param tag 書き込むNBT
*/
public static void inventoryToTag(InventoryBasic inv, NBTTagList tag)
{
int elements = inv.getSizeInventory();
ItemStack[] _inv = new ItemStack[elements];
for(int i = 0; i < elements; i++)
{
_inv[i] = inv.getStackInSlot(i);
}
VillagerData.inventoryToTag(_inv, tag);
}
示例12: updateTask
import net.minecraft.inventory.InventoryBasic; //导入方法依赖的package包/类
/**
* Updates the task
*/
public void updateTask()
{
super.updateTask();
this.theVillager.getLookHelper().setLookPosition((double)this.destinationBlock.getX() + 0.5D, (double)(this.destinationBlock.getY() + 1), (double)this.destinationBlock.getZ() + 0.5D, 10.0F, (float)this.theVillager.getVerticalFaceSpeed());
if (this.getIsAboveDestination())
{
World world = this.theVillager.worldObj;
BlockPos blockpos = this.destinationBlock.up();
IBlockState iblockstate = world.getBlockState(blockpos);
Block block = iblockstate.getBlock();
if (this.field_179501_f == 0 && block instanceof BlockCrops && ((Integer)iblockstate.getValue(BlockCrops.AGE)).intValue() == 7)
{
world.destroyBlock(blockpos, true);
}
else if (this.field_179501_f == 1 && block == Blocks.air)
{
InventoryBasic inventorybasic = this.theVillager.getVillagerInventory();
for (int i = 0; i < inventorybasic.getSizeInventory(); ++i)
{
ItemStack itemstack = inventorybasic.getStackInSlot(i);
boolean flag = false;
if (itemstack != null)
{
if (itemstack.getItem() == Items.wheat_seeds)
{
world.setBlockState(blockpos, Blocks.wheat.getDefaultState(), 3);
flag = true;
}
else if (itemstack.getItem() == Items.potato)
{
world.setBlockState(blockpos, Blocks.potatoes.getDefaultState(), 3);
flag = true;
}
else if (itemstack.getItem() == Items.carrot)
{
world.setBlockState(blockpos, Blocks.carrots.getDefaultState(), 3);
flag = true;
}
}
if (flag)
{
--itemstack.stackSize;
if (itemstack.stackSize <= 0)
{
inventorybasic.setInventorySlotContents(i, (ItemStack)null);
}
break;
}
}
}
this.field_179501_f = -1;
this.runDelay = 10;
}
}
示例13: updateTask
import net.minecraft.inventory.InventoryBasic; //导入方法依赖的package包/类
/**
* Updates the task
*/
public void updateTask()
{
super.updateTask();
this.theVillager.getLookHelper().setLookPosition((double)this.destinationBlock.getX() + 0.5D, (double)(this.destinationBlock.getY() + 1), (double)this.destinationBlock.getZ() + 0.5D, 10.0F, (float)this.theVillager.getVerticalFaceSpeed());
if (this.getIsAboveDestination())
{
World world = this.theVillager.world;
BlockPos blockpos = this.destinationBlock.up();
IBlockState iblockstate = world.getBlockState(blockpos);
Block block = iblockstate.getBlock();
if (this.currentTask == 0 && block instanceof BlockCrops && ((BlockCrops)block).isMaxAge(iblockstate))
{
world.destroyBlock(blockpos, true);
}
else if (this.currentTask == 1 && iblockstate.getMaterial() == Material.AIR)
{
InventoryBasic inventorybasic = this.theVillager.getVillagerInventory();
for (int i = 0; i < inventorybasic.getSizeInventory(); ++i)
{
ItemStack itemstack = inventorybasic.getStackInSlot(i);
boolean flag = false;
if (!itemstack.func_190926_b())
{
if (itemstack.getItem() == Items.WHEAT_SEEDS)
{
world.setBlockState(blockpos, Blocks.WHEAT.getDefaultState(), 3);
flag = true;
}
else if (itemstack.getItem() == Items.POTATO)
{
world.setBlockState(blockpos, Blocks.POTATOES.getDefaultState(), 3);
flag = true;
}
else if (itemstack.getItem() == Items.CARROT)
{
world.setBlockState(blockpos, Blocks.CARROTS.getDefaultState(), 3);
flag = true;
}
else if (itemstack.getItem() == Items.BEETROOT_SEEDS)
{
world.setBlockState(blockpos, Blocks.BEETROOTS.getDefaultState(), 3);
flag = true;
}
}
if (flag)
{
itemstack.func_190918_g(1);
if (itemstack.func_190926_b())
{
inventorybasic.setInventorySlotContents(i, ItemStack.field_190927_a);
}
break;
}
}
}
this.currentTask = -1;
this.runDelay = 10;
}
}
示例14: updateTask
import net.minecraft.inventory.InventoryBasic; //导入方法依赖的package包/类
/**
* Updates the task
*/
public void updateTask()
{
super.updateTask();
this.theVillager.getLookHelper().setLookPosition((double)this.destinationBlock.getX() + 0.5D, (double)(this.destinationBlock.getY() + 1), (double)this.destinationBlock.getZ() + 0.5D, 10.0F, (float)this.theVillager.getVerticalFaceSpeed());
if (this.getIsAboveDestination())
{
World world = this.theVillager.worldObj;
BlockPos blockpos = this.destinationBlock.up();
IBlockState iblockstate = world.getBlockState(blockpos);
Block block = iblockstate.getBlock();
if (this.currentTask == 0 && block instanceof BlockCrops && ((BlockCrops)block).isMaxAge(iblockstate))
{
world.destroyBlock(blockpos, true);
}
else if (this.currentTask == 1 && iblockstate.getMaterial() == Material.AIR)
{
InventoryBasic inventorybasic = this.theVillager.getVillagerInventory();
for (int i = 0; i < inventorybasic.getSizeInventory(); ++i)
{
ItemStack itemstack = inventorybasic.getStackInSlot(i);
boolean flag = false;
if (itemstack != null)
{
if (itemstack.getItem() == Items.WHEAT_SEEDS)
{
world.setBlockState(blockpos, Blocks.WHEAT.getDefaultState(), 3);
flag = true;
}
else if (itemstack.getItem() == Items.POTATO)
{
world.setBlockState(blockpos, Blocks.POTATOES.getDefaultState(), 3);
flag = true;
}
else if (itemstack.getItem() == Items.CARROT)
{
world.setBlockState(blockpos, Blocks.CARROTS.getDefaultState(), 3);
flag = true;
}
else if (itemstack.getItem() == Items.BEETROOT_SEEDS)
{
world.setBlockState(blockpos, Blocks.BEETROOTS.getDefaultState(), 3);
flag = true;
}
}
if (flag)
{
--itemstack.stackSize;
if (itemstack.stackSize <= 0)
{
inventorybasic.setInventorySlotContents(i, (ItemStack)null);
}
break;
}
}
}
this.currentTask = -1;
this.runDelay = 10;
}
}
示例15: updateTask
import net.minecraft.inventory.InventoryBasic; //导入方法依赖的package包/类
/**
* Updates the task
*/
public void updateTask()
{
super.updateTask();
if (this.interactionDelay > 0)
{
--this.interactionDelay;
if (this.interactionDelay == 0)
{
InventoryBasic inventorybasic = this.villager.getVillagerInventory();
for (int i = 0; i < inventorybasic.getSizeInventory(); ++i)
{
ItemStack itemstack = inventorybasic.getStackInSlot(i);
ItemStack itemstack1 = null;
if (itemstack != null)
{
Item item = itemstack.getItem();
if ((item == Items.BREAD || item == Items.POTATO || item == Items.CARROT || item == Items.BEETROOT) && itemstack.stackSize > 3)
{
int l = itemstack.stackSize / 2;
itemstack.stackSize -= l;
itemstack1 = new ItemStack(item, l, itemstack.getMetadata());
}
else if (item == Items.WHEAT && itemstack.stackSize > 5)
{
int j = itemstack.stackSize / 2 / 3 * 3;
int k = j / 3;
itemstack.stackSize -= j;
itemstack1 = new ItemStack(Items.BREAD, k, 0);
}
if (itemstack.stackSize <= 0)
{
inventorybasic.setInventorySlotContents(i, (ItemStack)null);
}
}
if (itemstack1 != null)
{
double d0 = this.villager.posY - 0.30000001192092896D + (double)this.villager.getEyeHeight();
EntityItem entityitem = new EntityItem(this.villager.worldObj, this.villager.posX, d0, this.villager.posZ, itemstack1);
float f = 0.3F;
float f1 = this.villager.rotationYawHead;
float f2 = this.villager.rotationPitch;
entityitem.motionX = (double)(-MathHelper.sin(f1 * 0.017453292F) * MathHelper.cos(f2 * 0.017453292F) * 0.3F);
entityitem.motionZ = (double)(MathHelper.cos(f1 * 0.017453292F) * MathHelper.cos(f2 * 0.017453292F) * 0.3F);
entityitem.motionY = (double)(-MathHelper.sin(f2 * 0.017453292F) * 0.3F + 0.1F);
entityitem.setDefaultPickupDelay();
this.villager.worldObj.spawnEntityInWorld(entityitem);
break;
}
}
}
}
}