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.
This commit is contained in:
Jozufozu 2024-01-03 13:57:13 -08:00
parent 64df7ed981
commit 8221616eff
5 changed files with 24 additions and 12 deletions

View File

@ -1,11 +1,17 @@
package com.jozufozu.flywheel.api.visual; package com.jozufozu.flywheel.api.visual;
import java.util.List; import java.util.function.Consumer;
import com.jozufozu.flywheel.api.instance.Instance; import com.jozufozu.flywheel.api.instance.Instance;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
public interface BlockEntityVisual<T extends BlockEntity> extends Visual { public interface BlockEntityVisual<T extends BlockEntity> extends Visual {
List<Instance> 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<Instance> consumer);
} }

View File

@ -10,6 +10,7 @@ import com.jozufozu.flywheel.api.backend.BackendManager;
import com.jozufozu.flywheel.api.backend.Engine; import com.jozufozu.flywheel.api.backend.Engine;
import com.jozufozu.flywheel.api.event.RenderContext; import com.jozufozu.flywheel.api.event.RenderContext;
import com.jozufozu.flywheel.api.event.RenderStage; 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.Plan;
import com.jozufozu.flywheel.api.task.TaskExecutor; import com.jozufozu.flywheel.api.task.TaskExecutor;
import com.jozufozu.flywheel.api.visual.DynamicVisual; import com.jozufozu.flywheel.api.visual.DynamicVisual;
@ -227,7 +228,9 @@ public class VisualizationManagerImpl implements VisualizationManager {
continue; continue;
} }
var instances = visual.getCrumblingInstances(); List<Instance> instances = new ArrayList<>();
visual.collectCrumblingInstances(instances::add);
if (instances.isEmpty()) { if (instances.isEmpty()) {
// The visual doesn't want to render anything crumbling. // The visual doesn't want to render anything crumbling.

View File

@ -1,6 +1,6 @@
package com.jozufozu.flywheel.vanilla; package com.jozufozu.flywheel.vanilla;
import java.util.List; import java.util.function.Consumer;
import org.joml.AxisAngle4f; import org.joml.AxisAngle4f;
import org.joml.Quaternionf; import org.joml.Quaternionf;
@ -89,8 +89,8 @@ public class BellVisual extends AbstractBlockEntityVisual<BellBlockEntity> imple
} }
@Override @Override
public List<Instance> getCrumblingInstances() { public void collectCrumblingInstances(Consumer<Instance> consumer) {
return List.of(bell); consumer.accept(bell);
} }
@Override @Override

View File

@ -2,8 +2,8 @@ package com.jozufozu.flywheel.vanilla;
import java.util.Calendar; import java.util.Calendar;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Consumer;
import org.joml.Quaternionf; import org.joml.Quaternionf;
@ -161,8 +161,10 @@ public class ChestVisual<T extends BlockEntity & LidBlockEntity> extends Abstrac
} }
@Override @Override
public List<Instance> getCrumblingInstances() { public void collectCrumblingInstances(Consumer<Instance> consumer) {
return List.of(bottom, lid, lock); consumer.accept(bottom);
consumer.accept(lid);
consumer.accept(lock);
} }
@Override @Override

View File

@ -1,6 +1,6 @@
package com.jozufozu.flywheel.vanilla; package com.jozufozu.flywheel.vanilla;
import java.util.List; import java.util.function.Consumer;
import org.joml.Quaternionf; import org.joml.Quaternionf;
@ -126,8 +126,9 @@ public class ShulkerBoxVisual extends AbstractBlockEntityVisual<ShulkerBoxBlockE
} }
@Override @Override
public List<Instance> getCrumblingInstances() { public void collectCrumblingInstances(Consumer<Instance> consumer) {
return List.of(base, lid); consumer.accept(base);
consumer.accept(lid);
} }
@Override @Override