mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-15 07:43:40 +01:00
almost super fast kinetic rendering but we need to detect changes in light first (forge pr?)
fast contraption rendering
This commit is contained in:
parent
fa1e3ea543
commit
05ab482f70
33 changed files with 381 additions and 269 deletions
|
@ -8,7 +8,6 @@ import java.util.List;
|
|||
import javax.annotation.Nullable;
|
||||
|
||||
import com.simibubi.create.Create;
|
||||
import com.simibubi.create.CreateClient;
|
||||
import com.simibubi.create.content.contraptions.KineticNetwork;
|
||||
import com.simibubi.create.content.contraptions.RotationPropagator;
|
||||
import com.simibubi.create.content.contraptions.base.IRotate.SpeedLevel;
|
||||
|
@ -22,6 +21,7 @@ import com.simibubi.create.foundation.tileEntity.SmartTileEntity;
|
|||
import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour;
|
||||
import com.simibubi.create.foundation.utility.Lang;
|
||||
|
||||
import com.simibubi.create.foundation.utility.render.instancing.IInstanceRendered;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
|
@ -38,7 +38,7 @@ import net.minecraft.util.text.TextFormatting;
|
|||
import net.minecraft.world.World;
|
||||
|
||||
public abstract class KineticTileEntity extends SmartTileEntity
|
||||
implements ITickableTileEntity, IHaveGoggleInformation, IHaveHoveringInformation {
|
||||
implements ITickableTileEntity, IHaveGoggleInformation, IHaveHoveringInformation, IInstanceRendered {
|
||||
|
||||
public @Nullable Long network;
|
||||
public @Nullable BlockPos source;
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock;
|
|||
import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer;
|
||||
import com.simibubi.create.foundation.utility.AnimationTickHolder;
|
||||
import com.simibubi.create.foundation.utility.ColorHelper;
|
||||
import com.simibubi.create.foundation.utility.render.instancing.IInstancedTileEntityRenderer;
|
||||
import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer;
|
||||
import com.simibubi.create.foundation.utility.render.SuperByteBuffer;
|
||||
import com.simibubi.create.foundation.utility.render.SuperByteBufferCache.Compartment;
|
||||
|
@ -22,11 +23,12 @@ import net.minecraft.util.Direction;
|
|||
import net.minecraft.util.Direction.Axis;
|
||||
import net.minecraft.util.Direction.AxisDirection;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.LightType;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||
|
||||
@EventBusSubscriber(value = Dist.CLIENT)
|
||||
public class KineticTileEntityRenderer extends SafeTileEntityRenderer<KineticTileEntity> {
|
||||
public class KineticTileEntityRenderer extends SafeTileEntityRenderer<KineticTileEntity> implements IInstancedTileEntityRenderer<KineticTileEntity> {
|
||||
|
||||
public static final Compartment<BlockState> KINETIC_TILE = new Compartment<>();
|
||||
public static boolean rainbowMode = false;
|
||||
|
@ -43,27 +45,35 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer<KineticTil
|
|||
@Override
|
||||
protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer,
|
||||
int light, int overlay) {
|
||||
for (RenderType type : RenderType.getBlockLayers())
|
||||
if (RenderTypeLookup.canRenderInLayer(te.getBlockState(), type))
|
||||
renderRotatingBuffer(te, getRotatedModel(te), light);
|
||||
// for (RenderType type : RenderType.getBlockLayers())
|
||||
// if (RenderTypeLookup.canRenderInLayer(te.getBlockState(), type))
|
||||
// renderRotatingBuffer(te, getRotatedModel(te));
|
||||
addInstanceData(te);
|
||||
}
|
||||
|
||||
public static void renderRotatingKineticBlock(KineticTileEntity te, BlockState renderedState, int light) {
|
||||
@Override
|
||||
public void addInstanceData(KineticTileEntity te) {
|
||||
renderRotatingBuffer(te, getRotatedModel(te));
|
||||
}
|
||||
|
||||
public static void renderRotatingKineticBlock(KineticTileEntity te, BlockState renderedState) {
|
||||
RotatingBuffer instancedRenderer = CreateClient.kineticRenderer.renderBlockInstanced(KINETIC_TILE, renderedState);
|
||||
renderRotatingBuffer(te, instancedRenderer, light);
|
||||
renderRotatingBuffer(te, instancedRenderer);
|
||||
}
|
||||
|
||||
public static void renderRotatingBuffer(KineticTileEntity te, RotatingBuffer instancer, int light) {
|
||||
public static void renderRotatingBuffer(KineticTileEntity te, RotatingBuffer instancer) {
|
||||
instancer.setupInstance(data -> {
|
||||
final BlockPos pos = te.getPos();
|
||||
Axis axis = ((IRotate) te.getBlockState()
|
||||
.getBlock()).getRotationAxis(te.getBlockState());
|
||||
|
||||
data.setPackedLight(light)
|
||||
.setRotationalSpeed(te.getSpeed())
|
||||
.setRotationOffset(getRotationOffsetForPosition(te, pos, axis))
|
||||
.setRotationAxis(Direction.getFacingFromAxis(AxisDirection.POSITIVE, axis).getUnitVector())
|
||||
.setPosition(pos);
|
||||
data
|
||||
.setBlockLight(te.getWorld().getLightLevel(LightType.BLOCK, te.getPos()))
|
||||
.setSkyLight(te.getWorld().getLightLevel(LightType.SKY, te.getPos()))
|
||||
.setRotationalSpeed(te.getSpeed())
|
||||
.setRotationOffset(getRotationOffsetForPosition(te, pos, axis))
|
||||
.setRotationAxis(Direction.getFacingFromAxis(AxisDirection.POSITIVE, axis).getUnitVector())
|
||||
.setPosition(pos);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer;
|
|||
import com.simibubi.create.foundation.utility.render.SuperByteBuffer;
|
||||
import com.simibubi.create.foundation.utility.VecHelper;
|
||||
|
||||
import com.simibubi.create.foundation.utility.render.instancing.RotatingData;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
|
|
|
@ -7,9 +7,11 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
|||
import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer;
|
||||
import com.simibubi.create.content.contraptions.components.clock.CuckooClockTileEntity.Animation;
|
||||
import com.simibubi.create.foundation.utility.AngleHelper;
|
||||
import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer;
|
||||
import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer;
|
||||
import com.simibubi.create.foundation.utility.render.SuperByteBuffer;
|
||||
|
||||
import com.simibubi.create.foundation.utility.render.instancing.RotatingData;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
|
|
|
@ -19,6 +19,7 @@ import com.simibubi.create.foundation.utility.NBTHelper;
|
|||
import com.simibubi.create.foundation.utility.render.SuperByteBuffer;
|
||||
import com.simibubi.create.foundation.utility.VecHelper;
|
||||
|
||||
import com.simibubi.create.foundation.utility.render.instancing.IInstancedTileEntityRenderer;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
|
@ -37,7 +38,7 @@ import net.minecraft.util.math.MathHelper;
|
|||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class DeployerRenderer extends SafeTileEntityRenderer<DeployerTileEntity> {
|
||||
public class DeployerRenderer extends SafeTileEntityRenderer<DeployerTileEntity> implements IInstancedTileEntityRenderer<DeployerTileEntity> {
|
||||
|
||||
public DeployerRenderer(TileEntityRendererDispatcher dispatcher) {
|
||||
super(dispatcher);
|
||||
|
@ -49,10 +50,17 @@ public class DeployerRenderer extends SafeTileEntityRenderer<DeployerTileEntity>
|
|||
renderItem(te, partialTicks, ms, buffer, light, overlay);
|
||||
FilteringRenderer.renderOnTileEntity(te, partialTicks, ms, buffer, light, overlay);
|
||||
renderComponents(te, partialTicks, ms, buffer, light, overlay);
|
||||
|
||||
addInstanceData(te);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInstanceData(DeployerTileEntity te) {
|
||||
KineticTileEntityRenderer.renderRotatingKineticBlock(te, getRenderedBlockState(te));
|
||||
}
|
||||
|
||||
protected void renderItem(DeployerTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer,
|
||||
int light, int overlay) {
|
||||
int light, int overlay) {
|
||||
BlockState deployerState = te.getBlockState();
|
||||
Vec3d offset = getHandOffset(te, partialTicks, deployerState).add(VecHelper.getCenterOf(BlockPos.ZERO));
|
||||
ms.push();
|
||||
|
@ -102,7 +110,7 @@ public class DeployerRenderer extends SafeTileEntityRenderer<DeployerTileEntity>
|
|||
protected void renderComponents(DeployerTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer,
|
||||
int light, int overlay) {
|
||||
IVertexBuilder vb = buffer.getBuffer(RenderType.getSolid());
|
||||
KineticTileEntityRenderer.renderRotatingKineticBlock(te, getRenderedBlockState(te), light);
|
||||
KineticTileEntityRenderer.renderRotatingKineticBlock(te, getRenderedBlockState(te));
|
||||
|
||||
BlockState blockState = te.getBlockState();
|
||||
BlockPos pos = te.getPos();
|
||||
|
|
|
@ -15,6 +15,7 @@ import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
|||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.world.LightType;
|
||||
|
||||
public class EncasedFanRenderer extends KineticTileEntityRenderer {
|
||||
|
||||
|
@ -25,18 +26,24 @@ public class EncasedFanRenderer extends KineticTileEntityRenderer {
|
|||
@Override
|
||||
protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer,
|
||||
int light, int overlay) {
|
||||
addInstanceData(te);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInstanceData(KineticTileEntity te) {
|
||||
Direction direction = te.getBlockState()
|
||||
.get(FACING);
|
||||
.get(FACING);
|
||||
|
||||
BlockPos inFront = te.getPos().offset(direction);
|
||||
int blockLight = te.getWorld().getLightLevel(LightType.BLOCK, inFront);
|
||||
int skyLight = te.getWorld().getLightLevel(LightType.SKY, inFront);
|
||||
|
||||
int lightBehind = WorldRenderer.getLightmapCoordinates(te.getWorld(), te.getPos().offset(direction.getOpposite()));
|
||||
int lightInFront = WorldRenderer.getLightmapCoordinates(te.getWorld(), te.getPos().offset(direction));
|
||||
|
||||
RotatingBuffer shaftHalf =
|
||||
AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(te.getBlockState(), direction.getOpposite());
|
||||
AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(te.getBlockState(), direction.getOpposite());
|
||||
RotatingBuffer fanInner =
|
||||
AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouthRotating(te.getBlockState(), direction.getOpposite());
|
||||
AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouthRotating(te.getBlockState(), direction.getOpposite());
|
||||
|
||||
renderRotatingBuffer(te, shaftHalf, lightBehind);
|
||||
renderRotatingBuffer(te, shaftHalf);
|
||||
fanInner.setupInstance(data -> {
|
||||
final BlockPos pos = te.getPos();
|
||||
Direction.Axis axis = ((IRotate) te.getBlockState()
|
||||
|
@ -48,12 +55,12 @@ public class EncasedFanRenderer extends KineticTileEntityRenderer {
|
|||
if (speed < 0)
|
||||
speed = MathHelper.clamp(speed, -64 * 20, -80);
|
||||
|
||||
data.setPackedLight(lightInFront)
|
||||
data.setBlockLight(blockLight)
|
||||
.setSkyLight(skyLight)
|
||||
.setRotationalSpeed(speed)
|
||||
.setRotationOffset(getRotationOffsetForPosition(te, pos, axis))
|
||||
.setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector())
|
||||
.setPosition(pos);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,9 +9,11 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
|||
import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer;
|
||||
import com.simibubi.create.content.contraptions.components.flywheel.FlywheelBlock.ConnectionState;
|
||||
import com.simibubi.create.foundation.utility.AngleHelper;
|
||||
import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer;
|
||||
import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer;
|
||||
import com.simibubi.create.foundation.utility.render.SuperByteBuffer;
|
||||
|
||||
import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer;
|
||||
import com.simibubi.create.foundation.utility.render.instancing.RotatingData;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
|
|
|
@ -5,7 +5,9 @@ import com.simibubi.create.CreateClient;
|
|||
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
||||
import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer;
|
||||
|
||||
import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer;
|
||||
import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer;
|
||||
import com.simibubi.create.foundation.utility.render.instancing.RotatingData;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||
|
||||
public class MillstoneRenderer extends KineticTileEntityRenderer {
|
||||
|
|
|
@ -4,7 +4,9 @@ import com.simibubi.create.AllBlockPartials;
|
|||
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
||||
import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer;
|
||||
|
||||
import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer;
|
||||
import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer;
|
||||
import com.simibubi.create.foundation.utility.render.instancing.RotatingData;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||
|
||||
public class CreativeMotorRenderer extends KineticTileEntityRenderer {
|
||||
|
|
|
@ -12,6 +12,7 @@ import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringRe
|
|||
import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer;
|
||||
import com.simibubi.create.foundation.utility.*;
|
||||
|
||||
import com.simibubi.create.foundation.utility.render.instancing.IInstancedTileEntityRenderer;
|
||||
import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer;
|
||||
import com.simibubi.create.foundation.utility.render.SuperByteBuffer;
|
||||
import net.minecraft.block.BlockState;
|
||||
|
@ -29,7 +30,7 @@ import net.minecraft.util.Rotation;
|
|||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
public class SawRenderer extends SafeTileEntityRenderer<SawTileEntity> {
|
||||
public class SawRenderer extends SafeTileEntityRenderer<SawTileEntity> implements IInstancedTileEntityRenderer<SawTileEntity> {
|
||||
|
||||
public SawRenderer(TileEntityRendererDispatcher dispatcher) {
|
||||
super(dispatcher);
|
||||
|
@ -41,7 +42,13 @@ public class SawRenderer extends SafeTileEntityRenderer<SawTileEntity> {
|
|||
renderBlade(te, ms, buffer, light);
|
||||
renderItems(te, partialTicks, ms, buffer, light, overlay);
|
||||
FilteringRenderer.renderOnTileEntity(te, partialTicks, ms, buffer, light, overlay);
|
||||
renderShaft(te, ms, buffer, light, overlay);
|
||||
|
||||
addInstanceData(te);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInstanceData(SawTileEntity te) {
|
||||
KineticTileEntityRenderer.renderRotatingBuffer(te, getRotatedModel(te));
|
||||
}
|
||||
|
||||
protected void renderBlade(SawTileEntity te, MatrixStack ms, IRenderTypeBuffer buffer, int light){
|
||||
|
@ -79,7 +86,7 @@ public class SawRenderer extends SafeTileEntityRenderer<SawTileEntity> {
|
|||
}
|
||||
|
||||
protected void renderShaft(SawTileEntity te, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) {
|
||||
KineticTileEntityRenderer.renderRotatingBuffer(te, getRotatedModel(te), light);
|
||||
KineticTileEntityRenderer.renderRotatingBuffer(te, getRotatedModel(te));
|
||||
}
|
||||
|
||||
protected void renderItems(SawTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light,
|
||||
|
|
|
@ -53,8 +53,8 @@ public abstract class AbstractContraptionEntityRenderer<C extends AbstractContra
|
|||
transform(entity, partialTicks, matrixStacks);
|
||||
Contraption contraption = entity.getContraption();
|
||||
if (contraption != null) {
|
||||
ContraptionRenderer.render(entity.world, contraption, ms, msLocal, buffers);
|
||||
// not ready yet FastContraptionRenderer.markForRendering(entity.world, contraption, getPosition(entity, partialTicks), getRotation(entity, partialTicks));
|
||||
ContraptionRenderer.renderDynamic(entity.world, contraption, ms, msLocal, buffers);
|
||||
FastContraptionRenderer.markForRendering(entity.world, contraption, getPosition(entity, partialTicks), getRotation(entity, partialTicks));
|
||||
}
|
||||
ms.pop();
|
||||
|
||||
|
|
|
@ -18,6 +18,12 @@ import java.util.stream.Collectors;
|
|||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.simibubi.create.CreateClient;
|
||||
import com.simibubi.create.foundation.utility.render.FastContraptionRenderer;
|
||||
import com.simibubi.create.foundation.utility.render.FastKineticRenderer;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import org.apache.commons.lang3.tuple.MutablePair;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
|
|
|
@ -5,9 +5,11 @@ import com.simibubi.create.AllBlockPartials;
|
|||
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
||||
import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer;
|
||||
import com.simibubi.create.foundation.utility.AngleHelper;
|
||||
import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer;
|
||||
import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer;
|
||||
import com.simibubi.create.foundation.utility.render.SuperByteBuffer;
|
||||
|
||||
import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer;
|
||||
import com.simibubi.create.foundation.utility.render.instancing.RotatingData;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||
|
|
|
@ -6,9 +6,11 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
|||
import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer;
|
||||
import com.simibubi.create.foundation.utility.AngleHelper;
|
||||
import com.simibubi.create.foundation.utility.MatrixStacker;
|
||||
import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer;
|
||||
import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer;
|
||||
import com.simibubi.create.foundation.utility.render.SuperByteBuffer;
|
||||
|
||||
import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer;
|
||||
import com.simibubi.create.foundation.utility.render.instancing.RotatingData;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
|
|
|
@ -5,11 +5,12 @@ import com.simibubi.create.CreateClient;
|
|||
import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer;
|
||||
import com.simibubi.create.foundation.tileEntity.renderer.SmartTileEntityRenderer;
|
||||
|
||||
import com.simibubi.create.foundation.utility.render.instancing.IInstancedTileEntityRenderer;
|
||||
import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||
|
||||
public class SpeedControllerRenderer extends SmartTileEntityRenderer<SpeedControllerTileEntity> {
|
||||
public class SpeedControllerRenderer extends SmartTileEntityRenderer<SpeedControllerTileEntity> implements IInstancedTileEntityRenderer<SpeedControllerTileEntity> {
|
||||
|
||||
public SpeedControllerRenderer(TileEntityRendererDispatcher dispatcher) {
|
||||
super(dispatcher);
|
||||
|
@ -20,7 +21,12 @@ public class SpeedControllerRenderer extends SmartTileEntityRenderer<SpeedContro
|
|||
IRenderTypeBuffer buffer, int light, int overlay) {
|
||||
super.renderSafe(tileEntityIn, partialTicks, ms, buffer, light, overlay);
|
||||
|
||||
KineticTileEntityRenderer.renderRotatingBuffer(tileEntityIn, getRotatedModel(tileEntityIn), light);
|
||||
addInstanceData(tileEntityIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInstanceData(SpeedControllerTileEntity te) {
|
||||
KineticTileEntityRenderer.renderRotatingBuffer(te, getRotatedModel(te));
|
||||
}
|
||||
|
||||
private RotatingBuffer getRotatedModel(SpeedControllerTileEntity te) {
|
||||
|
|
|
@ -14,6 +14,7 @@ import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer
|
|||
import com.simibubi.create.foundation.utility.Iterate;
|
||||
import com.simibubi.create.foundation.utility.MatrixStacker;
|
||||
import com.simibubi.create.foundation.utility.render.instancing.BeltBuffer;
|
||||
import com.simibubi.create.foundation.utility.render.instancing.IInstancedTileEntityRenderer;
|
||||
import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer;
|
||||
import com.simibubi.create.foundation.utility.render.ShadowRenderHelper;
|
||||
|
||||
|
@ -29,8 +30,9 @@ import net.minecraft.util.Direction.AxisDirection;
|
|||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.world.LightType;
|
||||
|
||||
public class BeltRenderer extends SafeTileEntityRenderer<BeltTileEntity> {
|
||||
public class BeltRenderer extends SafeTileEntityRenderer<BeltTileEntity> implements IInstancedTileEntityRenderer<BeltTileEntity> {
|
||||
|
||||
public BeltRenderer(TileEntityRendererDispatcher dispatcher) {
|
||||
super(dispatcher);
|
||||
|
@ -45,6 +47,17 @@ public class BeltRenderer extends SafeTileEntityRenderer<BeltTileEntity> {
|
|||
protected void renderSafe(BeltTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer,
|
||||
int light, int overlay) {
|
||||
|
||||
BlockState blockState = te.getBlockState();
|
||||
if (!AllBlocks.BELT.has(blockState))
|
||||
return;
|
||||
|
||||
addInstanceData(te);
|
||||
|
||||
renderItems(te, partialTicks, ms, buffer, light, overlay);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInstanceData(BeltTileEntity te) {
|
||||
BlockState blockState = te.getBlockState();
|
||||
if (!AllBlocks.BELT.has(blockState))
|
||||
return;
|
||||
|
@ -73,13 +86,13 @@ public class BeltRenderer extends SafeTileEntityRenderer<BeltTileEntity> {
|
|||
for (boolean bottom : Iterate.trueAndFalse) {
|
||||
|
||||
AllBlockPartials beltPartial = diagonal
|
||||
? start ? AllBlockPartials.BELT_DIAGONAL_START
|
||||
? start ? AllBlockPartials.BELT_DIAGONAL_START
|
||||
: end ? AllBlockPartials.BELT_DIAGONAL_END : AllBlockPartials.BELT_DIAGONAL_MIDDLE
|
||||
: bottom
|
||||
: bottom
|
||||
? start ? AllBlockPartials.BELT_START_BOTTOM
|
||||
: end ? AllBlockPartials.BELT_END_BOTTOM : AllBlockPartials.BELT_MIDDLE_BOTTOM
|
||||
: end ? AllBlockPartials.BELT_END_BOTTOM : AllBlockPartials.BELT_MIDDLE_BOTTOM
|
||||
: start ? AllBlockPartials.BELT_START
|
||||
: end ? AllBlockPartials.BELT_END : AllBlockPartials.BELT_MIDDLE;
|
||||
: end ? AllBlockPartials.BELT_END : AllBlockPartials.BELT_MIDDLE;
|
||||
|
||||
BeltBuffer beltBuffer = beltPartial.renderOnBelt(blockState);
|
||||
SpriteShiftEntry spriteShift =
|
||||
|
@ -88,8 +101,8 @@ public class BeltRenderer extends SafeTileEntityRenderer<BeltTileEntity> {
|
|||
beltBuffer.setupInstance(data -> {
|
||||
float speed = te.getSpeed();
|
||||
if (((axisDirection == AxisDirection.NEGATIVE) ^ upward) ^
|
||||
((alongX && !diagonal) || (alongZ && diagonal)) ^
|
||||
vertical)
|
||||
((alongX && !diagonal) || (alongZ && diagonal)) ^
|
||||
vertical)
|
||||
speed = -speed;
|
||||
|
||||
float rotX = !diagonal && beltSlope != BeltSlope.HORIZONTAL ? 90 : 0;
|
||||
|
@ -97,8 +110,9 @@ public class BeltRenderer extends SafeTileEntityRenderer<BeltTileEntity> {
|
|||
float rotZ = sideways ? 90 : (vertical ? 180 : 0);
|
||||
|
||||
data.setPosition(te.getPos())
|
||||
.setBlockLight(te.getWorld().getLightLevel(LightType.BLOCK, te.getPos()))
|
||||
.setSkyLight(te.getWorld().getLightLevel(LightType.SKY, te.getPos()))
|
||||
.setRotation(rotX, rotY, rotZ)
|
||||
.setPackedLight(light)
|
||||
.setRotationalSpeed(speed)
|
||||
.setScrollTexture(spriteShift)
|
||||
.setScrollMult(diagonal ? 3f / 8f : 0.5f);
|
||||
|
@ -113,7 +127,7 @@ public class BeltRenderer extends SafeTileEntityRenderer<BeltTileEntity> {
|
|||
// TODO 1.15 find a way to cache this model matrix computation
|
||||
MatrixStack modelTransform = new MatrixStack();
|
||||
Direction dir = blockState.get(BeltBlock.HORIZONTAL_FACING)
|
||||
.rotateY();
|
||||
.rotateY();
|
||||
if (sideways)
|
||||
dir = Direction.UP;
|
||||
MatrixStacker msr = MatrixStacker.of(modelTransform);
|
||||
|
@ -126,15 +140,14 @@ public class BeltRenderer extends SafeTileEntityRenderer<BeltTileEntity> {
|
|||
msr.unCentre();
|
||||
|
||||
RotatingBuffer rotatingBuffer = CreateClient.kineticRenderer
|
||||
.renderDirectionalPartialInstanced(AllBlockPartials.BELT_PULLEY, blockState, dir, modelTransform);
|
||||
KineticTileEntityRenderer.renderRotatingBuffer(te, rotatingBuffer, light);
|
||||
.renderDirectionalPartialInstanced(AllBlockPartials.BELT_PULLEY, blockState, dir, modelTransform);
|
||||
KineticTileEntityRenderer.renderRotatingBuffer(te, rotatingBuffer);
|
||||
}
|
||||
|
||||
renderItems(te, partialTicks, ms, buffer, light, overlay);
|
||||
}
|
||||
|
||||
protected void renderItems(BeltTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer,
|
||||
int light, int overlay) {
|
||||
int light, int overlay) {
|
||||
if (!te.isController())
|
||||
return;
|
||||
if (te.beltLength == 0)
|
||||
|
|
|
@ -14,6 +14,7 @@ import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
|||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Direction.Axis;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.LightType;
|
||||
|
||||
public class SplitShaftRenderer extends KineticTileEntityRenderer {
|
||||
|
||||
|
@ -24,10 +25,19 @@ public class SplitShaftRenderer extends KineticTileEntityRenderer {
|
|||
@Override
|
||||
protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer,
|
||||
int light, int overlay) {
|
||||
|
||||
addInstanceData(te);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInstanceData(KineticTileEntity te) {
|
||||
Block block = te.getBlockState().getBlock();
|
||||
final Axis boxAxis = ((IRotate) block).getRotationAxis(te.getBlockState());
|
||||
final BlockPos pos = te.getPos();
|
||||
|
||||
int blockLight = te.getWorld().getLightLevel(LightType.BLOCK, te.getPos());
|
||||
int skyLight = te.getWorld().getLightLevel(LightType.SKY, te.getPos());
|
||||
|
||||
for (Direction direction : Iterate.directions) {
|
||||
Axis axis = direction.getAxis();
|
||||
if (boxAxis != axis)
|
||||
|
@ -46,7 +56,8 @@ public class SplitShaftRenderer extends KineticTileEntityRenderer {
|
|||
|
||||
speed *= modifier;
|
||||
|
||||
data.setPackedLight(light)
|
||||
data.setBlockLight(blockLight)
|
||||
.setSkyLight(skyLight)
|
||||
.setRotationalSpeed(speed)
|
||||
.setRotationOffset(getRotationOffsetForPosition(te, pos, axis))
|
||||
.setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector())
|
||||
|
@ -54,5 +65,4 @@ public class SplitShaftRenderer extends KineticTileEntityRenderer {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import net.minecraft.state.properties.BlockStateProperties;
|
|||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Direction.Axis;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.LightType;
|
||||
|
||||
public class GearboxRenderer extends KineticTileEntityRenderer {
|
||||
|
||||
|
@ -26,6 +27,9 @@ public class GearboxRenderer extends KineticTileEntityRenderer {
|
|||
final Axis boxAxis = te.getBlockState().get(BlockStateProperties.AXIS);
|
||||
final BlockPos pos = te.getPos();
|
||||
|
||||
int blockLight = te.getWorld().getLightLevel(LightType.BLOCK, te.getPos());
|
||||
int skyLight = te.getWorld().getLightLevel(LightType.SKY, te.getPos());
|
||||
|
||||
for (Direction direction : Iterate.directions) {
|
||||
final Axis axis = direction.getAxis();
|
||||
if (boxAxis == axis)
|
||||
|
@ -45,7 +49,8 @@ public class GearboxRenderer extends KineticTileEntityRenderer {
|
|||
speed *= -1;
|
||||
}
|
||||
|
||||
data.setPackedLight(light)
|
||||
data.setBlockLight(blockLight)
|
||||
.setSkyLight(skyLight)
|
||||
.setRotationalSpeed(speed)
|
||||
.setRotationOffset(getRotationOffsetForPosition(te, pos, axis))
|
||||
.setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector())
|
||||
|
|
|
@ -8,8 +8,10 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer;
|
|||
import com.simibubi.create.content.logistics.block.mechanicalArm.ArmTileEntity.Phase;
|
||||
import com.simibubi.create.foundation.utility.*;
|
||||
|
||||
import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer;
|
||||
import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer;
|
||||
import com.simibubi.create.foundation.utility.render.SuperByteBuffer;
|
||||
import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer;
|
||||
import com.simibubi.create.foundation.utility.render.instancing.RotatingData;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
|
|
|
@ -11,7 +11,8 @@ public class AnimationTickHolder {
|
|||
}
|
||||
|
||||
public static float getRenderTick() {
|
||||
return ticks + Minecraft.getInstance().getRenderPartialTicks();
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
return ticks + (mc.isGamePaused() ? mc.renderPartialTicksPaused : mc.getRenderPartialTicks());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ import java.util.concurrent.ExecutionException;
|
|||
|
||||
public class FastContraptionRenderer extends ContraptionRenderer {
|
||||
|
||||
private static final Cache<Contraption, FastContraptionRenderer> renderers = CacheBuilder.newBuilder().build();
|
||||
private static final Cache<Integer, FastContraptionRenderer> renderers = CacheBuilder.newBuilder().build();
|
||||
|
||||
private ArrayList<ContraptionBuffer> renderLayers = new ArrayList<>();
|
||||
|
||||
|
@ -105,7 +105,7 @@ public class FastContraptionRenderer extends ContraptionRenderer {
|
|||
|
||||
private static FastContraptionRenderer getRenderer(World world, Contraption c) {
|
||||
try {
|
||||
return renderers.get(c, () -> new FastContraptionRenderer(world, c));
|
||||
return renderers.get(c.entity.getEntityId(), () -> new FastContraptionRenderer(world, c));
|
||||
} catch (ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
|
@ -120,13 +120,20 @@ public class FastContraptionRenderer extends ContraptionRenderer {
|
|||
ShaderHelper.useShader(Shader.CONTRAPTION_STRUCTURE, ShaderHelper.getViewProjectionCallback(event));
|
||||
int shader = ShaderHelper.getShaderHandle(Shader.CONTRAPTION_STRUCTURE);
|
||||
|
||||
ArrayList<Integer> toRemove = new ArrayList<>();
|
||||
|
||||
for (FastContraptionRenderer renderer : renderers.asMap().values()) {
|
||||
renderer.render(shader);
|
||||
if (renderer.c.entity.isAlive())
|
||||
renderer.render(shader);
|
||||
else
|
||||
toRemove.add(renderer.c.entity.getEntityId());
|
||||
}
|
||||
|
||||
ShaderHelper.releaseShader();
|
||||
|
||||
CreateClient.kineticRenderer.teardown();
|
||||
|
||||
renderers.invalidateAll(toRemove);
|
||||
}
|
||||
|
||||
public static void invalidateAll() {
|
||||
|
|
|
@ -6,10 +6,7 @@ import com.mojang.blaze3d.matrix.MatrixStack;
|
|||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.simibubi.create.AllBlockPartials;
|
||||
import com.simibubi.create.Create;
|
||||
import com.simibubi.create.foundation.utility.render.instancing.BeltBuffer;
|
||||
import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer;
|
||||
import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer;
|
||||
import com.simibubi.create.foundation.utility.render.instancing.*;
|
||||
import com.simibubi.create.foundation.utility.render.shader.Shader;
|
||||
import com.simibubi.create.foundation.utility.render.shader.ShaderCallback;
|
||||
import com.simibubi.create.foundation.utility.render.shader.ShaderHelper;
|
||||
|
@ -18,11 +15,13 @@ import net.minecraft.client.Minecraft;
|
|||
import net.minecraft.client.renderer.*;
|
||||
import net.minecraft.client.renderer.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.texture.Texture;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||
import net.minecraft.inventory.container.PlayerContainer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
|
@ -36,13 +35,14 @@ import java.util.function.Supplier;
|
|||
|
||||
import static com.simibubi.create.foundation.utility.render.SuperByteBufferCache.PARTIAL;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = Create.ID, value = Dist.CLIENT)
|
||||
public class FastKineticRenderer {
|
||||
Map<SuperByteBufferCache.Compartment<?>, Cache<Object, RotatingBuffer>> rotating;
|
||||
Map<SuperByteBufferCache.Compartment<?>, Cache<Object, BeltBuffer>> belts;
|
||||
|
||||
Queue<Runnable> runs;
|
||||
|
||||
boolean rebuild;
|
||||
|
||||
public FastKineticRenderer() {
|
||||
rotating = new HashMap<>();
|
||||
belts = new HashMap<>();
|
||||
|
@ -52,7 +52,29 @@ public class FastKineticRenderer {
|
|||
registerCompartment(SuperByteBufferCache.DIRECTIONAL_PARTIAL);
|
||||
}
|
||||
|
||||
public void buildTileEntityBuffers(World world) {
|
||||
|
||||
List<TileEntity> tileEntities = world.loadedTileEntityList;
|
||||
|
||||
if (!tileEntities.isEmpty()) {
|
||||
for (TileEntity te : tileEntities) {
|
||||
if (te instanceof IInstanceRendered) {
|
||||
TileEntityRenderer<TileEntity> renderer = TileEntityRendererDispatcher.instance.getRenderer(te);
|
||||
|
||||
if (renderer instanceof IInstancedTileEntityRenderer) {
|
||||
addInstancedData(te, (IInstancedTileEntityRenderer<? super TileEntity>) renderer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private <T extends TileEntity> void addInstancedData(T te, IInstancedTileEntityRenderer<T> renderer) {
|
||||
renderer.addInstanceData(te);
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
// TODO: (later) detect changes in lighting with a mixin to ClientChunkProvider.markLightChanged()
|
||||
for (Cache<Object, RotatingBuffer> cache : rotating.values()) {
|
||||
for (RotatingBuffer renderer : cache.asMap().values()) {
|
||||
renderer.clearInstanceData();
|
||||
|
@ -64,6 +86,8 @@ public class FastKineticRenderer {
|
|||
renderer.clearInstanceData();
|
||||
}
|
||||
}
|
||||
|
||||
// rebuild = true;
|
||||
}
|
||||
|
||||
public void enqueue(Runnable run) {
|
||||
|
@ -72,6 +96,11 @@ public class FastKineticRenderer {
|
|||
|
||||
public void renderInstances(RenderWorldLastEvent event) {
|
||||
GameRenderer gameRenderer = Minecraft.getInstance().gameRenderer;
|
||||
//
|
||||
// if (rebuild) {
|
||||
// buildTileEntityBuffers(Minecraft.getInstance().world);
|
||||
// rebuild = false;
|
||||
// }
|
||||
|
||||
setup(gameRenderer);
|
||||
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
package com.simibubi.create.foundation.utility.render;
|
||||
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
|
||||
public class LightUtil {
|
||||
public static float getProperBlockLight(int packedLight) {
|
||||
return LightTexture.getBlockLightCoordinates(packedLight) / (float) 0xF;
|
||||
}
|
||||
|
||||
public static float getProperSkyLight(int packedLight) {
|
||||
return LightTexture.getSkyLightCoordinates(packedLight) / (float) 0xF;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package com.simibubi.create.foundation.utility.render.instancing;
|
||||
|
||||
import net.minecraft.client.renderer.Vector3f;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class BasicData<D extends BasicData<D>> extends InstanceData {
|
||||
|
||||
private float x;
|
||||
private float y;
|
||||
private float z;
|
||||
private float blockLight;
|
||||
private float skyLight;
|
||||
|
||||
public D setBlockLight(int blockLight) {
|
||||
this.blockLight = blockLight / 15f;
|
||||
return (D) this;
|
||||
}
|
||||
|
||||
public D setSkyLight(int skyLight) {
|
||||
this.skyLight = skyLight / 15f;
|
||||
return (D) this;
|
||||
}
|
||||
|
||||
public D setPosition(Vector3f pos) {
|
||||
this.x = pos.getX();
|
||||
this.y = pos.getY();
|
||||
this.z = pos.getZ();
|
||||
return (D) this;
|
||||
}
|
||||
|
||||
public D setPosition(BlockPos pos) {
|
||||
this.x = pos.getX();
|
||||
this.y = pos.getY();
|
||||
this.z = pos.getZ();
|
||||
return (D) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buf) {
|
||||
putVec3(buf, x, y, z);
|
||||
|
||||
putVec2(buf, blockLight, skyLight);
|
||||
}
|
||||
}
|
|
@ -1,15 +1,8 @@
|
|||
package com.simibubi.create.foundation.utility.render.instancing;
|
||||
|
||||
import com.simibubi.create.foundation.block.render.SpriteShiftEntry;
|
||||
import com.simibubi.create.foundation.utility.render.LightUtil;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class BeltBuffer extends InstanceBuffer<BeltBuffer.BeltData> {
|
||||
public class BeltBuffer extends InstanceBuffer<BeltData> {
|
||||
public BeltBuffer(BufferBuilder buf) {
|
||||
super(buf);
|
||||
}
|
||||
|
@ -24,84 +17,4 @@ public class BeltBuffer extends InstanceBuffer<BeltBuffer.BeltData> {
|
|||
return BeltData.FORMAT;
|
||||
}
|
||||
|
||||
public static class BeltData extends InstanceData {
|
||||
public static VertexFormat FORMAT = new VertexFormat(VEC3, VEC3, VEC2, FLOAT, VEC2, VEC4, FLOAT);
|
||||
|
||||
private float x;
|
||||
private float y;
|
||||
private float z;
|
||||
private float rotX;
|
||||
private float rotY;
|
||||
private float rotZ;
|
||||
private int packedLight;
|
||||
private float rotationalSpeed;
|
||||
private float sourceU;
|
||||
private float sourceV;
|
||||
private float minU;
|
||||
private float minV;
|
||||
private float maxU;
|
||||
private float maxV;
|
||||
private float scrollMult;
|
||||
|
||||
public BeltData setPosition(BlockPos pos) {
|
||||
this.x = pos.getX();
|
||||
this.y = pos.getY();
|
||||
this.z = pos.getZ();
|
||||
return this;
|
||||
}
|
||||
|
||||
public BeltData setRotation(float rotX, float rotY, float rotZ) {
|
||||
this.rotX = rotX;
|
||||
this.rotY = rotY;
|
||||
this.rotZ = rotZ;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BeltData setPackedLight(int packedLight) {
|
||||
this.packedLight = packedLight;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BeltData setRotationalSpeed(float rotationalSpeed) {
|
||||
this.rotationalSpeed = rotationalSpeed;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BeltData setScrollTexture(SpriteShiftEntry spriteShift) {
|
||||
TextureAtlasSprite source = spriteShift.getOriginal();
|
||||
TextureAtlasSprite target = spriteShift.getTarget();
|
||||
|
||||
this.sourceU = source.getMinU();
|
||||
this.sourceV = source.getMinV();
|
||||
this.minU = target.getMinU();
|
||||
this.minV = target.getMinV();
|
||||
this.maxU = target.getMaxU();
|
||||
this.maxV = target.getMaxV();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public BeltData setScrollMult(float scrollMult) {
|
||||
this.scrollMult = scrollMult;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buf) {
|
||||
float blockLightCoordinates = LightUtil.getProperBlockLight(packedLight);
|
||||
float skyLightCoordinates = LightUtil.getProperSkyLight(packedLight);
|
||||
|
||||
putVec3(buf, x, y, z);
|
||||
|
||||
putVec3(buf, rotX, rotY, rotZ);
|
||||
|
||||
putVec2(buf, blockLightCoordinates, skyLightCoordinates);
|
||||
putFloat(buf, rotationalSpeed);
|
||||
|
||||
putVec2(buf, sourceU, sourceV);
|
||||
putVec4(buf, minU, minV, maxU, maxV);
|
||||
|
||||
putFloat(buf, scrollMult);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
package com.simibubi.create.foundation.utility.render.instancing;
|
||||
|
||||
import com.simibubi.create.foundation.block.render.SpriteShiftEntry;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*;
|
||||
|
||||
public class BeltData extends BasicData<BeltData> {
|
||||
public static VertexFormat FORMAT = new VertexFormat(VEC3, VEC2, VEC3, FLOAT, VEC2, VEC4, FLOAT);
|
||||
|
||||
private float rotX;
|
||||
private float rotY;
|
||||
private float rotZ;
|
||||
private float rotationalSpeed;
|
||||
private float sourceU;
|
||||
private float sourceV;
|
||||
private float minU;
|
||||
private float minV;
|
||||
private float maxU;
|
||||
private float maxV;
|
||||
private float scrollMult;
|
||||
|
||||
public BeltData setRotation(float rotX, float rotY, float rotZ) {
|
||||
this.rotX = rotX;
|
||||
this.rotY = rotY;
|
||||
this.rotZ = rotZ;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BeltData setRotationalSpeed(float rotationalSpeed) {
|
||||
this.rotationalSpeed = rotationalSpeed;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BeltData setScrollTexture(SpriteShiftEntry spriteShift) {
|
||||
TextureAtlasSprite source = spriteShift.getOriginal();
|
||||
TextureAtlasSprite target = spriteShift.getTarget();
|
||||
|
||||
this.sourceU = source.getMinU();
|
||||
this.sourceV = source.getMinV();
|
||||
this.minU = target.getMinU();
|
||||
this.minV = target.getMinV();
|
||||
this.maxU = target.getMaxU();
|
||||
this.maxV = target.getMaxV();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public BeltData setScrollMult(float scrollMult) {
|
||||
this.scrollMult = scrollMult;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buf) {
|
||||
super.write(buf);
|
||||
|
||||
putVec3(buf, rotX, rotY, rotZ);
|
||||
|
||||
putFloat(buf, rotationalSpeed);
|
||||
|
||||
putVec2(buf, sourceU, sourceV);
|
||||
putVec4(buf, minU, minV, maxU, maxV);
|
||||
|
||||
putFloat(buf, scrollMult);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
package com.simibubi.create.foundation.utility.render.instancing;
|
||||
|
||||
public interface IInstanceRendered {
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.simibubi.create.foundation.utility.render.instancing;
|
||||
|
||||
import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public interface IInstancedTileEntityRenderer<T extends TileEntity> {
|
||||
|
||||
void addInstanceData(T te);
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
package com.simibubi.create.foundation.utility.render.instancing;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public abstract class InstancedTileEntityRenderer<T extends TileEntity, D extends InstanceData> {
|
||||
|
||||
public abstract D getInstanceData(T te);
|
||||
|
||||
public abstract InstanceBuffer<D> getModel(T te);
|
||||
}
|
|
@ -1,24 +1,8 @@
|
|||
package com.simibubi.create.foundation.utility.render.instancing;
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.simibubi.create.foundation.utility.render.LightUtil;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.GLAllocation;
|
||||
import net.minecraft.client.renderer.Vector3f;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormatElement;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL15;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
import org.lwjgl.opengl.GL40;
|
||||
|
||||
import java.nio.Buffer;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*;
|
||||
import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.FLOAT;
|
||||
|
||||
public class RotatingBuffer extends InstanceBuffer<RotatingBuffer.RotatingData> {
|
||||
public class RotatingBuffer extends InstanceBuffer<RotatingData> {
|
||||
public RotatingBuffer(BufferBuilder buf) {
|
||||
super(buf);
|
||||
}
|
||||
|
@ -33,74 +17,4 @@ public class RotatingBuffer extends InstanceBuffer<RotatingBuffer.RotatingData>
|
|||
return RotatingData.FORMAT;
|
||||
}
|
||||
|
||||
public static class RotatingData extends InstanceData {
|
||||
public static VertexFormat FORMAT = new VertexFormat(VEC3, VEC2, FLOAT, FLOAT, VEC3);
|
||||
|
||||
private float x;
|
||||
private float y;
|
||||
private float z;
|
||||
private int packedLight;
|
||||
private float rotationalSpeed;
|
||||
private float rotationOffset;
|
||||
private float rotationAxisX;
|
||||
private float rotationAxisY;
|
||||
private float rotationAxisZ;
|
||||
|
||||
public RotatingData setPackedLight(int packedLight) {
|
||||
this.packedLight = packedLight;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RotatingData setRotationalSpeed(float rotationalSpeed) {
|
||||
this.rotationalSpeed = rotationalSpeed;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RotatingData setRotationOffset(float rotationOffset) {
|
||||
this.rotationOffset = rotationOffset;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RotatingData setPosition(Vector3f pos) {
|
||||
this.x = pos.getX();
|
||||
this.y = pos.getY();
|
||||
this.z = pos.getZ();
|
||||
return this;
|
||||
}
|
||||
|
||||
public RotatingData setPosition(BlockPos pos) {
|
||||
this.x = pos.getX();
|
||||
this.y = pos.getY();
|
||||
this.z = pos.getZ();
|
||||
return this;
|
||||
}
|
||||
|
||||
public RotatingData setRotationAxis(Vector3f axis) {
|
||||
this.rotationAxisX = axis.getX();
|
||||
this.rotationAxisY = axis.getY();
|
||||
this.rotationAxisZ = axis.getZ();
|
||||
return this;
|
||||
}
|
||||
|
||||
public RotatingData setRotationAxis(float rotationAxisX, float rotationAxisY, float rotationAxisZ) {
|
||||
this.rotationAxisX = rotationAxisX;
|
||||
this.rotationAxisY = rotationAxisY;
|
||||
this.rotationAxisZ = rotationAxisZ;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buf) {
|
||||
float blockLightCoordinates = LightUtil.getProperBlockLight(packedLight);
|
||||
float skyLightCoordinates = LightUtil.getProperSkyLight(packedLight);
|
||||
|
||||
putVec3(buf, x, y, z);
|
||||
|
||||
putVec2(buf, blockLightCoordinates, skyLightCoordinates);
|
||||
putFloat(buf, rotationalSpeed);
|
||||
putFloat(buf, rotationOffset);
|
||||
|
||||
putVec3(buf, rotationAxisX, rotationAxisY, rotationAxisZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
package com.simibubi.create.foundation.utility.render.instancing;
|
||||
|
||||
import net.minecraft.client.renderer.Vector3f;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*;
|
||||
|
||||
public class RotatingData extends BasicData<RotatingData> {
|
||||
public static VertexFormat FORMAT = new VertexFormat(VEC3, VEC2, FLOAT, FLOAT, VEC3);
|
||||
|
||||
private float rotationalSpeed;
|
||||
private float rotationOffset;
|
||||
private float rotationAxisX;
|
||||
private float rotationAxisY;
|
||||
private float rotationAxisZ;
|
||||
|
||||
public RotatingData setRotationalSpeed(float rotationalSpeed) {
|
||||
this.rotationalSpeed = rotationalSpeed;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RotatingData setRotationOffset(float rotationOffset) {
|
||||
this.rotationOffset = rotationOffset;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RotatingData setRotationAxis(Vector3f axis) {
|
||||
this.rotationAxisX = axis.getX();
|
||||
this.rotationAxisY = axis.getY();
|
||||
this.rotationAxisZ = axis.getZ();
|
||||
return this;
|
||||
}
|
||||
|
||||
public RotatingData setRotationAxis(float rotationAxisX, float rotationAxisY, float rotationAxisZ) {
|
||||
this.rotationAxisX = rotationAxisX;
|
||||
this.rotationAxisY = rotationAxisY;
|
||||
this.rotationAxisZ = rotationAxisZ;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buf) {
|
||||
super.write(buf);
|
||||
putFloat(buf, rotationalSpeed);
|
||||
putFloat(buf, rotationOffset);
|
||||
|
||||
putVec3(buf, rotationAxisX, rotationAxisY, rotationAxisZ);
|
||||
}
|
||||
}
|
|
@ -6,8 +6,8 @@ layout (location = 1) in vec3 aNormal;
|
|||
layout (location = 2) in vec2 aTexCoords;
|
||||
|
||||
layout (location = 3) in vec3 instancePos;
|
||||
layout (location = 4) in vec3 rotationDegrees;
|
||||
layout (location = 5) in vec2 light;
|
||||
layout (location = 4) in vec2 light;
|
||||
layout (location = 5) in vec3 rotationDegrees;
|
||||
layout (location = 6) in float speed;
|
||||
layout (location = 7) in vec2 sourceUV;
|
||||
layout (location = 8) in vec4 scrollTexture;
|
||||
|
|
|
@ -38,14 +38,16 @@ mat4 contraptionRotation() {
|
|||
}
|
||||
|
||||
void main() {
|
||||
vec4 rotatedPos = contraptionRotation() * vec4(aPos - vec3(0.5), 1);
|
||||
mat4 rotation = contraptionRotation();
|
||||
|
||||
vec4 rotatedPos = rotation * vec4(aPos - vec3(0.5), 1);
|
||||
|
||||
vec4 worldPos = rotatedPos + vec4(cPos + vec3(0.5), 0);
|
||||
|
||||
vec3 boxCoord = (worldPos.xyz - cPos - cSize * 0.5) / cSize;
|
||||
|
||||
//Light = texture(lightVolume, boxCoord).rg;
|
||||
Normal = aNormal;
|
||||
Light = vec2(1.);
|
||||
Normal = normalize((rotation * vec4(aNormal, 0.)).xyz);
|
||||
TexCoords = aTexCoords;
|
||||
gl_Position = projection * view * worldPos;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue