]> git.lizzy.rs Git - LightOverlay.git/commitdiff
3.6.2
authorshedaniel <daniel@shedaniel.me>
Mon, 11 Nov 2019 12:57:51 +0000 (20:57 +0800)
committershedaniel <daniel@shedaniel.me>
Mon, 11 Nov 2019 12:57:51 +0000 (20:57 +0800)
build.gradle
src/main/java/me/shedaniel/lightoverlay/LightOverlay.java
src/main/java/me/shedaniel/lightoverlay/LightOverlayClient.java
src/main/java/me/shedaniel/lightoverlay/LightOverlayCloth.java [new file with mode: 0644]
src/main/resources/META-INF/mods.toml

index c4d17357bcaffc04ca04f1028cf5b2c4fc1958b0..2c1315c7570c40b410a23ca8d33b2270977dc1f7 100644 (file)
@@ -11,7 +11,7 @@ buildscript {
 apply plugin: 'net.minecraftforge.gradle'
 apply plugin: 'eclipse'
 
-version = "3.6.1"
+version = "3.6.2"
 group = "me.shedaniel" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
 archivesBaseName = "LightOverlay"
 
index 1c438660ad06886c2099f9d30a2014536d169776..5f76104b46f47c1429d1f93329d8952831c9fe85 100644 (file)
@@ -1,20 +1,14 @@
 package me.shedaniel.lightoverlay;
 
 import net.minecraftforge.api.distmarker.Dist;
+import net.minecraftforge.fml.DistExecutor;
 import net.minecraftforge.fml.common.Mod;
-import net.minecraftforge.fml.loading.FMLEnvironment;
 
 @Mod("lightoverlay-forge")
 public class LightOverlay {
     
     public LightOverlay() {
-        if (FMLEnvironment.dist == Dist.CLIENT) {
-            try {
-                Class.forName("me.shedaniel.lightoverlay.LightOverlayClient").getDeclaredMethod("register").invoke(null);
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-        }
+        DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> LightOverlayClient.register());
     }
     
 }
index 2f8084901837c27f5f780c8e59573340f6538daf..f570c942898c5cf742c3e40050bbb5972746dc13 100644 (file)
@@ -1,19 +1,14 @@
 package me.shedaniel.lightoverlay;
 
 import com.mojang.blaze3d.platform.GlStateManager;
-import me.shedaniel.forge.clothconfig2.api.ConfigBuilder;
-import me.shedaniel.forge.clothconfig2.api.ConfigCategory;
-import me.shedaniel.forge.clothconfig2.impl.ConfigEntryBuilderImpl;
 import net.minecraft.block.Block;
 import net.minecraft.block.BlockState;
 import net.minecraft.client.Minecraft;
 import net.minecraft.client.entity.player.ClientPlayerEntity;
-import net.minecraft.client.gui.screen.Screen;
 import net.minecraft.client.renderer.ActiveRenderInfo;
 import net.minecraft.client.renderer.BufferBuilder;
 import net.minecraft.client.renderer.Tessellator;
 import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
-import net.minecraft.client.resources.I18n;
 import net.minecraft.client.settings.KeyBinding;
 import net.minecraft.client.util.InputMappings;
 import net.minecraft.entity.Entity;
@@ -24,21 +19,20 @@ import net.minecraft.tags.BlockTags;
 import net.minecraft.util.Direction;
 import net.minecraft.util.ResourceLocation;
 import net.minecraft.util.math.BlockPos;
-import net.minecraft.util.math.MathHelper;
 import net.minecraft.util.math.shapes.ISelectionContext;
 import net.minecraft.util.math.shapes.VoxelShape;
 import net.minecraft.util.text.TranslationTextComponent;
 import net.minecraft.world.LightType;
 import net.minecraft.world.World;
 import net.minecraft.world.biome.Biome;
+import net.minecraftforge.api.distmarker.Dist;
 import net.minecraftforge.client.event.InputEvent;
 import net.minecraftforge.client.event.RenderWorldLastEvent;
 import net.minecraftforge.client.settings.KeyConflictContext;
 import net.minecraftforge.client.settings.KeyModifier;
 import net.minecraftforge.common.MinecraftForge;
 import net.minecraftforge.eventbus.api.SubscribeEvent;
-import net.minecraftforge.fml.ExtensionPoint;
-import net.minecraftforge.fml.ModLoadingContext;
+import net.minecraftforge.fml.DistExecutor;
 import net.minecraftforge.fml.client.registry.ClientRegistry;
 
 import java.io.File;
@@ -46,27 +40,24 @@ import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.text.DecimalFormat;
-import java.util.Locale;
-import java.util.Optional;
 import java.util.Properties;
-import java.util.function.BiFunction;
 
 public class LightOverlayClient {
     
+    static final DecimalFormat FORMAT = new DecimalFormat("#.#");
     private static final String KEYBIND_CATEGORY = "key.lightoverlay-forge.category";
     private static final ResourceLocation ENABLE_OVERLAY_KEYBIND = new ResourceLocation("lightoverlay-forge", "enable_overlay");
     private static final ResourceLocation INCREASE_REACH_KEYBIND = new ResourceLocation("lightoverlay-forge", "increase_reach");
     private static final ResourceLocation DECREASE_REACH_KEYBIND = new ResourceLocation("lightoverlay-forge", "decrease_reach");
     private static final ResourceLocation INCREASE_LINE_WIDTH_KEYBIND = new ResourceLocation("lightoverlay-forge", "increase_line_width");
     private static final ResourceLocation DECREASE_LINE_WIDTH_KEYBIND = new ResourceLocation("lightoverlay-forge", "decrease_line_width");
-    private static final DecimalFormat FORMAT = new DecimalFormat("#.#");
+    static int reach = 7;
+    static EntityType<Entity> testingEntityType;
+    static float lineWidth = 1.0F;
+    static int yellowColor = 0xFFFF00, redColor = 0xFF0000;
+    static File configFile = new File(new File(Minecraft.getInstance().gameDir, "config"), "lightoverlay.properties");
     private static KeyBinding enableOverlay, increaseReach, decreaseReach, increaseLineWidth, decreaseLineWidth;
     private static boolean enabled = false;
-    private static int reach = 7;
-    private static EntityType<Entity> testingEntityType;
-    private static float lineWidth = 1.0F;
-    private static File configFile = new File(new File(Minecraft.getInstance().gameDir, "config"), "lightoverlay.properties");
-    private static int yellowColor = 0xFFFF00, redColor = 0xFF0000;
     
     public static void register() {
         // Load Config
@@ -80,86 +71,14 @@ public class LightOverlayClient {
         increaseLineWidth = registerKeybind(INCREASE_LINE_WIDTH_KEYBIND, InputMappings.Type.KEYSYM, -1, KEYBIND_CATEGORY);
         decreaseLineWidth = registerKeybind(DECREASE_LINE_WIDTH_KEYBIND, InputMappings.Type.KEYSYM, -1, KEYBIND_CATEGORY);
         MinecraftForge.EVENT_BUS.register(LightOverlayClient.class);
-    
-        ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.CONFIGGUIFACTORY, () -> (BiFunction<Minecraft, Screen, Screen>) (client, parent) -> {
-            ConfigBuilder builder = ConfigBuilder.create().setParentScreen(parent).setTitle("key.lightoverlay.category");
-    
-            ConfigEntryBuilderImpl eb = builder.getEntryBuilder();
-            ConfigCategory general = builder.getOrCreateCategory("config.lightoverlay-forge.general");
-            general.addEntry(eb.startIntSlider("config.lightoverlay-forge.reach", LightOverlayClient.reach, 1, 50)
-                    .setDefaultValue(7)
-                    .setTextGetter(integer -> "Reach: " + integer + " Blocks")
-                    .setSaveConsumer(integer -> LightOverlayClient.reach = integer)
-                    .build()
-            );
-            general.addEntry(eb.startIntSlider("config.lightoverlay-forge.lineWidth", MathHelper.floor(LightOverlayClient.lineWidth * 100), 100, 700)
-                    .setDefaultValue(100)
-                    .setTextGetter(integer -> "Light Width: " + LightOverlayClient.FORMAT.format(integer / 100d))
-                    .setSaveConsumer(integer -> LightOverlayClient.lineWidth = integer / 100f)
-                    .build()
-            );
-            general.addEntry(eb.startStrField("config.lightoverlay-forge.yellowColor", "#" + toStringColor(LightOverlayClient.yellowColor))
-                    .setDefaultValue("#FFFF00")
-                    .setSaveConsumer(str -> LightOverlayClient.yellowColor = toIntColor(str))
-                    .setErrorSupplier(s -> {
-                        if (!s.startsWith("#") || s.length() != 7 || !isInt(s.substring(1)))
-                            return Optional.of(I18n.format("config.lightoverlay-forge.invalidColor"));
-                        else return Optional.empty();
-                    })
-                    .build()
-            );
-            general.addEntry(eb.startStrField("config.lightoverlay-forge.redColor", "#" + toStringColor(LightOverlayClient.redColor))
-                    .setDefaultValue("#FF0000")
-                    .setSaveConsumer(str -> LightOverlayClient.redColor = toIntColor(str))
-                    .setErrorSupplier(s -> {
-                        if (!s.startsWith("#") || s.length() != 7 || !isInt(s.substring(1)))
-                            return Optional.of(I18n.format("config.lightoverlay-forge.invalidColor"));
-                        else return Optional.empty();
-                    })
-                    .build()
-            );
-    
-            return builder.setSavingRunnable(() -> {
-                try {
-                    LightOverlayClient.saveConfig(LightOverlayClient.configFile);
-                } catch (Exception e) {
-                    e.printStackTrace();
-                }
-                LightOverlayClient.loadConfig(LightOverlayClient.configFile);
-            }).build();
-        });
-    }
-    
-    private static boolean isInt(String s) {
+        
         try {
-            Integer.parseInt(s, 16);
-            return true;
-        } catch (NumberFormatException e) {
-            return false;
+            DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> LightOverlayCloth.register());
+        } catch (Exception e) {
+            e.printStackTrace();
         }
     }
     
-    private static int toIntColor(String str) {
-        String substring = str.substring(1);
-        int r = Integer.parseInt(substring.substring(0, 2), 16);
-        int g = Integer.parseInt(substring.substring(2, 4), 16);
-        int b = Integer.parseInt(substring.substring(4, 6), 16);
-        return (r << 16) + (g << 8) + b;
-    }
-    
-    private static String toStringColor(int toolColor) {
-        String r = Integer.toHexString((toolColor >> 16) & 0xFF);
-        String g = Integer.toHexString((toolColor >> 8) & 0xFF);
-        String b = Integer.toHexString((toolColor >> 0) & 0xFF);
-        if (r.length() == 1)
-            r = "0" + r;
-        if (g.length() == 1)
-            g = "0" + g;
-        if (b.length() == 1)
-            b = "0" + b;
-        return (r + g + b).toUpperCase(Locale.ROOT);
-    }
-    
     public static CrossType getCrossType(BlockPos pos, World world, PlayerEntity playerEntity) {
         BlockState blockBelowState = world.getBlockState(pos.down());
         BlockState blockUpperState = world.getBlockState(pos);
@@ -292,7 +211,7 @@ public class LightOverlayClient {
         return keyBinding;
     }
     
-    private static void loadConfig(File file) {
+    static void loadConfig(File file) {
         try {
             redColor = 0xFF0000;
             yellowColor = 0xFFFF00;
@@ -333,7 +252,7 @@ public class LightOverlayClient {
         }
     }
     
-    private static void saveConfig(File file) throws IOException {
+    static void saveConfig(File file) throws IOException {
         FileOutputStream fos = new FileOutputStream(file, false);
         fos.write("# Light Overlay Config".getBytes());
         fos.write("\n".getBytes());
diff --git a/src/main/java/me/shedaniel/lightoverlay/LightOverlayCloth.java b/src/main/java/me/shedaniel/lightoverlay/LightOverlayCloth.java
new file mode 100644 (file)
index 0000000..95e23a9
--- /dev/null
@@ -0,0 +1,79 @@
+package me.shedaniel.lightoverlay;
+
+import me.shedaniel.forge.clothconfig2.api.ConfigBuilder;
+import me.shedaniel.forge.clothconfig2.api.ConfigCategory;
+import me.shedaniel.forge.clothconfig2.impl.ConfigEntryBuilderImpl;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.screen.Screen;
+import net.minecraft.client.resources.I18n;
+import net.minecraft.util.math.MathHelper;
+import net.minecraftforge.fml.ExtensionPoint;
+import net.minecraftforge.fml.ModLoadingContext;
+
+import java.util.Locale;
+import java.util.Optional;
+import java.util.function.BiFunction;
+
+public class LightOverlayCloth {
+    public static void register() {
+        ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.CONFIGGUIFACTORY, () -> (BiFunction<Minecraft, Screen, Screen>) (client, parent) -> {
+            ConfigBuilder builder = ConfigBuilder.create().setParentScreen(parent).setTitle("key.lightoverlay.category");
+            
+            ConfigEntryBuilderImpl eb = builder.getEntryBuilder();
+            ConfigCategory general = builder.getOrCreateCategory("config.lightoverlay-forge.general");
+            general.addEntry(eb.startIntSlider("config.lightoverlay-forge.reach", LightOverlayClient.reach, 1, 50).setDefaultValue(7).setTextGetter(integer -> "Reach: " + integer + " Blocks").setSaveConsumer(integer -> LightOverlayClient.reach = integer).build());
+            general.addEntry(eb.startIntSlider("config.lightoverlay-forge.lineWidth", MathHelper.floor(LightOverlayClient.lineWidth * 100), 100, 700).setDefaultValue(100).setTextGetter(integer -> "Light Width: " + LightOverlayClient.FORMAT.format(integer / 100d)).setSaveConsumer(integer -> LightOverlayClient.lineWidth = integer / 100f).build());
+            general.addEntry(eb.startStrField("config.lightoverlay-forge.yellowColor", "#" + toStringColor(LightOverlayClient.yellowColor)).setDefaultValue("#FFFF00").setSaveConsumer(str -> LightOverlayClient.yellowColor = toIntColor(str)).setErrorSupplier(s -> {
+                if (!s.startsWith("#") || s.length() != 7 || !isInt(s.substring(1)))
+                    return Optional.of(I18n.format("config.lightoverlay-forge.invalidColor"));
+                else
+                    return Optional.empty();
+            }).build());
+            general.addEntry(eb.startStrField("config.lightoverlay-forge.redColor", "#" + toStringColor(LightOverlayClient.redColor)).setDefaultValue("#FF0000").setSaveConsumer(str -> LightOverlayClient.redColor = toIntColor(str)).setErrorSupplier(s -> {
+                if (!s.startsWith("#") || s.length() != 7 || !isInt(s.substring(1)))
+                    return Optional.of(I18n.format("config.lightoverlay-forge.invalidColor"));
+                else
+                    return Optional.empty();
+            }).build());
+            
+            return builder.setSavingRunnable(() -> {
+                try {
+                    LightOverlayClient.saveConfig(LightOverlayClient.configFile);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+                LightOverlayClient.loadConfig(LightOverlayClient.configFile);
+            }).build();
+        });
+    }
+    
+    private static boolean isInt(String s) {
+        try {
+            Integer.parseInt(s, 16);
+            return true;
+        } catch (NumberFormatException e) {
+            return false;
+        }
+    }
+    
+    private static int toIntColor(String str) {
+        String substring = str.substring(1);
+        int r = Integer.parseInt(substring.substring(0, 2), 16);
+        int g = Integer.parseInt(substring.substring(2, 4), 16);
+        int b = Integer.parseInt(substring.substring(4, 6), 16);
+        return (r << 16) + (g << 8) + b;
+    }
+    
+    private static String toStringColor(int toolColor) {
+        String r = Integer.toHexString((toolColor >> 16) & 0xFF);
+        String g = Integer.toHexString((toolColor >> 8) & 0xFF);
+        String b = Integer.toHexString((toolColor >> 0) & 0xFF);
+        if (r.length() == 1)
+            r = "0" + r;
+        if (g.length() == 1)
+            g = "0" + g;
+        if (b.length() == 1)
+            b = "0" + b;
+        return (r + g + b).toUpperCase(Locale.ROOT);
+    }
+}
index 56869575b611e3a1b2c432d18c2199a71be1fc14..f00b9b3c2ee43ea759c701eb8e299c1f629cf17c 100755 (executable)
@@ -20,26 +20,25 @@ authors="Danielshe" #optional
 # A list of mods - how many allowed here is determined by the individual mod loader
 [[mods]] #mandatory
 # The modid of the mod
-modId="lightoverlay-forge" #mandatory
+    modId="lightoverlay-forge" #mandatory
 # The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
-version="${file.jarVersion}" #mandatory
+    version="${file.jarVersion}" #mandatory
  # A display name for the mod
-displayName="Light Overlay Forge" #mandatory
+    displayName="Light Overlay Forge" #mandatory
 # A URL to query for updates for this mod. See the JSON update specification <here>
 # updateJSONURL="http://myurl.me/" #optional
 # The description text for the mod (multi line!) (#mandatory)
-description='''
+    description='''
 To provide users with NEI-like light overlay.
 '''
 
-[[dependencies.examplemod]] #optional
+[[dependencies.lightoverlay-forge]] #optional
     # the modid of the dependency
     modId="cloth-config2" #mandatory
     # Does this dependency have to exist - if not, ordering below must be specified
     mandatory=true #mandatory
     # The version range of the dependency
     versionRange="[1.4.1,)" #mandatory
-    # An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory
-    ordering="AFTER"
+    ordering="NONE"
     # Side this dependency is applied on - BOTH, CLIENT or SERVER
     side="CLIENT"
\ No newline at end of file