返回提交历史
Modified
gradle.properties
+1
-1
Modified
src/main/java/com/xfestudio/mydimension/MyDimensionEvents.java
+3
-2
Modified
src/main/java/com/xfestudio/mydimension/client/RiftActionScreen.java
+123
-14
Modified
src/main/java/com/xfestudio/mydimension/item/RiftAction.java
+20
-7
Modified
src/main/java/com/xfestudio/mydimension/item/RiftItem.java
+10
-9
Modified
src/main/resources/assets/mydimension/lang/en_us.json
+7
-2
Modified
src/main/resources/assets/mydimension/lang/zh_cn.json
+7
-2
XFEstudio/MyDimension
优化轮盘选择界面
098368a
代码差异
7 个文件
+171
-37
@@ -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.3.0
14
mod_version=1.3.2
15
15
mod_group_id=com.xfestudio.mydimension
16
16
maven_group=com.xfestudio
17
17
archives_base_name=mydimension
@@ -140,7 +140,8 @@ public class MyDimensionEvents {
140
140
}
141
141
142
142
ItemStack stack = player.getMainHandItem();
143
if (!stack.is(ModItems.RIFT.get()) || RiftItem.getSelectedAction(stack) != RiftAction.SEND_MOB) {
143
RiftAction action = RiftItem.getSelectedAction(stack);
144
if (!stack.is(ModItems.RIFT.get()) || !action.sendsMob()) {
144
145
return;
145
146
}
146
147
@@ -148,7 +149,7 @@ public class MyDimensionEvents {
148
149
event.setCanceled(true);
149
150
150
151
if (!player.level().isClientSide()) {
151
RiftItem.sendToEtherealMind(player, target, stack);
152
RiftItem.sendToMind(player, target, stack, action.targetDimension());
152
153
}
153
154
}
154
155
@@ -1,17 +1,26 @@
1
1
package com.xfestudio.mydimension.client;
2
2
3
3
import com.xfestudio.mydimension.item.RiftAction;
4
import com.xfestudio.mydimension.item.RiftItem;
4
5
import com.xfestudio.mydimension.network.ModNetwork;
5
6
import com.xfestudio.mydimension.network.SetRiftActionPacket;
7
import com.xfestudio.mydimension.registry.ModItems;
8
import net.minecraft.client.Minecraft;
9
import net.minecraft.client.gui.Font;
6
10
import net.minecraft.client.gui.GuiGraphics;
7
11
import net.minecraft.client.gui.components.Button;
8
12
import net.minecraft.client.gui.screens.Screen;
9
13
import net.minecraft.network.chat.Component;
14
import net.minecraft.util.Mth;
15
import net.minecraft.world.item.ItemStack;
10
16
11
17
public class RiftActionScreen extends Screen {
12
18
private static final int BUTTON_WIDTH = 104;
13
private static final int BUTTON_HEIGHT = 20;
14
private static final int RADIUS = 72;
19
private static final int BUTTON_HEIGHT = 22;
20
private static final int INNER_RADIUS = 76;
21
private static final int OUTER_RADIUS = 122;
22
private static final int TRAVEL_COLOR = 0xFF3E8DB8;
23
private static final int MOB_COLOR = 0xFF8B58C8;
15
24
16
25
public RiftActionScreen() {
17
26
super(Component.translatable("screen.mydimension.rift_actions"));
@@ -19,25 +28,25 @@ public class RiftActionScreen extends Screen {
19
28
20
29
@Override
21
30
protected void init() {
22
RiftAction[] actions = RiftAction.values();
23
31
int centerX = width / 2;
24
32
int centerY = height / 2;
25
33
26
for (int i = 0; i < actions.length; i++) {
27
RiftAction action = actions[i];
28
double angle = -Math.PI / 2.0D + (Math.PI * 2.0D * i / actions.length);
29
int x = centerX + (int) Math.round(Math.cos(angle) * RADIUS) - BUTTON_WIDTH / 2;
30
int y = centerY + (int) Math.round(Math.sin(angle) * RADIUS) - BUTTON_HEIGHT / 2;
31
addRenderableWidget(Button.builder(action.displayName(), button -> select(action))
32
.bounds(x, y, BUTTON_WIDTH, BUTTON_HEIGHT)
33
.build());
34
}
34
addActionButton(RiftAction.ETHEREAL_MIND, centerX, centerY, -90.0D, INNER_RADIUS);
35
addActionButton(RiftAction.MIRROR_MIND, centerX, centerY, 0.0D, INNER_RADIUS);
36
addActionButton(RiftAction.WATER_MIND, centerX, centerY, 90.0D, INNER_RADIUS);
37
addActionButton(RiftAction.NATURE_MIND, centerX, centerY, 180.0D, INNER_RADIUS);
38
39
addActionButton(RiftAction.SEND_MOB_ETHEREAL, centerX, centerY, -135.0D, OUTER_RADIUS);
40
addActionButton(RiftAction.SEND_MOB_MIRROR, centerX, centerY, -45.0D, OUTER_RADIUS);
41
addActionButton(RiftAction.SEND_MOB_WATER, centerX, centerY, 45.0D, OUTER_RADIUS);
42
addActionButton(RiftAction.SEND_MOB_NATURE, centerX, centerY, 135.0D, OUTER_RADIUS);
35
43
}
36
44
37
45
@Override
38
46
public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTick) {
39
renderBackground(graphics);
40
graphics.drawCenteredString(font, title, width / 2, height / 2 - 8, 0xFFFFFF);
47
graphics.fillGradient(0, 0, width, height, 0xD0101218, 0xE0181026);
48
renderCenterPanel(graphics);
49
renderRingHints(graphics);
41
50
super.render(graphics, mouseX, mouseY, partialTick);
42
51
}
43
52
@@ -46,10 +55,110 @@ public class RiftActionScreen extends Screen {
46
55
return false;
47
56
}
48
57
58
private void addActionButton(RiftAction action, int centerX, int centerY, double degrees, int radius) {
59
double radians = Math.toRadians(degrees);
60
int x = centerX + (int) Math.round(Math.cos(radians) * radius) - BUTTON_WIDTH / 2;
61
int y = centerY + (int) Math.round(Math.sin(radians) * radius) - BUTTON_HEIGHT / 2;
62
addRenderableWidget(new ActionButton(x, y, action, getSelectedAction() == action));
63
}
64
65
private void renderCenterPanel(GuiGraphics graphics) {
66
int centerX = width / 2;
67
int centerY = height / 2;
68
graphics.fill(centerX - 52, centerY - 34, centerX + 52, centerY + 34, 0xAA070A10);
69
drawBorder(graphics, centerX - 52, centerY - 34, centerX + 52, centerY + 34, 0xFF85D6F7);
70
graphics.drawCenteredString(font, title, centerX, centerY - 23, 0xFFEAFBFF);
71
graphics.drawCenteredString(font, Component.translatable("screen.mydimension.rift_actions.travel"), centerX, centerY - 5, 0xFF9DDBFF);
72
graphics.drawCenteredString(font, Component.translatable("screen.mydimension.rift_actions.mob"), centerX, centerY + 10, 0xFFD0B6FF);
73
}
74
75
private void renderRingHints(GuiGraphics graphics) {
76
int centerX = width / 2;
77
int centerY = height / 2;
78
drawDiamond(graphics, centerX, centerY, INNER_RADIUS + 30, 0x4485D6F7);
79
drawDiamond(graphics, centerX, centerY, OUTER_RADIUS + 30, 0x447F53B9);
80
}
81
82
private RiftAction getSelectedAction() {
83
if (minecraft == null || minecraft.player == null) {
84
return RiftAction.ETHEREAL_MIND;
85
}
86
87
ItemStack mainHand = minecraft.player.getMainHandItem();
88
if (mainHand.is(ModItems.RIFT.get())) {
89
return RiftItem.getSelectedAction(mainHand);
90
}
91
92
ItemStack offHand = minecraft.player.getOffhandItem();
93
return offHand.is(ModItems.RIFT.get()) ? RiftItem.getSelectedAction(offHand) : RiftAction.ETHEREAL_MIND;
94
}
95
49
96
private void select(RiftAction action) {
50
97
ModNetwork.CHANNEL.sendToServer(new SetRiftActionPacket(action));
51
98
if (minecraft != null) {
52
99
minecraft.setScreen(null);
53
100
}
54
101
}
102
103
private static void drawBorder(GuiGraphics graphics, int left, int top, int right, int bottom, int color) {
104
graphics.fill(left, top, right, top + 1, color);
105
graphics.fill(left, bottom - 1, right, bottom, color);
106
graphics.fill(left, top, left + 1, bottom, color);
107
graphics.fill(right - 1, top, right, bottom, color);
108
}
109
110
private static void drawDiamond(GuiGraphics graphics, int centerX, int centerY, int radius, int color) {
111
graphics.fill(centerX - 1, centerY - radius, centerX + 1, centerY - radius + 2, color);
112
graphics.fill(centerX + radius - 1, centerY - 1, centerX + radius + 1, centerY + 1, color);
113
graphics.fill(centerX - 1, centerY + radius - 2, centerX + 1, centerY + radius, color);
114
graphics.fill(centerX - radius, centerY - 1, centerX - radius + 2, centerY + 1, color);
115
}
116
117
private class ActionButton extends Button {
118
private final RiftAction action;
119
private final boolean selected;
120
121
private ActionButton(int x, int y, RiftAction action, boolean selected) {
122
super(x, y, BUTTON_WIDTH, BUTTON_HEIGHT, action.displayName(), button -> select(action), DEFAULT_NARRATION);
123
this.action = action;
124
this.selected = selected;
125
}
126
127
@Override
128
protected void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float partialTick) {
129
int left = getX();
130
int top = getY();
131
int right = left + getWidth();
132
int bottom = top + getHeight();
133
int base = action.sendsMob() ? MOB_COLOR : TRAVEL_COLOR;
134
int fill = withAlpha(base, isHoveredOrFocused() ? 226 : 174);
135
int edge = selected ? 0xFFFFF4A8 : (action.sendsMob() ? 0xFFD8C1FF : 0xFFB8F0FF);
136
137
graphics.fillGradient(left, top, right, bottom, fill, darken(fill));
138
drawBorder(graphics, left, top, right, bottom, edge);
139
if (selected) {
140
graphics.fill(left + 2, top + 2, left + 5, bottom - 2, 0xFFFFF4A8);
141
}
142
143
int textColor = isHoveredOrFocused() ? 0xFFFFFFFF : 0xFFEAFBFF;
144
drawCenteredFittingText(graphics, Minecraft.getInstance().font, getMessage(), left, top, getWidth(), getHeight(), textColor);
145
}
146
147
private int withAlpha(int color, int alpha) {
148
return (Mth.clamp(alpha, 0, 255) << 24) | (color & 0x00FFFFFF);
149
}
150
151
private int darken(int color) {
152
int alpha = color & 0xFF000000;
153
int red = (int) (((color >> 16) & 0xFF) * 0.58F);
154
int green = (int) (((color >> 8) & 0xFF) * 0.58F);
155
int blue = (int) ((color & 0xFF) * 0.58F);
156
return alpha | (red << 16) | (green << 8) | blue;
157
}
158
159
private void drawCenteredFittingText(GuiGraphics graphics, Font font, Component text, int left, int top, int width, int height, int color) {
160
String label = font.plainSubstrByWidth(text.getString(), width - 10);
161
graphics.drawCenteredString(font, label, left + width / 2, top + (height - 8) / 2, color);
162
}
163
}
55
164
}
@@ -8,20 +8,25 @@ import net.minecraft.world.level.Level;
8
8
import java.util.Locale;
9
9
10
10
public enum RiftAction {
11
ETHEREAL_MIND("ethereal_mind", "action.mydimension.ethereal_mind", ModDimensions.ETHEREAL_MIND),
12
MIRROR_MIND("mirror_mind", "action.mydimension.mirror_mind", ModDimensions.MIRROR_MIND),
13
WATER_MIND("water_mind", "action.mydimension.water_mind", ModDimensions.WATER_MIND),
14
NATURE_MIND("nature_mind", "action.mydimension.nature_mind", ModDimensions.NATURE_MIND),
15
SEND_MOB("send_mob", "action.mydimension.send_mob", null);
11
ETHEREAL_MIND("ethereal_mind", "action.mydimension.ethereal_mind", ModDimensions.ETHEREAL_MIND, false),
12
MIRROR_MIND("mirror_mind", "action.mydimension.mirror_mind", ModDimensions.MIRROR_MIND, false),
13
WATER_MIND("water_mind", "action.mydimension.water_mind", ModDimensions.WATER_MIND, false),
14
NATURE_MIND("nature_mind", "action.mydimension.nature_mind", ModDimensions.NATURE_MIND, false),
15
SEND_MOB_ETHEREAL("send_mob_ethereal", "action.mydimension.send_mob_ethereal", ModDimensions.ETHEREAL_MIND, true),
16
SEND_MOB_MIRROR("send_mob_mirror", "action.mydimension.send_mob_mirror", ModDimensions.MIRROR_MIND, true),
17
SEND_MOB_WATER("send_mob_water", "action.mydimension.send_mob_water", ModDimensions.WATER_MIND, true),
18
SEND_MOB_NATURE("send_mob_nature", "action.mydimension.send_mob_nature", ModDimensions.NATURE_MIND, true);
16
19
17
20
private final String id;
18
21
private final String translationKey;
19
22
private final ResourceKey<Level> targetDimension;
23
private final boolean sendsMob;
20
24
21
RiftAction(String id, String translationKey, ResourceKey<Level> targetDimension) {
25
RiftAction(String id, String translationKey, ResourceKey<Level> targetDimension, boolean sendsMob) {
22
26
this.id = id;
23
27
this.translationKey = translationKey;
24
28
this.targetDimension = targetDimension;
29
this.sendsMob = sendsMob;
25
30
}
26
31
27
32
public String id() {
@@ -37,10 +42,18 @@ public enum RiftAction {
37
42
}
38
43
39
44
public boolean teleportsPlayer() {
40
return targetDimension != null;
45
return targetDimension != null && !sendsMob;
46
}
47
48
public boolean sendsMob() {
49
return sendsMob;
41
50
}
42
51
43
52
public static RiftAction byId(String id) {
53
if ("send_mob".equals(id)) {
54
return SEND_MOB_ETHEREAL;
55
}
56
44
57
for (RiftAction action : values()) {
45
58
if (action.id.equals(id)) {
46
59
return action;
@@ -88,7 +88,8 @@ public class RiftItem extends Item {
88
88
return InteractionResult.CONSUME;
89
89
}
90
90
91
if (getSelectedAction(stack) != RiftAction.SEND_MOB) {
91
RiftAction action = getSelectedAction(stack);
92
if (!action.sendsMob()) {
92
93
return InteractionResult.PASS;
93
94
}
94
95
@@ -97,7 +98,7 @@ public class RiftItem extends Item {
97
98
}
98
99
99
100
if (player instanceof ServerPlayer serverPlayer) {
100
sendToEtherealMind(serverPlayer, target, stack);
101
sendToMind(serverPlayer, target, stack, action.targetDimension());
101
102
}
102
103
103
104
return InteractionResult.CONSUME;
@@ -118,9 +119,9 @@ public class RiftItem extends Item {
118
119
119
120
private static void executeSelectedAction(ServerPlayer player, ItemStack stack) {
120
121
RiftAction action = getSelectedAction(stack);
121
if (action == RiftAction.SEND_MOB) {
122
if (action.sendsMob()) {
122
123
LivingEntity target = findLookedAtLivingEntity(player);
123
if (target == null || !sendToEtherealMind(player, target, stack)) {
124
if (target == null || !sendToMind(player, target, stack, action.targetDimension())) {
124
125
player.displayClientMessage(Component.translatable("message.mydimension.no_mob_target"), true);
125
126
}
126
127
return;
@@ -200,15 +201,15 @@ public class RiftItem extends Item {
200
201
return ModDimensions.entryHeight(dimension);
201
202
}
202
203
203
public static boolean sendToEtherealMind(ServerPlayer player, LivingEntity target, ItemStack stack) {
204
ServerLevel targetLevel = player.getServer().getLevel(ModDimensions.ETHEREAL_MIND);
204
public static boolean sendToMind(ServerPlayer player, LivingEntity target, ItemStack stack, ResourceKey<Level> targetDimension) {
205
ServerLevel targetLevel = player.getServer().getLevel(targetDimension);
205
206
if (targetLevel == null) {
206
207
player.displayClientMessage(Component.translatable("message.mydimension.missing_dimension"), true);
207
208
return false;
208
209
}
209
210
210
if (target.level().dimension().equals(ModDimensions.ETHEREAL_MIND)) {
211
player.displayClientMessage(Component.translatable("message.mydimension.already_in_ethereal_mind"), true);
211
if (target.level().dimension().equals(targetDimension)) {
212
player.displayClientMessage(Component.translatable("message.mydimension.already_in_target_mind"), true);
212
213
return false;
213
214
}
214
215
@@ -216,7 +217,7 @@ public class RiftItem extends Item {
216
217
target.stopRiding();
217
218
target.ejectPassengers();
218
219
219
Entity moved = target.changeDimension(targetLevel, new EtherealMindTeleporter(player.getX(), ETHEREAL_SURFACE_Y, player.getZ()));
220
Entity moved = target.changeDimension(targetLevel, new EtherealMindTeleporter(player.getX(), safeEntryY(targetLevel, targetDimension, player.getX(), player.getZ()), player.getZ()));
220
221
if (moved != null) {
221
222
moved.getPersistentData().putBoolean(IMPORTED_TO_ETHEREAL_MIND, true);
222
223
targetLevel.playSound(null, BlockPos.containing(moved.position()), SoundEvents.ENDERMAN_TELEPORT, SoundSource.NEUTRAL, 1.0F, 1.0F);
@@ -5,12 +5,17 @@
5
5
"dimension.mydimension.water_mind": "Water Mind",
6
6
"dimension.mydimension.nature_mind": "Nature Mind",
7
7
"screen.mydimension.rift_actions": "Rift",
8
"screen.mydimension.rift_actions.travel": "Inner: Travel",
9
"screen.mydimension.rift_actions.mob": "Outer: Send Mob",
8
10
"action.mydimension.ethereal_mind": "Go to Ethereal Mind",
9
11
"action.mydimension.mirror_mind": "Go to Mirror Mind",
10
12
"action.mydimension.water_mind": "Go to Water Mind",
11
13
"action.mydimension.nature_mind": "Go to Nature Mind",
12
"action.mydimension.send_mob": "Send Mob",
13
"message.mydimension.already_in_ethereal_mind": "That mob is already in Ethereal Mind",
14
"action.mydimension.send_mob_ethereal": "Send Mob to Ethereal",
15
"action.mydimension.send_mob_mirror": "Send Mob to Mirror",
16
"action.mydimension.send_mob_water": "Send Mob to Water",
17
"action.mydimension.send_mob_nature": "Send Mob to Nature",
18
"message.mydimension.already_in_target_mind": "That mob is already in the target mind dimension",
14
19
"message.mydimension.no_mob_target": "No mob target selected",
15
20
"message.mydimension.missing_dimension": "The target mind dimension is not loaded",
16
21
"message.mydimension.protected_tp": "%s is in a mind dimension and cannot be teleported by another player"
@@ -5,12 +5,17 @@
5
5
"dimension.mydimension.water_mind": "水之心境",
6
6
"dimension.mydimension.nature_mind": "自然心境",
7
7
"screen.mydimension.rift_actions": "裂罅",
8
"screen.mydimension.rift_actions.travel": "内环:前往心境",
9
"screen.mydimension.rift_actions.mob": "外环:传送生物",
8
10
"action.mydimension.ethereal_mind": "前往空灵心境",
9
11
"action.mydimension.mirror_mind": "前往镜之心境",
10
12
"action.mydimension.water_mind": "前往水之心境",
11
13
"action.mydimension.nature_mind": "前往自然心境",
12
"action.mydimension.send_mob": "传送生物",
13
"message.mydimension.already_in_ethereal_mind": "该生物已经在空灵心境中",
14
"action.mydimension.send_mob_ethereal": "传送生物到空灵",
15
"action.mydimension.send_mob_mirror": "传送生物到镜",
16
"action.mydimension.send_mob_water": "传送生物到水",
17
"action.mydimension.send_mob_nature": "传送生物到自然",
18
"message.mydimension.already_in_target_mind": "该生物已经在目标心境中",
14
19
"message.mydimension.no_mob_target": "没有瞄准可传送的生物",
15
20
"message.mydimension.missing_dimension": "目标心境维度未加载",
16
21
"message.mydimension.protected_tp": "%s 正处于心境维度,无法被其他玩家传送",