|
@@ -1,8 +1,8 @@
|
|
package me.shedaniel.lightoverlay;
|
|
package me.shedaniel.lightoverlay;
|
|
|
|
|
|
import com.mojang.blaze3d.platform.GlStateManager;
|
|
import com.mojang.blaze3d.platform.GlStateManager;
|
|
|
|
+import net.minecraft.block.Block;
|
|
import net.minecraft.block.BlockState;
|
|
import net.minecraft.block.BlockState;
|
|
-import net.minecraft.block.Blocks;
|
|
|
|
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.renderer.ActiveRenderInfo;
|
|
import net.minecraft.client.renderer.ActiveRenderInfo;
|
|
@@ -15,8 +15,11 @@ import net.minecraft.entity.Entity;
|
|
import net.minecraft.entity.EntityClassification;
|
|
import net.minecraft.entity.EntityClassification;
|
|
import net.minecraft.entity.EntityType;
|
|
import net.minecraft.entity.EntityType;
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
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.ResourceLocation;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
+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;
|
|
import net.minecraft.world.LightType;
|
|
import net.minecraft.world.LightType;
|
|
@@ -34,6 +37,13 @@ import net.minecraftforge.fml.client.registry.ClientRegistry;
|
|
import net.minecraftforge.fml.common.Mod;
|
|
import net.minecraftforge.fml.common.Mod;
|
|
|
|
|
|
import java.awt.*;
|
|
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)
|
|
@OnlyIn(Dist.CLIENT)
|
|
@Mod("lightoverlay-forge")
|
|
@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 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 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 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 boolean enabled = false;
|
|
private static int reach = 12;
|
|
private static int reach = 12;
|
|
private static EntityType<Entity> testingEntityType;
|
|
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() {
|
|
public LightOverlay() {
|
|
|
|
+ // Load Config
|
|
|
|
+ loadConfig(configFile);
|
|
|
|
+
|
|
|
|
+ // Setup
|
|
testingEntityType = EntityType.Builder.create(EntityClassification.MONSTER).size(0f, 0f).disableSerialization().build(null);
|
|
testingEntityType = EntityType.Builder.create(EntityClassification.MONSTER).size(0f, 0f).disableSerialization().build(null);
|
|
enableOverlay = registerKeybind(ENABLE_OVERLAY_KEYBIND, InputMappings.Type.KEYSYM, 296, KEYBIND_CATEGORY);
|
|
enableOverlay = registerKeybind(ENABLE_OVERLAY_KEYBIND, InputMappings.Type.KEYSYM, 296, KEYBIND_CATEGORY);
|
|
increaseReach = registerKeybind(INCREASE_REACH_KEYBIND, InputMappings.Type.KEYSYM, -1, KEYBIND_CATEGORY);
|
|
increaseReach = registerKeybind(INCREASE_REACH_KEYBIND, InputMappings.Type.KEYSYM, -1, KEYBIND_CATEGORY);
|
|
decreaseReach = registerKeybind(DECREASE_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);
|
|
MinecraftForge.EVENT_BUS.register(this);
|
|
}
|
|
}
|
|
|
|
|
|
public static CrossType getCrossType(BlockPos pos, World world, PlayerEntity playerEntity) {
|
|
public static CrossType getCrossType(BlockPos pos, World world, PlayerEntity playerEntity) {
|
|
BlockState blockBelowState = world.getBlockState(pos.down());
|
|
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;
|
|
return CrossType.NONE;
|
|
- if (blockBelowState.getBlock() == Blocks.BEDROCK || blockBelowState.getBlock() == Blocks.BARRIER)
|
|
|
|
|
|
+ if (blockUpperState.getBlock().isIn(BlockTags.RAILS))
|
|
return CrossType.NONE;
|
|
return CrossType.NONE;
|
|
|
|
+ // Check block state allow spawning (excludes bedrock and barriers automatically)
|
|
if (!blockBelowState.canEntitySpawn(world, pos.down(), testingEntityType))
|
|
if (!blockBelowState.canEntitySpawn(world, pos.down(), testingEntityType))
|
|
return CrossType.NONE;
|
|
return CrossType.NONE;
|
|
if (world.getLightFor(LightType.BLOCK, pos) >= 8)
|
|
if (world.getLightFor(LightType.BLOCK, pos) >= 8)
|
|
@@ -72,15 +103,18 @@ public class LightOverlay {
|
|
return CrossType.RED;
|
|
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();
|
|
ActiveRenderInfo info = Minecraft.getInstance().gameRenderer.getActiveRenderInfo();
|
|
- GlStateManager.lineWidth(1.0F);
|
|
|
|
|
|
+ GlStateManager.lineWidth(lineWidth);
|
|
GlStateManager.depthMask(false);
|
|
GlStateManager.depthMask(false);
|
|
GlStateManager.disableTexture();
|
|
GlStateManager.disableTexture();
|
|
Tessellator tessellator = Tessellator.getInstance();
|
|
Tessellator tessellator = Tessellator.getInstance();
|
|
BufferBuilder buffer = tessellator.getBuffer();
|
|
BufferBuilder buffer = tessellator.getBuffer();
|
|
double d0 = info.getProjectedView().x;
|
|
double d0 = info.getProjectedView().x;
|
|
double d1 = info.getProjectedView().y - .005D;
|
|
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;
|
|
double d2 = info.getProjectedView().z;
|
|
|
|
|
|
buffer.begin(1, DefaultVertexFormats.POSITION_COLOR);
|
|
buffer.begin(1, DefaultVertexFormats.POSITION_COLOR);
|
|
@@ -100,13 +134,43 @@ public class LightOverlay {
|
|
if (increaseReach.isPressed()) {
|
|
if (increaseReach.isPressed()) {
|
|
if (reach < 50)
|
|
if (reach < 50)
|
|
reach++;
|
|
reach++;
|
|
|
|
+ try {
|
|
|
|
+ saveConfig(configFile);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
Minecraft.getInstance().player.sendStatusMessage(new TranslationTextComponent("text.lightoverlay-forge.current_reach", reach), false);
|
|
Minecraft.getInstance().player.sendStatusMessage(new TranslationTextComponent("text.lightoverlay-forge.current_reach", reach), false);
|
|
}
|
|
}
|
|
if (decreaseReach.isPressed()) {
|
|
if (decreaseReach.isPressed()) {
|
|
if (reach > 1)
|
|
if (reach > 1)
|
|
reach--;
|
|
reach--;
|
|
|
|
+ try {
|
|
|
|
+ saveConfig(configFile);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
Minecraft.getInstance().player.sendStatusMessage(new TranslationTextComponent("text.lightoverlay-forge.current_reach", reach), false);
|
|
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
|
|
@SubscribeEvent
|
|
@@ -125,7 +189,7 @@ public class LightOverlay {
|
|
if (type != CrossType.NONE) {
|
|
if (type != CrossType.NONE) {
|
|
VoxelShape shape = world.getBlockState(pos).getCollisionShape(world, pos);
|
|
VoxelShape shape = world.getBlockState(pos).getCollisionShape(world, pos);
|
|
Color color = type == CrossType.RED ? Color.RED : Color.YELLOW;
|
|
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;
|
|
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 {
|
|
private static enum CrossType {
|
|
YELLOW,
|
|
YELLOW,
|
|
RED,
|
|
RED,
|