本文整理汇总了Java中net.minecraftforge.items.ItemHandlerHelper.canItemStacksStack方法的典型用法代码示例。如果您正苦于以下问题:Java ItemHandlerHelper.canItemStacksStack方法的具体用法?Java ItemHandlerHelper.canItemStacksStack怎么用?Java ItemHandlerHelper.canItemStacksStack使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraftforge.items.ItemHandlerHelper
的用法示例。
在下文中一共展示了ItemHandlerHelper.canItemStacksStack方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: insertItem
import net.minecraftforge.items.ItemHandlerHelper; //导入方法依赖的package包/类
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
if(stack.isEmpty()) return ItemStack.EMPTY;
if(!getKey().isPresent() || isEntangled(stack)) return stack;
ItemStack existing = getStackInSlot(slot);
int limit = stack.getMaxStackSize();
if(!existing.isEmpty()) {
if(!ItemHandlerHelper.canItemStacksStack(stack, existing)) {
return stack;
}
limit -= existing.getCount();
}
if(limit <= 0) return stack;
boolean reachedLimit = stack.getCount() > limit;
if(!simulate) {
if(existing.isEmpty()) {
setStackInSlot(slot, reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, limit) : stack);
} else {
existing.grow(reachedLimit ? limit : stack.getCount());
setStackInSlot(slot, existing);
}
onChange(slot);
}
return reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, stack.getCount() - limit) : ItemStack.EMPTY;
}
示例2: dropItems
import net.minecraftforge.items.ItemHandlerHelper; //导入方法依赖的package包/类
private void dropItems() {
if(world.getTotalWorldTime() % 10 != 0) return;
applyGravity(repulse, false);
IItemHandler handler = from.getKey();
ISidedInventory sidedInv = from.getValue();
Vector3 spawn = Vector3.create(getPos()).add(0.5D).offset(getFacingLazy(), 1);
for(int slot = 0; slot < handler.getSlots(); slot++) {
ItemStack inSlot = handler.getStackInSlot(slot);
if(!inSlot.isEmpty()
&& (lookup.isEmpty() || ItemHandlerHelper.canItemStacksStack(lookup, inSlot))
&& (sidedInv == null || sidedInv.canExtractItem(slot, inSlot, getFacingLazy()))) {
ItemStack out = handler.extractItem(slot, Integer.MAX_VALUE, false);
EntityTemporalItem entity = new EntityTemporalItem(world, spawn.x, spawn.y, spawn.z, out);
impulseEntityItem(spawn, entity);
world.spawnEntity(entity);
break;
}
}
}
示例3: transferIn
import net.minecraftforge.items.ItemHandlerHelper; //导入方法依赖的package包/类
private boolean transferIn(BlockPos pos, ItemStack inserted, boolean test) {
EnumFacing facing = getFacing();
Pair<IItemHandler, ISidedInventory> inv = getInventory(pos, facing);
if(inv.getKey() != null) {
IItemHandler handler = inv.getKey();
ISidedInventory tile = inv.getValue();
for(int slot = 0; slot < handler.getSlots(); slot++) {
ItemStack inSlot = handler.getStackInSlot(slot);
if(tile != null && !tile.canInsertItem(slot, inserted, facing)) return false;
if(inSlot.isEmpty() || (ItemHandlerHelper.canItemStacksStack(inSlot, inserted) && (inSlot.getCount() < inSlot.getMaxStackSize() && inSlot.getCount() < handler.getSlotLimit(slot)))) {
return handler.insertItem(slot, inserted, test) != inserted;
}
}
}
return false;
}
示例4: getItemStackLimit
import net.minecraftforge.items.ItemHandlerHelper; //导入方法依赖的package包/类
@Override
public int getItemStackLimit(ItemStack stack)
{
ItemStack currentStack = getStack();
int maxAdd = stack.getMaxStackSize();
if(currentStack == null ) return 64;
if(!ItemHandlerHelper.canItemStacksStack(stack, currentStack)) return 64;
int stackSize = currentStack.getCount() + stack.getCount();
if(stackSize > maxAdd) stackSize = maxAdd;
return stackSize;
}
示例5: insertItem
import net.minecraftforge.items.ItemHandlerHelper; //导入方法依赖的package包/类
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
if (!ItemStackTools.isValid(stack))
return ItemStackTools.getEmptyStack();
validateSlotIndex(slot);
ItemStack existing = this.items.get(slot);
int limit = getStackLimit(slot, stack);
if (!ItemStackTools.isNullStack(existing))
{
if (!ItemHandlerHelper.canItemStacksStack(stack, existing))
return stack;
limit -= ItemStackTools.getStackSize(existing);
}
if (limit <= 0)
return stack;
boolean reachedLimit = ItemStackTools.getStackSize(stack) > limit;
if (!simulate)
{
if (ItemStackTools.isNullStack(existing))
{
this.items.set(slot, reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, limit) : stack);
}
else
{
ItemStackTools.incStackSize(existing, reachedLimit ? limit : ItemStackTools.getStackSize(stack));
}
onContentsChanged(slot);
}
return reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, ItemStackTools.getStackSize(stack) - limit) : null;
}
示例6: insertItem
import net.minecraftforge.items.ItemHandlerHelper; //导入方法依赖的package包/类
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate)
{
if (ItemStackTools.isEmpty(stack))
return ItemStackTools.getEmptyStack();
ItemStack existing = crate.getStack();
int limit = getStackLimit(slot, stack);
if (ItemStackTools.isValid(existing))
{
if (!ItemHandlerHelper.canItemStacksStack(stack, existing))
return stack;
limit -= ItemStackTools.getStackSize(existing);
}
if (limit <= 0)
return stack;
boolean reachedLimit = ItemStackTools.getStackSize(stack) > limit;
if (!simulate)
{
if (ItemStackTools.isEmpty(existing))
{
crate.setStack(reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, limit) : stack);
}
else
{
ItemStackTools.incStackSize(existing, reachedLimit ? limit : ItemStackTools.getStackSize(stack));
crate.setStack(existing);
}
}
return reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, ItemStackTools.getStackSize(stack) - limit) : ItemStackTools.getEmptyStack();
}
示例7: insertItem
import net.minecraftforge.items.ItemHandlerHelper; //导入方法依赖的package包/类
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate)
{
if (stack.isEmpty()) return ItemStack.EMPTY;
validateSlotIndex(slot);
if (!canInsert(slot, stack)) return stack;
ItemStack existing = slots[slot];
int limit = getStackLimit(slot, stack);
if (!existing.isEmpty())
{
if (!ItemHandlerHelper.canItemStacksStack(stack, existing)) return stack;
limit -= existing.getCount();
}
if (limit <= 0) return stack;
boolean reachedLimit = stack.getCount() > limit;
if (!simulate)
{
if (existing.isEmpty())
slots[slot] = reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, limit) : stack;
else existing.grow(reachedLimit ? limit : stack.getCount());
onSlotChanged();
}
return reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, stack.getCount() - limit) : ItemStack.EMPTY;
}
示例8: insertItem
import net.minecraftforge.items.ItemHandlerHelper; //导入方法依赖的package包/类
@Nonnull @Override public ItemStack insertItem(int slot, @Nonnull ItemStack is, boolean sim) {
if (is.isEmpty())
return ItemStack.EMPTY;
checkSlot(slot);
if ((slot == 0 && TileEntityFurnace.getItemBurnTime(is) == 0) || (slot == 1 && !FluxGenRecipes.isCatalyst(is)))
return is;
int l = is.getMaxStackSize();
if (l > 64) l = 64;
int sc = is.getCount();
ItemStack xis = items[slot];
if (!xis.isEmpty()) {
if (!ItemHandlerHelper.canItemStacksStack(is, xis))
return is;
l -= xis.getCount();
}
if (0 >= l)
return is;
boolean rl = sc > l;
if (!sim) {
if (xis.isEmpty())
items[slot] = rl ? ItemHandlerHelper.copyStackWithSize(is, l) : is;
else
xis.grow(rl ? l : sc);
isDirty = true;
}
return rl ? ItemHandlerHelper.copyStackWithSize(is, sc - l) : ItemStack.EMPTY;
}
示例9: insertItem
import net.minecraftforge.items.ItemHandlerHelper; //导入方法依赖的package包/类
@Override
public ItemStack insertItem(int index, ItemStack stack, boolean simulate)
{
if (index >= inventorySlots.size())
{
if (!simulate)
{
inventorySlots.add(stack.copy());
onContentsChanged();
}
return ItemStack.EMPTY;
}
ItemStack remaining = stack.copy();
ItemStack slot = inventorySlots.get(index);
if (slot.getCount() > 0)
{
int max = Math.min(remaining.getMaxStackSize(), 64);
int transfer = Math.min(remaining.getCount(), max - slot.getCount());
if (transfer > 0 && ItemHandlerHelper.canItemStacksStack(remaining, slot))
{
if (!simulate) slot.grow(transfer);
remaining.shrink(transfer);
if (remaining.getCount() <= 0)
remaining = ItemStack.EMPTY;
}
}
if (!simulate) onContentsChanged();
return remaining;
}
示例10: insertItem
import net.minecraftforge.items.ItemHandlerHelper; //导入方法依赖的package包/类
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate)
{
if (!Config.isItemStackAllowed(stack))
return stack;
if (stack.getCount() <= 0)
return ItemStack.EMPTY;
validateSlotIndex(slot);
ItemStack existing = getStackInSlot(slot);
int limit = stack.getMaxStackSize();
if (existing.getCount() > 0)
{
if (!ItemHandlerHelper.canItemStacksStack(stack, existing))
return stack;
limit -= existing.getCount();
}
if (limit <= 0)
return stack;
boolean reachedLimit = stack.getCount() > limit;
if (!simulate)
{
if (existing.getCount() <= 0)
{
existing = reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, limit) : stack;
}
else
{
existing.grow(reachedLimit ? limit : stack.getCount());
}
setStackInSlot(slot, existing);
}
return reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, stack.getCount() - limit) : ItemStack.EMPTY;
}
示例11: tryAbsorbDroppedItem
import net.minecraftforge.items.ItemHandlerHelper; //导入方法依赖的package包/类
private boolean tryAbsorbDroppedItem(EntityItem item, IBlockState state)
{
ItemStack newStack = Prep1_11.getEmptyStack();
ItemStack stack = item.getItem();
switch(mode)
{
case DIFFUSION:
if(isIngredientPresent(stack)) return false;
if(stack.getItem() == Items.BOOK || stack.isItemEnchanted())
{
newStack = stack.copy();
newStack.setCount(1);
if(!world.isRemote) stack.shrink(1);
}
break;
case REPAIR:
if(pendingIngredients.isEmpty()) return false;
RecipeElement currentIngredient = pendingIngredients.peek();
if(currentIngredient.matches(stack))
{
newStack = stack.copy();
newStack.setCount(Math.min(currentIngredient.getStackSize(), stack.getCount()));
currentIngredient.setStackSize(currentIngredient.getStackSize() - Math.min(currentIngredient.getStackSize(), stack.getCount()));
if(currentIngredient.getStackSize() <= 0)
{
pendingIngredients.pop();
}
if(!world.isRemote) stack.shrink(newStack.getCount());
markDirty();
}
break;
default:
break;
}
if(newStack == null) return false;
boolean slotFound = false;
if(newStack.isItemEnchanted())
{
mainHandler.setStackInSlot(SLOT_ENCH_ITEM, newStack);
slotFound = true;
}
else
{
//attempt to insert stacks into inv
for(int s = SLOT_ENCH_ITEM + 1; s < mainHandler.getSlots(); s++)
{
ItemStack slotStack = mainHandler.getStackInSlot(s);
if (ItemHandlerHelper.canItemStacksStack(newStack, slotStack))
{
CapUtils.incrementStack(mainHandler, s, newStack.getCount());
slotFound = true;
break;
}
if(Prep1_11.isEmpty(slotStack))
{
mainHandler.setStackInSlot(s, newStack);
slotFound = true;
break;
}
}
}
return slotFound;
}
示例12: exportItem
import net.minecraftforge.items.ItemHandlerHelper; //导入方法依赖的package包/类
/**
* Attempt to export the given stack (usually a custom recipe result) to the given slots.
* @return Leftover items that weren't added to the slots, or null if all found a home.
*/
public ItemStack exportItem(ItemStack export, int[] slots, boolean simulate)
{
int simulatedExportStackSize = export.getCount();
for(int i : slots)
{
ItemStack stackInSlot = getStackInSlot(i);
if(stackInSlot.isEmpty())
{
if(!simulate)
setInventorySlotContents(i, export);
return ItemStack.EMPTY;
}
else if(ItemHandlerHelper.canItemStacksStack(stackInSlot, export))
{
int maxStack = Math.min(this.getInventoryStackLimit(), stackInSlot.getMaxStackSize());
int amountToMove = Math.min(maxStack - stackInSlot.getCount(), export.getCount());
if(!simulate)
{
stackInSlot.grow(amountToMove);
export.shrink(amountToMove);
if(export.getCount() <= 0)
return ItemStack.EMPTY;
}
else
{
simulatedExportStackSize -= amountToMove;
if(simulatedExportStackSize <= 0)
return ItemStack.EMPTY;
}
}
}
if(simulate)
{
ItemStack ret = export.copy();
ret.setCount(simulatedExportStackSize);
return ret;
}
else
{
markDirty();
}
return export;
}