Jump to content

Creating Sub Classes for Blocks v1.14.4


Nobisyu_12

Recommended Posts

Hi. I am very new and not well versed in modding yet. I want to make a block have a specific harvest tool and level, but I don't know where to begin. I have the block working with drops and everything, but I cannot find how to do this. Through research I know I am supposed to use sub classes or something, but nowhere did I find a tutorial on how to set that up. I was wondering if anyone could help me with this. This is my modid.java file.

Spoiler

package nobisyu.nobisyumod;

import net.minecraft.block.Block;

import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.item.AxeItem;
import net.minecraft.item.BlockItem;
import net.minecraft.item.HoeItem;
import net.minecraft.item.Item;
import net.minecraft.item.Item.Properties;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.PickaxeItem;
import net.minecraft.item.ShovelItem;
import net.minecraft.item.SwordItem;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import nobisyu.nobisyumod.lists.BlockList;
import nobisyu.nobisyumod.lists.ItemList;
import nobisyu.nobisyumod.lists.ToolMaterialList;

@Mod("nobisyumod")
public class NobisyuMod 
{
    public static NobisyuMod instance;
    public static final String modid = "nobisyumod";

    public NobisyuMod() 
    {
        instance = this;
        
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientRegistries);
        
        MinecraftForge.EVENT_BUS.register(this);
    }
    
    private void setup(final FMLCommonSetupEvent event)
    {

    }
    
    private void clientRegistries(final FMLClientSetupEvent event)
    {
        
    }
    
    @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
    public static class RegistryEvents
    {
        @SubscribeEvent
        public static void registerItems(final RegistryEvent.Register<Item> event)
        {
            event.getRegistry().registerAll
            (
                ItemList.flint_shard = new Item(new Item.Properties().group(ItemGroup.MISC)).setRegistryName(location("flint_shard")),
                ItemList.twig = new Item(new Item.Properties().group(ItemGroup.MISC)).setRegistryName(location("twig")),
                ItemList.plant_fiber = new Item(new Item.Properties().group(ItemGroup.MISC)).setRegistryName(location("plant_fiber")),
                ItemList.mudball = new Item(new Item.Properties().group(ItemGroup.MISC)).setRegistryName(location("mudball")),
                
                ItemList.flint_axe = new AxeItem(ToolMaterialList.nobisyu, 2.0f, -3.2f, new Item.Properties().group(ItemGroup.TOOLS)).setRegistryName(location("flint_axe")),
                ItemList.flint_hoe = new HoeItem(ToolMaterialList.nobisyu, 0.0f, new Item.Properties().group(ItemGroup.TOOLS)).setRegistryName(location("flint_hoe")),
                ItemList.flint_shovel = new ShovelItem(ToolMaterialList.nobisyu, -1.5f, -3.0f, new Item.Properties().group(ItemGroup.TOOLS)).setRegistryName(location("flint_shovel")),
                ItemList.flint_pickaxe = new PickaxeItem(ToolMaterialList.nobisyu, -2, -2.5f, new Item.Properties().group(ItemGroup.TOOLS)).setRegistryName(location("flint_pickaxe")),
                ItemList.flint_sword = new SwordItem(ToolMaterialList.nobisyu, 0, -2.1f, new Item.Properties().group(ItemGroup.COMBAT)).setRegistryName(location("flint_sword")),
                
                ItemList.mud = new BlockItem(BlockList.mud, new Item.Properties().group(ItemGroup.BUILDING_BLOCKS)).setRegistryName(BlockList.mud.getRegistryName()),
                ItemList.mud_bricks_wet = new BlockItem(BlockList.mud_bricks_wet, new Item.Properties().group(ItemGroup.BUILDING_BLOCKS)).setRegistryName(BlockList.mud_bricks_wet.getRegistryName()),
                ItemList.mud_bricks_dry = new BlockItem(BlockList.mud_bricks_dry, new Item.Properties().group(ItemGroup.BUILDING_BLOCKS)).setRegistryName(BlockList.mud_bricks_dry.getRegistryName())
            );
            
        }
        
        @SubscribeEvent
        public static void registerBlocks(final RegistryEvent.Register<Block> event)
        {
            event.getRegistry().registerAll
            (
                BlockList.mud = new Block(Block.Properties.create(Material.CLAY).hardnessAndResistance(0.25f, 2.0f).lightValue(0).sound(SoundType.WET_GRASS)).setRegistryName(location("mud")),
                BlockList.mud_bricks_wet = new Block(Block.Properties.create(Material.CLAY).hardnessAndResistance(0.5f, 6.0f).lightValue(0).sound(SoundType.WET_GRASS)).setRegistryName(location("mud_bricks_wet")),
                BlockList.mud_bricks_dry = new Block(Block.Properties.create(Material.CLAY).hardnessAndResistance(0.75f, 6.0f).lightValue(0).sound(SoundType.STONE)).setRegistryName(location("mud_bricks_dry"))
            );
            
        }
        
        
        private static ResourceLocation location(String name)
        {
            return new ResourceLocation(modid, name);
        }
    }
}

 

 

Edited by DaemonUmbra
Fixed Formatting
Link to comment
Share on other sites

Do you know Java or any other programming language?

This is my Forum Signature, I am currently attempting to transform it into a small guide for fixing easier issues using spoiler blocks to keep things tidy.

 

As the most common issue I feel I should put this outside the main bulk:

The only official source for Forge is https://files.minecraftforge.net, and the only site I trust for getting mods is CurseForge.

If you use any site other than these, please take a look at the StopModReposts project and install their browser extension, I would also advise running a virus scan.

 

For players asking for assistance with Forge please expand the spoiler below and read the appropriate section(s) in its/their entirety.

Spoiler

Logs (Most issues require logs to diagnose):

Spoiler

Please post logs using one of the following sites (Thank you Lumber Wizard for the list):

https://gist.github.com/100MB Requires member (Free)

https://pastebin.com/: 512KB as guest, 10MB as Pro ($$$)

https://hastebin.com/: 400KB

Do NOT use sites like Mediafire, Dropbox, OneDrive, Google Drive, or a site that has a countdown before offering downloads.

 

What to provide:

...for Crashes and Runtime issues:

Minecraft 1.14.4 and newer:

Post debug.log

Older versions:

Please update...

 

...for Installer Issues:

Post your installer log, found in the same place you ran the installer

This log will be called either installer.log or named the same as the installer but with .log on the end

Note for Windows users:

Windows hides file extensions by default so the installer may appear without the .jar extension then when the .log is added the log will appear with the .jar extension

 

Where to get it:

Mojang Launcher: When using the Mojang launcher debug.log is found in .minecraft\logs.

 

Curse/Overwolf: If you are using the Curse Launcher, their configurations break Forge's log settings, fortunately there is an easier workaround than I originally thought, this works even with Curse's installation of the Minecraft launcher as long as it is not launched THROUGH Twitch:

Spoiler
  1. Make sure you have the correct version of Forge installed (some packs are heavily dependent on one specific build of Forge)
  2. Make a launcher profile targeting this version of Forge.
  3. Set the launcher profile's GameDir property to the pack's instance folder (not the instances folder, the folder that has the pack's name on it).
  4. Now launch the pack through that profile and follow the "Mojang Launcher" instructions above.

Video:

Spoiler

 

 

 

or alternately, 

 

Fallback ("No logs are generated"):

If you don't see logs generated in the usual place, provide the launcher_log.txt from .minecraft

 

Server Not Starting:

Spoiler

If your server does not start or a command window appears and immediately goes away, run the jar manually and provide the output.

 

Reporting Illegal/Inappropriate Adfocus Ads:

Spoiler

Get a screenshot of the URL bar or copy/paste the whole URL into a thread on the General Discussion board with a description of the Ad.

Lex will need the Ad ID contained in that URL to report it to Adfocus' support team.

 

Posting your mod as a GitHub Repo:

Spoiler

When you have an issue with your mod the most helpful thing you can do when asking for help is to provide your code to those helping you. The most convenient way to do this is via GitHub or another source control hub.

When setting up a GitHub Repo it might seem easy to just upload everything, however this method has the potential for mistakes that could lead to trouble later on, it is recommended to use a Git client or to get comfortable with the Git command line. The following instructions will use the Git Command Line and as such they assume you already have it installed and that you have created a repository.

 

  1. Open a command prompt (CMD, Powershell, Terminal, etc).
  2. Navigate to the folder you extracted Forge’s MDK to (the one that had all the licenses in).
  3. Run the following commands:
    1. git init
    2. git remote add origin [Your Repository's URL]
      • In the case of GitHub it should look like: https://GitHub.com/[Your Username]/[Repo Name].git
    3. git fetch
    4. git checkout --track origin/master
    5. git stage *
    6. git commit -m "[Your commit message]"
    7. git push
  4. Navigate to GitHub and you should now see most of the files.
    • note that it is intentional that some are not synced with GitHub and this is done with the (hidden) .gitignore file that Forge’s MDK has provided (hence the strictness on which folder git init is run from)
  5. Now you can share your GitHub link with those who you are asking for help.

[Workaround line, please ignore]

 

Link to comment
Share on other sites

Tool is just another property, add it like you did hardness. 

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 11/3/2019 at 3:59 PM, Draco18s said:

Tool is just another property, add it like you did hardness. 

I don't quite understand how this would be done. Would I just put (for example): (Block.Properties.create(Material.ORGANIC).hardnessAndResistance(0.5f, 3.0f).setHarvestLevel("axe", 0).lightValue(0).sound(SoundType.PLANT))?

 

Because I tried that and the response I got from Eclipse was that it said setHarvestLevel was undefined.

 

Am I doing anything wrong here? Maybe I need to import a class or something. I really don't know.

Link to comment
Share on other sites

Because that isn't the method or its signature? 

Like, actually use 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.

Link to comment
Share on other sites

Okay. Update on the situation. I have been doing some research/trial and error and I found out that instead of the "setHarvestLevel("pickaxe", 0)" line, they instead are two separate lines now. One being ".harvestLevel(0)" and" .harvestTool(ToolType harvestTool)". I understand the .harvestLevel part, but I don't know what it's asking for in the ToolType and harvestTool sections. I have put in things such as PickaxeItem and "pickaxe" but nothing seems to work.

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



×
×
  • Create New...

Important Information

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