Skip to content

Commit

Permalink
removed string.format wherever possible
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke100000 committed Oct 31, 2023
1 parent 24bbaaa commit 96aa5a0
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 73 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ forge*changelog.txt
/common/src/main/resources/assets/mca_voices/
/scripts/TTS/temp.pcm
/immersiveLibraryToken
/scripts/GPT3_REST_API/.env
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 7.4.10

* Fixed data loading issues on systems with locales having non-western digits.

# 7.4.9

* Added compat with Chunks fade in
Expand Down
12 changes: 0 additions & 12 deletions common/src/main/java/net/mca/block/JewelerWorkbench.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
import net.minecraft.item.ItemStack;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.*;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
Expand Down Expand Up @@ -69,16 +67,6 @@ public VoxelShape getOutlineShape(BlockState state, BlockView worldIn, BlockPos
return SHAPE;
}

public VoxelShape getRayTraceShape(BlockState state, BlockView reader, BlockPos pos, ShapeContext context) {
return SHAPE;
}

public void addInformation(ItemStack item, @Nullable BlockView iBlock, List<Text> tooltip, TooltipContext iTooltipFlag) {
tooltip.add(new LiteralText("Workbench allows you to buy rings from Jeweler").formatted(Formatting.GRAY));
tooltip.add(new TranslatableText(String.format("tooltip.%s.block.statue.line1", MCA.MOD_ID)).formatted(Formatting.GRAY));
tooltip.add(new TranslatableText(String.format("tooltip.%s.block.statue.line2", MCA.MOD_ID)).formatted(Formatting.GRAY));
}

@Nullable
@Override
public BlockState getPlacementState(ItemPlacementContext context) {
Expand Down
5 changes: 3 additions & 2 deletions common/src/main/java/net/mca/client/SpeechManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ private void speak(String phrase, UUID sender) {

float pitch = villager.getSoundPitch();
float gene = villager.getGenetics().getGene(Genetics.VOICE_TONE);
int tone = Math.min(9, (int)Math.floor(gene * 10.0f));
int tone = Math.min(9, (int) Math.floor(gene * 10.0f));

Identifier sound = new Identifier("mca_voices", "%s/%s_%d".formatted(phrase, villager.getGenetics().getGender().binary().getDataName(), tone).toLowerCase(Locale.ROOT));
String gender = villager.getGenetics().getGender().binary().getDataName();
Identifier sound = new Identifier("mca_voices", phrase.toLowerCase(Locale.ROOT) + "/" + gender + "_" + tone);

if (client.world != null && client.player != null) {
Collection<Identifier> keys = client.getSoundManager().getKeys();
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/java/net/mca/client/book/Book.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class Book {
private boolean pageTurnSound = true;

public Book(String bookName) {
this(bookName, new TranslatableText(String.format("mca.books.%s.author", bookName)).formatted(Formatting.GRAY));
this(bookName, new TranslatableText("mca.books." + bookName + ".author").formatted(Formatting.GRAY));
}

public Book(String bookName, Text bookAuthor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class TextPage extends Page {
private List<OrderedText> cachedPage;

public TextPage(String name, int page) {
content = String.format("{ \"translate\": \"mca.books.%s.%d\" }", name, page);
content = "{ \"translate\": \"mca.books." + name + "." + page + "\" }";
}

public TextPage(String content) {
Expand Down
37 changes: 16 additions & 21 deletions common/src/main/java/net/mca/client/gui/VillagerEditorScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ protected void setPage(String page) {
if (shouldShowPageSelection()) {
String[] pages = getPages();
int w = DATA_WIDTH * 2 / pages.length;
int x = (int)(width / 2.0 - pages.length / 2.0 * w);
int x = (int) (width / 2.0 - pages.length / 2.0 * w);
for (String p : pages) {
addDrawableChild(new ButtonWidget(x, height / 2 - 105, w, 20, new TranslatableText("gui.villager_editor.page." + p), sender -> setPage(p))).active = !p.equals(page);
x += w;
Expand Down Expand Up @@ -197,16 +197,16 @@ protected void setPage(String page) {

//age
if (!villagerUUID.equals(playerUUID)) {
addDrawableChild(new GeneSliderWidget(width / 2, y, DATA_WIDTH, 20, new TranslatableText("gui.villager_editor.age"), 1.0 + villagerBreedingAge / (double)AgeState.getMaxAge(), b -> {
villagerBreedingAge = -(int)((1.0 - b) * AgeState.getMaxAge()) + 1;
addDrawableChild(new GeneSliderWidget(width / 2, y, DATA_WIDTH, 20, new TranslatableText("gui.villager_editor.age"), 1.0 + villagerBreedingAge / (double) AgeState.getMaxAge(), b -> {
villagerBreedingAge = -(int) ((1.0 - b) * AgeState.getMaxAge()) + 1;
villager.setBreedingAge(villagerBreedingAge);
villager.calculateDimensions();
}));
y += 28;
}

//relations
for (String who : new String[] {"father", "mother", "spouse"}) {
for (String who : new String[]{"father", "mother", "spouse"}) {
textFieldWidget = addDrawableChild(new NamedTextFieldWidget(this.textRenderer, width / 2, y, DATA_WIDTH, 18,
new TranslatableText("gui.villager_editor.relation." + who)));
textFieldWidget.setMaxLength(64);
Expand All @@ -223,7 +223,7 @@ protected void setPage(String page) {
}
case "body" -> {
//genes
if(!Config.getServerConfig().allowPlayerSizeAdjustment && villagerUUID.equals(playerUUID)){
if (!Config.getServerConfig().allowPlayerSizeAdjustment && villagerUUID.equals(playerUUID)) {
y = doubleGeneSliders(y, Genetics.BREAST, Genetics.SKIN);
genetics.setGene(Genetics.SIZE, 0.80f);
genetics.setGene(Genetics.WIDTH, 0.80f);
Expand Down Expand Up @@ -348,7 +348,7 @@ protected void setPage(String page) {
//profession
boolean right = false;
List<ButtonWidget> professionButtons = new LinkedList<>();
for (VillagerProfession p : new VillagerProfession[] {
for (VillagerProfession p : new VillagerProfession[]{
VillagerProfession.NONE,
ProfessionsMCA.GUARD.get(),
ProfessionsMCA.ARCHER.get(),
Expand Down Expand Up @@ -451,7 +451,7 @@ private Traits.Trait[] getValidTraits() {

private void updateClothingPageWidget() {
if (pageButtonWidget != null) {
pageButtonWidget.setMessage(new LiteralText(String.format("%d / %d", clothingPage + 1, clothingPageCount)));
pageButtonWidget.setMessage(new LiteralText((clothingPage + 1) + " / " + clothingPageCount));
}
}

Expand All @@ -477,7 +477,7 @@ private <T extends ClothingList.ListEntry> List<String> filter(HashMap<String, T
.map(Map.Entry::getKey)
.toList();

clothingPageCount = (int)Math.ceil(filtered.size() / ((float)CLOTHES_PER_PAGE));
clothingPageCount = (int) Math.ceil(filtered.size() / ((float) CLOTHES_PER_PAGE));
clothingPage = Math.max(0, Math.min(clothingPage, clothingPageCount - 1));

updateClothingPageWidget();
Expand All @@ -487,9 +487,9 @@ private <T extends ClothingList.ListEntry> List<String> filter(HashMap<String, T

protected String[] getPages() {
if (villagerUUID.equals(playerUUID)) {
return new String[] {"general", "body", "head", "traits"};
return new String[]{"general", "body", "head", "traits"};
} else {
return new String[] {"general", "body", "head", "personality", "traits", "debug"};
return new String[]{"general", "body", "head", "personality", "traits", "debug"};
}
}

Expand Down Expand Up @@ -634,7 +634,7 @@ private void sendCommand(String command, NbtCompound nbt) {

private void setTraitPage(int i) {
Traits.Trait[] traits = getValidTraits();
int maxPage = (int)Math.ceil((double)traits.length / TRAITS_PER_PAGE) - 1;
int maxPage = (int) Math.ceil((double) traits.length / TRAITS_PER_PAGE) - 1;
traitPage = Math.max(0, Math.min(maxPage, i));
setPage("traits");
}
Expand Down Expand Up @@ -663,7 +663,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
}

protected void eventCallback(String event) {

// nop
}

protected boolean shouldUsePlayerModel() {
Expand All @@ -684,7 +684,7 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
return;
}

villager.age = (int)(System.currentTimeMillis() / 50L);
villager.age = (int) (System.currentTimeMillis() / 50L);

if (shouldDrawEntity()) {
int x = width / 2 - DATA_WIDTH / 2;
Expand Down Expand Up @@ -728,8 +728,8 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
villagerVisualization.setHair(filteredHair.get(index));
}

int cx = width / 2 + (int)((x - CLOTHES_H / 2.0 + 0.5 - 0.5 * (y % 2)) * 40);
int cy = height / 2 + 25 + (int)((y - CLOTHES_V / 2.0 + 0.5) * 65);
int cx = width / 2 + (int) ((x - CLOTHES_H / 2.0 + 0.5 - 0.5 * (y % 2)) * 40);
int cy = height / 2 + 25 + (int) ((y - CLOTHES_V / 2.0 + 0.5) * 65);

if (Math.abs(cx - mouseX) <= 20 && Math.abs(cy - mouseY - 30) <= 30) {
hoveredClothingId = index;
Expand All @@ -748,11 +748,6 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
super.render(matrices, mouseX, mouseY, delta);
}

@Override
public boolean mouseReleased(double mouseX, double mouseY, int button) {
return super.mouseReleased(mouseX, mouseY, button);
}

protected boolean shouldDrawEntity() {
return !page.equals("loading") && !page.equals("clothing") && !page.equals("hair");
}
Expand Down Expand Up @@ -791,7 +786,7 @@ private void requestVillagerData() {

void syncVillagerData() {
NbtCompound nbt = villagerData;
((MobEntity)villager).writeCustomDataToNbt(nbt);
((MobEntity) villager).writeCustomDataToNbt(nbt);
nbt.putInt("Age", villagerBreedingAge);
NetworkHandler.sendToServer(new VillagerEditorSyncRequest("sync", villagerUUID, nbt));
}
Expand Down
20 changes: 8 additions & 12 deletions common/src/main/java/net/mca/entity/VillagerLike.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@
import net.minecraft.util.Identifier;
import net.minecraft.village.VillagerDataContainer;

import java.util.Map;
import java.util.Optional;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
import java.util.*;

public interface VillagerLike<E extends Entity & VillagerLike<E>> extends CTrackedEntity<E>, VillagerDataContainer, Infectable, Messenger {
CDataParameter<String> VILLAGER_NAME = CParameter.create("villagerName", "");
Expand Down Expand Up @@ -254,7 +250,7 @@ default void clearHairDye() {
}

default float[] getHairDye() {
return new float[] {
return new float[]{
getTrackedValue(HAIR_COLOR_RED),
getTrackedValue(HAIR_COLOR_GREEN),
getTrackedValue(HAIR_COLOR_BLUE)
Expand Down Expand Up @@ -385,17 +381,17 @@ default void validateClothes() {
if (ClothingList.getInstance().clothing.containsKey(id)) {
setClothes(id);
} else {
MCA.LOGGER.info(String.format("Villagers clothing %s does not exist!", getClothes()));
MCA.LOGGER.info(String.format(Locale.ROOT, "Villagers clothing %s does not exist!", getClothes()));
randomizeClothes();
}
} else {
MCA.LOGGER.info(String.format("Villagers clothing %s does not exist!", getClothes()));
MCA.LOGGER.info(String.format(Locale.ROOT, "Villagers clothing %s does not exist!", getClothes()));
randomizeClothes();
}
}

if (!HairList.getInstance().hair.containsKey(getHair())) {
MCA.LOGGER.info(String.format("Villagers hair %s does not exist!", getHair()));
MCA.LOGGER.info(String.format(Locale.ROOT, "Villagers hair %s does not exist!", getHair()));
randomizeHair();
}
}
Expand All @@ -404,13 +400,13 @@ default void validateClothes() {
@SuppressWarnings({"unchecked", "RedundantSuppression"})
default NbtCompound toNbtForConversion(EntityType<?> convertingTo) {
NbtCompound output = new NbtCompound();
this.getTypeDataManager().save((E)asEntity(), output);
this.getTypeDataManager().save((E) asEntity(), output);
return output;
}

@SuppressWarnings({"unchecked", "RedundantSuppression"})
default void readNbtForConversion(EntityType<?> convertingFrom, NbtCompound input) {
this.getTypeDataManager().load((E)asEntity(), input);
this.getTypeDataManager().load((E) asEntity(), input);
}

default void copyVillagerAttributesFrom(VillagerLike<?> other) {
Expand All @@ -427,7 +423,7 @@ static VillagerLike<?> toVillager(PlayerSaveData player) {

static VillagerLike<?> toVillager(Entity entity) {
if (entity instanceof VillagerLike<?>) {
return (VillagerLike<?>)entity;
return (VillagerLike<?>) entity;
} else if (entity instanceof ServerPlayerEntity playerEntity) {
return toVillager(PlayerSaveData.get(playerEntity));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.stream.Collectors;

public class VillageModule {
private final static Map<String, String> nameExceptions = Map.of(
private static final Map<String, String> nameExceptions = Map.of(
"fishermans_hut", "fisherman's hut",
"weaving_mill", "weaving mill",
"big_house", "big house",
Expand Down Expand Up @@ -42,7 +42,7 @@ public static void apply(List<String> input, VillagerEntityMCA villager, ServerP
}
}

input.add(String.format("$villager lives in a " + size + ", medieval village in a %s biom. ", biome.replace("_", " ")));
input.add("$villager lives in a " + size + ", medieval village in a " + biome.replace("_", " ") + " biom. ");
}

// Buildings
Expand Down
3 changes: 2 additions & 1 deletion common/src/main/java/net/mca/resources/HairList.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.util.profiler.Profiler;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

public class HairList extends JsonDataLoader {
Expand Down Expand Up @@ -45,7 +46,7 @@ protected void apply(Map<Identifier, JsonElement> data, ResourceManager manager,
JsonObject object = file.getAsJsonObject().get(key).getAsJsonObject();

for (int i = 0; i < JsonHelper.getInt(object, "count", 1); i++) {
String identifier = String.format(key, i);
String identifier = String.format(Locale.ROOT, key, i);

HairList.Hair c = new HairList.Hair(identifier);
c.gender = gender;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public String asString(Integer v) {
public String getTotalAsString() {
float positive = getSummands().stream().mapToInt(SerializablePair::getRight).filter(v -> v > 0).sum();
float negative = -getSummands().stream().mapToInt(SerializablePair::getRight).filter(v -> v < 0).sum();
return String.format("%d%% chance", (int)(positive / (positive + negative) * 100.0f));
int chance = (int) (positive / (positive + negative) * 100.0f);
return chance + "% chance";
}

@Override
Expand Down
7 changes: 2 additions & 5 deletions common/src/main/java/net/mca/server/command/AdminCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@
import net.minecraft.util.Util;
import net.minecraft.util.math.BlockPos;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.*;
import java.util.stream.Stream;

import static net.minecraft.util.Formatting.*;
Expand Down Expand Up @@ -73,7 +70,7 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
private static int listVillages(CommandContext<ServerCommandSource> ctx) {
for (Village village : VillageManager.get(ctx.getSource().getWorld())) {
final BlockPos pos = village.getBox().getCenter();
success(String.format("%d: %s with %d buildings and %d/%d villager(s)",
success(String.format(Locale.ROOT, "%d: %s with %d buildings and %d/%d villager(s)",
village.getId(),
village.getName(),
village.getBuildings().size(),
Expand Down
19 changes: 4 additions & 15 deletions common/src/main/java/net/mca/server/world/data/PlayerSaveData.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private void resetEntityData() {
villager.getGenetics().randomize();
villager.getTraits().randomize();
villager.getVillagerBrain().randomize();
((MobEntity)villager).writeCustomDataToNbt(entityData);
((MobEntity) villager).writeCustomDataToNbt(entityData);
}

public boolean isEntityDataSet() {
Expand Down Expand Up @@ -237,7 +237,7 @@ public void sendMail(NbtCompound nbt) {
}

public boolean hasMail() {
return inbox.size() > 0;
return !inbox.isEmpty();
}

public ItemStack getMail() {
Expand All @@ -251,19 +251,8 @@ public ItemStack getMail() {
}
}

// todo: Implement for 7.4.0
public void sendEngagementLetter(String name) {
sendLetter(List.of(
String.format("{ \"translate\": \"mca.letter.engagement\", \"with\": [\"%s\", \"%s\"] }",
getFamilyEntry().getName(), name)
));
}

public void sendLetterOfCondolence(String name, String village) {
sendLetter(List.of(
String.format("{ \"translate\": \"mca.letter.condolence\", \"with\": [\"%s\", \"%s\", \"%s\"] }",
getFamilyEntry().getName(), name, village)
));
sendLetter(List.of("{ \"translate\": \"mca.letter.condolence\", \"with\": [\"" + getFamilyEntry().getName() + "\", \"" + name + "\", \"" + village + "\"] }"));
}

public void sendLetter(List<String> lines) {
Expand All @@ -275,7 +264,7 @@ public void sendLetter(List<String> lines) {
nbt.put("pages", l);
sendMail(nbt);

Optional.ofNullable(world.getPlayerByUuid(uuid)).ifPresent(p -> showMailNotification((ServerPlayerEntity)p));
Optional.ofNullable(world.getPlayerByUuid(uuid)).ifPresent(p -> showMailNotification((ServerPlayerEntity) p));
}

public static void showMailNotification(ServerPlayerEntity player) {
Expand Down

0 comments on commit 96aa5a0

Please sign in to comment.