Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'fabric-loom' version '1.10-SNAPSHOT'
id 'maven-publish'
}

Expand Down Expand Up @@ -71,7 +71,8 @@ dependencies {

modApi include("org.ladysnake.cardinal-components-api:cardinal-components-level:${project.cca_version}")

modImplementation 'curse.maven:guardvillagers-571503:5427036'
// Guard Villagers mod is out-of-date
//modImplementation 'curse.maven:guardvillagers-571503:5427036'

modImplementation "maven.modrinth:midnightlib:${project.midnightlib_version}"

Expand All @@ -91,7 +92,7 @@ processResources {
}

tasks.withType(JavaCompile).configureEach {
// Minecraft 1.18 (1.18-pre2) upwards uses Java 17.
// Minecraft 1.20.5 (24w14a) upwards uses Java 21.
it.options.release = 21
}

Expand Down
21 changes: 11 additions & 10 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.21
yarn_mappings=1.21+build.2
loader_version=0.15.11
minecraft_version=1.21.6
yarn_mappings=1.21.6+build.1
loader_version=0.16.14
loom_version=1.10-SNAPSHOT

# Fabric API
fabric_version=0.100.1+1.21
fabric_version=0.127.0+1.21.6


# Mod Properties
mod_version = 4.5.4
mod_version = 4.5.4_5+1.21.6
maven_group = io.github.overlordsiii
archives_base_name=villagernames-1.21
archives_base_name=villagernames-fabric

# Dependencies
mod_menu_version=11.0.0-beta.1
cloth_config_version=15.0.127
cca_version=6.1.0
midnightlib_version=1.5.7-fabric
mod_menu_version=15.0.0-beta.3
cloth_config_version=19.0.147
cca_version=7.0.0-beta.1
midnightlib_version=1.7.5+1.21.6-fabric
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip
Empty file modified gradlew
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import io.github.overlordsiii.villagernames.config.VillagerConfig;
import io.github.overlordsiii.villagernames.integration.cca.IntComponent;
import io.github.overlordsiii.villagernames.integration.cca.RavagerCounterComponent;
import io.github.overlordsiii.villagernames.integration.guardvillagers.GuardVillagersIntegration;
//import io.github.overlordsiii.villagernames.integration.guardvillagers.GuardVillagersIntegration;
import io.github.overlordsiii.villagernames.util.NamesLoader;
import io.github.overlordsiii.villagernames.util.VillagerUtil;
import io.github.overlordsiii.villagernames.util.dev.NameDebugger;
Expand Down Expand Up @@ -92,7 +92,7 @@ public void onInitialize() {
} else if (CONFIG.villagerGeneralConfig.illagerEntityNames && entity instanceof RavagerEntity ravagerEntity) {
VillagerUtil.createRavagerNames(serverWorld, ravagerEntity);
} else if (FabricLoader.getInstance().isModLoaded("guardvillagers")) {
GuardVillagersIntegration.createGuardVillagerNames(entity);
//GuardVillagersIntegration.createGuardVillagerNames(entity);
} else if (entity instanceof CatEntity catEntity) {
VillagerUtil.createCatNames(catEntity);
VillagerUtil.updateCatNames(catEntity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,12 @@ private static int executeSetFormatting(CommandContext<ServerCommandSource> ctx,
ctx.getSource().sendFeedback(() -> Text.literal(String.format(displayText
, FormattingDummy.fromFormatting(newFormatting)))
.formatted(newFormatting == Formatting.OBFUSCATED ? Formatting.WHITE : newFormatting).styled(style ->
style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND
/*style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND
, "/villagername set villagerTextFormat " +
FormattingDummy.fromFormatting(newFormatting).toString()))*/
style.withClickEvent(new ClickEvent.RunCommand("/villagername set villagerTextFormat " +
FormattingDummy.fromFormatting(newFormatting).toString()))
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
Text.literal(FormattingDummy.fromFormatting(newFormatting)
.withHoverEvent(new HoverEvent.ShowText(Text.literal(FormattingDummy.fromFormatting(newFormatting)
.toString()).formatted(newFormatting))))
, true);
VillagerNames.CONFIG_MANAGER.save();
Expand All @@ -161,11 +162,9 @@ private static int executeSetString(CommandContext<ServerCommandSource> ctx, Str
}
String text = String.format(displayedText, newvalue);
ctx.getSource().sendFeedback( () -> Text.literal(text).formatted(Formatting.LIGHT_PURPLE)
.styled(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT
, Text.literal(
.styled(style -> style.withHoverEvent(new HoverEvent.ShowText(Text.literal(
"/villagername set " + literal + " " + newvalue)))
.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND
, "/villagername set " + literal))), true);
.withClickEvent(new ClickEvent.SuggestCommand("/villagername set " + literal))), true);
VillagerNames.CONFIG_MANAGER.save();
try {
broadCastConfigChangeToOps(ctx, ConfigChange.SET, VillagerGeneralConfig.class.getDeclaredField(literal), ctx.getSource().getPlayer(), null);
Expand All @@ -191,10 +190,8 @@ private static int executeToggle(CommandContext<ServerCommandSource> ctx, String
ctx.getSource().sendFeedback(() ->
Text.literal(text).formatted(Formatting.YELLOW)
.styled(style -> style.withClickEvent(
new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND
, "/villagername toggle " + literal))
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT
, Text.literal("Toggle the " + literal + " rule")))), true);
new ClickEvent.SuggestCommand("/villagername toggle " + literal))
.withHoverEvent(new HoverEvent.ShowText(Text.literal("Toggle the " + literal + " rule")))), true);
VillagerNames.CONFIG_MANAGER.save();
try {
broadCastConfigChangeToOps(ctx, ConfigChange.TOGGLE, VillagerGeneralConfig.class.getDeclaredField(literal), ctx.getSource().getPlayer(), null);
Expand All @@ -210,11 +207,9 @@ private static int executeAdd(CommandContext<ServerCommandSource> ctx, List<Stri
String text = String.format(displayText, toAdd);
ctx.getSource().sendFeedback(() ->
Text.literal(text).formatted(Formatting.AQUA)
.styled(style -> style.withHoverEvent(new HoverEvent(
HoverEvent.Action.SHOW_TEXT
, Text.literal("Add an item to the villager or golem list")))
.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND
, "/villagername add " + literal + " " + toAdd))), true);
.styled(style -> style.withHoverEvent(new HoverEvent.ShowText(
Text.literal("Add an item to the villager or golem list")))
.withClickEvent(new ClickEvent.SuggestCommand("/villagername add " + literal + " " + toAdd))), true);
}
else{
ctx.getSource().getPlayer().sendMessage(
Expand Down Expand Up @@ -246,9 +241,9 @@ private static int executeRemove(CommandContext<ServerCommandSource> ctx, List<S
String text = String.format(displayText, toRemove);
ctx.getSource().sendFeedback(() -> Text.literal(text)
.formatted(Formatting.GOLD)
.styled(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT
, Text.literal("Remove a name from the villager or golem name list")))
.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/villagername remove " + name + " " + toRemove)))
.styled(style -> style.withHoverEvent(new HoverEvent.ShowText(
Text.literal("Remove a name from the villager or golem name list")))
.withClickEvent(new ClickEvent.SuggestCommand("/villagername remove " + name + " " + toRemove)))
, true);
}
else{
Expand Down Expand Up @@ -281,8 +276,8 @@ private static int executeInfo(CommandContext<ServerCommandSource> ctx) throws C
Text.literal(field.getName() + " = " + field.get(VillagerNames.CONFIG.villagerGeneralConfig).toString())
.styled(style -> style.withClickEvent(
FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT ?
new ClickEvent(ClickEvent.Action.OPEN_FILE, FabricLoader.getInstance().getConfigDir() + "\\VillagerNames\\" + "villagerRules.json")
: new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/villagername info"))), false);
new ClickEvent.OpenFile(FabricLoader.getInstance().getConfigDir() + "\\VillagerNames\\" + "villagerRules.json")
: new ClickEvent.SuggestCommand("/villagername info"))), false);


}
Expand Down Expand Up @@ -327,8 +322,8 @@ private static void addConfigText(MutableText text){
.formatted(Formatting.ITALIC, Formatting.GRAY))
.append(Text.literal(" Would you like to restart the server?")
.formatted(Formatting.BOLD, Formatting.GOLD).styled(style ->
style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/stop"))
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
style.withClickEvent(new ClickEvent.RunCommand("/stop"))
.withHoverEvent(new HoverEvent.ShowText(
Text.literal("⚠ WARNING! YOU HAVE TO RESTART THE SERVER BY YOURSELF! ⚠").formatted(Formatting.RED)))));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package io.github.overlordsiii.villagernames.integration.cca;

import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.world.WorldProperties;
import net.minecraft.storage.ReadView;
import net.minecraft.storage.WriteView;

public class RavagerCounterComponent implements IntComponent {

Expand All @@ -19,30 +18,13 @@ public void setValue(int value) {
this.value = value;
}

/**
* Reads this component's properties from a {@link NbtCompound}.
*
* @param tag a {@code NbtCompound} on which this component's serializable data has been written
* @param registryLookup access to dynamic registry data
* @implNote implementations should not assert that the data written on the tag corresponds to any
* specific scheme, as saved data is susceptible to external tempering, and may come from an earlier
* version.
*/
@Override
public void readFromNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) {
if (tag.contains("ravagerValue")) {
this.value = tag.getInt("ravagerValue");
}
public void readData(ReadView view) {
view.getOptionalInt("ravagerValue").ifPresent(value -> this.value = value);
}

/**
* Writes this component's properties to a {@link NbtCompound}.
*
* @param tag a {@code NbtCompound} on which to write this component's serializable data
* @param registryLookup access to dynamic registry data
*/
@Override
public void writeToNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) {
tag.putInt("ravagerValue", this.value);
public void writeData(WriteView view) {
view.putInt("ravagerValue", this.value);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Guard Villagers mod is out-of-date
/*
package io.github.overlordsiii.villagernames.integration.guardvillagers;

import static io.github.overlordsiii.villagernames.VillagerNames.CONFIG;
Expand Down Expand Up @@ -45,3 +47,4 @@ private static Text getFullNameAsText(GuardEntity entity, boolean configFormatti


}
*/
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.Objects;

import io.github.overlordsiii.villagernames.api.PiglinNameManager;
import net.minecraft.storage.ReadView;
import net.minecraft.storage.WriteView;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand Down Expand Up @@ -84,35 +86,27 @@ public String getFullName() {
return fullName;
}

@Inject(method = "writeCustomDataToNbt", at = @At("TAIL"))
private void serializeData(NbtCompound tag, CallbackInfo ci) {
@Inject(method = "writeCustomData", at = @At("TAIL"))
private void serializeData(WriteView view, CallbackInfo ci) {
if (firstName != null) {
tag.putString("firstName", firstName);
view.putString("firstName", firstName);
}
if (fullName != null) {
tag.putString("fullName", fullName);
view.putString("fullName", fullName);
}
if (lastName != null) {
tag.putString("lastName", lastName);
view.putString("lastName", lastName);
}
if (playerName != null) {
tag.putString("playerName", playerName);
view.putString("playerName", playerName);
}
}

@Inject(method = "readCustomDataFromNbt", at = @At("TAIL"))
private void deserializeData(NbtCompound tag, CallbackInfo ci) {
if (tag.contains("firstName")) {
this.firstName = tag.getString("firstName");
}
if (tag.contains("fullName")) {
this.fullName = tag.getString("fullName");
}
if (tag.contains("lastName")) {
this.lastName = tag.getString("lastName");
}
if (tag.contains("playerName")) {
this.playerName = tag.getString("playerName");
}
@Inject(method = "readCustomData", at = @At("TAIL"))
private void deserializeData(ReadView view, CallbackInfo ci) {
view.getOptionalString("firstName").ifPresent(value -> this.firstName = value);
view.getOptionalString("fullName").ifPresent(value -> this.fullName = value);
view.getOptionalString("lastName").ifPresent(value -> this.lastName = value);
view.getOptionalString("playerName").ifPresent(value -> this.playerName = value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
import net.minecraft.entity.passive.MerchantEntity;
import net.minecraft.entity.passive.VillagerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.text.Text;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.storage.ReadView;
import net.minecraft.storage.WriteView;
import net.minecraft.village.VillagerData;
import net.minecraft.village.VillagerDataContainer;
import net.minecraft.village.VillagerProfession;
Expand All @@ -21,6 +24,7 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import static io.github.overlordsiii.villagernames.VillagerNames.CONFIG;

Expand All @@ -47,16 +51,16 @@ private void changeText(VillagerData villagerData, CallbackInfo ci){
if (!this.hasCustomName()) {
VillagerUtil.createVillagerNames((VillagerEntity) (Object) this);
}
if (villagerData.getProfession() != VillagerProfession.NONE && this.hasCustomName()) {
if (!VillagerUtil.getProfIdFromEntry(villagerData.profession()).equals(VillagerProfession.NONE.getValue().toString()) && this.hasCustomName()) {
VillagerUtil.addProfessionName((VillagerEntity) (Object) this);
}
if (this.hasCustomName() && villagerData.getProfession() == VillagerProfession.NONE){
if (this.hasCustomName() && VillagerUtil.getProfIdFromEntry(villagerData.profession()).equals(VillagerProfession.NONE.getValue().toString())){
VillagerUtil.updateLostVillagerProfessionName((VillagerEntity)(Object)this);
}
}

@Redirect(method = "onStruckByLightning", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/mob/WitchEntity;setCustomName(Lnet/minecraft/text/Text;)V"))
private void redirectWitchConversion(WitchEntity witchEntity, Text name) {
@Inject(method = "method_63666", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/mob/WitchEntity;setPersistent()V"), locals = LocalCapture.CAPTURE_FAILHARD)
private void redirectWitchConversion(ServerWorld serverWorld, WitchEntity witchEntity, CallbackInfo ci) {
RaiderNameManager.setFirstName(witchEntity, getFirstName());

if (CONFIG.villagerGeneralConfig.surNames) {
Expand All @@ -66,6 +70,7 @@ private void redirectWitchConversion(WitchEntity witchEntity, Text name) {
if (this.playerName != null) {
RaiderNameManager.setPlayerName(witchEntity, this.playerName);
}
//return null;
}

@Redirect(method = "onDeath", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;info(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V"))
Expand All @@ -86,42 +91,32 @@ private void updateBabyText(CallbackInfo ci){
VillagerUtil.updateGrownUpVillagerName((VillagerEntity)(Object)(this));
}

@Inject(method = "writeCustomDataToNbt", at = @At("TAIL"))
private void serializeData(NbtCompound tag, CallbackInfo ci) {
@Inject(method = "writeCustomData", at = @At("TAIL"))
private void serializeData(WriteView view, CallbackInfo ci) {
if (firstName != null) {
tag.putString("firstName", firstName);
view.putString("firstName", firstName);
}
if (fullName != null) {
tag.putString("fullName", fullName);
view.putString("fullName", fullName);
}
if (lastName != null) {
tag.putString("lastName", lastName);
view.putString("lastName", lastName);
}
if (profession != null) {
tag.putString("profession", profession);
view.putString("profession", profession);
}
if (playerName != null) {
tag.putString("playerName", playerName);
view.putString("playerName", playerName);
}
}

@Inject(method = "readCustomDataFromNbt", at = @At("TAIL"))
private void deserializeData(NbtCompound tag, CallbackInfo ci) {
if (tag.contains("firstName")) {
this.firstName = tag.getString("firstName");
}
if (tag.contains("fullName")) {
this.fullName = tag.getString("fullName");
}
if (tag.contains("lastName")) {
this.lastName = tag.getString("lastName");
}
if (tag.contains("profession")) {
this.profession = tag.getString("profession");
}
if (tag.contains("playerName")) {
this.playerName = tag.getString("playerName");
}
@Inject(method = "readCustomData", at = @At("TAIL"))
private void deserializeData(ReadView view, CallbackInfo ci) {
view.getOptionalString("firstName").ifPresent(value -> this.firstName = value);
view.getOptionalString("fullName").ifPresent(value -> this.fullName = value);
view.getOptionalString("lastName").ifPresent(value -> this.lastName = value);
view.getOptionalString("profession").ifPresent(value -> this.profession = value);
view.getOptionalString("playerName").ifPresent(value -> this.playerName = value);
}

/**
Expand Down
Loading