mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-11-11 04:22:00 +01:00
cart contraptions are lit
This commit is contained in:
parent
dea3f05364
commit
55ea7e3e55
9 changed files with 126 additions and 41 deletions
|
@ -2,6 +2,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement.be
|
|||
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.Contraption;
|
||||
import com.simibubi.create.foundation.render.contraption.RenderedContraption;
|
||||
import com.simibubi.create.foundation.render.light.ContraptionLighter;
|
||||
import com.simibubi.create.foundation.render.light.GridAlignedBB;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
|
@ -15,38 +16,21 @@ public class StabilizedLighter extends ContraptionLighter<StabilizedContraption>
|
|||
super(contraption);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(RenderedContraption owner) {
|
||||
GridAlignedBB contraptionBounds = getContraptionBounds();
|
||||
|
||||
if (!contraptionBounds.sameAs(bounds)) {
|
||||
lightVolume.move(contraption.entity.world, contraptionBoundsToVolume(contraptionBounds));
|
||||
bounds = contraptionBounds;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GridAlignedBB getContraptionBounds() {
|
||||
GridAlignedBB bb = GridAlignedBB.fromAABB(contraption.bounds);
|
||||
|
||||
// TODO: this whole thing is a hack and is not generalizable
|
||||
Iterable<Entity> allEntities = ((ClientWorld) contraption.entity.world).getAllEntities();
|
||||
|
||||
for (Entity entity : allEntities) {
|
||||
|
||||
if (entity.getUniqueID() == contraption.parentID && entity instanceof AbstractContraptionEntity) {
|
||||
Contraption mountedOn = ((AbstractContraptionEntity) entity).getContraption();
|
||||
|
||||
GridAlignedBB mountedBounds = GridAlignedBB.fromAABB(mountedOn.bounds);
|
||||
|
||||
Vec3i dir = contraption.getFacing().getDirectionVec();
|
||||
|
||||
int mulX = 1 - Math.abs(dir.getX());
|
||||
int mulY = 1 - Math.abs(dir.getY());
|
||||
int mulZ = 1 - Math.abs(dir.getZ());
|
||||
|
||||
bb.minX -= mulX * mountedBounds.sizeX();
|
||||
bb.minY -= mulY * mountedBounds.sizeY();
|
||||
bb.minZ -= mulZ * mountedBounds.sizeZ();
|
||||
bb.maxX += mulX * mountedBounds.sizeX();
|
||||
bb.maxY += mulY * mountedBounds.sizeY();
|
||||
bb.maxZ += mulZ * mountedBounds.sizeZ();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bb.translate(contraption.anchor);
|
||||
bb.translate(contraption.entity.getPosition());
|
||||
|
||||
return bb;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import static com.simibubi.create.content.contraptions.components.structureMovem
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import com.simibubi.create.foundation.render.light.ContraptionLighter;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
|
@ -160,4 +161,9 @@ public class MountedContraption extends Contraption {
|
|||
IItemHandlerModifiable handlerFromInv = new InvWrapper((IInventory) cart);
|
||||
inventory = new CombinedInvWrapper(handlerFromInv, inventory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContraptionLighter<?> makeLighter() {
|
||||
return new MountedLighter(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package com.simibubi.create.content.contraptions.components.structureMovement.mounted;
|
||||
|
||||
import com.simibubi.create.foundation.render.contraption.RenderedContraption;
|
||||
import com.simibubi.create.foundation.render.light.ContraptionLighter;
|
||||
import com.simibubi.create.foundation.render.light.GridAlignedBB;
|
||||
|
||||
public class MountedLighter extends ContraptionLighter<MountedContraption> {
|
||||
public MountedLighter(MountedContraption contraption) {
|
||||
super(contraption);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(RenderedContraption owner) {
|
||||
GridAlignedBB contraptionBounds = getContraptionBounds();
|
||||
|
||||
if (!contraptionBounds.sameAs(bounds)) {
|
||||
lightVolume.move(contraption.entity.world, contraptionBoundsToVolume(contraptionBounds));
|
||||
bounds = contraptionBounds;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GridAlignedBB getContraptionBounds() {
|
||||
GridAlignedBB bb = GridAlignedBB.fromAABB(contraption.bounds);
|
||||
|
||||
bb.translate(contraption.entity.getPosition());
|
||||
|
||||
return bb;
|
||||
}
|
||||
}
|
|
@ -26,6 +26,7 @@ import com.simibubi.create.foundation.networking.AllPackets;
|
|||
import com.simibubi.create.foundation.networking.LeftClickPacket;
|
||||
import com.simibubi.create.foundation.render.FastRenderDispatcher;
|
||||
import com.simibubi.create.foundation.render.RenderWork;
|
||||
import com.simibubi.create.foundation.render.contraption.ContraptionRenderDispatcher;
|
||||
import com.simibubi.create.foundation.render.light.LightVolumeDebugger;
|
||||
import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer;
|
||||
import com.simibubi.create.foundation.tileEntity.behaviour.edgeInteraction.EdgeInteractionRenderer;
|
||||
|
@ -106,6 +107,7 @@ public class ClientEvents {
|
|||
ArmInteractionPointHandler.tick();
|
||||
PlacementHelpers.tick();
|
||||
CreateClient.outliner.tickOutlines();
|
||||
ContraptionRenderDispatcher.tick();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.simibubi.create.foundation.render.contraption;
|
|||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.Contraption;
|
||||
import com.simibubi.create.foundation.render.FastKineticRenderer;
|
||||
import com.simibubi.create.foundation.render.shader.Shader;
|
||||
import com.simibubi.create.foundation.render.shader.ShaderCallback;
|
||||
import com.simibubi.create.foundation.render.shader.ShaderHelper;
|
||||
|
@ -30,6 +29,12 @@ public class ContraptionRenderDispatcher {
|
|||
}
|
||||
}
|
||||
|
||||
public static void tick() {
|
||||
for (RenderedContraption contraption : renderers.values()) {
|
||||
contraption.getLighter().tick(contraption);
|
||||
}
|
||||
}
|
||||
|
||||
private static RenderedContraption getRenderer(World world, Contraption c) {
|
||||
RenderedContraption renderer;
|
||||
int entityId = c.entity.getEntityId();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.simibubi.create.foundation.render.light;
|
||||
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.Contraption;
|
||||
import com.simibubi.create.foundation.render.contraption.RenderedContraption;
|
||||
import net.minecraft.util.math.SectionPos;
|
||||
import net.minecraft.world.ILightReader;
|
||||
import net.minecraft.world.LightType;
|
||||
|
@ -11,18 +12,28 @@ public abstract class ContraptionLighter<C extends Contraption> {
|
|||
protected final C contraption;
|
||||
public final LightVolume lightVolume;
|
||||
|
||||
protected GridAlignedBB bounds;
|
||||
|
||||
protected ContraptionLighter(C contraption) {
|
||||
this.contraption = contraption;
|
||||
|
||||
GridAlignedBB bounds = getContraptionBounds();
|
||||
bounds.grow(1); // so we have at least enough data on the edges to avoid artifacts and have smooth lighting
|
||||
bounds.minY = Math.max(bounds.minY, 0);
|
||||
bounds.maxY = Math.min(bounds.maxY, 255);
|
||||
bounds = getContraptionBounds();
|
||||
|
||||
lightVolume = new LightVolume(bounds);
|
||||
lightVolume = new LightVolume(contraptionBoundsToVolume(bounds));
|
||||
|
||||
lightVolume.initialize(contraption.entity.world);
|
||||
}
|
||||
|
||||
protected GridAlignedBB contraptionBoundsToVolume(GridAlignedBB bounds) {
|
||||
bounds = bounds.copy();
|
||||
bounds.grow(1); // so we have at least enough data on the edges to avoid artifacts and have smooth lighting
|
||||
bounds.minY = Math.max(bounds.minY, 0);
|
||||
bounds.maxY = Math.min(bounds.maxY, 255);
|
||||
|
||||
return bounds;
|
||||
}
|
||||
|
||||
public void tick(RenderedContraption owner) {}
|
||||
|
||||
public abstract GridAlignedBB getContraptionBounds();
|
||||
}
|
||||
|
|
|
@ -55,6 +55,19 @@ public class GridAlignedBB {
|
|||
return new AxisAlignedBB(bb.minX, bb.minY, bb.minZ, bb.maxX, bb.maxY, bb.maxZ);
|
||||
}
|
||||
|
||||
public GridAlignedBB copy() {
|
||||
return copy(this);
|
||||
}
|
||||
|
||||
public boolean sameAs(GridAlignedBB other) {
|
||||
return minX == other.minX &&
|
||||
minY == other.minY &&
|
||||
minZ == other.minZ &&
|
||||
maxX == other.maxX &&
|
||||
maxY == other.maxY &&
|
||||
maxZ == other.maxZ;
|
||||
}
|
||||
|
||||
public int sizeX() {
|
||||
return maxX - minX;
|
||||
}
|
||||
|
@ -272,4 +285,30 @@ public class GridAlignedBB {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
GridAlignedBB that = (GridAlignedBB) o;
|
||||
|
||||
if (minX != that.minX) return false;
|
||||
if (minY != that.minY) return false;
|
||||
if (minZ != that.minZ) return false;
|
||||
if (maxX != that.maxX) return false;
|
||||
if (maxY != that.maxY) return false;
|
||||
return maxZ == that.maxZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = minX;
|
||||
result = 31 * result + minY;
|
||||
result = 31 * result + minZ;
|
||||
result = 31 * result + maxX;
|
||||
result = 31 * result + maxY;
|
||||
result = 31 * result + maxZ;
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||
// to reread all the lighting data in those cases.
|
||||
public class LightVolume {
|
||||
|
||||
private final GridAlignedBB sampleVolume;
|
||||
private final GridAlignedBB textureVolume;
|
||||
private GridAlignedBB sampleVolume;
|
||||
private GridAlignedBB textureVolume;
|
||||
private ByteBuffer lightData;
|
||||
|
||||
private boolean bufferDirty;
|
||||
|
@ -27,14 +27,18 @@ public class LightVolume {
|
|||
private int glTexture;
|
||||
|
||||
public LightVolume(GridAlignedBB sampleVolume) {
|
||||
this.sampleVolume = GridAlignedBB.copy(sampleVolume);
|
||||
sampleVolume.nextPowerOf2Centered();
|
||||
this.textureVolume = sampleVolume;
|
||||
setSampleVolume(sampleVolume);
|
||||
|
||||
this.glTexture = GL11.glGenTextures();
|
||||
this.lightData = MemoryUtil.memAlloc(this.textureVolume.volume() * 2); // TODO: maybe figure out how to pack light coords into a single byte
|
||||
}
|
||||
|
||||
private void setSampleVolume(GridAlignedBB sampleVolume) {
|
||||
this.sampleVolume = sampleVolume;
|
||||
this.textureVolume = sampleVolume.copy();
|
||||
this.textureVolume.nextPowerOf2Centered();
|
||||
}
|
||||
|
||||
public GridAlignedBB getTextureVolume() {
|
||||
return GridAlignedBB.copy(textureVolume);
|
||||
}
|
||||
|
@ -79,6 +83,10 @@ public class LightVolume {
|
|||
return textureVolume.sizeZ();
|
||||
}
|
||||
|
||||
public void move(ILightReader world, GridAlignedBB newSampleVolume) {
|
||||
setSampleVolume(newSampleVolume);
|
||||
initialize(world);
|
||||
}
|
||||
|
||||
public void notifyLightUpdate(ILightReader world, LightType type, SectionPos location) {
|
||||
GridAlignedBB changedVolume = GridAlignedBB.fromSection(location);
|
||||
|
|
|
@ -53,9 +53,9 @@ void main() {
|
|||
|
||||
float scrollSize = scrollTexture.w - scrollTexture.y;
|
||||
|
||||
float scroll = fract(speed * time / (36 * 16.)) * scrollSize * scrollMult;
|
||||
float scroll = fract(speed * time / (36 * 16)) * scrollSize * scrollMult;
|
||||
|
||||
vec3 norm = (rotation * vec4(aNormal, 0.)).xyz;
|
||||
vec3 norm = (rotation * vec4(aNormal, 0)).xyz;
|
||||
|
||||
Diffuse = diffuse(norm);
|
||||
Light = light;
|
||||
|
|
Loading…
Reference in a new issue