Jump to content

How to set custom Hardness for generated ores


ICanHazCooki

Recommended Posts

Sooo here's a problem: I have a class called BlockOres that has a custom constructor for making custom ores (or that is at least what I think it does). The problem comes when I want to set a custom hardness value for ONE ore only. Because if I put setHardness(the value);

there it will change the hardness for all the ores.

Thx in advance

 

(btw I am a noob still so bare with meh)

 

(btw here is the class)

package technicalRevolution.mod.Objects.blocks;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import technicalRevolution.mod.Main;
import technicalRevolution.mod.Init.BlockInit;
import technicalRevolution.mod.Init.ItemInit;
import technicalRevolution.mod.Objects.blocks.item.ItemBlockVariant;
import technicalRevolution.mod.util.IHasModel;
import technicalRevolution.mod.util.handlers.EnumHandler;
import technicalRevolution.mod.util.interfaces.IMetaName;

public class BlockOres extends Block implements IHasModel, IMetaName
{
    public static final PropertyEnum<EnumHandler.EnumType> VARIANT = PropertyEnum.<EnumHandler.EnumType>create("variant", EnumHandler.EnumType.class);
    
    private String name, dimension;
    
    public BlockOres(String name, String dimension)
    {
        super(Material.ROCK);
        
        setUnlocalizedName(name);
        setRegistryName(name);
        setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
        setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, EnumHandler.EnumType.COPPER));
        
        this.name = name;
        this.dimension = dimension;
        
        BlockInit.BLOCKS.add(this);
        ItemInit.ITEMS.add(new ItemBlockVariant(this).setRegistryName(this.getRegistryName()));
    }

    @Override
    public int damageDropped(IBlockState state)
    {
        return ((EnumHandler.EnumType)state.getValue(VARIANT)).getMeta();
    }
    
    @Override
    public int getMetaFromState(IBlockState state)
    {
        return ((EnumHandler.EnumType)state.getValue(VARIANT)).getMeta();
    }
    
    @Override
    public IBlockState getStateFromMeta(int meta)
    {
        return this.getDefaultState().withProperty(VARIANT, EnumHandler.EnumType.byMetadata(meta));
    }
    
    @Override
    public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player)
    {
        return new ItemStack(Item.getItemFromBlock(this), 1, getMetaFromState(world.getBlockState(pos)));
    }
    
    @Override
    public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items)
    {
        for(EnumHandler.EnumType variant : EnumHandler.EnumType.values())
        {
            items.add(new ItemStack(this, 1, variant.getMeta()));
        }
    }
    
    @Override
    public void registerModels() 
    {
        for(int i = 0; i < EnumHandler.EnumType.values().length; i++)
        {
            Main.proxy.registerVariantRenderer(Item.getItemFromBlock(this), i, "ore_" + this.dimension + "_" + EnumHandler.EnumType.values().getName(), "inventory");
        }
    }
    
    @Override
    protected BlockStateContainer createBlockState()
    {
        return new BlockStateContainer(this, new IProperty[] {VARIANT});
    }
    
    @Override
    public String getSpecialName(ItemStack stack)
    {
        return EnumHandler.EnumType.values()[stack.getItemDamage()].getName();
    }
}
 

[!spoiler]

Edited by ICanHazCooki
Link to comment
Share on other sites

53 minutes ago, ICanHazCooki said:

Because if I put setHardness(the value);

there it will change the hardness for all the ores.

Override getHardness(IBlockState)

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

7 minutes ago, ICanHazCooki said:

@Animefan8888 would you mind to explain?

(Becouse im still a noob)

you can return hardness based upon the blockstate. so for example your initial hardness is 1.0F for your dirt ore. Your diamond ore would be your hardness + 3.0F. Check the blockstate then do something with it.

Edited by jredfox
Link to comment
Share on other sites

4 minutes ago, ICanHazCooki said:

@Animefan8888 would you mind to explain?

(Becouse im still a noob)

Which part do you not understand? Override is a basic java principle. And I have given you a method signature. The method is in the Block class.

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

Sidenote: I see that you implement an interface called IHasModel, something a bunch of garbage mod tutorials use. There is no point in doing that, since all registered blocks already have a model. Use the Forge events to register your models, which is ModelRegistryEvent in this case.

 

Also you'd want to keep your package names lowercase.

Link to comment
Share on other sites

2 hours ago, jt9 said:

Sidenote: I see that you implement an interface called IHasModel, something a bunch of garbage mod tutorials use. There is no point in doing that, since all registered blocks already have a model.

Or more accurately:

  • All blocks get models automatically
  • All items (including itemblocks) require models to be registered
  • None of the information relating to model registering requires private access

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.