Skip to content

Commit

Permalink
Merge pull request #31 from KatatsumuriPan/1.7.10/forge-dev
Browse files Browse the repository at this point in the history
Update to v1.0.1(1.7.10Forge)
  • Loading branch information
KatatsumuriPan authored Feb 20, 2024
2 parents 2c1db41 + dab4bb0 commit 44e9825
Show file tree
Hide file tree
Showing 19 changed files with 168 additions and 102 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

### [1.7.10-forge-1.0.1](https://github.com/KatatsumuriPan/BetterLineBreak/releases/tag/1.7.10-forge-1.0.1) - 2024-02-20

- Fix resetting config bug.
- Fix server crushing bug.

### [1.7.10-forge-1.0.0](https://github.com/KatatsumuriPan/BetterLineBreak/releases/tag/1.7.10-forge-1.0.0) - 2024-02-15

- First release.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ modId = better_line_break
# mcmod.info substitution, enabling assertions in run tasks, etc.
modGroup = kpan.b_line_break

modVersion = 1.0.0
modVersion = 1.0.1

# Whether to use modGroup as the maven publishing group.
# Due to a history of using JitPack, the default is com.github.GTNewHorizons for all mods.
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/kpan/b_line_break/asm/core/ASMTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public byte[] transform(String name, String transformedName, byte[] bytes) {
MyAsmNameRemapper.init();
if (bytes == null)
return null;
if(transformedName.startsWith("org."))
return bytes;
//byte配列を読み込み、利用しやすい形にする。
ClassReader cr = new ClassReader(bytes);
//これのvisitを呼ぶことによって情報が溜まっていく。
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/kpan/b_line_break/asm/core/AsmUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ public static String composeRuntimeMethodDesc(Object deobfReturnType, Object...
}

public static String runtimeMethodGenerics(String deobfGenerics) {
throw new NotImplementedException("TODO");//TODO
throw new RuntimeException("runtimeMethodGenerics is not implemented yet");//TODO
}

public static String[] runtimeExceptions(String[] deobfExceptions) {
throw new NotImplementedException("TODO");//TODO
throw new RuntimeException("runtimeMethodGenerics is not implemented yet");//TODO
}

public static int toLoadOpcode(String desc) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/kpan/b_line_break/config/ConfigHolder.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package kpan.b_line_break.config;

import kpan.b_line_break.config.core.ConfigAnnotations.ConfigOrder;
import kpan.b_line_break.config.core.ConfigAnnotations.FileComment;
import kpan.b_line_break.config.core.ConfigAnnotations.Id;
import kpan.b_line_break.config.core.ConfigVersionUpdateContext;

public class ConfigHolder {

@Id("Client")
@FileComment("Client Settings(Rendering, resources, etc.)")
@ConfigOrder(1)
public static Client client = new Client();

public static class Client {

@Id("LineBreakAlgorithm")
@FileComment("The algorithm used for line breaks")
@ConfigOrder(1)
public Algorithm lineBreakAlgorithm = Algorithm.NON_ASCII;

Expand Down
25 changes: 25 additions & 0 deletions src/main/java/kpan/b_line_break/config/core/CommentLocalizer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package kpan.b_line_break.config.core;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import kpan.b_line_break.ModMain;
import net.minecraft.client.resources.I18n;

public class CommentLocalizer {

public static String tryLocalize(String localizationKey, String defaultValue) {
if (!ModMain.proxy.hasClientSide())
return defaultValue;

String localized = format(localizationKey);
if (localizationKey.equals(localized))
return defaultValue;
else
return localized;
}

@SideOnly(Side.CLIENT)
private static String format(String localizationKey) {
return I18n.format(localizationKey);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ public class ConfigAnnotations {
String value();
}

// .cfgファイルに書き込まれるコメント
// GUIで表示されるものはこれではなく、Idから翻訳キーを通したもの
// シングルの場合のみ、Idからの翻訳を適用するようにしている
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface FileComment {
String value();
}

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface ConfigOrder {
Expand Down
24 changes: 17 additions & 7 deletions src/main/java/kpan/b_line_break/config/core/ConfigHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.base.Joiner;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import kpan.b_line_break.config.core.ConfigAnnotations.ConfigOrder;
import kpan.b_line_break.config.core.ConfigAnnotations.FileComment;
import kpan.b_line_break.config.core.ConfigAnnotations.RangeDouble;
import kpan.b_line_break.config.core.ConfigAnnotations.RangeFloat;
import kpan.b_line_break.config.core.ConfigAnnotations.RangeInt;
Expand Down Expand Up @@ -79,9 +80,10 @@ private void createProperties() {
private static void create(ModConfigurationFile config, String categoryPath, @Nullable Object instance, Field field) throws IllegalArgumentException, IllegalAccessException {
Class<?> type = field.getType();
String id = getId(field);
String fileComment = getCommentForFile(field);
if (type == boolean.class) {
boolean default_value = field.getBoolean(instance);
config.createBool(id, categoryPath, default_value, getOrder(field));
config.createBool(id, categoryPath, default_value, fileComment, getOrder(field));
} else if (type == int.class) {
int default_value = field.getInt(instance);
int min = Integer.MIN_VALUE;
Expand All @@ -91,7 +93,7 @@ private static void create(ModConfigurationFile config, String categoryPath, @Nu
min = annotation.minValue();
max = annotation.maxValue();
}
config.createInt(id, categoryPath, default_value, min, max, getOrder(field));
config.createInt(id, categoryPath, default_value, min, max, fileComment, getOrder(field));
} else if (type == long.class) {
long default_value = field.getLong(instance);
long min = Long.MIN_VALUE;
Expand All @@ -101,7 +103,7 @@ private static void create(ModConfigurationFile config, String categoryPath, @Nu
min = annotation.minValue();
max = annotation.maxValue();
}
config.createLong(id, categoryPath, default_value, min, max, getOrder(field));
config.createLong(id, categoryPath, default_value, min, max, fileComment, getOrder(field));
} else if (type == float.class) {
float default_value = field.getFloat(instance);
float min = -Float.MAX_VALUE;
Expand All @@ -111,7 +113,7 @@ private static void create(ModConfigurationFile config, String categoryPath, @Nu
min = annotation.minValue();
max = annotation.maxValue();
}
config.createFloat(id, categoryPath, default_value, min, max, getOrder(field));
config.createFloat(id, categoryPath, default_value, min, max, fileComment, getOrder(field));
} else if (type == double.class) {
double default_value = field.getDouble(instance);
double min = -Double.MAX_VALUE;
Expand All @@ -121,17 +123,17 @@ private static void create(ModConfigurationFile config, String categoryPath, @Nu
min = annotation.minValue();
max = annotation.maxValue();
}
config.createDouble(id, categoryPath, default_value, min, max, getOrder(field));
config.createDouble(id, categoryPath, default_value, min, max, fileComment, getOrder(field));
} else if (type.isPrimitive()) {
throw new RuntimeException("Not Supported:" + type.getName());
} else if (type.isEnum()) {
Enum<?> default_value = (Enum<?>) field.get(instance);
config.createEnum(id, categoryPath, default_value, getOrder(field));
config.createEnum(id, categoryPath, default_value, fileComment, getOrder(field));
} else if (type.isArray()) {
throw new RuntimeException("Array not Supported");
} else if (type == String.class) {
String default_value = (String) field.get(instance);
config.createString(id, categoryPath, default_value, getOrder(field));
config.createString(id, categoryPath, default_value, fileComment, getOrder(field));
} else {
String new_category_path;
if (categoryPath.isEmpty()) {
Expand All @@ -140,6 +142,7 @@ private static void create(ModConfigurationFile config, String categoryPath, @Nu
new_category_path = categoryPath + "." + id;
}
ModConfigCategory new_category = config.getOrCreateCategory(new_category_path);
new_category.setCommentForFile(fileComment);
new_category.setOrder(getOrder(field));
for (Field f : field.getType().getFields()) {
create(config, new_category_path, field.get(instance), f);
Expand Down Expand Up @@ -222,6 +225,13 @@ private static String getId(Field field) {
return field.getName();
}

private static String getCommentForFile(Field field) {
FileComment annotation = field.getAnnotation(FileComment.class);
if (annotation != null)
return annotation.value();
return "";
}

private static int getOrder(Field field) {
ConfigOrder annotation = field.getAnnotation(ConfigOrder.class);
if (annotation == null)
Expand Down
42 changes: 24 additions & 18 deletions src/main/java/kpan/b_line_break/config/core/ModConfigCategory.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import kpan.b_line_break.config.core.properties.ConfigPropertyInt;
import kpan.b_line_break.config.core.properties.ConfigPropertyLong;
import kpan.b_line_break.config.core.properties.ConfigPropertyString;
import net.minecraft.client.resources.I18n;
import net.minecraftforge.common.config.Configuration;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.Nullable;
Expand All @@ -36,6 +35,7 @@ public class ModConfigCategory implements IConfigElement {
private final String id;
public final boolean isRoot;
private final ModConfigurationFile configuration;
private String commentForFile = "";
private int order = 0;
private boolean showInGUI = true;
private final Map<String, ModConfigCategory> children = new TreeMap<>();
Expand All @@ -51,6 +51,13 @@ public String getId() {
return id;
}

public void setCommentForFile(String commentForFile) {
this.commentForFile = commentForFile;
}
public String getCommentForFile() {
return commentForFile;
}

public String getNameTranslationKey(String path) {
if (path.isEmpty())
return ModReference.MODID + ".config." + getId();
Expand Down Expand Up @@ -91,9 +98,8 @@ public List<IConfigElement> getOrderedElements() {
public void write(BufferedWriter out, int indent, String path) throws IOException {
String pad = getIndent(indent);

String commentKey = getCommentTranslationKey(path);
String comment = I18n.format(commentKey);
if (!comment.equals(commentKey)) {
String comment = CommentLocalizer.tryLocalize(getCommentTranslationKey(path), getCommentForFile());
if (!comment.isEmpty()) {
writeLine(out, pad, Configuration.COMMENT_SEPARATOR);
writeLine(out, pad, "# ", id);
writeLine(out, pad, "#--------------------------------------------------------------------------------------------------------#");
Expand Down Expand Up @@ -151,52 +157,52 @@ public ModConfigCategory tryGetCategory(String name) {
return children.get(name);
}

public void create(String id, boolean defaultValue, int order) {
public void create(String id, String commentForFile, boolean defaultValue, int order) {
if (get(id) != null)
throw new IllegalStateException("property named to \"" + id + "\" already exists!");
ConfigPropertyBool property = new ConfigPropertyBool(id, defaultValue, order);
ConfigPropertyBool property = new ConfigPropertyBool(id, defaultValue, commentForFile, order);
put(id, property);
}

public void create(String id, int defaultValue, int minValue, int maxValue, int order) {
public void create(String id, String commentForFile, int defaultValue, int minValue, int maxValue, int order) {
if (get(id) != null)
throw new IllegalStateException("property named to \"" + id + "\" already exists!");
ConfigPropertyInt property = new ConfigPropertyInt(id, defaultValue, minValue, maxValue, order);
ConfigPropertyInt property = new ConfigPropertyInt(id, defaultValue, minValue, maxValue, commentForFile, order);
put(id, property);
}

public void create(String id, long defaultValue, long minValue, long maxValue, int order) {
public void create(String id, String commentForFile, long defaultValue, long minValue, long maxValue, int order) {
if (get(id) != null)
throw new IllegalStateException("property named to \"" + id + "\" already exists!");
ConfigPropertyLong property = new ConfigPropertyLong(id, defaultValue, minValue, maxValue, order);
ConfigPropertyLong property = new ConfigPropertyLong(id, defaultValue, minValue, maxValue, commentForFile, order);
put(id, property);
}

public void create(String id, float defaultValue, float minValue, float maxValue, int order) {
public void create(String id, String commentForFile, float defaultValue, float minValue, float maxValue, int order) {
if (get(id) != null)
throw new IllegalStateException("property named to \"" + id + "\" already exists!");
ConfigPropertyFloat property = new ConfigPropertyFloat(id, defaultValue, minValue, maxValue, order);
ConfigPropertyFloat property = new ConfigPropertyFloat(id, defaultValue, minValue, maxValue, commentForFile, order);
put(id, property);
}

public void create(String id, double defaultValue, double minValue, double maxValue, int order) {
public void create(String id, String commentForFile, double defaultValue, double minValue, double maxValue, int order) {
if (get(id) != null)
throw new IllegalStateException("property named to \"" + id + "\" already exists!");
ConfigPropertyDouble property = new ConfigPropertyDouble(id, defaultValue, minValue, maxValue, order);
ConfigPropertyDouble property = new ConfigPropertyDouble(id, defaultValue, minValue, maxValue, commentForFile, order);
put(id, property);
}

public void create(String id, String defaultValue, int order) {
public void create(String id, String commentForFile, String defaultValue, int order) {
if (get(id) != null)
throw new IllegalStateException("property named to \"" + id + "\" already exists!");
ConfigPropertyString property = new ConfigPropertyString(id, defaultValue, order);
ConfigPropertyString property = new ConfigPropertyString(id, defaultValue, commentForFile, order);
put(id, property);
}

public void create(String id, Enum<?> defaultValue, int order) {
public void create(String id, String commentForFile, Enum<?> defaultValue, int order) {
if (get(id) != null)
throw new IllegalStateException("property named to \"" + id + "\" already exists!");
ConfigPropertyEnum property = new ConfigPropertyEnum(id, defaultValue, order);
ConfigPropertyEnum property = new ConfigPropertyEnum(id, defaultValue, commentForFile, order);
put(id, property);
}

Expand Down
Loading

0 comments on commit 44e9825

Please sign in to comment.