Skip to content

Commit

Permalink
okay now its height is correct
Browse files Browse the repository at this point in the history
  • Loading branch information
Goby56 committed Aug 23, 2024
1 parent 4169c8e commit fb098a0
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 35 deletions.
1 change: 0 additions & 1 deletion src/main/java/com/goby56/wakes/debug/DebugCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public static int spawnWakeNode(CommandContext<FabricClientCommandSource> cmdCtx
if (!cmdCtx.getSource().getWorld().getFluidState(new BlockPos((int) pos.x, (int) Math.floor(pos.y), (int) pos.z)).isIn(FluidTags.WATER)) return 0;
WakeNode node = new WakeNode(result.getPos(), 100);
node.floodLevel = cmdCtx.getArgument("flood_level", Integer.class);
node.spawner = "Command";
WakeHandler.getInstance().insert(node);
return 1;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/goby56/wakes/duck/ProducesWake.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

public interface ProducesWake {
boolean onWaterSurface();
Integer producingWaterLevel();
void setProducingHeight(int y);
Float producingWaterLevel();
void setProducingHeight(float h);
Vec3d getPrevPos();
void setPrevPos(Vec3d pos);
Vec3d getNumericalVelocity();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/goby56/wakes/mixin/LilyPadFallMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.goby56.wakes.WakesClient;
import com.goby56.wakes.config.enums.EffectSpawningRule;
import com.goby56.wakes.duck.ProducesWake;
import com.goby56.wakes.simulation.WakeNode;
import com.goby56.wakes.utils.WakesUtils;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
Expand All @@ -27,7 +28,7 @@ public void onLandedUpon(World world, BlockState state, BlockPos pos, Entity ent
EffectSpawningRule rule = WakesUtils.getEffectRuleFromSource(entity);
ProducesWake wakeProducer = (ProducesWake) entity;
if (rule.simulateWakes) {
wakeProducer.setProducingHeight(pos.getY());
wakeProducer.setProducingHeight(pos.getY() + WakeNode.WATER_OFFSET);
WakesUtils.placeFallSplash(entity);
}
}
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/com/goby56/wakes/mixin/WakeSpawnerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public abstract class WakeSpawnerMixin implements ProducesWake {
@Unique private Vec3d numericalVelocity = Vec3d.ZERO;
@Unique private double horizontalNumericalVelocity = 0;
@Unique private double verticalNumericalVelocity = 0;
@Unique private Integer producingWaterLevel = null;
@Unique private Float producingWaterLevel = null;
@Unique private SplashPlaneParticle splashPlane;
@Unique private boolean hasRecentlyTeleported = false;

Expand Down Expand Up @@ -68,13 +68,13 @@ public void setPrevPos(Vec3d pos) {
}

@Override
public Integer producingWaterLevel() {
public Float producingWaterLevel() {
return this.producingWaterLevel;
}

@Override
public void setProducingHeight(int y) {
this.producingWaterLevel = y;
public void setProducingHeight(float h) {
this.producingWaterLevel = h;
}

@Override
Expand Down Expand Up @@ -113,8 +113,7 @@ private void tick(CallbackInfo info) {
}

if (this.onWaterSurface && !this.hasRecentlyTeleported) {
if (this.producingWaterLevel == null)
this.producingWaterLevel = (int) Math.floor(WakesUtils.getWaterLevel(this.world, thisEntity));
this.producingWaterLevel = WakesUtils.getWaterLevel(this.world, thisEntity);

Vec3d currPos = new Vec3d(thisEntity.getX(), this.producingWaterLevel, thisEntity.getZ());

Expand All @@ -138,7 +137,7 @@ private void onSwimmingStart(CallbackInfo ci) {
EffectSpawningRule rule = WakesUtils.getEffectRuleFromSource(thisEntity);
if (rule.simulateWakes) {
if (this.producingWaterLevel == null)
this.producingWaterLevel = (int) Math.floor(WakesUtils.getWaterLevel(this.world, thisEntity));
this.producingWaterLevel = WakesUtils.getWaterLevel(this.world, thisEntity);
WakesUtils.placeFallSplash(((Entity) (Object) this));
}
// TODO ADD WAKE WHEN GETTING OUT OF WATER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void tick() {

if (this.owner instanceof ProducesWake wake) {
SplashPlaneParticle splashPlane = wake.getSplashPlane();
if (splashPlane == null || wake.producingWaterLevel() == null) {
if (splashPlane == null) {
this.markDead();
return;
}
Expand All @@ -55,7 +55,7 @@ public void tick() {

Vec3d particleOffset = new Vec3d(-splashPlane.direction.z, 0f, splashPlane.direction.x).multiply(this.offset * this.owner.getWidth() / 2f);
Vec3d pos = splashPlane.getPos().add(particleOffset).add(splashPlane.direction.multiply(-0.2f));
this.setPos(pos.x, wake.producingWaterLevel(), pos.z);
this.setPos(pos.x, pos.y, pos.z);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.goby56.wakes.particle.ModParticles;
import com.goby56.wakes.particle.WithOwnerParticleType;
import com.goby56.wakes.render.SplashPlaneRenderer;
import com.goby56.wakes.simulation.WakeNode;
import com.goby56.wakes.utils.WakesUtils;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand All @@ -28,7 +29,6 @@ public class SplashPlaneParticle extends Particle {
Entity owner;
float yaw;
float prevYaw;
int ticksSinceSplash = 0;

Vec3d direction = Vec3d.ZERO;

Expand Down Expand Up @@ -68,7 +68,6 @@ public void tick() {
}

private void aliveTick(ProducesWake wakeProducer) {
this.ticksSinceSplash++;
if (this.owner instanceof BoatEntity) {
this.yaw = -this.owner.getYaw();
} else {
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/goby56/wakes/simulation/WakeNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ public class WakeNode {
public float t = 0;
public int floodLevel;

public String spawner = "Self";

//TODO MORE GENERALIZED CONSTRUCTOR
public WakeNode(Vec3d position, int initialStrength) {
this.initValues();
Expand Down
20 changes: 2 additions & 18 deletions src/main/java/com/goby56/wakes/utils/WakesUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ public static void placeFallSplash(Entity entity) {
return;
}

for (WakeNode node : WakeNode.Factory.splashNodes(entity, ((ProducesWake) entity).producingWaterLevel())) {
node.spawner = entity.getName().toString();
for (WakeNode node : WakeNode.Factory.splashNodes(entity, (int) Math.floor(((ProducesWake) entity).producingWaterLevel()))) {
instance.insert(node);
}
}
Expand Down Expand Up @@ -73,11 +72,10 @@ public static void placeWakeTrail(Entity entity) {
}
ProducesWake producer = (ProducesWake) entity;
double velocity = producer.getHorizontalVelocity();
int y = producer.producingWaterLevel();
int y = (int) Math.floor(producer.producingWaterLevel());

if (entity instanceof BoatEntity boat) {
for (WakeNode node : WakeNode.Factory.rowingNodes(boat, y)) {
node.spawner = entity.getName().toString();
wakeHandler.insert(node);
}
if (WakesClient.CONFIG_INSTANCE.spawnParticles) {
Expand All @@ -94,7 +92,6 @@ public static void placeWakeTrail(Entity entity) {
return;
}
for (WakeNode node : WakeNode.Factory.thickNodeTrail(prevPos.x, prevPos.z, entity.getX(), entity.getZ(), y, WakesClient.CONFIG_INSTANCE.initialStrength, velocity, entity.getWidth())) {
node.spawner = entity.getName().toString();
wakeHandler.insert(node);
}
}
Expand Down Expand Up @@ -230,10 +227,6 @@ public static int rgbaArr2abgrInt(int[] arr) {
return n;
}

public static BlockPos vecToBlockPos(Vec3d v) {
return new BlockPos((int) Math.floor(v.x), (int) Math.floor(v.y), (int) Math.floor(v.z));
}

public static float getWaterLevel(World world, Entity entityInWater) {
Box box = entityInWater.getBoundingBox();
return getWaterLevel(world,
Expand Down Expand Up @@ -272,13 +265,4 @@ private static float getWaterLevel(World world, int minX, int maxX, int minY, in
return maxY + 1;

}

public static boolean validNodePos(World world, BlockPos pos) {
FluidState fluidState = world.getFluidState(pos);
FluidState fluidStateAbove = world.getFluidState(pos.up());
if (fluidState.isOf(Fluids.WATER) && fluidStateAbove.isEmpty()) {
return fluidState.isStill();
}
return false;
}
}

0 comments on commit fb098a0

Please sign in to comment.