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 {
@Override
public boolean hasSpecialMovementRenderer() {
return false;
public boolean renderAsNormalTileEntity() {
return true;
}
@Override

View file

@ -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

View file

@ -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);

View file

@ -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);

View file

@ -118,7 +118,8 @@ public abstract class Contraption {
// Client
public Map<BlockPos, TileEntity> presentTileEntities;
public List<TileEntity> renderedTileEntities;
public List<TileEntity> maybeInstancedTileEntities;
public List<TileEntity> 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),

View file

@ -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) {

View file

@ -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)

View file

@ -23,8 +23,8 @@ public class BasinMovementBehaviour extends MovementBehaviour {
}
@Override
public boolean hasSpecialMovementRenderer() {
return false;
public boolean renderAsNormalTileEntity() {
return true;
}
@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.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<TileEntity> tileEntities = c.renderedTileEntities;
Collection<TileEntity> tileEntities = c.maybeInstancedTileEntities;
if (!tileEntities.isEmpty()) {
for (TileEntity te : tileEntities) {
if (te instanceof IInstanceRendered) {

View file

@ -104,7 +104,7 @@ public abstract class InstanceBuffer<D extends InstanceData> 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() {

View file

@ -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;
}
}