fix saws not rendering their shafts in contraptions

This commit is contained in:
JozsefA 2021-01-23 16:39:11 -08:00
parent 4cbea0f9c9
commit dea3f05364
11 changed files with 48 additions and 24 deletions

View file

@ -10,8 +10,8 @@ import net.minecraft.util.math.Vec3d;
public class BellMovementBehaviour extends MovementBehaviour { public class BellMovementBehaviour extends MovementBehaviour {
@Override @Override
public boolean hasSpecialMovementRenderer() { public boolean renderAsNormalTileEntity() {
return false; return true;
} }
@Override @Override

View file

@ -10,8 +10,8 @@ import net.minecraft.particles.ParticleTypes;
public class CampfireMovementBehaviour extends MovementBehaviour { public class CampfireMovementBehaviour extends MovementBehaviour {
@Override @Override
public boolean hasSpecialMovementRenderer() { public boolean renderAsNormalTileEntity() {
return false; return true;
} }
@Override @Override

View file

@ -35,6 +35,11 @@ public class DrillMovementBehaviour extends BlockBreakingMovementBehaviour {
//DrillRenderer.renderInContraption(context, ms, msLocal, buffer); //DrillRenderer.renderInContraption(context, ms, msLocal, buffer);
} }
@Override
public boolean hasSpecialInstancedRendering() {
return true;
}
@Override @Override
public void addInstance(RenderedContraption contraption, MovementContext context) { public void addInstance(RenderedContraption contraption, MovementContext context) {
DrillRenderer.addInstanceForContraption(contraption, context); DrillRenderer.addInstanceForContraption(contraption, context);

View file

@ -36,6 +36,11 @@ public class HarvesterMovementBehaviour extends MovementBehaviour {
.getOpposite()); .getOpposite());
} }
@Override
public boolean hasSpecialInstancedRendering() {
return true;
}
@Override @Override
public void addInstance(RenderedContraption contraption, MovementContext context) { public void addInstance(RenderedContraption contraption, MovementContext context) {
HarvesterRenderer.addInstanceForContraption(contraption, context); HarvesterRenderer.addInstanceForContraption(contraption, context);

View file

@ -118,7 +118,8 @@ public abstract class Contraption {
// Client // Client
public Map<BlockPos, TileEntity> presentTileEntities; public Map<BlockPos, TileEntity> presentTileEntities;
public List<TileEntity> renderedTileEntities; public List<TileEntity> maybeInstancedTileEntities;
public List<TileEntity> specialRenderedTileEntities;
public Contraption() { public Contraption() {
blocks = new HashMap<>(); blocks = new HashMap<>();
@ -131,7 +132,8 @@ public abstract class Contraption {
glueToRemove = new ArrayList<>(); glueToRemove = new ArrayList<>();
initialPassengers = new HashMap<>(); initialPassengers = new HashMap<>();
presentTileEntities = new HashMap<>(); presentTileEntities = new HashMap<>();
renderedTileEntities = new ArrayList<>(); maybeInstancedTileEntities = new ArrayList<>();
specialRenderedTileEntities = new ArrayList<>();
pendingSubContraptions = new ArrayList<>(); pendingSubContraptions = new ArrayList<>();
stabilizedSubContraptions = new HashMap<>(); stabilizedSubContraptions = new HashMap<>();
} }
@ -520,7 +522,7 @@ public abstract class Contraption {
public void readNBT(World world, CompoundNBT nbt, boolean spawnData) { public void readNBT(World world, CompoundNBT nbt, boolean spawnData) {
blocks.clear(); blocks.clear();
presentTileEntities.clear(); presentTileEntities.clear();
renderedTileEntities.clear(); specialRenderedTileEntities.clear();
nbt.getList("Blocks", 10) nbt.getList("Blocks", 10)
.forEach(c -> { .forEach(c -> {
@ -534,7 +536,7 @@ public abstract class Contraption {
Block block = info.state.getBlock(); Block block = info.state.getBlock();
CompoundNBT tag = info.nbt; CompoundNBT tag = info.nbt;
MovementBehaviour movementBehaviour = AllMovementBehaviours.of(block); MovementBehaviour movementBehaviour = AllMovementBehaviours.of(block);
if (tag == null || (movementBehaviour != null && movementBehaviour.hasSpecialMovementRenderer())) if (tag == null)
return; return;
tag.putInt("x", info.pos.getX()); tag.putInt("x", info.pos.getX());
@ -557,8 +559,15 @@ public abstract class Contraption {
if (te instanceof KineticTileEntity) if (te instanceof KineticTileEntity)
((KineticTileEntity) te).setSpeed(0); ((KineticTileEntity) te).setSpeed(0);
te.getBlockState(); te.getBlockState();
if (movementBehaviour == null || !movementBehaviour.hasSpecialInstancedRendering())
maybeInstancedTileEntities.add(te);
if (movementBehaviour != null && !movementBehaviour.renderAsNormalTileEntity())
return;
presentTileEntities.put(info.pos, te); 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"))))); .add(Pair.of(NBTUtil.readBlockPos(c.getCompound("Pos")), Direction.byIndex(c.getByte("Direction")))));
seats.clear(); 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(); seatMapping.clear();
NBTHelper.iterateCompoundList(nbt.getList("Passengers", NBT.TAG_COMPOUND), NBTHelper.iterateCompoundList(nbt.getList("Passengers", NBT.TAG_COMPOUND),

View file

@ -76,7 +76,7 @@ public class ContraptionRenderer {
protected static void renderTileEntities(World world, Contraption c, MatrixStack ms, MatrixStack msLocal, protected static void renderTileEntities(World world, Contraption c, MatrixStack ms, MatrixStack msLocal,
IRenderTypeBuffer buffer) { 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) { private static SuperByteBuffer buildStructureBuffer(Contraption c, RenderType layer) {

View file

@ -48,8 +48,12 @@ public abstract class MovementBehaviour {
} }
public boolean hasSpecialMovementRenderer() { public boolean renderAsNormalTileEntity() {
return true; return false;
}
public boolean hasSpecialInstancedRendering() {
return false;
} }
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)

View file

@ -23,8 +23,8 @@ public class BasinMovementBehaviour extends MovementBehaviour {
} }
@Override @Override
public boolean hasSpecialMovementRenderer() { public boolean renderAsNormalTileEntity() {
return false; return true;
} }
@Override @Override

View file

@ -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.ContraptionRenderer;
import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour;
import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; 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.*;
import com.simibubi.create.foundation.render.instancing.actors.StaticRotatingActorData; import com.simibubi.create.foundation.render.instancing.actors.StaticRotatingActorData;
import com.simibubi.create.foundation.render.light.ContraptionLighter; 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 org.apache.commons.lang3.tuple.MutablePair;
import java.nio.FloatBuffer; import java.nio.FloatBuffer;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -87,7 +87,7 @@ public class RenderedContraption {
} }
private void buildInstancedTiles(Contraption c) { private void buildInstancedTiles(Contraption c) {
List<TileEntity> tileEntities = c.renderedTileEntities; Collection<TileEntity> tileEntities = c.maybeInstancedTileEntities;
if (!tileEntities.isEmpty()) { if (!tileEntities.isEmpty()) {
for (TileEntity te : tileEntities) { for (TileEntity te : tileEntities) {
if (te instanceof IInstanceRendered) { if (te instanceof IInstanceRendered) {

View file

@ -104,7 +104,7 @@ public abstract class InstanceBuffer<D extends InstanceData> extends GPUBuffer {
@Override @Override
protected void drawCall() { 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() { protected void preDrawTask() {

View file

@ -21,7 +21,7 @@ public class LightVolume {
private final GridAlignedBB textureVolume; private final GridAlignedBB textureVolume;
private ByteBuffer lightData; private ByteBuffer lightData;
private final AtomicBoolean bufferDirty = new AtomicBoolean(false); private boolean bufferDirty;
private boolean removed; private boolean removed;
private int glTexture; private int glTexture;
@ -110,7 +110,7 @@ public class LightVolume {
writeLight(x - shiftX, y - shiftY, z - shiftZ, blockLight, skyLight); 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); 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); writeSky(x - xShift, y - yShift, z - zShift, light);
}); });
bufferDirty.set(true); bufferDirty = true;
} }
public void use() { 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_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_R, GL20.GL_MIRRORED_REPEAT);
GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_WRAP_T, 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); 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;
} }
} }