Jump to content

Recommended Posts

Posted

I recently updated my mod from 1.11.2 to 1.12 only to find that, after redoing all registry, all my items except for one (which is baffling) don't have textures. Plus my blocks aren't registering in the game even though the FML log isn't giving me any errors except for one, which is for some reason registered under the minecraft domain DESPITE me distinctly stating the mod id as the domain

 

Posted
Just now, GooberGunter said:

I recently updated my mod from 1.11.2 to 1.12 only to find that, after redoing all registry, all my items except for one (which is baffling) don't have textures. Plus my blocks aren't registering in the game even though the FML log isn't giving me any errors except for one, which is for some reason registered under the minecraft domain DESPITE me distinctly stating the mod id as the domain

Code and ModelLoader.setCustomModelResourceLocation needs to be called from ModelRegistryEvent.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
3 minutes ago, GooberGunter said:

Thanks, Is this somewhere in the forge doc?

I do not believe so but you register your models the same way you did before, it just needs to be in the event.

  • Like 1

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

Alright, all the textures for the tools and items work. On another note, the blocks are still not being registered in the game even though i have the handler set up:

Spoiler


	@Mod.EventBusSubscriber(modid = Reference.MOD_ID)
	public static class BlockRegisterHandler{
		@SubscribeEvent
		public static void registerBlock(final RegistryEvent.Register<Block> event) {
			final IForgeRegistry<Block> reg = event.getRegistry();
			for(int i=0; i < blocklist.size(); i++) {
				reg.register(blocklist.get(i));
				blocklist.get(i).setCreativeTab(blocks);
				ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(blocklist.get(i)), 0, new ModelResourceLocation(new ResourceLocation(Reference.MOD_ID, blocklist.get(i).getUnlocalizedName().substring(5)), "inventory"));
				Utils.getLogger().info("Registered Block: " + blocklist.get(i).getUnlocalizedName().substring(5));
			}
			
			
		}
	}

 

 

Posted (edited)
new ModelResourceLocation(new ResourceLocation(Reference.MOD_ID, blocklist.get(i).getUnlocalizedName().substring(5)), "inventory")

Should be

new ModelResourceLocation(blocklist.get(i).getRegistryName(), "inventory")


Please do not follow old crappy tutorials.

Edited by MrBendelScrolls
Posted
Just now, GooberGunter said:

Got it, thanks

Also are you calling ModelLoader.setCustomModelResourceLocation in the Block Registry event? If so it has its own event ModelRegistryEvent. 

9 minutes ago, GooberGunter said:

On another note, the blocks are still not being registered in the game even though i have the handler set up:

You are not registering the ItemBlock for them.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted (edited)

Also, again... MY COMPLAINS ABOUT THE CODE! Feel free to call me a bad person with all of the synonyms.

This is unnecessary to use fori loop and list.get(i). This code is very hard to read.
Simplier and cleaner is to use foreach.
Example:

for (Block block : blocklist) {
    event.getRegistry().register(block);
}
Edited by MrBendelScrolls
I can't think
  • Like 1
Posted
2 minutes ago, MrBendelScrolls said:

Also, again... MY COMPLAINS ABOUT THE CODE! Feel free to call me a bad person with all of the synonyms.

This is unnecessary to use fori loop and list.get(i). This code is very hard to read.
Simplier and cleaner is to use foreach.
Example:


for (Block block : blocklist) {
    event.getRegistry().register(block);
}

Not at all, I'm happy to receive any information on how to improve my code and java practices. Thanks for the tip

Posted
4 minutes ago, GooberGunter said:

I

What method do I call?

I think you will also need a Item Registry event to register the ItemBlocks, but I am not really sure. I haven't started updating to 1.12 just yet.

  • Like 1

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

Fun, when I tried the item block registry, I got:

Spoiler

[11:46:57] [main/ERROR] [FML]: Exception caught during firing event net.minecraftforge.event.RegistryEvent$Register@7e3f3a34:
java.lang.NullPointerException: Can't use a null-name for the registry, object net.minecraft.item.ItemBlock@3cb8b037.
    at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:864) ~[guava-21.0.jar:?]
    at net.minecraftforge.registries.ForgeRegistry.add(ForgeRegistry.java:272) ~[ForgeRegistry.class:?]
    at net.minecraftforge.registries.ForgeRegistry.add(ForgeRegistry.java:266) ~[ForgeRegistry.class:?]
    at net.minecraftforge.registries.ForgeRegistry.register(ForgeRegistry.java:110) ~[ForgeRegistry.class:?]
    at com.ninja3659.explorationexpansion.init.ModBlocks$BlockRegisterHandler.registerItemBlock(ModBlocks.java:79) ~[ModBlocks$BlockRegisterHandler.class:?]
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_5_BlockRegisterHandler_registerItemBlock_Register.invoke(.dynamic) ~[?:?]
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90) ~[ASMEventHandler.class:?]
    at net.minecraftforge.fml.common.eventhandler.EventBus$1.invoke(EventBus.java:143) ~[EventBus$1.class:?]
    at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:179) [EventBus.class:?]
    at net.minecraftforge.registries.GameData.fireRegistryEvents(GameData.java:728) [GameData.class:?]
    at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:605) [Loader.class:?]
    at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:266) [FMLClientHandler.class:?]
    at net.minecraft.client.Minecraft.init(Minecraft.java:508) [Minecraft.class:?]
    at net.minecraft.client.Minecraft.run(Minecraft.java:416) [Minecraft.class:?]
    at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_131]
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_131]
    at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
    at GradleStart.main(GradleStart.java:26) [start/:?]
[11:46:57] [main/ERROR] [FML]: Index: 3 Listeners:
[11:46:57] [main/ERROR] [FML]: 0: NORMAL
[11:46:57] [main/ERROR] [FML]: 1: net.minecraftforge.fml.common.eventhandler.EventBus$1@26a8e303
[11:46:57] [main/ERROR] [FML]: 2: net.minecraftforge.fml.common.eventhandler.EventBus$1@18365e98
[11:46:57] [main/ERROR] [FML]: 3: net.minecraftforge.fml.common.eventhandler.EventBus$1@4c8c3285
[11:46:57] [main/ERROR] [FML]: 4: net.minecraftforge.fml.common.eventhandler.EventBus$1@74b57299
[11:46:57] [main/ERROR] [FML]: 5: net.minecraftforge.fml.common.eventhandler.EventBus$1@156437f7
[11:46:57] [main/INFO] [STDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:630]: ---- Minecraft Crash Report ----
// Oh - I know what I did wrong!

Time: 7/20/17 11:46 AM
Description: Initializing game

java.lang.NullPointerException: Can't use a null-name for the registry, object net.minecraft.item.ItemBlock@3cb8b037.
    at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:864)
    at net.minecraftforge.registries.ForgeRegistry.add(ForgeRegistry.java:272)
    at net.minecraftforge.registries.ForgeRegistry.add(ForgeRegistry.java:266)
    at net.minecraftforge.registries.ForgeRegistry.register(ForgeRegistry.java:110)
    at com.ninja3659.explorationexpansion.init.ModBlocks$BlockRegisterHandler.registerItemBlock(ModBlocks.java:79)
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_5_BlockRegisterHandler_registerItemBlock_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:728)
    at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:605)
    at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:266)
    at net.minecraft.client.Minecraft.init(Minecraft.java:508)
    at net.minecraft.client.Minecraft.run(Minecraft.java:416)
    at net.minecraft.client.main.Main.main(Main.java:118)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    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(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    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:272)
    at net.minecraftforge.registries.ForgeRegistry.add(ForgeRegistry.java:266)
    at net.minecraftforge.registries.ForgeRegistry.register(ForgeRegistry.java:110)
    at com.ninja3659.explorationexpansion.init.ModBlocks$BlockRegisterHandler.registerItemBlock(ModBlocks.java:79)
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_5_BlockRegisterHandler_registerItemBlock_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:728)
    at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:605)
    at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:266)
    at net.minecraft.client.Minecraft.init(Minecraft.java:508)

-- Initialization --
Details:
Stacktrace:
    at net.minecraft.client.Minecraft.run(Minecraft.java:416)
    at net.minecraft.client.main.Main.main(Main.java:118)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    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(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
    at GradleStart.main(GradleStart.java:26)

-- System Details --
Details:
    Minecraft Version: 1.12
    Operating System: Windows 10 (amd64) version 10.0
    Java Version: 1.8.0_131, Oracle Corporation
    Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
    Memory: 769691016 bytes (734 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)
    JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
    IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
    FML: MCP 9.40 Powered by Forge 14.21.1.2415 5 mods loaded, 5 mods active
    States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored
    UCH    minecraft{1.12} [Minecraft] (minecraft.jar) 
    UCH    mcp{9.19} [Minecraft Coder Pack] (minecraft.jar) 
    UCH    FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.12-14.21.1.2415.jar) 
    UCH    forge{14.21.1.2415} [Minecraft Forge] (forgeSrc-1.12-14.21.1.2415.jar) 
    UCH    neem{1.0-alpha} [Exploration Expansion] (bin) 
    Loaded coremods (and transformers): 
    GL info: ' Vendor: 'Intel' Version: '4.4.0 - Build 21.20.16.4550' Renderer: 'Intel(R) HD Graphics 520'
    Launched Version: 1.12
    LWJGL: 2.9.4
    OpenGL: Intel(R) HD Graphics 520 GL version 4.4.0 - Build 21.20.16.4550, Intel
    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: 4x Intel(R) Core(TM) i7-6500U CPU @ 2.50GHz
[11:46:57] [main/INFO] [STDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:630]: #@!@# Game crashed! Crash report saved to: #@!@# C:\Users\JEHan\Desktop\Exploration Expanded\run\.\crash-reports\crash-2017-07-20_11.46.57-client.txt
Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release
 

 

I can't see what the problem is since the first block I added is not null, unless you can't cast, but it's not telling me that I can't cast a block to ItemBlock

 

ModBlocks:

Spoiler

package com.ninja3659.explorationexpansion.init;


import java.awt.List;
import java.util.ArrayList;

import com.ninja3659.explorationexpansion.Reference;
import com.ninja3659.explorationexpansion.blocks.BlockDiamondiliumBlock;
import com.ninja3659.explorationexpansion.blocks.BlockDiamondilliumOre;
import com.ninja3659.explorationexpansion.creativetabs.TabNEEMBlocks;
import com.ninja3659.explorationexpansion.creativetabs.TabNEEMItems;
import com.ninja3659.explorationexpansion.util.Utils;

import net.minecraft.block.Block;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.util.ResourceLocation;
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;

public class ModBlocks {
	
	public static Block Dblock;
	public static Block dOre;
	public static final CreativeTabs blocks = new TabNEEMBlocks();
	public static ArrayList<Block> blocklist = new ArrayList();
	public static ArrayList<ItemBlock> itemblocklist = new ArrayList();

	
	public static void init() {
		Dblock = new BlockDiamondiliumBlock("Dblock", "Dblock");
		dOre = new BlockDiamondilliumOre("dore");
		blocklist.add(Dblock);
		blocklist.add(dOre);
		itemblocklist.add(new ItemBlock(Dblock));
		itemblocklist.add(new ItemBlock(dOre));
	}
	
	
	
	public static void registerRenders() {
		registerRender(Dblock);
		registerRender(dOre);
	}
	
	
	
	public static void registerRender(Block block) {
		//try{
			Utils.getLogger().info("Registered render for: " + block.getUnlocalizedName().substring(5));
		//} catch (in)
	}
	
	@Mod.EventBusSubscriber(modid = Reference.MOD_ID)
	public static class BlockRegisterHandler{
		@SubscribeEvent
		public static void registerBlock(final RegistryEvent.Register<Block> event) {
			final IForgeRegistry<Block> reg = event.getRegistry();
			for(Block block : blocklist) {
				reg.register(block);
				block.setCreativeTab(blocks);
				Utils.getLogger().info("Registered Block: " + block.getUnlocalizedName());
			}			
			
		}
		
		@SubscribeEvent
		public static void registerItemBlock(final RegistryEvent.Register<Item> event) {
			Utils.getLogger().info("Start ItemBlock");
			final IForgeRegistry<Item> reg = event.getRegistry();
			for (ItemBlock block : itemblocklist) {
				reg.register(block);
				Utils.getLogger().info("Registered item block " + block);
			}
		}
		
		
		public static void registerRender(final ModelRegistryEvent event) {
			for (Block block : blocklist) {
				ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0, new ModelResourceLocation(new ResourceLocation(Reference.MOD_ID, block.getUnlocalizedName()), "inventory"));
			}
		}
	}
}

 

 

Posted
1 minute ago, GooberGunter said:

but it's not telling me that I can't cast a block to ItemBlock

That is not true, what it says is 

2 minutes ago, GooberGunter said:

java.lang.NullPointerException: Can't use a null-name for the registry, object net.minecraft.item.ItemBlock@3cb8b037.

You never set the registry name for the ItemBlock.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
22 minutes ago, GooberGunter said:

registry name? OH, right. Now it rings a bell. But how do I do that?

new ItemBlock(block).setRegistryName(block.getRegistryName);

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted (edited)

If you don't mind me asking, I know the code is necessary, but why is it necessary? I don't fully understand what the line does. Also where would I put this line?

Edited by GooberGunter
Posted
8 minutes ago, GooberGunter said:

If you don't mind me asking, I know the code is necessary, but why is it necessary? I don't fully understand what the line does.

It is necessary because we need some form of id that will not change. Numerical ids will change and are not mod specific, while using a ResourceLocation allows a Block, Item, etc to be traced easily back to its mod, and they are also mod specific because of the modid. So in other words a register name is just an id.

11 minutes ago, GooberGunter said:

Also where would I put this line?

You make two new ItemBlock instances in your ModBlocks class. Every time you make a new instance of any Item, Block, etc you need to set it's registry name.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
Just now, GooberGunter said:

But I set the registry name when I initialized the block:


		Dblock = new BlockDiamondiliumBlock("Dblock", "Dblock");

 

You didn't do it for the ItemBlock though.

57 minutes ago, GooberGunter said:

itemblocklist.add(new ItemBlock(Dblock));

 

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted (edited)

Forge isn't reading the domain for the resource location of my blocks

ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0, new ModelResourceLocation(new ResourceLocation("neem: " + block.getRegistryName()), "inventory"));

I never really learned this part right

Edited by GooberGunter
Posted
3 minutes ago, GooberGunter said:

Forge isn't reading the domain for the resource location of my blocks

Don't do new ResourceLocation(String, String)

Block#getRegistryName() returns a ResourceLocation.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted (edited)

Then should there be something specific that I set the registry name to? Actually, in each of their block classes, the registry name is a new ResourceLocation(String, String). Is this right?

Apparently that doesn't matter because forge is still looking for the textures in minecraft:

I'm going to check my json files

 

EDIT: Yup, that was the problem. In the json files, the texture location didn't specify my mod id

Edited by GooberGunter
Posted
1 minute ago, GooberGunter said:

Then should there be something specific that I set the registry name to?

The registry name should follow these two rules

  1. It should contain the modid as the domainName.
  2. It should be unique.

Though i need to clear something up and it will be easier done through this modding video I made for 1.10.2, which doesn't use the events so ignore that part, but what it does do correctly is how to call the ModelLoader.setCustomModelResourceLocation method. At the bottom you will see how it is called, you may need to pause the video.

  • Like 1

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

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.