]> git.lizzy.rs Git - LightOverlay.git/commitdiff
3.1
authorUnknown <shekwancheung0528@gmail.com>
Sun, 28 Jul 2019 16:59:01 +0000 (00:59 +0800)
committerUnknown <shekwancheung0528@gmail.com>
Sun, 28 Jul 2019 16:59:01 +0000 (00:59 +0800)
build.gradle
src/main/java/me/shedaniel/lightoverlay/LightOverlay.java
src/main/resources/assets/lightoverlay-forge/lang/en_us.json

index 49a31a2c9b8be720f56da0e0b09ab0e8b6888cfd..b4a53a287a369f95f3fcabd820c170f7e2cd70b5 100644 (file)
@@ -11,7 +11,7 @@ buildscript {
 apply plugin: 'net.minecraftforge.gradle'
 apply plugin: 'eclipse'
 
-version = "1.1"
+version = "3.1"
 group = "me.shedaniel" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
 archivesBaseName = "LightOverlay"
 
index 2ca951b0a151dba2e3b2af638120d881348106be..50685f2e4d52a3f9bb0d8052cf18a908672eabb0 100644 (file)
@@ -1,8 +1,8 @@
 package me.shedaniel.lightoverlay;
 
 import com.mojang.blaze3d.platform.GlStateManager;
+import net.minecraft.block.Block;
 import net.minecraft.block.BlockState;
-import net.minecraft.block.Blocks;
 import net.minecraft.client.Minecraft;
 import net.minecraft.client.entity.player.ClientPlayerEntity;
 import net.minecraft.client.renderer.ActiveRenderInfo;
@@ -15,8 +15,11 @@ import net.minecraft.entity.Entity;
 import net.minecraft.entity.EntityClassification;
 import net.minecraft.entity.EntityType;
 import net.minecraft.entity.player.PlayerEntity;
+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.shapes.ISelectionContext;
 import net.minecraft.util.math.shapes.VoxelShape;
 import net.minecraft.util.text.TranslationTextComponent;
 import net.minecraft.world.LightType;
@@ -34,6 +37,13 @@ import net.minecraftforge.fml.client.registry.ClientRegistry;
 import net.minecraftforge.fml.common.Mod;
 
 import java.awt.*;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.text.DecimalFormat;
+import java.util.Map;
+import java.util.Properties;
 
 @OnlyIn(Dist.CLIENT)
 @Mod("lightoverlay-forge")
@@ -43,26 +53,47 @@ public class LightOverlay {
     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 KeyBinding enableOverlay, increaseReach, decreaseReach;
+    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("#.#");
+    private static KeyBinding enableOverlay, increaseReach, decreaseReach, increaseLineWidth, decreaseLineWidth;
     private static boolean enabled = false;
     private static int reach = 12;
     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");
     
     public LightOverlay() {
+        // Load Config
+        loadConfig(configFile);
+        
+        // Setup
         testingEntityType = EntityType.Builder.create(EntityClassification.MONSTER).size(0f, 0f).disableSerialization().build(null);
         enableOverlay = registerKeybind(ENABLE_OVERLAY_KEYBIND, InputMappings.Type.KEYSYM, 296, KEYBIND_CATEGORY);
         increaseReach = registerKeybind(INCREASE_REACH_KEYBIND, InputMappings.Type.KEYSYM, -1, KEYBIND_CATEGORY);
         decreaseReach = registerKeybind(DECREASE_REACH_KEYBIND, InputMappings.Type.KEYSYM, -1, KEYBIND_CATEGORY);
+        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(this);
     }
     
     public static CrossType getCrossType(BlockPos pos, World world, PlayerEntity playerEntity) {
         BlockState blockBelowState = world.getBlockState(pos.down());
-        BlockState blockState = world.getBlockState(pos);
-        if (blockBelowState.isAir() || !blockState.isAir())
+        BlockState blockUpperState = world.getBlockState(pos);
+        VoxelShape upperCollisionShape = blockUpperState.getCollisionShape(world, pos, ISelectionContext.forEntity(playerEntity));
+        /* WorldEntitySpawner.func_222266_a */
+        // Check if the outline is full
+        if (Block.doesSideFillSquare(upperCollisionShape, Direction.UP))
+            return CrossType.NONE;
+        // Check if there is power
+        if (blockUpperState.canProvidePower())
+            return CrossType.NONE;
+        // Check if the collision has a bump
+        if (upperCollisionShape.getEnd(Direction.Axis.Y) > 0)
             return CrossType.NONE;
-        if (blockBelowState.getBlock() == Blocks.BEDROCK || blockBelowState.getBlock() == Blocks.BARRIER)
+        if (blockUpperState.getBlock().isIn(BlockTags.RAILS))
             return CrossType.NONE;
+        // Check block state allow spawning (excludes bedrock and barriers automatically)
         if (!blockBelowState.canEntitySpawn(world, pos.down(), testingEntityType))
             return CrossType.NONE;
         if (world.getLightFor(LightType.BLOCK, pos) >= 8)
@@ -72,15 +103,18 @@ public class LightOverlay {
         return CrossType.RED;
     }
     
-    public static void renderCross(BlockPos pos, Color color, PlayerEntity entity) {
+    public static void renderCross(World world, BlockPos pos, Color color, PlayerEntity entity) {
         ActiveRenderInfo info = Minecraft.getInstance().gameRenderer.getActiveRenderInfo();
-        GlStateManager.lineWidth(1.0F);
+        GlStateManager.lineWidth(lineWidth);
         GlStateManager.depthMask(false);
         GlStateManager.disableTexture();
         Tessellator tessellator = Tessellator.getInstance();
         BufferBuilder buffer = tessellator.getBuffer();
         double d0 = info.getProjectedView().x;
         double d1 = info.getProjectedView().y - .005D;
+        VoxelShape upperOutlineShape = world.getBlockState(pos).getShape(world, pos, ISelectionContext.forEntity(entity));
+        if (!upperOutlineShape.isEmpty())
+            d1 -= upperOutlineShape.getEnd(Direction.Axis.Y);
         double d2 = info.getProjectedView().z;
         
         buffer.begin(1, DefaultVertexFormats.POSITION_COLOR);
@@ -100,13 +134,43 @@ public class LightOverlay {
         if (increaseReach.isPressed()) {
             if (reach < 50)
                 reach++;
+            try {
+                saveConfig(configFile);
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
             Minecraft.getInstance().player.sendStatusMessage(new TranslationTextComponent("text.lightoverlay-forge.current_reach", reach), false);
         }
         if (decreaseReach.isPressed()) {
             if (reach > 1)
                 reach--;
+            try {
+                saveConfig(configFile);
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
             Minecraft.getInstance().player.sendStatusMessage(new TranslationTextComponent("text.lightoverlay-forge.current_reach", reach), false);
         }
+        if (increaseLineWidth.isPressed()) {
+            if (lineWidth < 7)
+                lineWidth += 0.1f;
+            try {
+                saveConfig(configFile);
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+            Minecraft.getInstance().player.sendStatusMessage(new TranslationTextComponent("text.lightoverlay-forge.current_line_width", FORMAT.format(lineWidth)), false);
+        }
+        if (decreaseLineWidth.isPressed()) {
+            if (lineWidth > 1)
+                lineWidth -= 0.1F;
+            try {
+                saveConfig(configFile);
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+            Minecraft.getInstance().player.sendStatusMessage(new TranslationTextComponent("text.lightoverlay-forge.current_line_width", FORMAT.format(lineWidth)), false);
+        }
     }
     
     @SubscribeEvent
@@ -125,7 +189,7 @@ public class LightOverlay {
                     if (type != CrossType.NONE) {
                         VoxelShape shape = world.getBlockState(pos).getCollisionShape(world, pos);
                         Color color = type == CrossType.RED ? Color.RED : Color.YELLOW;
-                        LightOverlay.renderCross(pos, color, playerEntity);
+                        LightOverlay.renderCross(world, pos, color, playerEntity);
                     }
                 }
             });
@@ -140,6 +204,51 @@ public class LightOverlay {
         return keyBinding;
     }
     
+    private void loadConfig(File file) {
+        try {
+            if (!file.exists() || !file.canRead())
+                saveConfig(file);
+            FileInputStream fis = new FileInputStream(file);
+            Properties properties = new Properties();
+            properties.load(fis);
+            fis.close();
+            for(Map.Entry<Object, Object> entry : properties.entrySet()) {
+                if (entry.getKey() instanceof String && entry.getValue() instanceof String) {
+                    String key = (String) entry.getKey();
+                    String value = (String) entry.getValue();
+                    if (key.equals("reach")) {
+                        try {
+                            reach = Integer.valueOf(value);
+                        } catch (NumberFormatException e) {
+                            e.printStackTrace();
+                            reach = 12;
+                        }
+                    } else if (key.equals("lineWidth")) {
+                        try {
+                            lineWidth = Float.valueOf(value);
+                        } catch (NumberFormatException e) {
+                            e.printStackTrace();
+                            lineWidth = 1.0F;
+                        }
+                    }
+                }
+            }
+            saveConfig(file);
+        } catch (Exception e) {
+            e.printStackTrace();
+            reach = 12;
+            lineWidth = 1.0F;
+        }
+    }
+    
+    private void saveConfig(File file) throws IOException {
+        FileOutputStream fos = new FileOutputStream(file, false);
+        fos.write(("reach=" + String.valueOf(reach)).getBytes());
+        fos.write("\n".getBytes());
+        fos.write(("lineWidth=" + FORMAT.format(lineWidth)).getBytes());
+        fos.close();
+    }
+    
     private static enum CrossType {
         YELLOW,
         RED,
index 49756d04da7bf6dba38b3d4760435ba943b86df7..e1fad3009dd79279d1e985fa8d280776ccbb0f50 100755 (executable)
@@ -3,5 +3,8 @@
   "key.lightoverlay-forge.enable_overlay": "Toggle Light Overlay",
   "key.lightoverlay-forge.decrease_reach": "Decrease Light Overlay's Reach",
   "key.lightoverlay-forge.increase_reach": "Increase Light Overlay's Reach",
-  "text.lightoverlay-forge.current_reach": "The current reach is %d!"
+  "key.lightoverlay-forge.increase_line_width": "Increase Light Overlay's Line Width",
+  "key.lightoverlay-forge.decrease_line_width": "Decrease Light Overlay's Line Width",
+  "text.lightoverlay-forge.current_reach": "The current reach is %d!",
+  "text.lightoverlay-forge.current_line_width": "The current line width is %s!"
 }
\ No newline at end of file