本文整理匯總了Java中net.minecraftforge.items.ItemStackHandler類的典型用法代碼示例。如果您正苦於以下問題:Java ItemStackHandler類的具體用法?Java ItemStackHandler怎麽用?Java ItemStackHandler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ItemStackHandler類屬於net.minecraftforge.items包,在下文中一共展示了ItemStackHandler類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getRecipeIngredients
import net.minecraftforge.items.ItemStackHandler; //導入依賴的package包/類
private ItemStack[] getRecipeIngredients(ItemStackHandler inputStacks) {
List<ItemStack> enchantedBooks = new ItemStackHandlerIterable(inputStacks)
.stream()
.filter(book -> book.getItem() == Items.ENCHANTED_BOOK)
.collect(Collectors.toList());
if (enchantedBooks.isEmpty()) return null;
for (ItemStack inputStack : new ItemStackHandlerIterable(inputStacks)) {
if ((inputStack.isItemEnchantable() || inputStack.isItemEnchanted()) && inputStack.getItem() != Items.ENCHANTED_BOOK) {
for (ItemStack enchantedBook : enchantedBooks) {
Map<Enchantment, Integer> bookMap = EnchantmentHelper.getEnchantments(enchantedBook);
for (Map.Entry<Enchantment, Integer> entry : bookMap.entrySet()) {
if (entry.getKey().canApply(inputStack)) {
return new ItemStack[]{ inputStack, enchantedBook};
}
}
}
}
}
return null;
}
示例2: craftRecipe
import net.minecraftforge.items.ItemStackHandler; //導入依賴的package包/類
@Override
public NonNullList<ItemStack> craftRecipe(ItemStackHandler inputStacks) {
ItemStack enchantedStack = getDisenchantableItem(inputStacks);
getBook(inputStacks).shrink(1);
// take a random enchantment off the enchanted item...
Map<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(enchantedStack);
List<Enchantment> l = new ArrayList<>(enchantments.keySet());
Enchantment strippedEnchantment = l.get(new Random().nextInt(l.size()));
int level = enchantments.get(strippedEnchantment);
enchantments.remove(strippedEnchantment);
EnchantmentHelper.setEnchantments(enchantments, enchantedStack);
// ...and create an enchanted book with it
ItemStack enchantedBook = new ItemStack(Items.ENCHANTED_BOOK);
EnchantmentHelper.setEnchantments(ImmutableMap.of(strippedEnchantment, level), enchantedBook);
return NonNullList.from(ItemStack.EMPTY, enchantedBook);
}
示例3: getChargedDispenserUpgradeDrone
import net.minecraftforge.items.ItemStackHandler; //導入依賴的package包/類
private static EntityDrone getChargedDispenserUpgradeDrone(World world) {
EntityDrone drone = new EntityDrone(world);
NBTTagCompound tag = new NBTTagCompound();
drone.writeEntityToNBT(tag);
ItemStackHandler upgrades = new ItemStackHandler(9);
upgrades.setStackInSlot(0, new ItemStack(ItemRegistry.getInstance().getUpgrade(EnumUpgrade.DISPENSER), 64));
upgrades.setStackInSlot(1, new ItemStack(ItemRegistry.getInstance().getUpgrade(EnumUpgrade.SPEED), 10));
tag.setTag(ChargeableItemHandler.NBT_UPGRADE_TAG, upgrades.serializeNBT());
tag.setTag("Inventory", new NBTTagCompound());
tag.setFloat("currentAir", 100000);
drone.readEntityFromNBT(tag);
// FIXME: we really need to get a clientside localization here (on the server side)
drone.setCustomNameTag(net.minecraft.util.text.translation.I18n.translateToLocal("drone.amadronDeliveryDrone"));
drone.naturallySpawned = true; // Don't let the drone be dropped when wrenching it.
return drone;
}
示例4: writeToNBT
import net.minecraftforge.items.ItemStackHandler; //導入依賴的package包/類
@Override
public NBTTagCompound writeToNBT(NBTTagCompound tag) {
super.writeToNBT(tag);
tag.setTag("Items", inventory.serializeNBT());
NBTTagCompound tankTag = new NBTTagCompound();
tank.writeToNBT(tankTag);
tag.setTag("tank", tankTag);
ItemStackHandler handler = new ItemStackHandler(getFakePlayer().inventory.getSizeInventory());
for (int i = 0; i < handler.getSlots(); i++) {
handler.setStackInSlot(i, getFakePlayer().inventory.getStackInSlot(i));
}
tag.setTag("droneItems", handler.serializeNBT());
return tag;
}
示例5: importFromChamber
import net.minecraftforge.items.ItemStackHandler; //導入依賴的package包/類
private void importFromChamber(TileEntityPressureChamberValve core) {
ItemStackHandler chamberStacks = core.getStacksInChamber();
for (ItemStack chamberStack : new ItemStackHandlerIterable(chamberStacks)) {
ItemStack inputStack = inventory.getStackInSlot(0);
if ((inputStack.isEmpty() || inputStack.isItemEqual(chamberStack)) && filterHandler.doesItemMatchFilter(chamberStack)) {
int maxAllowedItems = Math.abs(core.getAirHandler(null).getAir()) / PneumaticValues.USAGE_CHAMBER_INTERFACE;
if (maxAllowedItems > 0) {
if (!inputStack.isEmpty()) {
maxAllowedItems = Math.min(maxAllowedItems, chamberStack.getMaxStackSize() - inputStack.getCount());
}
int transferredItems = Math.min(chamberStack.getCount(), maxAllowedItems);
ItemStack toTransferStack = chamberStack.copy().splitStack(transferredItems);
ItemStack excess = inventory.insertItem(0, toTransferStack, true);
if (excess.getCount() < toTransferStack.getCount()) {
// we can transfer at least some of the items
transferredItems = toTransferStack.getCount() - excess.getCount();
core.addAir((core.getAirHandler(null).getAir() > 0 ? -1 : 1) * transferredItems * PneumaticValues.USAGE_CHAMBER_INTERFACE);
toTransferStack.setCount(transferredItems);
inventory.insertItem(0, toTransferStack, false);
chamberStack.shrink(transferredItems);
}
}
}
}
}
示例6: initializeInventories
import net.minecraftforge.items.ItemStackHandler; //導入依賴的package包/類
@Override
protected void initializeInventories() {
super.initializeInventories();
modeList = new LinkedHashMap<>();
EnumDyeColor[] colors = new EnumDyeColor[]{EnumDyeColor.YELLOW, EnumDyeColor.BLUE, EnumDyeColor.GREEN, EnumDyeColor.ORANGE, EnumDyeColor.PURPLE};
for (int i = 0; i < 5; ++i) {
ItemStackHandler item = new ItemStackHandler(2);
this.addInventory(new CustomColoredItemHandler(item, colors[i], "Material process", 50 + 24 * i, 25, 1, 2) {
@Override
public boolean canInsertItem(int slot, ItemStack stack) {
return false;
}
});
this.addInventoryToStorage(item, "item" + i);
modeList.put(item, Mode.NONE);
}
}
示例7: readFromNBT
import net.minecraftforge.items.ItemStackHandler; //導入依賴的package包/類
@Override
public void readFromNBT(NBTTagCompound compound)
{
stacks.clear();
NBTTagList sortStacks = compound.getTagList("sortstacks", 10);
for(int i = 0; i < sortStacks.tagCount(); i++)
{
ItemStackHandler handler = new ItemStackHandler(9);
handler.deserializeNBT(sortStacks.getCompoundTagAt(i));
stacks.add(handler);
}
if(compound.hasKey("defaultsort"))
{
defaultSort = compound.getInteger("defaultsort");
}
super.readFromNBT(compound);
}
示例8: sideHasItem
import net.minecraftforge.items.ItemStackHandler; //導入依賴的package包/類
public boolean sideHasItem(ItemStack stack, EnumFacing side)
{
ItemStackHandler handler = this.getItemHandlerForSide(side);
if(!stack.isEmpty())
{
for(int i = 0; i < items.getSlots(); i++)
{
ItemStack sortStack = handler.getStackInSlot(i);
if(!sortStack.isEmpty() && ItemStack.areItemsEqual(stack, sortStack))
{
return true;
}
}
}
return false;
}
示例9: getCapability
import net.minecraftforge.items.ItemStackHandler; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Nullable
@Override
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
if (capability == CapabilityEnergy.ENERGY) return (T) energyStorage;
else if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
if (facing == null)
return (T) itemHandler;
switch (facing) {
case UP:
return (T) new ItemStackHandler(NonNullList.withSize(1, itemHandler.getStackInSlot(0)));
case DOWN:
return (T) new ItemStackHandler(NonNullList.withSize(1, itemHandler.getStackInSlot(1)));
default:
return (T) itemHandler;
}
}
else return super.getCapability(capability, facing);
}
示例10: craftRecipe
import net.minecraftforge.items.ItemStackHandler; //導入依賴的package包/類
@Override
public NonNullList<ItemStack> craftRecipe(ItemStackHandler inputStacks) {
ItemStack[] recipeIngredients = getRecipeIngredients(inputStacks);
ItemStack enchantedTool = recipeIngredients[0];
ItemStack enchantedBook = recipeIngredients[1];
Map<Enchantment, Integer> bookMap = EnchantmentHelper.getEnchantments(enchantedBook);
bookMap.forEach((enchant, lvl) -> enchantedTool.addEnchantment(enchant, lvl));
enchantedBook.shrink(1);
return NonNullList.from(ItemStack.EMPTY, new ItemStack(Items.BOOK));
}
示例11: getDisenchantableItem
import net.minecraftforge.items.ItemStackHandler; //導入依賴的package包/類
public ItemStack getDisenchantableItem(ItemStackHandler inputStacks){
return new ItemStackHandlerIterable(inputStacks)
.stream()
.filter(stack -> stack.getItem() != Items.ENCHANTED_BOOK && EnchantmentHelper.getEnchantments(stack).size() > 0)
.findFirst()
.orElse(ItemStack.EMPTY);
}
示例12: getBook
import net.minecraftforge.items.ItemStackHandler; //導入依賴的package包/類
public ItemStack getBook(ItemStackHandler inputStacks){
return new ItemStackHandlerIterable(inputStacks)
.stream()
.filter(stack -> stack.getItem() == Items.BOOK)
.findFirst()
.orElse(ItemStack.EMPTY);
}
示例13: getSyncedFieldForField
import net.minecraftforge.items.ItemStackHandler; //導入依賴的package包/類
private static SyncedField getSyncedFieldForField(Field field, Object te) {
if (int.class.isAssignableFrom(field.getType())) return new SyncedInt(te, field);
if (float.class.isAssignableFrom(field.getType())) return new SyncedFloat(te, field);
if (double.class.isAssignableFrom(field.getType())) return new SyncedDouble(te, field);
if (boolean.class.isAssignableFrom(field.getType())) return new SyncedBoolean(te, field);
if (String.class.isAssignableFrom(field.getType())) return new SyncedString(te, field);
if (field.getType().isEnum()) return new SyncedEnum(te, field);
if (ItemStack.class.isAssignableFrom(field.getType())) return new SyncedItemStack(te, field);
if (FluidTank.class.isAssignableFrom(field.getType())) return new SyncedFluidTank(te, field);
if (ItemStackHandler.class.isAssignableFrom(field.getType())) return new SyncedItemStackHandler(te, field);
return null;
}
示例14: readField
import net.minecraftforge.items.ItemStackHandler; //導入依賴的package包/類
public static Object readField(ByteBuf buf, int type) {
switch (type) {
case 0:
return buf.readInt();
case 1:
return buf.readFloat();
case 2:
return buf.readDouble();
case 3:
return buf.readBoolean();
case 4:
return ByteBufUtils.readUTF8String(buf);
case 5:
return buf.readByte();
case 6:
return ByteBufUtils.readItemStack(buf);
case 7:
if (!buf.readBoolean()) return null;
return new FluidStack(FluidRegistry.getFluid(ByteBufUtils.readUTF8String(buf)), buf.readInt(), ByteBufUtils.readTag(buf));
case 8:
try {
PacketBuffer packetBuffer = new PacketBuffer(buf);
NBTTagCompound tag = packetBuffer.readCompoundTag();
if (tag == null) return EmptyHandler.INSTANCE;
ItemStackHandler handler = new ItemStackHandler();
handler.deserializeNBT(tag);
return handler;
} catch (IOException e) {
return EmptyHandler.INSTANCE;
}
}
throw new IllegalArgumentException("Invalid sync type! " + type);
}
示例15: retrieveValue
import net.minecraftforge.items.ItemStackHandler; //導入依賴的package包/類
@Override
protected ItemStackHandler retrieveValue(Field field, Object te) throws Exception {
ItemStackHandler handler = (ItemStackHandler) field.get(te);
ItemStackHandler result = new ItemStackHandler(handler.getSlots());
for (int i = 0; i < handler.getSlots(); i++) {
result.setStackInSlot(i, handler.getStackInSlot(i));
}
return result;
}