Jump to content

Recommended Posts

Posted (edited)

This error is driving me crazy! I can't figure out what is it. 

 

Error Log:

---- Minecraft Crash Report ----
// I just don't know what went wrong :(

Time: 4/11/18 5:38 PM
Description: Initializing game

java.lang.NullPointerException: Can't use a null-name for the registry, object null.
	at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:864)
	at net.minecraftforge.registries.ForgeRegistry.add(ForgeRegistry.java:287)
	at net.minecraftforge.registries.ForgeRegistry.add(ForgeRegistry.java:281)
	at net.minecraftforge.registries.ForgeRegistry.register(ForgeRegistry.java:114)
	at net.minecraftforge.registries.ForgeRegistry.registerAll(ForgeRegistry.java:155)
	at tutuicraft3.sapphirecraft.init.ModBlocks.registerBlocks(ModBlocks.java:49)
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_4_ModBlocks_registerBlocks_Register.invoke(.dynamic)
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
	at net.minecraftforge.fml.common.eventhandler.EventBus$1.invoke(EventBus.java:143)
	at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:179)
	at net.minecraftforge.registries.GameData.fireRegistryEvents(GameData.java:736)
	at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:604)
	at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:270)
	at net.minecraft.client.Minecraft.init(Minecraft.java:513)
	at net.minecraft.client.Minecraft.run(Minecraft.java:421)
	at net.minecraft.client.main.Main.main(Main.java:118)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
	at GradleStart.main(GradleStart.java:26)


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

-- Head --
Thread: Client thread
Stacktrace:
	at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:864)
	at net.minecraftforge.registries.ForgeRegistry.add(ForgeRegistry.java:287)
	at net.minecraftforge.registries.ForgeRegistry.add(ForgeRegistry.java:281)
	at net.minecraftforge.registries.ForgeRegistry.register(ForgeRegistry.java:114)
	at net.minecraftforge.registries.ForgeRegistry.registerAll(ForgeRegistry.java:155)
	at tutuicraft3.sapphirecraft.init.ModBlocks.registerBlocks(ModBlocks.java:49)
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_4_ModBlocks_registerBlocks_Register.invoke(.dynamic)
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
	at net.minecraftforge.fml.common.eventhandler.EventBus$1.invoke(EventBus.java:143)
	at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:179)
	at net.minecraftforge.registries.GameData.fireRegistryEvents(GameData.java:736)
	at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:604)
	at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:270)
	at net.minecraft.client.Minecraft.init(Minecraft.java:513)

-- Initialization --
Details:
Stacktrace:
	at net.minecraft.client.Minecraft.run(Minecraft.java:421)
	at net.minecraft.client.main.Main.main(Main.java:118)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
	at GradleStart.main(GradleStart.java:26)

-- System Details --
Details:
	Minecraft Version: 1.12.2
	Operating System: Windows 7 (amd64) version 6.1
	Java Version: 1.8.0_162, Oracle Corporation
	Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
	Memory: 350758720 bytes (334 MB) / 504365056 bytes (481 MB) up to 954728448 bytes (910 MB)
	JVM Flags: 0 total; 
	IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
	FML: MCP 9.42 Powered by Forge 14.23.2.2627 6 mods loaded, 6 mods active
	States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored

	| State | ID        | Version      | Source                           | Signature |
	|:----- |:--------- |:------------ |:-------------------------------- |:--------- |
	| UCH   | minecraft | 1.12.2       | minecraft.jar                    | None      |
	| UCH   | mcp       | 9.42         | minecraft.jar                    | None      |
	| UCH   | FML       | 8.0.99.99    | forgeSrc-1.12.2-14.23.2.2627.jar | None      |
	| UCH   | forge     | 14.23.2.2627 | forgeSrc-1.12.2-14.23.2.2627.jar | None      |
	| UCH   | sc        | 1.0          | bin                              | None      |
	| UCH   | xray      | 1.4.0        | xray-1.12.2-1.4.0.jar            | None      |

	Loaded coremods (and transformers): 
	GL info: ' Vendor: 'NVIDIA Corporation' Version: '4.6.0 NVIDIA 391.24' Renderer: 'GeForce GT 430/PCIe/SSE2'
	Launched Version: 1.12.2
	LWJGL: 2.9.4
	OpenGL: GeForce GT 430/PCIe/SSE2 GL version 4.6.0 NVIDIA 391.24, NVIDIA Corporation
	GL Caps: Using GL 1.3 multitexturing.
Using GL 1.3 texture combiners.
Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.
Shaders are available because OpenGL 2.1 is supported.
VBOs are available because OpenGL 1.5 is supported.

	Using VBOs: Yes
	Is Modded: Definitely; Client brand changed to 'fml,forge'
	Type: Client (map_client.txt)
	Resource Packs: 
	Current Language: English (US)
	Profiler Position: N/A (disabled)
	CPU: 3x AMD Phenom(tm) 8400 Triple-Core Processor

 

My ModBlocks class:

 

package tutuicraft3.sapphirecraft.init;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.registries.IForgeRegistry;
import tutuicraft3.sapphirecraft.Reference;
import tutuicraft3.sapphirecraft.blocks.BlockOre;
import tutuicraft3.sapphirecraft.blocks.MSapphire_Block;
import tutuicraft3.sapphirecraft.blocks.Sapphire_Block;
import tutuicraft3.sapphirecraft.blocks.tileentity.MSapphire_Infusor;

@Mod.EventBusSubscriber(modid=Reference.MODID)
public class ModBlocks {
	
	static Block Sapphire_Block;
	
	public static Block Sapphire_Ore;
	
	static Block MSapphire_Block;
	
	public static MSapphire_Infusor infusor;
	
	public static void init() {
		
		Sapphire_Block = new Sapphire_Block("sapphire_block", Material.IRON);
		
		Sapphire_Ore = new BlockOre("sapphire_ore", Material.ROCK, ModItems.Sapphire, 1).setHardness(3.0F).setCreativeTab(ModItems.TabSapphireCraft);
		Sapphire_Ore.setHarvestLevel("pickaxe", 2);
		Sapphire_Ore.setResistance(5.0f);
		
		MSapphire_Block = new MSapphire_Block("msapphire_block", Material.IRON);
		
		infusor = new MSapphire_Infusor("msapphire_infusor", Material.IRON);
		
	}
	
	@SubscribeEvent
	public static void registerBlocks(RegistryEvent.Register<Block> event) {
		
		event.getRegistry().registerAll(Sapphire_Block); 
		event.getRegistry().registerAll(Sapphire_Ore); 
		event.getRegistry().registerAll(MSapphire_Block);
		event.getRegistry().registerAll(infusor);
		
		GameRegistry.registerTileEntity(infusor.getTileEntityClass(), infusor.getRegistryName().toString());
		
	}
	
	@SubscribeEvent
	public static void registerItemBlocks(RegistryEvent.Register<Item> event) {
		
		event.getRegistry().registerAll(new ItemBlock(Sapphire_Block).setRegistryName(Sapphire_Block.getRegistryName()));
		
		event.getRegistry().registerAll(new ItemBlock(Sapphire_Ore).setRegistryName(Sapphire_Ore.getRegistryName()));
		
		event.getRegistry().registerAll(new ItemBlock(MSapphire_Block).setRegistryName(MSapphire_Block.getRegistryName()));
		
		event.getRegistry().registerAll(new ItemBlock(infusor).setRegistryName(infusor.getRegistryName()));
				
	    
	
	}
	
	@SubscribeEvent
	public static void registerRenders(ModelRegistryEvent event) {
		
		registerRender(Item.getItemFromBlock(Sapphire_Block));
		
		registerRender(Item.getItemFromBlock(Sapphire_Ore));
		
		registerRender(Item.getItemFromBlock(MSapphire_Block));
		
		registerRender(Item.getItemFromBlock(infusor));
		
	}
	
	public static void registerRender(Item item) {
		
		ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(item.getRegistryName(), "inventory"));
		
	}	

}

 

I was wondering if someone could help me, please?

 

Edited by Arthur Wesley
Posted

You never call setRegistryName() for your blocks.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)
14 minutes ago, Draco18s said:

You never call setRegistryName() for your blocks.

Anyway, it looks like that didn't solve the crash. This line calls my attention:
 

java.lang.NullPointerException: Can't use a null-name for the registry, object null.

 

What could  that mean?

Edited by Arthur Wesley
Posted (edited)

What have you done to debug it? It should be easy to quickly see what is wrong if you just observe the execution. I personally like to add print statements throughout the code so I can watch (and learn) about the execution in real time. For example, if you put print statements at the beginning of each of your methods then you can confirm they are being called in the correct order. And if you put a print statement right before your error line you can print out the values of what you're trying to pass to the method and you should see that they are in fact null. Then you simply trace backwards until you find the first place it isn't doing what you expect.

 

This is how professionals debug -- by "tracing" the execution. Not just staring at the code or trying random changes. Since computers are logical, just watching the execution you can always find where it starts to go wrong.

 

Basically for this problem, it is obvious what the error actually is -- so something is either wrong with your order of operations, or else you may have created multiple instances and getting them confused with each other (i.e. one has registry name set and one doesn't). To be honest I think your instances are mixed up as you're not using the object holder annotation so you need to be careful about how you order and reference your instances.

Edited by jabelar

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted
19 minutes ago, jabelar said:

What have you done to debug it? It should be easy to quickly see what is wrong if you just observe the execution. I personally like to add print statements throughout the code so I can watch (and learn) about the execution in real time. For example, if you put print statements at the beginning of each of your methods then you can confirm they are being called in the correct order. And if you put a print statement right before your error line you can print out the values of what you're trying to pass to the method and you should see that they are in fact null. Then you simply trace backwards until you find the first place it isn't doing what you expect.

 

This is how professionals debug -- by "tracing" the execution. Not just staring at the code or trying random changes. Since computers are logical, just watching the execution you can always find where it starts to go wrong.

 

Basically for this problem, it is obvious what the error actually is -- so something is either wrong with your order of operations, or else you may have created multiple instances and getting them confused with each other (i.e. one has registry name set and one doesn't). To be honest I think your instances are mixed up as you're not using the object holder annotation so you need to be careful about how you order and reference your instances.

I've found out that the error occur when the ModBlocks class is registering the first block:

 

	@SubscribeEvent
	public static void registerBlocks(RegistryEvent.Register<Block> event) {
		
		System.out.println("ModBlocks registerBlocks -------------------------------------");
		
		System.out.println("register Sapphire Block -----------------------------------");
		event.getRegistry().registerAll(Sapphire_Block); //<-- THE ERROR STARTS HERE ================ <--
		System.out.println("register Sapphire Ore ----------------------------------------");
		event.getRegistry().registerAll(Sapphire_Ore); 
		event.getRegistry().registerAll(MSapphire_Block);
		event.getRegistry().registerAll(infusor);
		
		GameRegistry.registerTileEntity(infusor.getTileEntityClass(), infusor.getRegistryName().toString());
		
	}
	

 

with the same error lines:

 

[21:41:55] [main/ERROR] [FML]: Exception caught during firing event net.minecraftforge.event.RegistryEvent$Register@447bf09d:
java.lang.NullPointerException: Can't use a null-name for the registry, object null.

 

Posted

You can't use null for a registry name.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
9 minutes ago, Draco18s said:

You can't use null for a registry name.

But where am I using it? I don't know what happened, my mod was working perfectly this afternoon, and it suddenly started to occur this error... Strange.

Posted
6 minutes ago, GammaS_ said:

Can you show me where you are calling setRegistryName() for each of your blocks?

I call it on each blockclass, like this:  

 

package tutuicraft3.sapphirecraft.blocks;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import tutuicraft3.sapphirecraft.Main;

public class BlockBase extends Block {

	protected String name;

	public BlockBase(Material material, String name) {
		super(material);
	
		this.name = name;
	
		setUnlocalizedName(name);
		setRegistryName(name);
	}
	
	public void registerItemModel(Item itemBlock) {
		Main.proxy.registerItemRenderer(itemBlock, 0, name);
	}
	
	public Item createItemBlock() {
		return new ItemBlock(this).setRegistryName(getRegistryName());
	}
	
	@Override
	public BlockBase setCreativeTab(CreativeTabs tab) {
		super.setCreativeTab(tab);
		return this;
	}
}

 

Posted (edited)

Couple of things I can see with the given code:

  1. I cannot see anywhere you are calling registerItemModel()
  2. Are you sure you are calling ModBlocks.init() before the registry events?

 

Have you got a Github Reop, where I can look at all of your code?

Edited by GammaS_
Posted

It is pretty hard to debug this by staring at code, especially since you're not showing all of it. For example, your BlockBase constructor does set the registry name but you don't show the Sapphire_Block code so it is not clear that you actually extended that class, or properly passed the string along to the super constructor.

 

NOTE: It is not considered good programming style to name classes with underscores. It should be SapphireBlock, not Sapphire_Block.

 

Additionally, you construct the instance in your init() method, but it isn't clear where you call that so as far as we know that instance could still be null.

 

Basically, you're not giving us all your code and it is the EXACT order of things that matters for this bug. Anyway, my point is still that it isn't fair to have a bunch of people just reading your code when you can debug this easily yourself. Just keep adding print statements until you understand everything that is happening. For example, in your second print statement why don't you print out some useful data like the contents of the registry name. Assuming it is null, then work backwards to figure out why it is null. For example, put a print statement in your BlockBase constructor that prints out the registry name, then check if that is getting called before you try to register it. And so forth.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted (edited)
55 minutes ago, Arthur Wesley said:

I call it on each blockclass, like this:  

 


package tutuicraft3.sapphirecraft.blocks;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import tutuicraft3.sapphirecraft.Main;

public class BlockBase extends Block {

	protected String name;

	public BlockBase(Material material, String name) {
		super(material);
	
		this.name = name;
	
		setUnlocalizedName(name);
		setRegistryName(name);
	}
	
	public void registerItemModel(Item itemBlock) {
		Main.proxy.registerItemRenderer(itemBlock, 0, name);
	}
	
	public Item createItemBlock() {
		return new ItemBlock(this).setRegistryName(getRegistryName());
	}
	
	@Override
	public BlockBase setCreativeTab(CreativeTabs tab) {
		super.setCreativeTab(tab);
		return this;
	}
}

 

create a class that extends block then have it register automatically:
 

public class SimpleBlock extends Block{
  
  public SimpleBlock(ResourceLocation loc,Material mat)
  {
    	super(mat);
        this.setRegistryName(loc);
        ForgeRegistries.BLOCKS.register(this);
        ItemBlock item = new ItemBlock(this);
        ForgeRegistries.ITEMS.register(item);
    }
}

Then cleanup your main java by simply calling that. Yes you could store them in an array but, this will get you started. 1.8+ requires client proxy to have models unless you want your mod crashing on the server. If you plan on storing it on the array you can use the same array for both client proxy(models) and server(registeries). Do not register the array on the server proxy for some reason on dedicated servers it doesn't run at least I can't get it working.

Unless you need to override specific methods for your object do not create more then one class. You can use this for any basic block. I have a more advanced example via my lib so any block properties can be instantiated without having more then one class.
https://github.com/jredfox/evilnotchlib/blob/master/src/main/java/com/EvilNotch/lib/util/minecraft/content/blocks/BasicBlock.java

Edited by jredfox
  • Sad 1
Posted
1 minute ago, jredfox said:

create a class that extends block then have it register automatically:
 


        ForgeRegistries.BLOCKS.register(this);

        ForgeRegistries.ITEMS.register(item);

 

No. Bad modder.

  • Haha 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)
12 minutes ago, Draco18s said:

No. Bad modder.

yes I should register them during the register event via array it was just an example. The more proper way of doing this was looking at the 2d link where it stores an array to instantiate registers on client and server later

Edited by jredfox
Posted
1 hour ago, jredfox said:

it was just an example

A bad one that should never be used.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
1 hour ago, jredfox said:

yes I should register them during the register event via array it was just an example. The more proper way of doing this was looking at the 2d link where it stores an array to instantiate registers on client and server later

Most people try to get to "cute" with their registration code but you really don't need all of that. The problem is that the order of registration needs to be controlled but you also usually want static fields for the instances and it is difficult to control their initialization. So a lot of people then end up with null problems just like this poster is having.

 

So the most accepted practice is to construct the instance when registering and then inject the reference to the instance back to your field with the @ObjectHolder annotation system. If you do that, you will mostly be okay because the events are fired in a useful order and you'll always have a non-null instance registered but still get the benefit of having a field to reference the singleton directly later.

 

As in all coding, there are many ways to do things, but some are more prone to mistakes. In my experience the "self-registering" approach loses some of the control over the order of how things happen and in general simplicity is less error-prone.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
12 hours ago, GammaS_ said:

Couple of things I can see with the given code:

  1. I cannot see anywhere you are calling registerItemModel()
  2. Are you sure you are calling ModBlocks.init() before the registry events?

 

Have you got a Github Reop, where I can look at all of your code?

 I'm sorry, I cannot read anything more right now, I'm back in the evening.

 

By the way, here is my repository:

 

https://github.com/Arthgames3/-1.12.2-SapphireCraft

Posted

You see how you have this line?
System.out.println("register Sapphire Block -----------------------------------");

Why don't you do this:

System.out.println("register Sapphire Block: " + Sapphire_Block.getRegistryName().toString());

That will tell you what the block's registry name is as it attempts to register it. And if the block itself is null, you'll get a NPE there.

This gives you SO MUCH MORE INFORMATION than "I got here!"

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
2 hours ago, Draco18s said:

You see how you have this line?
System.out.println("register Sapphire Block -----------------------------------");

Why don't you do this:

System.out.println("register Sapphire Block: " + Sapphire_Block.getRegistryName().toString());

That will tell you what the block's registry name is as it attempts to register it. And if the block itself is null, you'll get a NPE there.

This gives you SO MUCH MORE INFORMATION than "I got here!"

Thanks. I'll see what I get.

Posted

So, I'll create a new, fresh workspace and start everything from 0 following a more advanced tutorial. Thanks for all the help.

 

"By the way, I'm 14 years old, I chose start programming Java with minecraft because I thought it was going to be interesting, because it's something I like. I choose to ask help for advanced modders because I thought I could learn more that way. Yes, I have done an algoritm course and I am actually making a Basic Java course, even if I know the real basicalready. I just think even if I learn advanced Java I couldn't just go and make a mod, I still should need to search, because it's minecraft forge, with it's own methods and callings ways. So yeah, call me noob, call me odd, call me wathever you want, I am just entering the programming world, and maybe I've done it in the wrong way..."

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Version 1.19 - Forge 41.0.63 I want to create a wolf entity that I can ride, so far it seems to be working, but the problem is that when I get on the wolf, I can’t control it. I then discovered that the issue is that the server doesn’t detect that I’m riding the wolf, so I’m struggling with synchronization. However, it seems to not be working properly. As I understand it, the server receives the packet but doesn’t register it correctly. I’m a bit new to Java, and I’ll try to provide all the relevant code and prints *The comments and prints are translated by chatgpt since they were originally in Spanish* Thank you very much in advance No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. MountableWolfEntity package com.vals.valscraft.entity; import com.vals.valscraft.network.MountSyncPacket; import com.vals.valscraft.network.NetworkHandler; import net.minecraft.client.Minecraft; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.animal.Wolf; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.Entity; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.network.PacketDistributor; public class MountableWolfEntity extends Wolf { private boolean hasSaddle; private static final EntityDataAccessor<Byte> DATA_ID_FLAGS = SynchedEntityData.defineId(MountableWolfEntity.class, EntityDataSerializers.BYTE); public MountableWolfEntity(EntityType<? extends Wolf> type, Level level) { super(type, level); this.hasSaddle = false; } @Override protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(DATA_ID_FLAGS, (byte)0); } public static AttributeSupplier.Builder createAttributes() { return Wolf.createAttributes() .add(Attributes.MAX_HEALTH, 20.0) .add(Attributes.MOVEMENT_SPEED, 0.3); } @Override public InteractionResult mobInteract(Player player, InteractionHand hand) { ItemStack itemstack = player.getItemInHand(hand); if (itemstack.getItem() == Items.SADDLE && !this.hasSaddle()) { if (!player.isCreative()) { itemstack.shrink(1); } this.setSaddle(true); return InteractionResult.SUCCESS; } else if (!level.isClientSide && this.hasSaddle()) { player.startRiding(this); MountSyncPacket packet = new MountSyncPacket(true); // 'true' means the player is mounted NetworkHandler.CHANNEL.sendToServer(packet); // Ensure the server handles the packet return InteractionResult.SUCCESS; } return InteractionResult.PASS; } @Override public void travel(Vec3 travelVector) { if (this.isVehicle() && this.getControllingPassenger() instanceof Player) { System.out.println("The wolf has a passenger."); System.out.println("The passenger is a player."); Player player = (Player) this.getControllingPassenger(); // Ensure the player is the controller this.setYRot(player.getYRot()); this.yRotO = this.getYRot(); this.setXRot(player.getXRot() * 0.5F); this.setRot(this.getYRot(), this.getXRot()); this.yBodyRot = this.getYRot(); this.yHeadRot = this.yBodyRot; float forward = player.zza; float strafe = player.xxa; if (forward <= 0.0F) { forward *= 0.25F; } this.flyingSpeed = this.getSpeed() * 0.1F; this.setSpeed((float) this.getAttributeValue(Attributes.MOVEMENT_SPEED) * 1.5F); this.setDeltaMovement(new Vec3(strafe, travelVector.y, forward).scale(this.getSpeed())); this.calculateEntityAnimation(this, false); } else { // The wolf does not have a passenger or the passenger is not a player System.out.println("No player is mounted, or the passenger is not a player."); super.travel(travelVector); } } public boolean hasSaddle() { return this.hasSaddle; } public void setSaddle(boolean hasSaddle) { this.hasSaddle = hasSaddle; } @Override protected void dropEquipment() { super.dropEquipment(); if (this.hasSaddle()) { this.spawnAtLocation(Items.SADDLE); this.setSaddle(false); } } @SubscribeEvent public static void onServerTick(TickEvent.ServerTickEvent event) { if (event.phase == TickEvent.Phase.START) { MinecraftServer server = net.minecraftforge.server.ServerLifecycleHooks.getCurrentServer(); if (server != null) { for (ServerPlayer player : server.getPlayerList().getPlayers()) { if (player.isPassenger() && player.getVehicle() instanceof MountableWolfEntity) { MountableWolfEntity wolf = (MountableWolfEntity) player.getVehicle(); System.out.println("Tick: " + player.getName().getString() + " is correctly mounted on " + wolf); } } } } } private boolean lastMountedState = false; @Override public void tick() { super.tick(); if (!this.level.isClientSide) { // Only on the server boolean isMounted = this.isVehicle() && this.getControllingPassenger() instanceof Player; // Only print if the state changed if (isMounted != lastMountedState) { if (isMounted) { Player player = (Player) this.getControllingPassenger(); // Verify the passenger is a player System.out.println("Server: Player " + player.getName().getString() + " is now mounted."); } else { System.out.println("Server: The wolf no longer has a passenger."); } lastMountedState = isMounted; } } } @Override public void addPassenger(Entity passenger) { super.addPassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(true)); } } } @Override public void removePassenger(Entity passenger) { super.removePassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is no longer mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(false)); } } } @Override public boolean isControlledByLocalInstance() { Entity entity = this.getControllingPassenger(); return entity instanceof Player; } @Override public void positionRider(Entity passenger) { if (this.hasPassenger(passenger)) { double xOffset = Math.cos(Math.toRadians(this.getYRot() + 90)) * 0.4; double zOffset = Math.sin(Math.toRadians(this.getYRot() + 90)) * 0.4; passenger.setPos(this.getX() + xOffset, this.getY() + this.getPassengersRidingOffset() + passenger.getMyRidingOffset(), this.getZ() + zOffset); } } } MountSyncPacket package com.vals.valscraft.network; import com.vals.valscraft.entity.MountableWolfEntity; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class MountSyncPacket { private final boolean isMounted; public MountSyncPacket(boolean isMounted) { this.isMounted = isMounted; } public void encode(FriendlyByteBuf buffer) { buffer.writeBoolean(isMounted); } public static MountSyncPacket decode(FriendlyByteBuf buffer) { return new MountSyncPacket(buffer.readBoolean()); } public void handle(NetworkEvent.Context context) { context.enqueueWork(() -> { ServerPlayer player = context.getSender(); // Get the player from the context if (player != null) { // Verifies if the player has dismounted if (!isMounted) { Entity vehicle = player.getVehicle(); if (vehicle instanceof MountableWolfEntity wolf) { // Logic to remove the player as a passenger wolf.removePassenger(player); System.out.println("Server: Player " + player.getName().getString() + " is no longer mounted."); } } } }); context.setPacketHandled(true); // Marks the packet as handled } } networkHandler package com.vals.valscraft.network; import com.vals.valscraft.valscraft; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.network.NetworkRegistry; import net.minecraftforge.network.simple.SimpleChannel; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class NetworkHandler { private static final String PROTOCOL_VERSION = "1"; public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel( new ResourceLocation(valscraft.MODID, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals ); public static void init() { int packetId = 0; // Register the mount synchronization packet CHANNEL.registerMessage( packetId++, MountSyncPacket.class, MountSyncPacket::encode, MountSyncPacket::decode, (msg, context) -> msg.handle(context.get()) // Get the context with context.get() ); } }  
    • Do you use features of inventory profiles next (ipnext) or is there a change without it?
    • Remove rubidium - you are already using embeddium, which is a fork of rubidium
  • Topics

×
×
  • Create New...

Important Information

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