Skip to content

Commit

Permalink
feat: add new api methods, ShipBlockHitResult; migrate some mixins to…
Browse files Browse the repository at this point in the history
… use new api methods; command out blocks using constraints
  • Loading branch information
Rubydesic committed Dec 27, 2024
1 parent 289933e commit 1f552f9
Show file tree
Hide file tree
Showing 38 changed files with 1,450 additions and 350 deletions.
21 changes: 13 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {
id "dev.architectury.loom" version "1.3.355" apply false
id 'io.github.juuxel.loom-vineflower' version '1.11.0' apply false
// Kotlin
id "org.jetbrains.kotlin.jvm" version "1.9.10" apply false
id "org.jetbrains.kotlin.jvm" version "2.1.0" apply false
id 'com.matthewprenger.cursegradle' version '1.4.0' apply false
id "com.modrinth.minotaur" version "2.4.3" apply false
}
Expand Down Expand Up @@ -70,20 +70,25 @@ subprojects {
apply plugin: "org.jetbrains.kotlin.jvm"
apply plugin: "io.github.juuxel.loom-vineflower"

configurations.each { it.resolutionStrategy.useGlobalDependencySubstitutionRules.set(false) }

repositories {
try {
def vsCoreBuild = gradle.includedBuild("vs-core")
mavenLocal {
content {
includeGroup("org.valkyrienskies.core")

tasks.register('removeIncludedClasses') {
// IntelliJ bug: IntelliJ always adds the build/classes folder in composite builds to the classpath,
// even though we want the shadowJar stuff on the classpath rather than build/classes
//
// To fix this, we just delete it. Very reliable and supported and not cursed at all.
doLast {
new File(vsCoreBuild.projectDir, "build/classes").deleteDir()
}
}

[':impl', ':api', ':api-game'].each {
compileJava.dependsOn(vsCoreBuild.task("${it}:publishToMavenLocal"))
tasks.named('classes') {
finalizedBy tasks.named('removeIncludedClasses')
dependsOn vsCoreBuild.task(":shadowJar")
}

} catch (UnknownDomainObjectException ignore) {}

mavenCentral()
Expand Down
15 changes: 12 additions & 3 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,23 @@ dependencies {

modCompileOnly("maven.modrinth:sodium:${sodium_version}")

implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.1.0")

// vs-core
implementation("org.valkyrienskies.core:impl:${rootProject.vs_core_version}") {
exclude module: "netty-buffer"
exclude module: "fastutil"
exclude module: "kotlin-stdlib"
}
implementation("org.valkyrienskies.core:api:${rootProject.vs_core_version}") {
exclude module: "kotlin-stdlib"
}
implementation("org.valkyrienskies.core:api-game:${rootProject.vs_core_version}") {
exclude module: "kotlin-stdlib"
}
implementation("org.valkyrienskies.core:util:${rootProject.vs_core_version}") {
exclude module: "kotlin-stdlib"
}
implementation("org.valkyrienskies.core:api:${rootProject.vs_core_version}")
implementation("org.valkyrienskies.core:api-game:${rootProject.vs_core_version}")
implementation("org.valkyrienskies.core:util:${rootProject.vs_core_version}")

// FTB Stuffs
modCompileOnly("curse.maven:ftb-util-404465:4210935")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.valkyrienskies.mod.common.VSGameUtilsKt;
import org.valkyrienskies.mod.api.ValkyrienSkies;

@Mixin(ConduitBlockEntity.class)
public class ConduitMixin extends BlockEntity {
Expand All @@ -31,12 +31,7 @@ public ConduitMixin(final BlockEntityType<?> blockEntityType, final BlockPos blo
)
private static boolean closerThan(final BlockPos instance, final Vec3i vec3i, final double distance,
final Level level, final BlockPos blockPos, final List<BlockPos> list) {
final double retValue =
VSGameUtilsKt.squaredDistanceBetweenInclShips(level, instance.getX(), instance.getY(), instance.getZ(),
vec3i.getX(),
vec3i.getY(),
vec3i.getZ());
return retValue < distance * distance;
return ValkyrienSkies.closerThan(level, instance, vec3i, distance);
}

@Redirect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
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.core.api.ships.ServerShip;
import org.valkyrienskies.core.api.ships.LoadedServerShip;
import org.valkyrienskies.mod.common.VSGameUtilsKt;
import org.valkyrienskies.mod.common.config.VSGameConfig;
import org.valkyrienskies.mod.common.util.GameTickForceApplier;
Expand Down Expand Up @@ -74,8 +74,8 @@ private void doExplodeForce() {
ClipContext.Fluid.NONE, null));
if (result.getType() == Type.BLOCK) {
final BlockPos blockPos = result.getBlockPos();
final ServerShip ship =
(ServerShip) VSGameUtilsKt.getShipObjectManagingPos(this.level, blockPos);
final LoadedServerShip ship =
(LoadedServerShip) VSGameUtilsKt.getShipObjectManagingPos(this.level, blockPos);
if (ship != null) {
final Vector3d forceVector =
VectorConversionsMCKt.toJOML(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import net.minecraft.world.phys.AABB;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.valkyrienskies.mod.common.VSGameUtilsKt;
import org.valkyrienskies.mod.api.ValkyrienSkies;

/**
* Transform the player's vehicle's bounding box to the shipyard, preventing the 'collision box too big' error.
Expand All @@ -29,6 +29,6 @@ protected MixinPlayer(final EntityType<? extends LivingEntity> entityType,
)
)
private AABB transformBoundingBoxToWorld(final AABB aabb) {
return VSGameUtilsKt.transformAabbToWorld(this.level(), aabb);
return ValkyrienSkies.toWorld(this.level(), aabb);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
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.common.VSGameUtilsKt;
import org.valkyrienskies.mod.api.ValkyrienSkies;
import org.valkyrienskies.mod.common.config.VSGameConfig;

@Mixin(NaturalSpawner.class)
Expand All @@ -18,7 +18,7 @@ public class NaturalSpawnerMixin {
private static void determineSpawningOnShips(final ServerLevel level, final LevelChunk chunk,
final SpawnState spawnState,
final boolean spawnFriendlies, final boolean spawnMonsters, final boolean bl, final CallbackInfo ci) {
if (VSGameUtilsKt.isChunkInShipyard(level, chunk.getPos().x, chunk.getPos().z)) {
if (ValkyrienSkies.isChunkInShipyard(level, chunk.getPos().x, chunk.getPos().z)) {
if (!VSGameConfig.SERVER.getAllowMobSpawns()) {
ci.cancel();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.spongepowered.asm.mixin.injection.At;
import org.valkyrienskies.core.api.ships.ClientShip;
import org.valkyrienskies.core.api.ships.Ship;
import org.valkyrienskies.mod.common.VSGameUtilsKt;
import org.valkyrienskies.mod.api.ValkyrienSkies;

/**
* This mixin fixes {@link BlockEntity}s belonging to ships not rendering.
Expand Down Expand Up @@ -48,7 +48,7 @@ private <E extends BlockEntity> boolean isTileEntityInRenderRange(final BlockEnt

// If by default was false, then check if this BlockEntity belongs to a ship
final BlockPos bePos = blockEntity.getBlockPos();
final Ship nullableShip = VSGameUtilsKt.getShipObjectManagingPos(level, bePos);
final Ship nullableShip = ValkyrienSkies.getShipManagingBlock(level, bePos);
if (nullableShip instanceof ClientShip ship) {
final Matrix4dc m = ship.getRenderTransform().getShipToWorld();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.valkyrienskies.core.api.ships.Ship;
import org.valkyrienskies.mod.common.VSGameUtilsKt;
import org.valkyrienskies.mod.api.ValkyrienSkies;
import org.valkyrienskies.mod.common.config.VSGameConfig;
import org.valkyrienskies.mod.common.entity.ShipyardPosSavable;
import org.valkyrienskies.mod.common.util.EntityDraggingInformation;
import org.valkyrienskies.mod.common.util.IEntityDraggingInformationProvider;
import org.valkyrienskies.mod.common.util.VectorConversionsMCKt;

@Mixin(ChunkMap.class)
public class MixinChunkMap {
Expand All @@ -35,12 +34,13 @@ public class MixinChunkMap {

@Inject(method = "removeEntity", at = @At("HEAD"))
protected void unloadEntityMixin(Entity entity, CallbackInfo info) {
if (entity instanceof Mob mob) {
if (entity instanceof Mob mob && entity instanceof ShipyardPosSavable savable) {
Vector3d shipyardPos = valkyrienskies$getShipyardPos(mob);
if (shipyardPos != null &&
VSGameUtilsKt.getShipManagingPos(this.level, shipyardPos) != null &&
((ShipyardPosSavable)mob).valkyrienskies$getUnloadedShipyardPos() == null) {
((ShipyardPosSavable)mob).valkyrienskies$setUnloadedShipyardPos(shipyardPos);
ValkyrienSkies.getShipManagingBlock(this.level, shipyardPos) != null &&
savable.valkyrienskies$getUnloadedShipyardPos() == null
) {
savable.valkyrienskies$setUnloadedShipyardPos(shipyardPos);
}
}
}
Expand All @@ -53,13 +53,13 @@ protected void unloadEntityMixin(Entity entity, CallbackInfo info) {

@Inject(method = "addEntity", at = @At("RETURN"))
protected void loadEntityMixin(Entity entity, CallbackInfo info) {
if (entity instanceof Mob mob) {
Vector3d shipyardPos = ((ShipyardPosSavable)mob).valkyrienskies$getUnloadedShipyardPos();
if(shipyardPos != null) {
if (entity instanceof Mob mob && entity instanceof ShipyardPosSavable savable) {
Vector3d shipyardPos = savable.valkyrienskies$getUnloadedShipyardPos();
if (shipyardPos != null) {
if (VSGameConfig.SERVER.getSaveMobsPositionOnShip()){
mob.teleportTo(shipyardPos.x, shipyardPos.y, shipyardPos.z);
}
((ShipyardPosSavable) mob).valkyrienskies$setUnloadedShipyardPos(null);
savable.valkyrienskies$setUnloadedShipyardPos(null);
}
}
}
Expand All @@ -75,9 +75,9 @@ protected void loadEntityMixin(Entity entity, CallbackInfo info) {
EntityDraggingInformation dragInfo = ((IEntityDraggingInformationProvider) entity).getDraggingInformation();

if (dragInfo.getLastShipStoodOn() != null) {
Ship ship = VSGameUtilsKt.getAllShips(this.level).getById(dragInfo.getLastShipStoodOn());
if (ship != null && ship.getWorldAABB().containsPoint(VectorConversionsMCKt.toJOML(entity.position()))) {
return ship.getWorldToShip().transformPosition(VectorConversionsMCKt.toJOML(entity.position()));
Ship ship = ValkyrienSkies.getShipById(this.level, dragInfo.getLastShipStoodOn());
if (ship != null && ship.getWorldAABB().containsPoint(ValkyrienSkies.toJOML(entity.position()))) {
return ship.getWorldToShip().transformPosition(ValkyrienSkies.toJOML(entity.position()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.valkyrienskies.core.api.ships.Ship;
import org.valkyrienskies.mod.api.ValkyrienSkies;
import org.valkyrienskies.mod.client.audio.SimpleSoundInstanceOnShip;
import org.valkyrienskies.mod.common.VSGameUtilsKt;

@Mixin(SimpleSoundInstance.class)
public class MixinSimpleSoundInstance {
Expand All @@ -25,7 +25,7 @@ public class MixinSimpleSoundInstance {
private static void forRecord(final SoundEvent sound, final Vec3 pos,
final CallbackInfoReturnable<SimpleSoundInstance> cir) {

final Ship ship = VSGameUtilsKt.getShipManagingPos(Minecraft.getInstance().level, pos.x(), pos.y(), pos.z());
final Ship ship = ValkyrienSkies.getShipManagingBlock(Minecraft.getInstance().level, pos.x(), pos.y(), pos.z());
if (ship != null) {
cir.setReturnValue(new SimpleSoundInstanceOnShip(
sound, SoundSource.RECORDS, 4.0F, 1.0F, SoundInstance.createUnseededRandom(), false, 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.valkyrienskies.core.api.ships.Ship;
import org.valkyrienskies.mod.common.VSGameUtilsKt;
import org.valkyrienskies.mod.api.ValkyrienSkies;
import org.valkyrienskies.mod.common.config.VSGameConfig;
import org.valkyrienskies.mod.common.util.EntityDraggingInformation;
import org.valkyrienskies.mod.common.util.IEntityDraggingInformationProvider;
Expand All @@ -42,7 +42,7 @@ void teleportToShip(final CompoundTag compoundTag, final CallbackInfo ci) {

final long lastShipId = compoundTag.getLong("LastShipId");

final Ship ship = VSGameUtilsKt.getShipObjectWorld(serverLevel()).getAllShips().getById(lastShipId);
final Ship ship = ValkyrienSkies.getShipById(serverLevel(), lastShipId);
// Don't teleport if the ship doesn't exist anymore
if (ship == null)
return;
Expand All @@ -69,7 +69,7 @@ void rememberLastShip(final CompoundTag compoundTag, final CallbackInfo ci) {
if (lastShipId == null)
return;

final Ship ship = VSGameUtilsKt.getShipObjectWorld(serverLevel()).getAllShips().getById(lastShipId);
final Ship ship = ValkyrienSkies.getShipById(serverLevel(), lastShipId);
if (ship == null)
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ private void postTick(final CallbackInfo ci) {
if (ship != null) {
try {
// This can happen if a player moves a train contraption from ship to world using a wrench
ship.getAttachment(WingManager.class)
ship.getWingManager()
.setWingGroupTransform(wingGroupId, computeContraptionWingTransform());
} catch (final Exception e) {
// I'm not sure why, but this fails sometimes. For now just catch the error and print it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.phys.Vec3;
import org.spongepowered.asm.mixin.Mixin;
import org.valkyrienskies.mod.common.VSGameUtilsKt;
import org.valkyrienskies.mod.api.ValkyrienSkies;
import traben.entity_texture_features.utils.ETFEntity;

@Mixin(value = BlockEntity.class, priority = 1200)
public abstract class MixinBlockEntity implements ETFEntity {
@Override
public float etf$distanceTo(final Entity entity) {
final var level = Minecraft.getInstance().level;
final var aW = VSGameUtilsKt.toWorldCoordinates(level, Vec3.atCenterOf(etf$getBlockPos()));
final var bW = VSGameUtilsKt.toWorldCoordinates(level, entity.position());
final var dist = aW.distanceTo(bW);
return (float) dist;
return (float) ValkyrienSkies.distance(
Minecraft.getInstance().level,
Vec3.atCenterOf(etf$getBlockPos()),
entity.position()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ public abstract class MixinMinecraftServer implements IShipObjectWorldServerProv
method = "runServer"
)
private void beforeInitServer(final CallbackInfo info) {
ValkyrienSkiesMod.setCurrentServer(MinecraftServer.class.cast(this));
ValkyrienSkiesMod.addServer(MinecraftServer.class.cast(this));
}

@Inject(at = @At("TAIL"), method = "stopServer")
private void afterStopServer(final CallbackInfo ci) {
ValkyrienSkiesMod.setCurrentServer(null);
ValkyrienSkiesMod.removeServer(MinecraftServer.class.cast(this));
}

@Nullable
Expand Down
Loading

0 comments on commit 1f552f9

Please sign in to comment.