Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [Solved][Outdated]How to override/use blocks without custom class
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 1
devguydan

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

By devguydan, March 13, 2019 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

devguydan    2

devguydan

devguydan    2

  • Tree Puncher
  • devguydan
  • Members
  • 2
  • 35 posts
Posted March 13, 2019 (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 February 10, 2020 by devguydan
Solved/outdated
  • Quote

I hate signatures, they're too distracting

Share this post


Link to post
Share on other sites

DavidM    179

DavidM

DavidM    179

  • World Shaper
  • DavidM
  • Members
  • 179
  • 1821 posts
Posted March 13, 2019

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));

.

  • Quote

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.

 

 

Share this post


Link to post
Share on other sites

devguydan    2

devguydan

devguydan    2

  • Tree Puncher
  • devguydan
  • Members
  • 2
  • 35 posts
Posted March 13, 2019 (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 March 13, 2019 by devguydan
Added why I am doing it this way
  • Quote

I hate signatures, they're too distracting

Share this post


Link to post
Share on other sites

DavidM    179

DavidM

DavidM    179

  • World Shaper
  • DavidM
  • Members
  • 179
  • 1821 posts
Posted March 13, 2019 (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 March 13, 2019 by DavidM
  • Quote

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.

 

 

Share this post


Link to post
Share on other sites

devguydan    2

devguydan

devguydan    2

  • Tree Puncher
  • devguydan
  • Members
  • 2
  • 35 posts
Posted March 13, 2019

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 

 

  • Quote

I hate signatures, they're too distracting

Share this post


Link to post
Share on other sites

diesieben07    7597

diesieben07

diesieben07    7597

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7597
  • 55122 posts
Posted March 13, 2019
1 minute ago, devguydan said:

The resources and textures?

The most important role is when saving the world to disk.

  • Quote

Share this post


Link to post
Share on other sites

devguydan    2

devguydan

devguydan    2

  • Tree Puncher
  • devguydan
  • Members
  • 2
  • 35 posts
Posted March 13, 2019

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

  • Quote

I hate signatures, they're too distracting

Share this post


Link to post
Share on other sites

devguydan    2

devguydan

devguydan    2

  • Tree Puncher
  • devguydan
  • Members
  • 2
  • 35 posts
Posted March 13, 2019

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.

  • Quote

I hate signatures, they're too distracting

Share this post


Link to post
Share on other sites

devguydan    2

devguydan

devguydan    2

  • Tree Puncher
  • devguydan
  • Members
  • 2
  • 35 posts
Posted March 13, 2019

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?

  • Quote

I hate signatures, they're too distracting

Share this post


Link to post
Share on other sites

devguydan    2

devguydan

devguydan    2

  • Tree Puncher
  • devguydan
  • Members
  • 2
  • 35 posts
Posted March 13, 2019

This should be simple right?

  • Quote

I hate signatures, they're too distracting

Share this post


Link to post
Share on other sites

diesieben07    7597

diesieben07

diesieben07    7597

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7597
  • 55122 posts
Posted March 13, 2019
  • Registry names must be all lowercase.
  • When using @ObjectHolder do not assign values to the fields yourself. That is the point of @ObjectHolder.
  • The registry name for your block and ItemBlock must be exactly the same.
  • Quote

Share this post


Link to post
Share on other sites

devguydan    2

devguydan

devguydan    2

  • Tree Puncher
  • devguydan
  • Members
  • 2
  • 35 posts
Posted March 13, 2019

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));
}

 

  • Quote

I hate signatures, they're too distracting

Share this post


Link to post
Share on other sites

diesieben07    7597

diesieben07

diesieben07    7597

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7597
  • 55122 posts
Posted March 13, 2019
  • 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.
  • Quote

Share this post


Link to post
Share on other sites

devguydan    2

devguydan

devguydan    2

  • Tree Puncher
  • devguydan
  • Members
  • 2
  • 35 posts
Posted March 13, 2019

Just got to models https://mcforge.readthedocs.io/en/latest/models/introduction/ this has to be it

  • Quote

I hate signatures, they're too distracting

Share this post


Link to post
Share on other sites

devguydan    2

devguydan

devguydan    2

  • Tree Puncher
  • devguydan
  • Members
  • 2
  • 35 posts
Posted March 13, 2019
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?

 

  • Quote

I hate signatures, they're too distracting

Share this post


Link to post
Share on other sites

diesieben07    7597

diesieben07

diesieben07    7597

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7597
  • 55122 posts
Posted March 13, 2019
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.

  • Quote

Share this post


Link to post
Share on other sites

devguydan    2

devguydan

devguydan    2

  • Tree Puncher
  • devguydan
  • Members
  • 2
  • 35 posts
Posted February 8, 2020 (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 February 10, 2020 by devguydan
Timeline wow
  • Quote

I hate signatures, they're too distracting

Share this post


Link to post
Share on other sites

Cadiboo    365

Cadiboo

Cadiboo    365

  • Reality Controller
  • Cadiboo
  • Members
  • 365
  • 3624 posts
Posted February 10, 2020

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

  • Quote

About Me

Spoiler

My Discord - Cadiboo#8887

My Website - Cadiboo.github.io

My Mods - Cadiboo.github.io/projects

My Tutorials - Cadiboo.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)

Share this post


Link to post
Share on other sites

devguydan    2

devguydan

devguydan    2

  • Tree Puncher
  • devguydan
  • Members
  • 2
  • 35 posts
Posted February 10, 2020
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.

  • Quote

I hate signatures, they're too distracting

Share this post


Link to post
Share on other sites

Cadiboo    365

Cadiboo

Cadiboo    365

  • Reality Controller
  • Cadiboo
  • Members
  • 365
  • 3624 posts
Posted February 13, 2020 (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 February 17, 2020 by Cadiboo
  • Thanks 1
  • Quote

About Me

Spoiler

My Discord - Cadiboo#8887

My Website - Cadiboo.github.io

My Mods - Cadiboo.github.io/projects

My Tutorials - Cadiboo.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)

Share this post


Link to post
Share on other sites

Draco18s    2406

Draco18s

Draco18s    2406

  • Reality Controller
  • Draco18s
  • Members
  • 2406
  • 15935 posts
Posted February 13, 2020
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
  • Quote

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.

Share this post


Link to post
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.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 1
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Klarks
      [1.16.4] what difference between custom slots and EquipmentSlotType

      By Klarks · Posted 33 minutes ago

      My constructor looks like this now. public ItemStackHandler handlerCustom; public IItemHandler handlerDefault; public IItemHandler both; LazyOptional<IItemHandler> optional; public WhoreEntity(EntityType<? extends WhoreEntity> type, World worldIn) { super(type, worldIn); handlerCustom = new ItemStackHandler(1); //1 handlerDefault = super.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY,Direction.EAST).orElseThrow(null); both = new CombinedInvWrapper(handlerCustom, ((IItemHandlerModifiable) handlerDefault)); optional = LazyOptional.of(() -> both); }   And my Override getCapability. I dont sure what is facing means @Nonnull @Override public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) { if(cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY && side != null) { return (LazyOptional<T>)optional; } return super.getCapability(cap, side); }   Did i do that all right?
    • poopoodice
      [1.15.2]ServerWorld.spawnParticle excluding specific player

      By poopoodice · Posted 42 minutes ago

      It sends a packet to all/tracking clients, you should be able to do the same thing but without sending to the specific player.
    • Woodside
      [1.15.2]ServerWorld.spawnParticle excluding specific player

      By Woodside · Posted 2 hours ago

      I have an item which I want to spawn a specific particle for the user, and then a separate particle for other players. Spawning one exclusively for the player using is easy enough, but spawning a particle server side has no way to exclude a specific player. Is there a way to do this without reflection?
    • DaemonUmbra
      I just started modding minecraft and I thought i had finished modding it but Titanium mod isn't loading properly. Can someone help me fix this?

      By DaemonUmbra · Posted 2 hours ago

      Please read the error...
    • DaemonUmbra
      HELP! WORLD WONT WORK

      By DaemonUmbra · Posted 2 hours ago

      I told you to delete a file in the save, not the save itself Go into the save and delete forge-server.toml from serverconfig
  • Topics

    • Klarks
      31
      [1.16.4] what difference between custom slots and EquipmentSlotType

      By Klarks
      Started Thursday at 06:22 AM

    • Woodside
      1
      [1.15.2]ServerWorld.spawnParticle excluding specific player

      By Woodside
      Started 2 hours ago

    • TheDonkey_King
      5
      I just started modding minecraft and I thought i had finished modding it but Titanium mod isn't loading properly. Can someone help me fix this?

      By TheDonkey_King
      Started 10 hours ago

    • BIGDog8808
      11
      HELP! WORLD WONT WORK

      By BIGDog8808
      Started 11 hours ago

    • Gubipe
      2
      Minecraft.getMinecraft().thePlayer.swingItem(); wont attack

      By Gubipe
      Started 6 hours ago

  • Who's Online (See full list)

    • LK1905
    • Klarks
    • HourShower
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [Solved][Outdated]How to override/use blocks without custom class
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community