Jump to content

[1.12] new registry system example / tutorial


Kombat Kitten

Recommended Posts

Hey guys,

 

I'm pretty confused by the new registry system. All the tutorials and example mods I could find still do it the old way. Even the ones that claim to be 1.12 still often use GameRegistry.register(), wich doesn't exist anymore (or am I blind?). Does anyone know a good tutorial or example mod that explains the new system?

 

Thanks

Link to comment
Share on other sites

51 minutes ago, Kombat Kitten said:

Even the ones that claim to be 1.12 still often use GameRegistry.register(), wich doesn't exist anymore (or am I blind?).

It's private.

Please link any 1.12 tutorials that are still doing it that way so that we can inform them that they're either doing it wrong or falsely claiming to be a 1.12 tutorial.

 

The new way feels oddly roundabout to me, but there are certain advantages to it (namely that the game can do a full rebuild of blocks and items while the game is running, should it need to).

 

Essentially you need to subscribe to the RegistryEvent.Register<T> events (and you'll put the type of object you want to register where the T is, e.g. RegistryEvent.Register<Block>) and call event.getRegistry().register(...) on all of your things. Note that you will have to register item forms of your blocks yourself if you want your blocks to exist as items (i.e. pickup-able).

 

You will also need to subscribe to the ModelRegistryEvent in order to register item models (though you still call ModelLoader.setCustomModelResourceLocation(...))

 

If you would like, I have set up two classes that I call my Easy Registry. It is essentially a wrapper around these things the way GameRegistry used to wrap around vanilla and forge internals.

 

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 EasyRegistry classes are effectively both event handler (for the aforementioned events) and the proxy classes for my library:

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/hardlib/HardLib.java#L44

 

You do not need to clone all of HardLib to make this work, you can re-point the references to your own library or main mod class, although there are some helpful interfaces you might want (that handle things like custom IStateMappers and so on).  Usage is very simple and easy.

 

It is also advised that you use @ObjectHolder annotations on your block/item fields (which I am not currently doing) in order to allow other mods to override your own (the "Substitution Alias" system wrought 1.12), see Lex's comments 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.

Link to comment
Share on other sites

Bad tutorials is a thing we do our best to fight against, letting their authors know about the problems so they can be fixed. No worries if you can't find them again, it just would have been helpful. :)

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

1 hour ago, Kokkie said:

Kombat Kitten you can look at your browser history (if it is safe to look at right now ( ͡° ͜ʖ ͡°))

Haha it is... though I've visited a few hundred websites today (learning to mod = using the internet, as you might know).

 

Further I have some problems with registering my texture. This is the code I have now:

https://github.com/KombatKitten/Collision/tree/Forums-Question/src

 

Does anyone know what I'm doing wrong?

Link to comment
Share on other sites

Not related to your problem, but:

https://github.com/KombatKitten/Collision/blob/Forums-Question/src/main/java/com/github/KombatKitten/dimensionalMagic/CommonProxy.java#L43-L44

You shouldn't do this. You should set the unlocalized name to the registry name so that your mod ID appears in the unlocalized name (this avoids conflicts with two mods naming their item the same thing).

 

Post your log file.

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

12 hours ago, Draco18s said:

Not related to your problem, but:

https://github.com/KombatKitten/Collision/blob/Forums-Question/src/main/java/com/github/KombatKitten/dimensionalMagic/CommonProxy.java#L43-L44

You shouldn't do this. You should set the unlocalized name to the registry name so that your mod ID appears in the unlocalized name (this avoids conflicts with two mods naming their item the same thing).

 

Post your log file.

like this?
        SIMPLEBLOCKI.setRegistryName(Reference.MODID, "simpleblock");
        SIMPLEBLOCKI.setUnlocalizedName(SIMPLEBLOCKI.getRegistryName().toString());

I changed unlocalized name of the block too.

 

console output (if that's what you mean): https://pastebin.com/G1Ha0F2T

 

 

Link to comment
Share on other sites

5 hours ago, Kombat Kitten said:

like this?
        SIMPLEBLOCKI.setRegistryName(Reference.MODID, "simpleblock");
        SIMPLEBLOCKI.setUnlocalizedName(SIMPLEBLOCKI.getRegistryName().toString());

I changed unlocalized name of the block too.

Yep.

5 hours ago, Kombat Kitten said:

console output (if that's what you mean): https://pastebin.com/G1Ha0F2T

Huh, I don't see anything in there.

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

1 minute ago, Kombat Kitten said:

you mean it's empty?

No, I mean I don't see any errors being logged.

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

@Choonster Can we get your eyes on this? You seem to be more adept than anyone in finding issues with item model problems.

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

@Mod.EventBusSubscriber registers the Class with the event bus, so only static @SubscribeEvent methods will be called. Your RegistryEvent.Register handlers in CommonProxy and ClientProxy are non-static, so they will never be called.

 

There's no need to handle Block/Item registration in your proxies, do it in common classes (e.g. DMBlocks/DMItems).

 

There's no reason to have a common proxy class, since proxies are for sided code. Common code belongs in your @Mod class or other common classes.

 

Always annotate override methods with @Override so you get a compilation error if they don't actually override/implement a super method.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

9 minutes ago, Choonster said:

@Mod.EventBusSubscriber registers the Class with the event bus, so only static @SubscribeEvent methods will be called. Your RegistryEvent.Register handlers in CommonProxy and ClientProxy are non-static, so they will never be called.

Ah ha. I still have trouble spotting this even though I know to look for it.

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

58 minutes ago, Choonster said:

@Mod.EventBusSubscriber registers the Class with the event bus, so only static @SubscribeEvent methods will be called. Your RegistryEvent.Register handlers in CommonProxy and ClientProxy are non-static, so they will never be called.

Yeah, I already changed them to static because I got an error. Now the error is gone but the block and the item are still using the basic textures (the item is acquirable through /give and the creative tab and the block is placable). I have pushed all the changes to GitHub.

Btw, the display name of the block/item is still equal to the unlocalized name, even though I have set up a .lang file. Maybe this could have something to do with de model not loading? Something could be wrong with the registering of the block and item.

Link to comment
Share on other sites

9 minutes ago, Kombat Kitten said:

Btw, the display name of the block/item is still equal to the unlocalized name, even though I have set up a .lang file. Maybe this could have something to do with de model not loading? Something could be wrong with the registering of the block and item.

https://github.com/KombatKitten/Collision/tree/Forums-Question/src/main/resources/assets/dimensional_magic/lang

Your langfile is incorrectly named. It should be en_us.lang (all lower case).

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

On 17-9-2017 at 7:02 PM, Choonster said:

@Mod.EventBusSubscriber registers the Class with the event bus, so only static @SubscribeEvent methods will be called. Your RegistryEvent.Register handlers in CommonProxy and ClientProxy are non-static, so they will never be called.

 

I changed them to static, but it's still not working. I don't think the problem is in the java code so could you take a look at the .json files? I might have made a mistake there

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

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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