本文整理汇总了Java中net.minecraftforge.items.IItemHandlerModifiable.setStackInSlot方法的典型用法代码示例。如果您正苦于以下问题:Java IItemHandlerModifiable.setStackInSlot方法的具体用法?Java IItemHandlerModifiable.setStackInSlot怎么用?Java IItemHandlerModifiable.setStackInSlot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraftforge.items.IItemHandlerModifiable
的用法示例。
在下文中一共展示了IItemHandlerModifiable.setStackInSlot方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: copyInventory
import net.minecraftforge.items.IItemHandlerModifiable; //导入方法依赖的package包/类
private void copyInventory(IItemHandlerModifiable from, int[][] fromSlotIds, IItemHandlerModifiable to, int[][] toSlotIds)
{
for (int i = 0; i < fromSlotIds.length; i++)
{
int[] slotIds = fromSlotIds[i];
for (int j = 0; j < slotIds.length; j++)
{
int fromSlot = slotIds[j];
if (j < toSlotIds[i].length)
{
int toSlot = toSlotIds[i][j];
to.setStackInSlot(toSlot, from.getStackInSlot(fromSlot));
from.setStackInSlot(fromSlot, ItemStack.EMPTY);
}
}
}
}
示例2: setStackInSlot
import net.minecraftforge.items.IItemHandlerModifiable; //导入方法依赖的package包/类
@Override
public void setStackInSlot(int slot, ItemStack stack)
{
int index = getIndexForSlot(slot);
IItemHandlerModifiable handler = getHandlerFromIndex(index);
slot = getSlotFromIndex(slot, index);
handler.setStackInSlot(slot, stack);
}
示例3: consumeFromInventoryFuel
import net.minecraftforge.items.IItemHandlerModifiable; //导入方法依赖的package包/类
public static int consumeFromInventoryFuel(IItemHandlerModifiable handler, int fuelAmtToConsume, boolean simulate, @Nullable NBTTagCompound matchNBTTag) {
Map<Integer, ItemStack> contents = findItemsIndexedInInventoryFuel(handler, matchNBTTag);
if (contents.isEmpty()) {
return fuelAmtToConsume;
}
for (int slot : contents.keySet()) {
ItemStack inSlot = contents.get(slot);
if(inSlot.getItem().hasContainerItem(inSlot)) {
if(inSlot.getCount() > 1) {
continue; //uh... rip. we won't consume 16 buckets at once.
}
ItemStack stack = ForgeHooks.getContainerItem(inSlot);
fuelAmtToConsume -= TileEntityFurnace.getItemBurnTime(inSlot);
if (!simulate) {
handler.setStackInSlot(slot, stack.copy());
}
if (fuelAmtToConsume <= 0) {
break;
}
}
int fuelPer = TileEntityFurnace.getItemBurnTime(inSlot);
int toConsumeDiv = fuelAmtToConsume / fuelPer;
int fuelMod = fuelAmtToConsume % fuelPer;
int toConsume = toConsumeDiv + (fuelMod > 0 ? 1 : 0);
int toRemove = toConsume > inSlot.getCount() ? inSlot.getCount() : toConsume;
fuelAmtToConsume -= toRemove * fuelPer;
if (!simulate) {
handler.setStackInSlot(slot, copyStackWithSize(inSlot, inSlot.getCount() - toRemove));
}
if (fuelAmtToConsume <= 0) {
break;
}
}
return fuelAmtToConsume;
}
示例4: consumeFromInventory
import net.minecraftforge.items.IItemHandlerModifiable; //导入方法依赖的package包/类
public static boolean consumeFromInventory(IItemHandlerModifiable handler, ItemStack toConsume, boolean simulate, @Nullable NBTTagCompound matchNBTTag) {
Map<Integer, ItemStack> contents = findItemsIndexedInInventory(handler, toConsume, false, matchNBTTag);
if (contents.isEmpty()) return false;
int cAmt = toConsume.getCount();
for (int slot : contents.keySet()) {
ItemStack inSlot = contents.get(slot);
if(inSlot.getItem().hasContainerItem(inSlot)) {
if(inSlot.getCount() > 1) {
continue; //uh... rip. we won't consume 16 buckets at once.
}
ItemStack stack = ForgeHooks.getContainerItem(inSlot);
cAmt--;
if (!simulate) {
handler.setStackInSlot(slot, stack.copy());
}
if (cAmt <= 0) {
break;
}
}
int toRemove = cAmt > inSlot.getCount() ? inSlot.getCount() : cAmt;
cAmt -= toRemove;
if (!simulate) {
handler.setStackInSlot(slot, copyStackWithSize(inSlot, inSlot.getCount() - toRemove));
}
if (cAmt <= 0) {
break;
}
}
return cAmt <= 0;
}
示例5: consumeFromInventoryOreDict
import net.minecraftforge.items.IItemHandlerModifiable; //导入方法依赖的package包/类
public static boolean consumeFromInventoryOreDict(IItemHandlerModifiable handler, String oreName, int amount, boolean simulate, @Nullable NBTTagCompound matchNBTTag) {
Map<Integer, ItemStack> contents = findItemsIndexedInInventoryOreDict(handler, oreName, matchNBTTag);
if (contents.isEmpty()) return false;
int cAmt = amount;
for (int slot : contents.keySet()) {
ItemStack inSlot = contents.get(slot);
if(inSlot.getItem().hasContainerItem(inSlot)) {
if(inSlot.getCount() > 1) {
continue; //uh... rip. we won't consume 16 buckets at once.
}
ItemStack stack = ForgeHooks.getContainerItem(inSlot);
cAmt--;
if (!simulate) {
handler.setStackInSlot(slot, stack.copy());
}
if (cAmt <= 0) {
break;
}
}
int toRemove = cAmt > inSlot.getCount() ? inSlot.getCount() : cAmt;
cAmt -= toRemove;
if (!simulate) {
handler.setStackInSlot(slot, copyStackWithSize(inSlot, inSlot.getCount() - toRemove));
}
if (cAmt <= 0) {
break;
}
}
return cAmt <= 0;
}
示例6: tick
import net.minecraftforge.items.IItemHandlerModifiable; //导入方法依赖的package包/类
@Override
public boolean tick(Color color, IItemHandlerModifiable items, IItemHandlerModifiable output, int ticks) {
if (ticks >= 200) {
CapsUtils.clearInventory(items);
output.setStackInSlot(0, result.copy());
return false;
}
return true;
}
示例7: tick
import net.minecraftforge.items.IItemHandlerModifiable; //导入方法依赖的package包/类
@Override
public boolean tick(Color color, IItemHandlerModifiable items, IItemHandlerModifiable output, int ticks) {
if (ticks >= 200) {
CapsUtils.clearInventory(items);
ItemStack stack = result.copy();
ItemNBTHelper.setInt(stack, "color", color.getRGB());
output.setStackInSlot(0, stack);
return false;
}
return true;
}
示例8: incrementStack
import net.minecraftforge.items.IItemHandlerModifiable; //导入方法依赖的package包/类
public static void incrementStack(IItemHandlerModifiable handler, int slot, int amount)
{
ItemStack stack = handler.getStackInSlot(slot).copy();
stack.grow(amount);
handler.setStackInSlot(slot, stack);
}
示例9: decrementStack
import net.minecraftforge.items.IItemHandlerModifiable; //导入方法依赖的package包/类
public static void decrementStack(IItemHandlerModifiable handler, int slot, int amount)
{
ItemStack stack = handler.getStackInSlot(slot).copy();
stack.shrink(amount);
handler.setStackInSlot(slot, stack);
}
示例10: clearInventory
import net.minecraftforge.items.IItemHandlerModifiable; //导入方法依赖的package包/类
public static void clearInventory(IItemHandlerModifiable inventory) {
for (int i = 0; i < inventory.getSlots(); i++)
inventory.setStackInSlot(i, null);
}
示例11: handleHorseSpecialSlots
import net.minecraftforge.items.IItemHandlerModifiable; //导入方法依赖的package包/类
/**
* Handles special slots of the horse inventory (Slot 0: Saddle, Slot 1: Armor) and
* a special slot 99 which must be a chest (sets whether the horse is chested or not)
*
* @param slot the special horse slot (0, 1 or 99)
* @param horse the horse
* @param stack the item stack (must be saddle for slot 0, any horse armor for slot 1 and chest for slot 99)
* @param tag the new nbt tag of the special slot (works only for 0 and 1, e.g. to enchant the armor)
* @param mergeLists See the "mergeLists" parameter of {@link #nbtMerge(NBTTagCompound, NBTTagCompound, boolean)}
* @return whether the given data was valid (valid slot, valid item, etc.) and whether the special slots could successfully be handled
* @throws Exeption if reflective access failed
*/
private static boolean handleHorseSpecialSlots(AbstractHorse horse, int slot, ItemStack stack, NBTTagCompound tag, boolean mergeLists) throws Exception {
IItemHandler h = horse.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
IItemHandlerModifiable inventory = h instanceof IItemHandlerModifiable ? (IItemHandlerModifiable) h : null;
if (initChest == null || updateSlots == null || inventory == null) return false;
if (tag != null) {
if (slot < inventory.getSlots()) return false;
if (inventory.getStackInSlot(slot) != ItemStack.EMPTY) {
stack = inventory.getStackInSlot(slot).copy();
nbtMerge(stack.getTagCompound(), tag, mergeLists);
inventory.setStackInSlot(slot, stack);
updateSlots.invoke(horse);
}
return true;
}
if (slot == 99 && horse instanceof AbstractChestHorse) {
if (stack == ItemStack.EMPTY || ((AbstractChestHorse) horse).hasChest()) {
((AbstractChestHorse) horse).setChested(false);
initChest.invoke(horse);
return true;
}
if (stack != ItemStack.EMPTY && stack.getItem() == Item.getItemFromBlock(Blocks.CHEST) && !(horse instanceof AbstractChestHorse)) {
((AbstractChestHorse) horse).setChested(true);
initChest.invoke(horse);
return true;
}
return false;
}
else if (slot >= 0 && slot < 2 && slot < inventory.getSlots()) {
if (slot == 0 && stack != ItemStack.EMPTY && stack.getItem() != Items.SADDLE) return false;
else if (slot != 1 || (stack == ItemStack.EMPTY || horse.isArmor(stack)) && horse.wearsArmor()) {
inventory.setStackInSlot(slot, stack == ItemStack.EMPTY ? ItemStack.EMPTY : stack.copy());
updateSlots.invoke(horse);
return true;
}
else return false;
}
else return false;
}
示例12: sortInventoryWithinRangeByTypes
import net.minecraftforge.items.IItemHandlerModifiable; //导入方法依赖的package包/类
private static int sortInventoryWithinRangeByTypes(IItemHandlerModifiable inv, List<ItemTypeByName> types, SlotRange range)
{
int slot = range.first;
int slots = 0;
for (ItemTypeByName type : types)
{
ItemStack stack = type.getStack();
while (true)
{
int max = inv instanceof IItemHandlerSize ? ((IItemHandlerSize) inv).getItemStackLimit(slot, stack) : inv.getSlotLimit(slot);
//System.out.printf("sorting for: %s - slot: %d, max: %d\n", stack.toString(), slot, max);
if (slot >= range.lastInc)
{
//System.out.printf("slot >= range.lastInc\n");
return slots;
}
SlotRange rangeTmp = new SlotRange(slot, range.lastExc - slot);
stack = collectItemsFromInventoryFromSlotRange(inv, stack, rangeTmp, max, false, false);
//System.out.printf("collected stack: %s from range: %s\n", stack, rangeTmp.toString());
if (stack.isEmpty())
{
break;
}
ItemStack stackTmp = inv.getStackInSlot(slot);
// There is a stack in the slot that we are moving items to, try to move the stack towards the end of the inventory
if (stackTmp.isEmpty() == false)
{
//System.out.printf("existing stack: %s\n", inv.getStackInSlot(slot).toString());
rangeTmp = new SlotRange(slot + 1, range.lastExc - (slot + 1));
stackTmp = tryInsertItemStackToInventoryWithinSlotRange(inv, stackTmp, rangeTmp);
//System.out.printf("tried moving stack to range: %s - remaining: %s\n", rangeTmp.toString(), stackTmp);
// Failed to move the stack - this shouldn't happen, we are in trouble now!
if (stackTmp.isEmpty() == false)
{
//System.out.printf("failed moving existing stack, panic mode!\n");
// Try to return all the items currently being worked on and then bail out
tryInsertItemStackToInventoryWithinSlotRange(inv, stackTmp, range);
tryInsertItemStackToInventoryWithinSlotRange(inv, stack, range);
return slots;
}
}
//System.out.printf("setting stack: %s to slot: %d - slots: %d\n", stack, slot, slots + 1);
// Put the stack (collected starting from this slot towards the end of the inventory) into this slot
inv.setStackInSlot(slot, stack);
/*if (inv instanceof IItemHandlerModifiable)
{
((IItemHandlerModifiable)inv).setStackInSlot(slot, stack);
}
else
{
tryToEmptySlot(inv, slots, 128);
inv.insertItem(slot, stack, false);
}*/
slot++;
slots++;
}
}
return slots;
}
示例13: onUpdate
import net.minecraftforge.items.IItemHandlerModifiable; //导入方法依赖的package包/类
@Override
public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean held)
{
if (world.isRemote || world.getTotalWorldTime() % UPDATE_INTERVAL != 0)
return;
IItemHandler handler = entity.getCapability(ITEM_HANDLER_CAPABILITY, null);
if (!(handler instanceof IItemHandlerModifiable))
return;
if (entity instanceof EntityPlayer && ((EntityPlayer)entity).capabilities.isCreativeMode)
return;
IItemHandlerModifiable inventory = (IItemHandlerModifiable)handler;
if (stack.getMetadata() == LIT_METADATA && entity.isWet())
{
for (int i = 0; i < inventory.getSlots(); i++)
{
stack = inventory.getStackInSlot(i);
if (stack != null && stack.getItem() == this && stack.stackSize != 0)
{
stack = stack.copy();
stack.setItemDamage(UNLIT_METADATA);
inventory.setStackInSlot(i, stack);
}
}
playDousingSound(entity.worldObj, entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ);
}
else if (stack.getMetadata() == UNLIT_METADATA && entity.isBurning())
{
for (int i = 0; i < inventory.getSlots(); i++)
{
stack = inventory.getStackInSlot(i);
if (stack != null && stack.getItem() == this && stack.stackSize != 0)
{
stack = stack.copy();
stack.setItemDamage(LIT_METADATA);
inventory.setStackInSlot(i, stack);
}
}
playIgnitingSound(entity.worldObj, entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ);
}
}