Skip to content

Commit

Permalink
Fix: Corrected the direction of projectiles fired when the entity is …
Browse files Browse the repository at this point in the history
…on a ship. (vanilla and TaCZ only) #66
  • Loading branch information
xiewuzhiying committed Dec 2, 2024
1 parent 3e097b0 commit 2fafdfa
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Fixed the issue of crashing with VMod in some cases.
- Fixed the issue where other players were kicked out when using the sticker from the Create mod or the gravitron from the Clockwork mod.
- Re-enabled explosion mixin, but it will still be overwritten by Lithium mixin.
- Corrected the direction of projectiles fired when the entity is on a ship. (vanilla and TaCZ only) [#66](https://github.com/xiewuzhiying/VS-Addition/issues/66)

## Fabric

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.projectile.AbstractArrow;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
import org.joml.Vector3d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
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.Ship;
import org.valkyrienskies.mod.common.VSGameUtilsKt;
import org.valkyrienskies.mod.common.util.IEntityDraggingInformationProvider;
import org.valkyrienskies.mod.common.util.VectorConversionsMCKt;

import java.util.function.Consumer;

Expand Down Expand Up @@ -43,4 +48,17 @@ public boolean shipCollision(Level level, AABB aabb, Operation<Boolean> original
VSGameUtilsKt.transformFromWorldToNearbyShipsAndWorld(level, aabb, consumer);
return original.call(level, aabb) && noShipCollision[0];
}

@Inject(
method = "<init>(Lnet/minecraft/world/entity/EntityType;Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/level/Level;)V",
at = @At("RETURN")
)
private void postInit(EntityType<? extends AbstractArrow> entityType, LivingEntity shooter, Level level, CallbackInfo ci) {
final Ship ship = VSGameUtilsKt.getShipMountedTo(shooter);
if (ship != null) {
final Vector3d pos = VectorConversionsMCKt.toJOML(shooter.position());
ship.getTransform().getWorldToShip().transformPosition(pos);
this.setPos(pos.x, pos.y + shooter.getEyeHeight() - 0.10000000149011612, pos.z);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
package io.github.xiewuzhiying.vs_addition.fabric.mixin.tacz;

import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.tacz.guns.entity.EntityKineticBullet;
import com.tacz.guns.resource.pojo.data.gun.BulletData;
import io.github.xiewuzhiying.vs_addition.mixinducks.minecraft.HitResultMixinDuck;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import org.joml.Vector3d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.valkyrienskies.core.api.ships.Ship;
import org.valkyrienskies.mod.common.VSGameUtilsKt;
import org.valkyrienskies.mod.common.util.VectorConversionsMCKt;

import static io.github.xiewuzhiying.vs_addition.util.ShipUtilsKt.clipIncludeShipsWrapper;

@Mixin(EntityKineticBullet.class)
public abstract class MixinEntityKineticBullet {
public abstract class MixinEntityKineticBullet extends Projectile{
public MixinEntityKineticBullet(EntityType<? extends Projectile> entityType, Level level) {
super(entityType, level);
}

@WrapOperation(
method = "onBulletTick",
at = @At(
Expand Down Expand Up @@ -46,4 +60,18 @@ private void getOriginPos(EntityKineticBullet instance, BlockHitResult result, V
original.call(instance, result, fireState, offsetPos);
}

@WrapMethod(
method = "<init>(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/resources/ResourceLocation;ZLcom/tacz/guns/resource/pojo/data/gun/BulletData;)V"
)
private void postInit(Level worldIn, LivingEntity throwerIn, ResourceLocation ammoId, ResourceLocation gunId, boolean isTracerAmmo, BulletData data, Operation<Void> original) {
final Ship ship = VSGameUtilsKt.getShipMountedTo(throwerIn);
if (ship != null) {
final Vector3d pos = VectorConversionsMCKt.toJOML(throwerIn.position());
final Vector3d oPos = new Vector3d(throwerIn.xOld, throwerIn.yOld, throwerIn.zOld);
ship.getTransform().getWorldToShip().transformPosition(pos);
ship.getTransform().getWorldToShip().transformPosition(oPos);
final Vector3d newPos = oPos.add(pos.sub(oPos).mul(0.5));
this.setPos(newPos.x, newPos.y + throwerIn.getEyeHeight(), newPos.z);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,35 @@
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.tacz.guns.entity.EntityKineticBullet;
import com.tacz.guns.resource.pojo.data.gun.BulletData;
import com.tacz.guns.resource.pojo.data.gun.GunData;
import io.github.xiewuzhiying.vs_addition.mixinducks.minecraft.HitResultMixinDuck;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import org.joml.Vector3d;
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.Ship;
import org.valkyrienskies.mod.common.VSGameUtilsKt;
import org.valkyrienskies.mod.common.util.VectorConversionsMCKt;

import static io.github.xiewuzhiying.vs_addition.util.ShipUtilsKt.clipIncludeShipsWrapper;

@Mixin(EntityKineticBullet.class)
public abstract class MixinEntityKineticBullet {
public abstract class MixinEntityKineticBullet extends Projectile {
protected MixinEntityKineticBullet(EntityType<? extends Projectile> entityType, Level level) {
super(entityType, level);
}

@WrapOperation(
method = "onBulletTick",
at = @At(
Expand Down Expand Up @@ -46,4 +63,21 @@ private void getOriginPos(EntityKineticBullet instance, BlockHitResult result, V
}
original.call(instance, result, fireState, offsetPos);
}

@Inject(
method = "<init>(Lnet/minecraft/world/entity/EntityType;Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/resources/ResourceLocation;ZLcom/tacz/guns/resource/pojo/data/gun/GunData;Lcom/tacz/guns/resource/pojo/data/gun/BulletData;)V",
at = @At("RETURN"),
remap = false
)
private void postInit(EntityType<? extends Projectile> type, Level worldIn, LivingEntity throwerIn, ItemStack gunItem, ResourceLocation ammoId, ResourceLocation gunId, boolean isTracerAmmo, GunData gunData, BulletData bulletData, CallbackInfo ci) {
final Ship ship = VSGameUtilsKt.getShipMountedTo(throwerIn);
if (ship != null) {
final Vector3d pos = VectorConversionsMCKt.toJOML(throwerIn.position());
final Vector3d oPos = new Vector3d(throwerIn.xOld, throwerIn.yOld, throwerIn.zOld);
ship.getTransform().getWorldToShip().transformPosition(pos);
ship.getTransform().getWorldToShip().transformPosition(oPos);
final Vector3d newPos = oPos.add(pos.sub(oPos).mul(0.5));
this.setPos(newPos.x, newPos.y + throwerIn.getEyeHeight(), newPos.z);
}
}
}

0 comments on commit 2fafdfa

Please sign in to comment.