Skip to content

Commit 76e0093

Browse files
committed
Update sable companion
1 parent 9c10a73 commit 76e0093

42 files changed

Lines changed: 162 additions & 174 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

common/src/main/java/dev/ryanhcode/sable/ActiveSableCompanion.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.ryanhcode.sable;
22

33
import dev.ryanhcode.sable.api.SubLevelHelper;
4+
import dev.ryanhcode.sable.api.entity.EntitySubLevelUtil;
45
import dev.ryanhcode.sable.api.physics.handle.RigidBodyHandle;
56
import dev.ryanhcode.sable.api.sublevel.ServerSubLevelContainer;
67
import dev.ryanhcode.sable.api.sublevel.SubLevelContainer;
@@ -11,6 +12,7 @@
1112
import dev.ryanhcode.sable.companion.math.JOMLConversion;
1213
import dev.ryanhcode.sable.companion.math.Pose3dc;
1314
import dev.ryanhcode.sable.mixinterface.clip_overwrite.LevelPoseProviderExtension;
15+
import dev.ryanhcode.sable.mixinterface.entity.entity_sublevel_collision.EntityMovementExtension;
1416
import dev.ryanhcode.sable.mixinterface.plot.SubLevelContainerHolder;
1517
import dev.ryanhcode.sable.sublevel.ClientSubLevel;
1618
import dev.ryanhcode.sable.sublevel.ServerSubLevel;
@@ -29,11 +31,14 @@
2931
import net.minecraft.world.level.Level;
3032
import net.minecraft.world.level.block.entity.BlockEntity;
3133
import net.minecraft.world.phys.Vec3;
34+
import org.jetbrains.annotations.NotNull;
3235
import org.jetbrains.annotations.Nullable;
36+
import org.joml.Quaterniondc;
3337
import org.joml.Vector3d;
3438
import org.joml.Vector3dc;
3539

3640
import java.util.List;
41+
import java.util.UUID;
3742
import java.util.function.BiFunction;
3843

3944
/**
@@ -378,6 +383,68 @@ public boolean isInPlotGrid(final Level level, final int chunkX, final int chunk
378383
return container != null && container.inBounds(chunkX, chunkZ);
379384
}
380385

386+
@Override
387+
public @Nullable SubLevel getTrackingSubLevel(final Entity entity) {
388+
return ((EntityMovementExtension) entity).sable$getTrackingSubLevel();
389+
}
390+
391+
@Override
392+
public @Nullable SubLevel getLastTrackingSubLevel(final Entity entity) {
393+
final UUID uuid = ((EntityMovementExtension) entity).sable$getLastTrackingSubLevelID();
394+
if (uuid != null) {
395+
final SubLevelContainer container = SubLevelContainer.getContainer(entity.level());
396+
return container.getSubLevel(uuid);
397+
}
398+
return null;
399+
}
400+
401+
@Override
402+
public @Nullable SubLevel getTrackingOrVehicleSubLevel(final Entity entity) {
403+
SubLevel trackingSubLevel = Sable.HELPER.getTrackingSubLevel(entity);
404+
405+
if (trackingSubLevel == null) {
406+
trackingSubLevel = Sable.HELPER.getVehicleSubLevel(entity);
407+
}
408+
409+
return trackingSubLevel;
410+
}
411+
412+
@Override
413+
public @Nullable SubLevel getVehicleSubLevel(final Entity entity) {
414+
if (entity.getVehicle() != null) {
415+
return Sable.HELPER.getContaining(entity.getVehicle());
416+
}
417+
418+
return null;
419+
}
420+
421+
@Override
422+
public @NotNull Vec3 getEyePositionInterpolated(final Entity entity, final float partialTicks) {
423+
final SubLevel trackingSubLevel = Sable.HELPER.getTrackingOrVehicleSubLevel(entity);
424+
425+
if (trackingSubLevel instanceof final ClientSubLevel clientSubLevel) {
426+
final Vector3d startPos = new Vector3d(entity.xo, entity.yo + entity.getEyeHeight(), entity.zo);
427+
final Vector3d endPos = new Vector3d(entity.getX(), entity.getY() + entity.getEyeHeight(), entity.getZ());
428+
429+
final Pose3dc renderPose = clientSubLevel.renderPose(partialTicks);
430+
clientSubLevel.lastPose().transformPositionInverse(startPos);
431+
clientSubLevel.logicalPose().transformPositionInverse(endPos);
432+
433+
startPos.lerp(endPos, partialTicks);
434+
renderPose.transformPosition(startPos);
435+
436+
return new Vec3(startPos.x, startPos.y, startPos.z);
437+
} else {
438+
return entity.getEyePosition(partialTicks);
439+
}
440+
}
441+
442+
@Override
443+
public @NotNull Vector3d getFeetPos(final Entity entity, final float distanceDown) {
444+
final Quaterniondc orientation = EntitySubLevelUtil.getCustomEntityOrientation(entity, 1.0f);
445+
return Sable.HELPER.getFeetPos(entity, distanceDown, orientation);
446+
}
447+
381448
@Override
382449
public Level getClientLevel() {
383450
throw new UnsupportedOperationException("Should not be called");
Lines changed: 5 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
package dev.ryanhcode.sable.api.entity;
22

33
import dev.ryanhcode.sable.Sable;
4-
import dev.ryanhcode.sable.api.SubLevelHelper;
5-
import dev.ryanhcode.sable.api.sublevel.SubLevelContainer;
64
import dev.ryanhcode.sable.companion.math.JOMLConversion;
7-
import dev.ryanhcode.sable.companion.math.Pose3dc;
85
import dev.ryanhcode.sable.index.SableTags;
9-
import dev.ryanhcode.sable.mixinterface.entity.entity_sublevel_collision.EntityMovementExtension;
10-
import dev.ryanhcode.sable.sublevel.ClientSubLevel;
116
import dev.ryanhcode.sable.sublevel.SubLevel;
127
import net.minecraft.commands.arguments.EntityAnchorArgument;
138
import net.minecraft.util.Mth;
@@ -16,75 +11,23 @@
1611
import net.minecraft.world.entity.projectile.AbstractArrow;
1712
import net.minecraft.world.entity.projectile.AbstractHurtingProjectile;
1813
import net.minecraft.world.phys.Vec3;
19-
import org.jetbrains.annotations.NotNull;
2014
import org.jetbrains.annotations.Nullable;
2115
import org.joml.Quaterniondc;
2216
import org.joml.Vector3d;
2317

24-
import java.util.UUID;
25-
2618
/**
2719
* Utility for operations regarding entities and sub-levels
2820
*/
2921
public class EntitySubLevelUtil {
3022

31-
/**
32-
* Queries the sub-level an entity is currently "tracking", if any.
33-
* Entities move with their tracking sub-levels, are networked in the local frame of them,
34-
* and log out with tracking points located in them.
35-
*
36-
* @param entity the entity to query the tracking sub-level of
37-
* @return the sub-level that the entity is tracking, if any
38-
*/
39-
public static @Nullable SubLevel getTrackingSubLevel(final Entity entity) {
40-
return ((EntityMovementExtension) entity).sable$getTrackingSubLevel();
41-
}
42-
43-
public static @Nullable SubLevel getLastTrackingSubLevel(final Entity entity) {
44-
final UUID uuid = ((EntityMovementExtension) entity).sable$getLastTrackingSubLevelID();
45-
if(uuid != null) {
46-
final SubLevelContainer container = SubLevelContainer.getContainer(entity.level());
47-
return container.getSubLevel(uuid);
48-
}
49-
return null;
50-
}
51-
52-
/**
53-
* Queries the sub-level an entity is currently tracking, or the vehicle sub-level.
54-
*
55-
* @param entity the entity to query
56-
* @return the sub-level that the entity is tracking or the passenger of, if any
57-
*/
58-
public static @Nullable SubLevel getTrackingOrVehicleSubLevel(final Entity entity) {
59-
SubLevel trackingSubLevel = getTrackingSubLevel(entity);
60-
61-
if (trackingSubLevel == null) {
62-
trackingSubLevel = getVehicleSubLevel(entity);
63-
}
64-
65-
return trackingSubLevel;
66-
}
67-
68-
/**
69-
* @param entity the entity to query
70-
* @return the sub-level that the entity is passenger of, if any
71-
*/
72-
public static @Nullable SubLevel getVehicleSubLevel(final Entity entity) {
73-
if (entity.getVehicle() != null) {
74-
return Sable.HELPER.getContaining(entity.getVehicle());
75-
}
76-
77-
return null;
78-
}
79-
8023
/**
8124
* Sets the old pos of an entity for no apparent movement, taking their tracking sub-level
8225
* into account.
8326
*
8427
* @param entity the entity to set the old pos of
8528
*/
8629
public static void setOldPosNoMovement(final Entity entity) {
87-
final SubLevel trackingSubLevel = getTrackingSubLevel(entity);
30+
final SubLevel trackingSubLevel = Sable.HELPER.getTrackingSubLevel(entity);
8831

8932
if (trackingSubLevel != null) {
9033
final Vec3 entityPos = entity.position();
@@ -106,29 +49,6 @@ public static void setOldPosNoMovement(final Entity entity) {
10649
}
10750
}
10851

109-
/**
110-
* Gets the interpolated eye position of an entity, taking their tracking sub-level into account.
111-
*/
112-
public static Vec3 getEyePositionInterpolated(final Entity entity, final float partialTicks) {
113-
final SubLevel trackingSubLevel = getTrackingOrVehicleSubLevel(entity);
114-
115-
if (trackingSubLevel instanceof final ClientSubLevel clientSubLevel) {
116-
final Vector3d startPos = new Vector3d(entity.xo, entity.yo + entity.getEyeHeight(), entity.zo);
117-
final Vector3d endPos = new Vector3d(entity.getX(), entity.getY() + entity.getEyeHeight(), entity.getZ());
118-
119-
final Pose3dc renderPose = clientSubLevel.renderPose(partialTicks);
120-
clientSubLevel.lastPose().transformPositionInverse(startPos);
121-
clientSubLevel.logicalPose().transformPositionInverse(endPos);
122-
123-
startPos.lerp(endPos, partialTicks);
124-
renderPose.transformPosition(startPos);
125-
126-
return new Vec3(startPos.x, startPos.y, startPos.z);
127-
} else {
128-
return entity.getEyePosition(partialTicks);
129-
}
130-
}
131-
13252
/**
13353
* Kicks an entity out of a sub-level, including velocity and position.
13454
*
@@ -137,11 +57,11 @@ public static Vec3 getEyePositionInterpolated(final Entity entity, final float p
13757
*/
13858
public static void kickEntity(final SubLevel subLevel, final Entity entity) {
13959
final Vector3d subLevelGainedVelo = new Vector3d();
140-
if (entity instanceof final AbstractHurtingProjectile ahp && ahp.accelerationPower == 0) {
141-
Sable.HELPER.getVelocity(entity.level(), JOMLConversion.toJOML(entity.position()), subLevelGainedVelo);
142-
}
60+
if (entity instanceof final AbstractHurtingProjectile ahp && ahp.accelerationPower == 0) {
61+
Sable.HELPER.getVelocity(entity.level(), JOMLConversion.toJOML(entity.position()), subLevelGainedVelo);
62+
}
14363

144-
// convert from m/s to m/t
64+
// convert from m/s to m/t
14565
subLevelGainedVelo.mul(1.0 / 20.0);
14666

14767
final Vec3 pos = entity.position();
@@ -176,23 +96,4 @@ public static Quaterniondc getCustomEntityOrientation(final Entity entity, final
17696
public static boolean hasCustomEntityOrientation(final Entity entity) {
17797
return false;
17898
}
179-
180-
public static @NotNull Vec3 getFeetPos(final Entity entity, final float distanceDown) {
181-
final Quaterniondc orientation = getCustomEntityOrientation(entity, 1.0f);
182-
183-
return getFeetPos(entity, distanceDown, orientation);
184-
}
185-
186-
public static @NotNull Vec3 getFeetPos(final Entity entity, final float distanceDown, final Quaterniondc orientation) {
187-
final Vec3 feetPos;
188-
189-
if (orientation == null) {
190-
feetPos = entity.position().subtract(0.0, distanceDown, 0.0);
191-
} else {
192-
feetPos = entity.getEyePosition().subtract(JOMLConversion.toMojang(
193-
orientation.transform(new Vector3d(0.0, distanceDown + entity.getEyeHeight(), 0.0))
194-
));
195-
}
196-
return feetPos;
197-
}
19899
}

common/src/main/java/dev/ryanhcode/sable/command/argument/SubLevelSelector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public Collection<ServerSubLevel> getSubLevels(final CommandSourceStack source)
8888
yield Collections.emptySet();
8989
}
9090

91-
final ServerSubLevel subLevel = (ServerSubLevel) EntitySubLevelUtil.getTrackingSubLevel(source.getEntity());
91+
final ServerSubLevel subLevel = (ServerSubLevel) Sable.HELPER.getTrackingSubLevel(source.getEntity());
9292

9393
if (subLevel != null) {
9494
yield Collections.singleton(subLevel);

common/src/main/java/dev/ryanhcode/sable/mixin/camera/new_camera_types/MinecraftMixin.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dev.ryanhcode.sable.mixin.camera.new_camera_types;
22

3+
import dev.ryanhcode.sable.Sable;
34
import dev.ryanhcode.sable.api.entity.EntitySubLevelUtil;
45
import dev.ryanhcode.sable.mixinhelpers.camera.new_camera_types.SableCameraTypes;
56
import dev.ryanhcode.sable.mixinterface.camera.camera_zoom.CameraZoomExtension;
@@ -50,7 +51,7 @@ public class MinecraftMixin {
5051
final Camera camera = this.gameRenderer.getMainCamera();
5152
((CameraZoomExtension) camera).sable$setZoomAmount(0.0f);
5253

53-
final SubLevel subLevel = EntitySubLevelUtil.getVehicleSubLevel(this.cameraEntity);
54+
final SubLevel subLevel = Sable.HELPER.getVehicleSubLevel(this.cameraEntity);
5455

5556
if (subLevel != null) {
5657
final Vec3 globalLookDir = subLevel.logicalPose().transformNormalInverse(this.player.getLookAngle());
@@ -62,7 +63,7 @@ public class MinecraftMixin {
6263
@Inject(method = "handleKeybinds", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Options;setCameraType(Lnet/minecraft/client/CameraType;)V", shift = At.Shift.AFTER))
6364
public void sable$postCycleCameraType(final CallbackInfo ci) {
6465
while (this.options.getCameraType() == SableCameraTypes.SUB_LEVEL_VIEW || this.options.getCameraType() == SableCameraTypes.SUB_LEVEL_VIEW_UNLOCKED) {
65-
final SubLevel subLevel = EntitySubLevelUtil.getVehicleSubLevel(this.cameraEntity);
66+
final SubLevel subLevel = Sable.HELPER.getVehicleSubLevel(this.cameraEntity);
6667
if (subLevel != null) break;
6768

6869
this.options.setCameraType(this.options.getCameraType().cycle());
@@ -73,7 +74,7 @@ public class MinecraftMixin {
7374
if (cameraType == SableCameraTypes.SUB_LEVEL_VIEW) {
7475
this.player.displayClientMessage(Component.translatable("camera_type.sub_level_view").withColor(0xffaaaaaa), true);
7576
} else if (cameraType == SableCameraTypes.SUB_LEVEL_VIEW_UNLOCKED) {
76-
final SubLevel subLevel = EntitySubLevelUtil.getVehicleSubLevel(this.cameraEntity);
77+
final SubLevel subLevel = Sable.HELPER.getVehicleSubLevel(this.cameraEntity);
7778

7879
// View view orientation
7980
if (subLevel != null) {

common/src/main/java/dev/ryanhcode/sable/mixin/clip_overwrite/EntityMixin.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package dev.ryanhcode.sable.mixin.clip_overwrite;
22

3-
import dev.ryanhcode.sable.api.entity.EntitySubLevelUtil;
3+
import dev.ryanhcode.sable.Sable;
44
import net.minecraft.world.entity.Entity;
55
import net.minecraft.world.phys.Vec3;
66
import org.spongepowered.asm.mixin.Mixin;
@@ -12,7 +12,6 @@ public class EntityMixin {
1212

1313
@Redirect(method = "pick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;getEyePosition(F)Lnet/minecraft/world/phys/Vec3;"))
1414
private Vec3 sable$getEyePosition(final Entity instance, final float partialTicks) {
15-
return EntitySubLevelUtil.getEyePositionInterpolated(instance, partialTicks);
15+
return Sable.HELPER.getEyePositionInterpolated(instance, partialTicks);
1616
}
17-
1817
}

common/src/main/java/dev/ryanhcode/sable/mixin/clip_overwrite/GameRendererMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class GameRendererMixin {
4040

4141
@Redirect(method = "pick(Lnet/minecraft/world/entity/Entity;DDF)Lnet/minecraft/world/phys/HitResult;", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;getEyePosition(F)Lnet/minecraft/world/phys/Vec3;"))
4242
private Vec3 sable$getEyePosition(final Entity instance, final float partialTicks) {
43-
return EntitySubLevelUtil.getEyePositionInterpolated(instance, partialTicks);
43+
return Sable.HELPER.getEyePositionInterpolated(instance, partialTicks);
4444
}
4545

4646
@WrapOperation(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GameRenderer;pick(F)V"))

common/src/main/java/dev/ryanhcode/sable/mixin/death_message/CombatTrackerMixin.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
44
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
5+
import dev.ryanhcode.sable.Sable;
56
import dev.ryanhcode.sable.api.entity.EntitySubLevelUtil;
67
import dev.ryanhcode.sable.sublevel.SubLevel;
78
import net.minecraft.network.chat.Component;
@@ -16,18 +17,19 @@
1617
@Mixin(CombatTracker.class)
1718
public class CombatTrackerMixin {
1819

19-
@Shadow @Final private LivingEntity mob;
20-
21-
@WrapOperation(method = "getFallMessage", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/chat/Component;translatable(Ljava/lang/String;[Ljava/lang/Object;)Lnet/minecraft/network/chat/MutableComponent;"))
22-
private MutableComponent sable$getFallMessage(String string, Object[] objects, Operation<MutableComponent> original) {
23-
LivingEntity entity = this.mob;
24-
SubLevel subLevel = EntitySubLevelUtil.getLastTrackingSubLevel(entity);
25-
if(subLevel != null && subLevel.getName() != null) {
26-
if(!subLevel.getName().isEmpty() && EntitySubLevelUtil.getTrackingSubLevel(entity) != subLevel) {
27-
return Component.translatable("death.attack.fall.from_sublevel", entity.getDisplayName(), subLevel.getName());
28-
}
29-
}
30-
return original.call(string, objects);
31-
}
20+
@Shadow
21+
@Final
22+
private LivingEntity mob;
3223

24+
@WrapOperation(method = "getFallMessage", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/chat/Component;translatable(Ljava/lang/String;[Ljava/lang/Object;)Lnet/minecraft/network/chat/MutableComponent;"))
25+
private MutableComponent sable$getFallMessage(final String string, final Object[] objects, final Operation<MutableComponent> original) {
26+
final LivingEntity entity = this.mob;
27+
final SubLevel subLevel = Sable.HELPER.getLastTrackingSubLevel(entity);
28+
if (subLevel != null && subLevel.getName() != null) {
29+
if (!subLevel.getName().isEmpty() && Sable.HELPER.getTrackingSubLevel(entity) != subLevel) {
30+
return Component.translatable("death.attack.fall.from_sublevel", entity.getDisplayName(), subLevel.getName());
31+
}
32+
}
33+
return original.call(string, objects);
34+
}
3335
}

common/src/main/java/dev/ryanhcode/sable/mixin/death_message/EntityMixin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dev.ryanhcode.sable.mixin.death_message;
22

3+
import dev.ryanhcode.sable.Sable;
34
import dev.ryanhcode.sable.api.entity.EntitySubLevelUtil;
45
import dev.ryanhcode.sable.mixinterface.entity.entity_sublevel_collision.EntityMovementExtension;
56
import net.minecraft.world.entity.Entity;
@@ -15,7 +16,7 @@ public abstract class EntityMixin {
1516
private void sable$updateLastSubLevelId(final CallbackInfo ci) {
1617
final Entity self = (Entity) (Object) this;
1718

18-
if (EntitySubLevelUtil.getTrackingSubLevel(self) == null && self.onGround()) {
19+
if (Sable.HELPER.getTrackingSubLevel(self) == null && self.onGround()) {
1920
((EntityMovementExtension) self).sable$setLastTrackingSubLevelID(null);
2021
}
2122
}

common/src/main/java/dev/ryanhcode/sable/mixin/entity/entities_stick_sublevels/EntityRenderDispatcherMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class EntityRenderDispatcherMixin {
3030
@Inject(method = "renderHitbox", at = @At("TAIL"))
3131
private static void renderHitbox(final PoseStack poseStack, final VertexConsumer vertexConsumer, final Entity entity, final float partialTicks, final float g, final float h, final float i, final CallbackInfo ci) {
3232
// collision hitbox
33-
final SubLevel tracking = EntitySubLevelUtil.getTrackingSubLevel(entity);
33+
final SubLevel tracking = Sable.HELPER.getTrackingSubLevel(entity);
3434

3535
if (tracking instanceof final ClientSubLevel clientSubLevel) {
3636
Quaterniondc customOrientation = EntitySubLevelUtil.getCustomEntityOrientation(entity, partialTicks);

0 commit comments

Comments
 (0)