Jump to content

[Solved] [1.16.5] Getting my custom recipes by IRecipeType using RecipeManager#getAllRecipesFor method


mclich

Recommended Posts

So i have my custom block with its own tile entity and container, and i also added my own recipe and serializer for it and they work absolutely fine. In my container class i want to get all my custom recipes (actually a few .json files in assets/mod/recipes folder) to check if input is correct by comparing inputs from .json files with my custom container item holder. Similar thing is also implemented in AbstractFurnaceTileEntity#tick method:

IRecipe<?> irecipe = this.level.getRecipeManager().getRecipeFor((IRecipeType<AbstractCookingRecipe>)this.recipeType, this, this.level).orElse(null);

The only difference is in my container class i want to use RecipeManager#getAllRecipesFor method, not RecipeManager#getRecipeFor, but it actually doesn't matter. What does matter is getAllRecipesFor method always returns null even though all my .json files are loaded and serializer doesn't have errors. I've also implemented getType method in my recipe class and it returns static field that i pass in RecipeManager#getAllRecipesFor method:

public static final IRecipeType<BrewingRecipe> TYPE=IRecipeType.register("brewing");

So the problem is RecipeManager just cannot find my .json recipes that are loaded. Can someone figure out where am i wrong? Or maybe there is another way to access all my .json recipes by IRecipeType?

Edited by mclich
Link to comment
Share on other sites

41 minutes ago, diesieben07 said:
  • Include your ModID when registering your recipe type.

Done, seems it did not help..

 

42 minutes ago, diesieben07 said:
  • Register your recipe type in FMLCommonSetupEvent#enqueueWork, not in some random static initializer.

What should i return in getType method in that case? I need to have field that stores IRecipeType

 

43 minutes ago, diesieben07 said:
  • It is impossible for getAllRecipesFor(IRecipeType) to return null. Please clarify what you mean.

Well, i have a list variable in my container class for my custom recipes. When i try to initialize it in constructor like that:

this.recipes=this.tileEntity.getLevel().getRecipeManager().getAllRecipesFor(BrewingRecipe.TYPE);

where BrewingRecipe.TYPE is my recipe type variable, i get the following error in that line:

[22:30:56] [Render thread/FATAL] [minecraft/ThreadTaskExecutor]: Error executing task on Client
java.lang.NullPointerException: null

 

Link to comment
Share on other sites

8 minutes ago, diesieben07 said:

Why do you want to store the whole list of recipes?

 

1 hour ago, mclich said:

In my container class i want to get all my custom recipes (actually a few .json files in assets/mod/recipes folder) to check if input is correct by comparing inputs from .json files with my custom container item holder.

 

Link to comment
Share on other sites

5 minutes ago, diesieben07 said:

This is precisely what getRecipeFor does though...? It tells you if a recipe matches.

I thought it just returns first found recipe, because there is an findFirst method in return statement:
 

public <C extends IInventory, T extends IRecipe<C>> Optional<T> getRecipeFor(IRecipeType<T> p_215371_1_, C p_215371_2_, World p_215371_3_) {
      return this.byType(p_215371_1_).values().stream().flatMap((p_215372_3_) -> {
         return Util.toStream(p_215371_1_.tryMatch(p_215372_3_, p_215371_3_, p_215371_2_));
      }).findFirst();
   }

Edit: in my case, i need all the recipes, not just first

Edited by mclich
Link to comment
Share on other sites

31 minutes ago, mclich said:

Edit: in my case, i need all the recipes, not just first

Why do you not initialize the field the first time you use it?
or use a get method inside your code which checks if the Field is null and set it
something like that:

	public List<BrewingRecipe> getRecipes(Level level) {
		if (this.recipes == null) {
			this.recipes = level.getRecipeManager().getAllRecipesFor(BrewingRecipe.TYPE);
		}
		return this.recipes;
	}

 

Link to comment
Share on other sites

1 hour ago, Luis_ST said:

Why do you not initialize the field the first time you use it?
or use a get method inside your code which checks if the Field is null and set it
something like that:


	public List<BrewingRecipe> getRecipes(Level level) {
		if (this.recipes == null) {
			this.recipes = level.getRecipeManager().getAllRecipesFor(BrewingRecipe.TYPE);
		}
		return this.recipes;
	}

 

I just initialize it like usual variable in constructor, so this is not a case

Edited by mclich
Link to comment
Share on other sites

3 hours ago, diesieben07 said:

This is why you use the debugger. If getAllRecipesFor returned null, this wouldn't throw a NullPointerException.

The thing that throws here is that getLevel returns null in the constructor.

Update 2: so i've done some debugging and seems that you are right: getLevel returns null. The thing is constructor is called twice every time i open my container in-game, when it needs to be called once (as i understand).
Here is my container constructor code and logs:

public BreweryContainer(int windowId, BreweryTileEntity tileEntity, PlayerInventory playerInventory, PlayerEntity player)
{
	super(ENGContainers.BREWERY_CONTAINER.get(), windowId);
	this.tileEntity=tileEntity;
	World world=this.tileEntity.getLevel();
	ElderNorseGods.LOGGER.info("world ---> "+world);
	ElderNorseGods.LOGGER.info("tile_entity ---> "+this.tileEntity);
	try
	{
		ElderNorseGods.LOGGER.info("world_try ---> "+world);
		ElderNorseGods.LOGGER.info("tile_entity_try ---> "+this.tileEntity);
		this.recipes=world.getRecipeManager().getAllRecipesFor(ENGRecipeTypes.getBrewingType());
	}
	catch(NullPointerException ex)
	{
		ElderNorseGods.LOGGER.info("msg ---> "+ex.getLocalizedMessage());
		ElderNorseGods.LOGGER.info("world_catch ---> "+world);
		ElderNorseGods.LOGGER.info("tile_entity_catch ---> "+this.tileEntity);
		ElderNorseGods.LOGGER.info("recipes ---> "+this.recipes);
	}
	if(this.tileEntity!=null)
	{
		this.tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).ifPresent
		(
			itemHandler->
			{
				this.addSlot(new BottleSlot(itemHandler, 0, 35, 17));
				this.addSlot(new BottleSlot(itemHandler, 1, 58, 17));
				this.addSlot(new BottleSlot(itemHandler, 2, 81, 17));
				this.addSlot(new FuelSlot(itemHandler, 3, 58, 53));
				this.addSlot(new IngredientSlot(itemHandler, 4, 16, 53));
				this.addSlot(new ResultSlot(itemHandler, 5, 140, 35));
			}
		);
	}
	for(int i=0; i<3; ++i)
	{
		for(int j=0; j<9; ++j)
		{
			this.addSlot(new Slot(playerInventory, j+i*9+9, 8+j*18, 84+i*18));
		}
	}
	for(int k=0; k<9; ++k)
	{
		this.addSlot(new Slot(playerInventory, k, 8+k*18, 142));
	}
}
[01:57:34] [Server thread/INFO] [co.mc.en.ElderNorseGods/]: world ---> ServerLevel[New World]
[01:57:34] [Server thread/INFO] [co.mc.en.ElderNorseGods/]: tile_entity ---> com.mclich.engmod.entity.tile.BreweryTileEntity@4ee51390

[01:57:34] [Server thread/INFO] [co.mc.en.ElderNorseGods/]: world_try ---> ServerLevel[New World]
[01:57:34] [Server thread/INFO] [co.mc.en.ElderNorseGods/]: tile_entity_try ---> com.mclich.engmod.entity.tile.BreweryTileEntity@4ee51390

[01:57:34] [Render thread/INFO] [co.mc.en.ElderNorseGods/]: world ---> null
[01:57:34] [Render thread/INFO] [co.mc.en.ElderNorseGods/]: tile_entity ---> com.mclich.engmod.entity.tile.BreweryTileEntity@43d84df1

[01:57:34] [Render thread/INFO] [co.mc.en.ElderNorseGods/]: world_try ---> null
[01:57:34] [Render thread/INFO] [co.mc.en.ElderNorseGods/]: tile_entity_try ---> com.mclich.engmod.entity.tile.BreweryTileEntity@43d84df1

[01:57:34] [Render thread/INFO] [co.mc.en.ElderNorseGods/]: msg ---> null
[01:57:34] [Render thread/INFO] [co.mc.en.ElderNorseGods/]: world_catch ---> null
[01:57:34] [Render thread/INFO] [co.mc.en.ElderNorseGods/]: tile_entity_catch ---> com.mclich.engmod.entity.tile.BreweryTileEntity@43d84df1
[01:57:34] [Render thread/INFO] [co.mc.en.ElderNorseGods/]: recipes ---> null

 

Edited by mclich
Link to comment
Share on other sites

8 hours ago, mclich said:

Update 2: so i've done some debugging and seems that you are right: getLevel returns null. The thing is constructor is called twice every time i open my container in-game, when it needs to be called once (as i understand).
Here is my container constructor code and logs:

the container is created twice, one time on server and one time on client
i already told you how to fix the error (remove the 'final' modifier from the field and initialize the field the first time you use it):

11 hours ago, Luis_ST said:

Why do you not initialize the field the first time you use it?
or use a get method inside your code which checks if the Field is null and set it
something like that:

Link to comment
Share on other sites

6 hours ago, Luis_ST said:

the container is created twice, one time on server and one time on client
i already told you how to fix the error (remove the 'final' modifier from the field and initialize the field the first time you use it):

It didn't help. I don't know why you think i have 'final' modifier on the field of recipes. As i've already said, i've never had it

Link to comment
Share on other sites

19 minutes ago, diesieben07 said:

Show new stacktrace and updated code.

Container class:

public class BreweryContainer extends Container
{
	private BreweryTileEntity tileEntity;
	private List<BrewingRecipe> recipes;
	
    public BreweryContainer(int windowId, PlayerInventory playerInventory, PacketBuffer data)
    {
    	this(windowId, ENGTileEntities.BREWERY_TILE.get().create(), playerInventory, playerInventory.player);
    }
    
    public BreweryContainer(int windowId, BreweryTileEntity tileEntity, PlayerInventory playerInventory, PlayerEntity player)
	{
		super(ENGContainers.BREWERY_CONTAINER.get(), windowId);
		this.tileEntity=tileEntity;
        if(this.tileEntity!=null)
        {
        	//if(!this.tileEntity.getLevel().isClientSide()) this.recipes=this.tileEntity.getLevel().getRecipeManager().getAllRecipesFor(ENGRecipeTypes.getBrewingType());
        	this.tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).ifPresent
        	(
        		itemHandler->
        		{
        			this.addSlot(new BottleSlot(itemHandler, 0, 35, 17));
                	this.addSlot(new BottleSlot(itemHandler, 1, 58, 17));
                	this.addSlot(new BottleSlot(itemHandler, 2, 81, 17));
                	this.addSlot(new FuelSlot(itemHandler, 3, 58, 53));
                	this.addSlot(new IngredientSlot(itemHandler, 4, 16, 53));
                	this.addSlot(new ResultSlot(itemHandler, 5, 140, 35));
        		}
        	);
        }
        for(int i=0; i<3; ++i)
        {
        	for(int j=0; j<9; ++j)
        	{
        		this.addSlot(new Slot(playerInventory, j+i*9+9, 8+j*18, 84+i*18));
        	}
        }
        for(int k=0; k<9; ++k)
        {
        	this.addSlot(new Slot(playerInventory, k, 8+k*18, 142));
        }
	}

	public boolean isValidBottle(ItemStack itemStack)
	{
		ElderNorseGods.LOGGER.info("recipes ---> "+this.getRecipes(this.tileEntity.getLevel()));
		return true;
	}
	
	public boolean isFuel(ItemStack itemStack)
	{
		return ForgeHooks.getBurnTime(itemStack, null)>0;
	}
	
	public boolean isIngredient(ItemStack itemStack)
	{
		return itemStack.getItem()==Items.WHEAT||
			   itemStack.getItem()==ENGItems.BARLEY.get()||
			   itemStack.getItem()==ENGItems.HOP.get();
	}
	
	public boolean isResultItem(ItemStack itemStack)
	{
		return true;
	}
	
	public List<BrewingRecipe> getRecipes(World world)
	{
		if(this.recipes==null) this.recipes=world.getRecipeManager().getAllRecipesFor(ENGRecipeTypes.getBrewingType());
		return this.recipes;
	}
	
	@Override
	public boolean stillValid(PlayerEntity player)
	{
		return this.tileEntity!=null?this.tileEntity.stillValid(player):false;
	}
	
	@Override
	public ItemStack quickMoveStack(PlayerEntity player, int slotIndex)
	{
		Slot slot=this.slots.get(slotIndex);
		if(slot!=null&&slot.hasItem())
		{
			ItemStack itemStack=slot.getItem();
			if(this.isValidBottle(itemStack))
			{
				if((slotIndex==0||slotIndex==1||slotIndex==2)&&!this.moveItemStackTo(itemStack, 6, 42, false)) return ItemStack.EMPTY;
				else if(!this.moveItemStackTo(itemStack, 0, 3, false)) return ItemStack.EMPTY;
			}
			else if(this.isFuel(itemStack))
			{
				if(slotIndex==3&&!this.moveItemStackTo(itemStack, 6, 42, false)) return ItemStack.EMPTY;
				else if(!this.moveItemStackTo(itemStack, 3, 4, false)) return ItemStack.EMPTY;
			}
			else if(this.isIngredient(itemStack))
			{
				if(slotIndex==4&&!this.moveItemStackTo(itemStack, 6, 42, false)) return ItemStack.EMPTY;
				else if(!this.moveItemStackTo(itemStack, 4, 5, false)) return ItemStack.EMPTY;
			}
			else if(this.isResultItem(itemStack)&&slotIndex==5&&!this.moveItemStackTo(itemStack, 6, 42, true)) return ItemStack.EMPTY;
			else if(slotIndex>5&&slotIndex<33&&!this.moveItemStackTo(itemStack, 33, 42, false)) return ItemStack.EMPTY;
			else if(!this.moveItemStackTo(itemStack, 6, 33, false)) return ItemStack.EMPTY;
			if(itemStack.isEmpty()) slot.set(ItemStack.EMPTY);
			slot.setChanged();
		}
		return ItemStack.EMPTY;
	}

	public class BottleSlot extends SlotItemHandler
	{
		public BottleSlot(IItemHandler itemHandler, int index, int xPixel, int yPixel)
		{
			super(itemHandler, index, xPixel, yPixel);
		}
		
		@Override
		public int getMaxStackSize()
		{
			return 1;
		}

		@Override
		public boolean mayPlace(ItemStack itemStack)
		{
			return isValidBottle(itemStack);
		}
	}
	
	public class FuelSlot extends SlotItemHandler
	{
		public FuelSlot(IItemHandler itemHandler, int index, int xPixel, int yPixel)
		{
			super(itemHandler, index, xPixel, yPixel);
		}
		
		@Override
		public int getMaxStackSize(ItemStack itemStack)
		{
			return itemStack.getItem()==Items.BUCKET?1:64;
		}

		@Override
		public boolean mayPlace(ItemStack itemStack)
		{
			return isFuel(itemStack);
		}
	}
	
	public class IngredientSlot extends SlotItemHandler
	{
		public IngredientSlot(IItemHandler itemHandler, int index, int xPixel, int yPixel)
		{
			super(itemHandler, index, xPixel, yPixel);
		}
		
		@Override
		public int getMaxStackSize()
		{
			return 64;
		}

		@Override
		public boolean mayPlace(ItemStack itemStack)
		{
			return isIngredient(itemStack);
		}
	}
	
	public class ResultSlot extends SlotItemHandler
	{
		public ResultSlot(IItemHandler itemHandler, int index, int xPixel, int yPixel)
		{
			super(itemHandler, index, xPixel, yPixel);
		}
		
		@Override
		public int getMaxStackSize()
		{
			return 64;
		}
		
		@Override
		public boolean mayPlace(ItemStack itemStack)
		{
			return false;
		}
	}
}

 

Logs:
 

[17:50:51] [Render thread/FATAL] [minecraft/Minecraft]: Reported exception thrown!
net.minecraft.crash.ReportedException: Container click
	at net.minecraft.client.gui.screen.Screen.wrapScreenError(Screen.java:434) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.MouseHelper.onPress(MouseHelper.java:91) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.MouseHelper.lambda$null$4(MouseHelper.java:181) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.util.concurrent.ThreadTaskExecutor.execute(ThreadTaskExecutor.java:86) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.client.MouseHelper.lambda$setup$5(MouseHelper.java:180) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at org.lwjgl.glfw.GLFWMouseButtonCallbackI.callback(GLFWMouseButtonCallbackI.java:36) ~[lwjgl-glfw-3.2.2.jar:build 10] {}
	at org.lwjgl.system.JNI.invokeV(Native Method) ~[lwjgl-3.2.2.jar:build 10] {}
	at org.lwjgl.glfw.GLFW.glfwPollEvents(GLFW.java:3101) ~[lwjgl-glfw-3.2.2.jar:build 10] {}
	at com.mojang.blaze3d.systems.RenderSystem.flipFrame(RenderSystem.java:93) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.MainWindow.updateDisplay(MainWindow.java:305) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.runTick(Minecraft.java:996) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.run(Minecraft.java:607) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.main.Main.main(Main.java:184) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_291] {}
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_291] {}
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_291] {}
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_291] {}
	at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:52) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-8.0.9.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-8.0.9.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-8.0.9.jar:?] {}
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:82) [modlauncher-8.0.9.jar:?] {}
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) [modlauncher-8.0.9.jar:?] {}
	at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:108) [forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {}
Caused by: java.lang.NullPointerException
	at com.mclich.engmod.block.container.BreweryContainer.getRecipes(BreweryContainer.java:94) ~[main/:?] {re:classloading}
	at com.mclich.engmod.block.container.BreweryContainer.isValidBottle(BreweryContainer.java:71) ~[main/:?] {re:classloading}
	at com.mclich.engmod.block.container.BreweryContainer$BottleSlot.mayPlace(BreweryContainer.java:151) ~[main/:?] {re:classloading}
	at net.minecraft.inventory.container.Container.doClick(Container.java:272) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at net.minecraft.inventory.container.Container.clicked(Container.java:160) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at net.minecraft.client.multiplayer.PlayerController.handleInventoryMouseClick(PlayerController.java:379) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.screen.inventory.ContainerScreen.slotClicked(ContainerScreen.java:539) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.screen.inventory.ContainerScreen.mouseReleased(ContainerScreen.java:509) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.MouseHelper.lambda$onPress$1(MouseHelper.java:93) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.screen.Screen.wrapScreenError(Screen.java:427) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	... 23 more
[17:50:51] [Render thread/INFO] [STDOUT/]: [net.minecraft.util.registry.Bootstrap:realStdoutPrintln:123]: ---- Minecraft Crash Report ----
// You should try our sister game, Minceraft!

Time: 28.08.21 17:50
Description: Container click

java.lang.NullPointerException: Container click
	at com.mclich.engmod.block.container.BreweryContainer.getRecipes(BreweryContainer.java:94) ~[main/:?] {re:classloading}
	at com.mclich.engmod.block.container.BreweryContainer.isValidBottle(BreweryContainer.java:71) ~[main/:?] {re:classloading}
	at com.mclich.engmod.block.container.BreweryContainer$BottleSlot.mayPlace(BreweryContainer.java:151) ~[main/:?] {re:classloading}
	at net.minecraft.inventory.container.Container.doClick(Container.java:272) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at net.minecraft.inventory.container.Container.clicked(Container.java:160) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at net.minecraft.client.multiplayer.PlayerController.handleInventoryMouseClick(PlayerController.java:379) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.screen.inventory.ContainerScreen.slotClicked(ContainerScreen.java:539) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.screen.inventory.ContainerScreen.mouseReleased(ContainerScreen.java:509) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.MouseHelper.lambda$onPress$1(MouseHelper.java:93) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.screen.Screen.wrapScreenError(Screen.java:427) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.MouseHelper.onPress(MouseHelper.java:91) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.MouseHelper.lambda$null$4(MouseHelper.java:181) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.util.concurrent.ThreadTaskExecutor.execute(ThreadTaskExecutor.java:86) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.client.MouseHelper.lambda$setup$5(MouseHelper.java:180) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at org.lwjgl.glfw.GLFWMouseButtonCallbackI.callback(GLFWMouseButtonCallbackI.java:36) ~[lwjgl-glfw-3.2.2.jar:build 10] {}
	at org.lwjgl.system.JNI.invokeV(Native Method) ~[lwjgl-3.2.2.jar:build 10] {}
	at org.lwjgl.glfw.GLFW.glfwPollEvents(GLFW.java:3101) ~[lwjgl-glfw-3.2.2.jar:build 10] {}
	at com.mojang.blaze3d.systems.RenderSystem.flipFrame(RenderSystem.java:93) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.MainWindow.updateDisplay(MainWindow.java:305) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.runTick(Minecraft.java:996) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.run(Minecraft.java:607) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.main.Main.main(Main.java:184) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_291] {}
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_291] {}
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_291] {}
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_291] {}
	at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:52) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-8.0.9.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-8.0.9.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-8.0.9.jar:?] {}
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:82) [modlauncher-8.0.9.jar:?] {}
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) [modlauncher-8.0.9.jar:?] {}
	at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:108) [forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {}


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Render thread
Stacktrace:
	at com.mclich.engmod.block.container.BreweryContainer.getRecipes(BreweryContainer.java:94) ~[?:?] {re:classloading}
	at com.mclich.engmod.block.container.BreweryContainer.isValidBottle(BreweryContainer.java:71) ~[?:?] {re:classloading}
	at com.mclich.engmod.block.container.BreweryContainer$BottleSlot.mayPlace(BreweryContainer.java:151) ~[?:?] {re:classloading}
	at net.minecraft.inventory.container.Container.doClick(Container.java:272) ~[forge:?] {re:classloading}
-- Click info --
Details:
	Menu Type: engmod:brewery
	Menu Class: com.mclich.engmod.block.container.BreweryContainer
	Slot Count: 42
	Slot: 0
	Button: 1
	Type: PICKUP
Stacktrace:
	at net.minecraft.inventory.container.Container.clicked(Container.java:160) ~[forge:?] {re:classloading}
	at net.minecraft.client.multiplayer.PlayerController.handleInventoryMouseClick(PlayerController.java:379) ~[forge:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.screen.inventory.ContainerScreen.slotClicked(ContainerScreen.java:539) ~[forge:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.screen.inventory.ContainerScreen.mouseReleased(ContainerScreen.java:509) ~[forge:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.MouseHelper.lambda$onPress$1(MouseHelper.java:93) ~[forge:?] {re:classloading,pl:runtimedistcleaner:A}


-- Affected screen --
Details:
	Screen name: com.mclich.engmod.client.gui.screen.BreweryScreen
Stacktrace:
	at net.minecraft.client.gui.screen.Screen.wrapScreenError(Screen.java:427) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.MouseHelper.onPress(MouseHelper.java:91) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.MouseHelper.lambda$null$4(MouseHelper.java:181) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.util.concurrent.ThreadTaskExecutor.execute(ThreadTaskExecutor.java:86) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.client.MouseHelper.lambda$setup$5(MouseHelper.java:180) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at org.lwjgl.glfw.GLFWMouseButtonCallbackI.callback(GLFWMouseButtonCallbackI.java:36) ~[lwjgl-glfw-3.2.2.jar:build 10] {}
	at org.lwjgl.system.JNI.invokeV(Native Method) ~[lwjgl-3.2.2.jar:build 10] {}
	at org.lwjgl.glfw.GLFW.glfwPollEvents(GLFW.java:3101) ~[lwjgl-glfw-3.2.2.jar:build 10] {}
	at com.mojang.blaze3d.systems.RenderSystem.flipFrame(RenderSystem.java:93) ~[forge:?] {re:classloading,pl:runtimedistcleaner:A}


-- Affected level --
Details:
	All players: 1 total; [ClientPlayerEntity['mclich'/13, l='ClientLevel', x=109.10, y=3.94, z=533.66]]
	Chunk stats: Client Chunk Cache: 841, 529
	Level dimension: minecraft:overworld
	Level spawn location: World: (32,4,112), Chunk: (at 0,0,0 in 2,7; contains blocks 32,0,112 to 47,255,127), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
	Level time: 477766 game time, 1007 day time
	Server brand: forge
	Server type: Integrated singleplayer server
Stacktrace:
	at net.minecraft.client.world.ClientWorld.fillReportDetails(ClientWorld.java:447) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.fillReport(Minecraft.java:2029) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.run(Minecraft.java:623) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.main.Main.main(Main.java:184) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_291] {}
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_291] {}
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_291] {}
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_291] {}
	at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:52) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-8.0.9.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-8.0.9.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-8.0.9.jar:?] {}
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:82) [modlauncher-8.0.9.jar:?] {}
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) [modlauncher-8.0.9.jar:?] {}
	at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:108) [forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {}

 

Edited by mclich
Link to comment
Share on other sites

12 minutes ago, diesieben07 said:

Yes, if the tile entity is attached to the world. But you just called your factory, which essentially just calls your TE constructor.

Get the tile entity from the world using World#getBlockEntity.

So i changed my constructors a little bit, here is the code:

public BreweryContainer(int windowId, PlayerInventory playerInventory, PacketBuffer data)
    {
    	this(windowId, playerInventory.player.getCommandSenderWorld().getBlockEntity(data.readBlockPos()), playerInventory, playerInventory.player);
    }
    
    public BreweryContainer(int windowId, TileEntity tileEntity, PlayerInventory playerInventory, PlayerEntity player)
	{
		super(ENGContainers.BREWERY_CONTAINER.get(), windowId);
		if(tileEntity!=null&&tileEntity instanceof BreweryTileEntity) this.tileEntity=(BreweryTileEntity)tileEntity;
        if(this.tileEntity!=null)
        {
        	//if(!this.tileEntity.getLevel().isClientSide()) this.recipes=this.tileEntity.getLevel().getRecipeManager().getAllRecipesFor(ENGRecipeTypes.getBrewingType());
        	this.tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).ifPresent
        	(
        		itemHandler->
        		{
        			this.addSlot(new BottleSlot(itemHandler, 0, 35, 17));
                	this.addSlot(new BottleSlot(itemHandler, 1, 58, 17));
                	this.addSlot(new BottleSlot(itemHandler, 2, 81, 17));
                	this.addSlot(new FuelSlot(itemHandler, 3, 58, 53));
                	this.addSlot(new IngredientSlot(itemHandler, 4, 16, 53));
                	this.addSlot(new ResultSlot(itemHandler, 5, 140, 35));
        		}
        	);
        }
        for(int i=0; i<3; ++i)
        {
        	for(int j=0; j<9; ++j)
        	{
        		this.addSlot(new Slot(playerInventory, j+i*9+9, 8+j*18, 84+i*18));
        	}
        }
        for(int k=0; k<9; ++k)
        {
        	this.addSlot(new Slot(playerInventory, k, 8+k*18, 142));
        }
	}

However, i still have NullPointerException:
 

[18:11:58] [Render thread/FATAL] [minecraft/ThreadTaskExecutor]: Error executing task on Client
java.lang.NullPointerException: null
	at com.mclich.engmod.block.container.BreweryContainer.<init>(BreweryContainer.java:34) ~[main/:?] {re:classloading}
	at net.minecraftforge.fml.network.IContainerFactory.create(IContainerFactory.java:34) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at net.minecraft.inventory.container.ContainerType.create(ContainerType.java:47) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.client.gui.ScreenManager$IScreenFactory.fromPacket(ScreenManager.java:115) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.ScreenManager.lambda$create$0(ScreenManager.java:43) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at java.util.Optional.ifPresent(Optional.java:159) ~[?:1.8.0_291] {}
	at net.minecraft.client.gui.ScreenManager.create(ScreenManager.java:43) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.network.play.ClientPlayNetHandler.handleOpenScreen(ClientPlayNetHandler.java:1052) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.network.play.server.SOpenWindowPacket.handle(SOpenWindowPacket.java:41) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at net.minecraft.network.play.server.SOpenWindowPacket.handle(SOpenWindowPacket.java:14) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at net.minecraft.network.PacketThreadUtil.lambda$ensureRunningOnSameThread$0(PacketThreadUtil.java:19) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at net.minecraft.util.concurrent.ThreadTaskExecutor.doRunTask(ThreadTaskExecutor.java:136) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.util.concurrent.RecursiveEventLoop.doRunTask(RecursiveEventLoop.java:22) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at net.minecraft.util.concurrent.ThreadTaskExecutor.pollTask(ThreadTaskExecutor.java:109) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.util.concurrent.ThreadTaskExecutor.runAllTasks(ThreadTaskExecutor.java:97) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.client.Minecraft.runTick(Minecraft.java:947) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.run(Minecraft.java:607) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.main.Main.main(Main.java:184) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_291] {}
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_291] {}
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_291] {}
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_291] {}
	at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:52) ~[forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-8.0.9.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-8.0.9.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-8.0.9.jar:?] {}
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:82) [modlauncher-8.0.9.jar:?] {}
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) [modlauncher-8.0.9.jar:?] {}
	at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:108) [forge-1.16.5-36.2.2_mapped_official_1.16.5-recomp.jar:?] {}

 

Link to comment
Share on other sites

Just now, diesieben07 said:

What is line 34? Use the debugger to find out what is null there.

This line:
 

this(windowId, playerInventory.player.getCommandSenderWorld().getBlockEntity(data.readBlockPos()), playerInventory, playerInventory.player);

 

Link to comment
Share on other sites

14 minutes ago, diesieben07 said:

What is null there?

Seems the problem is with data field. In my registry file my container is registred like this: 

public static final RegistryObject<ContainerType<BreweryContainer>> BREWERY_CONTAINER=ENGContainers.CONTAINERS.register(BreweryBlock.ID, ()->IForgeContainerType.create(BreweryContainer::new));

 

IForgeContainerType#create by default returns null as PacketBuffer, so data field in my container constructor is null:

public interface IContainerFactory<T extends Container> extends ContainerType.IFactory<T>
{
    T create(int windowId, PlayerInventory inv, PacketBuffer data);
    
    @Override
    default T create(int p_create_1_, PlayerInventory p_create_2_)
    {
        return create(p_create_1_, p_create_2_, null);
    }
}

 

Link to comment
Share on other sites

9 minutes ago, diesieben07 said:
  • Do not put DeferredRegister and its RegistryObjects in separate classes.

Of course i'm not. My DeferredRegister and its RegistryObjects are in one class, i just showed my container declaration line
 

 

9 minutes ago, diesieben07 said:
  • How are you opening your GUI?

In my BreweryBlock class i have overrided AbstractBlock#use method:
 

@Override
	public ActionResultType use(BlockState blockState, World world, BlockPos blockPos, PlayerEntity player, Hand hand, BlockRayTraceResult blockRayTrace)
	{
		if(world.isClientSide()) return ActionResultType.SUCCESS;
		else
		{
			TileEntity tileEntity=world.getBlockEntity(blockPos);
			if(tileEntity instanceof BreweryTileEntity)
			{
				player.openMenu((BreweryTileEntity)tileEntity)
			}
			return ActionResultType.CONSUME;
		}
	}

I know that there is a way to open gui with NetworkHooks#openGui, but i don't actually know what is the difference between it and PlayerEntity#openMenu method

Edited by mclich
Link to comment
Share on other sites

11 minutes ago, diesieben07 said:

Then why is there ENGContainers.CONTAINERS.register there?

Oh, it is just personal thing. I always use class name with its static fields (as well as this with non-static fields), even inside that class. It is easier for me to read my own code like this
 

11 minutes ago, diesieben07 said:

You should always use NetworkHooks.openGui. The difference is that NetworkHooks lets you send additional data, which is received by your IContainerFactory in form of the PacketBuffer. If you use PlayerEntity#openMenu the default, which passes null, is used instead.

Jeez, it is finally working! Thank you so much, you are a legend

Edited by mclich
Link to comment
Share on other sites

  • mclich changed the title to [Solved] [1.16.5] Getting my custom recipes by IRecipeType using RecipeManager#getAllRecipesFor method

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.