Jump to content

[1.8.9] Setting the texture color data for an IFlexibleBakedModel?


Recommended Posts

Posted

Hi,

I was wondering if it is possible to set the texture data of an instance of IFlexibleBakedModel. I searched around the forums for a bit and it would seem like this is something that can be done. What I'm attempting to do is take the texture data from a model, convert it to a sepia version (which is a brownish filter, see bit.ly/1ZOLgSt) and change the hue of the sepia texture to a light cyan. Basically, make a block look like a light blue version of that block. Reading some other forums (like this one bit.ly/1ZazR2w, I've managed to change the color, but I cannot figure out what indices of the model's vertex data to change to the appropriate RGB value. My code for what I'm doing is below. The issue is within the 'alterColor' method. And for what it's worth, it seems to change every model into a bright red, texture-less cube. Any information about vertex data or my issue would be much appreciated. Thanks!

 

public class FrozenBlockModelBuilder implements ISmartBlockModel
{
public static final ModelResourceLocation modelResourceLocation = new ModelResourceLocation(Reference.MODID + ":frozenBlock");
private IBakedModel currentBlockModel;

public FrozenBlockModelBuilder(IBakedModel defaultModel)
{
	this.currentBlockModel = defaultModel;
}

@Override
public IBakedModel handleBlockState(IBlockState state)
{
	this.currentBlockModel = I9Utils.getBlockModel(FrozenBlockRegistry.getFrozenState(state));
	return this;
}

@Override
public TextureAtlasSprite getTexture()
{
	return this.currentBlockModel.getTexture();
}

@Override
public List getFaceQuads(EnumFacing face)
{
	List<BakedQuad> quads = Lists.<BakedQuad>newArrayList();
	List<BakedQuad> faceQuads = this.currentBlockModel.getFaceQuads(face);

	for(BakedQuad bq : faceQuads)
	{
		quads.add(new BakedQuad(this.alterColor(bq.getVertexData()), 0, face));
	}

	return quads;
}

@Override
public List getGeneralQuads()
{
	List<BakedQuad> quads = Lists.<BakedQuad>newArrayList();
	List<BakedQuad> generalQuads = this.currentBlockModel.getGeneralQuads();

	for(BakedQuad bq : generalQuads)
	{
		quads.add(new BakedQuad(this.alterColor(bq.getVertexData()), 0, bq.getFace()));
	}

	return quads;
}

private int[] alterColor(int[] vd)
{
	int[] vertexData = Arrays.copyOf(vd, vd.length);
	int[] vc = this.sepiaizeWithHue(vertexData[3], vertexData[4], vertexData[5]);
	int[] vc2 = this.sepiaizeWithHue(vertexData[10], vertexData[11], vertexData[12]);
	int[] vc3 = this.sepiaizeWithHue(vertexData[17], vertexData[18], vertexData[19]);
	int[] vc4 = this.sepiaizeWithHue(vertexData[24], vertexData[25], vertexData[26]);

	/* THIS SECTION IS WHAT DOESN'T WORK */
	vertexData[3] = vc[0];
	vertexData[4] = vc[1];
	vertexData[5] = vc[2];
	vertexData[10] = vc2[0];
	vertexData[11] = vc2[1];
	vertexData[12] = vc2[2];
	vertexData[17] = vc3[0];
	vertexData[18] = vc3[1];
	vertexData[19] = vc3[2];
	vertexData[24] = vc4[0];
	vertexData[25] = vc4[1];
	vertexData[26] = vc4[2];
	/* ---------------------------------- */

	return vertexData;
}

private int[] sepiaizeWithHue(int red, int green, int blue)
{
	int tr = (int)((0.393D * red) + (0.769D * green) + (0.189D * blue));
	int tg = (int)((0.349D * red) + (0.686D * green) + (0.168D * blue));
	int tb = (int)((0.272D * red) + (0.534D * green) + (0.131D * blue));
	float[] hsv = Color.RGBtoHSB(Math.min(tr, 255), Math.min(tg, 255), Math.min(tb, 255), null);
	int color = Color.getHSBColor(180, 20, hsv[2]).getRGB();
	int nR = (color >> 16) & 0xFF;
	int nG = (color >>  & 0xFF;
	int nB = (color) & 0xFF;
	return new int[] { nR, nG, nB };
}

@Override
public boolean isAmbientOcclusion()
{
	return this.currentBlockModel.isAmbientOcclusion();
}

@Override
public boolean isGui3d()
{
	return this.currentBlockModel.isGui3d();
}

@Override
public boolean isBuiltInRenderer()
{
	return this.currentBlockModel.isBuiltInRenderer();
}

@Override
public ItemCameraTransforms getItemCameraTransforms()
{
	return this.currentBlockModel.getItemCameraTransforms();
}
}

Posted

EDIT:

 

It would seem like I am too use to shaders in WebGL. I had assumed that each vertex on a side had an associated RGB int array, but apparently that is not the case. I dug deeper into Forge's code and I looks like I was completely wrong. Each vertex does not have an RGB array, but rather, each side has an RGB int shader. I was updating indicies that I thought were colors but were actually uv and vertex points, which explains why the model always rendered as a solid red cube. The correct shader code is below, with vd being the original vertex data array.

 

	private int[] alterColor(int[] vd)
{
	int[] vertexData = Arrays.copyOf(vd, vd.length);
	vertexData[3] = this.sepiaizeWithHue(vd[3]);
	vertexData[10] = this.sepiaizeWithHue(vd[10]);
	vertexData[17] = this.sepiaizeWithHue(vd[17]);
	vertexData[24] = this.sepiaizeWithHue(vd[24]);
	return vertexData;
}

 

HOWEVER

 

This is half-way to what I aim to accomplish. At the moment, the generated color is overlayed on top of the existing color. Does anyone know a way to completely remove the original color of the texture so that only my sepia version remains?

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

    • i managed to fix it by reinstalling the modpack and re-add all the extra mods I've had previously.
    • Ah, it appears I spoke too soon, I still need a little help here. I now have the forceloading working reliably.  However, I've realized it's not always the first tick that loads the entity.  I've seen it take anywhere from 2-20ish to actually go through, in which time my debugging has revealed that the chunk is loaded, but during which time calling  serverLevelIn.getEntity(uuidIn) returns a null result.  I suspect this has to do with queuing and how entities are loaded into the game.  While not optimal, it's acceptable, and I don't think there's a whole ton I can do to avoid it. However, my concern is that occasionally teleporting an entity in this manner causes a lag spike.  It's not every time and gives the appearance of being correlated with when other chunks are loading in.  It's also not typically a long spike, but can last a second or two, which is less than ideal.  The gist of how I'm summoning is here (although I've omitted some parts that weren't relevant.  The lag occurs before the actual summon so I'm pretty confident it's the loading, and not the actual summon call). ChunkPos chunkPos = new ChunkPos(entityPosIn); if (serverLevelIn.areEntitiesLoaded(chunkPos.toLong())) { boolean isSummoned = // The method I'm using for actual summoning is called here. Apart from a few checks, the bulk of it is shown later on. if (isSummoned) { // Code that runs here just notifies the player of the summon, clears it from the queue, and removes the forceload } } else { // I continue forcing the chunk until the summon succeeds, to make sure it isn't inadvertently cleared ForgeChunkManager.forceChunk(serverLevelIn, MODID, summonPosIn, chunkPos.x, chunkPos.z, true, true); } The summon code itself uses serverLevelIn.getEntity(uuidIn) to retrieve the entity, and moves it as such.  It is then moved thusly: if (entity.isAlive()) { entity.moveTo(posIn.getX(), posIn.getY(), posIn.getZ()); serverLevelIn.playSound(null, entity, SoundEvents.ENDERMAN_TELEPORT, SoundSource.NEUTRAL, 1.0F, 1.0F); return true; } I originally was calling .getEntity() more frequently and didn't have the check for whether or not entities were loaded in place to prevent unnecessary code calls, but even with those safety measures in place, the lag still persists.  Could this just be an issue with 1.18's lack of optimization in certain areas?  Is there anything I can do to mitigate it?  Is there a performance boosting mod I could recommend alongside my own to reduce the chunk loading lag? At the end of the day, it does work, and I'm putting measures in place to prevent players from abusing the system to cause lag (i.e. each player can only have one queued summon at a time-- trying to summon another replaces the first call).  It's also not an unacceptable level of lag, IMO, given the infrequency of such calls, and the fact that I'm providing the option to toggle off the feature if server admins don't want it used.  However, no amount of lag is ideal, so if possible I'd love to find a more elegant solution-- or at least a mod recommendation to help improve it. Thanks!
    • When i start my forge server its on but when i try to join its come a error Internal Exception: java.lang.OutOfMemoryError: Requested array size exceeds VM limit Server infos: Linux Minecraft version 1.20.1 -Xmx11G -Xms8G
    • Also add the latest.log from your logs-folder
  • Topics

×
×
  • Create New...

Important Information

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