2018-08-09 21:48:10 +00:00
|
|
|
/*
|
|
|
|
* This file is part of Baritone.
|
|
|
|
*
|
|
|
|
* Baritone is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Baritone is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package baritone.bot.utils;
|
|
|
|
|
|
|
|
import baritone.bot.pathing.path.IPath;
|
|
|
|
import net.minecraft.block.state.IBlockState;
|
2018-08-09 23:44:41 +00:00
|
|
|
import net.minecraft.client.Minecraft;
|
2018-08-09 21:48:10 +00:00
|
|
|
import net.minecraft.client.entity.EntityPlayerSP;
|
|
|
|
import net.minecraft.client.renderer.BufferBuilder;
|
|
|
|
import net.minecraft.client.renderer.GlStateManager;
|
|
|
|
import net.minecraft.client.renderer.Tessellator;
|
|
|
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.init.Blocks;
|
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
|
|
|
|
import java.awt.*;
|
2018-08-09 23:44:41 +00:00
|
|
|
import java.util.Collection;
|
2018-08-09 21:48:10 +00:00
|
|
|
import java.util.List;
|
|
|
|
|
2018-08-10 01:25:43 +00:00
|
|
|
import static org.lwjgl.opengl.GL11.*;
|
2018-08-09 21:48:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Brady
|
|
|
|
* @since 8/9/2018 4:39 PM
|
|
|
|
*/
|
|
|
|
public final class PathRenderer implements Helper {
|
|
|
|
|
|
|
|
private PathRenderer() {}
|
|
|
|
|
2018-08-10 01:25:43 +00:00
|
|
|
private static final Tessellator TESSELLATOR = Tessellator.getInstance();
|
|
|
|
private static final BufferBuilder BUFFER = TESSELLATOR.getBuffer();
|
2018-08-09 23:44:41 +00:00
|
|
|
|
2018-08-09 21:48:10 +00:00
|
|
|
public static void drawPath(IPath path, int startIndex, EntityPlayerSP player, float partialTicks, Color color) {
|
|
|
|
GlStateManager.enableBlend();
|
2018-08-10 01:25:43 +00:00
|
|
|
GlStateManager.tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
|
2018-08-09 21:48:10 +00:00
|
|
|
GlStateManager.color(color.getColorComponents(null)[0], color.getColorComponents(null)[1], color.getColorComponents(null)[2], 0.4F);
|
2018-08-11 04:43:23 +00:00
|
|
|
GlStateManager.glLineWidth(3.0F);
|
2018-08-09 21:48:10 +00:00
|
|
|
GlStateManager.disableTexture2D();
|
|
|
|
GlStateManager.depthMask(false);
|
|
|
|
List<BlockPos> positions = path.positions();
|
|
|
|
int next;
|
2018-08-09 23:44:41 +00:00
|
|
|
Tessellator tessellator = Tessellator.getInstance();
|
2018-08-09 21:48:10 +00:00
|
|
|
for (int i = startIndex; i < positions.size() - 1; i = next) {
|
|
|
|
BlockPos start = positions.get(i);
|
|
|
|
|
|
|
|
next = i + 1;
|
|
|
|
BlockPos end = positions.get(next);
|
2018-08-10 01:25:43 +00:00
|
|
|
BlockPos direction = Utils.diff(start, end);
|
|
|
|
while (next + 1 < positions.size() && direction.equals(Utils.diff(end, positions.get(next + 1)))) {
|
2018-08-09 21:48:10 +00:00
|
|
|
next++;
|
|
|
|
end = positions.get(next);
|
|
|
|
}
|
|
|
|
double x1 = start.getX();
|
|
|
|
double y1 = start.getY();
|
|
|
|
double z1 = start.getZ();
|
|
|
|
double x2 = end.getX();
|
|
|
|
double y2 = end.getY();
|
|
|
|
double z2 = end.getZ();
|
2018-08-10 01:25:43 +00:00
|
|
|
drawLine(player, x1, y1, z1, x2, y2, z2, partialTicks);
|
2018-08-09 23:44:41 +00:00
|
|
|
tessellator.draw();
|
2018-08-09 21:48:10 +00:00
|
|
|
}
|
2018-08-09 23:44:41 +00:00
|
|
|
//GlStateManager.color(0.0f, 0.0f, 0.0f, 0.4f);
|
2018-08-09 21:48:10 +00:00
|
|
|
GlStateManager.depthMask(true);
|
|
|
|
GlStateManager.enableTexture2D();
|
|
|
|
GlStateManager.disableBlend();
|
|
|
|
}
|
|
|
|
|
2018-08-10 01:25:43 +00:00
|
|
|
public static void drawLine(EntityPlayer player, double bp1x, double bp1y, double bp1z, double bp2x, double bp2y, double bp2z, float partialTicks) {
|
2018-08-09 21:48:10 +00:00
|
|
|
double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double) partialTicks;
|
|
|
|
double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double) partialTicks;
|
|
|
|
double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double) partialTicks;
|
2018-08-10 01:25:43 +00:00
|
|
|
BUFFER.begin(GL_LINE_STRIP, DefaultVertexFormats.POSITION);
|
|
|
|
BUFFER.pos(bp1x + 0.5D - d0, bp1y + 0.5D - d1, bp1z + 0.5D - d2).endVertex();
|
|
|
|
BUFFER.pos(bp2x + 0.5D - d0, bp2y + 0.5D - d1, bp2z + 0.5D - d2).endVertex();
|
|
|
|
BUFFER.pos(bp2x + 0.5D - d0, bp2y + 0.53D - d1, bp2z + 0.5D - d2).endVertex();
|
|
|
|
BUFFER.pos(bp1x + 0.5D - d0, bp1y + 0.53D - d1, bp1z + 0.5D - d2).endVertex();
|
|
|
|
BUFFER.pos(bp1x + 0.5D - d0, bp1y + 0.5D - d1, bp1z + 0.5D - d2).endVertex();
|
2018-08-09 21:48:10 +00:00
|
|
|
}
|
|
|
|
|
2018-08-09 23:44:41 +00:00
|
|
|
public static void drawManySelectionBoxes(EntityPlayer player, Collection<BlockPos> positions, float partialTicks, Color color) {
|
2018-08-09 21:48:10 +00:00
|
|
|
GlStateManager.enableBlend();
|
2018-08-09 23:44:41 +00:00
|
|
|
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
|
2018-08-09 21:48:10 +00:00
|
|
|
GlStateManager.color(color.getColorComponents(null)[0], color.getColorComponents(null)[1], color.getColorComponents(null)[2], 0.4F);
|
2018-08-11 04:43:23 +00:00
|
|
|
GlStateManager.glLineWidth(5.0F);
|
2018-08-09 21:48:10 +00:00
|
|
|
GlStateManager.disableTexture2D();
|
|
|
|
GlStateManager.depthMask(false);
|
2018-08-10 01:25:43 +00:00
|
|
|
float expand = 0.002F;
|
2018-08-09 23:44:41 +00:00
|
|
|
//BlockPos blockpos = movingObjectPositionIn.getBlockPos();
|
|
|
|
|
2018-08-10 01:25:43 +00:00
|
|
|
double renderPosX = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double) partialTicks;
|
|
|
|
double renderPosY = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double) partialTicks;
|
|
|
|
double renderPosZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double) partialTicks;
|
|
|
|
positions.forEach(pos -> {
|
2018-08-09 23:44:41 +00:00
|
|
|
IBlockState state = BlockStateInterface.get(pos);
|
|
|
|
AxisAlignedBB toDraw;
|
2018-08-10 01:25:43 +00:00
|
|
|
if (state.getBlock().equals(Blocks.AIR)) {
|
|
|
|
toDraw = Blocks.DIRT.getDefaultState().getSelectedBoundingBox(Minecraft.getMinecraft().world, pos);
|
2018-08-09 23:44:41 +00:00
|
|
|
} else {
|
|
|
|
toDraw = state.getSelectedBoundingBox(Minecraft.getMinecraft().world, pos);
|
|
|
|
}
|
2018-08-10 01:25:43 +00:00
|
|
|
toDraw = toDraw.expand(expand, expand, expand).offset(-renderPosX, -renderPosY, -renderPosZ);
|
|
|
|
BUFFER.begin(GL_LINE_STRIP, DefaultVertexFormats.POSITION);
|
|
|
|
BUFFER.pos(toDraw.minX, toDraw.minY, toDraw.minZ).endVertex();
|
|
|
|
BUFFER.pos(toDraw.maxX, toDraw.minY, toDraw.minZ).endVertex();
|
|
|
|
BUFFER.pos(toDraw.maxX, toDraw.minY, toDraw.maxZ).endVertex();
|
|
|
|
BUFFER.pos(toDraw.minX, toDraw.minY, toDraw.maxZ).endVertex();
|
|
|
|
BUFFER.pos(toDraw.minX, toDraw.minY, toDraw.minZ).endVertex();
|
|
|
|
TESSELLATOR.draw();
|
|
|
|
BUFFER.begin(GL_LINE_STRIP, DefaultVertexFormats.POSITION);
|
|
|
|
BUFFER.pos(toDraw.minX, toDraw.maxY, toDraw.minZ).endVertex();
|
|
|
|
BUFFER.pos(toDraw.maxX, toDraw.maxY, toDraw.minZ).endVertex();
|
|
|
|
BUFFER.pos(toDraw.maxX, toDraw.maxY, toDraw.maxZ).endVertex();
|
|
|
|
BUFFER.pos(toDraw.minX, toDraw.maxY, toDraw.maxZ).endVertex();
|
|
|
|
BUFFER.pos(toDraw.minX, toDraw.maxY, toDraw.minZ).endVertex();
|
|
|
|
TESSELLATOR.draw();
|
|
|
|
BUFFER.begin(GL_LINES, DefaultVertexFormats.POSITION);
|
|
|
|
BUFFER.pos(toDraw.minX, toDraw.minY, toDraw.minZ).endVertex();
|
|
|
|
BUFFER.pos(toDraw.minX, toDraw.maxY, toDraw.minZ).endVertex();
|
|
|
|
BUFFER.pos(toDraw.maxX, toDraw.minY, toDraw.minZ).endVertex();
|
|
|
|
BUFFER.pos(toDraw.maxX, toDraw.maxY, toDraw.minZ).endVertex();
|
|
|
|
BUFFER.pos(toDraw.maxX, toDraw.minY, toDraw.maxZ).endVertex();
|
|
|
|
BUFFER.pos(toDraw.maxX, toDraw.maxY, toDraw.maxZ).endVertex();
|
|
|
|
BUFFER.pos(toDraw.minX, toDraw.minY, toDraw.maxZ).endVertex();
|
|
|
|
BUFFER.pos(toDraw.minX, toDraw.maxY, toDraw.maxZ).endVertex();
|
|
|
|
TESSELLATOR.draw();
|
|
|
|
});
|
2018-08-09 23:44:41 +00:00
|
|
|
|
2018-08-09 21:48:10 +00:00
|
|
|
GlStateManager.depthMask(true);
|
|
|
|
GlStateManager.enableTexture2D();
|
|
|
|
GlStateManager.disableBlend();
|
|
|
|
}
|
|
|
|
}
|