Jump to content

[1.12.1] [UNSOLVED] Registering blocks/items and models


Bektor

Recommended Posts

Hi,

 

I've got the following code I've used so far for handling all varius aspects of registering my blocks and the models for its. This code is for blocks only, but I've got some similiar code for items, too.

 

My problem is now, I'm currently porting some things from my mod over to 1.12.1 and 1.11.2 with using the new RegistryEvents, but I don't want to lose  the flexibility of the system I've got below.

Note: This system was also used in my old mod for orginizing stuff. This means I've used it in my old mod also to register everything with sub-folders. For example I've got those paths when a block had multiply variants and still want to have it as an

optional part in my 1.12 code with the RegistryEvents.

Quote

assets.primevalforest.models.item.stoneBrick

assets.primevalforest.textures.blocks.rocks

	/**
	 * Provides the functionality of automatically registering the block and
	 * setting the registry name and unlocalized name. It also registered
	 * the block JSON renderer's and the item block with it's JSON renderer's.
	 * 
	 * @param block The block to register
	 * @param name The unique name of the block
	 * @param itemFactory  A function that creates the ItemBlock instance, or null if no ItemBlock should be created
	 * @param withMeta Should the meta data of the block also be registered?
	 * @return The block
	 */
	public static Block register(Block block, String name, @Nullable Function<Block, ItemBlock> itemFactory, boolean withMeta) {
		block.setUnlocalizedName(Constants.MOD_ID.toLowerCase() + "." + name);
		block.setRegistryName(name);
		GameRegistry.register(block);
		
		if(itemFactory != null) {
			final ItemBlock itemBlock = itemFactory.apply(block);
			GameRegistry.register(itemBlock.setRegistryName(block.getRegistryName()));
			
			if(block instanceof IItemOreDict)
				((IItemOreDict)block).initOreDict();
			
			if(itemBlock instanceof IItemOreDict)
				((IItemOreDict)itemBlock).initOreDict();
			
			if(FMLCommonHandler.instance().getEffectiveSide().isClient())
				BlockRegistry.registerRenderer(block, withMeta);
		}
		
		return block;
	}
	
	/**
	 * Provides the functionality of automatically registering the block 
	 * JSON renderer's and the item block with it's JSON renderer's.
	 * 
	 * @param block The block to register
	 * @param withMeta Should the meta data of the block also be registered?
	 * @return If the registration of the JSON renderer was successful.
	 */
	@SideOnly(Side.CLIENT)
	private static boolean registerRenderer(Block block, boolean withMeta) {
		Iterator<IBlockState> it = block.getBlockState().getValidStates().iterator();
		boolean flag = true;
		
		while(it.hasNext()) {
			IBlockState state = it.next();
			
			if(state == null) {
				JustAnotherEnergy.getLogger().error("Skipping block rendering registration for {}", state);
				flag = false;
				break;
			}
			
			int meta = block.getMetaFromState(state);
			RenderUtil.renderBlock(block, withMeta ? meta : 0);
		}
		return flag;
	}
	
		/**
	 * Provides the functionality of automatically registering the block and
	 * setting the registry name and unlocalized name. It also registered
	 * the block JSON renderer's and the item block with it's JSON renderer's.
	 * <p>
	 * This method tells Minecraft that the model json's can be found in a sub-folder.
	 * 
	 * @param block The block to register
	 * @param name The unique name of the block
	 * @param itemFactory  A function that creates the ItemBlock instance, or null if no ItemBlock should be created
	 * @param withMeta Should the meta data of the block also be registered?
	 * @param variants The different variants in which block comes
	 * @return The block
	 */
	public static <T extends IType> Block register(Block block, String name, @Nullable Function<Block, ItemBlock> itemFactory, boolean withMeta, @Nullable T[] variants) {
		block.setUnlocalizedName(Constants.MOD_ID.toLowerCase() + "." + name);
		block.setRegistryName(name);
		GameRegistry.register(block);
		
		if(itemFactory != null) {
			final ItemBlock itemBlock = itemFactory.apply(block);
			GameRegistry.register(itemBlock.setRegistryName(block.getRegistryName()));
			
			if(FMLCommonHandler.instance().getEffectiveSide().isClient()) {
				Iterator<IBlockState> it = block.getBlockState().getValidStates().iterator();
				
				while(it.hasNext()) {
					IBlockState state = it.next();
					
					if(state == null) {
						JustAnotherEnergy.getLogger().error("Skipping block rendering registration for {}", state);
						break;
					}
					
					for(T variant : variants) {
						RenderUtil.renderBlock(BlockRegistry.getResourcePath(name), block, variant.getID(), variant.getName());
					}
				}
			}
		}
		
		return block;
	}

 

Thx in advance.

Bektor

Developer of Primeval Forest.

Link to comment
Share on other sites

GameRegistry.register is private in 1.12, so I don't know how you're using it. You should be using the Registry events.

 

If you want to have a one-line registration and handle everything all at once regardless of how you want to register the block, check out my EasyRegistry classes:

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/hardlib/EasyRegistry.java

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/hardlib/client/ClientEasyRegistry.java

 

note that the classes are both proxy and event handler.

Edited by Draco18s

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.

Link to comment
Share on other sites

2 minutes ago, Draco18s said:

GameRegistry.register is private in 1.12, so I don't know how you're using it. You should be using the Registry events.

 

I'm not using GameRegistry.register. The code is from 1.10.2 and my goal is to have a system which does something similiar in 1.12 using Registry events. I know how to register blocks and

items with the registry events, but I don't know how to do it in a flexible way like my old code allowed it.

 

4 minutes ago, Draco18s said:

If you want to have a one-line registration and handle everything all at once regardless of how you want to register the block, check out my EasyRegistry classes:

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/hardlib/EasyRegistry.java

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/hardlib/client/ClientEasyRegistry.java

 

note that the classes are both proxy and event handler.

Ok,I'm looking into it. ;) 

Developer of Primeval Forest.

Link to comment
Share on other sites

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

    • 2024-05-30 17:15:50,640 main WARN Advanced terminal features are not available in this environment [17:15:50] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher running: args [--launchTarget, forgeserver, --fml.forgeVersion, 43.3.0, --fml.mcVersion, 1.19.2, --fml.forgeGroup, net.minecraftforge, --fml.mcpVersion, 20220805.130853] [17:15:50] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher 10.0.8+10.0.8+main.0ef7e830 starting: java version 22.0.1 by Oracle Corporation; OS Windows 10 arch amd64 version 10.0 [17:15:51] [main/INFO] [mixin/]: SpongePowered MIXIN Subsystem Version=0.8.5 Source=union:/C:/Users/Gamer/OneDrive/Skrivebord/MC%20SB%204/libraries/org/spongepowered/mixin/0.8.5/mixin-0.8.5.jar%2363!/ Service=ModLauncher Env=SERVER [17:15:52] [main/WARN] [ne.mi.fm.lo.mo.ModFileParser/LOADING]: Mod file C:\Users\Gamer\OneDrive\Skrivebord\MC SB 4\libraries\net\minecraftforge\fmlcore\1.19.2-43.3.0\fmlcore-1.19.2-43.3.0.jar is missing mods.toml file [17:15:52] [main/WARN] [ne.mi.fm.lo.mo.ModFileParser/LOADING]: Mod file C:\Users\Gamer\OneDrive\Skrivebord\MC SB 4\libraries\net\minecraftforge\javafmllanguage\1.19.2-43.3.0\javafmllanguage-1.19.2-43.3.0.jar is missing mods.toml file [17:15:52] [main/WARN] [ne.mi.fm.lo.mo.ModFileParser/LOADING]: Mod file C:\Users\Gamer\OneDrive\Skrivebord\MC SB 4\libraries\net\minecraftforge\lowcodelanguage\1.19.2-43.3.0\lowcodelanguage-1.19.2-43.3.0.jar is missing mods.toml file [17:15:52] [main/WARN] [ne.mi.fm.lo.mo.ModFileParser/LOADING]: Mod file C:\Users\Gamer\OneDrive\Skrivebord\MC SB 4\libraries\net\minecraftforge\mclanguage\1.19.2-43.3.0\mclanguage-1.19.2-43.3.0.jar is missing mods.toml file [17:15:52] [main/INFO] [ne.mi.fm.lo.mo.JarInJarDependencyLocator/]: Found 2 dependencies adding them to mods collection [17:15:54] [main/INFO] [mixin/]: Compatibility level set to JAVA_17 [17:15:54] [main/INFO] [cp.mo.mo.LaunchServiceHandler/MODLAUNCHER]: Launching target 'forgeserver' with arguments [] [17:15:55] [main/WARN] [mixin/]: Error loading class: java/lang/invoke/MethodHandles$Lookup (java.lang.IllegalArgumentException: Unsupported class file major version 66) [17:15:55] [main/WARN] [mixin/]: Error loading class: java/lang/Boolean (java.lang.IllegalArgumentException: Unsupported class file major version 66) Exception in thread "main" java.lang.RuntimeException: org.spongepowered.asm.mixin.transformer.throwables.MixinTransformerError: An unexpected critical error was encountered         at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:32)         at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53)         at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71)         at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.Launcher.run(Launcher.java:106)         at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.Launcher.main(Launcher.java:77)         at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26)         at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23)         at [email protected]/cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) Caused by: org.spongepowered.asm.mixin.transformer.throwables.MixinTransformerError: An unexpected critical error was encountered         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinProcessor.applyMixins(MixinProcessor.java:392)         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinTransformer.transformClass(MixinTransformer.java:250)         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.service.modlauncher.MixinTransformationHandler.processClass(MixinTransformationHandler.java:131)         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.launch.MixinLaunchPluginLegacy.processClass(MixinLaunchPluginLegacy.java:131)         at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.serviceapi.ILaunchPluginService.processClassWithFlags(ILaunchPluginService.java:156)         at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.LaunchPluginHandler.offerClassNodeToPlugins(LaunchPluginHandler.java:88)         at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.ClassTransformer.transform(ClassTransformer.java:120)         at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.TransformingClassLoader.maybeTransformClassBytes(TransformingClassLoader.java:50)         at cpw.mods.securejarhandler/cpw.mods.cl.ModuleClassLoader.readerToClass(ModuleClassLoader.java:113)         at cpw.mods.securejarhandler/cpw.mods.cl.ModuleClassLoader.lambda$findClass$15(ModuleClassLoader.java:219)         at cpw.mods.securejarhandler/cpw.mods.cl.ModuleClassLoader.loadFromModule(ModuleClassLoader.java:229)         at cpw.mods.securejarhandler/cpw.mods.cl.ModuleClassLoader.findClass(ModuleClassLoader.java:219)         at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:637)         at java.base/java.lang.Class.forName(Class.java:620)         at java.base/java.lang.Class.forName(Class.java:595)         at MC-BOOTSTRAP/[email protected]/net.minecraftforge.fml.loading.targets.CommonServerLaunchHandler.lambda$launchService$0(CommonServerLaunchHandler.java:29)         at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:30)         ... 7 more Caused by: org.spongepowered.asm.mixin.throwables.ClassMetadataNotFoundException: java.lang.Boolean         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinPreProcessorStandard.transformMethod(MixinPreProcessorStandard.java:754)         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinPreProcessorStandard.transform(MixinPreProcessorStandard.java:739)         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinPreProcessorStandard.attach(MixinPreProcessorStandard.java:310)         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinPreProcessorStandard.createContextFor(MixinPreProcessorStandard.java:280)         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinInfo.createContextFor(MixinInfo.java:1288)         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinApplicatorStandard.apply(MixinApplicatorStandard.java:292)         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.TargetClassContext.apply(TargetClassContext.java:383)         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.TargetClassContext.applyMixins(TargetClassContext.java:365)         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinProcessor.applyMixins(MixinProcessor.java:363)         ... 23 more Press any key to continue . . . I get this crash message and a few more but this one seams the most relavant. Do anyone know what to do?
    • Also I should mention, This is for inellij, not for mcCreator 
    • But does it work without essential?
    • Well, I only have the Xaero’s Minimap, and the essential I’ll use it to play with friends online there’s any way to send a picture to show you my .minecraft folder
    • I am currently Porting a mod from 1.19 to 1.20.1, one of the Items writes some information into the chat when used. To prevent spamming older messages are deleted.  public boolean receive(Supplier<NetworkEvent.Context> context) { context.get().enqueueWork(() -> { ChatComponent chatGui = Minecraft.getInstance().gui.getChat(); chatGui.deleteMessage(signature); chatGui.addMessage(message, signature, GuiMessageTag.system()); }); return true; } In 1.20.1 it doesn't work anymore. The Message gets replaced after 60 Seconds with a message saying: "This chat message has been deleted by the server."
  • Topics

×
×
  • Create New...

Important Information

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