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 xScale;
private float yScale; private float yScale;
private float zScale; private float zScale;
@ApiStatus.Experimental private boolean visible = true;
public boolean visible = true; private boolean skipDraw = false;
@ApiStatus.Experimental
public boolean skipDraw;
private boolean changed; private boolean changed;
@ -235,6 +233,48 @@ public final class InstanceTree {
changed = false; 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() { public float xPos() {
return x; return x;
} }

View File

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