-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fad8c88
commit aaa7a38
Showing
16 changed files
with
380 additions
and
19 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
8 changes: 8 additions & 0 deletions
8
...n/java/org/valkyrienskies/mod/mixin/feature/ai/goal_redirector/MixinRandomStrollGoal.java
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,8 @@ | ||
package org.valkyrienskies.mod.mixin.feature.ai.goal_redirector; | ||
|
||
import net.minecraft.world.entity.ai.goal.RandomStrollGoal; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
|
||
@Mixin(RandomStrollGoal.class) | ||
public class MixinRandomStrollGoal { | ||
} |
8 changes: 8 additions & 0 deletions
8
...lkyrienskies/mod/mixin/feature/ai/goal_redirector/MixinWaterAvoidingRandomStrollGoal.java
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,8 @@ | ||
package org.valkyrienskies.mod.mixin.feature.ai.goal_redirector; | ||
|
||
import net.minecraft.world.entity.ai.goal.WaterAvoidingRandomStrollGoal; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
|
||
@Mixin(WaterAvoidingRandomStrollGoal.class) | ||
public class MixinWaterAvoidingRandomStrollGoal { | ||
} |
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
44 changes: 44 additions & 0 deletions
44
...rc/main/java/org/valkyrienskies/mod/mixin/feature/entity_collision/MixinLivingEntity.java
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,44 @@ | ||
package org.valkyrienskies.mod.mixin.feature.entity_collision; | ||
|
||
import net.minecraft.client.multiplayer.ClientLevel; | ||
import net.minecraft.client.player.LocalPlayer; | ||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.entity.EntityType; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.level.Level; | ||
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.valkyrienskies.core.api.ships.ClientShip; | ||
import org.valkyrienskies.mod.common.VSGameUtilsKt; | ||
import org.valkyrienskies.mod.common.util.EntityDraggingInformation; | ||
import org.valkyrienskies.mod.common.util.EntityLerper; | ||
import org.valkyrienskies.mod.common.util.IEntityDraggingInformationProvider; | ||
import org.valkyrienskies.mod.util.LoggingKt; | ||
|
||
@Mixin(LivingEntity.class) | ||
public abstract class MixinLivingEntity extends Entity { | ||
|
||
public MixinLivingEntity(EntityType<?> entityType, Level level) { | ||
super(entityType, level); | ||
} | ||
|
||
@Inject( | ||
method = "aiStep", | ||
at = @At(value = "HEAD") | ||
) | ||
private void preAiStep(CallbackInfo ci) { | ||
// fake lerp movement gaming | ||
if (this.level != null && this.level.isClientSide() && !firstTick) { | ||
if (((Object) this) instanceof LocalPlayer) return; | ||
EntityDraggingInformation dragInfo = ((IEntityDraggingInformationProvider) this).getDraggingInformation(); | ||
if (dragInfo != null && dragInfo.getLastShipStoodOn() != null) { | ||
final ClientShip ship = VSGameUtilsKt.getShipObjectWorld((ClientLevel) level).getAllShips().getById(dragInfo.getLastShipStoodOn()); | ||
if (ship != null) { | ||
//EntityLerper.INSTANCE.lerpStep(dragInfo, ship, (LivingEntity) (Object) this); | ||
} | ||
} | ||
} | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...rc/main/java/org/valkyrienskies/mod/mixin/feature/entity_collision/MixinServerEntity.java
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,69 @@ | ||
package org.valkyrienskies.mod.mixin.feature.entity_collision; | ||
|
||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import java.util.function.Consumer; | ||
import net.minecraft.network.protocol.game.ClientboundMoveEntityPacket; | ||
import net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket; | ||
import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket; | ||
import net.minecraft.server.level.ServerEntity; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.world.entity.Entity; | ||
import org.joml.Vector3d; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.valkyrienskies.core.api.ships.ServerShip; | ||
import org.valkyrienskies.mod.common.VSGameUtilsKt; | ||
import org.valkyrienskies.mod.common.ValkyrienSkiesMod; | ||
import org.valkyrienskies.mod.common.networking.PacketEntityShipMotion; | ||
import org.valkyrienskies.mod.common.util.EntityDraggingInformation; | ||
import org.valkyrienskies.mod.common.util.IEntityDraggingInformationProvider; | ||
|
||
@Mixin(ServerEntity.class) | ||
public class MixinServerEntity { | ||
|
||
@Shadow | ||
@Final | ||
private Entity entity; | ||
|
||
@Shadow | ||
@Final | ||
private ServerLevel level; | ||
|
||
@WrapOperation( | ||
method = "sendChanges", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Ljava/util/function/Consumer;accept(Ljava/lang/Object;)V") | ||
) | ||
private void wrapBroadcastAccept(Consumer instance, Object t, Operation<Void> original) { | ||
if (t instanceof ClientboundSetEntityMotionPacket || t instanceof ClientboundTeleportEntityPacket || t instanceof ClientboundMoveEntityPacket) { | ||
if (entity instanceof IEntityDraggingInformationProvider draggedEntity) { | ||
EntityDraggingInformation dragInfo = draggedEntity.getDraggingInformation(); | ||
|
||
if (dragInfo != null && dragInfo.isEntityBeingDraggedByAShip() && dragInfo.getLastShipStoodOn() != null) { | ||
ServerShip ship = VSGameUtilsKt.getShipObjectWorld(level).getAllShips().getById(dragInfo.getLastShipStoodOn()); | ||
if (ship != null) { | ||
Vector3d position = ship.getWorldToShip().transformPosition(new Vector3d(entity.getX(), entity.getY(), entity.getZ())); | ||
Vector3d motion = ship.getTransform().transformDirectionNoScalingFromWorldToShip(new Vector3d(entity.getDeltaMovement().x(), entity.getDeltaMovement().y(), entity.getDeltaMovement().z()), new Vector3d()); | ||
Vector3d entityLookYawOnly = new Vector3d(Math.sin(-Math.toRadians(entity.getYRot())), 0.0, Math.cos(-Math.toRadians(entity.getYRot()))); | ||
double yaw = ship.getTransform().transformDirectionNoScalingFromWorldToShip(entityLookYawOnly, new Vector3d()).y; | ||
double pitch = entity.getXRot(); | ||
PacketEntityShipMotion vsPacket = new PacketEntityShipMotion(entity.getId(), ship.getId(), | ||
position.x, position.y, position.z, | ||
motion.x, motion.y, motion.z, | ||
yaw, pitch); | ||
|
||
ValkyrienSkiesMod.getVsCore().getSimplePacketNetworking().sendToAllClients(vsPacket); | ||
return; | ||
} | ||
|
||
|
||
} | ||
} | ||
} | ||
original.call(instance, t); | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
common/src/main/kotlin/org/valkyrienskies/mod/common/networking/PacketEntityShipMotion.kt
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,20 @@ | ||
package org.valkyrienskies.mod.common.networking | ||
|
||
import org.valkyrienskies.core.impl.networking.simple.SimplePacket | ||
|
||
/** | ||
* This packet is used to update an entity's relative position while being dragged by a ship, in place of | ||
* [net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket], [net.minecraft.network.protocol.game.ClientboundMoveEntityPacket], and [net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket]. | ||
*/ | ||
data class PacketEntityShipMotion( | ||
val entityID: Int, | ||
val shipID: Long, | ||
val x: Double, | ||
val y: Double, | ||
val z: Double, | ||
val xVel: Double, | ||
val yVel: Double, | ||
val zVel: Double, | ||
val yRot: Double, | ||
val xRot: Double, | ||
): SimplePacket |
Oops, something went wrong.