本文整理汇总了Java中net.minecraftforge.items.IItemHandlerModifiable.getSlots方法的典型用法代码示例。如果您正苦于以下问题:Java IItemHandlerModifiable.getSlots方法的具体用法?Java IItemHandlerModifiable.getSlots怎么用?Java IItemHandlerModifiable.getSlots使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraftforge.items.IItemHandlerModifiable
的用法示例。
在下文中一共展示了IItemHandlerModifiable.getSlots方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extract
import net.minecraftforge.items.IItemHandlerModifiable; //导入方法依赖的package包/类
public static ItemStack extract(TileEntity tile, EnumFacing from, boolean fullStack) {
if (tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, from)) {
IItemHandlerModifiable handler = (IItemHandlerModifiable) tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, from);
if (handler != null) {
int invSize = handler.getSlots();
for (int i = 0; i < invSize; i++) {
ItemStack current = handler.getStackInSlot(i);
if (current != null && !current.isEmpty() && current.getItem() != Items.AIR) {
ItemStack stack = handler.extractItem(i, !fullStack ? 1 : current.getCount(), false);
return stack;
}
}
}
} // TODO: TileEntities that don't have capabilities - needs testing
return null;
}
示例2: findItemsIndexedInInventoryFuel
import net.minecraftforge.items.IItemHandlerModifiable; //导入方法依赖的package包/类
public static Map<Integer, ItemStack> findItemsIndexedInInventoryFuel(IItemHandlerModifiable handler, @Nullable NBTTagCompound matchNBTTag) {
Map<Integer, ItemStack> stacksOut = new HashMap<>();
for (int j = 0; j < handler.getSlots(); j++) {
ItemStack s = handler.getStackInSlot(j);
if (TileEntityFurnace.getItemBurnTime(s) > 0 && NBTMatchingHelper.matchNBTCompound(matchNBTTag, s.getTagCompound())) {
stacksOut.put(j, s.copy());
}
}
return stacksOut;
}
示例3: findItemsIndexedInInventoryOreDict
import net.minecraftforge.items.IItemHandlerModifiable; //导入方法依赖的package包/类
public static Map<Integer, ItemStack> findItemsIndexedInInventoryOreDict(IItemHandlerModifiable handler, String oreDict, @Nullable NBTTagCompound matchNBTTag) {
Map<Integer, ItemStack> stacksOut = new HashMap<>();
for (int j = 0; j < handler.getSlots(); j++) {
ItemStack s = handler.getStackInSlot(j);
if(s.isEmpty()) continue;
int[] ids = OreDictionary.getOreIDs(s);
for (int id : ids) {
if(OreDictionary.getOreName(id).equals(oreDict) && NBTMatchingHelper.matchNBTCompound(matchNBTTag, s.getTagCompound())) {
stacksOut.put(j, s.copy());
}
}
}
return stacksOut;
}
示例4: findItemsIndexedInInventory
import net.minecraftforge.items.IItemHandlerModifiable; //导入方法依赖的package包/类
public static Map<Integer, ItemStack> findItemsIndexedInInventory(IItemHandlerModifiable handler, ItemStack match, boolean strict, @Nullable NBTTagCompound matchNBTTag) {
Map<Integer, ItemStack> stacksOut = new HashMap<>();
for (int j = 0; j < handler.getSlots(); j++) {
ItemStack s = handler.getStackInSlot(j);
if ((strict ? matchStacks(s, match) : matchStackLoosely(s, match)) && NBTMatchingHelper.matchNBTCompound(matchNBTTag, s.getTagCompound())) {
stacksOut.put(j, s.copy());
}
}
return stacksOut;
}
示例5: breakBlock
import net.minecraftforge.items.IItemHandlerModifiable; //导入方法依赖的package包/类
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { // Drop item when block breaks
TileEntity t = worldIn.getTileEntity(pos);
if(!(t instanceof IItemHandlerModifiable)) return;
IItemHandlerModifiable h = (IItemHandlerModifiable) t;
for(int i = 0; i<h.getSlots(); ++i) {
if(h.getStackInSlot(i)!=null && h.getStackInSlot(i).stackSize>0)
InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), h.getStackInSlot(i));
}
super.breakBlock(worldIn, pos, state);
}
示例6: 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);
}
示例7: 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;
}
示例8: isSlotMatching
import net.minecraftforge.items.IItemHandlerModifiable; //导入方法依赖的package包/类
/**
* Compares a given ItemStack with the one at a slot of an inventory of an entity
*
* @param entity the entity
* @param slot the inventory slot to replace corresponding to a slot shortcut (see {@link #getSlotForShortcut(String)}
* @param stack the item stack to compare (the item and the nbt tag can be null if they shouldn't be compared).
* @param noMeta whether to compare metadata
* @param equalLists The opposite of the "listContains" parameter of {@link #nbtContains(NBTBase, NBTBase, boolean)}
* @return whether the two ItemStacks are equal
*/
public static boolean isSlotMatching(Entity entity, int slot, ItemStack stack, boolean noMeta, boolean equalLists) {
if (entity instanceof IInventory) return isSlotMatching((IInventory) entity, slot, stack, noMeta, equalLists);
ItemStack stackInSlot;
if (slot >= 400 && slot < 500 && entity instanceof EntityHorse)
slot -= 300;
if (slot >= 0 && slot < 100 && entity instanceof EntityLivingBase) {
if (slot >= EntityEquipmentSlot.values().length) return false;
stackInSlot = ((EntityLivingBase) entity).getItemStackFromSlot(EntityEquipmentSlot.values()[slot]);
}
else if (slot >= 100 && slot < 200) {
slot -= 100;
IItemHandler h = entity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
if (!(h instanceof IItemHandlerModifiable)) return false;
IItemHandlerModifiable inventory = (IItemHandlerModifiable) h;
if (slot >= inventory.getSlots()) return false;
else stackInSlot = inventory.getStackInSlot(slot);
}
else if (slot >= 200 && slot < 300 && entity instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) entity;
slot -= 200;
if (slot >= player.getInventoryEnderChest().getSizeInventory()) return false;
else stackInSlot = player.getInventoryEnderChest().getStackInSlot(slot);
}
else if (slot >= 300 && slot < 400 && entity instanceof EntityVillager) {
EntityVillager villager = (EntityVillager) entity;
slot -= 300;
if (slot >= villager.getVillagerInventory().getSizeInventory()) return false;
else stackInSlot = villager.getVillagerInventory().getStackInSlot(slot);
}
else return false;
if (stack == ItemStack.EMPTY || stackInSlot == ItemStack.EMPTY) return stackInSlot == ItemStack.EMPTY && stack == ItemStack.EMPTY;
else {
boolean matches = stack.getItem() == null || stack.getItem() == stackInSlot.getItem();
matches = matches && (noMeta || stack.getItemDamage() == stackInSlot.getItemDamage());
matches = matches && (stack.isEmpty() || stack.getCount() == stackInSlot.getCount());
matches = matches && nbtContains(stackInSlot.getTagCompound(), stack.getTagCompound(), !equalLists);
return matches;
}
}
示例9: 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);
}
}