Skip to content

Commit e68a080

Browse files
committed
Fix armor stand landing and culling
1 parent 278232f commit e68a080

4 files changed

Lines changed: 41 additions & 5 deletions

File tree

common/src/main/java/dev/ryanhcode/sable/mixin/entity/entity_rendering/LevelRendererMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ private void renderEntityOnSubLevel(final Entity entity,
4444
@Local(ordinal = 5) final LocalDoubleRef entityZ,
4545
@Share("renderPose") final LocalRef<Pose3dc> renderPoseShare) {
4646
// Render the entity on the data
47-
final ClientSubLevel subLevel = (ClientSubLevel) Sable.HELPER.getContaining(entity);
47+
final ClientSubLevel subLevel = Sable.HELPER.getContainingClient(entity.getX(), entity.getZ());
4848

4949
if (subLevel == null) {
5050
// Tracking sub-levels

common/src/main/java/dev/ryanhcode/sable/mixin/entity/entity_sublevel_collision/ArmorStandMixin.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
import net.minecraft.world.entity.decoration.ArmorStand;
99
import net.minecraft.world.level.Level;
1010
import net.minecraft.world.phys.Vec3;
11+
import net.minecraft.core.BlockPos;
12+
import net.minecraft.core.Direction;
13+
import net.minecraft.world.level.block.state.BlockState;
1114
import org.spongepowered.asm.mixin.Mixin;
15+
import org.spongepowered.asm.mixin.Unique;
1216
import org.spongepowered.asm.mixin.injection.At;
1317
import org.spongepowered.asm.mixin.injection.Inject;
1418
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@@ -20,23 +24,32 @@ public ArmorStandMixin(final EntityType<?> entityType, final Level level) {
2024
super(entityType, level);
2125
}
2226

27+
@Unique
28+
private int sable$lastAttachedTick;
29+
2330
@Inject(method = "tick", at = @At("TAIL"))
2431
private void sable$postTick(final CallbackInfo ci) {
2532
if (this.level().isClientSide) return;
2633

2734
final SubLevel containingSubLevel = Sable.HELPER.getContaining(this);
2835

2936
if (containingSubLevel != null) {
30-
if (!this.onGround()) {
37+
if (this.tickCount - this.sable$lastAttachedTick > 1 && !this.onGround()) {
3138
EntitySubLevelUtil.kickEntity(containingSubLevel, this);
3239
}
3340
} else if (this.onGround()) {
3441
final SubLevel landed = Sable.HELPER.getTrackingSubLevel(this);
3542
if (landed != null) {
3643
final Vec3 shipyardPos = landed.logicalPose().transformPositionInverse(this.position());
37-
final Vec3 shipyardVel = landed.logicalPose().transformNormalInverse(this.getDeltaMovement());
38-
this.moveTo(shipyardPos.x, shipyardPos.y, shipyardPos.z);
39-
this.setDeltaMovement(shipyardVel);
44+
final BlockPos belowPos = BlockPos.containing(shipyardPos.x, shipyardPos.y - 0.5, shipyardPos.z);
45+
final BlockState belowState = this.level().getBlockState(belowPos);
46+
if (belowState.isFaceSturdy(this.level(), belowPos, Direction.UP)
47+
&& Math.abs(shipyardPos.y - (belowPos.getY() + 1)) < 0.1) {
48+
final Vec3 shipyardVel = landed.logicalPose().transformNormalInverse(this.getDeltaMovement());
49+
this.moveTo(shipyardPos.x, shipyardPos.y, shipyardPos.z);
50+
this.setDeltaMovement(shipyardVel);
51+
this.sable$lastAttachedTick = this.tickCount;
52+
}
4053
}
4154
}
4255
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package dev.ryanhcode.sable.mixin.entity.no_culling;
2+
3+
import dev.ryanhcode.sable.api.entity.EntitySubLevelUtil;
4+
import net.minecraft.world.entity.Entity;
5+
import net.minecraft.world.entity.EntityType;
6+
import net.minecraft.world.level.Level;
7+
import org.spongepowered.asm.mixin.Mixin;
8+
import org.spongepowered.asm.mixin.injection.At;
9+
import org.spongepowered.asm.mixin.injection.Inject;
10+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
11+
12+
@Mixin(Entity.class)
13+
public abstract class EntityMixin {
14+
15+
@Inject(method = "<init>", at = @At("TAIL"))
16+
private void sable$disableCullingForRetained(final EntityType<?> type, final Level level, final CallbackInfo ci) {
17+
final Entity self = (Entity) (Object) this;
18+
if (!EntitySubLevelUtil.shouldKick(self)) {
19+
self.noCulling = true;
20+
}
21+
}
22+
}

common/src/main/resources/sable.mixins.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"entity.entity_sublevel_collision.CameraMixin",
4242
"entity.entity_swimming.CameraMixin",
4343
"entity.parrot.ParrotMixin",
44+
"entity.no_culling.EntityMixin",
4445
"loaded_chunk_debug.BlockUpdatePacketMixin",
4546
"loaded_chunk_debug.ChunkBorderRendererMixin",
4647
"loaded_chunk_debug.ClientChunkCacheStorageAccessor",

0 commit comments

Comments
 (0)