Reimplement block highlighting

This commit is contained in:
Marcel Konrad
2020-03-10 12:41:54 +01:00
parent 835b2c6944
commit 1f67c8e695
5 changed files with 50 additions and 79 deletions

View File

@@ -21,7 +21,7 @@ public class ConfigCategorySettings
private final BooleanValue pause;
private final BooleanValue customTimes;
private final BooleanValue permissionQuery;
// private final BooleanValue highlightBlocks;
private final BooleanValue highlightBlocks;
private final IntValue dawn;
private final IntValue noon;
private final IntValue sunset;
@@ -68,10 +68,10 @@ public class ConfigCategorySettings
.translation("gui.worldhandler.config.settings.permission_query")
.comment("Whether or not the permission query is enabled")
.define("permission_query", true);
// this.highlightBlocks = builder
// .translation("gui.worldhandler.config.settings.highlight_blocks")
// .comment("Whether or not selected blocks will be highlighted")
// .define("highlight_blocks", true);
this.highlightBlocks = builder
.translation("gui.worldhandler.config.settings.highlight_blocks")
.comment("Whether or not selected blocks will be highlighted")
.define("highlight_blocks", true);
this.dawn = builder
.translation("gui.worldhandler.config.settings.custom_time_dawn")
@@ -188,15 +188,15 @@ public class ConfigCategorySettings
Config.set(this.permissionQuery, enabled);
}
// public boolean highlightBlocks()
// {
// return this.highlightBlocks.get();
// }
//
// public void setHighlightBlocks(boolean enabled)
// {
// Config.set(this.highlightBlocks, enabled);
// }
public boolean highlightBlocks()
{
return this.highlightBlocks.get();
}
public void setHighlightBlocks(boolean enabled)
{
Config.set(this.highlightBlocks, enabled);
}
public int getDawn()
{

View File

@@ -1,13 +1,21 @@
package exopandora.worldhandler.event;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.ParseResults;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import exopandora.worldhandler.config.Config;
import exopandora.worldhandler.util.BlockHelper;
import exopandora.worldhandler.util.CommandHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.command.CommandSource;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.event.ClientChatEvent;
@@ -20,68 +28,30 @@ public class ClientEventHandler
@SubscribeEvent
public static void renderWorldLastEvent(RenderWorldLastEvent event)
{
// if(Config.getSettings().highlightBlocks() && Minecraft.getInstance().world != null && Minecraft.getInstance().getRenderManager().info != null)
// {
// final double constant = 0.0020000000949949026D;
// Vec3d projected = Minecraft.getInstance().getRenderManager().info.getProjectedView();
//
// double minX = Math.min(BlockHelper.getPos1().getX(), BlockHelper.getPos2().getX()) - constant - projected.getX();
// double minY = Math.min(BlockHelper.getPos1().getY(), BlockHelper.getPos2().getY()) - constant - projected.getY();
// double minZ = Math.min(BlockHelper.getPos1().getZ(), BlockHelper.getPos2().getZ()) - constant - projected.getZ();
//
// double maxX = Math.max(BlockHelper.getPos1().getX(), BlockHelper.getPos2().getX()) + constant - projected.getX() + 1;
// double maxY = Math.max(BlockHelper.getPos1().getY(), BlockHelper.getPos2().getY()) + constant - projected.getY() + 1;
// double maxZ = Math.max(BlockHelper.getPos1().getZ(), BlockHelper.getPos2().getZ()) + constant - projected.getZ() + 1;
//
//// event.getMatrixStack().push();
// IVertexBuilder builder = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource().getBuffer(RenderType.lines());
// WorldRenderer.drawBoundingBox(event.getMatrixStack(), builder, minX, minY, minZ, maxX, maxY, maxZ, 1.0F, 0.5F, 0.5F, 1.0F);
//// event.getMatrixStack().pop();
//
// RenderSystem.pushMatrix();
// RenderSystem.disableAlphaTest();
// RenderSystem.enableBlend();
// RenderSystem.defaultBlendFunc();
// RenderSystem.lineWidth(2.0F);
// RenderSystem.disableTexture();
// RenderSystem.depthMask(false);
//
// Tessellator tesselator = Tessellator.getInstance();
// BufferBuilder buffer = tesselator.getBuffer();
//
// final int alpha = 255;
// final int color1 = 223;
// final int color2 = 127;
//
// RenderSystem.lineWidth(2.0F);
// buffer.begin(3, DefaultVertexFormats.POSITION_COLOR);
// buffer.pos(minX, minY, minZ).color(color1, color1, color1, 0).endVertex();
// buffer.pos(minX, minY, minZ).color(color1, color1, color1, alpha).endVertex();
// buffer.pos(maxX, minY, minZ).color(color1, color2, color2, alpha).endVertex();
// buffer.pos(maxX, minY, maxZ).color(color1, color1, color1, alpha).endVertex();
// buffer.pos(minX, minY, maxZ).color(color1, color1, color1, alpha).endVertex();
// buffer.pos(minX, minY, minZ).color(color2, color2, color1, alpha).endVertex();
// buffer.pos(minX, maxY, minZ).color(color2, color1, color2, alpha).endVertex();
// buffer.pos(maxX, maxY, minZ).color(color1, color1, color1, alpha).endVertex();
// buffer.pos(maxX, maxY, maxZ).color(color1, color1, color1, alpha).endVertex();
// buffer.pos(minX, maxY, maxZ).color(color1, color1, color1, alpha).endVertex();
// buffer.pos(minX, maxY, minZ).color(color1, color1, color1, alpha).endVertex();
// buffer.pos(minX, maxY, maxZ).color(color1, color1, color1, alpha).endVertex();
// buffer.pos(minX, minY, maxZ).color(color1, color1, color1, alpha).endVertex();
// buffer.pos(maxX, minY, maxZ).color(color1, color1, color1, alpha).endVertex();
// buffer.pos(maxX, maxY, maxZ).color(color1, color1, color1, alpha).endVertex();
// buffer.pos(maxX, maxY, minZ).color(color1, color1, color1, alpha).endVertex();
// buffer.pos(maxX, minY, minZ).color(color1, color1, color1, alpha).endVertex();
// buffer.pos(maxX, minY, minZ).color(color1, color1, color1, 0).endVertex();
// tesselator.draw();
//
// RenderSystem.lineWidth(1.0F);
// RenderSystem.depthMask(true);
// RenderSystem.enableTexture();
// RenderSystem.disableBlend();
// RenderSystem.enableAlphaTest();
// RenderSystem.popMatrix();
// }
if(Config.getSettings().highlightBlocks() && Minecraft.getInstance().world != null && Minecraft.getInstance().getRenderManager().info != null)
{
Vec3d projected = Minecraft.getInstance().getRenderManager().info.getProjectedView();
MatrixStack matrix = event.getMatrixStack();
matrix.push();
matrix.translate(-projected.getX(), -projected.getY(), -projected.getZ());
double minX = Math.min(BlockHelper.getPos1().getX(), BlockHelper.getPos2().getX());
double minY = Math.min(BlockHelper.getPos1().getY(), BlockHelper.getPos2().getY());
double minZ = Math.min(BlockHelper.getPos1().getZ(), BlockHelper.getPos2().getZ());
double maxX = Math.max(BlockHelper.getPos1().getX(), BlockHelper.getPos2().getX()) + 1;
double maxY = Math.max(BlockHelper.getPos1().getY(), BlockHelper.getPos2().getY()) + 1;
double maxZ = Math.max(BlockHelper.getPos1().getZ(), BlockHelper.getPos2().getZ()) + 1;
IRenderTypeBuffer.Impl buffer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource();
IVertexBuilder builder = buffer.getBuffer(RenderType.getLines());
WorldRenderer.drawBoundingBox(matrix, builder, minX, minY, minZ, maxX, maxY, maxZ, 0.9F, 0.9F, 0.9F, 1.0F, 0.5F, 0.5F, 0.5F);
buffer.finish(RenderType.LINES);
matrix.pop();
}
}
@SubscribeEvent

View File

@@ -169,7 +169,7 @@ public class ContentPlayer extends Content
Minecraft.getInstance().fontRenderer.drawString(Minecraft.getInstance().player.getName().getFormattedText(), container.width / 2 - playerNameWidth + 59, yPos - 73, 0xE0E0E0);
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
InventoryScreen.func_228187_a_(xPos, yPos, 30, xPos - mouseX, yPos - mouseY - 44, Minecraft.getInstance().player);
InventoryScreen.drawEntityOnScreen(xPos, yPos, 30, xPos - mouseX, yPos - mouseY - 44, Minecraft.getInstance().player);
RenderSystem.defaultBlendFunc();
}
else if(Page.SCORE.equals(this.page))

View File

@@ -36,7 +36,7 @@ public class ContentSettings extends ContentChild
SETTINGS.add(new BooleanSetting("pause_game", Config.CLIENT.getSettings()::pause, Config.CLIENT.getSettings()::setPause));
SETTINGS.add(new BooleanSetting("custom_times", Config.CLIENT.getSettings()::customTimes, Config.CLIENT.getSettings()::setCustomTimes));
SETTINGS.add(new BooleanSetting("permission_query", Config.CLIENT.getSettings()::permissionQuery, Config.CLIENT.getSettings()::setPermissionQuery));
// SETTINGS.add(new BooleanSetting("highlight_blocks", Config.CLIENT.getSettings()::highlightBlocks, Config.CLIENT.getSettings()::setHighlightBlocks));
SETTINGS.add(new BooleanSetting("highlight_blocks", Config.CLIENT.getSettings()::highlightBlocks, Config.CLIENT.getSettings()::setHighlightBlocks));
SETTINGS.add(new IntegerSetting("custom_time_dawn", Config.CLIENT.getSettings()::getDawn, Config.CLIENT.getSettings()::setDawn));
SETTINGS.add(new IntegerSetting("custom_time_noon", Config.CLIENT.getSettings()::getNoon, Config.CLIENT.getSettings()::setNoon));
SETTINGS.add(new IntegerSetting("custom_time_sunset", Config.CLIENT.getSettings()::getSunset, Config.CLIENT.getSettings()::setSunset));

View File

@@ -4,6 +4,7 @@ import com.mojang.blaze3d.systems.RenderSystem;
import exopandora.worldhandler.config.Config;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.AbstractGui;
import net.minecraft.client.gui.screen.Screen;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@@ -11,7 +12,7 @@ import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
public class UtilRender
{
public static void drawWatchIntoGui(Screen gui, int width, int height, long worldTicks, boolean smooth)
public static void drawWatchIntoGui(AbstractGui gui, int width, int height, long worldTicks, boolean smooth)
{
float hour = TextFormatting.getHour(worldTicks);
float minute = TextFormatting.getMinute(worldTicks);