Skip to content

Commit 190c034

Browse files
committed
cleanup classes
1 parent 6f35a20 commit 190c034

8 files changed

Lines changed: 54 additions & 58 deletions

File tree

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import net.minecraft.world.level.block.entity.BlockEntityType;
3232
import net.minecraft.world.level.block.state.BlockState;
3333
import net.minecraft.world.level.ClipContext;
34+
import net.minecraft.world.phys.AABB;
3435
import net.minecraft.world.phys.Vec3;
3536
import net.minecraft.world.phys.BlockHitResult;
3637
import org.joml.Math;
@@ -44,6 +45,8 @@
4445
import dev.ryanhcode.sable.api.physics.handle.RigidBodyHandle;
4546
import dev.ryanhcode.sable.sublevel.ServerSubLevel;
4647

48+
import javax.annotation.Nullable;
49+
4750
public abstract class AbstractThrusterBlockEntity extends SmartBlockEntity
4851
implements IHaveGoggleInformation, dev.ryanhcode.sable.api.block.BlockEntitySubLevelActor, BlockSubLevelAssemblyListener {
4952
// ThrusterData thrust is stored in pN-like units where `thrustUnitsPerKn` units == 1 displayed kN.
@@ -66,11 +69,39 @@ public abstract class AbstractThrusterBlockEntity extends SmartBlockEntity
6669

6770
//Common State
6871
protected ThrusterData thrusterData;
72+
@Nullable
73+
protected BlockPos controllerPos;
6974
public int width = 1;
7075
protected String dyeId = null;
7176
protected int emptyBlocks;
7277
protected boolean isThrustDirty = false;
7378

79+
public boolean isMultiblock() {
80+
return width > 1;
81+
}
82+
83+
public boolean isController() {
84+
return controllerPos == null;
85+
}
86+
87+
abstract public boolean supportsMultiblock();
88+
89+
protected AABB getSingleRenderBox(){
90+
return super.getRenderBoundingBox();
91+
}
92+
93+
@Override
94+
public AABB getRenderBoundingBox() {
95+
if (isMultiblock()) {
96+
if (isController()) {
97+
return MeshedThrusterFlameUtils.inflateRenderBoundingBox(this,
98+
new AABB(
99+
worldPosition.getX(), worldPosition.getY(), worldPosition.getZ(),
100+
worldPosition.getX() + width, worldPosition.getY() + width, worldPosition.getZ() + width));
101+
}else return MeshedThrusterFlameUtils.NULL_AABB;
102+
} else return MeshedThrusterFlameUtils.inflateRenderBoundingBox(this, getSingleRenderBox());
103+
}
104+
74105
//Ticking
75106
private int currentTick = 0;
76107

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public static void renderMeshFlame(AbstractThrusterBlockEntity be, float partial
117117
if (crossed) ms.mulPose(Axis.YP.rotation((float) (Math.PI / 4)));
118118
renderFlame(ms, FLAME_SIZE, lengthMultiplier, widthMultiplier);
119119
if (crossed) {
120-
ms.mulPose(Axis.YP.rotation((float) (Math.PI / 2)));
120+
ms.mulPose(Axis.YP.rotation((float) -(Math.PI / 2)));
121121
renderFlame(ms, FLAME_SIZE, lengthMultiplier, widthMultiplier);
122122
}
123123
ms.popPose();
@@ -172,6 +172,7 @@ public static float random01(long seed) {
172172

173173
public static AABB inflateRenderBoundingBox(AbstractThrusterBlockEntity be, AABB box) {
174174
if (be.getPlumeRenderType() == PropulsionConfig.ThrusterPlumeType.PARTICLES) return box;
175+
175176
final var state = be.getBlockState();
176177
Vec3 center = box.getCenter();
177178
float power = Mth.clamp(be.interpolatedPower.getValue(), 0f, 1f);
@@ -195,18 +196,18 @@ public static AABB inflateVectorRenderBoundingBox(VectorThrusterBlockEntity be,
195196
if (be.getPlumeRenderType() == PropulsionConfig.ThrusterPlumeType.PARTICLES) return box;
196197
Vec3 center = box.getCenter();
197198
Direction facing = be.getBlockState().getValue(ThrusterBlock.FACING);
198-
float rotX = be.getInterpolatedVectorX(1) * 3;
199-
float rotY = be.getInterpolatedVectorY(1) * 3;
199+
float xInflate = be.getInterpolatedVectorX(1) * 3.5f;
200+
float yInflate = be.getInterpolatedVectorY(1) * 3.5f;
200201
float power = Mth.clamp(be.interpolatedPower.getValue(), 0f, 1f);
201-
double length = power * RENDER_BOX_FLAME_LENGTH - Math.max(Math.abs(rotX), Math.abs(rotY)) * 2;
202+
double length = power * RENDER_BOX_FLAME_LENGTH - Math.max(Math.abs(xInflate), Math.abs(yInflate)) * 0.8f;
202203

203204
Vector3d end = switch (facing) {
204-
case DOWN -> new Vector3d(center.x, box.maxY + length, center.z).add(rotX, 0, -rotY);
205-
case UP -> new Vector3d(center.x, box.minY - length, center.z).add(-rotX, 0, -rotY);
206-
case SOUTH -> new Vector3d(center.x, center.y, box.minZ - length).add(-rotX, rotY, 0);
207-
case NORTH -> new Vector3d(center.x, center.y, box.maxZ + length).add(rotX, rotY, 0);
208-
case WEST -> new Vector3d(box.maxX + length, center.y, center.z).add(0, rotY, -rotX);
209-
case EAST -> new Vector3d(box.minX - length, center.y, center.z).add(0, rotY, rotX);
205+
case DOWN -> new Vector3d(center.x, box.maxY + length, center.z).add(xInflate, 0, -yInflate);
206+
case UP -> new Vector3d(center.x, box.minY - length, center.z).add(-xInflate, 0, -yInflate);
207+
case SOUTH -> new Vector3d(center.x, center.y, box.minZ - length).add(-xInflate, yInflate, 0);
208+
case NORTH -> new Vector3d(center.x, center.y, box.maxZ + length).add(xInflate, yInflate, 0);
209+
case WEST -> new Vector3d(box.maxX + length, center.y, center.z).add(0, yInflate, -xInflate);
210+
case EAST -> new Vector3d(box.minX - length, center.y, center.z).add(0, yInflate, xInflate);
210211
};
211212
// System.out.println("rotx=" + rotX + " roty=" + rotY + " flameEnd=" + end + " center=" + center);
212213
return fitPoint(box, end.x, end.y, end.z);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ public boolean isIon() {
323323

324324

325325
@Override
326-
protected boolean supportsMultiblock() {
326+
public boolean supportsMultiblock() {
327327
return true;
328328
}
329329

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,10 @@ public PropulsionConfig.ThrusterPlumeType getPlumeRenderType() {
5454
}
5555

5656
@Override
57-
public AABB getRenderBoundingBox() {
58-
return MeshedThrusterFlameUtils.inflateRenderBoundingBox(this, super.getRenderBoundingBox());
57+
public boolean supportsMultiblock() {
58+
return false;
5959
}
6060

61-
6261
@Override
6362
public void tick() {
6463
if (level != null && !level.isClientSide) {

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

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ public class ThrusterBlockEntity extends AbstractThrusterBlockEntity {
4040
public SmartFluidTankBehaviour tank;
4141
public SmartFluidTankBehaviour oxidizerTank;
4242

43-
@Nullable
44-
protected BlockPos controllerPos;
4543
protected boolean updateConnectivity = true;
4644
protected double lastConsumedMbPerTick = 0.0d;
4745
protected double lastOxidizerConsumedMbPerTick = 0.0d;
@@ -73,13 +71,7 @@ public void addBehaviours(List<BlockEntityBehaviour> behaviours) {
7371
}
7472
}
7573

76-
public boolean isMultiblock() {
77-
return width > 1;
78-
}
7974

80-
public boolean isController() {
81-
return controllerPos == null;
82-
}
8375

8476
public PropulsionConfig.ThrusterPlumeType getPlumeRenderType() {
8577
return PropulsionConfig.getThrusterPlumeType();
@@ -342,20 +334,9 @@ public IFluidHandler getFluidHandler(Direction side) {
342334
return (ox != null) ? new dev.propulsionteam.propulsionsimulated.utility.MultiFluidHandler(fuel, ox) : fuel;
343335
}
344336

345-
protected boolean supportsMultiblock() {
346-
return true;
347-
}
348-
349337
@Override
350-
public AABB 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());
338+
public boolean supportsMultiblock() {
339+
return true;
359340
}
360341

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

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

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@
3737

3838
public class CreativeThrusterBlockEntity extends AbstractThrusterBlockEntity {
3939
public static final int MAX_WIDTH = 3;
40-
@Nullable
41-
protected BlockPos controllerPos;
40+
4241
protected boolean updateConnectivity = true;
4342
private static final int DISASSEMBLY_GRACE_TICKS = 5;
4443
private int disassemblyCooldown = 0;
@@ -202,17 +201,12 @@ public void tick() {
202201
}
203202
}
204203

205-
public boolean isMultiblock() {
206-
return width > 1;
207-
}
208204

209-
protected boolean supportsMultiblock() {
205+
@Override
206+
public boolean supportsMultiblock() {
210207
return true;
211208
}
212209

213-
public boolean isController() {
214-
return controllerPos == null;
215-
}
216210

217211
public boolean isBaseLayerMember() {
218212
if (!isMultiblock()) return true;
@@ -669,17 +663,7 @@ protected void read(CompoundTag compound, net.minecraft.core.HolderLookup.Provid
669663
updateConnectivity = width <= 1 || !compound.contains("UpdateConnectivity") || savedConnectivity;
670664
}
671665

672-
@Override
673-
public AABB 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());
682-
}
666+
683667

684668
@Override
685669
public void afterMove(ServerLevel oldLevel, ServerLevel newLevel, BlockState state, BlockPos oldPos, BlockPos newPos) {

src/main/java/dev/propulsionteam/propulsionsimulated/content/thruster/vector_thruster/VectorThrusterBlockEntity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public VectorThrusterBlockEntity(BlockPos pos, BlockState state) {
5959
}
6060

6161
@Override
62-
protected boolean supportsMultiblock() {
62+
public boolean supportsMultiblock() {
6363
return false;
6464
}
6565

@@ -155,7 +155,7 @@ public float getInterpolatedFlapProgress(float partialTick) {
155155

156156
@Override
157157
public AABB getRenderBoundingBox() {
158-
return MeshedThrusterFlameUtils.inflateVectorRenderBoundingBox(this, super.getRenderBoundingBox());
158+
return MeshedThrusterFlameUtils.inflateVectorRenderBoundingBox(this, getSingleRenderBox());
159159
}
160160

161161
/**

src/main/java/dev/propulsionteam/propulsionsimulated/content/thruster/vector_thruster/liquid_vector_thruster/LiquidVectorThrusterBlockEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ protected float calculateObstructionEffect() {
246246
}
247247

248248
@Override
249-
protected boolean supportsMultiblock() {
249+
public boolean supportsMultiblock() {
250250
return false;
251251
}
252252

0 commit comments

Comments
 (0)