diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/BellMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/BellMovementBehaviour.java index cc14b1ffc..3bcaa5286 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/BellMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/BellMovementBehaviour.java @@ -10,8 +10,8 @@ import net.minecraft.util.math.Vec3d; public class BellMovementBehaviour extends MovementBehaviour { @Override - public boolean hasSpecialMovementRenderer() { - return false; + public boolean renderAsNormalTileEntity() { + return true; } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/CampfireMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/CampfireMovementBehaviour.java index a1f1c148f..e27cffee5 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/CampfireMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/CampfireMovementBehaviour.java @@ -10,8 +10,8 @@ import net.minecraft.particles.ParticleTypes; public class CampfireMovementBehaviour extends MovementBehaviour { @Override - public boolean hasSpecialMovementRenderer() { - return false; + public boolean renderAsNormalTileEntity() { + return true; } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java index dd5441db7..2ec0ed260 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java @@ -35,6 +35,11 @@ public class DrillMovementBehaviour extends BlockBreakingMovementBehaviour { //DrillRenderer.renderInContraption(context, ms, msLocal, buffer); } + @Override + public boolean hasSpecialInstancedRendering() { + return true; + } + @Override public void addInstance(RenderedContraption contraption, MovementContext context) { DrillRenderer.addInstanceForContraption(contraption, context); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterMovementBehaviour.java index a70af09ab..c135526e5 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterMovementBehaviour.java @@ -36,6 +36,11 @@ public class HarvesterMovementBehaviour extends MovementBehaviour { .getOpposite()); } + @Override + public boolean hasSpecialInstancedRendering() { + return true; + } + @Override public void addInstance(RenderedContraption contraption, MovementContext context) { HarvesterRenderer.addInstanceForContraption(contraption, context); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java index 83059c93e..d84eb8cf7 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java @@ -118,7 +118,8 @@ public abstract class Contraption { // Client public Map presentTileEntities; - public List renderedTileEntities; + public List maybeInstancedTileEntities; + public List specialRenderedTileEntities; public Contraption() { blocks = new HashMap<>(); @@ -131,7 +132,8 @@ public abstract class Contraption { glueToRemove = new ArrayList<>(); initialPassengers = new HashMap<>(); presentTileEntities = new HashMap<>(); - renderedTileEntities = new ArrayList<>(); + maybeInstancedTileEntities = new ArrayList<>(); + specialRenderedTileEntities = new ArrayList<>(); pendingSubContraptions = new ArrayList<>(); stabilizedSubContraptions = new HashMap<>(); } @@ -520,7 +522,7 @@ public abstract class Contraption { public void readNBT(World world, CompoundNBT nbt, boolean spawnData) { blocks.clear(); presentTileEntities.clear(); - renderedTileEntities.clear(); + specialRenderedTileEntities.clear(); nbt.getList("Blocks", 10) .forEach(c -> { @@ -534,7 +536,7 @@ public abstract class Contraption { Block block = info.state.getBlock(); CompoundNBT tag = info.nbt; MovementBehaviour movementBehaviour = AllMovementBehaviours.of(block); - if (tag == null || (movementBehaviour != null && movementBehaviour.hasSpecialMovementRenderer())) + if (tag == null) return; tag.putInt("x", info.pos.getX()); @@ -557,8 +559,15 @@ public abstract class Contraption { if (te instanceof KineticTileEntity) ((KineticTileEntity) te).setSpeed(0); te.getBlockState(); + + if (movementBehaviour == null || !movementBehaviour.hasSpecialInstancedRendering()) + maybeInstancedTileEntities.add(te); + + if (movementBehaviour != null && !movementBehaviour.renderAsNormalTileEntity()) + return; + presentTileEntities.put(info.pos, te); - renderedTileEntities.add(te); + specialRenderedTileEntities.add(te); } }); @@ -576,7 +585,8 @@ public abstract class Contraption { .add(Pair.of(NBTUtil.readBlockPos(c.getCompound("Pos")), Direction.byIndex(c.getByte("Direction"))))); seats.clear(); - NBTHelper.iterateCompoundList(nbt.getList("Seats", NBT.TAG_COMPOUND), c -> seats.add(NBTUtil.readBlockPos(c))); + NBTHelper.iterateCompoundList(nbt.getList("Seats", NBT.TAG_COMPOUND), c -> seats.add + (NBTUtil.readBlockPos(c))); seatMapping.clear(); NBTHelper.iterateCompoundList(nbt.getList("Passengers", NBT.TAG_COMPOUND), diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java index b839f558d..e22bf6284 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionRenderer.java @@ -76,7 +76,7 @@ public class ContraptionRenderer { protected static void renderTileEntities(World world, Contraption c, MatrixStack ms, MatrixStack msLocal, IRenderTypeBuffer buffer) { - TileEntityRenderHelper.renderTileEntities(world, c.renderedTileEntities, ms, msLocal, buffer); + TileEntityRenderHelper.renderTileEntities(world, c.specialRenderedTileEntities, ms, msLocal, buffer); } private static SuperByteBuffer buildStructureBuffer(Contraption c, RenderType layer) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MovementBehaviour.java index d82dcfe38..82ae42088 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MovementBehaviour.java @@ -48,8 +48,12 @@ public abstract class MovementBehaviour { } - public boolean hasSpecialMovementRenderer() { - return true; + public boolean renderAsNormalTileEntity() { + return false; + } + + public boolean hasSpecialInstancedRendering() { + return false; } @OnlyIn(Dist.CLIENT) diff --git a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinMovementBehaviour.java index a3de35c6c..1f77c0caa 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinMovementBehaviour.java @@ -23,8 +23,8 @@ public class BasinMovementBehaviour extends MovementBehaviour { } @Override - public boolean hasSpecialMovementRenderer() { - return false; + public boolean renderAsNormalTileEntity() { + return true; } @Override diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java b/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java index fab94150c..76e8d7f9a 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java @@ -6,7 +6,6 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Con import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; -import com.simibubi.create.foundation.render.FastKineticRenderer; import com.simibubi.create.foundation.render.instancing.*; import com.simibubi.create.foundation.render.instancing.actors.StaticRotatingActorData; import com.simibubi.create.foundation.render.light.ContraptionLighter; @@ -22,6 +21,7 @@ import net.minecraft.world.gen.feature.template.Template; import org.apache.commons.lang3.tuple.MutablePair; import java.nio.FloatBuffer; +import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -87,7 +87,7 @@ public class RenderedContraption { } private void buildInstancedTiles(Contraption c) { - List tileEntities = c.renderedTileEntities; + Collection tileEntities = c.maybeInstancedTileEntities; if (!tileEntities.isEmpty()) { for (TileEntity te : tileEntities) { if (te instanceof IInstanceRendered) { diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java index bbb729de3..9a482dd8d 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceBuffer.java @@ -104,7 +104,7 @@ public abstract class InstanceBuffer extends GPUBuffer { @Override protected void drawCall() { - GL40.glDrawElementsInstanced(GL11.GL_QUADS, vertexCount, GL11.GL_UNSIGNED_SHORT, 0, instanceCount); + GL31.glDrawElementsInstanced(GL11.GL_QUADS, vertexCount, GL11.GL_UNSIGNED_SHORT, 0, instanceCount); } protected void preDrawTask() { diff --git a/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java b/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java index ac2c89a3c..7b180c52b 100644 --- a/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java +++ b/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java @@ -21,7 +21,7 @@ public class LightVolume { private final GridAlignedBB textureVolume; private ByteBuffer lightData; - private final AtomicBoolean bufferDirty = new AtomicBoolean(false); + private boolean bufferDirty; private boolean removed; private int glTexture; @@ -110,7 +110,7 @@ public class LightVolume { writeLight(x - shiftX, y - shiftY, z - shiftZ, blockLight, skyLight); }); - bufferDirty.set(true); + bufferDirty = true; } /** @@ -132,7 +132,7 @@ public class LightVolume { writeBlock(x - xShift, y - yShift, z - zShift, light); }); - bufferDirty.set(true); + bufferDirty = true; } /** @@ -154,7 +154,7 @@ public class LightVolume { writeSky(x - xShift, y - yShift, z - zShift, light); }); - bufferDirty.set(true); + bufferDirty = true; } public void use() { @@ -168,9 +168,9 @@ public class LightVolume { GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_S, GL20.GL_MIRRORED_REPEAT); GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_R, GL20.GL_MIRRORED_REPEAT); GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_T, GL20.GL_MIRRORED_REPEAT); - if (bufferDirty.get()) { + if (bufferDirty) { GL12.glTexImage3D(GL12.GL_TEXTURE_3D, 0, GL40.GL_RG8, textureVolume.sizeX(), textureVolume.sizeY(), textureVolume.sizeZ(), 0, GL40.GL_RG, GL40.GL_UNSIGNED_BYTE, lightData); - bufferDirty.set(false); + bufferDirty = false; } }