本文整理汇总了Java中net.minecraftforge.items.IItemHandler.getSlots方法的典型用法代码示例。如果您正苦于以下问题:Java IItemHandler.getSlots方法的具体用法?Java IItemHandler.getSlots怎么用?Java IItemHandler.getSlots使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraftforge.items.IItemHandler
的用法示例。
在下文中一共展示了IItemHandler.getSlots方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: breakBlock
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
TileEntity tile = worldIn.getTileEntity(pos);
if (tile != null)
{
IItemHandler itemHandler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
if (itemHandler != null)
{
for (int i = 0; i < itemHandler.getSlots(); i++)
{
ItemStack stack = itemHandler.getStackInSlot(i);
if (!stack.isEmpty())
{
InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), stack);
}
}
}
}
super.breakBlock(worldIn, pos, state);
}
示例2: apply
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
/** Applies the recipe to the storage provided, determining whether or not the output should be produced. Optionally
* consumes the items.
*/
public boolean apply(FluidTank tank, IItemHandler inventory, boolean consume) {
if (consume && !apply(tank, inventory, false)) return false; //Always dry-run before destructive ops
if (tank.getFluid()==null) return false;
//Next line shouldn't happen but it pays to plan for the impossible
if (tank.getFluid().getFluid() != FluidRegistry.WATER) return false;
if (tank.getFluidAmount()<water) return false;
FluidStack fluidExtracted = tank.drainInternal(water, consume);
if (fluidExtracted.amount<water) return false;
int remaining = count;
for(int i=0; i<inventory.getSlots(); i++) {
ItemStack stack = inventory.getStackInSlot(i);
if (stack.isEmpty()) continue;
if (item.apply(stack)) {
ItemStack extracted = inventory.extractItem(i, remaining, !consume);
if (extracted.isEmpty()) continue;
remaining -= extracted.getCount();
}
}
return remaining<=0;
}
示例3: breakBlock
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state)
{
TileEntityInfusionAltar te = (TileEntityInfusionAltar) world.getTileEntity(pos);
IItemHandler cap = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
for (int i = 0; i < cap.getSlots(); ++i)
{
ItemStack itemstack = cap.getStackInSlot(i);
if (!itemstack.isEmpty())
{
InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), itemstack);
}
}
super.breakBlock(world, pos, state);
}
示例4: getCraftingResult
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
/**
* Returns an Item that is the result of this recipe
*/
@Override
public ItemStack getCraftingResult(TileEntityOvenBase oven)
{
ItemStack itemstack = getRecipeOutput().copy();
IItemHandler itemHandler = CapUtils.getItemHandler(oven);
if (strangeField)
{
for (int i = 0; i < itemHandler.getSlots(); ++i)
{
ItemStack itemstack1 = itemHandler.getStackInSlot(i);
if (itemstack1 != null && itemstack1.hasTagCompound())
{
itemstack.setTagCompound((NBTTagCompound)itemstack1.getTagCompound().copy());
}
}
}
return itemstack;
}
示例5: getComparatorInputOverride
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
@Override
public int getComparatorInputOverride(IBlockState blockState, World world, BlockPos pos) {
TileEntity tileentity = world.getTileEntity(pos);
if (tileentity!=null && tileentity.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) {
IItemHandler inventory = tileentity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
int capacity = inventory.getSlots();
int filled = 0;
for(int i=0; i<capacity; i++) {
if (!inventory.getStackInSlot(i).isEmpty()) filled++;
}
float fraction = filled / (float)capacity;
return (int)(fraction*15);
} else {
return 0;
}
}
示例6: breakBlock
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state)
{
TileEntityInfernalSmelter te = (TileEntityInfernalSmelter) world.getTileEntity(pos);
IItemHandler cap = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
for (int i = 0; i < cap.getSlots(); ++i)
{
ItemStack itemstack = cap.getStackInSlot(i);
if (!itemstack.isEmpty())
{
InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), itemstack);
}
}
super.breakBlock(world, pos, state);
}
示例7: breakBlock
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
TileEntityPhotoProcessor te = (TileEntityPhotoProcessor) worldIn.getTileEntity(pos);
IItemHandler inv = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP);
for (int i = inv.getSlots() - 1; i >= 0; --i) {
if (inv.getStackInSlot(i) != null) {
Block.spawnAsEntity(worldIn, pos, inv.getStackInSlot(i));
((IItemHandlerModifiable) inv).setStackInSlot(i, null);
}
}
super.breakBlock(worldIn, pos, state);
}
示例8: canHack
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
@Override
public boolean canHack(Entity entity, EntityPlayer player) {
if (entity.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) {
IItemHandler handler = entity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
for (int i = 0; i < handler.getSlots(); i++) {
if (!handler.getStackInSlot(i).isEmpty()) return true;
}
}
return false;
}
示例9: addTileEntitySlots
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
private void addTileEntitySlots()
{
IItemHandler handler = te.getStackHandler();
int xPos = 51;
int yPos = 15;
int colWidth = 18;
for (int i = 0; i < handler.getSlots(); ++i)
{
addSlotToContainer(new SlotItemHandler(handler, i, xPos, yPos));
xPos += colWidth;
}
}
示例10: ContainerBelt
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
public ContainerBelt(IInventory playerInventory, IItemHandler beltInventory, int blockedSlot)
{
beltSlots = beltInventory.getSlots();
int xoff = ((9 - beltSlots) * 18) / 2;
for (int k = 0; k < beltSlots; ++k)
{
this.addSlotToContainer(new SlotBelt(beltInventory, k, 8 + xoff + k * 18, 20));
}
bindPlayerInventory(playerInventory, blockedSlot);
}
示例11: findInventoryContainingMost
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
protected boolean findInventoryContainingMost(List<BlockPos> inventoryList, Predicate<ItemStack> matcher, Consumer<BlockPos> job) {
World world = entity.getEntityWorld();
List<BlockPos> inventories = new ArrayList<>();
Map<BlockPos, Float> countMatching = new HashMap<>();
for (BlockPos pos : inventoryList) {
TileEntity te = world.getTileEntity(pos);
IItemHandler handler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP);
int cnt = 0;
for (int i = 0; i < handler.getSlots(); i++) {
ItemStack stack = handler.getStackInSlot(i);
if (stack == null) {
// There are still bad mods!
String badBlock = world.getBlockState(pos).getBlock().getRegistryName().toString();
MeeCreeps.logger.warn("Block " + badBlock + " is returning null for handler.getStackInSlot()! That's a bug!");
} else if (!stack.isEmpty()) {
if (matcher.test(stack)) {
cnt += stack.getCount();
}
}
}
if (cnt > 0) {
inventories.add(pos);
countMatching.put(pos, (float) cnt);
}
}
if (inventories.isEmpty()) {
return false;
} else {
// Sort so that highest score goes first
inventories.sort((p1, p2) -> Float.compare(countMatching.get(p2), countMatching.get(p1)));
navigateTo(inventories.get(0), job);
return true;
}
}
示例12: dropInventory
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
public static void dropInventory(World world, BlockPos pos, IItemHandler itemHandler)
{
for(int i = 0; i < itemHandler.getSlots(); i++)
{
if(itemHandler.getStackInSlot(i) != null)
{
InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), itemHandler.getStackInSlot(i));
}
}
}
示例13: addStorageSlots
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
private void addStorageSlots()
{
IItemHandler itemHandler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
int xPos = 8;
int yPos = 118;
int slotIndex = 0;
for(int i = 0; i < itemHandler.getSlots(); i++)
{
this.addSlotToContainer(new SlotItemHandler(itemHandler, slotIndex, xPos, yPos));
slotIndex++;
xPos += 18;
}
}
示例14: hasEnoughPuzzleStacks
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
public boolean hasEnoughPuzzleStacks(EntityPlayer player, ItemStack stack) {
int amountLeft = stack.getCount();
if (player != null) {
for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
ItemStack playerStack = player.inventory.getStackInSlot(i);
if (PneumaticCraftUtils.areStacksEqual(playerStack, stack, true, true, false, false)) {
amountLeft -= playerStack.getCount();
if (amountLeft <= 0) return true;
}
}
}
for (EnumFacing d : EnumFacing.VALUES) {
TileEntity te = getWorld().getTileEntity(getPos().offset(d));
if (te != null && te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, d.getOpposite())) {
IItemHandler handler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, d.getOpposite());
for (int slot = 0; slot < handler.getSlots(); slot++) {
ItemStack neighborStack = handler.getStackInSlot(slot);
if (PneumaticCraftUtils.areStacksEqual(neighborStack, stack, true, true, false, false)) {
amountLeft -= neighborStack.getCount();
if (amountLeft <= 0) return true;
}
}
}
}
return false;
}
示例15: getUpgrades
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
public static int getUpgrades(IItemHandler inv, IItemRegistry.EnumUpgrade upgrade) {
int upgrades = 0;
Item upgradeItem = Itemss.upgrades.get(upgrade);
for (int i = 0; i < inv.getSlots(); i++) {
if (inv.getStackInSlot(i).getItem() == upgradeItem) {
upgrades += inv.getStackInSlot(i).getCount();
}
}
return upgrades;
}