Jump to content

[1.8] Strange color issues with custom leaves (SOLVED)


brsgamer

Recommended Posts

I'm updating my mod and I have a strange issue. I have 11 types of leaves. I finally got the coloring to work on placed block, but I noticed that leaves are not transparent,colors are little bit off and also they aren't colored in inventory(water level is another mod):

dQMmITC.png

Why is this happening? Here's my leaf class:

package com.lessoner.treeores.trees;

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

import net.minecraft.block.Block;
import net.minecraft.block.BlockLeaves;
import net.minecraft.block.BlockPlanks;
import net.minecraft.block.BlockPlanks.EnumType;
import net.minecraft.block.properties.IProperty;
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.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.world.ColorizerFoliage;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import com.google.common.base.Predicate;
import com.lessoner.treeores.TreeOresBlocks;

public class TreeOresLeaf1 extends BlockLeaves {

public static final PropertyEnum VARIANT = PropertyEnum.create("variant", TreeOresLog1.EnumType.class, new Predicate() {
	public boolean apply(TreeOresLog1.EnumType type) {
		return type.getMetadata() < 4;
	}

	public boolean apply(Object p_apply_1_) {
		return this.apply((TreeOresLog1.EnumType) p_apply_1_);
	}
});

public TreeOresLeaf1() {
	this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, TreeOresLog1.EnumType.IRON)
			.withProperty(CHECK_DECAY, Boolean.valueOf(true)).withProperty(DECAYABLE, Boolean.valueOf(true)));
}

public Item getItemDropped(IBlockState state, Random rand, int fortune) {

		return Item.getItemFromBlock(TreeOresBlocks.Saplings1);

}

@SideOnly(Side.CLIENT)
public int getRenderColor(IBlockState state) {
	if (state.getBlock() != this) {
		return super.getRenderColor(state);
	} else {
		TreeOresLog1.EnumType enumtype = (TreeOresLog1.EnumType) state.getValue(VARIANT);
		return enumtype == TreeOresLog1.EnumType.GOLD ? LeaveColours.gold() : (enumtype == TreeOresLog1.EnumType.COAL ? LeaveColours.coal()
				: (enumtype == TreeOresLog1.EnumType.IRON ? LeaveColours.iron() : (enumtype == TreeOresLog1.EnumType.REDSTONE ? LeaveColours
						.redstone() : super.getRenderColor(state))));
	}
}

@SideOnly(Side.CLIENT)
public int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass) {
	IBlockState iblockstate = worldIn.getBlockState(pos);

	if (iblockstate.getBlock() == this) {
		TreeOresLog1.EnumType enumtype = (TreeOresLog1.EnumType) iblockstate.getValue(VARIANT);

		if (enumtype == TreeOresLog1.EnumType.IRON) {
			return LeaveColours.iron();
		}

		if (enumtype == TreeOresLog1.EnumType.GOLD) {
			return LeaveColours.gold();
		}
		if (enumtype == TreeOresLog1.EnumType.COAL) {
			return LeaveColours.coal();
		}

		if (enumtype == TreeOresLog1.EnumType.REDSTONE) {
			return LeaveColours.redstone();
		}
	}

	return super.colorMultiplier(worldIn, pos, renderPass);
}

protected void dropApple(World worldIn, BlockPos pos, IBlockState state, int chance) {
	if (state.getValue(VARIANT) == TreeOresLog1.EnumType.IRON && worldIn.rand.nextInt(chance) == 0) {
		spawnAsEntity(worldIn, pos, new ItemStack(Items.iron_ingot, 1, 0));
	}
	if (state.getValue(VARIANT) == TreeOresLog1.EnumType.GOLD && worldIn.rand.nextInt(chance) == 0) {
		spawnAsEntity(worldIn, pos, new ItemStack(Items.gold_ingot, 1, 0));
	}
	if (state.getValue(VARIANT) == TreeOresLog1.EnumType.COAL && worldIn.rand.nextInt(chance) == 0) {
		spawnAsEntity(worldIn, pos, new ItemStack(Items.coal, 1, 0));
	}
	if (state.getValue(VARIANT) == TreeOresLog1.EnumType.REDSTONE && worldIn.rand.nextInt(chance) == 0) {
		spawnAsEntity(worldIn, pos, new ItemStack(Items.redstone, 1, 0));
	}
}

protected int getSaplingDropChance(IBlockState state) {
	return state.getValue(VARIANT) == TreeOresLog1.EnumType.REDSTONE ? 40 : super.getSaplingDropChance(state);
}

@SideOnly(Side.CLIENT)
public void getSubBlocks(Item itemIn, CreativeTabs tab, List list) {
	list.add(new ItemStack(itemIn, 1, TreeOresLog1.EnumType.IRON.getMetadata()));
	list.add(new ItemStack(itemIn, 1, TreeOresLog1.EnumType.GOLD.getMetadata()));
	list.add(new ItemStack(itemIn, 1, TreeOresLog1.EnumType.COAL.getMetadata()));
	list.add(new ItemStack(itemIn, 1, TreeOresLog1.EnumType.REDSTONE.getMetadata()));
}

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

public IBlockState getStateFromMeta(int meta) {
	return this.getDefaultState().withProperty(VARIANT, TreeOresLog1.EnumType.byMetadata((meta & 3) % 4))
			.withProperty(DECAYABLE, Boolean.valueOf((meta & 4) == 0)).withProperty(CHECK_DECAY, Boolean.valueOf((meta &  > 0));
}

public int getMetaFromState(IBlockState state) {
	byte b0 = 0;
	int i = b0 | ((TreeOresLog1.EnumType) state.getValue(VARIANT)).getMetadata();

	if (!((Boolean) state.getValue(DECAYABLE)).booleanValue()) {
		i |= 4;
	}

	if (((Boolean) state.getValue(CHECK_DECAY)).booleanValue()) {
		i |= 8;
	}

	return i;
}

protected BlockState createBlockState() {
	return new BlockState(this, new IProperty[] { VARIANT, CHECK_DECAY, DECAYABLE });
}

public int damageDropped(IBlockState state) {
	return ((TreeOresLog1.EnumType) state.getValue(VARIANT)).getMetadata();
}

public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te) {
	if (!worldIn.isRemote && player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == Items.shears) {
		player.triggerAchievement(StatList.mineBlockStatArray[block.getIdFromBlock(this)]);
		spawnAsEntity(worldIn, pos,
				new ItemStack(Item.getItemFromBlock(this), 1, ((TreeOresLog1.EnumType) state.getValue(VARIANT)).getMetadata()));
	} else {
		super.harvestBlock(worldIn, player, pos, state, te);
	}
}

@Override
public List<ItemStack> onSheared(ItemStack item, IBlockAccess world, BlockPos pos, int fortune) {
	IBlockState state = world.getBlockState(pos);
	return new java.util.ArrayList(
			java.util.Arrays.asList(new ItemStack(this, 1, ((TreeOresLog1.EnumType) state.getValue(VARIANT)).getMetadata())));
}

@Override
public EnumType getWoodType(int meta) {
	return null;
}
}

 

LeaveColours class just has 11 integers with rgb values. (this class just has 4 leaves)

 

Thanks in advance.

Link to comment
Share on other sites

I suggest - look at ItemLeaves.  You have created a custom ItemBlock corresponding to your Block, yeah?

 

This looks promising...

    @SideOnly(Side.CLIENT)

    public int getColorFromItemStack(ItemStack stack, int renderPass)

    {

        return this.leaves.getRenderColor(this.leaves.getStateFromMeta(stack.getMetadata()));

    }

 

-TGG

Link to comment
Share on other sites

  • 2 months later...

I suggest - look at ItemLeaves.  You have created a custom ItemBlock corresponding to your Block, yeah?

 

This looks promising...

    @SideOnly(Side.CLIENT)

    public int getColorFromItemStack(ItemStack stack, int renderPass)

    {

        return this.leaves.getRenderColor(this.leaves.getStateFromMeta(stack.getMetadata()));

    }

 

-TGG

 

how do i do that exactly?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • My journey with Wizard Web Recovery began with skepticism, as I had already been burned once. However, desperate times called for desperate measures. I reached out to them, and from the onset, their professionalism was evident. They took  time to understand my situation, reassured me of their expertise, and provided a detailed plan on how they intended to recover my lost Bitcoin. Wizard Web Recovery stands out for several reasons. Firstly, their team comprises highly skilled professionals who specialize in blockchain technology and cyber forensics. This expertise is crucial when dealing with the complexities of cryptocurrency theft. They explained every step of the process to me, ensuring I was well-informed and comfortable with their approach. Communication with Wizard Web Recovery was seamless. They maintained regular updates, keeping me in the loop about the progress they were making. This transparency was something I had not experienced with other firms I had contacted. It built my confidence in their ability to deliver on their promises. Another significant aspect of Wizard Web Recovery is its ethical approach. They operate with integrity, ensuring that every action they take is within legal boundaries. In a field rife with scams and false promises, their commitment to ethical practices is a breath of fresh air. They provided me with all necessary documentation and evidence of their progress, which further reassured me of their legitimacy. The actual recovery process was nothing short of impressive. Wizard Web Recovery used advanced techniques to trace the stolen Bitcoin through the blockchain. They were able to identify the wallets it had been transferred to and worked tirelessly to negotiate the return of my funds. The level of detail and precision they demonstrated was extraordinary. By the end of the process, Wizard Web Recovery had successfully recovered my lost Bitcoin. The relief and gratitude I felt were overwhelming. It was not just about the money but about restoring my faith in the possibility of justice and recovery in the cryptocurrency world. Wizard Web Recovery turned my nightmare into a success story. Their expertise, transparency, ethical approach, and relentless effort make them the best in the business. If you are in a similar situation, do not hesitate to reach out to them. They are proof that amidst the darkness of scams, there are still trustworthy experts dedicated to helping you recover your digital assets.  
    • My journey with Wizard Web Recovery began with skepticism, as I had already been burned once. However, desperate times called for desperate measures. I reached out to them, and from the onset, their professionalism was evident. They took  time to understand my situation, reassured me of their expertise, and provided a detailed plan on how they intended to recover my lost Bitcoin. Wizard Web Recovery stands out for several reasons. Firstly, their team comprises highly skilled professionals who specialize in blockchain technology and cyber forensics. This expertise is crucial when dealing with the complexities of cryptocurrency theft. They explained every step of the process to me, ensuring I was well-informed and comfortable with their approach. Communication with Wizard Web Recovery was seamless. They maintained regular updates, keeping me in the loop about the progress they were making. This transparency was something I had not experienced with other firms I had contacted. It built my confidence in their ability to deliver on their promises. Another significant aspect of Wizard Web Recovery is its ethical approach. They operate with integrity, ensuring that every action they take is within legal boundaries. In a field rife with scams and false promises, their commitment to ethical practices is a breath of fresh air. They provided me with all necessary documentation and evidence of their progress, which further reassured me of their legitimacy. The actual recovery process was nothing short of impressive. Wizard Web Recovery used advanced techniques to trace the stolen Bitcoin through the blockchain. They were able to identify the wallets it had been transferred to and worked tirelessly to negotiate the return of my funds. The level of detail and precision they demonstrated was extraordinary. By the end of the process, Wizard Web Recovery had successfully recovered my lost Bitcoin. The relief and gratitude I felt were overwhelming. It was not just about the money but about restoring my faith in the possibility of justice and recovery in the cryptocurrency world. Wizard Web Recovery turned my nightmare into a success story. Their expertise, transparency, ethical approach, and relentless effort make them the best in the business. If you are in a similar situation, do not hesitate to reach out to them. They are proof that amidst the darkness of scams, there are still trustworthy experts dedicated to helping you recover your digital assets.   Contact Below:   Mail - wizard webrecovery@ programmer . net
    • Well don't I feel dumb, thank you as always @TileEntity you're the GOAT
    • Here is my code: @Mod.EventBusSubscriber(modid = Mod.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT) public class PlayerRenderModifications { @SubscribeEvent public static void prePlayerRender(RenderPlayerEvent.Pre evt) { RenderSystem.setShaderColor(0.0F, 1.0F, 1.0F, 1.0F); } @SubscribeEvent public static void postPlayerRender(RenderPlayerEvent.Post evt) { RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); } } This code is supposed to tint the player blue, however it doesn't tint the player at all (yes i know it only runs in f5 mode or when rendering players in multiplayer). I had also done some testing and it seems if I remove "postPlayerRender" then it tints the player, and also tints everything else that renders after the player (like other entities, clouds, etc.)   If you need me to provide other information then go ahead and ask!
  • Topics

×
×
  • Create New...

Important Information

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