|
@@ -1,14 +1,19 @@
|
|
package me.shedaniel.lightoverlay;
|
|
package me.shedaniel.lightoverlay;
|
|
|
|
|
|
import com.mojang.blaze3d.platform.GlStateManager;
|
|
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.Block;
|
|
import net.minecraft.block.BlockState;
|
|
import net.minecraft.block.BlockState;
|
|
import net.minecraft.client.Minecraft;
|
|
import net.minecraft.client.Minecraft;
|
|
import net.minecraft.client.entity.player.ClientPlayerEntity;
|
|
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.ActiveRenderInfo;
|
|
import net.minecraft.client.renderer.BufferBuilder;
|
|
import net.minecraft.client.renderer.BufferBuilder;
|
|
import net.minecraft.client.renderer.Tessellator;
|
|
import net.minecraft.client.renderer.Tessellator;
|
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
|
|
|
+import net.minecraft.client.resources.I18n;
|
|
import net.minecraft.client.settings.KeyBinding;
|
|
import net.minecraft.client.settings.KeyBinding;
|
|
import net.minecraft.client.util.InputMappings;
|
|
import net.minecraft.client.util.InputMappings;
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.entity.Entity;
|
|
@@ -19,6 +24,7 @@ import net.minecraft.tags.BlockTags;
|
|
import net.minecraft.util.Direction;
|
|
import net.minecraft.util.Direction;
|
|
import net.minecraft.util.ResourceLocation;
|
|
import net.minecraft.util.ResourceLocation;
|
|
import net.minecraft.util.math.BlockPos;
|
|
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.ISelectionContext;
|
|
import net.minecraft.util.math.shapes.VoxelShape;
|
|
import net.minecraft.util.math.shapes.VoxelShape;
|
|
import net.minecraft.util.text.TranslationTextComponent;
|
|
import net.minecraft.util.text.TranslationTextComponent;
|
|
@@ -31,6 +37,8 @@ import net.minecraftforge.client.settings.KeyConflictContext;
|
|
import net.minecraftforge.client.settings.KeyModifier;
|
|
import net.minecraftforge.client.settings.KeyModifier;
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
|
|
+import net.minecraftforge.fml.ExtensionPoint;
|
|
|
|
+import net.minecraftforge.fml.ModLoadingContext;
|
|
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
|
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
@@ -38,7 +46,10 @@ import java.io.FileInputStream;
|
|
import java.io.FileOutputStream;
|
|
import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.text.DecimalFormat;
|
|
import java.text.DecimalFormat;
|
|
|
|
+import java.util.Locale;
|
|
|
|
+import java.util.Optional;
|
|
import java.util.Properties;
|
|
import java.util.Properties;
|
|
|
|
+import java.util.function.BiFunction;
|
|
|
|
|
|
public class LightOverlayClient {
|
|
public class LightOverlayClient {
|
|
|
|
|
|
@@ -69,6 +80,84 @@ public class LightOverlayClient {
|
|
increaseLineWidth = registerKeybind(INCREASE_LINE_WIDTH_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);
|
|
decreaseLineWidth = registerKeybind(DECREASE_LINE_WIDTH_KEYBIND, InputMappings.Type.KEYSYM, -1, KEYBIND_CATEGORY);
|
|
MinecraftForge.EVENT_BUS.register(LightOverlayClient.class);
|
|
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;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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) {
|
|
public static CrossType getCrossType(BlockPos pos, World world, PlayerEntity playerEntity) {
|