Java Code Examples for net.minecraft.util.NonNullList#toArray()

The following examples show how to use net.minecraft.util.NonNullList#toArray() . 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: ItemHelperTests.java    From customstuff4 with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void test_isSameRecipeInput()
{
    assertTrue(ItemHelper.isSameRecipeInput(new OreIngredient("stickWood"), "stickWood"));
    assertFalse(ItemHelper.isSameRecipeInput(new OreIngredient("stickWood"), "oreIron"));

    assertTrue(ItemHelper.isSameRecipeInput(Ingredient.fromItem(Items.APPLE), new ItemStack(Items.APPLE)));
    assertFalse(ItemHelper.isSameRecipeInput(Ingredient.fromItem(Items.APPLE), new ItemStack(Items.DIAMOND_SWORD)));

    NonNullList<ItemStack> stickWoodList = OreDictionary.getOres("stickWood");
    ItemStack[] stickWood = stickWoodList.toArray(new ItemStack[0]);

    assertTrue(ItemHelper.isSameRecipeInput(Ingredient.fromStacks(stickWood), stickWoodList));
    assertFalse(ItemHelper.isSameRecipeInput(Ingredient.fromStacks(stickWood), OreDictionary.getOres("ingotIron")));

    assertTrue(ItemHelper.isSameRecipeInput(Ingredient.fromStacks(stickWood), new ItemStack(Items.STICK)));
    assertTrue(ItemHelper.isSameRecipeInput(Ingredient.fromItem(Items.STICK), stickWoodList));
    assertFalse(ItemHelper.isSameRecipeInput(Ingredient.fromStacks(stickWood), new ItemStack(Items.DIAMOND_PICKAXE)));
}
 
Example 2
Source File: CmdPeek.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCommand(String command, String[] args) throws Exception {
	ItemStack item = mc.player.inventory.getCurrentItem();
	
	if (!(item.getItem() instanceof BlockItem)) {
		BleachLogger.errorMessage("Must be holding a containter to peek.");
		return;
	}
	
	if (!(((BlockItem) item.getItem()).getBlock() instanceof ContainerBlock)) {
		BleachLogger.errorMessage("Must be holding a containter to peek.");
		return;
	}
	
	NonNullList<ItemStack> items = NonNullList.withSize(27, new ItemStack(Items.AIR));
	CompoundNBT nbt = item.getTag();
	
	if (nbt != null && nbt.contains("BlockEntityTag")) {
		CompoundNBT itemnbt = nbt.getCompound("BlockEntityTag");
		if (itemnbt.contains("Items")) ItemStackHelper.loadAllItems(itemnbt, items);
	}
	
	Inventory inv = new Inventory(items.toArray(new ItemStack[27]));
	
	BleachQueue.queue.add(() -> {
		mc.displayGuiScreen(new ShulkerBoxScreen(
				new ShulkerBoxContainer(420, mc.player.inventory, inv),
				mc.player.inventory,
				item.getDisplayName()));
	});
}