Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[Solved][Outdated]How to override/use blocks without custom class


devguydan
 Share

Recommended Posts

I am working my way through the docs and I find this: https://mcforge.readthedocs.io/en/latest/blocks/blocks/#basic-blocks

I think this is a great place to start and so I decide I want to create a rock-type class that breaks easily. Simple enough right? Well not for me rn.

I start with a base project: https://github.com/djpeach/ExampleMod/tree/baseStructure

I start trying to work with what I can figure out and try:

@SubscribeEvent
public static void addBlocks(RegistryEvent.Register<Block> event) {
    Block myRock = new Block(Material.ROCK);
    myRock.setHardness(0.1f);
    event.getRegistry().register(myRock);
}

I guess perhaps this is registering, but I cannot see it in my creative tabs so I try:


myRock.setCreativeTab(CreativeTabs.MATERIALS);

Still nothing. I don't know quite what to try next. My gut tells me it has something to do with registries, which is where I am most confused. I figure it might have to do with https://mcforge.readthedocs.io/en/latest/concepts/registries/#creating-registries, more specifically the ObjectHolder stuff. I can't seem to work out its purpose however.

If someone could nudge me down the right path here, that would be great. Going to move on to Items for now. Hopefully they are easier :)

Edited by devguydan
Solved/outdated

I hate signatures, they're too distracting

Link to comment
Share on other sites

1. Remember to set the block's registry name with Block#setRegistryName.

2. If you want to have an item representation of your block, you also need to register an ItemBlock of it (in RegistryEvent.Register<Item>):

itemRegistry.register(new ItemBlock(myBlock));

.

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Link to comment
Share on other sites

What exactly does the registryName do for us? I have read that page 5+ times and it doesn't really say why. But I did it and I registered an ItemBlock with it. Still not working

 

I know I could get this working if I followed all these examples with external classes, but the docs very clearly say that is not necessary for the basics. And I want to be able to understand what is going on at a lower level before moving into more abstract designs.

Edited by devguydan
Added why I am doing it this way

I hate signatures, they're too distracting

Link to comment
Share on other sites

1. A registry name is like the unique identifier for a block/item.

2. Push your repo. I cannot find your code for your block in all 4 branches.

Edited by DavidM

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Link to comment
Share on other sites

Makes sense. I'm just so far from that rn. I want to register and see an [unrendered] block. And I want to do it at a VERY basic level. I don't want to extend the Block class or anything. The docs make it seem this is very possible, so idk what step in this I am missing.

 

This is what I expect to see:  

image.png

I hate signatures, they're too distracting

Link to comment
Share on other sites

One thing I am noticing in other code that I don't have is 

ModelRegistryEvent

and 

ModelLoader.setCustomModelResourceLocation()

Is this the step I am missing? I cannot find anything about registering models or setting the resource location in the docs. Are there more in-depth docs somewhere? Or do I need to start diving into source code and reading comments?

I hate signatures, they're too distracting

Link to comment
Share on other sites

Ok I lowercase and matched my registry names.

I made the @ObjectHolder variable final, and created the Block when registering it? Not sure how to do this part

@SubscribeEvent
public static void addBlocks(RegistryEvent.Register<Block> event) {
    Blocks.myRock.setHardness(0.1f);
    Blocks.myRock.setCreativeTab(CreativeTabs.MATERIALS);
    Blocks.myRock.setRegistryName(MOD_ID,"myrock");
    event.getRegistry().register(new Block(Material.ROCK));
}

 

I hate signatures, they're too distracting

Link to comment
Share on other sites

2 minutes ago, diesieben07 said:
  • You cannot access Blocks.myRock there. Object holders are initialized after all registry events.
  • Use a local variable, apply all properties to it, then register it. Blocks.myRock will then be filled properly by @ObjectHolder.

Ok I totally misunderstood their purpose then. So I know they are refreshed after block, item, and then all other registry events. What does "refreshed" do to them and why? What do they get used for down the line?

 

I hate signatures, they're too distracting

Link to comment
Share on other sites

5 minutes ago, devguydan said:

What does "refreshed" do to them and why? What do they get used for down the line?

The purpose for @ObjectHolder is: "Put the registry entry (block, item, etc.) with this registry name into this field". Forge will make sure the field stays up to date if the entry ever changes, registry entries can be overridden. It can also be used for soft-dependencies between mods: If you want to do something with a block from another mod, only if that mod is there, you can ask Forge to inject that block using @ObjectHolder and it will do so, if it's present.

Link to comment
Share on other sites

  • 10 months later...

It’s funny seeing how much stuff I did not know back then. I understand all this now, and am lost and confused on completely different things now, yay!

 

And I can’t believe this was less than a year ago. I don’t remember it at all.

Edited by devguydan
Timeline wow

I hate signatures, they're too distracting

Link to comment
Share on other sites

Btw, DeferredRegister is the best way to do stuff now.

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

3 hours ago, Cadiboo said:

Btw, DeferredRegister is the best way to do stuff now.

Yes! I was trying to get Deferred registers to work based on what I saw in your example mod, but was getting issues with a null registry. I got it all working without deferred registries now, so I plan to revisit it again next time I get a chance to look at it. Also just curious, what are the benefits of the deferred registries over the event hooks? Sounds like they both register things at the correct time.

I hate signatures, they're too distracting

Link to comment
Share on other sites

On 2/11/2020 at 1:49 AM, devguydan said:

what are the benefits of the deferred registries over the event hooks? 

DeferredRegister uses the event hooks. They just have much simpler and cleaner syntax. They also take care of ensuring your object references stay up to date and also support registry overrides.

Edited by Cadiboo
  • Thanks 1

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

1 hour ago, Cadiboo said:

ensuring your object references stay out of date

I am pretty sure this is not what you meant. ;)

  • Like 1
  • Thanks 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.

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.

Guest
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.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.