Jump to content

[SOLVED] [1.8.9] Wrong texture variant when placing log horizontally


Recommended Posts

Posted

I'm trying to create custom logs. The overall goal is that if you sneak while breaking a log, it drops bark and gets replaced with a stripped log. I've created a custom block class for the properties and a corresponding item class. I have two variants so far, oak and birch. Everything is working fine, except that when I place the stripped oak horizontally, it uses the birch texture instead. Any idea what's going on?

 

My custom log block class:

 

public class PrimalBlockLog extends BlockLog {

    public static final PropertyEnum VARIANT = PropertyEnum.create("variant", PrimalBlockLog.EnumWoodType.class, new Predicate()
    {
        public boolean apply(PrimalBlockLog.EnumWoodType type)
        {
            return type.getMetadata() < 4;
        }
        public boolean apply(Object p_apply_1_)
        {
            return this.apply((PrimalBlockLog.EnumWoodType)p_apply_1_);
        }
    });

    public PrimalBlockLog()
    {
        this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, PrimalBlockLog.EnumWoodType.STRIPPEDOAK).withProperty(LOG_AXIS, BlockLog.EnumAxis.Y));
        setHardness(2.0F);
    	setResistance(0.5F);
    	//setStepSound(Block.soundTypeWood);
	this.setCreativeTab(PrimalCreativeTabs.tabPrimalcraft);
    }
    
    @SideOnly(Side.CLIENT)
    public void getSubBlocks(Item block, CreativeTabs tab, List list) {
        list.add(new ItemStack(block, 1, PrimalBlockLog.EnumWoodType.STRIPPEDOAK.getMetadata()));
        list.add(new ItemStack(block, 1, PrimalBlockLog.EnumWoodType.STRIPPEDBIRCH.getMetadata()));
    }

    /**
     * Convert the given metadata into a BlockState for this Block
     */
    public IBlockState getStateFromMeta(int meta)
    {
        IBlockState iblockstate = this.getDefaultState().withProperty(VARIANT, PrimalBlockLog.EnumWoodType.byMetadata((meta & 3) % 4));

        switch (meta & 12)
        {
            case 0:
                iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.Y);
                break;
            case 4:
                iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.X);
                break;
            case 8:
                iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.Z);
                break;
            default:
                iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.NONE);
        }

        return iblockstate;
    }

    /**
     * Convert the BlockState into the correct metadata value
     */
    public int getMetaFromState(IBlockState state)
    {
        byte b0 = 0;
        int i = b0 | ((PrimalBlockLog.EnumWoodType)state.getValue(VARIANT)).getMetadata();
    	
        switch (PrimalBlockLog.SwitchEnumAxis.AXIS_LOOKUP[((PrimalBlockLog.EnumAxis)state.getValue(LOG_AXIS)).ordinal()])
        {
            case 1:
                i = 4;
                break;
            case 2:
                i = 8;
                break;
            case 3:
                i = 12;
        }

        return i;
    }

    @Override
    protected BlockState createBlockState()
    {
        return new BlockState(this, new IProperty[] {VARIANT, LOG_AXIS});
    }

    protected ItemStack createStackedBlock(IBlockState state)
    {
        return new ItemStack(Item.getItemFromBlock(this), 1, ((PrimalBlockLog.EnumWoodType)state.getValue(VARIANT)).getMetadata());
    }

    /**
     * Get the damage value that this Block should drop
     */
    public int damageDropped(IBlockState state)
    {
        return ((PrimalBlockLog.EnumWoodType)state.getValue(VARIANT)).getMetadata();
    }

    static final class SwitchEnumAxis
        {
            static final int[] AXIS_LOOKUP = new int[blockLog.EnumAxis.values().length];

            static
            {
                try
                {
                    AXIS_LOOKUP[blockLog.EnumAxis.X.ordinal()] = 1;
                }
                catch (NoSuchFieldError var3)
                {
                    ;
                }

                try
                {
                    AXIS_LOOKUP[blockLog.EnumAxis.Z.ordinal()] = 2;
                }
                catch (NoSuchFieldError var2)
                {
                    ;
                }

                try
                {
                    AXIS_LOOKUP[blockLog.EnumAxis.NONE.ordinal()] = 3;
                }
                catch (NoSuchFieldError var1)
                {
                    ;
                }
            }
        }
    
    public static enum EnumWoodType implements IStringSerializable {
    	
        STRIPPEDOAK(0, "log_oak_stripped"),
        STRIPPEDBIRCH(1, "log_birch_stripped");
    	
        private static final PrimalBlockLog.EnumWoodType[] META_LOOKUP = new PrimalBlockLog.EnumWoodType[values().length];

        private final int meta;
        private final String name;
        private final String unlocalizedName;
        
        private EnumWoodType(int meta, String name) {
            this(meta, name, name);
        }

        private EnumWoodType(int meta, String name, String unlocalizedName) {
            this.meta = meta;
            this.name = name;
            this.unlocalizedName = unlocalizedName;
        }
       
        public int getMetadata() {
            return this.meta;
        }
        
        public String toString() {
        	return getName();
        }
       
        public static PrimalBlockLog.EnumWoodType byMetadata(int meta)
        {
            if (meta < 0 || meta >= META_LOOKUP.length) {
                meta = 0;
            }
            return META_LOOKUP[meta];
        }

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

        public String getUnlocalizedName() {
            return this.unlocalizedName;
        }
        
        static
        {
        	PrimalBlockLog.EnumWoodType[] var0 = values();
            int var1 = var0.length;

            for (int var2 = 0; var2 < var1; ++var2)
            {
            	PrimalBlockLog.EnumWoodType var3 = var0[var2];
                META_LOOKUP[var3.getMetadata()] = var3;
            }
        }

    }
    
}

 

My log item class:

 

public class PrimalItemLog extends ItemBlock {

private final static String[] subNames = {
		"log_oak_stripped", "log_birch_stripped"
	};

	public PrimalItemLog(Block id) {
		super(id);
		setHasSubtypes(true);
	}

	@Override
	public int getMetadata (int damageValue) {
		return damageValue;
	}

	@Override
	public String getUnlocalizedName(ItemStack itemstack) {
		return "tile.log_" + subNames[itemstack.getItemDamage()] ;
	}

}

 

The block register class:

 

public class BlockRenderRegister {

public static String modid = Main.MODID;
static RenderItem renderItem = Minecraft.getMinecraft().getRenderItem();

public static void registerBlockRenderer() {

	reg(PrimalBlockRegistry.log_stripped, 0, "log_oak_stripped");
	reg(PrimalBlockRegistry.log_stripped, 1, "log_birch_stripped");

}

public static ModelResourceLocation resloc(String name) {
	return new ModelResourceLocation(modid + ":" + name, "inventory");
}

public static void preInit() {
	ModelBakery.registerItemVariants(Item.getItemFromBlock(PrimalBlockRegistry.log_stripped), resloc("log_oak_stripped"), resloc("log_birch_stripped"));
}

public static void reg(Block block, String name) {
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(block), 0, resloc(name));
}

public static void reg(Block block, int meta, String name) {
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(block), meta, resloc(name));
}

}

 

JSON files for stripped oak variant:

 

 

Blockstates:

{
    "variants": {
        "axis=y,variant=log_oak_stripped":    { "model": "primalcraft:log_oak_stripped" },
        "axis=z,variant=log_oak_stripped":     { "model": "primalcraft:log_oak_stripped_side" },
        "axis=x,variant=log_oak_stripped":     { "model": "primalcraft:log_oak_stripped_side", "y": 90 },
        "axis=none,variant=log_oak_stripped":   { "model": "primalcraft:log_oak_stripped_bare" },
        "axis=y,variant=log_birch_stripped":    { "model": "primalcraft:log_birch_stripped" },
        "axis=z,variant=log_birch_stripped":     { "model": "primalcraft:log_birch_stripped_side" },
        "axis=x,variant=log_birch_stripped":     { "model": "primalcraft:log_birch_stripped_side", "y": 90 },
        "axis=none,variant=log_birch_stripped":   { "model": "primalcraft:log_birch_stripped_bare" }
    }
}

Column:

{
    "parent": "block/cube_column",
    "textures": {
        "end": "primalcraft:blocks/log_oak_stripped_top",
        "side": "primalcraft:blocks/log_oak_stripped"
    }
}

Side column:

{
    "parent": "block/column_side",
    "textures": {
        "end": "primalcraft:blocks/log_oak_stripped_top",
        "side": "primalcraft:blocks/log_oak_stripped"
    }
}

Bark (I'm calling it "bare"):

{
    "parent": "block/cube_all",
    "textures": {
        "all": "primalcraft:blocks/log_oak_stripped"
    }
}

Item model:

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

 

 

Posted

Your getMetaFromState is fucked up.

 

 int i = b0 | ((PrimalBlockLog.EnumWoodType)state.getValue(VARIANT)).getMetadata();

 

Well, b0 was already 0, so I don't see what the point was.

 

            case 1:
                i = 4;
                break;

 

You know what, fuck it, just overwrite the value, we didn't need it.

 

Not actually a problem, but in your getStateFromMeta:

 

((meta & 3) % 4))

 

(meta & 3) already returns a value, [0-3] so why the %4?

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

Well, that was dumb of me. New getMetaFromState:

 

   public int getMetaFromState(IBlockState state)
    {
        int i = 0;
        i = i | ((PrimalBlockStrippedLog.EnumWoodType)state.getValue(VARIANT)).getMetadata();
    	
        switch (PrimalBlockStrippedLog.SwitchEnumAxis.AXIS_LOOKUP[((PrimalBlockStrippedLog.EnumAxis)state.getValue(LOG_AXIS)).ordinal()])
        {
            case 1:
                i |= 4;
                break;
            case 2:
                i |= 8;
                break;
            case 3:
                i |= 12;
        }

        return i;
    }

 

Seems to be working great so far. Thanks for the tip.

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.