Skip to content

Commit 91818ff

Browse files
committed
Fix taterzens being in the listing twice
1 parent 484bb53 commit 91818ff

5 files changed

Lines changed: 28 additions & 42 deletions

File tree

common/src/main/java/org/samo_lego/taterzens/commands/NpcCommand.java

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.List;
3333
import java.util.UUID;
3434
import java.util.function.Consumer;
35+
import java.util.stream.IntStream;
3536

3637
import static net.minecraft.commands.Commands.argument;
3738
import static net.minecraft.commands.Commands.literal;
@@ -164,17 +165,13 @@ private static int listTaterzens(CommandContext<CommandSourceStack> context) thr
164165

165166
boolean sel = taterzenNPC == npc;
166167

167-
response
168-
.append(
168+
response.append(
169169
Component.literal("\n" + i + "-> " + name)
170170
.withStyle(sel ? ChatFormatting.BOLD : ChatFormatting.RESET)
171171
.withStyle(sel ? ChatFormatting.GREEN : (i % 2 == 0 ? ChatFormatting.YELLOW : ChatFormatting.GOLD))
172172
.withStyle(style -> style
173-
.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/npc select uuid" + taterzenNPC.getUUID().toString()))
174-
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, translate(sel ? "taterzens.tooltip.current_selection" : "taterzens.tooltip.new_selection", name))
175-
)
176-
)
177-
)
173+
.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/npc select uuid " + taterzenNPC.getUUID().toString()))
174+
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, translate(sel ? "taterzens.tooltip.current_selection" : "taterzens.tooltip.new_selection", name)))))
178175
.append(
179176
Component.literal(" (" + (console ? taterzenNPC.getStringUUID() : "uuid") + ")")
180177
.withStyle(ChatFormatting.GRAY)
@@ -189,18 +186,17 @@ private static int listTaterzens(CommandContext<CommandSourceStack> context) thr
189186
source.sendSuccess(response, false);
190187
return 1;
191188
}
192-
private static String[] getAvailableTaterzenIndices() {
193-
String[] availableIDs = new String[TATERZEN_NPCS.size()];
194-
for (int i = 0; i < TATERZEN_NPCS.size(); i++) {
195-
availableIDs[i] = Integer.toString(i + 1);
196-
}
197-
return availableIDs;
189+
190+
private static List<String> getAvailableTaterzenIndices() {
191+
return IntStream.range(0, TATERZEN_NPCS.size())
192+
.mapToObj(i -> String.valueOf(i + 1))
193+
.toList();
198194
}
199195

200196
private static int selectTaterzenById(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
201197
int id = IntegerArgumentType.getInteger(context, "id");
202198
CommandSourceStack source = context.getSource();
203-
if(id > TATERZEN_NPCS.size()) {
199+
if (id > TATERZEN_NPCS.size()) {
204200
source.sendFailure(errorText("taterzens.error.404.id", String.valueOf(id)));
205201
} else {
206202
TaterzenNPC taterzen = (TaterzenNPC) TATERZEN_NPCS.values().toArray()[id - 1];
@@ -226,20 +222,13 @@ private static int selectTaterzenById(CommandContext<CommandSourceStack> context
226222
return 1;
227223
}
228224

229-
private static String[] getAvailableTaterzenNames() {
230-
String[] availableNames = new String[TATERZEN_NPCS.size()];
231-
232-
int i = 0;
233-
for (var taterzen : TATERZEN_NPCS.values()) {
234-
availableNames[i] = taterzen.getName().getString();
235-
availableNames[i] = "\"" + availableNames[i] + "\""; // Adds quotation marks to the suggested name, such that
236-
// Names containing a whitespace character (ex. the
237-
// name is 'Foo Bar') can be completed and correctly
238-
// used without the user having to enclose the argument
239-
// name with quotation marks themselves.
240-
++i;
241-
}
242-
return availableNames;
225+
private static List<String> getAvailableTaterzenNames() {
226+
// Adds quotation marks to the suggested name, such that
227+
// Names containing a whitespace character (ex. the
228+
// name is 'Foo Bar') can be completed and correctly
229+
// used without the user having to enclose the argument
230+
// name with quotation marks themselves.
231+
return TATERZEN_NPCS.values().stream().map(npc -> "\"" + npc.getName().getString() + "\"").toList();
243232
}
244233

245234
private static int selectTaterzenByName(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {

common/src/main/java/org/samo_lego/taterzens/mixin/ChunkMapMixin_TaterzenList.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ public class ChunkMapMixin_TaterzenList {
1919
*/
2020
@Inject(method = "addEntity(Lnet/minecraft/world/entity/Entity;)V", at = @At("TAIL"))
2121
private void onEntityAdded(Entity entity, CallbackInfo ci) {
22-
if(entity instanceof TaterzenNPC)
22+
if (entity instanceof TaterzenNPC && !TATERZEN_NPCS.containsKey(entity.getUUID())) {
23+
System.out.println("Adding " + entity.getName() + " to Taterzen NPCs " + entity.getUUID());
2324
TATERZEN_NPCS.put(entity.getUUID(), (TaterzenNPC) entity);
25+
}
2426
}
2527

2628
/**
@@ -29,7 +31,8 @@ private void onEntityAdded(Entity entity, CallbackInfo ci) {
2931
*/
3032
@Inject(method = "removeEntity(Lnet/minecraft/world/entity/Entity;)V", at = @At("TAIL"))
3133
private void onEntityRemoved(Entity entity, CallbackInfo ci) {
32-
if(entity instanceof TaterzenNPC)
33-
TATERZEN_NPCS.remove(entity);
34+
if (entity instanceof TaterzenNPC) {
35+
TATERZEN_NPCS.remove(entity.getUUID());
36+
}
3437
}
3538
}

common/src/main/java/org/samo_lego/taterzens/npc/TaterzenNPC.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ public TaterzenNPC(EntityType<? extends PathfinderMob> entityType, Level world)
210210
this.npcData.deathSounds = new ArrayList<>(config.defaults.deathSounds);
211211
}
212212

213-
TATERZEN_NPCS.put(this.getUUID(), this);
214213
}
215214

216215
/**

forge/src/main/java/org/samo_lego/taterzens/forge/platform/ForgePlatform.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package org.samo_lego.taterzens.forge.platform;
22

3-
import eu.pb4.sgui.api.gui.SimpleGui;
43
import net.minecraft.commands.CommandSourceStack;
54
import net.minecraft.resources.ResourceLocation;
6-
import net.minecraft.server.level.ServerPlayer;
75
import net.minecraft.world.entity.EntityType;
86
import net.minecraft.world.entity.MobCategory;
97
import net.minecraft.world.entity.player.Player;
@@ -17,13 +15,10 @@
1715
import org.samo_lego.taterzens.platform.Platform;
1816

1917
import java.nio.file.Path;
20-
import java.util.Collections;
2118

2219
import static org.samo_lego.taterzens.Taterzens.MOD_ID;
2320
import static org.samo_lego.taterzens.Taterzens.NPC_ID;
2421
import static org.samo_lego.taterzens.Taterzens.TATERZEN_TYPE;
25-
import static org.samo_lego.taterzens.commands.NpcCommand.npcNode;
26-
import static org.samo_lego.taterzens.gui.EditorGUI.createCommandGui;
2722

2823
public class ForgePlatform extends Platform {
2924

@@ -65,7 +60,7 @@ public void registerTaterzenType() {
6560

6661
@Override
6762
public void openEditorGui(Player player) {
68-
SimpleGui editorGUI = createCommandGui((ServerPlayer) player, null, npcNode, Collections.singletonList("npc"), false);
69-
editorGUI.open();
63+
/*SimpleGui editorGUI = createCommandGui((ServerPlayer) player, null, npcNode, Collections.singletonList("npc"), false);
64+
editorGUI.open();*/
7065
}
7166
}

gradle.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ loader_version=0.14.6
88
fabric_version=0.55.2+1.19
99
#Forge
1010
forge_version=41.0.1
11-
enable_forge=false
11+
enable_forge=true
1212
# Mod Properties
13-
mod_version=1.10.1
13+
mod_version=1.10.2
1414
maven_group=org.samo_lego
1515
archives_base_name=taterzens
1616
# Dependencies
1717
disguiselib_version=1.2.1
18-
c2b_version=4c3b0be618
18+
c2b_version=1.1.4
1919
sgui_version=1.1.0+1.19

0 commit comments

Comments
 (0)