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;
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;
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
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);
return keyBinding;
}
- private static void loadConfig(File file) {
+ static void loadConfig(File file) {
try {
redColor = 0xFF0000;
yellowColor = 0xFFFF00;
}
}
- 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());
--- /dev/null
+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);
+ }
+}