Jump to content

Recommended Posts

Posted (edited)

Hi everyone :D I'm trying to make metadata blocks in 1.12.2 using the forge_marker blockstates system. Now, the block itself works fine, if i place them down i get different textures based on their variant. But in inventory i get the black/purple texture :/ This is my json blockstate file
 

{
    "forge_marker": 1,
    "defaults": {
        "textures": {
        },
        "model": "cube_all"
    },
    "variants": {
        "normal": [{

        }],
        "inventory": [{

        }],
         "color": {
            "white":  { "textures": { "all": "mineworld:blocks/marble_white"} },
            "black":  { "textures": { "all": "mineworld:blocks/marble_black"} },
            "red":  { "textures": { "all": "mineworld:blocks/marble_red"} },
            "brown":  { "textures": { "all": "mineworld:blocks/marble_brown"} },
            "pink":  { "textures": { "all": "mineworld:blocks/marble_pink"} },
            "yellow":  { "textures": { "all": "mineworld:blocks/marble_yellow"} },
            "green":  { "textures": { "all": "mineworld:blocks/marble_green"} }
        }
    }
}

And this is how i register them
 

ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(MARBLE), 0, new ModelResourceLocation(MARBLE.getRegistryName() + "_white", "white"));
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(MARBLE), 1, new ModelResourceLocation(MARBLE.getRegistryName() + "_black", "black"));
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(MARBLE), 2, new ModelResourceLocation(MARBLE.getRegistryName() + "_red", "red"));
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(MARBLE), 3, new ModelResourceLocation(MARBLE.getRegistryName() + "_brown", "brown"));
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(MARBLE), 4, new ModelResourceLocation(MARBLE.getRegistryName() + "_pink", "pink"));
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(MARBLE), 5, new ModelResourceLocation(MARBLE.getRegistryName() + "_yellow", "yellow"));
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(MARBLE), 6, new ModelResourceLocation(MARBLE.getRegistryName() + "_green", "green"));

 

What am i missing here? :/ 

 

Edited by JimiIT92
Solved

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

Posted
MARBLE.getRegistryName() + "_black", "black"));

 

You're telling it to look for a different file every time. Drop that "_color" bit.

 

Also, read your logs.

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.

Posted (edited)

I removed that color part but nothing changed. My log throws this error

 

[15:40:30] [main/ERROR] [FML]: Exception loading model for variant mineworld:marble#white for item "mineworld:marble", blockstate location exception: 
net.minecraftforge.client.model.ModelLoaderRegistry$LoaderException: Exception loading model mineworld:marble#white with loader VariantLoader.INSTANCE, skipping
	at net.minecraftforge.client.model.ModelLoaderRegistry.getModel(ModelLoaderRegistry.java:161) ~[ModelLoaderRegistry.class:?]
	at net.minecraftforge.client.model.ModelLoader.loadItemModels(ModelLoader.java:296) ~[ModelLoader.class:?]
	at net.minecraft.client.renderer.block.model.ModelBakery.loadVariantItemModels(ModelBakery.java:175) ~[ModelBakery.class:?]
	at net.minecraftforge.client.model.ModelLoader.setupModelRegistry(ModelLoader.java:151) ~[ModelLoader.class:?]
	at net.minecraft.client.renderer.block.model.ModelManager.onResourceManagerReload(ModelManager.java:28) [ModelManager.class:?]
	at net.minecraft.client.resources.SimpleReloadableResourceManager.registerReloadListener(SimpleReloadableResourceManager.java:121) [SimpleReloadableResourceManager.class:?]
	at net.minecraft.client.Minecraft.init(Minecraft.java:559) [Minecraft.class:?]
	at net.minecraft.client.Minecraft.run(Minecraft.java:421) [Minecraft.class:?]
	at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_181]
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_181]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_181]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_181]
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_181]
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_181]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_181]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_181]
	at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
	at GradleStart.main(GradleStart.java:25) [start/:?]
Caused by: net.minecraft.client.renderer.block.model.ModelBlockDefinition$MissingVariantException
	at net.minecraft.client.renderer.block.model.ModelBlockDefinition.getVariant(ModelBlockDefinition.java:83) ~[ModelBlockDefinition.class:?]
	at net.minecraftforge.client.model.ModelLoader$VariantLoader.loadModel(ModelLoader.java:1175) ~[ModelLoader$VariantLoader.class:?]
	at net.minecraftforge.client.model.ModelLoaderRegistry.getModel(ModelLoaderRegistry.java:157) ~[ModelLoaderRegistry.class:?]
	... 20 more

 

Edited by JimiIT92
removed log syntax highlight

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

Posted

If i change to this

 

{
    "forge_marker": 1,
    "defaults": {
        "textures": {
        },
        "model": "cube_all"
    },
    "variants": {
        "normal": [{

        }],
        "inventory": [{

        }],
        "color": {
            "color=white":  { "textures": { "all": "mineworld:blocks/marble_white"} },
            "color=black":  { "textures": { "all": "mineworld:blocks/marble_black"} },
            "color=red":  { "textures": { "all": "mineworld:blocks/marble_red"} },
            "color=brown":  { "textures": { "all": "mineworld:blocks/marble_brown"} },
            "color=pink":  { "textures": { "all": "mineworld:blocks/marble_pink"} },
            "color=yellow":  { "textures": { "all": "mineworld:blocks/marble_yellow"} },
            "color=green":  { "textures": { "all": "mineworld:blocks/marble_green"} }
        }
    }
}

or to this
 

{
    "forge_marker": 1,
    "defaults": {
        "textures": {
        },
        "model": "cube_all"
    },
    "variants": {
        "normal": [{

        }],
        "inventory": [{

        }],
        "color=white":  { "textures": { "all": "mineworld:blocks/marble_white"} },
        "color=black":  { "textures": { "all": "mineworld:blocks/marble_black"} },
        "color=red":  { "textures": { "all": "mineworld:blocks/marble_red"} },
        "color=brown":  { "textures": { "all": "mineworld:blocks/marble_brown"} },
        "color=pink":  { "textures": { "all": "mineworld:blocks/marble_pink"} },
        "color=yellow":  { "textures": { "all": "mineworld:blocks/marble_yellow"} },
        "color=green":  { "textures": { "all": "mineworld:blocks/marble_green"} }
    }
}

then the placed block has no texture too :/ Also i don't understand where the difference comes from and how to tell the game to use the one without "color=" instead

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

Posted

Ok, i thought it was some error in the json file since it's the first time i use the forge blockstate format. Anyway this is the class i'm using to create the block with the variants
 

package com.mineworld.block;

import com.mineworld.block.enums.EnumMarble;
import com.mineworld.core.MWTabs;

import net.minecraft.block.BlockPlanks;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.MapColor;
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.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;

public class BlockMarble extends BlockMW {
	private static final PropertyEnum<EnumMarble> COLOR = PropertyEnum.<EnumMarble>create("color", EnumMarble.class);

	public BlockMarble(String name) {
		super(name, Material.ROCK, MapColor.QUARTZ, SoundType.STONE, MWTabs.BUILDING_BLOCKS);
		this.setDefaultState(this.blockState.getBaseState().withProperty(COLOR, EnumMarble.WHITE));
		setHardness(1.5F);
		setResistance(10.0F);
	}

	/**
	 * Gets the metadata of the item this Block can drop. This method is called when
	 * the block gets destroyed. It returns the metadata of the dropped item based
	 * on the old metadata of the block.
	 */
	public int damageDropped(IBlockState state) {
		return ((EnumMarble) state.getValue(COLOR)).getMetadata();
	}

	/**
	 * returns a list of blocks with the same ID, but different meta (eg: wood
	 * returns 4 blocks)
	 */
	public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items) {
		for (EnumMarble value : EnumMarble.values()) {
			items.add(new ItemStack(this, 1, value.getMetadata()));
		}
	}

	/**
	 * Get the MapColor for this Block and the given BlockState
	 */
	public MapColor getMapColor(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
		return ((EnumMarble) state.getValue(COLOR)).getMapColor();
	}

	/**
	 * Convert the BlockState into the correct metadata value
	 */
	public int getMetaFromState(IBlockState state) {
		return ((EnumMarble) state.getValue(COLOR)).getMetadata();
	}

	protected BlockStateContainer createBlockState() {
		return new BlockStateContainer(this, new IProperty[] { COLOR });
	}

	/**
	 * Convert the given metadata into a BlockState for this Block
	 */
	public IBlockState getStateFromMeta(int meta) {
		return this.getDefaultState().withProperty(COLOR, EnumMarble.byMetadata(meta));
	}
}

BlockMW just sets the registry name, the unlocalized name and the creative tab

 

This is the enum i use to create the variants
 

package com.mineworld.block.enums;

import net.minecraft.block.material.MapColor;
import net.minecraft.util.IStringSerializable;

public enum EnumMarble implements IStringSerializable {
	WHITE(0, "white", MapColor.QUARTZ),
	BLACK(1, "black", MapColor.BLACK),
	RED(2, "red", MapColor.RED),
	BROWN(3, "brown", MapColor.BROWN),
	PINK(4, "pink", MapColor.PINK),
	YELLOW(5, "yellow", MapColor.YELLOW),
	GREEN(6, "green", MapColor.GREEN);

	private static final EnumMarble[] META_LOOKUP = new EnumMarble[values().length];
	private final int meta;
    private final String name;
    private final MapColor mapColor;
	
    private EnumMarble(int metaIn, String nameIn, MapColor mapColorIn)
    {
        this.meta = metaIn;
        this.name = nameIn;
        this.mapColor = mapColorIn;
    }
    
    static
    {
        for (EnumMarble value : values())
        {
            META_LOOKUP[value.getMetadata()] = value;
        }
    }
    
    public static EnumMarble byMetadata(int meta)
    {
        if (meta < 0 || meta >= META_LOOKUP.length)
        {
            meta = 0;
        }

        return META_LOOKUP[meta];
    }
    
	@Override
	public String getName() {
		return this.name;
	}

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

	public MapColor getMapColor() {
		return this.mapColor;
	}

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

 I looked at the vanilla code for planks but i can't find any difference that makes the variant incorrect

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

Posted

I use that base class just for blocks that don't have any particular feature (like ores, mineral blocks or colored blocks) :) Anyway i changed the registration part to "color=white" instead of just white and it worked. Except it isn't for slabs, wich i did the same thing. It says it can't found a variant for slab#color=yellow but in the model registration i specified the variant like the normal block ("color=yellow"). In this case the error could be in the json file? Here's the one i'm using

 

{
    "forge_marker": 1,
    "variants": {
        "normal": [{

        }],
        "inventory": [{

        }],
        "half": {
            "top": {
                "model": "upper_slab"
            },
            "bottom": {
                "model": "half_slab"
            }
        },
        "color": {
            "white":  { "textures": { "bottom": "mineworld:blocks/marble_white", 
                "side": "mineworld:blocks/marble_white", 
                "top": "mineworld:blocks/marble_white"

            } },
            "black":  { "textures": { "bottom": "mineworld:blocks/marble_black", 
                "side": "mineworld:blocks/marble_black", 
                "top": "mineworld:blocks/marble_black"

            } },
            "red":  { "textures": { "bottom": "mineworld:blocks/marble_red", 
                "side": "mineworld:blocks/marble_red", 
                "top": "mineworld:blocks/marble_red"

            } },
            "brown":  { "textures": { "bottom": "mineworld:blocks/marble_brown", 
                "side": "mineworld:blocks/marble_brown", 
                "top": "mineworld:blocks/marble_brown"

            } },
            "pink":  { "textures": { "bottom": "mineworld:blocks/marble_pink", 
                "side": "mineworld:blocks/marble_pink", 
                "top": "mineworld:blocks/marble_pink"

            } },
            "yellow":  { "textures": { "bottom": "mineworld:blocks/marble_yellow", 
                "side": "mineworld:blocks/marble_yellow", 
                "top": "mineworld:blocks/marble_yellow"

            } },
            "green":  { "textures": { "bottom": "mineworld:blocks/marble_green", 
                "side": "mineworld:blocks/marble_green", 
                "top": "mineworld:blocks/marble_green"

            } }
        }
    }
}

 

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

Posted

Maybe there's an issue on how i register it? I use this method to register the slab

 

public static <E extends Enum<?>> void registerMetadataBlockModel(Block block, String variantName, Class<E> variants) {
		for(int i = 0; i < variants.getEnumConstants().length; i++) {
			ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), i, new ModelResourceLocation(block.getRegistryName(),  variantName + "=" + variants.getEnumConstants()[i].name()));
		}
	}

And from the model registry event i call it like this
 

BlockUtils.registerMetadataBlockModel(MARBLE_SLAB, "color", EnumMarble.class);
BlockUtils.registerMetadataBlockModel(MARBLE_DOUBLE_SLAB, "color", EnumMarble.class);

 

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

Posted

But this method works for the normal colored blocks... By the way i changed it to get the lower case name of the enum value, but still got no inventory texture :/ 

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

Posted (edited)

The json hasn't changed, but i post it again so there's everything in one place. This is the method i use to register a block with variants. It takes the block itself, the variant name and the enum class corresponding to the variant values

 

Spoiler

public static <E extends Enum<?>> void registerMetadataBlockModel(Block block, String variantName, Class<E> variants) {
        for(int i = 0; i < variants.getEnumConstants().length; i++) {
            ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), i, new ModelResourceLocation(block.getRegistryName(),  variantName + "=" + variants.getEnumConstants().name().toLowerCase()));
        }
    }

 

The enum i'm using to give the slab a variant is this

 

Spoiler

package com.mineworld.block.enums;

import com.mineworld.block.BlockMarble;

import net.minecraft.block.material.MapColor;
import net.minecraft.util.IStringSerializable;

public enum EnumOre implements IStringSerializable {
    RUBY(0, "ruby", MapColor.RED, 2, 0),
    SAPPHIRE(1, "sapphire", MapColor.BLUE, 2, 0),
    COPPER(2, "copper", MapColor.TNT, 1, 10),
    BRONZE(3, "bronze", MapColor.BROWN, 1, 5),
    SILVER(4, "silver", MapColor.LIGHT_BLUE, 1, 0),
    ALUMINIUM(5, "aluminium", MapColor.SILVER, 1, 0),
    PYRITE(6, "pyrite", MapColor.YELLOW, 0, 0);

    private static final EnumOre[] META_LOOKUP = new EnumOre[values().length];
    private final int meta;
    private final String name;
    private final MapColor mapColor;
    private final int harvestLevel;
    private final int powerLevel;
    
    private EnumOre(int metaIn, String nameIn, MapColor mapColorIn, int harvestLevel, int powerLevel)
    {
        this.meta = metaIn;
        this.name = nameIn;
        this.mapColor = mapColorIn;
        this.harvestLevel = harvestLevel;
        this.powerLevel = powerLevel;
    }
    
    static
    {
        for (EnumOre value : values())
        {
            META_LOOKUP[value.getMetadata()] = value;
        }
    }
    
    public static EnumOre byMetadata(int meta)
    {
        if (meta < 0 || meta >= META_LOOKUP.length)
        {
            meta = 0;
        }

        return META_LOOKUP[meta];
    }
    
    @Override
    public String getName() {
        return this.name;
    }

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

    public MapColor getMapColor() {
        return this.mapColor;
    }
    
    public int getHarvestLevel() {
        return this.harvestLevel;
    }
    
    public int getPowerLevel() {
        return this.powerLevel;
    }

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

 

and this is the slab base class 

 

Spoiler

package com.mineworld.block.slab;

import java.util.Arrays;
import java.util.Random;

import javax.annotation.Nullable;

import com.google.common.base.Predicate;
import com.mineworld.block.enums.EnumMarble;
import com.mineworld.core.MWBlocks;
import com.mineworld.core.MWTabs;
import com.mineworld.settings.ModSettings;

import net.minecraft.block.BlockSlab;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.MapColor;
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.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public abstract class BlockMarbleSlab extends BlockSlab
{
    public static final PropertyEnum<EnumMarble> COLOR = PropertyEnum.<EnumMarble>create("color", EnumMarble.class);

    public BlockMarbleSlab(String name)
    {
        super(Material.ROCK);
        setUnlocalizedName(ModSettings.MODID + "." + name);
        setRegistryName(name);
        setSoundType(SoundType.METAL);
        IBlockState iblockstate = this.blockState.getBaseState();

        if (!this.isDouble())
        {
            iblockstate = iblockstate.withProperty(HALF, BlockSlab.EnumBlockHalf.BOTTOM);
        }

        this.setDefaultState(iblockstate.withProperty(COLOR, EnumMarble.WHITE));
        this.setCreativeTab(MWTabs.BUILDING_BLOCKS);
        this.setHardness(1.5F);
        this.setResistance(10.0F);
    }

    /**
     * Get the MapColor for this Block and the given BlockState
     */
    public MapColor getMapColor(IBlockState state, IBlockAccess worldIn, BlockPos pos)
    {
        return ((EnumMarble)state.getValue(COLOR)).getMapColor();
    }

    /**
     * Get the Item that this Block should drop when harvested.
     */
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
    {
        return Item.getItemFromBlock(MWBlocks.MARBLE_SLAB);
    }

    public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
    {
        return new ItemStack(MWBlocks.MARBLE_SLAB, 1, ((EnumMarble)state.getValue(COLOR)).getMetadata());
    }

    /**
     * Returns the slab block name with the type associated with it
     */
    public String getUnlocalizedName(int meta)
    {
        return super.getUnlocalizedName() + "." + EnumMarble.byMetadata(meta).getName();
    }

    public IProperty<?> getVariantProperty()
    {
        return COLOR;
    }

    public Comparable<?> getTypeForItem(ItemStack stack)
    {
        return EnumMarble.byMetadata(stack.getMetadata() & 7);
    }

    /**
     * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
     */
    public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items)
    {
        for(EnumMarble ore : COLOR.getAllowedValues()) {
            items.add(new ItemStack(this, 1, ore.getMetadata()));
        }
    }

    /**
     * Convert the given metadata into a BlockState for this Block
     */
    public IBlockState getStateFromMeta(int meta)
    {
        IBlockState iblockstate = this.getDefaultState().withProperty(COLOR, EnumMarble.byMetadata(meta & 7));

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

        return iblockstate;
    }

    /**
     * Convert the BlockState into the correct metadata value
     */
    public int getMetaFromState(IBlockState state)
    {
        int i = 0;
        i = i | ((EnumMarble)state.getValue(COLOR)).getMetadata();

        if (!this.isDouble() && state.getValue(HALF) == BlockSlab.EnumBlockHalf.TOP)
        {
            i |= 8;
        }

        return i;
    }

    protected BlockStateContainer createBlockState()
    {
        return this.isDouble() ? new BlockStateContainer(this, new IProperty[] {COLOR}) : new BlockStateContainer(this, new IProperty[] {HALF, COLOR});
    }

    /**
     * Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
     * returns the metadata of the dropped item based on the old metadata of the block.
     */
    public int damageDropped(IBlockState state)
    {
        return ((EnumMarble)state.getValue(COLOR)).getMetadata();
    }
}

 

In the register block event i register the half slab and the double slab block like this

 

Spoiler

event.getRegistry().registerAll(new BlockHalfMarbleSlab("marble_slab"),
                new BlockDoubleMarbleSlab("marble_double_slab"))

 

As well as the item block in the register item event

 

Spoiler

event.getRegistry().registerAll(new ItemSlab(MARBLE_SLAB, MARBLE_SLAB, MARBLE_DOUBLE_SLAB).setRegistryName(MARBLE_SLAB.getRegistryName()))

 

And finally i register the model using the ModelRegistryEvent like this

 

Spoiler

registerMetadataBlockModel(MARBLE_SLAB, "color", EnumMarble.class);
registerMetadataBlockModel(MARBLE_DOUBLE_SLAB, "color", EnumMarble.class);

 

The blockstates json file i use for the half slab is this

 

Spoiler

{
    "forge_marker": 1,
    "variants": {
        "normal": [{

        }],
        "inventory": [{

        }],
        "half": {
            "top": {
                "model": "upper_slab"
            },
            "bottom": {
                "model": "half_slab"
            }
        },
        "color": {
            "white":  { "textures": { "bottom": "mineworld:blocks/marble_white", 
                "side": "mineworld:blocks/marble_white", 
                "top": "mineworld:blocks/marble_white"

            } },
            "black":  { "textures": { "bottom": "mineworld:blocks/marble_black", 
                "side": "mineworld:blocks/marble_black", 
                "top": "mineworld:blocks/marble_black"

            } },
            "red":  { "textures": { "bottom": "mineworld:blocks/marble_red", 
                "side": "mineworld:blocks/marble_red", 
                "top": "mineworld:blocks/marble_red"

            } },
            "brown":  { "textures": { "bottom": "mineworld:blocks/marble_brown", 
                "side": "mineworld:blocks/marble_brown", 
                "top": "mineworld:blocks/marble_brown"

            } },
            "pink":  { "textures": { "bottom": "mineworld:blocks/marble_pink", 
                "side": "mineworld:blocks/marble_pink", 
                "top": "mineworld:blocks/marble_pink"

            } },
            "yellow":  { "textures": { "bottom": "mineworld:blocks/marble_yellow", 
                "side": "mineworld:blocks/marble_yellow", 
                "top": "mineworld:blocks/marble_yellow"

            } },
            "green":  { "textures": { "bottom": "mineworld:blocks/marble_green", 
                "side": "mineworld:blocks/marble_green", 
                "top": "mineworld:blocks/marble_green"

            } }
        }
    }
}

 

While for the double slab i use this json file

 

Spoiler

{
    "forge_marker": 1,
    "defaults": {
        "model": "cube_all"
    },
    "variants": {
        "normal": [{

        }],
        "inventory": [{

        }],
        "color": {
            "white":  { "textures": { "all": "mineworld:blocks/marble_white"
            } },
            "black":  { "textures": { "all": "mineworld:blocks/marble_black"
            } },
            "red":  { "textures": { "all": "mineworld:blocks/marble_red"
            } },
            "brown":  { "textures": { "all": "mineworld:blocks/marble_brown"
            } },
            "pink":  { "textures": { "all": "mineworld:blocks/marble_pink"
            } },
            "yellow":  { "textures": { "all": "mineworld:blocks/marble_yellow"
            } },
            "green":  { "textures": { "all": "mineworld:blocks/marble_green"
            } }
        }
    }
}

 

If i place the block on the ground it works fine, both for half slabs and double slabs, is just in inventory that i get no icon and model, just a plain black/purple texture

Edited by JimiIT92
Code lost from previous edit, fixed now

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

Posted

Update: so, after spending some time trying to figure out the arcane i did it. Reading the old messages i thought about the "variant=something" thing and i remembered that when you have multiple properties, the blockstate is something like "property1=value1,property2=value2". And so i tried using the "half=bottom,color=white" to register the white slab and it worked! I now have a proper icon displaying in the inventory :D Thanks everyone for your help :)

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

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.