Skip to content

Commit

Permalink
Merge pull request jcm236#20 from GuyApooye/main
Browse files Browse the repository at this point in the history
Better ship and entity teleportation handler
  • Loading branch information
blockninja124 authored Jan 14, 2025
2 parents add6228 + 94d0e3c commit 7e21e19
Show file tree
Hide file tree
Showing 11 changed files with 344 additions and 25 deletions.
7 changes: 6 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ minecraft {
// Recommended logging level for the console
// You can set various levels here.
// Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
property 'forge.logging.console.level', 'debug'
property 'forge.logging.console.level', 'info'

mods {
"${mod_id}" {
Expand Down Expand Up @@ -191,6 +191,11 @@ dependencies {
implementation ("org.valkyrienskies.core:util:${vs_core_version}")
implementation fg.deobf("org.valkyrienskies:valkyrienskies-120-forge:${vs2_version}")

compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:0.4.1"))
implementation(jarJar("io.github.llamalad7:mixinextras-forge:0.4.1")) {
jarJar.ranged(it, "[0.4.1,)")
}

//implementation fg.deobf("mekanism:Mekanism:${mekanism_version}")
//runtimeOnly fg.deobf("mekanism:Mekanism:${mekanism_version}:generators")
//runtimeOnly fg.deobf("mekanism:Mekanism:${mekanism_version}:additions")
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/jcm/vsch/VSCHEvents.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.jcm.vsch;

import com.mojang.logging.LogUtils;
import net.jcm.vsch.entity.VSCHEntities;
import net.lointain.cosmos.network.CosmosModVariables;
import net.jcm.vsch.event.GravityInducer;
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/net/jcm/vsch/ducks/IEntityDuck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.jcm.vsch.ducks;

import net.minecraft.world.entity.Entity;

public interface IEntityDuck {
Entity vsch$getNewEntity();
}
6 changes: 4 additions & 2 deletions src/main/java/net/jcm/vsch/event/AtmosphericCollision.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.jcm.vsch.event;

import net.jcm.vsch.util.TeleportUtils;
import net.jcm.vsch.util.TeleportationHandler;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.nbt.Tag;
Expand All @@ -12,8 +13,10 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.joml.Vector3d;
import org.valkyrienskies.core.api.ships.Ship;
import org.valkyrienskies.mod.common.VSGameUtilsKt;
import org.valkyrienskies.mod.common.ValkyrienSkiesMod;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -79,8 +82,7 @@ public static void atmosphericCollisionTick(ServerLevel level, LevelAccessor wor
}*/

TeleportUtils.teleportShipAndConstrained(ship, level, gotoDimension, posX, posY, posZ);

new TeleportationHandler(VSCHUtils.dimToLevel(ValkyrienSkiesMod.getCurrentServer(), gotoDimension), level, false).handleTeleport(ship, new Vector3d(posX, posY, posZ));

}
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/net/jcm/vsch/event/PlanetCollision.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import io.netty.buffer.Unpooled;
import net.jcm.vsch.VSCHMod;
import net.jcm.vsch.util.TeleportUtils;
import net.jcm.vsch.util.TeleportationHandler;
import net.jcm.vsch.util.VSCHUtils;
import net.lointain.cosmos.network.CosmosModVariables;
import net.lointain.cosmos.world.inventory.LandingSelectorMenu;
Expand All @@ -25,9 +25,11 @@
import net.minecraftforge.network.NetworkHooks;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.joml.Vector3d;
import org.valkyrienskies.core.api.ships.Ship;
import org.valkyrienskies.core.util.datastructures.DenseBlockPosSet;
import org.valkyrienskies.mod.common.VSGameUtilsKt;
import org.valkyrienskies.mod.common.ValkyrienSkiesMod;
import org.valkyrienskies.mod.common.util.VectorConversionsMCKt;

import java.util.List;
Expand Down Expand Up @@ -102,7 +104,7 @@ public static void playerMenuTick(Player player, Ship ship, ServerLevel level, C
return;
}
logger.info("[VSCH]: Teleporting VS ship into planet!");
TeleportUtils.teleportShipAndConstrained(ship, level, dimension, posX, posY, posZ);
new TeleportationHandler(VSCHUtils.dimToLevel(ValkyrienSkiesMod.getCurrentServer(), dimension), level, true).handleTeleport(ship, new Vector3d(posX, posY, posZ));
vars.landing_coords = "^";
vars.check_collision = true;
vars.syncPlayerVariables(player);
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/net/jcm/vsch/mixin/MixinEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package net.jcm.vsch.mixin;

import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
import net.jcm.vsch.ducks.IEntityDuck;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.RelativeMovement;
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.CallbackInfoReturnable;

import javax.annotation.Nullable;
import java.util.Set;

@Mixin(Entity.class)
public abstract class MixinEntity implements IEntityDuck {
@Shadow public abstract void moveTo(double pX, double pY, double pZ, float pYRot, float pXRot);

@Shadow protected abstract void teleportPassengers();

@Shadow public abstract void setYHeadRot(float pYHeadRot);

@Shadow public abstract void unRide();

@Shadow public abstract EntityType<?> getType();

@Shadow public abstract void setRemoved(Entity.RemovalReason pRemovalReason);

@Shadow @Nullable private Entity vehicle;

@Unique
private Entity vsch$weirdEntity;

public Entity vsch$getNewEntity() {
return vsch$weirdEntity;
}

@Inject(method = "teleportTo(Lnet/minecraft/server/level/ServerLevel;DDDLjava/util/Set;FF)Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;addDuringTeleport(Lnet/minecraft/world/entity/Entity;)V"))
private void getNewEntity(ServerLevel pLevel, double pX, double pY, double pZ, Set<RelativeMovement> pRelativeMovements, float pYRot, float pXRot, CallbackInfoReturnable<Boolean> cir, @Local(name = "entity") Entity entity) {
vsch$weirdEntity = entity;
}
}
43 changes: 43 additions & 0 deletions src/main/java/net/jcm/vsch/util/ShipUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package net.jcm.vsch.util;

import net.minecraft.world.entity.Entity;
import org.joml.Quaterniond;
import org.joml.Vector3d;
import org.valkyrienskies.core.api.ships.Ship;
import org.valkyrienskies.core.api.ships.properties.ShipTransform;
import org.valkyrienskies.core.apigame.physics.PhysicsEntityServer;
import org.valkyrienskies.core.apigame.world.ServerShipWorldCore;
import org.valkyrienskies.core.impl.game.ships.ShipObjectServerWorld;
import org.valkyrienskies.core.impl.game.ships.ShipTransformImpl;
import org.valkyrienskies.mod.common.util.EntityDraggingInformation;
import org.valkyrienskies.mod.common.util.IEntityDraggingInformationProvider;

import java.util.Objects;

public class ShipUtils {
public static ShipTransform transformFromId(Long id, ServerShipWorldCore shipWorld) {
Ship ship = shipWorld.getAllShips().getById(id);
if (ship == null) {
PhysicsEntityServer physicsEntity = ((ShipObjectServerWorld)shipWorld).getLoadedPhysicsEntities().get(id);
if (physicsEntity == null) return new ShipTransformImpl(new Vector3d(), new Vector3d(), new Quaterniond(), new Vector3d());
return physicsEntity.getShipTransform();
}
return ship.getTransform();
}

public static boolean isEntityDraggedByShip(Ship ship, Entity entity) {
IEntityDraggingInformationProvider provider = (IEntityDraggingInformationProvider) entity;
if (!provider.vs$shouldDrag()) return false;
EntityDraggingInformation information = provider.getDraggingInformation();
if (!information.isEntityBeingDraggedByAShip()) return false;
return Objects.equals(information.getLastShipStoodOn(), ship.getId());
}

public static boolean isEntityDraggedByShip(Long id, Entity entity) {
IEntityDraggingInformationProvider provider = (IEntityDraggingInformationProvider) entity;
if (!provider.vs$shouldDrag()) return false;
EntityDraggingInformation information = provider.getDraggingInformation();
if (!information.isEntityBeingDraggedByAShip()) return false;
return Objects.equals(information.getLastShipStoodOn(), id);
}
}
1 change: 1 addition & 0 deletions src/main/java/net/jcm/vsch/util/TeleportUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import java.util.*;

@Deprecated(forRemoval = true)
public class TeleportUtils {
public static void teleportShipAndConstrained(Ship ship, ServerLevel level, String newDim, double x, double y, double z) {
ServerShipObjectWorldAccessor shipWorld = (ServerShipObjectWorldAccessor) VSGameUtilsKt.getShipObjectWorld(level);
Expand Down
Loading

0 comments on commit 7e21e19

Please sign in to comment.