Jump to content

Recommended Posts

Posted

I created a block to update the color based on the rgb input of the player. I've managed to create the tile entity and implement the IBlockColor and IItemColor for the block. However, the in-game block model doesn't update. I know that the code is working somewhat because the block's particles change color.

 

Color Handler within postInit:

Minecraft.getMinecraft().getBlockColors().registerBlockColorHandler(new IBlockColor() {	
	@Override
	public int colorMultiplier(IBlockState state, IBlockAccess worldIn, BlockPos pos, int tintIndex) {
		TileEntitySingleColor te = (TileEntitySingleColor)worldIn.getTileEntity(pos);
		return te.hex();
	}
}, CustomBlocks.single_color);
final IItemColor item_color = (stack, tintIndex) -> {
	IBlockState iblockstate = ((ItemBlock) stack.getItem()).getBlock().getDefaultState();
	return Minecraft.getMinecraft().getBlockColors().colorMultiplier(iblockstate, null, null, tintIndex);
};
Minecraft.getMinecraft().getItemColors().registerItemColorHandler(item_color, CustomBlocks.single_color);

 

Simplified version of onBlockActivated (Test purposes):

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing heldItem, float side, float hitX, float hitY) {
	TileEntitySingleColor color = (TileEntitySingleColor)worldIn.getTileEntity(pos);
	color.setRgb(255, 0, 0);
	color.getWorld().notifyBlockUpdate(pos, state, state, 0);
	return true;
}

 

Can anyone please help me figure out what I'm doing incorrectly? Thank you.

 

 

Posted
  On 1/28/2018 at 12:37 PM, diesieben07 said:

You must set the color on the server only and then synchronize it to the client from within the tile entity appropriately.

Expand  

This is my tile entity class. I'm pretty sure it synchronizing with the client because debug I ran has both values as the same during the read and write. Also, as I mentioned previously, the particles do change color which I can only assume is from the client. The only thing that doesn't change color is the actual block. I apologize if I'm misunderstanding what you meant.

 

public class TileEntitySingleColor extends TileEntity implements ITickable{
	
	private int red = 0, green = 0, blue = 0;
	
	@Override
	public NBTTagCompound writeToNBT(NBTTagCompound compound) {
		super.writeToNBT(compound);
		compound.setInteger("red", this.red);
		compound.setInteger("green", this.green);
		compound.setInteger("blue", this.blue);
		return compound;
	}
	
	@Override
	public void readFromNBT(NBTTagCompound compound) {
		super.readFromNBT(compound);
		this.red = compound.getInteger("red");
		this.green = compound.getInteger("green");
		this.blue = compound.getInteger("blue");
	}
	
	@Override
	public NBTTagCompound getUpdateTag() {
		return this.writeToNBT(new NBTTagCompound());
	}
	
	@Override
	public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
		this.readFromNBT(pkt.getNbtCompound());
	}
	
	@Override
	public SPacketUpdateTileEntity getUpdatePacket() {
		return new SPacketUpdateTileEntity(this.pos, 0, this.getUpdateTag());
	}
	
	public void setRgb(int red, int green, int blue) {
		this.red = red;
		this.green = green;
		this.blue = blue;
	}
	
	public int[] rgb() {
		return new int[] {this.red, this.green, this.blue};
	}
	
	public int hex() {
		return ((red&0x0ff)<<16)|((green&0x0ff)<<8)|(blue&0x0ff);
	}

	@Override
	public void update() {
		
	}
}

 

Posted

Why do you implement ITickable? Is there a reason to make your TE tick?

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.

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

    • If you're in Austria and trying the Temu app for the first time, this exclusive deal is for you. New users can apply the Temu discount code [alb232118] to instantly receive a €100 Temu coupon code bundle and a generous 30% discount on their first order over €10. This welcome offer is only valid for first-time users who complete their purchase within one hour of installing the Temu mobile app. Using this Temu promo code, you'll unlock a maximum discount of €30. The coupons are applied automatically once you register a new account through the app. Please note that this promotion is only available via the mobile version of Temu and cannot be used on desktop browsers. If you've already created a Temu account in the past, this offer won't apply. But for new users in Austria, this is the perfect way to start shopping and saving right away. Download the Temu app, enter the Temu discount code [alb232118], and enjoy massive savings with verified Temu coupon code rewards in Austria.      
    • New to Temu and located in Australia? Here's your chance to claim an exclusive welcome deal. By using the Temu discount code [alb232118], first-time users of the Temu mobile app can receive an AU$100 Temu coupon code package and enjoy an instant 30% off on their first purchase over AU$20. This offer is valid only for new users who make a qualifying purchase within one hour of installing the app. The Temu promo code [alb232118] grants a maximum discount of AU$30 and works automatically at checkout. The coupons are activated as soon as you sign up with a new account through the Temu mobile app. Note that this promotion is not available on desktop and is strictly for mobile use. If you’ve registered with Temu before, this offer won’t apply. But if you're a brand-new user in Australia, this is a smart way to start saving on your first shopping experience. Download the app today, apply the Temu discount code [alb232118], and unlock your AU$100 in coupons with extra savings thanks to this verified Temu coupon code.  
    • There are client-side-only mods in your server's mods folder DayCount is mentioned Start with removing this mod from your server - if this is still crashing, add the new crash-report  
    • hi, i cant start server on aternos bc this crash i poping out, im not a programist so for me its just a lot of words. anyone cna help me out? we just wanted to play mc on mods with da boys! crash report here: https://mclo.gs/pOtNvCQ  
    • Hi Everyone, I'm FlamingPigman! About 12 years ago I developed a mod called the Power Gems Mod, which added 7 new ores to the game and added some more uses for Lapis Lazuli. Each new ore is tied to a special power with an associated armor set and tools + a special weapon/tool and a special effect when you have a full armor set! I'm currently working on creating versions that can run on some of the more popular MC versions. If this sounds like a mod that interests you, check it out here: https://www.curseforge.com/minecraft/mc-mods/power-gems-mod Appreciate the support folks!
  • Topics

×
×
  • Create New...

Important Information

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