From 151f5c8588b9f5ec2600dfedaf031a15c143726c Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 19 May 2026 13:28:42 +0200 Subject: [PATCH 1/3] Update AbstractMinecartMixin to handle minecart derailing --- .../AbstractMinecartMixin.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/common/src/main/java/dev/ryanhcode/sable/mixin/entity/entity_sublevel_collision/AbstractMinecartMixin.java b/common/src/main/java/dev/ryanhcode/sable/mixin/entity/entity_sublevel_collision/AbstractMinecartMixin.java index a31c7a46..b7f094fd 100644 --- a/common/src/main/java/dev/ryanhcode/sable/mixin/entity/entity_sublevel_collision/AbstractMinecartMixin.java +++ b/common/src/main/java/dev/ryanhcode/sable/mixin/entity/entity_sublevel_collision/AbstractMinecartMixin.java @@ -1,12 +1,15 @@ package dev.ryanhcode.sable.mixin.entity.entity_sublevel_collision; import dev.ryanhcode.sable.Sable; -import dev.ryanhcode.sable.index.SableTags; +import dev.ryanhcode.sable.api.entity.EntitySubLevelUtil; import dev.ryanhcode.sable.sublevel.SubLevel; +import net.minecraft.core.BlockPos; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.vehicle.AbstractMinecart; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.BaseRailBlock; +import net.minecraft.world.level.block.state.BlockState; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -15,22 +18,21 @@ @Mixin(AbstractMinecart.class) public abstract class AbstractMinecartMixin extends Entity { - public AbstractMinecartMixin(final EntityType entityType, final Level level) { super(entityType, level); } @Inject(method = "tick", at = @At("TAIL")) private void sable$postTick(final CallbackInfo ci) { - if (!this.getType().is(SableTags.DESTROY_WHEN_LEAVING_PLOT)) { - return; - } - final SubLevel containingSubLevel = Sable.HELPER.getContaining(this); + if (containingSubLevel == null) return; + + final BlockPos pos = this.blockPosition(); + final BlockState here = this.level().getBlockState(pos); + final BlockState below = this.level().getBlockState(pos.below()); + + if (BaseRailBlock.isRail(here) || BaseRailBlock.isRail(below)) return; - // Destroy us if we're in #sable:destroy_when_leaving_plot and we've left the plot - if (containingSubLevel != null && !this.getBoundingBox().intersects(containingSubLevel.getPlot().getBoundingBox().toAABB().inflate(0.5))) { - this.kill(); - } + EntitySubLevelUtil.kickEntity(containingSubLevel, this); } } From db2ca264d7019b769df6aa8dfcc5e2ff14db76dc Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 19 May 2026 18:11:32 +0200 Subject: [PATCH 2/3] fixed THIS WILL ACTUALLY WORK THIS TIME --- .../AbstractMinecartMixin.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/common/src/main/java/dev/ryanhcode/sable/mixin/entity/entity_sublevel_collision/AbstractMinecartMixin.java b/common/src/main/java/dev/ryanhcode/sable/mixin/entity/entity_sublevel_collision/AbstractMinecartMixin.java index b7f094fd..05f711f8 100644 --- a/common/src/main/java/dev/ryanhcode/sable/mixin/entity/entity_sublevel_collision/AbstractMinecartMixin.java +++ b/common/src/main/java/dev/ryanhcode/sable/mixin/entity/entity_sublevel_collision/AbstractMinecartMixin.java @@ -3,14 +3,12 @@ import dev.ryanhcode.sable.Sable; import dev.ryanhcode.sable.api.entity.EntitySubLevelUtil; import dev.ryanhcode.sable.sublevel.SubLevel; -import net.minecraft.core.BlockPos; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.vehicle.AbstractMinecart; import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.BaseRailBlock; -import net.minecraft.world.level.block.state.BlockState; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -22,16 +20,16 @@ public AbstractMinecartMixin(final EntityType entityType, final Level level) super(entityType, level); } + @Shadow public abstract boolean isOnRails(); + @Inject(method = "tick", at = @At("TAIL")) private void sable$postTick(final CallbackInfo ci) { + if (this.level().isClientSide) return; + final SubLevel containingSubLevel = Sable.HELPER.getContaining(this); if (containingSubLevel == null) return; - final BlockPos pos = this.blockPosition(); - final BlockState here = this.level().getBlockState(pos); - final BlockState below = this.level().getBlockState(pos.below()); - - if (BaseRailBlock.isRail(here) || BaseRailBlock.isRail(below)) return; + if (this.isOnRails()) return; EntitySubLevelUtil.kickEntity(containingSubLevel, this); } From 4ab8a73ca9106e61ebd90a67d0c575191f4ac7c1 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 19 May 2026 18:12:25 +0200 Subject: [PATCH 3/3] this should fix the issue I'm trying to fix --- .../entities_stick_sublevels/ClientPacketListenerMixin.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/dev/ryanhcode/sable/mixin/entity/entities_stick_sublevels/ClientPacketListenerMixin.java b/common/src/main/java/dev/ryanhcode/sable/mixin/entity/entities_stick_sublevels/ClientPacketListenerMixin.java index b8bc2e5e..5a1a65d1 100644 --- a/common/src/main/java/dev/ryanhcode/sable/mixin/entity/entities_stick_sublevels/ClientPacketListenerMixin.java +++ b/common/src/main/java/dev/ryanhcode/sable/mixin/entity/entities_stick_sublevels/ClientPacketListenerMixin.java @@ -105,11 +105,12 @@ public abstract class ClientPacketListenerMixin { if (subLevel != null && actuallyInSubLevel && existingSubLevel != subLevel) { entity.setPos(subLevel.logicalPose().transformPositionInverse(entity.position())); } else if (existingSubLevel != null && subLevel == null) { - entity.setPos(existingSubLevel.logicalPose().transformPosition(entity.position())); + final Vec3 newPos = existingSubLevel.logicalPose().transformPosition(entity.position()); + entity.moveTo(newPos.x, newPos.y, newPos.z); } entity.lerpTo(pX, pY, pZ, pYRot, pXRot, pLerpSteps); extension.sable$setPlotPosition(null); } } -} \ No newline at end of file +}