Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality to fake blockId for shaders #114

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class CapturingTessellator extends Tessellator implements ITessellatorIns
private final Quad.Flags FLAGS = new Quad.Flags(true, true, true, true);
private final ObjectPooler<QuadView> quadBuf = new ObjectPooler<>(Quad::new);
private final List<QuadView> collectedQuads = new ObjectArrayList<>();
private int shaderBlockId = -1;

// Any offset we need to the Tesselator's offset!
private final BlockPos offset = new BlockPos();
Expand Down Expand Up @@ -101,6 +102,7 @@ public int draw() {
-offset.x,
-offset.y,
-offset.z);
quad.setShaderBlockId(shaderBlockId);

if (quad.isDeleted()) {
quadBuf.releaseInstance(quad);
Expand Down Expand Up @@ -249,4 +251,15 @@ public void ensureBuffer() {
}
}

public void setShaderBlockId(int blockId) {
// Flush queue, so we capture the blockId in quads before we change it
if (isDrawing) {
draw();
isDrawing = true;
}

// Now set new blockId
shaderBlockId = blockId;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class Quad implements QuadView {
@Getter
private ForgeDirection face;
private int colorIndex = -1;
private int shaderBlockId = -1;
private TextureAtlasSprite sprite = null;

/** Returns the face, forced to take one of 6 directions to mirror the behavior of baked quads in 1.16.5. */
Expand Down Expand Up @@ -109,6 +110,11 @@ public int getColorIndex() {
return this.colorIndex;
}

@Override
public int getShaderBlockId() {
return this.shaderBlockId;
}

@Override
public TextureAtlasSprite rubidium$getSprite() {
return this.sprite;
Expand Down Expand Up @@ -174,6 +180,11 @@ public void setSprite(TextureAtlasSprite sprite) {
this.sprite = sprite;
}

@Override
public void setShaderBlockId(int shaderBlockId) {
this.shaderBlockId = shaderBlockId;
}

@Override
public int[] getRawData() {
return this.data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ static QuadView allocate() {

int[] getRawData();

void setShaderBlockId(int shaderBlockId);

int getShaderBlockId();

/**
* Present for compatibility with the Tesselator, not recommended for general use.
*/
Expand Down