Jump to content

[1.13.2] Store value in Block + Advanced Texturing & Colouring


Simon_kungen

Recommended Posts

Hi

 

I have a block that needs to store a single int value. When breaking that block will drop n amount of items depending on that block's value.

 

public class BlockHardOre extends Block {

    private int meta = 4;

    public BlockHardOre(final String name, final float hardness, final float resistance) {
        super(Block.Properties.create(Material.ROCK).hardnessAndResistance(hardness,resistance));

        setRegistryName(name+"_ore");
    }

    
    public IItemProvider getItemDropped(IBlockState state, World worldIn, BlockPos pos, int fortune) {
        return Items.DIAMOND;
    }
    public int getItemsToDropCount(IBlockState state, int fortune, World worldIn, BlockPos pos, Random random) {
        return Math.max(this.meta,1);
    }
}

 

The value meta here is simply a placeholder when I was testing. The real meta value would derive from the stored value in the block.

 

The second would be to have the block's appearance be changed what that value is. Stone's texture as the background and then apply my texture on top of it just like how Potions' model works, the secondary texture would have to be coloured.

Link to comment
Share on other sites

Blocks are singletons. This means that there is only one block instance in the entire game. To store stuff like this you need to use BlockStates and their properties (look at tallgrass for examples). Depending on what you want, you might be able to accomplish everything with the json model system. If not, you can use the IModelData system.

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.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)

Link to comment
Share on other sites

23 hours ago, Cadiboo said:

Blocks are singletons. This means that there is only one block instance in the entire game. To store stuff like this you need to use BlockStates and their properties (look at tallgrass for examples). Depending on what you want, you might be able to accomplish everything with the json model system. If not, you can use the IModelData system.

Alright. I managed to do the layer by making it into two models overlapping each other with the second layer being transparent. But I'm having some issues with Blockstates:

{
  "forge_marker": 1,
  "variants": {
    "density": {
      "0": {
        "model": "minecraft:block/stone"
      },
      "1": {
        "model": "intercraftcore:block/ore_faces/ore_0"
      },
      "2": {
        "model": "intercraftcore:block/ore_faces/ore_1"
      },
      "3": {
        "model": "intercraftcore:block/ore_faces/ore_2"
      },
      "4": {
        "model": "intercraftcore:block/ore_faces/ore_3"
      }
    }
  }
}

 

I would guess it should be like this, but when I try and spawn it into the world it says that property doesn't exist. I'm also having issues with setting the default blockstate when you place it into the world by hand, it should be in that case be variant 4.

Link to comment
Share on other sites

Alright, not sure if the first one would work if I got this problem solved:

 

Seems like you have to add a property to the block class, so I tried that:

Spoiler

BlockHardOre.java


    public BlockHardOre(final String name, final float hardness, final float resistance) {
        super(Block.Properties.create(Material.ROCK, MaterialColor.STONE).hardnessAndResistance(hardness,resistance));

        setRegistryName(name+"_ore");
        setDefaultState(this.stateContainer.getBaseState().with(BlockProperties.DENSITY, 1));
    }

 

BlockProperties.java


public class BlockProperties {
    public static final IntegerProperty DENSITY = IntegerProperty.create("density",0,4);
}

 

 

 

But I run into the error:

Caused by: java.lang.IllegalArgumentException: Cannot set property IntegerProperty{name=density, clazz=class java.lang.Integer, values=[0, 1, 2, 3, 4]} as it does not exist in Block{minecraft:air}

So my guess is that I need to register this to the Block class. But I have no idea how to do that.

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

8 hours ago, Simon_kungen said:

Block{minecraft:air}

Either you badly registered your block, or you're trying to set your property on an air block, not your block.

 

8 hours ago, Simon_kungen said:

setDefaultState(this.stateContainer.getBaseState().with(BlockProperties.DENSITY, 1));

do NOT do this. Override fillStateContainer

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.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)

Link to comment
Share on other sites

6 hours ago, Cadiboo said:

Either you badly registered your block, or you're trying to set your property on an air block, not your block.

 

do NOT do this. Override fillStateContainer

Ok, that worked. Can now place the block with the desired density. But it looks like it is still not changing the block model.

Spoiler

{
  "forge_marker": 1,
  "variants": {
    "density": {
      0: {
        "model": "minecraft:block/stone"
      },
      1: {
        "model": "intercraftcore:block/ore_faces/ore_0"
      },
      2: {
        "model": "intercraftcore:block/ore_faces/ore_1"
      },
      3: {
        "model": "intercraftcore:block/ore_faces/ore_2"
      },
      4: {
        "model": "intercraftcore:block/ore_faces/ore_3"
      }
    }
  }
}

 

 

 

Link to comment
Share on other sites

Looks like it doesn't find the file. When I change the blockstate file the model works just fine.

Unable to load model: 'intercraftcore:block/block/ore_faces/ore_2' referenced from: intercraftcore:cu_ore#density=0: java.io.FileNotFoundException: intercraftcore:models/block/block/ore_faces/ore_2.json

 

structure.png.83b2b274772123f451d3d741d980a6bd.png

Link to comment
Share on other sites

Spot the difference between

"intercraftcore:models/block/block/ore_faces/ore_2.json" and
"intercraftcore:models/block/ore_faces/ore_2.json"

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.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)

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.