Skip to content

Commit

Permalink
Merge branch '1.20.1/main' into 1.20.1/splitting-n-sodium
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePlasticPotato authored Feb 11, 2024
2 parents c78eb8d + 93b62e4 commit 170a74a
Show file tree
Hide file tree
Showing 49 changed files with 1,096 additions and 313 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ forge*changelog.txt

# Files generated for Fabric
/fabric/src/generated/
/.architectury-transformer/debug.log
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,11 @@ Occasionally forge will break in strange ways. When this occurs, delete all the
`Error occurred during initialization of VM
Could not reserve enough space for 4194304KB object heap`
For patch the problem go to gradle.properties and change `org.gradle.jvmargs=-Xmx4096M` to `org.gradle.jvmargs=-Xmx1024` or `org.gradle.jvmargs=-Xmx4G -XX:MaxMetaspaceSize=1G` to `org.gradle.jvmargs=-Xmx1G -XX:MaxMetaspaceSize=1G`

## Attributions

Valkyrien Skies 2 was originally created by Triode and Rubydesic. You can check
other contributors by viewing the git history.

The Create compatibility code was originally and largely written by [FluffyJenkins](https://github.com/FluffyJenkins/),
but the git history was clobbered when we transferred the code from Clockwork
20 changes: 10 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,6 @@ subprojects {
includeModule "curse.maven", "kotlinforforge-351264"
}
}
maven {
name = "Valkyrien Skies Internal"
url = project.vs_maven_url ?: 'https://maven.valkyrienskies.org'
if (project.vs_maven_username && project.vs_maven_password) {
credentials {
username = project.vs_maven_username
password = project.vs_maven_password
}
}
}
if (!project.block_external_repositories) {
mavenLocal()
maven {
Expand All @@ -128,6 +118,16 @@ subprojects {
maven { url = "https://maven.cafeteria.dev/releases" } // Fake Player API
maven { url = "https://maven.jamieswhiteshirt.com/libs-release" } // Reach Entity Attributes
}
maven {
name = "Valkyrien Skies Internal"
url = project.vs_maven_url ?: 'https://maven.valkyrienskies.org'
if (project.vs_maven_username && project.vs_maven_password) {
credentials {
username = project.vs_maven_username
password = project.vs_maven_password
}
}
}
}

// Remove automatically added repos
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.spongepowered.asm.mixin.Mixins;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
import org.spongepowered.asm.service.MixinService;
import org.valkyrienskies.mod.compat.VSRenderer;

/**
Expand Down Expand Up @@ -72,6 +73,15 @@ public boolean shouldApplyMixin(final String s, final String mixinClassName) {
if (mixinClassName.contains("org.valkyrienskies.mod.mixin.feature.render_pathfinding")) {
return PATH_FINDING_DEBUG;
}
if (mixinClassName.contains("org.valkyrienskies.mod.mixin.mod_compat.create.client.trackOutlines")) {
//interactive has its own track outline stuff so disable fixed version of VS2's track outline stuff
if (classExists("org.valkyrienskies.create_interactive.mixin.client.MixinTrackBlockOutline")) {
MixinService.getService().getLogger("mixin")
.info("[VS2] found Interactive, disabling VS2's trackOutline Compat - " +
mixinClassName.substring(mixinClassName.lastIndexOf(".") + 1));
return false;
}
}

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,14 @@ public void deleteShipObjectWorldClient() {
shipObjectWorldCopy.destroyWorld();
shipObjectWorld = null;
}

@Inject(
method = "clearLevel",
at = @At("TAIL")
)
private void postClearLevel(final CallbackInfo ci) {
if (shipObjectWorld != null) {
deleteShipObjectWorldClient();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.valkyrienskies.core.api.ships.ClientShip;
import org.valkyrienskies.core.apigame.world.ClientShipWorldCore;
import org.valkyrienskies.mod.client.IVSCamera;
import org.valkyrienskies.mod.common.IShipObjectWorldClientProvider;
import org.valkyrienskies.mod.common.entity.ShipMountedToData;
import org.valkyrienskies.mod.common.VSGameUtilsKt;
import org.valkyrienskies.mod.common.util.EntityDraggingInformation;
import org.valkyrienskies.mod.common.util.IEntityDraggingInformationProvider;
import org.valkyrienskies.mod.common.util.VectorConversionsMCKt;
import org.valkyrienskies.mod.common.world.RaycastUtilsKt;
import org.valkyrienskies.mod.mixinducks.client.MinecraftDuck;

Expand Down Expand Up @@ -91,17 +94,23 @@ public HitResult modifyCrosshairTargetBlocks(final Entity receiver, final double
return pick.call(receiver, maxDistance, tickDelta, includeFluids);
}

@WrapOperation(
@Redirect(
method = "pick",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/phys/Vec3;distanceToSqr(Lnet/minecraft/world/phys/Vec3;)D"
)
)
public double correctDistanceChecks(final Vec3 instance, final Vec3 vec, final Operation<Vec3> distanceToSqr) {
return VSGameUtilsKt.squaredDistanceBetweenInclShips(this.minecraft.level,
vec.x, vec.y, vec.z,
instance.x, instance.y, instance.z);
public double correctDistanceChecks(final Vec3 instance, final Vec3 vec) {
return VSGameUtilsKt.squaredDistanceBetweenInclShips(
this.minecraft.level,
vec.x,
vec.y,
vec.z,
instance.x,
instance.y,
instance.z
);
}

@Inject(method = "render", at = @At("HEAD"))
Expand All @@ -119,18 +128,20 @@ private void preRender(final float tickDelta, final long startTime, final boolea

// Also update entity last tick positions, so that they interpolate correctly
for (final Entity entity : clientWorld.entitiesForRendering()) {
if (!((IEntityDraggingInformationProvider) entity).vs$shouldDrag()) {
continue;
}
// The position we want to render [entity] at for this frame
// This is set when an entity is mounted to a ship, or an entity is being dragged by a ship
Vector3dc entityShouldBeHere = null;

// First, try getting [entityShouldBeHere] from [shipMountedTo]
final ClientShip shipMountedTo =
VSGameUtilsKt.getShipObjectEntityMountedTo(clientWorld, entity);
// First, try getting the ship the entity is mounted to, if one exists
final ShipMountedToData shipMountedToData = VSGameUtilsKt.getShipMountedToData(entity, tickDelta);

if (shipMountedTo != null) {
if (shipMountedToData != null) {
final ClientShip shipMountedTo = (ClientShip) shipMountedToData.getShipMountedTo();
// If the entity is mounted to a ship then update their position
final Vector3dc passengerPos =
VSGameUtilsKt.getPassengerPos(entity.getVehicle(), entity.getMyRidingOffset(), tickDelta);
final Vector3dc passengerPos = shipMountedToData.getMountPosInShip();
entityShouldBeHere = shipMountedTo.getRenderTransform().getShipToWorld()
.transformPosition(passengerPos, new Vector3d());
entity.setPos(entityShouldBeHere.x(), entityShouldBeHere.y(), entityShouldBeHere.z());
Expand All @@ -143,41 +154,39 @@ private void preRender(final float tickDelta, final long startTime, final boolea
continue;
}

if (entityShouldBeHere == null) {
final EntityDraggingInformation entityDraggingInformation =
((IEntityDraggingInformationProvider) entity).getDraggingInformation();
final Long lastShipStoodOn = entityDraggingInformation.getLastShipStoodOn();
// Then try getting [entityShouldBeHere] from [entityDraggingInformation]
if (lastShipStoodOn != null && entityDraggingInformation.isEntityBeingDraggedByAShip()) {
final ClientShip shipObject =
VSGameUtilsKt.getShipObjectWorld(clientWorld).getLoadedShips().getById(lastShipStoodOn);
if (shipObject != null) {
entityDraggingInformation.setCachedLastPosition(
new Vector3d(entity.xo, entity.yo, entity.zo));
entityDraggingInformation.setRestoreCachedLastPosition(true);

// The velocity added to the entity by ship dragging
final Vector3dc entityAddedVelocity = entityDraggingInformation.getAddedMovementLastTick();

// The velocity of the entity before we added ship dragging
final double entityMovementX = entity.getX() - entityAddedVelocity.x() - entity.xo;
final double entityMovementY = entity.getY() - entityAddedVelocity.y() - entity.yo;
final double entityMovementZ = entity.getZ() - entityAddedVelocity.z() - entity.zo;

// Without ship dragging, the entity would've been here
final Vector3dc entityShouldBeHerePreTransform = new Vector3d(
entity.xo + entityMovementX * tickDelta,
entity.yo + entityMovementY * tickDelta,
entity.zo + entityMovementZ * tickDelta
);

// Move [entityShouldBeHerePreTransform] with the ship, using the prev transform and the
// current render transform
entityShouldBeHere = shipObject.getRenderTransform().getShipToWorldMatrix()
.transformPosition(
shipObject.getPrevTickShipTransform().getWorldToShipMatrix()
.transformPosition(entityShouldBeHerePreTransform, new Vector3d()));
}
final EntityDraggingInformation entityDraggingInformation =
((IEntityDraggingInformationProvider) entity).getDraggingInformation();
final Long lastShipStoodOn = entityDraggingInformation.getLastShipStoodOn();
// Then try getting [entityShouldBeHere] from [entityDraggingInformation]
if (lastShipStoodOn != null && entityDraggingInformation.isEntityBeingDraggedByAShip()) {
final ClientShip shipObject =
VSGameUtilsKt.getShipObjectWorld(clientWorld).getLoadedShips().getById(lastShipStoodOn);
if (shipObject != null) {
entityDraggingInformation.setCachedLastPosition(
new Vector3d(entity.xo, entity.yo, entity.zo));
entityDraggingInformation.setRestoreCachedLastPosition(true);

// The velocity added to the entity by ship dragging
final Vector3dc entityAddedVelocity = entityDraggingInformation.getAddedMovementLastTick();

// The velocity of the entity before we added ship dragging
final double entityMovementX = entity.getX() - entityAddedVelocity.x() - entity.xo;
final double entityMovementY = entity.getY() - entityAddedVelocity.y() - entity.yo;
final double entityMovementZ = entity.getZ() - entityAddedVelocity.z() - entity.zo;

// Without ship dragging, the entity would've been here
final Vector3dc entityShouldBeHerePreTransform = new Vector3d(
entity.xo + entityMovementX * tickDelta,
entity.yo + entityMovementY * tickDelta,
entity.zo + entityMovementZ * tickDelta
);

// Move [entityShouldBeHerePreTransform] with the ship, using the prev transform and the
// current render transform
entityShouldBeHere = shipObject.getRenderTransform().getShipToWorldMatrix()
.transformPosition(
shipObject.getPrevTickShipTransform().getWorldToShipMatrix()
.transformPosition(entityShouldBeHerePreTransform, new Vector3d()));
}
}

Expand Down Expand Up @@ -239,42 +248,44 @@ private void setupCameraWithMountedShip(final LevelRenderer instance, final Pose
prepareCullFrustum.call(instance, matrixStack, vec3, matrix4f);
return;
}
final ClientShip playerShipMountedTo =
VSGameUtilsKt.getShipObjectEntityMountedTo(clientLevel, player);
if (playerShipMountedTo == null) {

final ShipMountedToData shipMountedToData = VSGameUtilsKt.getShipMountedToData(player, partialTicks);
if (shipMountedToData == null) {
prepareCullFrustum.call(instance, matrixStack, vec3, matrix4f);
return;
}

final Entity playerVehicle = player.getVehicle();
if (playerVehicle == null) {
prepareCullFrustum.call(instance, matrixStack, vec3, matrix4f);
return;
}

// Update [matrixStack] to mount the camera to the ship
final Vector3dc inShipPos =
VSGameUtilsKt.getPassengerPos(playerVehicle, player.getMyRidingOffset(), partialTicks);

final Camera camera = this.mainCamera;
if (camera == null) {
prepareCullFrustum.call(instance, matrixStack, vec3, matrix4f);
return;
}

final ClientShip clientShip = (ClientShip) shipMountedToData.getShipMountedTo();

((IVSCamera) camera).setupWithShipMounted(
this.minecraft.level,
this.minecraft.getCameraEntity() == null ? this.minecraft.player : this.minecraft.getCameraEntity(),
!this.minecraft.options.getCameraType().isFirstPerson(),
this.minecraft.options.getCameraType().isMirrored(),
partialTicks,
playerShipMountedTo,
inShipPos
clientShip,
shipMountedToData.getMountPosInShip()
);

// Apply the ship render transform to [matrixStack]
final Quaterniond invShipRenderRotation =
playerShipMountedTo.getRenderTransform().getShipToWorldRotation().conjugate(new Quaterniond());
matrixStack.mulPose(new Quaternionf().set(invShipRenderRotation));
final Quaternionf invShipRenderRotation = new Quaternionf(
clientShip.getRenderTransform().getShipToWorldRotation().conjugate(new Quaterniond())
);
matrixStack.mulPose(invShipRenderRotation);

// We also need to recompute [inverseViewRotationMatrix] after updating [matrixStack]
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.joml.Vector3d;
import org.joml.Vector3dc;
import org.joml.primitives.AABBd;
Expand All @@ -33,6 +32,7 @@
import org.valkyrienskies.core.api.ships.Ship;
import org.valkyrienskies.core.api.ships.properties.ShipTransform;
import org.valkyrienskies.core.impl.game.ships.ShipObjectClient;
import org.valkyrienskies.mod.common.entity.ShipMountedToData;
import org.valkyrienskies.mod.common.VSGameUtilsKt;
import org.valkyrienskies.mod.common.util.EntityDraggingInformation;
import org.valkyrienskies.mod.common.util.IEntityDraggingInformationProvider;
Expand Down Expand Up @@ -105,11 +105,11 @@ private void originalCheckInside(final AABBd aABB) {
*/
@Inject(method = "getEyePosition(F)Lnet/minecraft/world/phys/Vec3;", at = @At("HEAD"), cancellable = true)
private void preGetEyePosition(final float partialTicks, final CallbackInfoReturnable<Vec3> cir) {
final LoadedShip shipMountedTo =
VSGameUtilsKt.getShipObjectEntityMountedTo(level, Entity.class.cast(this));
if (shipMountedTo == null) {
final ShipMountedToData shipMountedToData = VSGameUtilsKt.getShipMountedToData(Entity.class.cast(this), partialTicks);
if (shipMountedToData == null) {
return;
}
final LoadedShip shipMountedTo = shipMountedToData.getShipMountedTo();

final ShipTransform shipTransform;
if (shipMountedTo instanceof ShipObjectClient) {
Expand All @@ -118,24 +118,20 @@ private void preGetEyePosition(final float partialTicks, final CallbackInfoRetur
shipTransform = shipMountedTo.getShipTransform();
}
final Vector3dc basePos = shipTransform.getShipToWorldMatrix()
.transformPosition(VSGameUtilsKt.getPassengerPos(this.vehicle, getMyRidingOffset(), partialTicks),
new Vector3d());
.transformPosition(shipMountedToData.getMountPosInShip(), new Vector3d());
final Vector3dc eyeRelativePos = shipTransform.getShipCoordinatesToWorldCoordinatesRotation().transform(
new Vector3d(0.0, getEyeHeight(), 0.0)
);
final Vec3 newEyePos = VectorConversionsMCKt.toMinecraft(basePos.add(eyeRelativePos, new Vector3d()));
cir.setReturnValue(newEyePos);
}

@Shadow
private Vec3 position;

/**
* @reason Needed for players to pick blocks correctly when mounted to a ship
*/
@Inject(method = "calculateViewVector", at = @At("HEAD"), cancellable = true)
private void preCalculateViewVector(final float xRot, final float yRot, final CallbackInfoReturnable<Vec3> cir) {
final LoadedShip shipMountedTo = VSGameUtilsKt.getShipObjectEntityMountedTo(level, Entity.class.cast(this));
final LoadedShip shipMountedTo = VSGameUtilsKt.getShipMountedTo(Entity.class.cast(this));
if (shipMountedTo == null) {
return;
}
Expand Down Expand Up @@ -180,9 +176,6 @@ private void preCalculateViewVector(final float xRot, final float yRot, final Ca
@Shadow
public abstract double getX();

@Shadow
private @Nullable Entity vehicle;

@Shadow
public abstract float getEyeHeight();

Expand All @@ -191,12 +184,14 @@ private void preCalculateViewVector(final float xRot, final float yRot, final Ca
@Shadow
public abstract EntityType<?> getType();

@Shadow
public abstract double getMyRidingOffset();

@Override
@NotNull
public EntityDraggingInformation getDraggingInformation() {
return draggingInformation;
}

@Override
public boolean vs$shouldDrag() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private void beforeClose(final CallbackInfo ci) {
cancellable = true
)
private void beforeHandleLevelChunk(final ClientboundLevelChunkWithLightPacket packet, final CallbackInfo ci) {
if (chunks.queue(packet.getX(), packet.getZ(), packet, level)) {
if (level != null && chunks.queue(packet.getX(), packet.getZ(), packet, level)) {
ci.cancel();
}
}
Expand Down
Loading

0 comments on commit 170a74a

Please sign in to comment.