forked from jcm236/Starlance
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request jcm236#20 from GuyApooye/main
Better ship and entity teleportation handler
- Loading branch information
Showing
11 changed files
with
344 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.