Jump to content

Fixing bad modding practices


Eilux

Recommended Posts

After reading several pages on the forums I have realized that my mod uses several bad practices including IHasModel and a weird convoluted way of registering blocks and items it is very confusing to try to fix without a point of reference so I was wondering if anyone could point me to a good example of block and item registration.

Link to comment
Share on other sites

Create the registry event.

Create your items/blocks/biomes/whatever in it.

Register them.

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

39 minutes ago, Eilux said:

Is there somewhere where I could find sample code of this.

Probably all over github. But it is as simple as draco said. You should already have a registry event if you are using a modern version. So step one complete. Step two is to only call new BlahItem in the Item Registry Event, and likewise for Blocks. Then you need to register those items and blocks in the event.

 

Now if you need to have access to those values use the ObjectHolder annotation

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Is it necessary to make a new class for every block or item added or is it acceptable to make a generic block class that takes in parameters the one that i had been using previously was this.

package mod.eilux.mcge.blocks;

import mod.eilux.mcge.McGE;
import mod.eilux.mcge.init.ModBlocks;
import mod.eilux.mcge.init.ModItems;
import mod.eilux.mcge.util.IHasModel;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class BlockBase extends Block implements IHasModel {
    private static final Map<String, SoundType> soundIndex;
    private static final Map<String,CreativeTabs> tabIndex;


    static {
        Map<String, SoundType> tempSoundIndex = new HashMap<>();
        tempSoundIndex.put("metal", SoundType.METAL);
        tempSoundIndex.put("stone", SoundType.STONE);
        tempSoundIndex.put("anvil", SoundType.ANVIL);
        tempSoundIndex.put("cloth", SoundType.CLOTH);
        tempSoundIndex.put("glass", SoundType.GLASS);
        tempSoundIndex.put("ground", SoundType.GROUND);
        tempSoundIndex.put("ladder", SoundType.LADDER);
        tempSoundIndex.put("plant", SoundType.PLANT);
        tempSoundIndex.put("sand", SoundType.SAND);
        tempSoundIndex.put("slime", SoundType.SLIME);
        tempSoundIndex.put("snow", SoundType.SNOW);
        tempSoundIndex.put("wood", SoundType.WOOD);

        soundIndex = Collections.unmodifiableMap(tempSoundIndex);

        Map<String, CreativeTabs> tempTabIndex = new HashMap<>();
        tempTabIndex.put("misc", CreativeTabs.MISC);
        tempTabIndex.put("brewing", CreativeTabs.BREWING);
        tempTabIndex.put("building_blocks", CreativeTabs.BUILDING_BLOCKS);
        tempTabIndex.put("combat", CreativeTabs.COMBAT);
        tempTabIndex.put("decorations", CreativeTabs.DECORATIONS);
        tempTabIndex.put("food", CreativeTabs.FOOD);
        tempTabIndex.put("redstone", CreativeTabs.REDSTONE);
        tempTabIndex.put("tools", CreativeTabs.TOOLS);
        tempTabIndex.put("transportation", CreativeTabs.TRANSPORTATION);

        tabIndex = Collections.unmodifiableMap(tempTabIndex);
    }

    public BlockBase(String name, Material material, String tab, String soundType, Float hardness, Float blastRes, String harvestTool, int harvestLevel, Float lightLevel, int opacity){

        super(material);




        setTranslationKey(name);
        setRegistryName(name);
        setCreativeTab(tabIndex.get(tab));
        setSoundType(soundIndex.get(soundType));
        setHardness(hardness);
        setResistance(blastRes);
        setHarvestLevel(harvestTool,harvestLevel);
        setLightLevel(lightLevel);
        setLightOpacity(opacity);




        ModBlocks.BLOCKS.add(this);
        ModItems.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
    }


    @Override
    public void registerModels() {
        McGE.proxy.registerItemRenderer(Item.getItemFromBlock(this),0,"inventory");

    }
}

*I am still in the process of removing IHasModel

Link to comment
Share on other sites

17 minutes ago, Eilux said:

Is it necessary to make a new class for every block or item added or is it acceptable to make a generic block class that takes in parameters

You just described the Block and Item class. You should not make a "base" class for your mod because it already exists. You only need a new class if your block needs custom behavior(right click, a te, etc). 

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

8 minutes ago, Eilux said:

whenever I add .setHarvestLevel() to the Block class it gives me an incompatible type error: expected: Block, got: void

Show your code.

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

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

×
×
  • Create New...

Important Information

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