From 8221616eff0948b03ee3b53ed616f3a727171d82 Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Wed, 3 Jan 2024 13:57:13 -0800 Subject: [PATCH] Crumbling inheritance - Instead of returning a list, collect crumbling instances via consumer. - This is much friendlier to inheritance and generally better represents the behavior we want from Visuals. --- .../flywheel/api/visual/BlockEntityVisual.java | 10 ++++++++-- .../impl/visualization/VisualizationManagerImpl.java | 5 ++++- .../java/com/jozufozu/flywheel/vanilla/BellVisual.java | 6 +++--- .../com/jozufozu/flywheel/vanilla/ChestVisual.java | 8 +++++--- .../jozufozu/flywheel/vanilla/ShulkerBoxVisual.java | 7 ++++--- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/jozufozu/flywheel/api/visual/BlockEntityVisual.java b/src/main/java/com/jozufozu/flywheel/api/visual/BlockEntityVisual.java index 461de922c..3436a303c 100644 --- a/src/main/java/com/jozufozu/flywheel/api/visual/BlockEntityVisual.java +++ b/src/main/java/com/jozufozu/flywheel/api/visual/BlockEntityVisual.java @@ -1,11 +1,17 @@ package com.jozufozu.flywheel.api.visual; -import java.util.List; +import java.util.function.Consumer; import com.jozufozu.flywheel.api.instance.Instance; import net.minecraft.world.level.block.entity.BlockEntity; public interface BlockEntityVisual extends Visual { - List getCrumblingInstances(); + /** + * Collect all instances that should render with a crumbling overlay + * when the block corresponding to this visual is being broken. + * + * @param consumer A consumer to provide instances to. + */ + void collectCrumblingInstances(Consumer consumer); } diff --git a/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationManagerImpl.java b/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationManagerImpl.java index 625ac7a17..c09ca4d7c 100644 --- a/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationManagerImpl.java +++ b/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationManagerImpl.java @@ -10,6 +10,7 @@ import com.jozufozu.flywheel.api.backend.BackendManager; import com.jozufozu.flywheel.api.backend.Engine; import com.jozufozu.flywheel.api.event.RenderContext; import com.jozufozu.flywheel.api.event.RenderStage; +import com.jozufozu.flywheel.api.instance.Instance; import com.jozufozu.flywheel.api.task.Plan; import com.jozufozu.flywheel.api.task.TaskExecutor; import com.jozufozu.flywheel.api.visual.DynamicVisual; @@ -227,7 +228,9 @@ public class VisualizationManagerImpl implements VisualizationManager { continue; } - var instances = visual.getCrumblingInstances(); + List instances = new ArrayList<>(); + + visual.collectCrumblingInstances(instances::add); if (instances.isEmpty()) { // The visual doesn't want to render anything crumbling. diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/BellVisual.java b/src/main/java/com/jozufozu/flywheel/vanilla/BellVisual.java index d6126d5af..aded9687b 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/BellVisual.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/BellVisual.java @@ -1,6 +1,6 @@ package com.jozufozu.flywheel.vanilla; -import java.util.List; +import java.util.function.Consumer; import org.joml.AxisAngle4f; import org.joml.Quaternionf; @@ -89,8 +89,8 @@ public class BellVisual extends AbstractBlockEntityVisual imple } @Override - public List getCrumblingInstances() { - return List.of(bell); + public void collectCrumblingInstances(Consumer consumer) { + consumer.accept(bell); } @Override diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/ChestVisual.java b/src/main/java/com/jozufozu/flywheel/vanilla/ChestVisual.java index 01df7480c..e5ed24fdd 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/ChestVisual.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/ChestVisual.java @@ -2,8 +2,8 @@ package com.jozufozu.flywheel.vanilla; import java.util.Calendar; import java.util.EnumMap; -import java.util.List; import java.util.Map; +import java.util.function.Consumer; import org.joml.Quaternionf; @@ -161,8 +161,10 @@ public class ChestVisual extends Abstrac } @Override - public List getCrumblingInstances() { - return List.of(bottom, lid, lock); + public void collectCrumblingInstances(Consumer consumer) { + consumer.accept(bottom); + consumer.accept(lid); + consumer.accept(lock); } @Override diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxVisual.java b/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxVisual.java index c04326622..efa9491e8 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxVisual.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxVisual.java @@ -1,6 +1,6 @@ package com.jozufozu.flywheel.vanilla; -import java.util.List; +import java.util.function.Consumer; import org.joml.Quaternionf; @@ -126,8 +126,9 @@ public class ShulkerBoxVisual extends AbstractBlockEntityVisual getCrumblingInstances() { - return List.of(base, lid); + public void collectCrumblingInstances(Consumer consumer) { + consumer.accept(base); + consumer.accept(lid); } @Override