Jump to content

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


Recommended Posts

Posted (edited)

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

Posted

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.

 

 

Posted (edited)

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

Posted (edited)

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.

 

 

Posted

pushed

Where is that unique id used? The resources and textures? I can't even get it to tell me it can't find the resources 

 

I hate signatures, they're too distracting

Posted

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

Posted

And it would be nice to learn (along the same lines) how to modify the hardnes/other properties of existing blocks. Say for example, make dirt hard as obsidian.

I hate signatures, they're too distracting

Posted

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

Posted

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

Posted
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

  • 10 months later...
Posted (edited)

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

Posted

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)

Posted
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

Posted (edited)
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)

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

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

    • Hi, I've been having trouble trying to use forge as it shows a black screen when I open the game, but I can still interact with it and hear the music.  I've done all of the step by steps and most common fixes like updating drivers, keeping up to date with Java, deleting and reinstalling minecraft, restarting my computer MANY times, even smaller things like splash.properties (I didn't have that file so I added it and set it to false thinking it would do something, definitely not) and making sure to prioritize my rtx 3070 in the settings but with no luck. Minecraft works as intended when I uninstall forge and I also don't have any mods currently, it just gives me this issue when I install forge. I also increased the ram usage, made sure my hardware isn't full or anything, and even changed the resolution in hopes it would fix things. I checked my antivirus and firewall but that isn't the issue either. Trust me, I've done everything I can think of. For some reason the black screen does flicker a little into the main menu, but obviously unplayable. I couldn't even make my way to the settings with how little it flickered. I'm not sure if it flickered randomly or if it was because I was messing around moving and clicking a bunch, I didn't really test it that much.  
    • I've had a really weird issue recently,  I wanted to add the Depper and Darker mod on my dedicated server (MC 1.21 with Fabric 0.16.9, hosted on nitroserv.com) but whenever I do add the mod the sever stops doing anything after listing the mods, and I get no crash or error or anything, just a stuck server. Here's a normal log of the server booting up: https://pastebin.com/JipFF2Eh and here's the log of the server doing the weird thing: https://pastebin.com/W4JBh3eX I just don't understand it. I've tried removing other mods (somewhat randomly) but deeper and darker still breaks my server whenever I add it. NitroServ support staff is about as confused as I am and I've had no response from the Deeper and Darker support staff... Now I know this is the Forge support not the Fabric support but I'm just trying to know if anyone has any kind of idea to fix this (aside from not using the mod obviously) Also I still have a bunch of errors and warnings whenever the server does start properly, are there any of them I should be worried about?
    • Delete the config of RandomTweaker (config folder) If there is no change, remove this mod
    • Hello! So i have been trying to make a mod that adds plant fiber to minecraft 1.16.5 (i believe there are mods that add plant fiber but not for 1.16.5) but the problem is that i want to modify the loot table of grass to always drop plant fiber but also keep the vanilla drops. Most common answer i have seen is GlobalLootModifiers. But my tiny brain cant understand any tutorials. So any help is appreciated.
  • Topics

×
×
  • Create New...

Important Information

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