Skip to content

Commit

Permalink
Merge branch '1.18.x/main' of https://github.com/ValkyrienSkies/Valky…
Browse files Browse the repository at this point in the history
…rien-Skies-2 into 1.18.x/main
  • Loading branch information
ThePlasticPotato committed Jan 20, 2024
2 parents 535ef4f + 2a9c46f commit 473a1e8
Show file tree
Hide file tree
Showing 33 changed files with 1,976 additions and 169 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
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;
Expand Down Expand Up @@ -134,14 +135,13 @@ private void preRender(final float tickDelta, final long startTime, final boolea
// 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 Down Expand Up @@ -248,41 +248,43 @@ 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 Quaternion invShipRenderRotation = VectorConversionsMCKt.toMinecraft(
playerShipMountedTo.getRenderTransform().getShipToWorldRotation().conjugate(new Quaterniond()));
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,9 +184,6 @@ 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import org.joml.Vector3d;
import org.joml.Vector3dc;
import org.joml.primitives.AABBd;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import org.valkyrienskies.core.api.ships.ClientShip;
import org.valkyrienskies.core.api.ships.properties.ShipTransform;
import org.valkyrienskies.mod.common.VSGameUtilsKt;
import org.valkyrienskies.mod.common.entity.ShipMountedToData;
import org.valkyrienskies.mod.common.entity.handling.VSEntityManager;
import org.valkyrienskies.mod.common.util.VectorConversionsMCKt;

Expand All @@ -32,27 +37,53 @@ <T extends Entity> void render(
final T entity, final double x, final double y, final double z, final float rotationYaw,
final float partialTicks, final PoseStack matrixStack,
final MultiBufferSource buffer, final int packedLight, final CallbackInfo ci,
final EntityRenderer<T> entityRenderer) {
final EntityRenderer<T> entityRenderer
) {
final ShipMountedToData shipMountedToData = VSGameUtilsKt.getShipMountedToData(entity, partialTicks);

final ClientShip ship =
(ClientShip) VSGameUtilsKt.getShipObjectManagingPos(entity.level, entity.blockPosition());
if (ship != null) {
if (shipMountedToData != null) {
// Remove the earlier applied translation
matrixStack.popPose();
matrixStack.pushPose();

VSEntityManager.INSTANCE.getHandler(entity)
.applyRenderTransform(ship, entity, entityRenderer, x, y, z,
rotationYaw, partialTicks, matrixStack,
buffer, packedLight);
} else if (entity.isPassenger()) {
final ClientShip vehicleShip =
(ClientShip) VSGameUtilsKt.getShipObjectManagingPos(entity.level,
entity.getVehicle().blockPosition());
// If the entity is a passenger and that vehicle is in ship space
if (vehicleShip != null) {
VSEntityManager.INSTANCE.getHandler(entity.getVehicle())
.applyRenderOnMountedEntity(vehicleShip, entity.getVehicle(), entity, partialTicks, matrixStack);
final ShipTransform renderTransform = ((ClientShip) shipMountedToData.getShipMountedTo()).getRenderTransform();

final Vec3 entityPosition = entity.getPosition(partialTicks);
final Vector3dc transformed = renderTransform.getShipToWorld().transformPosition(shipMountedToData.getMountPosInShip(), new Vector3d());

final double camX = x - entityPosition.x;
final double camY = y - entityPosition.y;
final double camZ = z - entityPosition.z;

final Vec3 offset = entityRenderer.getRenderOffset(entity, partialTicks);
final Vector3dc scale = renderTransform.getShipToWorldScaling();

matrixStack.translate(transformed.x() + camX, transformed.y() + camY, transformed.z() + camZ);
matrixStack.mulPose(VectorConversionsMCKt.toMinecraft(renderTransform.getShipToWorldRotation()));
matrixStack.scale((float) scale.x(), (float) scale.y(), (float) scale.z());
matrixStack.translate(offset.x, offset.y, offset.z);
} else {
final ClientShip ship =
(ClientShip) VSGameUtilsKt.getShipObjectManagingPos(entity.level, entity.blockPosition());
if (ship != null) {
// Remove the earlier applied translation
matrixStack.popPose();
matrixStack.pushPose();

VSEntityManager.INSTANCE.getHandler(entity)
.applyRenderTransform(ship, entity, entityRenderer, x, y, z,
rotationYaw, partialTicks, matrixStack,
buffer, packedLight);
} else if (entity.isPassenger()) {
final ClientShip vehicleShip =
(ClientShip) VSGameUtilsKt.getShipObjectManagingPos(entity.level,
entity.getVehicle().blockPosition());
// If the entity is a passenger and that vehicle is in ship space
if (vehicleShip != null) {
VSEntityManager.INSTANCE.getHandler(entity.getVehicle())
.applyRenderOnMountedEntity(vehicleShip, entity.getVehicle(), entity, partialTicks,
matrixStack);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
package org.valkyrienskies.mod.mixin.feature.shipyard_entities;

import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import it.unimi.dsi.fastutil.longs.LongSet;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.entity.EntitySectionStorage;
import net.minecraft.world.level.entity.PersistentEntitySectionManager;
import net.minecraft.world.level.entity.Visibility;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
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.callback.CallbackInfo;
import org.valkyrienskies.mod.mixinducks.world.OfLevel;

@Mixin(PersistentEntitySectionManager.class)
public class MixinPersistentEntitySectionManager implements OfLevel {
public abstract class MixinPersistentEntitySectionManager implements OfLevel {
@Shadow
@Final
EntitySectionStorage<Entity> sectionStorage;
Expand All @@ -29,4 +36,41 @@ public void setLevel(final Level level) {
this.level = level;
((OfLevel) this.sectionStorage).setLevel(level);
}

@Shadow
@Final
private LongSet chunksToUnload;

@Shadow
@Final
private Long2ObjectMap<Visibility> chunkVisibility;

@Shadow
private boolean processChunkUnload(final long l) {
throw new IllegalStateException("This should not be invoked");
}

/**
* This fixes this function randomly crashing. I'm not sure why but the removeIf() function is buggy
*/
@Inject(
method = "processUnloads", at = @At(value = "HEAD"), cancellable = true
)
private void replaceProcessUnloads(final CallbackInfo ci) {
// I don't know why this crashes, try-catch please help me!
try {
final LongSet toRemove = new LongOpenHashSet();
for (final long key : this.chunksToUnload) {
if (this.chunkVisibility.get(key) != Visibility.HIDDEN) {
toRemove.add(key);
} else if (this.processChunkUnload(key)) {
toRemove.add(key);
}
}
chunksToUnload.removeAll(toRemove);
} catch (final Exception e) {
e.printStackTrace();
}
ci.cancel();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private void injectListenerVelocity(final Listener listener, final Vec3 position
((HasOpenALVelocity) listener).setVelocity(new Vector3d());

if (level != null && player != null) {
final ClientShip mounted = VSGameUtilsKt.getShipObjectEntityMountedTo(level, player);
final ClientShip mounted = (ClientShip) VSGameUtilsKt.getShipMountedTo(player);
if (mounted != null) {
((HasOpenALVelocity) listener).setVelocity(mounted.getVelocity());
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Create Compat

This package contains the Create compatibility code

## Attributions

Most of this code was originally created by [FluffyJenkins](https://github.com/FluffyJenkins/). However, the git history
got clobbered when we transferred it over from the Clockwork repository, causing it to be attributed to StewStrong.
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,42 @@
@Mixin(StickerBlock.class)
public abstract class MixinStickerBlock extends WrenchableDirectionalBlock implements IBE<StickerBlockEntity> {

public MixinStickerBlock(Properties properties) {
public MixinStickerBlock(final Properties properties) {
super(properties);
}

@Override
public void onRemove(@NotNull BlockState state, @NotNull Level world, @NotNull BlockPos pos, @NotNull BlockState newState, boolean isMoving) {
public void onRemove(
@NotNull final BlockState state,
@NotNull final Level world,
@NotNull final BlockPos pos,
@NotNull final BlockState newState,
final boolean isMoving
) {
IBE.onRemove(state, world, pos, newState);
}

@Inject(method = "neighborChanged", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/BlockState;getValue(Lnet/minecraft/world/level/block/state/properties/Property;)Ljava/lang/Comparable;", ordinal = 0), cancellable = true)
private void injectNeighbourChanged(BlockState state, Level worldIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving, CallbackInfo ci) {
StickerBlockEntity ste = getBlockEntity(worldIn, pos);
if (ste != null && ((IMixinStickerTileEntity) ste).isAlreadyPowered(false)) {
@Inject(
method = "neighborChanged",
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/BlockState;getValue(Lnet/minecraft/world/level/block/state/properties/Property;)Ljava/lang/Comparable;", ordinal = 0),
cancellable = true
)
private void injectNeighbourChanged(
final BlockState state,
final Level worldIn,
final BlockPos pos,
final Block blockIn,
final BlockPos fromPos,
final boolean isMoving,
final CallbackInfo ci
) {
final StickerBlockEntity ste = getBlockEntity(worldIn, pos);
// By checking `instanceof IMixinStickerTileEntity` we only run this code if Clockwork is installed
if (ste instanceof final IMixinStickerTileEntity iMixinStickerTileEntity && iMixinStickerTileEntity.isAlreadyPowered(false)) {
if (!worldIn.hasNeighborSignal(pos)) {
ci.cancel();
} else {
((IMixinStickerTileEntity) ste).isAlreadyPowered(true);
iMixinStickerTileEntity.isAlreadyPowered(true);
}
}
}
Expand Down
Loading

0 comments on commit 473a1e8

Please sign in to comment.