diff options
author | Detrav <witalyezep@gmail.com> | 2016-04-18 14:09:18 +0300 |
---|---|---|
committer | Detrav <witalyezep@gmail.com> | 2016-04-18 14:09:18 +0300 |
commit | 3e53fcce73d78f94550a8f79f8932ba0df3bf531 (patch) | |
tree | b5635e3c989eb0ba0b5b49d00b550f0d614e0137 /src/main/java | |
parent | 608b62b171fe314e9a75001a06c44383054ba376 (diff) | |
download | GT5-Unofficial-3e53fcce73d78f94550a8f79f8932ba0df3bf531.tar.gz GT5-Unofficial-3e53fcce73d78f94550a8f79f8932ba0df3bf531.tar.bz2 GT5-Unofficial-3e53fcce73d78f94550a8f79f8932ba0df3bf531.zip |
Add "Detrav" mode overlay
Diffstat (limited to 'src/main/java')
4 files changed, 164 insertions, 35 deletions
diff --git a/src/main/java/com/detrav/events/DetravBlockSideRenderEventHandler.java b/src/main/java/com/detrav/events/DetravBlockSideRenderEventHandler.java deleted file mode 100644 index bf08bfb1bf..0000000000 --- a/src/main/java/com/detrav/events/DetravBlockSideRenderEventHandler.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.detrav.events; - -import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.client.event.RenderWorldLastEvent; - -/** - * Created by wital_000 on 18.04.2016. - */ -public class DetravBlockSideRenderEventHandler { - - public static long modeBlockBreak = 0L; - - @SubscribeEvent - public void onRender(RenderWorldLastEvent ev) { - //need to draw large borders - } - - - static boolean inited = false; - - public static void register() { - if (!inited) { - inited = true; - DetravBlockSideRenderEventHandler handler = new DetravBlockSideRenderEventHandler(); - MinecraftForge.EVENT_BUS.register(handler); - FMLCommonHandler.instance().bus().register(handler); - } - } -} diff --git a/src/main/java/com/detrav/events/DetravDrawBlockHighlightEventHandler.java b/src/main/java/com/detrav/events/DetravDrawBlockHighlightEventHandler.java new file mode 100644 index 0000000000..756bfd1264 --- /dev/null +++ b/src/main/java/com/detrav/events/DetravDrawBlockHighlightEventHandler.java @@ -0,0 +1,160 @@ +package com.detrav.events; + +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.MovingObjectPosition; +import net.minecraftforge.client.event.DrawBlockHighlightEvent; +import net.minecraftforge.common.MinecraftForge; +import org.lwjgl.opengl.GL11; +//import net.minecraftforge.client.event.RenderWorldLastEvent; + +/** + * Created by wital_000 on 18.04.2016. + */ +public class DetravDrawBlockHighlightEventHandler { + + public static long modeBlockBreak = 0L; + public static boolean disableDepthBuffer = false; + public static float thickness = 4F; + public static float offset = 0F; + public static float red = 0.1F; + public static float green = 1F; + public static float blue = 0.1F; + public static float alpha = 1F; + + @SubscribeEvent + public void onDrawBlockHighlight(DrawBlockHighlightEvent e) { + drawSelectionBox(e.player, e.target, 0, e.currentItem, e.partialTicks); + e.setCanceled(true); + } + + public static void drawSelectionBox(EntityPlayer player, MovingObjectPosition mouseHit, int par3, ItemStack par4ItemStack, float par5) { + if ((par3 == 0) && (mouseHit.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)) { + //float breakProgress = getBlockDamage(player, block); + if (disableDepthBuffer) { + GL11.glDisable(2929); + } + GL11.glEnable(3042); + GL11.glBlendFunc(770, 771); + GL11.glLineWidth(thickness); + GL11.glDisable(3553); + GL11.glDepthMask(false); + float f1 = offset; + + Minecraft mc = Minecraft.getMinecraft(); + Block b = mc.theWorld.getBlock(mouseHit.blockX, mouseHit.blockY, mouseHit.blockZ); + if (b != Blocks.air) { + b.setBlockBoundsBasedOnState(mc.theWorld, mouseHit.blockX, mouseHit.blockY, mouseHit.blockZ); + + double xOffset = player.lastTickPosX + (player.posX - player.lastTickPosX) * par5; + double yOffset = player.lastTickPosY + (player.posY - player.lastTickPosY) * par5; + double zOffset = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * par5; + + float xExpand = 0F; + float yExpand = 0F; + float zExpand = 0F; + + switch ((int) modeBlockBreak) { + case 1: + switch (mouseHit.sideHit) { + case 0: + case 1: + xExpand = 1F; + zExpand = 1F; + break; + case 2: + case 3: + xExpand = 1F; + yExpand = 1F; + break; + case 4: + case 5: + yExpand = 1F; + zExpand = 1F; + break; + } + break; + case 2: + xExpand = 1F; + zExpand = 1F; + break; + case 3: + float rotationYaw = player.rotationYaw; + while (rotationYaw > 0) rotationYaw -= 360F; + while (rotationYaw < -360) rotationYaw += 360F; + if ((-135 <= rotationYaw && rotationYaw <= -45) || (-315 <= rotationYaw && rotationYaw <= -225)) { + yExpand = 1F; + zExpand = 1F; + } else if ((-225 <= rotationYaw && rotationYaw <= -135) || -45 <= rotationYaw || rotationYaw <= -315) { + xExpand = 1F; + yExpand = 1F; + } + break; + case 4: + xExpand = 1F; + yExpand = 1F; + zExpand = 1F; + break; + } + + AxisAlignedBB bb = b.getSelectedBoundingBoxFromPool(mc.theWorld, mouseHit.blockX, mouseHit.blockY, mouseHit.blockZ).expand(xExpand + f1, yExpand + f1, zExpand + f1).getOffsetBoundingBox(-xOffset, -yOffset, -zOffset); + GL11.glColor4f(red, green, blue, alpha); + drawOutlinedBoundingBox(bb); + } + GL11.glDepthMask(true); + GL11.glEnable(3553); + GL11.glDisable(3042); + if (disableDepthBuffer) { + GL11.glEnable(2929); + } + } + } + + + private static void drawOutlinedBoundingBox(AxisAlignedBB par1AxisAlignedBB) { + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawing(3); + tessellator.addVertex(par1AxisAlignedBB.minX, par1AxisAlignedBB.minY, par1AxisAlignedBB.minZ); + tessellator.addVertex(par1AxisAlignedBB.maxX, par1AxisAlignedBB.minY, par1AxisAlignedBB.minZ); + tessellator.addVertex(par1AxisAlignedBB.maxX, par1AxisAlignedBB.minY, par1AxisAlignedBB.maxZ); + tessellator.addVertex(par1AxisAlignedBB.minX, par1AxisAlignedBB.minY, par1AxisAlignedBB.maxZ); + tessellator.addVertex(par1AxisAlignedBB.minX, par1AxisAlignedBB.minY, par1AxisAlignedBB.minZ); + tessellator.draw(); + tessellator.startDrawing(3); + tessellator.addVertex(par1AxisAlignedBB.minX, par1AxisAlignedBB.maxY, par1AxisAlignedBB.minZ); + tessellator.addVertex(par1AxisAlignedBB.maxX, par1AxisAlignedBB.maxY, par1AxisAlignedBB.minZ); + tessellator.addVertex(par1AxisAlignedBB.maxX, par1AxisAlignedBB.maxY, par1AxisAlignedBB.maxZ); + tessellator.addVertex(par1AxisAlignedBB.minX, par1AxisAlignedBB.maxY, par1AxisAlignedBB.maxZ); + tessellator.addVertex(par1AxisAlignedBB.minX, par1AxisAlignedBB.maxY, par1AxisAlignedBB.minZ); + tessellator.draw(); + tessellator.startDrawing(1); + tessellator.addVertex(par1AxisAlignedBB.minX, par1AxisAlignedBB.minY, par1AxisAlignedBB.minZ); + tessellator.addVertex(par1AxisAlignedBB.minX, par1AxisAlignedBB.maxY, par1AxisAlignedBB.minZ); + tessellator.addVertex(par1AxisAlignedBB.maxX, par1AxisAlignedBB.minY, par1AxisAlignedBB.minZ); + tessellator.addVertex(par1AxisAlignedBB.maxX, par1AxisAlignedBB.maxY, par1AxisAlignedBB.minZ); + tessellator.addVertex(par1AxisAlignedBB.maxX, par1AxisAlignedBB.minY, par1AxisAlignedBB.maxZ); + tessellator.addVertex(par1AxisAlignedBB.maxX, par1AxisAlignedBB.maxY, par1AxisAlignedBB.maxZ); + tessellator.addVertex(par1AxisAlignedBB.minX, par1AxisAlignedBB.minY, par1AxisAlignedBB.maxZ); + tessellator.addVertex(par1AxisAlignedBB.minX, par1AxisAlignedBB.maxY, par1AxisAlignedBB.maxZ); + tessellator.draw(); + } + + + static boolean inited = false; + + public static void register() { + if (!inited) { + inited = true; + DetravDrawBlockHighlightEventHandler handler = new DetravDrawBlockHighlightEventHandler(); + MinecraftForge.EVENT_BUS.register(handler); + FMLCommonHandler.instance().bus().register(handler); + } + } +}
\ No newline at end of file diff --git a/src/main/java/com/detrav/net/DetravModePacket03.java b/src/main/java/com/detrav/net/DetravModePacket03.java index 50524a538b..0d087dedf3 100644 --- a/src/main/java/com/detrav/net/DetravModePacket03.java +++ b/src/main/java/com/detrav/net/DetravModePacket03.java @@ -1,12 +1,10 @@ package com.detrav.net; -import com.detrav.DetravScannerMod; -import com.detrav.events.DetravBlockSideRenderEventHandler; +import com.detrav.events.DetravDrawBlockHighlightEventHandler; import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.ChatComponentText; /** * Created by wital_000 on 18.04.2016. @@ -54,6 +52,6 @@ public class DetravModePacket03 extends DetravPacket { @Override public void process() { - DetravBlockSideRenderEventHandler.modeBlockBreak = mode; + DetravDrawBlockHighlightEventHandler.modeBlockBreak = mode; } } diff --git a/src/main/java/com/detrav/proxies/ClientProxy.java b/src/main/java/com/detrav/proxies/ClientProxy.java index a3e3e7653f..2f78f8c739 100644 --- a/src/main/java/com/detrav/proxies/ClientProxy.java +++ b/src/main/java/com/detrav/proxies/ClientProxy.java @@ -2,6 +2,7 @@ package com.detrav.proxies; import com.detrav.DetravScannerMod; import com.detrav.enums.Textures01; +import com.detrav.events.DetravDrawBlockHighlightEventHandler; import com.detrav.events.DetravKeyHandler; import com.detrav.gui.DetravGuiProPick; import gregtech.api.enums.Textures; @@ -22,6 +23,7 @@ public class ClientProxy extends CommonProxy { @Override public void onPostLoad() { super.onPostLoad(); + DetravDrawBlockHighlightEventHandler.register(); //Textures.ItemIcons.CustomIcon test = new Textures.ItemIcons.CustomIcon("iconsets/PRO_PICK_HEAD"); //test.run(); |