返回提交历史
Modified
gradle.properties
+1
-1
Modified
src/main/java/com/xfestudio/mydimension/item/RiftItem.java
+89
-5
Modified
src/main/resources/data/mydimension/dimension_type/ethereal_mind.json
+0
-1
XFEstudio/MyDimension
现在进入和退出维度会记录原维度坐标
3fde2c4
代码差异
3 个文件
+90
-7
@@ -11,7 +11,7 @@ loader_version_range=[47,)
11
11
mod_id=mydimension
12
12
mod_name=\u6211\u7684\u7ef4\u5ea6
13
13
mod_license=CC0-1.0
14
mod_version=1.1.3
14
mod_version=1.1.4
15
15
mod_group_id=com.xfestudio.mydimension
16
16
maven_group=com.xfestudio
17
17
archives_base_name=mydimension
@@ -2,7 +2,10 @@ package com.xfestudio.mydimension.item;
2
2
3
3
import com.xfestudio.mydimension.world.ModDimensions;
4
4
import net.minecraft.core.BlockPos;
5
import net.minecraft.nbt.CompoundTag;
5
6
import net.minecraft.network.chat.Component;
7
import net.minecraft.resources.ResourceKey;
8
import net.minecraft.resources.ResourceLocation;
6
9
import net.minecraft.server.level.ServerLevel;
7
10
import net.minecraft.server.level.ServerPlayer;
8
11
import net.minecraft.sounds.SoundEvents;
@@ -28,6 +31,14 @@ import java.util.function.Function;
28
31
public class RiftItem extends Item {
29
32
public static final double ETHEREAL_SURFACE_Y = 66.0D;
30
33
public static final String IMPORTED_TO_ETHEREAL_MIND = "mydimension_imported_to_ethereal_mind";
34
private static final String RETURN_POINT_TAG = "ReturnPoint";
35
private static final String ETHEREAL_POINT_TAG = "EtherealPoint";
36
private static final String RETURN_DIMENSION_TAG = "Dimension";
37
private static final String RETURN_X_TAG = "X";
38
private static final String RETURN_Y_TAG = "Y";
39
private static final String RETURN_Z_TAG = "Z";
40
private static final String RETURN_Y_ROT_TAG = "YRot";
41
private static final String RETURN_X_ROT_TAG = "XRot";
31
42
32
43
public RiftItem(Properties properties) {
33
44
super(properties);
@@ -83,7 +94,10 @@ public class RiftItem extends Item {
83
94
private static void teleport(ServerPlayer player) {
84
95
ServerLevel currentLevel = player.serverLevel();
85
96
boolean inEtherealMind = currentLevel.dimension().equals(ModDimensions.ETHEREAL_MIND);
86
ServerLevel targetLevel = player.getServer().getLevel(inEtherealMind ? Level.OVERWORLD : ModDimensions.ETHEREAL_MIND);
97
ItemStack stack = player.getMainHandItem();
98
ReturnPoint returnPoint = inEtherealMind ? readPoint(stack, RETURN_POINT_TAG) : null;
99
ReturnPoint etherealPoint = inEtherealMind ? null : readPoint(stack, ETHEREAL_POINT_TAG);
100
ServerLevel targetLevel = inEtherealMind ? getReturnLevel(player, returnPoint) : player.getServer().getLevel(ModDimensions.ETHEREAL_MIND);
87
101
88
102
if (targetLevel == null) {
89
103
player.displayClientMessage(Component.translatable("message.mydimension.missing_dimension"), true);
@@ -93,15 +107,38 @@ public class RiftItem extends Item {
93
107
double x = player.getX();
94
108
double z = player.getZ();
95
109
double y = inEtherealMind ? overworldSpawnY(targetLevel) : ETHEREAL_SURFACE_Y;
110
float yRot = player.getYRot();
111
float xRot = player.getXRot();
96
112
97
113
if (inEtherealMind) {
98
BlockPos spawn = targetLevel.getSharedSpawnPos();
99
x = spawn.getX() + 0.5D;
100
z = spawn.getZ() + 0.5D;
114
if (returnPoint != null) {
115
x = returnPoint.x();
116
y = returnPoint.y();
117
z = returnPoint.z();
118
yRot = returnPoint.yRot();
119
xRot = returnPoint.xRot();
120
} else {
121
BlockPos spawn = targetLevel.getSharedSpawnPos();
122
x = spawn.getX() + 0.5D;
123
z = spawn.getZ() + 0.5D;
124
}
125
} else {
126
writePoint(stack, RETURN_POINT_TAG, player);
127
if (etherealPoint != null) {
128
x = etherealPoint.x();
129
y = etherealPoint.y();
130
z = etherealPoint.z();
131
yRot = etherealPoint.yRot();
132
xRot = etherealPoint.xRot();
133
}
134
}
135
136
if (inEtherealMind) {
137
writePoint(stack, ETHEREAL_POINT_TAG, player);
101
138
}
102
139
103
140
targetLevel.playSound(null, player.blockPosition(), SoundEvents.ENDERMAN_TELEPORT, SoundSource.PLAYERS, 1.0F, 1.0F);
104
player.teleportTo(targetLevel, x, y, z, player.getYRot(), player.getXRot());
141
player.teleportTo(targetLevel, x, y, z, yRot, xRot);
105
142
targetLevel.playSound(null, BlockPos.containing(x, y, z), SoundEvents.ENDERMAN_TELEPORT, SoundSource.PLAYERS, 1.0F, 1.0F);
106
143
}
107
144
@@ -155,6 +192,53 @@ public class RiftItem extends Item {
155
192
return hit != null && hit.getEntity() instanceof LivingEntity living ? living : null;
156
193
}
157
194
195
private static void writePoint(ItemStack stack, String tagName, ServerPlayer player) {
196
CompoundTag point = new CompoundTag();
197
point.putString(RETURN_DIMENSION_TAG, player.level().dimension().location().toString());
198
point.putDouble(RETURN_X_TAG, player.getX());
199
point.putDouble(RETURN_Y_TAG, player.getY());
200
point.putDouble(RETURN_Z_TAG, player.getZ());
201
point.putFloat(RETURN_Y_ROT_TAG, player.getYRot());
202
point.putFloat(RETURN_X_ROT_TAG, player.getXRot());
203
stack.getOrCreateTag().put(tagName, point);
204
}
205
206
private static ReturnPoint readPoint(ItemStack stack, String tagName) {
207
CompoundTag tag = stack.getTag();
208
if (tag == null || !tag.contains(tagName, CompoundTag.TAG_COMPOUND)) {
209
return null;
210
}
211
212
CompoundTag point = tag.getCompound(tagName);
213
ResourceLocation dimension = ResourceLocation.tryParse(point.getString(RETURN_DIMENSION_TAG));
214
if (dimension == null) {
215
return null;
216
}
217
218
return new ReturnPoint(
219
ResourceKey.create(net.minecraft.core.registries.Registries.DIMENSION, dimension),
220
point.getDouble(RETURN_X_TAG),
221
point.getDouble(RETURN_Y_TAG),
222
point.getDouble(RETURN_Z_TAG),
223
point.getFloat(RETURN_Y_ROT_TAG),
224
point.getFloat(RETURN_X_ROT_TAG)
225
);
226
}
227
228
private static ServerLevel getReturnLevel(ServerPlayer player, ReturnPoint returnPoint) {
229
if (returnPoint != null) {
230
ServerLevel savedLevel = player.getServer().getLevel(returnPoint.dimension());
231
if (savedLevel != null) {
232
return savedLevel;
233
}
234
}
235
236
return player.getServer().getLevel(Level.OVERWORLD);
237
}
238
239
private record ReturnPoint(ResourceKey<Level> dimension, double x, double y, double z, float yRot, float xRot) {
240
}
241
158
242
private static class EtherealMindTeleporter implements ITeleporter {
159
243
private final double x;
160
244
private final double y;
@@ -3,7 +3,6 @@
3
3
"bed_works": true,
4
4
"coordinate_scale": 1.0,
5
5
"effects": "minecraft:overworld",
6
"fixed_time": 6000,
7
6
"has_ceiling": false,
8
7
"has_raids": false,
9
8
"has_skylight": true,