Skip to content

Commit d5ddba4

Browse files
committed
fix: prevent footprints from being placed without a block beneath them
1 parent d46ee0c commit d5ddba4

File tree

2 files changed

+33
-60
lines changed

2 files changed

+33
-60
lines changed

src/main/java/dev/galacticraft/mod/misc/footprint/Footprint.java

-27
Original file line numberDiff line numberDiff line change
@@ -84,33 +84,6 @@ public static Vector3d getFootprintPosition(Level level, float rotation, Vector3
8484
int mainPosX = Mth.floor(position.x());
8585
int mainPosY = Mth.floor(position.y());
8686
int mainPosZ = Mth.floor(position.z());
87-
BlockPos posMain = new BlockPos(mainPosX, mainPosY, mainPosZ);
88-
89-
// If the footprint is hovering over air...
90-
if (level.getBlockState(posMain).isAir()) {
91-
position.x += (playerCenter.x - mainPosX);
92-
position.z += (playerCenter.z - mainPosZ);
93-
94-
BlockPos pos1 = new BlockPos(Mth.floor(position.x()), Mth.floor(position.y()), Mth.floor(position.z()));
95-
// If the footprint is still over air....
96-
BlockState b2 = level.getBlockState(pos1);
97-
if (b2.isAir()) {
98-
for (Direction direction : Direction.values()) {
99-
BlockPos offsetPos = posMain.relative(direction);
100-
if (direction != Direction.DOWN && direction != Direction.UP) {
101-
if (!level.getBlockState(offsetPos).isAir()) {
102-
position.x += direction.getStepX();
103-
position.z += direction.getStepZ();
104-
break;
105-
}
106-
}
107-
}
108-
}
109-
}
110-
111-
mainPosX = Mth.floor(position.x());
112-
mainPosZ = Mth.floor(position.z());
113-
;
11487

11588
double x0 = (Math.sin((45 - rotation) / Constant.RADIANS_TO_DEGREES) * footprintScale) + position.x;
11689
double x1 = (Math.sin((135 - rotation) / Constant.RADIANS_TO_DEGREES) * footprintScale) + position.x;

src/main/java/dev/galacticraft/mod/mixin/EntityMixin.java

+33-33
Original file line numberDiff line numberDiff line change
@@ -202,43 +202,43 @@ private void tickFootprints(MoverType type, Vec3 motion, CallbackInfo ci) {
202202
if ((Object) this instanceof Player player)
203203
isFlying = player.getAbilities().flying;
204204
if (motionSqrd > 0.001 && this.level.dimensionTypeRegistration().is(GCTags.FOOTPRINTS_DIMENSIONS) && getVehicle() == null && !isFlying) {
205-
int iPosX = Mth.floor(getX());
206-
int iPosY = Mth.floor(getY() - 0.05);
207-
int iPosZ = Mth.floor(getZ());
208-
BlockPos pos1 = new BlockPos(iPosX, iPosY, iPosZ);
209-
BlockState state = this.level.getBlockState(pos1);
210-
211-
// If the block below is the moon block
212-
if (state.is(GCTags.FOOTPRINTS)) {
213-
// If it has been long enough since the last step
214-
if (galacticraft$getDistanceSinceLastStep() > 0.35) {
215-
Vector3d pos = new Vector3d(getX(), getY(), getZ());
216-
// Set the footprint position to the block below and add
217-
// random number to stop z-fighting
218-
pos.y = Mth.floor(getY()) + random.nextFloat() / 100.0F;
219-
220-
// Adjust footprint to left or right depending on step
221-
// count
222-
switch (galacticraft$getLastStep()) {
223-
case 0:
224-
pos.add(new Vector3d(Math.sin(Math.toRadians(-getYRot() + 90)) * 0.25, 0, Math.cos(Math.toRadians(-getYRot() + 90)) * 0.25));
225-
break;
226-
case 1:
227-
pos.add(new Vector3d(Math.sin(Math.toRadians(-getYRot() - 90)) * 0.25, 0, Math.cos(Math.toRadians(-getYRot() - 90)) * 0.25));
228-
break;
229-
}
230-
231-
pos = Footprint.getFootprintPosition(level, getYRot() - 180, pos, position());
205+
// If it has been long enough since the last step
206+
if (galacticraft$getDistanceSinceLastStep() > 0.35) {
207+
Vector3d pos = new Vector3d(getX(), getY(), getZ());
208+
// Set the footprint position to the block below and add
209+
// random number to stop z-fighting
210+
pos.y = Mth.floor(getY()) + random.nextFloat() / 100.0F;
211+
212+
// Adjust footprint to left or right depending on step
213+
// count
214+
switch (galacticraft$getLastStep()) {
215+
case 0:
216+
pos.add(new Vector3d(Math.sin(Math.toRadians(-getYRot() + 90)) * 0.25, 0, Math.cos(Math.toRadians(-getYRot() + 90)) * 0.25));
217+
break;
218+
case 1:
219+
pos.add(new Vector3d(Math.sin(Math.toRadians(-getYRot() - 90)) * 0.25, 0, Math.cos(Math.toRadians(-getYRot() - 90)) * 0.25));
220+
break;
221+
}
222+
223+
pos = Footprint.getFootprintPosition(level, getYRot() - 180, pos, position());
224+
225+
int iPosX = Mth.floor(pos.x);
226+
int iPosY = Mth.floor(pos.y - 0.05);
227+
int iPosZ = Mth.floor(pos.z);
228+
BlockPos blockPos = new BlockPos(iPosX, iPosY, iPosZ);
229+
BlockState state = this.level.getBlockState(blockPos);
232230

231+
// If the block below is the moon block
232+
if (state.is(GCTags.FOOTPRINTS)) {
233233
long chunkKey = ChunkPos.asLong(SectionPos.blockToSectionCoord(pos.x), SectionPos.blockToSectionCoord(pos.z));
234234
level.galacticraft$getFootprintManager().addFootprint(chunkKey, new Footprint(level.dimensionTypeRegistration().unwrapKey().get().location(), pos, getYRot(), getUUID()));
235-
236-
// Increment and cap step counter at 1
237-
galacticraft$setLastStep((galacticraft$getLastStep() + 1) % 2);
238-
galacticraft$setDistanceSinceLastStep(0);
239-
} else {
240-
galacticraft$setDistanceSinceLastStep(galacticraft$getDistanceSinceLastStep() + motionSqrd);
241235
}
236+
237+
// Increment and cap step counter at 1
238+
galacticraft$setLastStep((galacticraft$getLastStep() + 1) % 2);
239+
galacticraft$setDistanceSinceLastStep(0);
240+
} else {
241+
galacticraft$setDistanceSinceLastStep(galacticraft$getDistanceSinceLastStep() + motionSqrd);
242242
}
243243
}
244244
}

0 commit comments

Comments
 (0)