-
Notifications
You must be signed in to change notification settings - Fork 0
/
MixinProjectile.java
65 lines (57 loc) · 2.26 KB
/
MixinProjectile.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package org.auioc.mcmod.arnicalib.mixin.common;
import javax.annotation.Nullable;
import org.auioc.mcmod.arnicalib.game.nbt.NbtUtils;
import org.auioc.mcmod.arnicalib.mixin.common.api.IMixinProjectile;
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 net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.phys.Vec3;
@Mixin(value = Projectile.class)
public class MixinProjectile implements IMixinProjectile {
@Nullable
private Vec3 shootingPosition;
@Nullable
@Override
public Vec3 getShootingPosition() {
return this.shootingPosition;
}
@Inject(
method = "Lnet/minecraft/world/entity/projectile/Projectile;tick()V",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/entity/projectile/Projectile;gameEvent(Lnet/minecraft/world/level/gameevent/GameEvent;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/core/BlockPos;)V",
ordinal = 0
),
require = 1,
allow = 1
)
private void tick(CallbackInfo ci) {
var pos = ((Projectile) (Object) this).position();
this.shootingPosition = new Vec3(pos.x, pos.y, pos.z);
}
@Inject(
method = "Lnet/minecraft/world/entity/projectile/Projectile;readAdditionalSaveData(Lnet/minecraft/nbt/CompoundTag;)V",
at = @At(value = "TAIL"),
require = 1,
allow = 1
)
private void readAdditionalSaveData(CompoundTag p_37262_, CallbackInfo ci) {
if (p_37262_.contains("ShootingPosition", 6)) {
this.shootingPosition = NbtUtils.readVec3(p_37262_.getList("ShootingPosition", 6));
}
}
@Inject(
method = "Lnet/minecraft/world/entity/projectile/Projectile;addAdditionalSaveData(Lnet/minecraft/nbt/CompoundTag;)V",
at = @At(value = "TAIL"),
require = 1,
allow = 1
)
private void addAdditionalSaveData(CompoundTag p_37265_, CallbackInfo ci) {
if (this.shootingPosition != null) {
p_37265_.put("ShootingPosition", NbtUtils.writeVec3(this.shootingPosition));
}
}
}