Skip to content

Commit 6f35a20

Browse files
committed
added single multiblock flame!
1 parent 6b0c087 commit 6f35a20

12 files changed

Lines changed: 71 additions & 57 deletions

src/main/java/dev/propulsionteam/propulsionsimulated/content/thruster/AbstractThrusterBlockEntity.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,9 @@ public void tick() {
216216
}
217217

218218
if (shouldEmitPlume()) {
219-
if (isMeshedPlume()) emitMeshedParticles(level, worldPosition, currentBlockState);
220-
else emitPlumeParticles(level, worldPosition, currentBlockState);
219+
if (getPlumeRenderType() == PropulsionConfig.ThrusterPlumeType.PARTICLES)
220+
emitPlumeParticles(level, worldPosition, currentBlockState);
221+
else emitMeshedParticles(level, worldPosition, currentBlockState);
221222
}
222223

223224
currentTick++;
@@ -238,13 +239,6 @@ public void tick() {
238239
}
239240
}
240241

241-
/**
242-
*
243-
* @return if this thruster is a meshed plume or a particle only plume
244-
*/
245-
public boolean isMeshedPlume() {
246-
return false;
247-
}
248242

249243
public abstract void updateThrust(BlockState currentBlockState);
250244

@@ -348,6 +342,12 @@ public CreativeThrusterBlockEntity.PlumeType getPlumeType() {
348342
return CreativeThrusterBlockEntity.PlumeType.NONE;
349343
}
350344

345+
/**
346+
*
347+
* @return if this thruster is a meshed plume or a particle only plume
348+
*/
349+
public abstract PropulsionConfig.ThrusterPlumeType getPlumeRenderType();
350+
351351
public boolean isBluePlume() {
352352
return getPlumeType() == CreativeThrusterBlockEntity.PlumeType.PLASMA ||
353353
getPlumeType() == CreativeThrusterBlockEntity.PlumeType.ION;

src/main/java/dev/propulsionteam/propulsionsimulated/content/thruster/MeshedThrusterFlameUtils.java

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
import com.mojang.blaze3d.vertex.*;
55
import com.mojang.math.Axis;
66
import dev.propulsionteam.propulsionsimulated.CreatePropulsion;
7+
import dev.propulsionteam.propulsionsimulated.PropulsionConfig;
78
import dev.propulsionteam.propulsionsimulated.content.thruster.thruster.ThrusterBlock;
9+
import dev.propulsionteam.propulsionsimulated.content.thruster.thruster.ThrusterBlockEntity;
810
import dev.propulsionteam.propulsionsimulated.content.thruster.vector_thruster.VectorThrusterBlockEntity;
9-
import dev.propulsionteam.propulsionsimulated.content.thruster.vector_thruster.liquid_vector_thruster.LiquidVectorThrusterBlockEntity;
1011
import dev.ryanhcode.sable.Sable;
1112
import dev.ryanhcode.sable.sublevel.SubLevel;
1213
import net.createmod.ponder.api.level.PonderLevel;
@@ -32,9 +33,12 @@ public class MeshedThrusterFlameUtils {
3233
private static final float BLOCK_PIXEL = 1f / 16f;
3334
private static final float FLAME_PIXEL = BLOCK_PIXEL / FLAME_SIZE;
3435
protected static final float DISPLAY_THRESHOLD = 0.03f;
35-
public static final float RENDER_BOX_FLAME_LENGTH = 5.0f;
36+
public static final float RENDER_BOX_FLAME_LENGTH = 7.0f;
3637

37-
private static final boolean SINGLE_MULTIBLOCK_FLAME = false;
38+
public static boolean isSpritePlume(AbstractThrusterBlockEntity be) {
39+
return be.getPlumeRenderType() == PropulsionConfig.ThrusterPlumeType.SPRITE_MESH ||
40+
be.getPlumeRenderType() == PropulsionConfig.ThrusterPlumeType.SPRITE_MESH_SINGLE_MULTIBLOCK;
41+
}
3842

3943
public static void renderMultiblockFlame(AbstractThrusterBlockEntity be, float partialTicks, PoseStack ms, MultiBufferSource buffer, int w) {
4044
final var state = be.getBlockState();
@@ -53,11 +57,11 @@ public static void renderMultiblockFlame(AbstractThrusterBlockEntity be, float p
5357
final ShaderProgram shader = VeilRenderSystem.setShader(THRUSTER_FLAME_SHADER);
5458
boolean bluePlume = be.isBluePlume();
5559

56-
if (SINGLE_MULTIBLOCK_FLAME) {
60+
if (be.getPlumeRenderType() == PropulsionConfig.ThrusterPlumeType.SPRITE_MESH_SINGLE_MULTIBLOCK) {
5761
ms.pushPose();
58-
ms.scale(1f / w, 1f / w, 1f / w);
62+
ms.scale(w, w, w);
5963
MeshedThrusterFlameUtils.renderMeshFlame(be, partialTicks, ms, buffer, shader,
60-
bluePlume, 0 + offset.x, offset.y, 0 + offset.z, false);
64+
bluePlume, 0 + offset.x, offset.y, 0 + offset.z, true);
6165
ms.popPose();
6266
} else {
6367
for (int x = 0; x < w; x++) {
@@ -70,15 +74,17 @@ public static void renderMultiblockFlame(AbstractThrusterBlockEntity be, float p
7074
}
7175
}
7276

73-
public static void renderMeshFlame(AbstractThrusterBlockEntity be, float partialTicks, PoseStack ms, MultiBufferSource buffer, boolean isRotatedPoseStack) {
77+
public final static AABB NULL_AABB = AABB.ofSize(Vec3.ZERO, 0, 0, 0);
78+
79+
public static void renderMeshFlame(AbstractThrusterBlockEntity be, float partialTicks, PoseStack ms, MultiBufferSource buffer) {
7480
final ShaderProgram shader = VeilRenderSystem.setShader(THRUSTER_FLAME_SHADER);
75-
renderMeshFlame(be, partialTicks, ms, buffer, shader, be.isBluePlume(), 0, 0, 0, isRotatedPoseStack);
81+
renderMeshFlame(be, partialTicks, ms, buffer, shader, be.isBluePlume(), 0, 0, 0, false);
7682
}
7783

7884

7985
public static void renderMeshFlame(AbstractThrusterBlockEntity be, float partialTicks, PoseStack ms, MultiBufferSource buffer,
8086
ShaderProgram shader,
81-
boolean soulFlame, int offsetX, int offsetY, int offsetZ, boolean offsetPoseStack) {
87+
boolean soulFlame, int offsetX, int offsetY, int offsetZ, boolean crossed) {
8288
if (shader != null) {
8389
//Get the interpolated power
8490
float power = Mth.clamp(be.interpolatedPower.getValue(partialTicks), 0f, 1f);
@@ -97,12 +103,7 @@ public static void renderMeshFlame(AbstractThrusterBlockEntity be, float partial
97103
rotateTowardsFacing(ms, facing);
98104
ms.translate(offsetX, offsetY, offsetZ);
99105

100-
if (offsetPoseStack) {//TODO: Fix this when I learn how to properly rotate the billboard
101-
//V2 isnt really that bad, but It seemed like there was a bit of a tradeoff with how the billboard behaved
102-
ms.mulPose(Axis.YP.rotation(getBillboardAngleV2(be, pos, ms, partialTicks)));
103-
} else {
104-
ms.mulPose(Axis.YP.rotation(getBillboardAngleV1(be, pos, facing, flameOffset, partialTicks)));
105-
}
106+
106107
float r = random01( //Randomness of the flame to prevent flames next to each other from looking the same
107108
(pos.getX() + offsetX) * 73856093L ^ (pos.getY() + offsetY) * 19349663L ^ (pos.getZ() + offsetZ) * 83492791L);
108109
float shaderTime = r + (be.getLevel().getGameTime() + partialTicks) * 0.1f;
@@ -111,7 +112,14 @@ public static void renderMeshFlame(AbstractThrusterBlockEntity be, float partial
111112
shader.getUniformSafe("Palette").setFloat(soulFlame ? 1 : 0); //Soul Fire modifier
112113
shader.getUniformSafe("LengthMultiplier").setFloat(Math.max(lengthMultiplier, FLAME_PIXEL));
113114
shader.getUniformSafe("WidthMultiplier").setFloat(Math.max(widthMultiplier, FLAME_PIXEL));
115+
116+
ms.mulPose(Axis.YP.rotation(getBillboardAngleV1(be, pos, facing, flameOffset, partialTicks)));
117+
if (crossed) ms.mulPose(Axis.YP.rotation((float) (Math.PI / 4)));
114118
renderFlame(ms, FLAME_SIZE, lengthMultiplier, widthMultiplier);
119+
if (crossed) {
120+
ms.mulPose(Axis.YP.rotation((float) (Math.PI / 2)));
121+
renderFlame(ms, FLAME_SIZE, lengthMultiplier, widthMultiplier);
122+
}
115123
ms.popPose();
116124
}
117125
}
@@ -163,11 +171,14 @@ public static float random01(long seed) {
163171
}
164172

165173
public static AABB inflateRenderBoundingBox(AbstractThrusterBlockEntity be, AABB box) {
166-
if (!be.isMeshedPlume()) return box;
174+
if (be.getPlumeRenderType() == PropulsionConfig.ThrusterPlumeType.PARTICLES) return box;
167175
final var state = be.getBlockState();
168176
Vec3 center = box.getCenter();
169177
float power = Mth.clamp(be.interpolatedPower.getValue(), 0f, 1f);
170178
double length = power * RENDER_BOX_FLAME_LENGTH;
179+
if (be.getPlumeRenderType() == PropulsionConfig.ThrusterPlumeType.SPRITE_MESH_SINGLE_MULTIBLOCK) {
180+
length *= be.width;
181+
}
171182

172183
Vec3 flameEnd = switch (state.getValue(ThrusterBlock.FACING)) {
173184
case DOWN -> new Vec3(center.x, box.maxY + length, center.z);
@@ -181,7 +192,7 @@ public static AABB inflateRenderBoundingBox(AbstractThrusterBlockEntity be, AABB
181192
}
182193

183194
public static AABB inflateVectorRenderBoundingBox(VectorThrusterBlockEntity be, AABB box) {
184-
if (!be.isMeshedPlume()) return box;
195+
if (be.getPlumeRenderType() == PropulsionConfig.ThrusterPlumeType.PARTICLES) return box;
185196
Vec3 center = box.getCenter();
186197
Direction facing = be.getBlockState().getValue(ThrusterBlock.FACING);
187198
float rotX = be.getInterpolatedVectorX(1) * 3;

src/main/java/dev/propulsionteam/propulsionsimulated/content/thruster/ion_thruster/IonThrusterBlockEntity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ public boolean shouldEmitPlume() {
349349
return getThrottle() > 0 && getTotalEnergyStoredFe() > 0;
350350
}
351351

352-
public boolean isMeshedPlume() {
353-
return PropulsionConfig.getIonThrusterPlumeType() == PropulsionConfig.ThrusterPlumeType.SPRITE_MESH;
352+
public PropulsionConfig.ThrusterPlumeType getPlumeRenderType() {
353+
return PropulsionConfig.getIonThrusterPlumeType();
354354
}
355355

356356
@Override

src/main/java/dev/propulsionteam/propulsionsimulated/content/thruster/ion_thruster/IonThrusterRenderer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ protected void renderSafe(IonThrusterBlockEntity be, float partialTick, PoseStac
3838
} else {
3939
if (be.isMultiblock()) {
4040
if (be.isController()) renderMultiblock(be, partialTick, ms, buffer, light, overlay);
41-
} else if (be.isMeshedPlume())
42-
MeshedThrusterFlameUtils.renderMeshFlame(be, partialTick, ms, buffer, false);
41+
} else if (MeshedThrusterFlameUtils.isSpritePlume(be))
42+
MeshedThrusterFlameUtils.renderMeshFlame(be, partialTick, ms, buffer);
4343
}
4444
}
4545

@@ -64,7 +64,7 @@ private static void renderMultiblock(IonThrusterBlockEntity be, float partialTic
6464
ms.popPose();
6565

6666
//Draw meshed thrusters
67-
if (be.isMeshedPlume()) {
67+
if (MeshedThrusterFlameUtils.isSpritePlume(be)) {
6868
MeshedThrusterFlameUtils.renderMultiblockFlame(be, partialTicks, ms, buffer, w);
6969
}
7070
}

src/main/java/dev/propulsionteam/propulsionsimulated/content/thruster/solid_fuel_thruster/SolidFuelThrusterBlockEntity.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,16 @@ public SolidFuelThrusterBlockEntity(BlockEntityType<?> type, BlockPos pos, Block
4949
super(type, pos, state);
5050
}
5151

52-
public boolean isMeshedPlume() {
53-
return PropulsionConfig.getSolidFuelThrusterPlumeType() == PropulsionConfig.ThrusterPlumeType.SPRITE_MESH;
52+
public PropulsionConfig.ThrusterPlumeType getPlumeRenderType() {
53+
return PropulsionConfig.getSolidFuelThrusterPlumeType();
5454
}
5555

5656
@Override
5757
public AABB getRenderBoundingBox() {
5858
return MeshedThrusterFlameUtils.inflateRenderBoundingBox(this, super.getRenderBoundingBox());
5959
}
6060

61+
6162
@Override
6263
public void tick() {
6364
if (level != null && !level.isClientSide) {

src/main/java/dev/propulsionteam/propulsionsimulated/content/thruster/solid_fuel_thruster/SolidFuelThrusterRenderer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public SolidFuelThrusterRenderer(BlockEntityRendererProvider.Context context) {
2626
@Override
2727
protected void renderSafe(SolidFuelThrusterBlockEntity be, float partialTick, PoseStack ms, MultiBufferSource buffer, int light, int overlay) {
2828
ThrusterDebugRenderer.render(be, ms, buffer);
29-
MeshedThrusterFlameUtils.renderMeshFlame(be, partialTick, ms, buffer, false);
29+
MeshedThrusterFlameUtils.renderMeshFlame(be, partialTick, ms, buffer);
3030
}
3131

3232
}

src/main/java/dev/propulsionteam/propulsionsimulated/content/thruster/thruster/ThrusterBlockEntity.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ public boolean isController() {
8181
return controllerPos == null;
8282
}
8383

84-
public boolean isMeshedPlume() {//TODO: Update these
85-
return PropulsionConfig.getThrusterPlumeType() == PropulsionConfig.ThrusterPlumeType.SPRITE_MESH;
84+
public PropulsionConfig.ThrusterPlumeType getPlumeRenderType() {
85+
return PropulsionConfig.getThrusterPlumeType();
8686
}
8787

8888

@@ -348,13 +348,14 @@ protected boolean supportsMultiblock() {
348348

349349
@Override
350350
public AABB getRenderBoundingBox() {
351-
if (isController() && isMultiblock()) {
352-
return MeshedThrusterFlameUtils.inflateRenderBoundingBox(this,
353-
new AABB(
354-
worldPosition.getX(), worldPosition.getY(), worldPosition.getZ(),
355-
worldPosition.getX() + width, worldPosition.getY() + width, worldPosition.getZ() + width));
356-
}
357-
return MeshedThrusterFlameUtils.inflateRenderBoundingBox(this, super.getRenderBoundingBox());
351+
if (isMultiblock()) {
352+
if (isController()) {
353+
return MeshedThrusterFlameUtils.inflateRenderBoundingBox(this,
354+
new AABB(
355+
worldPosition.getX(), worldPosition.getY(), worldPosition.getZ(),
356+
worldPosition.getX() + width, worldPosition.getY() + width, worldPosition.getZ() + width));
357+
}else return MeshedThrusterFlameUtils.NULL_AABB;
358+
} else return MeshedThrusterFlameUtils.inflateRenderBoundingBox(this, super.getRenderBoundingBox());
358359
}
359360

360361
private boolean isFrontLayerCell(ThrusterBlockEntity ctrl, Direction cubeFacing) {

src/main/java/dev/propulsionteam/propulsionsimulated/content/thruster/thruster/ThrusterRenderer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected void renderSafe(ThrusterBlockEntity be, float partialTick, PoseStack m
4848
MeshedThrusterFlameUtils.renderMultiblockFlame(be, partialTick, ms, buffer, w);
4949
}
5050
} else {
51-
MeshedThrusterFlameUtils.renderMeshFlame(be, partialTick, ms, buffer, false);
51+
MeshedThrusterFlameUtils.renderMeshFlame(be, partialTick, ms, buffer);
5252
}
5353
}
5454

src/main/java/dev/propulsionteam/propulsionsimulated/content/thruster/thruster/creative_thruster/CreativeThrusterBlockEntity.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ public CreativeThrusterBlockEntity(BlockPos pos, BlockState state) {
5858
this(PropulsionBlockEntities.CREATIVE_THRUSTER_BLOCK_ENTITY.get(), pos, state);
5959
}
6060

61-
public boolean isMeshedPlume() {
62-
return PropulsionConfig.getCreativeThrusterPlumeType() == PropulsionConfig.ThrusterPlumeType.SPRITE_MESH;
61+
public PropulsionConfig.ThrusterPlumeType getPlumeRenderType() {
62+
return PropulsionConfig.getCreativeThrusterPlumeType();
6363
}
6464

6565

@@ -671,13 +671,14 @@ protected void read(CompoundTag compound, net.minecraft.core.HolderLookup.Provid
671671

672672
@Override
673673
public AABB getRenderBoundingBox() {
674-
if (isController() && isMultiblock()) {
675-
return MeshedThrusterFlameUtils.inflateRenderBoundingBox(this,
676-
new AABB(
677-
worldPosition.getX(), worldPosition.getY(), worldPosition.getZ(),
678-
worldPosition.getX() + width, worldPosition.getY() + width, worldPosition.getZ() + width));
679-
}
680-
return MeshedThrusterFlameUtils.inflateRenderBoundingBox(this, super.getRenderBoundingBox());
674+
if (isMultiblock()) {
675+
if (isController()) {
676+
return MeshedThrusterFlameUtils.inflateRenderBoundingBox(this,
677+
new AABB(
678+
worldPosition.getX(), worldPosition.getY(), worldPosition.getZ(),
679+
worldPosition.getX() + width, worldPosition.getY() + width, worldPosition.getZ() + width));
680+
}else return MeshedThrusterFlameUtils.NULL_AABB;
681+
} else return MeshedThrusterFlameUtils.inflateRenderBoundingBox(this, super.getRenderBoundingBox());
681682
}
682683

683684
@Override

src/main/java/dev/propulsionteam/propulsionsimulated/content/thruster/thruster/creative_thruster/CreativeThrusterRenderer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected void renderSafe(final CreativeThrusterBlockEntity be,
4040
return;
4141
}
4242
} else {
43-
MeshedThrusterFlameUtils.renderMeshFlame(be, partialTick, ms, buffer, false);
43+
MeshedThrusterFlameUtils.renderMeshFlame(be, partialTick, ms, buffer);
4444
}
4545

4646
//Visualization

0 commit comments

Comments
 (0)