From 0a4311b51efc7186da90fd9119ce0ccce7789c79 Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Thu, 23 Dec 2021 14:41:10 -0800 Subject: [PATCH] Contraptions and engines - Sort of get the batching engine working for contraptions but this feels wrong - TaskEngine gets passed in methods - Better naming for TaskEngines - Do BufferSource ourselves - Change BufferBuilderMixin to allow for injection into BufferBuilder objects --- .../render/ContraptionGroup.java | 6 +- .../render/ContraptionInstanceManager.java | 22 ++--- .../render/ContraptionRenderDispatcher.java | 7 +- .../render/ContraptionRenderInfo.java | 1 + ...er.java => ContraptionRenderingWorld.java} | 4 +- ...edContraption.java => FlwContraption.java} | 83 +++++++++++++++---- .../render/FlwContraptionManager.java | 19 +++-- .../render/SBBContraptionManager.java | 2 +- .../curiosities/TreeFertilizerItem.java | 2 +- .../content/schematics/SchematicWorld.java | 8 +- .../worldWrappers/DummyStatusListener.java | 4 +- .../PlacementSimulationWorld.java | 42 ++++++---- .../utility/worldWrappers/RayTraceWorld.java | 4 +- .../worldWrappers/WrappedChunkProvider.java | 6 +- .../utility/worldWrappers/WrappedWorld.java | 11 ++- .../utility/worldWrappers/package-info.java | 6 ++ 16 files changed, 143 insertions(+), 84 deletions(-) rename src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/{ContraptionRenderManager.java => ContraptionRenderingWorld.java} (95%) rename src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/{RenderedContraption.java => FlwContraption.java} (63%) create mode 100644 src/main/java/com/simibubi/create/foundation/utility/worldWrappers/package-info.java diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionGroup.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionGroup.java index ead1523c2..c52a7d882 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionGroup.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionGroup.java @@ -7,9 +7,9 @@ import net.minecraft.client.renderer.RenderType; public class ContraptionGroup

extends InstancedMaterialGroup

{ - private final RenderedContraption contraption; + private final FlwContraption contraption; - public ContraptionGroup(RenderedContraption contraption, InstancingEngine

owner, RenderType type) { + public ContraptionGroup(FlwContraption contraption, InstancingEngine

owner, RenderType type) { super(owner, type); this.contraption = contraption; @@ -20,7 +20,7 @@ public class ContraptionGroup

extends InstancedMat contraption.setup(program); } - public static

InstancingEngine.GroupFactory

forContraption(RenderedContraption c) { + public static

InstancingEngine.GroupFactory

forContraption(FlwContraption c) { return (materialManager, type) -> new ContraptionGroup<>(c, materialManager, type); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionInstanceManager.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionInstanceManager.java index 96e9b6f00..927207f91 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionInstanceManager.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionInstanceManager.java @@ -1,6 +1,5 @@ package com.simibubi.create.content.contraptions.components.structureMovement.render; -import java.lang.ref.WeakReference; import java.util.ArrayList; import javax.annotation.Nullable; @@ -8,11 +7,12 @@ import javax.annotation.Nullable; import org.apache.commons.lang3.tuple.Pair; import com.jozufozu.flywheel.api.MaterialManager; -import com.jozufozu.flywheel.backend.instancing.ImmediateExecutor; +import com.jozufozu.flywheel.backend.instancing.TaskEngine; import com.jozufozu.flywheel.backend.instancing.tile.TileInstanceManager; import com.simibubi.create.AllMovementBehaviours; import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; +import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; import net.minecraft.client.Camera; import net.minecraft.core.BlockPos; @@ -22,11 +22,11 @@ public class ContraptionInstanceManager extends TileInstanceManager { protected ArrayList actors = new ArrayList<>(); - private final WeakReference contraption; + private final PlacementSimulationWorld renderWorld; - ContraptionInstanceManager(RenderedContraption contraption, MaterialManager materialManager) { - super(ImmediateExecutor.INSTANCE, materialManager); - this.contraption = new WeakReference<>(contraption); + ContraptionInstanceManager(MaterialManager materialManager, PlacementSimulationWorld contraption) { + super(materialManager); + this.renderWorld = contraption; } public void tick() { @@ -34,8 +34,8 @@ public class ContraptionInstanceManager extends TileInstanceManager { } @Override - public void beginFrame(Camera info) { - super.beginFrame(info); + public void beginFrame(TaskEngine taskEngine, Camera info) { + super.beginFrame(taskEngine, info); actors.forEach(ActorInstance::beginFrame); } @@ -53,7 +53,7 @@ public class ContraptionInstanceManager extends TileInstanceManager { MovementBehaviour movementBehaviour = AllMovementBehaviours.of(blockInfo.state); if (movementBehaviour != null && movementBehaviour.hasSpecialInstancedRendering()) { - ActorInstance instance = movementBehaviour.createInstance(materialManager, getContraption().renderWorld, context); + ActorInstance instance = movementBehaviour.createInstance(materialManager, renderWorld, context); actors.add(instance); @@ -62,9 +62,5 @@ public class ContraptionInstanceManager extends TileInstanceManager { return null; } - - public RenderedContraption getContraption() { - return contraption.get(); - } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java index c6ae0310d..ea4b1d9ed 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java @@ -43,7 +43,7 @@ import net.minecraftforge.fml.common.Mod; @Mod.EventBusSubscriber(Dist.CLIENT) public class ContraptionRenderDispatcher { - private static WorldAttached> WORLDS = new WorldAttached<>(SBBContraptionManager::new); + private static WorldAttached> WORLDS = new WorldAttached<>(SBBContraptionManager::new); /** * Reset a contraption's renderer. @@ -113,8 +113,7 @@ public class ContraptionRenderDispatcher { // Skip individual lighting updates to prevent lag with large contraptions renderWorld.setBlock(info.pos, info.state, Block.UPDATE_SUPPRESS_LIGHT); - renderWorld.updateLightSources(); - renderWorld.lighter.runUpdates(Integer.MAX_VALUE, false, false); + renderWorld.runLightingEngine(); return renderWorld; } @@ -176,7 +175,7 @@ public class ContraptionRenderDispatcher { } public static void reset() { - WORLDS.empty(ContraptionRenderManager::delete); + WORLDS.empty(ContraptionRenderingWorld::delete); if (Backend.isOn()) { WORLDS = new WorldAttached<>(FlwContraptionManager::new); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderInfo.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderInfo.java index 648311387..13724e05b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderInfo.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderInfo.java @@ -1,5 +1,6 @@ package com.simibubi.create.content.contraptions.components.structureMovement.render; +import com.jozufozu.flywheel.backend.instancing.TaskEngine; import com.jozufozu.flywheel.event.BeginFrameEvent; import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderManager.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderingWorld.java similarity index 95% rename from src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderManager.java rename to src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderingWorld.java index a5ae70382..072b8842d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderManager.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderingWorld.java @@ -17,7 +17,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; -public abstract class ContraptionRenderManager { +public abstract class ContraptionRenderingWorld { protected final Level world; private int removalTimer; @@ -25,7 +25,7 @@ public abstract class ContraptionRenderManager protected final Int2ObjectMap renderInfos = new Int2ObjectOpenHashMap<>(); protected final List visible = new ObjectArrayList<>(); - public ContraptionRenderManager(LevelAccessor world) { + public ContraptionRenderingWorld(LevelAccessor world) { this.world = (Level) world; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraption.java similarity index 63% rename from src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java rename to src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraption.java index 8c9195b34..9b68b06fe 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraption.java @@ -7,13 +7,18 @@ import java.util.Map; import java.util.function.Supplier; import com.jozufozu.flywheel.backend.Backend; +import com.jozufozu.flywheel.backend.instancing.Engine; import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry; +import com.jozufozu.flywheel.backend.instancing.SerialTaskEngine; +import com.jozufozu.flywheel.backend.instancing.TaskEngine; +import com.jozufozu.flywheel.backend.instancing.batching.BatchingEngine; import com.jozufozu.flywheel.backend.instancing.instancing.InstancingEngine; import com.jozufozu.flywheel.backend.model.ArrayModelRenderer; import com.jozufozu.flywheel.backend.model.ModelRenderer; import com.jozufozu.flywheel.core.model.Model; import com.jozufozu.flywheel.core.model.WorldModel; import com.jozufozu.flywheel.event.BeginFrameEvent; +import com.jozufozu.flywheel.event.RenderLayerEvent; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Matrix4f; import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; @@ -30,29 +35,23 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; -public class RenderedContraption extends ContraptionRenderInfo { +public class FlwContraption extends ContraptionRenderInfo { private final ContraptionLighter lighter; - public final InstancingEngine engine; - public final ContraptionInstanceManager kinetics; - private final Map renderLayers = new HashMap<>(); private final Matrix4f modelViewPartial = new Matrix4f(); + private final ContraptionInstanceWorld instanceWorld; private boolean modelViewPartialReady; - // floats because we're uploading this to the gpu + // floats because we upload this to the gpu private AABB lightBox; - public RenderedContraption(Contraption contraption, PlacementSimulationWorld renderWorld) { + public FlwContraption(Contraption contraption, PlacementSimulationWorld renderWorld) { super(contraption, renderWorld); this.lighter = contraption.makeLighter(); - this.engine = InstancingEngine.builder(CreateContexts.CWORLD) - .setGroupFactory(ContraptionGroup.forContraption(this)) - .setIgnoreOriginCoordinate(true) - .build(); - this.kinetics = new ContraptionInstanceManager(this, engine); - this.engine.addListener(this.kinetics); + + instanceWorld = new ContraptionInstanceWorld(this); buildLayers(); if (Backend.isOn()) { @@ -65,7 +64,7 @@ public class RenderedContraption extends ContraptionRenderInfo { return lighter; } - public void doRenderLayer(RenderType layer, ContraptionProgram shader) { + public void renderStructureLayer(RenderType layer, ContraptionProgram shader) { ModelRenderer structure = renderLayers.get(layer); if (structure != null) { setup(shader); @@ -73,6 +72,21 @@ public class RenderedContraption extends ContraptionRenderInfo { } } + public void renderInstanceLayer(RenderLayerEvent event) { + + event.stack.pushPose(); + float partialTicks = AnimationTickHolder.getPartialTicks(); + AbstractContraptionEntity entity = contraption.entity; + double x = Mth.lerp(partialTicks, entity.xOld, entity.getX()); + double y = Mth.lerp(partialTicks, entity.yOld, entity.getY()); + double z = Mth.lerp(partialTicks, entity.zOld, entity.getZ()); + event.stack.translate(x - event.camX, y - event.camY, z - event.camZ); + ContraptionMatrices.transform(event.stack, getMatrices().getModel()); + instanceWorld.engine.render(SerialTaskEngine.INSTANCE, event); + + event.stack.popPose(); + } + public void beginFrame(BeginFrameEvent event) { super.beginFrame(event); @@ -81,7 +95,7 @@ public class RenderedContraption extends ContraptionRenderInfo { if (!isVisible()) return; - kinetics.beginFrame(event.getInfo()); + instanceWorld.tileInstanceManager.beginFrame(SerialTaskEngine.INSTANCE, event.getInfo()); Vec3 cameraPos = event.getCameraPos(); @@ -113,8 +127,7 @@ public class RenderedContraption extends ContraptionRenderInfo { lighter.delete(); - engine.delete(); - kinetics.invalidate(); + instanceWorld.delete(); } private void buildLayers() { @@ -141,7 +154,7 @@ public class RenderedContraption extends ContraptionRenderInfo { .canInstance(te.getType())) { Level world = te.getLevel(); te.setLevel(renderWorld); - kinetics.add(te); + instanceWorld.tileInstanceManager.add(te); te.setLevel(world); } } @@ -149,7 +162,7 @@ public class RenderedContraption extends ContraptionRenderInfo { } private void buildActors() { - contraption.getActors().forEach(kinetics::createActor); + contraption.getActors().forEach(instanceWorld.tileInstanceManager::createActor); } public static void setupModelViewPartial(Matrix4f matrix, Matrix4f modelMatrix, AbstractContraptionEntity entity, double camX, double camY, double camZ, float pt) { @@ -160,4 +173,38 @@ public class RenderedContraption extends ContraptionRenderInfo { matrix.multiply(modelMatrix); } + public void tick() { + instanceWorld.tileInstanceManager.tick(); + } + + public static class ContraptionInstanceWorld { + + private final Engine engine; + private final ContraptionInstanceManager tileInstanceManager; + + public ContraptionInstanceWorld(FlwContraption parent) { + switch (Backend.getInstance().getEngine()) { + case INSTANCING -> { + InstancingEngine engine = InstancingEngine.builder(CreateContexts.CWORLD) + .setGroupFactory(ContraptionGroup.forContraption(parent)) + .setIgnoreOriginCoordinate(true) + .build(); + tileInstanceManager = new ContraptionInstanceManager(engine, parent.renderWorld); + engine.addListener(tileInstanceManager); + + this.engine = engine; + } + case BATCHING -> { + engine = new BatchingEngine(); + tileInstanceManager = new ContraptionInstanceManager(engine, parent.renderWorld); + } + default -> throw new IllegalArgumentException("Unknown engine type"); + } + } + + public void delete() { + engine.delete(); + tileInstanceManager.invalidate(); + } + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java index f2c9c8ee1..f7a596670 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java @@ -17,7 +17,7 @@ import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationW import net.minecraft.client.renderer.RenderType; import net.minecraft.world.level.LevelAccessor; -public class FlwContraptionManager extends ContraptionRenderManager { +public class FlwContraptionManager extends ContraptionRenderingWorld { public FlwContraptionManager(LevelAccessor world) { super(world); @@ -27,8 +27,8 @@ public class FlwContraptionManager extends ContraptionRenderManager { +public class SBBContraptionManager extends ContraptionRenderingWorld { public static final SuperByteBufferCache.Compartment> CONTRAPTION = new SuperByteBufferCache.Compartment<>(); public SBBContraptionManager(LevelAccessor world) { diff --git a/src/main/java/com/simibubi/create/content/curiosities/TreeFertilizerItem.java b/src/main/java/com/simibubi/create/content/curiosities/TreeFertilizerItem.java index 8477f6578..efc548e31 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/TreeFertilizerItem.java +++ b/src/main/java/com/simibubi/create/content/curiosities/TreeFertilizerItem.java @@ -76,7 +76,7 @@ public class TreeFertilizerItem extends Item { return super.useOn(context); } - private class TreesDreamWorld extends PlacementSimulationServerWorld { + private static class TreesDreamWorld extends PlacementSimulationServerWorld { private final BlockPos saplingPos; private final BlockState soil; diff --git a/src/main/java/com/simibubi/create/content/schematics/SchematicWorld.java b/src/main/java/com/simibubi/create/content/schematics/SchematicWorld.java index 80c7bc4d9..9c662be2b 100644 --- a/src/main/java/com/simibubi/create/content/schematics/SchematicWorld.java +++ b/src/main/java/com/simibubi/create/content/schematics/SchematicWorld.java @@ -45,7 +45,7 @@ public class SchematicWorld extends WrappedWorld implements ServerLevelAccessor protected List renderedTileEntities; protected List entities; protected BoundingBox bounds; - + public BlockPos anchor; public boolean renderMode; @@ -149,12 +149,12 @@ public class SchematicWorld extends WrappedWorld implements ServerLevelAccessor public int getBrightness(LightLayer p_226658_1_, BlockPos p_226658_2_) { return 10; } - + @Override public LevelTickAccess getBlockTicks() { return BlackholeTickAccess.emptyLevelList(); } - + @Override public LevelTickAccess getFluidTicks() { return BlackholeTickAccess.emptyLevelList(); @@ -170,7 +170,7 @@ public class SchematicWorld extends WrappedWorld implements ServerLevelAccessor Predicate arg2) { return Collections.emptyList(); } - + @Override public List players() { return Collections.emptyList(); diff --git a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/DummyStatusListener.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/DummyStatusListener.java index d6dfda197..b54485931 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/DummyStatusListener.java +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/DummyStatusListener.java @@ -1,5 +1,7 @@ package com.simibubi.create.foundation.utility.worldWrappers; +import javax.annotation.Nullable; + import net.minecraft.server.level.progress.ChunkProgressListener; import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.chunk.ChunkStatus; @@ -10,7 +12,7 @@ public class DummyStatusListener implements ChunkProgressListener { public void updateSpawnPos(ChunkPos pCenter) {} @Override - public void onStatusChange(ChunkPos pChunkPosition, ChunkStatus pNewStatus) {} + public void onStatusChange(ChunkPos pChunkPosition, @Nullable ChunkStatus pNewStatus) {} @Override public void start() {} diff --git a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java index e97ec1adc..9ef910057 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java @@ -7,6 +7,8 @@ import java.util.Map; import java.util.Set; import java.util.function.Predicate; +import javax.annotation.Nullable; + import com.jozufozu.flywheel.api.FlywheelWorld; import net.minecraft.core.BlockPos; @@ -19,33 +21,31 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.lighting.LevelLightEngine; public class PlacementSimulationWorld extends WrappedWorld implements FlywheelWorld { - public Map blocksAdded; - public Map tesAdded; + public Map blocksAdded = new HashMap<>(); + public Map tesAdded = new HashMap<>(); - public Set spannedSections; + public Set spannedSections = new HashSet<>(); public LevelLightEngine lighter; - public WrappedChunkProvider chunkProvider; + public final WrappedChunkProvider chunkSource; private final BlockPos.MutableBlockPos scratch = new BlockPos.MutableBlockPos(); public PlacementSimulationWorld(Level wrapped) { this(wrapped, new WrappedChunkProvider()); } - public PlacementSimulationWorld(Level wrapped, WrappedChunkProvider chunkProvider) { - super(wrapped, chunkProvider); - this.chunkProvider = chunkProvider.setPlacementWorld(this); - spannedSections = new HashSet<>(); - lighter = new LevelLightEngine(chunkProvider, true, false); // blockLight, skyLight - blocksAdded = new HashMap<>(); - tesAdded = new HashMap<>(); + public PlacementSimulationWorld(Level wrapped, WrappedChunkProvider chunkSource) { + super(wrapped, chunkSource); + // You can't leak this before the super ctor is called. + // You can't create inner classes before super ctor is called. + chunkSource.setPlacementWorld(this); + this.chunkSource = chunkSource; + lighter = new LevelLightEngine(chunkSource, true, false); } - @Override - public LevelLightEngine getLightEngine() { - return lighter; - } - - public void updateLightSources() { + /** + * Run this after you're done using setBlock(). + */ + public void runLightingEngine() { for (Map.Entry entry : blocksAdded.entrySet()) { BlockPos pos = entry.getKey(); BlockState state = entry.getValue(); @@ -54,6 +54,13 @@ public class PlacementSimulationWorld extends WrappedWorld implements FlywheelWo lighter.onBlockEmissionIncrease(pos, light); } } + + lighter.runUpdates(Integer.MAX_VALUE, false, false); + } + + @Override + public LevelLightEngine getLightEngine() { + return lighter; } public void setTileEntities(Collection tileEntities) { @@ -87,6 +94,7 @@ public class PlacementSimulationWorld extends WrappedWorld implements FlywheelWo } @Override + @Nullable public BlockEntity getBlockEntity(BlockPos pos) { return tesAdded.get(pos); } diff --git a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/RayTraceWorld.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/RayTraceWorld.java index 20a7a9f5f..cc6d567c0 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/RayTraceWorld.java +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/RayTraceWorld.java @@ -11,8 +11,8 @@ import net.minecraft.world.level.material.FluidState; public class RayTraceWorld implements BlockGetter { - private LevelAccessor template; - private BiFunction stateGetter; + private final LevelAccessor template; + private final BiFunction stateGetter; public RayTraceWorld(LevelAccessor template, BiFunction stateGetter) { this.template = template; diff --git a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedChunkProvider.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedChunkProvider.java index 9b82e8c21..8b4b48a6e 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedChunkProvider.java +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedChunkProvider.java @@ -29,11 +29,11 @@ public class WrappedChunkProvider extends ChunkSource { fallbackWorld = world; return this; } - - public WrappedChunkProvider setPlacementWorld(PlacementSimulationWorld world) { + + // VirtualChunkSource is created before VirtualRenderWorld, so we can't initialize it in the ctor. + public void setPlacementWorld(PlacementSimulationWorld world) { fallbackWorld = this.world = world; this.chunks = new HashMap<>(); - return this; } public Stream getLightSources() { diff --git a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedWorld.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedWorld.java index fe405971a..499fb619e 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedWorld.java +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedWorld.java @@ -32,8 +32,6 @@ import net.minecraft.world.level.storage.WritableLevelData; import net.minecraft.world.scores.Scoreboard; import net.minecraft.world.ticks.LevelTickAccess; -@MethodsReturnNonnullByDefault -@ParametersAreNonnullByDefault public class WrappedWorld extends Level { protected Level world; @@ -67,17 +65,18 @@ public class WrappedWorld extends Level { } @Override - public boolean isStateAtPosition(@Nullable BlockPos p_217375_1_, @Nullable Predicate p_217375_2_) { + public boolean isStateAtPosition(BlockPos p_217375_1_, Predicate p_217375_2_) { return world.isStateAtPosition(p_217375_1_, p_217375_2_); } @Override - public BlockEntity getBlockEntity(@Nullable BlockPos pos) { + @Nullable + public BlockEntity getBlockEntity(BlockPos pos) { return world.getBlockEntity(pos); } @Override - public boolean setBlock(@Nullable BlockPos pos, @Nullable BlockState newState, int flags) { + public boolean setBlock(BlockPos pos, BlockState newState, int flags) { return world.setBlock(pos, newState, flags); } @@ -95,7 +94,7 @@ public class WrappedWorld extends Level { public LevelTickAccess getBlockTicks() { return world.getBlockTicks(); } - + @Override public LevelTickAccess getFluidTicks() { return world.getFluidTicks(); diff --git a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/package-info.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/package-info.java new file mode 100644 index 000000000..87851a339 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/package-info.java @@ -0,0 +1,6 @@ +@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault +package com.simibubi.create.foundation.utility.worldWrappers; + +import javax.annotation.ParametersAreNonnullByDefault; + +import net.minecraft.MethodsReturnNonnullByDefault;