Visions of visibility

- Add visible/skipDraw getter/setter to InstanceTree
- Minecart finally gets to resolve its TODO!
This commit is contained in:
Jozufozu 2024-09-22 13:04:51 -07:00
parent ee0f799f60
commit ff73e78e21
2 changed files with 46 additions and 10 deletions

View File

@ -39,10 +39,8 @@ public final class InstanceTree {
private float xScale;
private float yScale;
private float zScale;
@ApiStatus.Experimental
public boolean visible = true;
@ApiStatus.Experimental
public boolean skipDraw;
private boolean visible = true;
private boolean skipDraw = false;
private boolean changed;
@ -235,6 +233,48 @@ public final class InstanceTree {
changed = false;
}
/**
* Set the visibility of this tree and all its children, recursively.
*
* @param visible Whether to make this tree visible.
*/
public void visible(boolean visible) {
this.visible = visible;
updateVisible();
// I think you'll get weird behavior if you mark a parent invisible and then mark its child visible.
// Not sure if there's a good way to solve that, though.
for (InstanceTree child : children) {
child.visible(visible);
}
}
/**
* Set the visibility of this specific node in the tree.
*
* @param skipDraw Whether this node should skip rendering.
*/
public void skipDraw(boolean skipDraw) {
this.skipDraw = skipDraw;
updateVisible();
}
private void updateVisible() {
if (instance != null) {
instance.setVisible(visible && !skipDraw);
}
}
public boolean visible() {
return visible;
}
public boolean skipDraw() {
return skipDraw;
}
public float xPos() {
return x;
}

View File

@ -43,7 +43,6 @@ public class MinecartVisual<T extends AbstractMinecart> extends ComponentEntityV
private final Matrix4fStack stack = new Matrix4fStack(2);
private BlockState blockState;
private boolean active;
public MinecartVisual(VisualizationContext ctx, T entity, float partialTick, ModelLayerLocation layerLocation) {
super(ctx, entity, partialTick);
@ -65,11 +64,9 @@ public class MinecartVisual<T extends AbstractMinecart> extends ComponentEntityV
RenderShape shape = blockState.getRenderShape();
if (shape == RenderShape.ENTITYBLOCK_ANIMATED) {
instances.traverse(instance -> instance.setZeroTransform().setChanged());
active = false;
instances.visible(false);
return null;
}
active = true;
if (shape == RenderShape.INVISIBLE) {
return null;
@ -100,8 +97,7 @@ public class MinecartVisual<T extends AbstractMinecart> extends ComponentEntityV
return;
}
// TODO: add proper way to temporarily disable rendering a specific instance
if (!active) {
if (!instances.visible()) {
return;
}