Jump to content

[1.14.2] Custom Grass Block


MatsCraft1

Recommended Posts

Okay, this is how I registered it:

    public static final Block MARBLEGRASS = new GrassBlock(Block.Properties.create(Material.ORGANIC)
            .tickRandomly().hardnessAndResistance(4.0F).sound(SoundType.PLANT)).setRegistryName("marble_grass");
event.getRegistry().register(MoreStuff.MARBLEGRASS);
event.getRegistry().register(new MarbleDirt_BlockItem(MoreStuff.MARBLEGRASS, properties.group(MoreStuff.morestuff_rock.GroupRock).maxStackSize(32)).setRegistryName("marble_grass"));

I made the model files just like the vanilla ones, the BlockItem has a texture where the "grass" part is grey, just like the texture file.

When I place my block it has the error texture and I have no idea why, could you help me or give me any reference?

 

Here are my model files:

 

morestuff/blockstates/marble_grass

{
  "variants": {
    "snowy=false": [
      { "model": "morestuff:block/soil/marble_grass" },
      { "model": "morestuff:block/soil/marble_grass", "y": 90 },
      { "model": "morestuff:block/soil/marble_grass", "y": 180 },
      { "model": "morestuff:block/soil/marble_grass", "y": 270 }
    ],
    "snowy=true":  { "model": "morestuff:block/soil/marble_grass_snowy" }
  }
}

 

morestuff/models/block/soil/marble_grass

{   "parent": "block/block",
  "textures": {
    "particle": "morestuff:block/soil/dirt_marble",
    "bottom": "morestuff:block/soil/dirt_marble",
    "top": "block/grass_block_top",
    "side": "morestuff:block/soil/dirt_marble",
    "overlay": "block/grass_block_side_overlay"
  },
  "elements": [
    {   "from": [ 0, 0, 0 ],
      "to": [ 16, 16, 16 ],
      "faces": {
        "down":  { "uv": [ 0, 0, 16, 16 ], "texture": "#bottom", "cullface": "down" },
        "up":    { "uv": [ 0, 0, 16, 16 ], "texture": "#top",    "cullface": "up", "tintindex": 0 },
        "north": { "uv": [ 0, 0, 16, 16 ], "texture": "#side",   "cullface": "north" },
        "south": { "uv": [ 0, 0, 16, 16 ], "texture": "#side",   "cullface": "south" },
        "west":  { "uv": [ 0, 0, 16, 16 ], "texture": "#side",   "cullface": "west" },
        "east":  { "uv": [ 0, 0, 16, 16 ], "texture": "#side",   "cullface": "east" }
      }
    },
    {   "from": [ 0, 0, 0 ],
      "to": [ 16, 16, 16 ],
      "faces": {
        "north": { "uv": [ 0, 0, 16, 16 ], "texture": "#overlay", "tintindex": 0, "cullface": "north" },
        "south": { "uv": [ 0, 0, 16, 16 ], "texture": "#overlay", "tintindex": 0, "cullface": "south" },
        "west":  { "uv": [ 0, 0, 16, 16 ], "texture": "#overlay", "tintindex": 0, "cullface": "west" },
        "east":  { "uv": [ 0, 0, 16, 16 ], "texture": "#overlay", "tintindex": 0, "cullface": "east" }
      }
    }
  ]
}

 

morestuff/models/block/soil/marble_grass_snowy

{
  "parent": "block/cube_bottom_top",
  "textures": {
    "particle": "morestuff:block/soil/dirt_marble",
    "bottom": "morestuff:block/soil/dirt_marble",
    "top": "block/grass_block_top",
    "side": "morestuff:block/soil/marble_grass_snowy"
  }
}

 

morestuff/models/item/marble_grass

{
  "parent": "morestuff:block/soil/marble_grass"
}
Link to comment
Share on other sites

2 minutes ago, Simon_kungen said:

Could you post the log? In the meantime, you can try and use vanilla Minecraft's grass model and see if that works (minecraft:block/grass_block).

And I would recommend creating a different block class for your grass block if you are going to add more blocks in your mod, it can get cluttered pretty easily.

I found out what the problem is, I need a ColorHandler.

Edited by MatsCraft1
  • Like 1
Link to comment
Share on other sites

Okay, I got this far now

package com.aug15.morestuff.blocks;


import com.aug15.morestuff.MoreStuff;
import net.minecraft.block.BlockState;
import net.minecraft.client.renderer.color.BlockColors;
import net.minecraft.client.renderer.color.IBlockColor;
import net.minecraft.client.renderer.color.IItemColor;
import net.minecraft.client.renderer.color.ItemColors;
import net.minecraft.item.BlockItem;
import net.minecraft.world.GrassColors;
import net.minecraft.world.biome.BiomeColors;
import net.minecraftforge.client.event.ColorHandlerEvent;
import net.minecraftforge.event.terraingen.BiomeEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber(modid = MoreStuff.MODID)
public class ModColourManager {

    @SubscribeEvent
    public static void registerBlockColourHandlers(final ColorHandlerEvent.Block event) {
        final BlockColors blockColors = event.getBlockColors();

        final IBlockColor grassColourHandler = (state, blockAccess, pos, tintIndex) -> {
            if (blockAccess != null && pos != null) {
                return BiomeEvent.BiomeColor.GetGrassColor(biome, original);
            }

            return GrassColors.get(0.5D, 1.0D);
        };

        blockColors.register(grassColourHandler, MoreStuff.MARBLEGRASS);
    }

    @SubscribeEvent
    public static void registerItemColourHandlers(final ColorHandlerEvent.Item event) {
        final BlockColors blockColors = event.getBlockColors();
        final ItemColors itemColors = event.getItemColors();

        final IItemColor itemBlockColourHandler = (stack, tintIndex) -> {
            @SuppressWarnings("deprecation")
            final BlockState state = ((BlockItem) stack.getItem()).getBlock().getDefaultState();
            return blockColors.getColor(state, null, null, tintIndex);
        };

        itemColors.register(itemBlockColourHandler, MoreStuff.MARBLEGRASS);
    }
}

 

but I have no idea what to put here

return BiomeEvent.BiomeColor.GetGrassColor(biome, original);

"biome, original" is marked as wrong "cannot resolve symbol"

Link to comment
Share on other sites

2 hours ago, diesieben07 said:

I don't know what you are trying to achieve there. You need to reigster an instance of IBlockColor to the instance of BlockColors thats provided to you by the event.

IBlockColor is a simple interface that takes in information about a block position and produces the color that that block si supposed to have.

like this?

        @OnlyIn(Dist.CLIENT)
        @SubscribeEvent
        public static void registerBlockColorHandlers(final ColorHandlerEvent.Block event) {
            event.getBlockColors().register((x, reader, pos, u) -> reader != null
                    && pos != null ? BiomeColors.getGrassColor(reader, pos)
                    : GrassColors.get(0.5D, 1.0D), MoreStuff.MARBLEGRASS);
        }

 

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.