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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
package re.jag.parquet.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.mojang.authlib.GameProfile;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionType;
import re.jag.parquet.interfaces.CameraModeData;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
@Mixin(ServerPlayerEntity.class)
public abstract class ServerPlayerEntityMixin extends PlayerEntity implements CameraModeData{
public ServerPlayerEntityMixin(World world, GameProfile profile) {
super(world, profile);
}
private double saved_x, saved_y, saved_z;
private int saved_dimension;
private boolean save_active = false;
@Shadow
public MinecraftServer server;
@Shadow
public void teleport(ServerWorld arg, double d, double e, double f, float g, float h) {}
@Inject(method="writeCustomDataToTag", at = @At("RETURN"))
private void onWriteCustomDataToTag(CompoundTag arg, CallbackInfo ci) {
arg.put("ParquetSavedPos", (Tag)toListTag(new double[] { saved_x, saved_y, saved_z }));
arg.putInt("ParquetSavedDimension", saved_dimension);
arg.putBoolean("ParquetSaveActive", save_active);
}
@Inject(method="readCustomDataFromTag", at = @At("RETURN"))
private void onReadCustomDataFromTag(CompoundTag arg, CallbackInfo ci) {
ListTag lv = arg.getList("ParquetSavedPos", 6);
this.saved_dimension = arg.getInt("ParquetSavedDimension");
this.save_active = arg.getBoolean("ParquetSaveActive");
if(lv != null) {
this.saved_x = lv.getDouble(0);
this.saved_y = lv.getDouble(1);
this.saved_z = lv.getDouble(2);
}
}
//INTERFACE CameraModeData
public boolean saveCameraPosition() {
if (!this.save_active) {
this.saved_x = getX();
this.saved_y = getY();
this.saved_z = getZ();
this.saved_dimension = this.dimension.getRawId();
this.save_active = true;
return true;
}
return false;
}
public boolean restoreCameraPosition() {
if (this.save_active) {
this.teleport(server.getWorld(DimensionType.byRawId(saved_dimension)), saved_x, saved_y, saved_z, 0,0);
this.save_active = false;
return true;
}
return false;
}
}
|