Java Code Examples for net.minecraft.util.NonNullList#create()
The following examples show how to use
net.minecraft.util.NonNullList#create() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockSnowTest.java From customstuff4 with GNU General Public License v3.0 | 7 votes |
@Test public void test_getDrops() { ContentBlockSnow content = new ContentBlockSnow(); content.id = "test_getDrops"; content.snowball = new WrappedItemStackConstant(new ItemStack(Items.APPLE, 3)); content.drop = Attribute.constant(new BlockDrop[] {new BlockDrop(new WrappedItemStackConstant(new ItemStack(Items.STICK)), IntRange.create(2, 2))}); Block block = content.createBlock(); NonNullList<ItemStack> drops = NonNullList.create(); block.getDrops(drops, null, null, block.getDefaultState().withProperty(BlockSnow.LAYERS, 5), 0); ItemStack drop1 = drops.get(0); ItemStack drop2 = drops.get(1); assertEquals(2, drops.size()); assertSame(Items.APPLE, drop1.getItem()); assertEquals(18, drop1.getCount()); assertSame(Items.STICK, drop2.getItem()); assertEquals(2, drop2.getCount()); }
Example 2
Source File: MetaTileEntityPrimitiveBlastFurnace.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void readFromNBT(NBTTagCompound data) { super.readFromNBT(data); this.isActive = data.getBoolean("Active"); this.wasActiveAndNeedUpdate = data.getBoolean("WasActive"); this.fuelUnitsLeft = data.getFloat("FuelUnitsLeft"); this.maxProgressDuration = data.getInteger("MaxProgress"); if (maxProgressDuration > 0) { this.currentProgress = data.getInteger("Progress"); NBTTagList itemOutputs = data.getTagList("Outputs", NBT.TAG_COMPOUND); this.outputsList = NonNullList.create(); for (int i = 0; i < itemOutputs.tagCount(); i++) { this.outputsList.add(new ItemStack(itemOutputs.getCompoundTagAt(i))); } } }
Example 3
Source File: InventoryUtils.java From enderutilities with GNU Lesser General Public License v3.0 | 6 votes |
/** * Creates a copy of the non-empty stacks in the inventory and returns it in a new NonNullList. * @param inv * @return a NonNullList containing copies of the non-empty stacks */ public static NonNullList<ItemStack> createInventorySnapshotOfNonEmptySlots(IItemHandler inv) { final int invSize = inv.getSlots(); NonNullList<ItemStack> items = NonNullList.create(); for (int i = 0; i < invSize; i++) { ItemStack stack = inv.getStackInSlot(i); if (stack.isEmpty() == false) { items.add(stack.copy()); } } return items; }
Example 4
Source File: ClientProxy.java From enderutilities with GNU Lesser General Public License v3.0 | 6 votes |
private static void registerItemModelWithVariants(ItemEnderUtilities item) { if (item.isEnabled()) { ResourceLocation[] variants = item.getItemVariants(); NonNullList<ItemStack> items = NonNullList.create(); item.getSubItems(item.getCreativeTab(), items); int i = 0; for (ItemStack stack : items) { ModelResourceLocation mrl = (variants[i] instanceof ModelResourceLocation) ? (ModelResourceLocation)variants[i] : new ModelResourceLocation(variants[i], "inventory"); ModelLoader.setCustomModelResourceLocation(stack.getItem(), stack.getMetadata(), mrl); i++; } } }
Example 5
Source File: ClientProxy.java From enderutilities with GNU Lesser General Public License v3.0 | 6 votes |
private static void registerAllItemBlockModels(BlockEnderUtilities blockIn, String variantPre, String variantPost) { if (blockIn.isEnabled()) { NonNullList<ItemStack> stacks = NonNullList.create(); blockIn.getSubBlocks(blockIn.getCreativeTab(), stacks); String[] names = blockIn.getUnlocalizedNames(); for (ItemStack stack : stacks) { Item item = stack.getItem(); int meta = stack.getMetadata(); ModelResourceLocation mrl = new ModelResourceLocation(item.getRegistryName(), variantPre + names[meta] + variantPost); ModelLoader.setCustomModelResourceLocation(item, meta, mrl); } } }
Example 6
Source File: ItemBookCode.java From Minecoprocessors with GNU General Public License v3.0 | 6 votes |
@SubscribeEvent public static void registerRecipes(final RegistryEvent.Register<IRecipe> event) { NonNullList<Ingredient> lst = NonNullList.create(); lst.add(Ingredient.fromItem(Items.WRITABLE_BOOK)); lst.add(Ingredient.fromItem(BlockMinecoprocessor.ITEM_INSTANCE)); event.getRegistry().register(new ShapelessRecipes("", new ItemStack(ItemBookCode.INSTANCE), lst) { @Override public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv) { NonNullList<ItemStack> l = NonNullList.withSize(inv.getSizeInventory(), ItemStack.EMPTY); for (int i = 0; i < l.size(); ++i) { ItemStack stack = inv.getStackInSlot(i); if (stack.getItem() == BlockMinecoprocessor.ITEM_INSTANCE) { ItemStack returnStack = stack.copy(); returnStack.setCount(1); l.set(i, returnStack); return l; } } throw new RuntimeException("Item to return not found in inventory"); } }.setRegistryName(ItemBookCode.REGISTRY_NAME)); }
Example 7
Source File: AbstractRecipeLogic.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void deserializeNBT(NBTTagCompound compound) { this.workingEnabled = compound.getBoolean("WorkEnabled"); this.progressTime = compound.getInteger("Progress"); if(compound.hasKey("AllowOverclocking")) { this.allowOverclocking = compound.getBoolean("AllowOverclocking"); } this.isActive = false; if (progressTime > 0) { this.isActive = true; this.maxProgressTime = compound.getInteger("MaxProgress"); this.recipeEUt = compound.getInteger("RecipeEUt"); NBTTagList itemOutputsList = compound.getTagList("ItemOutputs", Constants.NBT.TAG_COMPOUND); this.itemOutputs = NonNullList.create(); for (int i = 0; i < itemOutputsList.tagCount(); i++) { this.itemOutputs.add(new ItemStack(itemOutputsList.getCompoundTagAt(i))); } NBTTagList fluidOutputsList = compound.getTagList("FluidOutputs", Constants.NBT.TAG_COMPOUND); this.fluidOutputs = new ArrayList<>(); for (int i = 0; i < fluidOutputsList.tagCount(); i++) { this.fluidOutputs.add(FluidStack.loadFluidStackFromNBT(fluidOutputsList.getCompoundTagAt(i))); } } }
Example 8
Source File: ModHandler.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
public static Collection<ItemStack> getAllSubItems(ItemStack item) { //match subtypes only on wildcard damage value items if (item.getItemDamage() != GTValues.W) return Collections.singleton(item); NonNullList<ItemStack> stackList = NonNullList.create(); CreativeTabs[] visibleTags = item.getItem().getCreativeTabs(); for (CreativeTabs creativeTab : visibleTags) { NonNullList<ItemStack> thisList = NonNullList.create(); item.getItem().getSubItems(creativeTab, thisList); loop: for (ItemStack newStack : thisList) { for (ItemStack alreadyExists : stackList) { if (ItemStack.areItemStacksEqual(alreadyExists, newStack)) continue loop; //do not add equal item stacks } stackList.add(newStack); } } return stackList; }
Example 9
Source File: RecipeShapelessFluidFactory.java From Wizardry with GNU Lesser General Public License v3.0 | 5 votes |
@Override public IRecipe parse(JsonContext context, JsonObject json) { String group = JsonUtils.getString(json, "group", ""); NonNullList<Ingredient> ingredients = NonNullList.create(); for (JsonElement element : JsonUtils.getJsonArray(json, "ingredients")) ingredients.add(CraftingHelper.getIngredient(element, context)); if (ingredients.isEmpty()) throw new JsonParseException("No ingredients in shapeless recipe"); ItemStack result = CraftingHelper.getItemStack(JsonUtils.getJsonObject(json, "result"), context); RecipeShapelessFluid recipe = new RecipeShapelessFluid(group.isEmpty() ? null : new ResourceLocation(group), result, ingredients); return recipe; }
Example 10
Source File: MetaTileEntityFisher.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void update() { super.update(); ItemStack baitStack = importItems.getStackInSlot(0); if (!getWorld().isRemote && energyContainer.getEnergyStored() >= energyAmountPerFish && getTimer() % fishingTicks == 0L && !baitStack.isEmpty()) { WorldServer world = (WorldServer) this.getWorld(); int waterCount = 0; int edgeSize = (int) Math.sqrt(WATER_CHECK_SIZE); for (int x = 0; x < edgeSize; x++){ for (int z = 0; z < edgeSize; z++){ BlockPos waterCheckPos = getPos().down().add(x - edgeSize / 2, 0, z - edgeSize / 2); if (world.getBlockState(waterCheckPos).getBlock() instanceof BlockLiquid && world.getBlockState(waterCheckPos).getMaterial() == Material.WATER) { waterCount++; } } } if (waterCount == WATER_CHECK_SIZE) { LootTable table = world.getLootTableManager().getLootTableFromLocation(LootTableList.GAMEPLAY_FISHING); NonNullList<ItemStack> itemStacks = NonNullList.create(); itemStacks.addAll(table.generateLootForPools(world.rand, new LootContext.Builder(world).build())); if(addItemsToItemHandler(exportItems, true, itemStacks)) { addItemsToItemHandler(exportItems, false, itemStacks); energyContainer.removeEnergy(energyAmountPerFish); baitStack.shrink(1); } } } if(!getWorld().isRemote && getTimer() % 5 == 0) { pushItemsIntoNearbyHandlers(getFrontFacing()); } }
Example 11
Source File: RecipeBuilder.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@SuppressWarnings("CopyConstructorMissesField") protected RecipeBuilder(RecipeBuilder<R> recipeBuilder) { this.recipeMap = recipeBuilder.recipeMap; this.inputs = NonNullList.create(); this.inputs.addAll(recipeBuilder.getInputs()); this.outputs = NonNullList.create(); this.outputs.addAll(GTUtility.copyStackList(recipeBuilder.getOutputs())); this.chancedOutputs = new ArrayList<>(recipeBuilder.chancedOutputs); this.fluidInputs = GTUtility.copyFluidList(recipeBuilder.getFluidInputs()); this.fluidOutputs = GTUtility.copyFluidList(recipeBuilder.getFluidOutputs()); this.duration = recipeBuilder.duration; this.EUt = recipeBuilder.EUt; this.hidden = recipeBuilder.hidden; }
Example 12
Source File: MixinTests.java From customstuff4 with GNU General Public License v3.0 | 5 votes |
public SuperCallTest() { new StringBuilder(); // This is also invokespecial and shouldn't be redirected // invokevirtual but from different class NonNullList<Integer> list = NonNullList.create(); list.add(1); }
Example 13
Source File: WikiRegistry.java From IGW-mod with GNU General Public License v2.0 | 5 votes |
public static List<ItemStack> getItemAndBlockPageEntries(){ // List<ItemStack> entries = new ArrayList<ItemStack>(); NonNullList<ItemStack> entries = NonNullList.create(); for(Map.Entry<String, ItemStack> entry : itemAndBlockPageEntries) { if(entry.getValue().getItemDamage() == OreDictionary.WILDCARD_VALUE) { entry.getValue().getItem().getSubItems(CreativeTabs.SEARCH, entries); } else { entries.add(entry.getValue()); } } return entries; }
Example 14
Source File: ClientProxy.java From Signals with GNU General Public License v3.0 | 5 votes |
private static void registerItemModels(Item item){ NonNullList<ItemStack> stacks = NonNullList.create(); item.getSubItems(CreativeTabs.SEARCH, stacks); for(ItemStack stack : stacks) { registerItemModel(stack); } }
Example 15
Source File: GTRecipeIterators.java From GT-Classic with GNU Lesser General Public License v3.0 | 5 votes |
/** Iterates through loaded itemstacks for all mods **/ public static void postInit() { createMortarRecipe(); if (GTConfig.general.addCompressorRecipesForBlocks) { createUniversalProcessingRecipes(); } for (Item item : Item.REGISTRY) { NonNullList<ItemStack> items = NonNullList.create(); item.getSubItems(CreativeTabs.SEARCH, items); for (ItemStack stack : items) { if (GTConfig.general.oreDictWroughtIron && GTHelperStack.matchOreDict(stack, "ingotWroughtIron") && !GTHelperStack.matchOreDict(stack, "ingotRefinedIron")) { OreDictionary.registerOre("ingotRefinedIron", stack); } if (GTHelperStack.matchOreDict(stack, "ingotAluminum") && !GTHelperStack.matchOreDict(stack, "ingotAluminium")) { OreDictionary.registerOre("ingotAluminium", stack); } if (GTHelperStack.matchOreDict(stack, "dustAluminum") && !GTHelperStack.matchOreDict(stack, "dustAluminium")) { OreDictionary.registerOre("dustAluminium", stack); } if (GTHelperStack.matchOreDict(stack, "ingotChromium") && !GTHelperStack.matchOreDict(stack, "ingotChrome")) { OreDictionary.registerOre("ingotChrome", stack); } } } for (Block block : Block.REGISTRY) { if (block.getDefaultState().getMaterial() == Material.ROCK && !GTHelperStack.oreDictStartsWith(GTMaterialGen.get(block), "ore")) { GTItemJackHammer.rocks.add(block); } } GTMod.logger.info("Jack Hammer stone list populated with " + GTItemJackHammer.rocks.size() + " entries"); }
Example 16
Source File: DamageableShapelessOreRecipe.java From customstuff4 with GNU General Public License v3.0 | 5 votes |
@Override public IRecipe parse(JsonContext context, JsonObject json) { String group = JsonUtils.getString(json, "group", ""); NonNullList<Ingredient> ings = NonNullList.create(); for (JsonElement ele : JsonUtils.getJsonArray(json, "ingredients")) ings.add(CraftingHelper.getIngredient(ele, context)); if (ings.isEmpty()) throw new JsonParseException("No ingredients for shapeless recipe"); ItemStack itemstack = CraftingHelper.getItemStack(JsonUtils.getJsonObject(json, "result"), context); int[] damage = new int[ings.size()]; if (JsonUtils.hasField(json, "damage")) { JsonArray array = JsonUtils.getJsonArray(json, "damage"); if (array.size() > damage.length) throw new JsonParseException("Too many values for damage array: got " + array.size() + ", expected " + damage.length); for (int i = 0; i < array.size(); i++) { JsonElement element = array.get(i); if (!element.isJsonPrimitive() || !element.getAsJsonPrimitive().isNumber()) throw new JsonSyntaxException("Entry in damage array is not a number, got " + element); damage[i] = element.getAsJsonPrimitive().getAsInt(); } } return new DamageableShapelessOreRecipe(group.isEmpty() ? null : new ResourceLocation(group), damage, ings, itemstack); }
Example 17
Source File: RecipeBuilder.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
protected RecipeBuilder() { this.inputs = NonNullList.create(); this.outputs = NonNullList.create(); this.chancedOutputs = new ArrayList<>(); this.fluidInputs = new ArrayList<>(0); this.fluidOutputs = new ArrayList<>(0); }
Example 18
Source File: ItemHandlerMachine.java From customstuff4 with GNU General Public License v3.0 | 5 votes |
private NonNullList<ItemStack> getRange(int from, int to) { NonNullList<ItemStack> list = NonNullList.create(); for (int i = from; i <= to; i++) { if (!getStackInSlot(i).isEmpty()) { list.add(getStackInSlot(i)); } } return list; }
Example 19
Source File: MultiblockInfoRecipeWrapper.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
private static void gatherBlockDrops(World world, Collection<BlockPos> positions, Set<ItemStackKey> drops) { NonNullList<ItemStack> dropsList = NonNullList.create(); for (BlockPos pos : positions) { IBlockState blockState = world.getBlockState(pos); blockState.getBlock().getDrops(dropsList, world, pos, blockState, 0); } for (ItemStack itemStack : dropsList) { drops.add(new ItemStackKey(itemStack)); } }
Example 20
Source File: EmptyRecipe.java From customstuff4 with GNU General Public License v3.0 | 4 votes |
@Override public List<RecipeInput> getRecipeInput() { return NonNullList.create(); }