Jump to content

Recommended Posts

Posted

As by title, i'm trying to make a slab that looks like grass, but i have incorrect textures when placing the single slab (the double slab looks like a grass bock as i want) :/

This is the code for my Slab class

package mw.blocks.vanilla;

import java.util.List;
import java.util.Random;

import mw.core.MWMetadataBlocks;
import mw.core.MWTabs;
import mw.core.MWVanillaSlabs;
import net.minecraft.block.BlockSlab;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumWorldBlockLayer;
import net.minecraft.util.IStringSerializable;
import net.minecraft.world.ColorizerGrass;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeColorHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class BlockGrassSlab extends BlockSlab
{
    public static final PropertyBool seamlessBool = PropertyBool.create("seamless");
    public static final PropertyEnum typeVar = PropertyEnum.create("variant", BlockGrassSlab.EnumType.class);

    public BlockGrassSlab()
    {
        super(Material.grass);
        IBlockState iblockstate = this.blockState.getBaseState();
        if (this.isDouble())
        {
            iblockstate = iblockstate.withProperty(seamlessBool, Boolean.valueOf(false));
        }
        else
        {
            iblockstate = iblockstate.withProperty(HALF, BlockSlab.EnumBlockHalf.BOTTOM);
        }
        this.setDefaultState(iblockstate.withProperty(typeVar, BlockGrassSlab.EnumType.NORMAL));
        this.setCreativeTab(MWTabs.tabBlock);
        this.setHardness(0.7F);
        this.setResistance(0.0F);
        this.useNeighborBrightness = !this.isDouble();
        this.setStepSound(soundTypeGrass);
    }

    @SideOnly(Side.CLIENT)
    public EnumWorldBlockLayer getBlockLayer()
    {
      return EnumWorldBlockLayer.CUTOUT_MIPPED;
    }
    
    @SideOnly(Side.CLIENT)
    public int getBlockColor()
    {
        return ColorizerGrass.getGrassColor(0.5D, 1.0D);
    }

    @SideOnly(Side.CLIENT)
    public int getRenderColor(IBlockState state)
    {
        return this.getBlockColor();
    }

    @SideOnly(Side.CLIENT)
    public int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass)
    {
        return BiomeColorHelper.getGrassColorAtPos(worldIn, pos);
    }

    
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
    {
        return Item.getItemFromBlock(MWVanillaSlabs.grass_single_slab);
    }

    @SideOnly(Side.CLIENT)
    public Item getItem(World worldIn, BlockPos pos)
    {
    	
        return Item.getItemFromBlock(MWVanillaSlabs.grass_single_slab);
    }

    public String getUnlocalizedName(int meta)
    {
        return "tile." + BlockGrassSlab.EnumType.func_176625_a(meta).func_176627_c();
    }

    public IProperty getVariantProperty()
    {
        return typeVar;
    }

    public Object getVariant(ItemStack stack)
    {
        return BlockGrassSlab.EnumType.func_176625_a(stack.getMetadata() & 7);
    }

    @SideOnly(Side.CLIENT)
    public void getSubBlocks(Item itemIn, CreativeTabs tab, List list)
    {
        if (itemIn != Item.getItemFromBlock(MWVanillaSlabs.grass_double_slab))
        {
            BlockGrassSlab.EnumType[] aenumtype = BlockGrassSlab.EnumType.values();
            int i = aenumtype.length;

            for (int j = 0; j < i; ++j)
            {
                BlockGrassSlab.EnumType enumtype = aenumtype[j];

                    list.add(new ItemStack(itemIn, 1, enumtype.func_176624_a()));
               
            }
        }
    }

    public IBlockState getStateFromMeta(int meta)
    {
        IBlockState iblockstate = this.getDefaultState().withProperty(typeVar, BlockGrassSlab.EnumType.func_176625_a(meta & 7));

        if (this.isDouble())
        {
            iblockstate = iblockstate.withProperty(seamlessBool, Boolean.valueOf((meta &  != 0));
        }
        else
        {
            iblockstate = iblockstate.withProperty(HALF, (meta &  == 0 ? BlockSlab.EnumBlockHalf.BOTTOM : BlockSlab.EnumBlockHalf.TOP);
        }

        return iblockstate;
    }

    public int getMetaFromState(IBlockState state)
    {
        byte b0 = 0;
        int i = b0 | ((BlockGrassSlab.EnumType)state.getValue(typeVar)).func_176624_a();

        if (this.isDouble())
        {
            if (((Boolean)state.getValue(seamlessBool)).booleanValue())
            {
                i |= 8;
            }
        }
        else if (state.getValue(HALF) == BlockSlab.EnumBlockHalf.TOP)
        {
            i |= 8;
        }

        return i;
    }

    protected BlockState createBlockState()
    {
        return this.isDouble() ? new BlockState(this, new IProperty[] {seamlessBool, typeVar}): new BlockState(this, new IProperty[] {HALF, typeVar});
    }

    public int damageDropped(IBlockState state)
    {
        return ((BlockGrassSlab.EnumType)state.getValue(typeVar)).func_176624_a();
    }

    public static enum EnumType implements IStringSerializable
    {
    //	VARIANT(META, "VAR NAME", "UNL.NAME");
    	NORMAL(0, "normal", "grass_single_slab");

        private static final BlockGrassSlab.EnumType[] field_176640_i = new BlockGrassSlab.EnumType[values().length];
        private final int meta;
        private final String variantName;
        private final String name;


        private EnumType(int meta, String name)
        {
            this(meta, name, name);
        }

        private EnumType(int meta, String variantName, String name)
        {
            this.meta = meta;
            this.variantName = variantName;
            this.name = name;
        }

        public int func_176624_a()
        {
            return this.meta;
        }

        public String toString()
        {
            return this.variantName;
        }

        public static BlockGrassSlab.EnumType func_176625_a(int meta)
        {
            if (meta < 0 || meta >= field_176640_i.length)
            {
                meta = 0;
            }

            return field_176640_i[meta];
        }

        public String getName()
        {
            return this.variantName;
        }

        public String func_176627_c()
        {
            return this.name;
        }

        static
        {
            BlockGrassSlab.EnumType[] var0 = values();
            int var1 = var0.length;

            for (int var2 = 0; var2 < var1; ++var2)
            {
                BlockGrassSlab.EnumType var3 = var0[var2];
                field_176640_i[var3.func_176624_a()] = var3;
            }
        }
    }

@Override
public boolean isDouble() {
	return false;
}

@Override
public boolean isSideSolid(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
{
	if(side == EnumFacing.UP)
		return true;
	else
		return false;
}

}

 

And here is a screenshot of what the single slab looks like in inventory, on ground and on the upper half of a block

RkCsN8j.png

 

Basically is not painting the grass top grass texture :/

Also, there is a better way to make a slab that has no variant (just 1 type of slab, for example: only grass or only stone....)?

Thanks in advance to all who will help me :)

 

Don't blame me if i always ask for your help. I just want to learn to be better :)

Posted

Blocks are only rendered with a colour multiplier if the model defines a tint index for the face. Look at the grass.json and grass_normal.json models.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

OK, so 'ive tried adding this code from the grass.json file to my both upper and half slab .json files

"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" }
            }
        }
    ]

 

So i now have this half_grass_slab.json file

{
"parent": "block/half_slab",
"textures": {
	"particle": "blocks/dirt",
        "bottom": "blocks/dirt",
        "top": "blocks/grass_top",
        "side": "blocks/grass_side",
        "overlay": "blocks/grass_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" }
            }
        }
    ]
}

and this upper_grass_slab.json file

{
"parent": "block/upper_slab",
"textures": {
	"particle": "blocks/dirt",
        "bottom": "blocks/dirt",
        "top": "blocks/grass_top",
        "side": "blocks/grass_side",
        "overlay": "blocks/grass_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" }
            }
        }
    ]
}

 

But i have errors in Eclipse, saying:

13:35:55] [Client thread/ERROR] [FML]: Exception loading model mw:block/upper_grass_slab with loader instance, skipping
com.google.gson.JsonParseException: BlockModel requires either elements or parent, found both
at net.minecraft.client.renderer.block.model.ModelBlock$Deserializer.parseModelBlock(ModelBlock.java:256) ~[ModelBlock$Deserializer.class:?]
at net.minecraft.client.renderer.block.model.ModelBlock$Deserializer.deserialize(ModelBlock.java:323) ~[ModelBlock$Deserializer.class:?]
at com.google.gson.TreeTypeAdapter.read(TreeTypeAdapter.java:58) ~[TreeTypeAdapter.class:?]
at com.google.gson.Gson.fromJson(Gson.java:803) ~[Gson.class:?]
at com.google.gson.Gson.fromJson(Gson.java:741) ~[Gson.class:?]
at net.minecraft.client.renderer.block.model.ModelBlock.deserialize(ModelBlock.java:47) ~[ModelBlock.class:?]
at net.minecraft.client.resources.model.ModelBakery.loadModel(ModelBakery.java:269) ~[ModelBakery.class:?]
at net.minecraftforge.client.model.ModelLoader.access$900(ModelLoader.java:67) ~[ModelLoader.class:?]
at net.minecraftforge.client.model.ModelLoader$VanillaLoader.loadModel(ModelLoader.java:451) ~[ModelLoader$VanillaLoader.class:?]
at net.minecraftforge.client.model.ModelLoaderRegistry.getModel(ModelLoaderRegistry.java:92) [ModelLoaderRegistry.class:?]
at net.minecraftforge.client.model.ModelLoader.loadAnyModel(ModelLoader.java:187) [ModelLoader.class:?]
at net.minecraftforge.client.model.ModelLoader.getModel(ModelLoader.java:170) [ModelLoader.class:?]
at net.minecraftforge.client.model.ModelLoader$WeightedRandomModel.<init>(ModelLoader.java:342) [ModelLoader$WeightedRandomModel.class:?]
at net.minecraftforge.client.model.ModelLoader.registerVariant(ModelLoader.java:140) [ModelLoader.class:?]
at net.minecraft.client.resources.model.ModelBakery.loadVariants(ModelBakery.java:122) [ModelBakery.class:?]
at net.minecraftforge.client.model.ModelLoader.loadBlocks(ModelLoader.java:121) [ModelLoader.class:?]
at net.minecraftforge.client.model.ModelLoader.setupModelRegistry(ModelLoader.java:91) [ModelLoader.class:?]
at net.minecraft.client.resources.model.ModelManager.onResourceManagerReload(ModelManager.java:29) [ModelManager.class:?]
at net.minecraft.client.resources.SimpleReloadableResourceManager.notifyReloadListeners(SimpleReloadableResourceManager.java:134) [simpleReloadableResourceManager.class:?]
at net.minecraft.client.resources.SimpleReloadableResourceManager.reloadResources(SimpleReloadableResourceManager.java:118) [simpleReloadableResourceManager.class:?]
at net.minecraft.client.Minecraft.refreshResources(Minecraft.java:767) [Minecraft.class:?]
at net.minecraftforge.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:306) [FMLClientHandler.class:?]
at net.minecraft.client.Minecraft.startGame(Minecraft.java:521) [Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:356) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:117) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_51]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_51]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?]
at GradleStart.main(Unknown Source) [start/:?]
[13:35:55] [Client thread/ERROR] [FML]: Exception loading model mw:block/half_grass_slab with loader instance, skipping
com.google.gson.JsonParseException: BlockModel requires either elements or parent, found both
at net.minecraft.client.renderer.block.model.ModelBlock$Deserializer.parseModelBlock(ModelBlock.java:256) ~[ModelBlock$Deserializer.class:?]
at net.minecraft.client.renderer.block.model.ModelBlock$Deserializer.deserialize(ModelBlock.java:323) ~[ModelBlock$Deserializer.class:?]
at com.google.gson.TreeTypeAdapter.read(TreeTypeAdapter.java:58) ~[TreeTypeAdapter.class:?]
at com.google.gson.Gson.fromJson(Gson.java:803) ~[Gson.class:?]
at com.google.gson.Gson.fromJson(Gson.java:741) ~[Gson.class:?]
at net.minecraft.client.renderer.block.model.ModelBlock.deserialize(ModelBlock.java:47) ~[ModelBlock.class:?]
at net.minecraft.client.resources.model.ModelBakery.loadModel(ModelBakery.java:269) ~[ModelBakery.class:?]
at net.minecraftforge.client.model.ModelLoader.access$900(ModelLoader.java:67) ~[ModelLoader.class:?]
at net.minecraftforge.client.model.ModelLoader$VanillaLoader.loadModel(ModelLoader.java:451) ~[ModelLoader$VanillaLoader.class:?]
at net.minecraftforge.client.model.ModelLoaderRegistry.getModel(ModelLoaderRegistry.java:92) [ModelLoaderRegistry.class:?]
at net.minecraftforge.client.model.ModelLoader.loadAnyModel(ModelLoader.java:187) [ModelLoader.class:?]
at net.minecraftforge.client.model.ModelLoader.getModel(ModelLoader.java:170) [ModelLoader.class:?]
at net.minecraftforge.client.model.ModelLoader$WeightedRandomModel.<init>(ModelLoader.java:342) [ModelLoader$WeightedRandomModel.class:?]
at net.minecraftforge.client.model.ModelLoader.registerVariant(ModelLoader.java:140) [ModelLoader.class:?]
at net.minecraft.client.resources.model.ModelBakery.loadVariants(ModelBakery.java:122) [ModelBakery.class:?]
at net.minecraftforge.client.model.ModelLoader.loadBlocks(ModelLoader.java:121) [ModelLoader.class:?]
at net.minecraftforge.client.model.ModelLoader.setupModelRegistry(ModelLoader.java:91) [ModelLoader.class:?]
at net.minecraft.client.resources.model.ModelManager.onResourceManagerReload(ModelManager.java:29) [ModelManager.class:?]
at net.minecraft.client.resources.SimpleReloadableResourceManager.notifyReloadListeners(SimpleReloadableResourceManager.java:134) [simpleReloadableResourceManager.class:?]
at net.minecraft.client.resources.SimpleReloadableResourceManager.reloadResources(SimpleReloadableResourceManager.java:118) [simpleReloadableResourceManager.class:?]
at net.minecraft.client.Minecraft.refreshResources(Minecraft.java:767) [Minecraft.class:?]
at net.minecraftforge.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:306) [FMLClientHandler.class:?]
at net.minecraft.client.Minecraft.startGame(Minecraft.java:521) [Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:356) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:117) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_51]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_51]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?]
at GradleStart.main(Unknown Source) [start/:?]

 

How can i solve that?

Don't blame me if i always ask for your help. I just want to learn to be better :)

Posted

Like the error says, a model can only specify a parent or elements; but not both. Since you need to specify the

tintindex

in the elements, you need to define the elements yourself instead of inheriting from the default slab models.

 

You'll need to copy the grass.json model, adjust the height (the y dimension of the

from

and

to

coordinates) of each element to 8 instead of 16 and remove the

cullface

from the

up

or

down

face (like the slab models). You can then inherit from this model for each variant of grass you want to support like the default grass models.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

Thanks for the answer :) Ok, i've edit the json files and now the slab looks fine on ground, but in inventory the top of the slab is still grey :/

Don't blame me if i always ask for your help. I just want to learn to be better :)

Posted

This is the half_grass_slab block model:

{
"textures": {
	"particle": "blocks/dirt",
        "bottom": "blocks/dirt",
        "top": "blocks/grass_top",
        "side": "blocks/grass_side",
        "overlay": "blocks/grass_side_overlay"
},
"elements": [
        {   "from": [ 0, 0, 0 ],
            "to": [ 16, 8, 16 ],
            "faces": {
                "down":  { "uv": [ 0, 0, 16, 16 ], "texture": "#bottom" },
                "up":    { "uv": [ 0, 0, 16, 16 ], "texture": "#top", "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, 8, 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" }
            }
        }
    ]
}

 

This is the upper_grass_slab block model:

{
"textures": {
	"particle": "blocks/dirt",
        "bottom": "blocks/dirt",
        "top": "blocks/grass_top",
        "side": "blocks/grass_side",
        "overlay": "blocks/grass_side_overlay"
},
"elements": [
        {   "from": [ 0, 8, 0 ],
            "to": [ 16, 16, 16 ],
            "faces": {
                "down":  { "uv": [ 0, 0, 16, 16 ], "texture": "#bottom" },
                "up":    { "uv": [ 0, 0, 16, 16 ], "texture": "#top", "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, 8, 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" }
            }
        }
    ]
}

 

And this is the item model file

{
"parent": "mw:block/half_grass_slab",
"display": {
	"thirdperson": {
		"rotation": [ 10, -45, 170],
		"translation": [ 0, 1.5, -2.75],
		"scale": [ 0.375, 0.375, 0.375]
	}
}
}

 

As mentioned above the slabs itself have no problems, only the rendering in inventory is wrong :/

This is how it looks right now

X0x2Qec.png

Don't blame me if i always ask for your help. I just want to learn to be better :)

Posted

As mentioned above the slabs itself have no problems, only the rendering in inventory is wrong :/

 

Ah, I didn't get that from your last post.

 

If it's rendering with colour in the world but grey in your inventory, you need to create a custom

ItemBlock

class that overrides

Item#getColorFromItemStack

like

ItemColored

does. You'll want to extend

ItemSlab

(to inherit the slab placement logic) and have a constructor that takes your actual single/double slab classes for the

singleSlab

and

doubleSlab

parameters instead of

BlockSlab

(so FML can find the constructor via reflection when you register your

Block

s).

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

Yay! :D I added this function to my ItemGrassSlab class

@SideOnly(Side.CLIENT)
    public int getColorFromItemStack(ItemStack stack, int renderPass)
    {
        return this.single.getRenderColor(this.single.getStateFromMeta(stack.getMetadata()));
    }

and it worked :D Thanks for the answer :)

Don't blame me if i always ask for your help. I just want to learn to be better :)

  • 3 months later...
Posted

Hi. I made a custom grass block model of this example. But the particles from the block also colored in the biome color. How can I fix it?

Sorry, I don't speak English very well...

Posted

The UV's in your models are off, currently they are rendering the full texture on half a block.

 

half_grass_slab block model:

{
    "textures": {
        "particle": "blocks/dirt",
        "bottom": "blocks/dirt",
        "top": "blocks/grass_top",
        "side": "blocks/grass_side",
        "overlay": "blocks/grass_side_overlay"
    },
    "elements": [
        {   "from": [ 0, 0, 0 ],
            "to": [ 16, 8, 16 ],
            "faces": {
                "down":  { "uv": [ 0, 0, 16, 16 ], "texture": "#bottom", "cullface": "down" },
                "up":    { "uv": [ 0, 0, 16, 16 ], "texture": "#top", "tintindex": 0 },
                "north": { "uv": [ 0, 8, 16, 16 ], "texture": "#side", "cullface": "north" },
                "south": { "uv": [ 0, 8, 16, 16 ], "texture": "#side", "cullface": "south" },
                "west":  { "uv": [ 0, 8, 16, 16 ], "texture": "#side", "cullface": "west" },
                "east":  { "uv": [ 0, 8, 16, 16 ], "texture": "#side", "cullface": "east" }
            }
        },
        {   "from": [ 0, 0, 0 ],
            "to": [ 16, 8, 16 ],
            "faces": {
                "north": { "uv": [ 0, 0, 16, 8 ], "texture": "#overlay", "tintindex": 0, "cullface": "north" },
                "south": { "uv": [ 0, 0, 16, 8 ], "texture": "#overlay", "tintindex": 0, "cullface": "south" },
                "west":  { "uv": [ 0, 0, 16, 8 ], "texture": "#overlay", "tintindex": 0, "cullface": "west" },
                "east":  { "uv": [ 0, 0, 16, 8 ], "texture": "#overlay", "tintindex": 0, "cullface": "east" }
            }
        }
    ]
}

 

upper_grass_slab block model:

{
    "textures": {
        "particle": "blocks/dirt",
        "bottom": "blocks/dirt",
        "top": "blocks/grass_top",
        "side": "blocks/grass_side",
        "overlay": "blocks/grass_side_overlay"
    },
    "elements": [
        {   "from": [ 0, 8, 0 ],
            "to": [ 16, 16, 16 ],
            "faces": {
                "down":  { "uv": [ 0, 0, 16, 16 ], "texture": "#bottom" },
                "up":    { "uv": [ 0, 0, 16, 16 ], "texture": "#top", "tintindex": 0, "cullface": "up" },
                "north": { "uv": [ 0, 0, 16,  8 ], "texture": "#side", "cullface": "north" },
                "south": { "uv": [ 0, 0, 16,  8 ], "texture": "#side", "cullface": "south" },
                "west":  { "uv": [ 0, 0, 16,  8 ], "texture": "#side", "cullface": "west" },
                "east":  { "uv": [ 0, 0, 16,  8 ], "texture": "#side", "cullface": "east" }
            }
        },
        {   "from": [ 0, 8, 0 ],
            "to": [ 16, 16, 16 ],
            "faces": {
                "north": { "uv": [ 0, 0, 16, 8 ], "texture": "#overlay", "tintindex": 0, "cullface": "north" },
                "south": { "uv": [ 0, 0, 16, 8 ], "texture": "#overlay", "tintindex": 0, "cullface": "south" },
                "west":  { "uv": [ 0, 0, 16, 8 ], "texture": "#overlay", "tintindex": 0, "cullface": "west" },
                "east":  { "uv": [ 0, 0, 16, 8 ], "texture": "#overlay", "tintindex": 0, "cullface": "east" }
            }
        }
    ]
}

Posted

No, I need a full grass block.

First, I created a model.

 

my_grass_model:

{
    "elements": [
        {  "from": [ 0, 0, 0 ],
            "to": [ 16, 16, 16 ],
            "faces": {
                "down":  { "uv": [ 0, 0, 16, 16 ], "texture": "#down", "cullface": "down" },
                "up":    { "uv": [ 0, 0, 16, 16 ], "texture": "#up",    "cullface": "up", "tintindex": 0 },
                "north": { "uv": [ 0, 0, 16, 16 ], "texture": "#north",   "cullface": "north" },
                "south": { "uv": [ 0, 0, 16, 16 ], "texture": "#south",   "cullface": "south" },
                "west":  { "uv": [ 0, 0, 16, 16 ], "texture": "#west",   "cullface": "west" },
                "east":  { "uv": [ 0, 0, 16, 16 ], "texture": "#east",   "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" }
            }
        }
    ]
}

 

Then, based on it created a model for my block.

 

my_grass_block

{  
    "parent": "mymod:block/my_grass_model",
    "textures": {
        "particle": "blocks/dirt",
        "down": "mymod:blocks/MyGrass_Bottom",
        "up": "blocks/grass_top",
        "north": "mymod:blocks/MyGrass",
        "east": "mymod:blocks/MyGrass",
        "south": "mymod:blocks/MyGrass",
        "west": "mymod:blocks/MyGrass",
        "overlay": "blocks/grass_side_overlay"
    }
}

 

And particles from the block have no color of the dirt. They are painted in green. How can I fix it?

 

width=800 height=601https://file-up.net/big_748f23757e8c8371e820151209082645.jpg[/img]

 

Sorry, I don't speak English very well...

Posted

@Liahim

Sorry for the confusion, I was pointing out the UV error to JimiIT92.

 

As for your particle issue, I'm not sure.

I've currently got a block with the opposite issue; item and block colored correctly but particles are grey.

Eventually I'll look into it but since I have larger parts of my mod left to upgrade its low priority.

 

I'm am using tintindex 1 for that block so my thinking is: tintindex 0 might always be used for particles so anything other then white results in colored particles, and the default grass is case exempted.

But that is based entirely on observation and has no bases in the code itself.

 

EDIT:

After posting I started wonder why I was still using tintindex 1, (it was from an older model design, and I simply didn't go through and change it)

So I change my models to use tintindex 0 and updated the colorMultiplier, and my particles are correctly colored.

 

This makes it look even more like tintindex 0 is always used on particles and grass is just hard coded.

I'd suggest using tintindex 1 in your model and changing it in your Block.colorMultiplier and Item.getColorFromItemStack.

Posted

@ShetiPhian

Sorry. How can I change the colorMultiplier method for these purposes?

I do not quite understand.

 

Now it looks like this:

    @SideOnly(Side.CLIENT)
    public int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass)
    {
        return BiomeColorHelper.getGrassColorAtPos(worldIn, pos);
    }

 

O! I did it! Thanks for help )

    @SideOnly(Side.CLIENT)
    public int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass)
    {
        return renderPass == 1 ? BiomeColorHelper.getGrassColorAtPos(worldIn, pos) : 16777215;
    }

Sorry, I don't speak English very well...

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Version 1.19 - Forge 41.0.63 I want to create a wolf entity that I can ride, so far it seems to be working, but the problem is that when I get on the wolf, I can’t control it. I then discovered that the issue is that the server doesn’t detect that I’m riding the wolf, so I’m struggling with synchronization. However, it seems to not be working properly. As I understand it, the server receives the packet but doesn’t register it correctly. I’m a bit new to Java, and I’ll try to provide all the relevant code and prints *The comments and prints are translated by chatgpt since they were originally in Spanish* Thank you very much in advance No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. MountableWolfEntity package com.vals.valscraft.entity; import com.vals.valscraft.network.MountSyncPacket; import com.vals.valscraft.network.NetworkHandler; import net.minecraft.client.Minecraft; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.animal.Wolf; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.Entity; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.network.PacketDistributor; public class MountableWolfEntity extends Wolf { private boolean hasSaddle; private static final EntityDataAccessor<Byte> DATA_ID_FLAGS = SynchedEntityData.defineId(MountableWolfEntity.class, EntityDataSerializers.BYTE); public MountableWolfEntity(EntityType<? extends Wolf> type, Level level) { super(type, level); this.hasSaddle = false; } @Override protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(DATA_ID_FLAGS, (byte)0); } public static AttributeSupplier.Builder createAttributes() { return Wolf.createAttributes() .add(Attributes.MAX_HEALTH, 20.0) .add(Attributes.MOVEMENT_SPEED, 0.3); } @Override public InteractionResult mobInteract(Player player, InteractionHand hand) { ItemStack itemstack = player.getItemInHand(hand); if (itemstack.getItem() == Items.SADDLE && !this.hasSaddle()) { if (!player.isCreative()) { itemstack.shrink(1); } this.setSaddle(true); return InteractionResult.SUCCESS; } else if (!level.isClientSide && this.hasSaddle()) { player.startRiding(this); MountSyncPacket packet = new MountSyncPacket(true); // 'true' means the player is mounted NetworkHandler.CHANNEL.sendToServer(packet); // Ensure the server handles the packet return InteractionResult.SUCCESS; } return InteractionResult.PASS; } @Override public void travel(Vec3 travelVector) { if (this.isVehicle() && this.getControllingPassenger() instanceof Player) { System.out.println("The wolf has a passenger."); System.out.println("The passenger is a player."); Player player = (Player) this.getControllingPassenger(); // Ensure the player is the controller this.setYRot(player.getYRot()); this.yRotO = this.getYRot(); this.setXRot(player.getXRot() * 0.5F); this.setRot(this.getYRot(), this.getXRot()); this.yBodyRot = this.getYRot(); this.yHeadRot = this.yBodyRot; float forward = player.zza; float strafe = player.xxa; if (forward <= 0.0F) { forward *= 0.25F; } this.flyingSpeed = this.getSpeed() * 0.1F; this.setSpeed((float) this.getAttributeValue(Attributes.MOVEMENT_SPEED) * 1.5F); this.setDeltaMovement(new Vec3(strafe, travelVector.y, forward).scale(this.getSpeed())); this.calculateEntityAnimation(this, false); } else { // The wolf does not have a passenger or the passenger is not a player System.out.println("No player is mounted, or the passenger is not a player."); super.travel(travelVector); } } public boolean hasSaddle() { return this.hasSaddle; } public void setSaddle(boolean hasSaddle) { this.hasSaddle = hasSaddle; } @Override protected void dropEquipment() { super.dropEquipment(); if (this.hasSaddle()) { this.spawnAtLocation(Items.SADDLE); this.setSaddle(false); } } @SubscribeEvent public static void onServerTick(TickEvent.ServerTickEvent event) { if (event.phase == TickEvent.Phase.START) { MinecraftServer server = net.minecraftforge.server.ServerLifecycleHooks.getCurrentServer(); if (server != null) { for (ServerPlayer player : server.getPlayerList().getPlayers()) { if (player.isPassenger() && player.getVehicle() instanceof MountableWolfEntity) { MountableWolfEntity wolf = (MountableWolfEntity) player.getVehicle(); System.out.println("Tick: " + player.getName().getString() + " is correctly mounted on " + wolf); } } } } } private boolean lastMountedState = false; @Override public void tick() { super.tick(); if (!this.level.isClientSide) { // Only on the server boolean isMounted = this.isVehicle() && this.getControllingPassenger() instanceof Player; // Only print if the state changed if (isMounted != lastMountedState) { if (isMounted) { Player player = (Player) this.getControllingPassenger(); // Verify the passenger is a player System.out.println("Server: Player " + player.getName().getString() + " is now mounted."); } else { System.out.println("Server: The wolf no longer has a passenger."); } lastMountedState = isMounted; } } } @Override public void addPassenger(Entity passenger) { super.addPassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(true)); } } } @Override public void removePassenger(Entity passenger) { super.removePassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is no longer mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(false)); } } } @Override public boolean isControlledByLocalInstance() { Entity entity = this.getControllingPassenger(); return entity instanceof Player; } @Override public void positionRider(Entity passenger) { if (this.hasPassenger(passenger)) { double xOffset = Math.cos(Math.toRadians(this.getYRot() + 90)) * 0.4; double zOffset = Math.sin(Math.toRadians(this.getYRot() + 90)) * 0.4; passenger.setPos(this.getX() + xOffset, this.getY() + this.getPassengersRidingOffset() + passenger.getMyRidingOffset(), this.getZ() + zOffset); } } } MountSyncPacket package com.vals.valscraft.network; import com.vals.valscraft.entity.MountableWolfEntity; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class MountSyncPacket { private final boolean isMounted; public MountSyncPacket(boolean isMounted) { this.isMounted = isMounted; } public void encode(FriendlyByteBuf buffer) { buffer.writeBoolean(isMounted); } public static MountSyncPacket decode(FriendlyByteBuf buffer) { return new MountSyncPacket(buffer.readBoolean()); } public void handle(NetworkEvent.Context context) { context.enqueueWork(() -> { ServerPlayer player = context.getSender(); // Get the player from the context if (player != null) { // Verifies if the player has dismounted if (!isMounted) { Entity vehicle = player.getVehicle(); if (vehicle instanceof MountableWolfEntity wolf) { // Logic to remove the player as a passenger wolf.removePassenger(player); System.out.println("Server: Player " + player.getName().getString() + " is no longer mounted."); } } } }); context.setPacketHandled(true); // Marks the packet as handled } } networkHandler package com.vals.valscraft.network; import com.vals.valscraft.valscraft; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.network.NetworkRegistry; import net.minecraftforge.network.simple.SimpleChannel; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class NetworkHandler { private static final String PROTOCOL_VERSION = "1"; public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel( new ResourceLocation(valscraft.MODID, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals ); public static void init() { int packetId = 0; // Register the mount synchronization packet CHANNEL.registerMessage( packetId++, MountSyncPacket.class, MountSyncPacket::encode, MountSyncPacket::decode, (msg, context) -> msg.handle(context.get()) // Get the context with context.get() ); } }  
    • Do you use features of inventory profiles next (ipnext) or is there a change without it?
    • Remove rubidium - you are already using embeddium, which is a fork of rubidium
  • Topics

×
×
  • Create New...

Important Information

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