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
  • [1.14.3] Where to put Item.getItemFromBlock
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 0
VGLyen

[1.14.3] Where to put Item.getItemFromBlock

By VGLyen, July 24, 2019 in Modder Support

  • Start new topic

Recommended Posts

VGLyen    0

VGLyen

VGLyen    0

  • Tree Puncher
  • VGLyen
  • Members
  • 0
  • 2 posts
Posted July 24, 2019 (edited)

Hello guys.

 

It's been a while since I programmed with Forge and everything changed since. (I think the last time was on Minecraft Version 1.8.8)

I've already searched for examples but everything I found was outdated.

 

So these are my files. What I want is, that after you destroyed the Ore you get the Block as an Item.

 

@Mod.EventBusSubscriber(modid = Reference.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
@ObjectHolder(Reference.MODID)
public class BlockRegistry {

    public static final Block cyby_ore = null;

    @SubscribeEvent
    public static void registerBlocks(final RegistryEvent.Register<Block> event) {

        event.getRegistry().registerAll(

                new CybyOre(Block.Properties.create(Material.ROCK)).setRegistryName(Reference.MODID, "cyby_ore")

        );
    }


}
public class CybyOre extends Block {

    public CybyOre(Properties prop) {
        super(prop.hardnessAndResistance(3.0f, 3.0f).harvestLevel(3).harvestTool(ToolType.PICKAXE).lightValue(15/16));
    }
}
@Mod.EventBusSubscriber(modid = Reference.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
@ObjectHolder(Reference.MODID)
public class ItemRegistry {

    public static final Item cyby_ingot = null;
    public static final Item cyby_ore = null;

    @SubscribeEvent
    public static void registerItems(RegistryEvent.Register<Item> event) {
        event.getRegistry().registerAll(

                new Item(new Item.Properties().group(ItemGroup.MATERIALS)).setRegistryName(Reference.MODID, "cyby_ingot"),

                new BlockItem(BlockRegistry.cyby_ore, new Item.Properties().group(ItemGroup.BUILDING_BLOCKS)).setRegistryName(Reference.MODID, "cyby_ore")
        );
    }
}

 

In Minecraft 1.8.8 you did it like this:     

    @EventHandler
    public void init(FMLInitializationEvent event)
    {
        /*Blocks*/
        CybyOre = new CybyOre(CybyOreID, Material.rock).setUnlocalizedName("CybyOre").setCreativeTab(tabModBlock);
        GameRegistry.registerBlock(CybyOre, "CybyOre");

        Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(CybyOre), 0, new ModelResourceLocation("MODID:CybyOre", "inventory"));

    }

 

At this moment it is just a guessing game where I need to put it and I feel pretty dumb.

Hope you can help me, and please be kind.

Thanks

 

BlockRegistry.java CybyOre.java ItemRegistry.java

Edited July 24, 2019 by VGLyen

Share this post


Link to post
Share on other sites

Draco18s    2414

Draco18s

Draco18s    2414

  • Reality Controller
  • Draco18s
  • Members
  • 2414
  • 15998 posts
Posted July 24, 2019 (edited)

Block drops are handled by loot tables now.

 

Also:

32 minutes ago, VGLyen said:

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(CybyOre), 0, new ModelResourceLocation("MODID:CybyOre", "inventory"));

This was never the correct way to do this, much less the correct way to drop items when the block is harvested. ;)

Edited July 24, 2019 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.

Share this post


Link to post
Share on other sites

VGLyen    0

VGLyen

VGLyen    0

  • Tree Puncher
  • VGLyen
  • Members
  • 0
  • 2 posts
Posted July 28, 2019
On 7/24/2019 at 4:30 PM, Draco18s said:

Block drops are handled by loot tables now.

Ok, thank you. But I have still some issues. The documentation says:

 

In order to make Minecraft load and be aware of your loot table, simply call LootTableList.register(new ResourceLocation("modid", "loot_table_name")), which will resolve and load /assets/modid/loot_tables/loot_table_name.json. This call can be made during any of preinit, init, or postinit. You may organize your tables into folders freely.

 

But this doesn't work for me. Probably because I use a newer version which is not documented yet. I've searched a while for a good example, but I did not find anything. If you could help me a second time, this would be awesome.

 

And a second question:

 

The documentation says:

 

When a block is registered, only a block is registered. The block does not automatically have an ItemBlock. To create a basic ItemBlock for a block, one should use new ItemBlock(block).setRegistryName(block.getRegistryName()). The unlocalized name is the same as the block’s. Custom subclasses of ItemBlock may be used as well. Once an ItemBlock has been registered for a block, Item.getItemFromBlock can be used to retrieve it. Item.getItemFromBlock will return null if there is no ItemBlock for the Block, so if you are not certain that there is an ItemBlock for the Block you are using, check for null.

 

Is this really outdated for 1.14.3? Because it would be easier if I just could use this instead of a whole .json File only to drop the Block itself.

 

Thanks for the help.

Share this post


Link to post
Share on other sites

Draco18s    2414

Draco18s

Draco18s    2414

  • Reality Controller
  • Draco18s
  • Members
  • 2414
  • 15998 posts
Posted July 28, 2019
48 minutes ago, VGLyen said:

In order to make Minecraft load and be aware of your loot table, simply call LootTableList.register(new ResourceLocation("modid", "loot_table_name")), which will resolve and load /assets/modid/loot_tables/loot_table_name.json. This call can be made during any of preinit, init, or postinit. You may organize your tables into folders freely.

You don't need to do this, block loot tables are loaded automatically.


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

Huntpor    0

Huntpor

Huntpor    0

  • Tree Puncher
  • Huntpor
  • Members
  • 0
  • 5 posts
Posted January 19

Can someone please fully explain this then? How are they loaded automatically?  At the moment I have my project file (where do I create the Data folder then) In Src/main/resources or just where I have the file now? 

Share this post


Link to post
Share on other sites

Draco18s    2414

Draco18s

Draco18s    2414

  • Reality Controller
  • Draco18s
  • Members
  • 2414
  • 15998 posts
Posted January 19

Linked resources are not in your src folder, they're stored elsewhere and referenced in your Project Explorer tab of your IDE.


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

diesieben07    7696

diesieben07

diesieben07    7696

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7696
  • 56382 posts
Posted January 19

1.14 is no longer supported.

If you have an issue with a modern version, make your own thread.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • cadbane86140
      Minecraft: Parkour Stairs Part 1!

      By cadbane86140 · Posted 27 minutes ago

      Hello There! Today we are playing a BRAND NEW parkour map that was actually just released about a month ago and all I gotta say is that this map is so freaking unique and the map creators did something with this map that we have never seen in parkour before! There are so many hilarious moments in this video that I know you guys are gonna love! I hope you all enjoy this video and if you did don't forget to like and sub for more! https://www.youtube.com/watch?v=5aGkMp5bExg
    • cadbane86140
      Revisiting our 2013 head shop!

      By cadbane86140 · Posted 28 minutes ago

      Hello there! With the recent re release of the old creative server I knew I had to make a video on there. So that is exactly what we did! We did a small tour of our old plot like we did last time but however we remembered some of our old friends and we checked out their old plots too! If you guys want us to do more where we just travel to different plots and talk about them let me know! But I hope you all enjoy this video and if you did don’t forget to like and sub for more videos Like this in the future! https://youtu.be/_m_lViaMlGU
    • kiou.23
      Block Rotate

      By kiou.23 · Posted 57 minutes ago

      That's usually the case, always try to understand the code before copy and pasting, or else you'll get a lot of headaches later in the code's life
    • Varzac
      Forge jar file not opening

      By Varzac · Posted 1 hour ago

      I ran Jarfix and then tried installing again with the same results. Nothing happening I even tried using winrar, but as you said nothing happened
    • BeardlessBrady
      [1.16.4] Null when OpenGUI

      By BeardlessBrady · Posted 1 hour ago

      Ah.. Thats what I get for stopping half way through and not double checking, thanks!
  • Topics

    • cadbane86140
      0
      Minecraft: Parkour Stairs Part 1!

      By cadbane86140
      Started 27 minutes ago

    • cadbane86140
      0
      Revisiting our 2013 head shop!

      By cadbane86140
      Started 28 minutes ago

    • ehbean
      10
      Block Rotate

      By ehbean
      Started 7 hours ago

    • Varzac
      3
      Forge jar file not opening

      By Varzac
      Started 13 hours ago

    • BeardlessBrady
      2
      [1.16.4] Null when OpenGUI

      By BeardlessBrady
      Started 2 hours ago

  • Who's Online (See full list)

    • ehbean
    • kiou.23
    • -MCS_Gaming-
    • Gorp5
    • cadbane86140
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.14.3] Where to put Item.getItemFromBlock
  • Theme

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