本文整理汇总了Java中net.minecraft.inventory.IInventory.setInventorySlotContents方法的典型用法代码示例。如果您正苦于以下问题:Java IInventory.setInventorySlotContents方法的具体用法?Java IInventory.setInventorySlotContents怎么用?Java IInventory.setInventorySlotContents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.inventory.IInventory
的用法示例。
在下文中一共展示了IInventory.setInventorySlotContents方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pullItemFromSlot
import net.minecraft.inventory.IInventory; //导入方法依赖的package包/类
/**
* Pulls from the specified slot in the inventory and places in any available slot in the hopper. Returns true if
* the entire stack was moved
*/
private static boolean pullItemFromSlot(IHopper hopper, IInventory inventoryIn, int index, EnumFacing direction)
{
ItemStack itemstack = inventoryIn.getStackInSlot(index);
if (itemstack != null && canExtractItemFromSlot(inventoryIn, itemstack, index, direction))
{
ItemStack itemstack1 = itemstack.copy();
ItemStack itemstack2 = putStackInInventoryAllSlots(hopper, inventoryIn.decrStackSize(index, 1), (EnumFacing)null);
if (itemstack2 == null || itemstack2.stackSize == 0)
{
inventoryIn.markDirty();
return true;
}
inventoryIn.setInventorySlotContents(index, itemstack1);
}
return false;
}
示例2: generateChestContents
import net.minecraft.inventory.IInventory; //导入方法依赖的package包/类
public static void generateChestContents(Random random, List<WeightedRandomChestContent> listIn, IInventory inv, int max)
{
for (int i = 0; i < max; ++i)
{
WeightedRandomChestContent weightedrandomchestcontent = (WeightedRandomChestContent)WeightedRandom.getRandomItem(random, listIn);
int j = weightedrandomchestcontent.minStackSize + random.nextInt(weightedrandomchestcontent.maxStackSize - weightedrandomchestcontent.minStackSize + 1);
if (weightedrandomchestcontent.theItemId.getMaxStackSize() >= j)
{
ItemStack itemstack1 = weightedrandomchestcontent.theItemId.copy();
itemstack1.stackSize = j;
inv.setInventorySlotContents(random.nextInt(inv.getSizeInventory()), itemstack1);
}
else
{
for (int k = 0; k < j; ++k)
{
ItemStack itemstack = weightedrandomchestcontent.theItemId.copy();
itemstack.stackSize = 1;
inv.setInventorySlotContents(random.nextInt(inv.getSizeInventory()), itemstack);
}
}
}
}
示例3: moveItemsIntoStack
import net.minecraft.inventory.IInventory; //导入方法依赖的package包/类
private static void moveItemsIntoStack(IInventory chest, ItemStack stack)
{
if (stack.getTagCompound() == null)
{
stack.setTagCompound(new NBTTagCompound());
}
NBTTagList nbtList = new NBTTagList();
for (int i = 0; i < chest.getSizeInventory(); ++i)
{
if (!chest.getStackInSlot(i).isEmpty())
{
NBTTagCompound nbtTabCompound2 = new NBTTagCompound();
nbtTabCompound2.setShort("Slot", (short) i);
chest.getStackInSlot(i).copy().writeToNBT(nbtTabCompound2);
chest.setInventorySlotContents(i, ItemStack.EMPTY);
nbtList.appendTag(nbtTabCompound2);
}
}
stack.getTagCompound().setTag("Items", nbtList);
}
示例4: pushItemIInventory
import net.minecraft.inventory.IInventory; //导入方法依赖的package包/类
protected boolean pushItemIInventory(IInventory inventory, int slot) {
if(inventory.getStackInSlot(slot) == null) {
if(debug)
FMLLog.log(Level.INFO, "F");
inventory.setInventorySlotContents(slot, blockItemStack.copy());
blockItemStack = null;
markDirty = true;
} else if(inventory.getStackInSlot(slot).getItem() == blockItemStack.getItem() && inventory.getStackInSlot(slot).stackSize < inventory.getInventoryStackLimit() && inventory.getStackInSlot(slot).stackSize < inventory.getStackInSlot(slot).getMaxStackSize()) {
if(debug)
FMLLog.log(Level.INFO, "G");
blockItemStack.stackSize = blockItemStack.stackSize + inventory.getStackInSlot(slot).stackSize;
inventory.setInventorySlotContents(slot, blockItemStack.copy());
blockItemStack = null;
markDirty = true;
} else {
if(debug)
FMLLog.log(Level.INFO, "Ga");
}
return markDirty;
}
示例5: load
import net.minecraft.inventory.IInventory; //导入方法依赖的package包/类
/**
* Load inventory data from NBT tag
* @param inventory Target inventory
* @param tag tag to load
* @param seed Loading seed
*/
private static void load(IInventory inventory, NBTTagCompound tag, long seed) {
if (tag == null || !Configurator.NATIVE_LOOT) {
return;
}
Random random = new Random(seed);
NBTTagList items = tag.getTagList("Items", Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < items.tagCount() && i < inventory.getSizeInventory(); ++i) {
NBTTagCompound stackTag = items.getCompoundTagAt(i);
String itemName = stackTag.getString("id").replaceAll(".*:", "");
itemName = itemName.isEmpty() ? String.valueOf(stackTag.getShort("id")) : itemName;
Pattern iPattern = Pattern.compile(Pattern.quote(itemName), Pattern.CASE_INSENSITIVE);
UItem item = Utils.select(UItems.items.select(iPattern), random.nextLong());
byte count = items.getCompoundTagAt(i).getByte("Count");
int damage = items.getCompoundTagAt(i).getShort("Damage");
int slot = stackTag.hasKey("Slot", Constants.NBT.TAG_BYTE) ? stackTag.getByte("Slot") : i;
slot = (slot < 0 || slot >= inventory.getSizeInventory()) ? i : slot;
if (item != null && count > 0 && UItems.getPossibleMeta(item).contains(damage)) {
inventory.setInventorySlotContents(slot, new UItemStack(item, count, damage).getItemStack());
}
}
}
示例6: damageItem
import net.minecraft.inventory.IInventory; //导入方法依赖的package包/类
private static void damageItem(EntityPlayer entityPlayer, IInventory inventory, int index, Item shiftedIndex)
{
if (inventory.getStackInSlot(index).getItem() != shiftedIndex)
return;
ItemStack item = inventory.getStackInSlot(index).copy();
if (item == null)
return;
item.damageItem(1 , entityPlayer);
if (item.getItemDamage() != 0 || entityPlayer.capabilities.isCreativeMode)
{
inventory.setInventorySlotContents(index, item);
inventory.getStackInSlot(index).stackSize = inventory.getStackInSlot(index).stackSize + 1;
if (inventory.getStackInSlot(index).stackSize > 2)
inventory.getStackInSlot(index).stackSize = 2;
}
}
示例7: pullItemFromSlot
import net.minecraft.inventory.IInventory; //导入方法依赖的package包/类
/**
* Pulls from the specified slot in the inventory and places in any available slot in the hopper. Returns true if
* the entire stack was moved
*/
private static boolean pullItemFromSlot(IHopper hopper, IInventory inventoryIn, int index, EnumFacing direction)
{
ItemStack itemstack = inventoryIn.getStackInSlot(index);
if (!itemstack.func_190926_b() && canExtractItemFromSlot(inventoryIn, itemstack, index, direction))
{
ItemStack itemstack1 = itemstack.copy();
ItemStack itemstack2 = putStackInInventoryAllSlots(inventoryIn, hopper, inventoryIn.decrStackSize(index, 1), (EnumFacing)null);
if (itemstack2.func_190926_b())
{
inventoryIn.markDirty();
return true;
}
inventoryIn.setInventorySlotContents(index, itemstack1);
}
return false;
}
示例8: fillInventory
import net.minecraft.inventory.IInventory; //导入方法依赖的package包/类
@Override
public void fillInventory(IInventory inventory, Random rand, LootContext context)
{
TileEntityChest chest = (TileEntityChest) inventory;
CustomLootContext.Builder context$builder = new CustomLootContext.Builder((WorldServer) chest.getWorld());
context$builder.withChestPos(chest.getPos());
CustomLootContext customContext = context$builder.build();
List<ItemStack> list = this.generateLootForPools(rand, customContext);
List<Integer> list1 = this.getEmptySlotsRandomized(inventory, rand);
this.shuffleItems(list, list1.size(), rand);
for (ItemStack itemstack : list)
{
if (list1.isEmpty())
{
LootSlashConquer.LOGGER.warn("Tried to over-fill a container");
return;
}
if (itemstack.isEmpty())
{
inventory.setInventorySlotContents(((Integer)list1.remove(list1.size() - 1)).intValue(), ItemStack.EMPTY);
}
else
{
inventory.setInventorySlotContents(((Integer)list1.remove(list1.size() - 1)).intValue(), itemstack);
}
}
}
示例9: readInventory
import net.minecraft.inventory.IInventory; //导入方法依赖的package包/类
public static void readInventory(NBTTagCompound nbt, IInventory inventory) {
if (nbt == null)
return;
if (!nbt.hasKey("Items"))
return;
NBTTagList list = nbt.getTagList("Items", 10);
for (int i = 0; i < list.tagCount(); ++i) {
NBTTagCompound stackTag = list.getCompoundTagAt(i);
int slot = stackTag.getByte("Slot") & 255;
inventory.setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(stackTag));
}
}
示例10: pushItemIInventory
import net.minecraft.inventory.IInventory; //导入方法依赖的package包/类
protected boolean pushItemIInventory(IInventory inventory, int slot) {
if(inventory.getStackInSlot(slot) == null) {
if(debug)
FMLLog.log(Level.INFO, "gF");
inventory.setInventorySlotContents(slot, blockItemStack.copy());
blockItemStack = null;
markDirty = true;
} else {
if(debug)
FMLLog.log(Level.INFO, "gGa");
}
return markDirty;
}
示例11: pushItemIInventory
import net.minecraft.inventory.IInventory; //导入方法依赖的package包/类
protected boolean pushItemIInventory(IInventory inventory, int slot) {
if(blockItemStack.stackSize > 1) {
ItemStack oldStack = blockItemStack.copy();
ItemStack newStack = blockItemStack.splitStack(1);
if(inventory.getStackInSlot(slot) == null) {
if(debug)
FMLLog.log(Level.INFO, "fF");
inventory.setInventorySlotContents(slot, newStack.copy());
newStack = null;
markDirty = true;
} else if(inventory.getStackInSlot(slot).getItem() == newStack.getItem() && inventory.getStackInSlot(slot).stackSize < inventory.getInventoryStackLimit() && inventory.getStackInSlot(slot).stackSize < inventory.getStackInSlot(slot).getMaxStackSize()) {
if(debug)
FMLLog.log(Level.INFO, "fG");
newStack.stackSize += inventory.getStackInSlot(slot).stackSize;
inventory.setInventorySlotContents(slot, newStack.copy());
newStack = null;
markDirty = true;
} else {
if(debug)
FMLLog.log(Level.INFO, "fGa");
}
if(newStack == null || newStack.stackSize == 0) {
if(debug)
FMLLog.log(Level.INFO, "fDa");
markDirty = true;
} else {
blockItemStack = oldStack;
}
}
return markDirty;
}
示例12: insertStack
import net.minecraft.inventory.IInventory; //导入方法依赖的package包/类
/**
* Insert the specified stack to the specified inventory and return any leftover items
*/
private static ItemStack insertStack(IInventory inventoryIn, ItemStack stack, int index, EnumFacing side)
{
ItemStack itemstack = inventoryIn.getStackInSlot(index);
if (canInsertItemInSlot(inventoryIn, stack, index, side))
{
boolean flag = false;
if (itemstack == null)
{
inventoryIn.setInventorySlotContents(index, stack);
stack = null;
flag = true;
}
else if (canCombine(itemstack, stack))
{
int i = stack.getMaxStackSize() - itemstack.stackSize;
int j = Math.min(stack.stackSize, i);
stack.stackSize -= j;
itemstack.stackSize += j;
flag = j > 0;
}
if (flag)
{
if (inventoryIn instanceof TileEntityHopper)
{
TileEntityHopper tileentityhopper = (TileEntityHopper)inventoryIn;
if (tileentityhopper.mayTransfer())
{
tileentityhopper.setTransferCooldown(8);
}
inventoryIn.markDirty();
}
inventoryIn.markDirty();
}
}
return stack;
}
示例13: insertStack
import net.minecraft.inventory.IInventory; //导入方法依赖的package包/类
/**
* Insert the specified stack to the specified inventory and return any leftover items
*/
private static ItemStack insertStack(IInventory inventoryIn, IInventory stack, ItemStack index, int side, EnumFacing p_174916_4_)
{
ItemStack itemstack = stack.getStackInSlot(side);
if (canInsertItemInSlot(stack, index, side, p_174916_4_))
{
boolean flag = false;
boolean flag1 = stack.func_191420_l();
if (itemstack.func_190926_b())
{
stack.setInventorySlotContents(side, index);
index = ItemStack.field_190927_a;
flag = true;
}
else if (canCombine(itemstack, index))
{
int i = index.getMaxStackSize() - itemstack.func_190916_E();
int j = Math.min(index.func_190916_E(), i);
index.func_190918_g(j);
itemstack.func_190917_f(j);
flag = j > 0;
}
if (flag)
{
if (flag1 && stack instanceof TileEntityHopper)
{
TileEntityHopper tileentityhopper1 = (TileEntityHopper)stack;
if (!tileentityhopper1.mayTransfer())
{
int k = 0;
if (inventoryIn != null && inventoryIn instanceof TileEntityHopper)
{
TileEntityHopper tileentityhopper = (TileEntityHopper)inventoryIn;
if (tileentityhopper1.field_190578_g >= tileentityhopper.field_190578_g)
{
k = 1;
}
}
tileentityhopper1.setTransferCooldown(8 - k);
}
}
stack.markDirty();
}
}
return index;
}