Jump to content

[1.12.2] How could I color a block according to r, g, b & a values?


lyghtningwither

Recommended Posts

I am a precisionist. I must have everything colored the right way. So that's why I created the RGB block: for people like me who aren't satisfied with Minecraft's 14 or so default colors and want to be able to have all 4,294,967,296 possible RGBA colors. But I've run into a big problem. I can't figure out how to color it. It is, by default, black. I am using a TileEntitySpecialRenderer. I know my tile entity's R, G, B & A values are being set (I printed them out to the console). The way they are set is kind of like a sign, as when you place it a screen pops up prompting you to enter in the RGBA values. Then the TESR takes those values in, binds a white texture, renders the model, and calls GLStateManager.color, using the TileEntityRgb's R, G, B & A values divided by 255 (as they're 0-255), and then calls pop matrix and all that stuff. But for some reason, it's still only placing black. The lighting and everything is working, it just isn't setting the correct texture. Attached is a screenshot of a block that should've been a transparent, light blue.

Here is my code for the TESR:

private static final ResourceLocation TEXTURE = new ResourceLocation(Reference.MOD_ID + ":textures/blocks/rgb.png");
	private final ModelRgbBlock MODEL = new ModelRgbBlock();
	
	@Override
	public void render(TileEntityRgb te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
		
		GlStateManager.enableDepth();
        GlStateManager.depthFunc(515);
        GlStateManager.depthMask(true);
    	
    	ModelRgbBlock model = MODEL;
    	
    	if (destroyStage >= 0) {
    		
            this.bindTexture(DESTROY_STAGES[destroyStage]);
            GlStateManager.matrixMode(5890);
            GlStateManager.pushMatrix();
            GlStateManager.scale(4.0F, 4.0F, 1.0F);
            GlStateManager.translate(0.0625F, 0.0625F, 0.0625F);
            GlStateManager.matrixMode(5888);
        } else this.bindTexture(TEXTURE);
    	
    	GlStateManager.pushMatrix();
        GlStateManager.enableRescaleNormal();
        GlStateManager.translate((float)x, (float)y + 1.0F, (float)z + 1.0F);
        GlStateManager.scale(1.0F, -1.0F, -1.0F);
        GlStateManager.translate(0.5F, 0.5F, 0.5F);
        GlStateManager.translate(-0.5F, -0.5F, -0.5F);
       
        model.renderAll();
        GlStateManager.color(te.r / 255, te.g / 255, te.b / 255, te.a / 255);
        GlStateManager.disableRescaleNormal();
        GlStateManager.popMatrix();

        if (destroyStage >= 0) {
        	
            GlStateManager.matrixMode(5890);
            GlStateManager.popMatrix();
            GlStateManager.matrixMode(5888);
        

By the way, renderAll() is just a function that renders without the need for entity variables and all that stuff that isn't needed just to render a cube.

I don't know what's going on with this code, so please, if you could, point me in the right direction on what I need to do. Thanks in advance!

2018-12-26_17.38.38.png

I like programming. I also have a lot of problems with programming. So I came here on this forum so that I could get my problems solved.

 

Thank you to everyone who has helped me on the forum! You will be appreciated.

Link to comment
Share on other sites

Are your RGB values actually being synced to the client? I suspect that they're always 0 on the client, so the block is being rendered black.

 

There's no need for a TESR here at all. If you register a standard JSON model with a tint index (see the wiki), you can then register an IBlockColor that reads the RGB value from the TileEntity and returns it.

Edited by Choonster

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.

Link to comment
Share on other sites

Huh. I never even knew there was a tint thingy. I want to stick to the TESR, though, as I eventually want you to be able to apply custom textures and rotations and stuff like that. How would I update this on the client side?

I like programming. I also have a lot of problems with programming. So I came here on this forum so that I could get my problems solved.

 

Thank you to everyone who has helped me on the forum! You will be appreciated.

Link to comment
Share on other sites

2 hours ago, lyghtningwither said:

Huh. I never even knew there was a tint thingy. I want to stick to the TESR, though, as I eventually want you to be able to apply custom textures and rotations and stuff like that. How would I update this on the client side?

 

See the Forge documentation.

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.

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
    • It is an issue with quark - update it to this build: https://www.curseforge.com/minecraft/mc-mods/quark/files/3642325
    • Remove Instant Massive Structures Mod from your server     Add new crash-reports with sites like https://paste.ee/  
    • Update your drivers: https://www.amd.com/en/support/graphics/amd-radeon-r9-series/amd-radeon-r9-200-series/amd-radeon-r9-280x
  • Topics

×
×
  • Create New...

Important Information

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