Skip to content

Commit ee65dc1

Browse files
committed
2.0
1 parent 4774903 commit ee65dc1

9 files changed

+92
-25
lines changed

src/main/java/org/samo_lego/taterzens/Taterzens.java

+5
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ public void onInitialize() {
7777
public static Logger getLogger() {
7878
return LOGGER;
7979
}
80+
81+
/**
82+
* Gets the minecraft Taterzens config directory.
83+
* @return config directory folder.
84+
*/
8085
public static File getTaterDir() {
8186
return taterDir;
8287
}

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher, b
7171
.then(argument("id", IntegerArgumentType.integer(1)).executes(NpcCommand::selectTaterzenById))
7272
.executes(NpcCommand::selectTaterzen)
7373
)
74-
.then(literal("deselect").executes(NpcCommand::selectTaterzen))
74+
.then(literal("deselect").executes(NpcCommand::deselectTaterzen))
7575
.then(literal("list").executes(NpcCommand::listTaterzens))
7676
.then(literal("remove").executes(NpcCommand::removeTaterzen))
7777
.then(literal("preset")
@@ -139,6 +139,12 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher, b
139139
);
140140
}
141141

142+
private static int deselectTaterzen(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
143+
((TaterzenEditor) context.getSource().getPlayer()).selectNpc(null);
144+
context.getSource().sendFeedback(new LiteralText(lang.success.deselectedTaterzen).formatted(Formatting.GREEN), false);
145+
return 0;
146+
}
147+
142148
private static int deleteTaterzenMessage(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
143149
ServerPlayerEntity player = context.getSource().getPlayer();
144150
TaterzenNPC taterzen = ((TaterzenEditor) player).getNpc();
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
package org.samo_lego.taterzens.mixin;
22

33
import net.fabricmc.fabric.impl.registry.sync.RegistrySyncManager;
4+
import net.minecraft.nbt.CompoundTag;
5+
import net.minecraft.network.Packet;
6+
import net.minecraft.network.PacketByteBuf;
47
import org.spongepowered.asm.mixin.Mixin;
8+
import org.spongepowered.asm.mixin.injection.At;
9+
import org.spongepowered.asm.mixin.injection.Inject;
10+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
11+
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
12+
13+
import static org.samo_lego.taterzens.Taterzens.MODID;
514

615
@Mixin(RegistrySyncManager.class)
716
public class RegistrySyncManagerMixin_TaterzenSyncDisabler {
@@ -10,22 +19,20 @@ public class RegistrySyncManagerMixin_TaterzenSyncDisabler {
1019
* Removes taterzen tag from registry sync, as we do not need it on client.
1120
* Prevents client from being kicked if using FAPI.
1221
*/
13-
/*@Inject(
22+
@Inject(
1423
method = "createPacket",
15-
at = @At(
16-
value = "INVOKE",
17-
target = "Lnet/minecraft/network/PacketByteBuf;writeCompoundTag(Lnet/minecraft/nbt/CompoundTag;)Lnet/minecraft/network/PacketByteBuf;"
18-
),
24+
at = @At("TAIL"),
1925
locals = LocalCapture.CAPTURE_FAILHARD,
2026
remap = false
2127
)
22-
private static void removeTaterzenFromSync(CallbackInfoReturnable<Packet<?>> cir, CompoundTag tag, PacketByteBuf _buf) {
28+
private static void removeTaterzenFromSync(CallbackInfoReturnable<Packet<?>> cir, CompoundTag tag, PacketByteBuf buf) {
2329
CompoundTag registries = tag.getCompound("registries");
2430
if(registries != null) {
2531
CompoundTag entityTypes = registries.getCompound("minecraft:entity_type");
2632
if(entityTypes != null) {
2733
entityTypes.remove(MODID + ":npc");
34+
buf.writeCompoundTag(tag);
2835
}
2936
}
30-
}*/
37+
}
3138
}

src/main/java/org/samo_lego/taterzens/mixin/ServerPlayNetworkHandlerMixin_MsgEditor.java

+10
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
public class ServerPlayNetworkHandlerMixin_MsgEditor {
2424
@Shadow public ServerPlayerEntity player;
2525

26+
/**
27+
* Catches messages; if player is in
28+
* message edit mode, messages sent to chat
29+
* will be saved to taterzen instead.
30+
*
31+
* @param msg
32+
* @param ci
33+
*/
2634
@Inject(
2735
method = "method_31286(Ljava/lang/String;)V",
2836
at = @At(
@@ -49,6 +57,7 @@ private void onMessage(String msg, CallbackInfo ci) {
4957
} else {
5058
Text text;
5159
if(msg.startsWith("{") && msg.endsWith("}")) {
60+
// NBT tellraw message structure, try parse it
5261
try {
5362
text = Text.Serializer.fromJson(new StringReader(msg));
5463
} catch(JsonParseException ignored) {
@@ -59,6 +68,7 @@ private void onMessage(String msg, CallbackInfo ci) {
5968
} else
6069
text = new LiteralText(msg);
6170
if(((TaterzenEditor) player).getMessageEditing() != -1) {
71+
// Editing selected message
6272
taterzen.setMessage(((TaterzenEditor) player).getMessageEditing(), text); // Editing message
6373
player.sendMessage(TextUtil.successText(lang.success.messageChanged, text), false);
6474

src/main/java/org/samo_lego/taterzens/mixin/ServerPlayerEntityMixinCast_TaterzenPlayer.java

+11
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,15 @@ public class ServerPlayerEntityMixinCast_TaterzenPlayer implements TaterzenPlaye
2323
*/
2424
@Unique
2525
private long taterzens$lastNPCInteraction = 0;
26+
/**
27+
* Ticks since this player got last message from taterzen.
28+
*/
2629
@Unique
2730
private int taterzens$lastMessageTicks = 0;
31+
/**
32+
* The last message index of the message that was sent
33+
* to player.
34+
*/
2835
@Unique
2936
private int taterzens$currentMsg = 0;
3037

@@ -58,6 +65,10 @@ public void setCurrentMsgPos(int newPos) {
5865
this.taterzens$currentMsg = newPos;
5966
}
6067

68+
/**
69+
* Increases the ticks since last message counter.
70+
* @param ci
71+
*/
6172
@Inject(method = "tick()V", at = @At("TAIL"))
6273
private void postTick(CallbackInfo ci) {
6374
++this.taterzens$lastMessageTicks;

src/main/java/org/samo_lego/taterzens/npc/NPCData.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class NPCData {
1717
public EntityType<?> entityType = EntityType.PLAYER;
1818
public boolean fakeTypeAlive = true;
1919
/**
20-
* Used for att
20+
* Used for taterzen attributes.
2121
*/
2222
public boolean hostile = false;
2323
public boolean leashable = config.defaults.leashable;

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

+33-8
Original file line numberDiff line numberDiff line change
@@ -596,28 +596,53 @@ else if(!this.npcData.command.isEmpty()) {
596596
return result;
597597
}
598598

599+
/**
600+
* Adds the message to taterzen's message list.
601+
* @param text message to add
602+
*/
599603
public void addMessage(Text text) {
600604
this.npcData.messages.add(new Pair<>(text, config.messages.messageDelay));
601605
}
602606

603-
public void setMessage(int messageEditing, Text text) {
604-
this.npcData.messages.set(messageEditing, new Pair<>(text, config.messages.messageDelay));
607+
/**
608+
* Edits the message from taterzen's message list at index.
609+
* @param index index of the message to edit
610+
* @param text
611+
*/
612+
public void setMessage(int index, Text text) {
613+
if(index < this.npcData.messages.size())
614+
this.npcData.messages.set(index, new Pair<>(text, config.messages.messageDelay));
605615
}
606616

607-
public void removeMessage(int selected) {
608-
this.npcData.messages.remove(selected);
617+
/**
618+
* Removes message at index.
619+
* @param index index of message to be removed.
620+
*/
621+
public void removeMessage(int index) {
622+
if(index < this.npcData.messages.size())
623+
this.npcData.messages.remove(index);
609624
}
610625

611-
/*public void setMessageDelay(int delay) {
612-
if(!this.npcData.messages.isEmpty()) {
613-
this.npcData.messages.get(this.npcData.currentMessage).mapSecond(previous -> delay);
626+
/**
627+
* Sets message delay.
628+
*
629+
* @param index index of the message to change delay for.
630+
* @param delay new delay.
631+
*/
632+
public void setMessageDelay(int index, int delay) {
633+
if(index < this.npcData.messages.size()) {
634+
this.npcData.messages.get(index).mapSecond(previous -> delay);
614635
}
615-
}*/
636+
}
616637

617638
public void clearMessages() {
618639
this.npcData.messages = new ArrayList<>();
619640
}
620641

642+
/**
643+
* Gets {@link ArrayList} of {@link Pair}s of messages and their delays.
644+
* @return arraylist of pairs with texts and delays.
645+
*/
621646
public ArrayList<Pair<Text, Integer>> getMessages() {
622647
return this.npcData.messages;
623648
}

src/main/java/org/samo_lego/taterzens/storage/TaterConfig.java

+10-8
Original file line numberDiff line numberDiff line change
@@ -22,33 +22,35 @@ public class TaterConfig {
2222
*
2323
* Located at $minecraftFolder/config/Taterzens/$lang.json
2424
*/
25+
public String _comment_language = "// Language file to use.";
2526
public String language = "en_us";
26-
public Defaults defaults = new Defaults();
27-
public Path path = new Path();
28-
public Messages messages = new Messages();
2927

3028
/**
3129
* Whether to remind you that if FabricTailor
32-
* mod is installed, it has some more skin functionality
33-
* (source: https://github.com/samolego/FabricTailor)
30+
* mod is installed, it has some more skin functionality.
31+
*
32+
* @see <a href="https://github.com/samolego/FabricTailor">FabricTailor</a>
3433
*/
3534
public boolean fabricTailorAdvert = true;
3635

36+
public Defaults defaults = new Defaults();
37+
public Path path = new Path();
38+
public Messages messages = new Messages();
3739

3840
/**
3941
* Default {@link org.samo_lego.taterzens.npc.TaterzenNPC} settings.
4042
*/
4143
public static class Defaults {
42-
public String _comment = "// Default settings for new Taterzens.";
44+
public String _comment_name = "// Default settings for new Taterzens.";
4345
public String name = "Taterzen";
4446
public boolean leashable = false;
4547
public boolean pushable = false;
4648
}
4749

4850
public static class Messages {
49-
public String _commment = "// Default delay between each message, in ticks.";
51+
public String _comment_messageDelay = "// Default delay between each message, in ticks.";
5052
public int messageDelay = 100;
51-
public String _comment = "// Whether to exit message editor mode after editing a message";
53+
public String _comment_exitEditorAfterMsgEdit = "// Whether to exit message editor mode after editing a message.";
5254
public boolean exitEditorAfterMsgEdit = true;
5355
}
5456

src/main/java/org/samo_lego/taterzens/storage/TaterLang.java

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public static class Success {
5555
public String messageDelaySet = "Message delay for the last message is now %s.";
5656
public String messageChanged = "Message has been changed to %s.";
5757
public String messageDeleted = "Message %s has been deleted successfully.";
58+
public String deselectedTaterzen = "Your Taterzen selection has been cleared.";
5859
}
5960

6061
public static class Error {

0 commit comments

Comments
 (0)