hell merge

This commit is contained in:
Leijurv 2018-08-09 16:44:41 -07:00
commit e6494cdf53
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
7 changed files with 252 additions and 201 deletions

View File

@ -17,7 +17,6 @@
package baritone.bot.behavior.impl;
import baritone.bot.pathing.movement.MovementHelper;
import baritone.bot.utils.BlockStateInterface;
import baritone.bot.utils.Helper;
import baritone.bot.utils.Rotation;
@ -27,15 +26,20 @@ import net.minecraft.util.math.*;
import java.util.Optional;
import static baritone.bot.utils.Utils.DEG_TO_RAD;
public final class LookBehaviorUtils implements Helper {
public static final Vec3d[] BLOCK_SIDE_MULTIPLIERS = new Vec3d[]{
new Vec3d(0, 0.5, 0.5),
new Vec3d(1, 0.5, 0.5),
new Vec3d(0.5, 0, 0.5),
new Vec3d(0.5, 1, 0.5),
new Vec3d(0.5, 0.5, 0),
new Vec3d(0.5, 0.5, 1)
/**
* Offsets from the root block position to the center of each side.
*/
private static final Vec3d[] BLOCK_SIDE_MULTIPLIERS = new Vec3d[] {
new Vec3d(0.5, 0, 0.5), // Down
new Vec3d(0.5, 1, 0.5), // Up
new Vec3d(0.5, 0.5, 0), // North
new Vec3d(0.5, 0.5, 1), // South
new Vec3d(0, 0.5, 0.5), // West
new Vec3d(1, 0.5, 0.5) // East
};
/**
@ -45,10 +49,10 @@ public final class LookBehaviorUtils implements Helper {
* @return vector of the rotation
*/
public static Vec3d calcVec3dFromRotation(Rotation rotation) {
float f = MathHelper.cos(-rotation.getFirst() * 0.017453292F - (float) Math.PI);
float f1 = MathHelper.sin(-rotation.getFirst() * 0.017453292F - (float) Math.PI);
float f2 = -MathHelper.cos(-rotation.getSecond() * 0.017453292F);
float f3 = MathHelper.sin(-rotation.getSecond() * 0.017453292F);
float f = MathHelper.cos(-rotation.getFirst() * (float) DEG_TO_RAD - (float) Math.PI);
float f1 = MathHelper.sin(-rotation.getFirst() * (float) DEG_TO_RAD - (float) Math.PI);
float f2 = -MathHelper.cos(-rotation.getSecond() * (float) DEG_TO_RAD);
float f3 = MathHelper.sin(-rotation.getSecond() * (float) DEG_TO_RAD);
return new Vec3d((double) (f1 * f2), (double) f3, (double) (f * f2));
}
@ -60,16 +64,13 @@ public final class LookBehaviorUtils implements Helper {
if (possibleRotation.isPresent())
return possibleRotation;
IBlockState bstate = BlockStateInterface.get(pos);
AxisAlignedBB bbox = bstate.getBoundingBox(mc.world, pos);
for (Vec3d vecMult : BLOCK_SIDE_MULTIPLIERS) {
double xDiff = bbox.minX * vecMult.x + bbox.maxX * (1 - vecMult.x);//lol
double yDiff = bbox.minY * vecMult.y + bbox.maxY * (1 - vecMult.y);
double zDiff = bbox.minZ * vecMult.z + bbox.maxZ * (1 - vecMult.z);
double x = pos.getX() + xDiff;
double y = pos.getY() + yDiff;
double z = pos.getZ() + zDiff;
possibleRotation = reachableRotation(pos, new Vec3d(x, y, z));
IBlockState state = BlockStateInterface.get(pos);
AxisAlignedBB aabb = state.getBoundingBox(mc.world, pos);
for (Vec3d sideOffset : BLOCK_SIDE_MULTIPLIERS) {
double xDiff = aabb.minX * sideOffset.x + aabb.maxX * (1 - sideOffset.x);
double yDiff = aabb.minY * sideOffset.y + aabb.maxY * (1 - sideOffset.y);
double zDiff = aabb.minZ * sideOffset.z + aabb.maxZ * (1 - sideOffset.z);
possibleRotation = reachableOffset(pos, new Vec3d(pos).add(xDiff, yDiff, zDiff));
if (possibleRotation.isPresent())
return possibleRotation;
}
@ -77,25 +78,26 @@ public final class LookBehaviorUtils implements Helper {
}
private static RayTraceResult rayTraceTowards(Rotation rotation) {
double blockReachDistance = (double) mc.playerController.getBlockReachDistance();
Vec3d vec3 = mc.player.getPositionEyes(1.0F);
Vec3d vec31 = calcVec3dFromRotation(rotation);
Vec3d vec32 = vec3.add(vec31.x * blockReachDistance,
vec31.y * blockReachDistance,
vec31.z * blockReachDistance);
return mc.world.rayTraceBlocks(vec3, vec32, false, false, true);
double blockReachDistance = mc.playerController.getBlockReachDistance();
Vec3d start = mc.player.getPositionEyes(1.0F);
Vec3d direction = calcVec3dFromRotation(rotation);
Vec3d end = start.add(
direction.x * blockReachDistance,
direction.y * blockReachDistance,
direction.z * blockReachDistance
);
return mc.world.rayTraceBlocks(start, end, false, false, true);
}
/**
* Checks if coordinate is reachable with the given block-face rotation offset
*
* @param pos
* @param offset
* @param offsetPos
* @return
*/
protected static Optional<Rotation> reachableRotation(BlockPos pos, Vec3d offset) {
Rotation rotation = Utils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F),
offset);
protected static Optional<Rotation> reachableOffset(BlockPos pos, Vec3d offsetPos) {
Rotation rotation = Utils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F), offsetPos);
RayTraceResult result = rayTraceTowards(rotation);
if (result != null
&& result.typeOfHit == RayTraceResult.Type.BLOCK
@ -111,14 +113,7 @@ public final class LookBehaviorUtils implements Helper {
* @return
*/
protected static Optional<Rotation> reachableCenter(BlockPos pos) {
Rotation rotation = Utils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F),
Utils.calcCenterFromCoords(pos, mc.world));
RayTraceResult result = rayTraceTowards(rotation);
if (result != null
&& result.typeOfHit == RayTraceResult.Type.BLOCK
&& result.getBlockPos().equals(pos))
return Optional.of(rotation);
return Optional.empty();
return reachableOffset(pos, Utils.calcCenterFromCoords(pos, mc.world));
}
/**
@ -133,5 +128,4 @@ public final class LookBehaviorUtils implements Helper {
}
return Optional.empty();
}
}

View File

@ -30,25 +30,11 @@ import baritone.bot.pathing.goals.GoalBlock;
import baritone.bot.pathing.goals.GoalXZ;
import baritone.bot.pathing.path.IPath;
import baritone.bot.pathing.path.PathExecutor;
import baritone.bot.utils.BlockStateInterface;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
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 baritone.bot.utils.PathRenderer;
import net.minecraft.util.math.BlockPos;
import org.lwjgl.opengl.GL11;
import java.awt.*;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
public class PathingBehavior extends Behavior {
@ -74,14 +60,6 @@ public class PathingBehavior extends Behavior {
}
}
public PathExecutor getExecutor() {
return current;
}
public Optional<IPath> getPath() {
return Optional.ofNullable(current).map(PathExecutor::getPath);
}
@Override
public void onSendChatMessage(ChatEvent event) {
String msg = event.getMessage();
@ -109,18 +87,19 @@ public class PathingBehavior extends Behavior {
return;
}
if (msg.toLowerCase().startsWith("thisway")) {
goal = fromAngleAndDirection(Double.parseDouble(msg.substring(7).trim()));
goal = GoalXZ.fromDirection(playerFeetAsVec(), player().rotationYaw, Double.parseDouble(msg.substring(7).trim()));
displayChatMessageRaw("Goal: " + goal);
event.cancel();
return;
}
}
public GoalXZ fromAngleAndDirection(double distance) {
double theta = ((double) player().rotationYaw) * Math.PI / 180D;
double x = player().posX - Math.sin(theta) * distance;
double z = player().posZ + Math.cos(theta) * distance;
return new GoalXZ((int) x, (int) z);
public PathExecutor getExecutor() {
return current;
}
public Optional<IPath> getPath() {
return Optional.ofNullable(current).map(PathExecutor::getPath);
}
/**
@ -136,7 +115,8 @@ public class PathingBehavior extends Behavior {
}
findPath(start).map(PathExecutor::new).ifPresent(path -> current = path);
/*isThereAnythingInProgress = false;
/*
isThereAnythingInProgress = false;
if (!currentPath.goal.isInGoal(currentPath.end)) {
if (talkAboutIt) {
Out.gui("I couldn't get all the way to " + goal + ", but I'm going to get as close as I can. " + currentPath.numNodes + " nodes considered", Out.Mode.Standard);
@ -144,7 +124,8 @@ public class PathingBehavior extends Behavior {
planAhead();
} else if (talkAboutIt) {
Out.gui(, Out.Mode.Debug);
}*/
}
*/
if (talkAboutIt && current != null && current.getPath() != null) {
displayChatMessageRaw("Finished finding a path from " + start + " to " + goal + ". " + current.getPath().getNumNodesConsidered() + " nodes considered");
}
@ -173,29 +154,31 @@ public class PathingBehavior extends Behavior {
@Override
public void onRenderPass(RenderEvent event) {
//System.out.println("Render passing");
//System.out.println(event.getPartialTicks());
// System.out.println("Render passing");
// System.out.println(event.getPartialTicks());
float partialTicks = event.getPartialTicks();
long start = System.nanoTime();
// Render the current path, if there is one
if (current != null && current.getPath() != null) {
int renderBegin = Math.max(current.getPosition() - 3, 0);
drawPath(current.getPath(), renderBegin, player(), partialTicks, Color.RED);
PathRenderer.drawPath(current.getPath(), renderBegin, player(), partialTicks, Color.RED);
}
long split = System.nanoTime();
if (current != null) {
drawManySelectionBoxes(player(), current.toBreak(), partialTicks, Color.RED);
drawManySelectionBoxes(player(), current.toPlace(), partialTicks, Color.GREEN);
PathRenderer.drawManySelectionBoxes(player(), current.toBreak(), partialTicks, Color.RED);
PathRenderer.drawManySelectionBoxes(player(), current.toPlace(), partialTicks, Color.GREEN);
}
// If there is a path calculation currently running, render the path calculation process
AbstractNodeCostSearch.getCurrentlyRunning().ifPresent(currentlyRunning -> {
currentlyRunning.bestPathSoFar().ifPresent(p -> {
drawPath(p, 0, player(), partialTicks, Color.BLUE);
PathRenderer.drawPath(p, 0, player(), partialTicks, Color.BLUE);
currentlyRunning.pathToMostRecentNodeConsidered().ifPresent(mr -> {
drawPath(mr, 0, player(), partialTicks, Color.CYAN);
drawManySelectionBoxes(player(), Arrays.asList(mr.getDest()), partialTicks, Color.CYAN);
PathRenderer.drawPath(mr, 0, player(), partialTicks, Color.CYAN);
PathRenderer.drawManySelectionBoxes(player(), Arrays.asList(mr.getDest()), partialTicks, Color.CYAN);
});
});
});
@ -203,118 +186,6 @@ public class PathingBehavior extends Behavior {
//System.out.println((end - split) + " " + (split - start));
// if (end - start > 0)
// System.out.println("Frame took " + (split - start) + " " + (end - split));
}
private static BlockPos diff(BlockPos a, BlockPos b) {
return new BlockPos(a.getX() - b.getX(), a.getY() - b.getY(), a.getZ() - b.getZ());
}
public void drawPath(IPath path, int startIndex, EntityPlayerSP player, float partialTicks, Color color) {
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
GlStateManager.color(color.getColorComponents(null)[0], color.getColorComponents(null)[1], color.getColorComponents(null)[2], 0.4F);
GL11.glLineWidth(3.0F);
GlStateManager.disableTexture2D();
GlStateManager.depthMask(false);
List<BlockPos> positions = path.positions();
int next;
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer();
for (int i = startIndex; i < positions.size() - 1; i = next) {
BlockPos start = positions.get(i);
next = i + 1;
BlockPos end = positions.get(next);
BlockPos direction = diff(start, end);
while (next + 1 < positions.size() && direction.equals(diff(end, positions.get(next + 1)))) {
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();
drawLine(player, x1, y1, z1, x2, y2, z2, partialTicks, buffer);
}
tessellator.draw();
//GlStateManager.color(0.0f, 0.0f, 0.0f, 0.4f);
GlStateManager.depthMask(true);
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
}
public static void drawLine(EntityPlayer player, double bp1x, double bp1y, double bp1z, double bp2x, double bp2y, double bp2z, float partialTicks, BufferBuilder buffer) {
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;
buffer.begin(3, 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();
}
public static void drawManySelectionBoxes(EntityPlayer player, Collection<BlockPos> positions, float partialTicks, Color color) {
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
GlStateManager.color(color.getColorComponents(null)[0], color.getColorComponents(null)[1], color.getColorComponents(null)[2], 0.4F);
GL11.glLineWidth(5.0F);
GlStateManager.disableTexture2D();
GlStateManager.depthMask(false);
float f = 0.002F;
//BlockPos blockpos = movingObjectPositionIn.getBlockPos();
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;
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer();
for (BlockPos pos : positions) {
IBlockState state = BlockStateInterface.get(pos);
Block block = state.getBlock();
AxisAlignedBB toDraw;
if (block.equals(Blocks.AIR)) {
toDraw = Blocks.DIRT.getSelectedBoundingBox(state, Minecraft.getMinecraft().world, pos);
} else {
toDraw = state.getSelectedBoundingBox(Minecraft.getMinecraft().world, pos);
}
toDraw = toDraw.expand(0.0020000000949949026D, 0.0020000000949949026D, 0.0020000000949949026D).offset(-d0, -d1, -d2);
buffer.begin(3, 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(3, 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(1, 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();
GlStateManager.depthMask(true);
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
}
}

View File

@ -17,7 +17,9 @@
package baritone.bot.pathing.goals;
import baritone.bot.utils.Utils;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
/**
* Useful for long-range goals that don't have a specific Y level.
@ -54,6 +56,11 @@ public class GoalXZ implements Goal {
return calculate(xDiff, zDiff);
}
@Override
public String toString() {
return "Goal{x=" + x + ",z=" + z + "}";
}
public static double calculate(double xDiff, double zDiff) {
return calculate(xDiff, zDiff, 0);
}
@ -93,8 +100,10 @@ public class GoalXZ implements Goal {
return (diagonal + straight) * WALK_ONE_BLOCK_COST;
}
@Override
public String toString() {
return "Goal{x=" + x + ",z=" + z + "}";
public static GoalXZ fromDirection(Vec3d origin, float yaw, double distance) {
double theta = Utils.degToRad(yaw);
double x = origin.x - Math.sin(theta) * distance;
double z = origin.z + Math.cos(theta) * distance;
return new GoalXZ((int) x, (int) z);
}
}

View File

@ -50,6 +50,10 @@ public interface Helper {
return new BlockPos(player().posX, player().posY, player().posZ);
}
default Vec3d playerFeetAsVec() {
return new Vec3d(player().posX, player().posY, player().posZ);
}
default Vec3d playerHead() {
return new Vec3d(player().posX, player().posY + player().getEyeHeight(), player().posZ);
}

View File

@ -0,0 +1,157 @@
/*
* 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.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
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 org.lwjgl.opengl.GL11;
import java.awt.*;
import java.util.Collection;
import java.util.List;
import static org.lwjgl.opengl.GL11.GL_LINES;
import static org.lwjgl.opengl.GL11.GL_LINE_STRIP;
/**
* @author Brady
* @since 8/9/2018 4:39 PM
*/
public final class PathRenderer implements Helper {
private PathRenderer() {}
private static BlockPos diff(BlockPos a, BlockPos b) {
return new BlockPos(a.getX() - b.getX(), a.getY() - b.getY(), a.getZ() - b.getZ());
}
public static void drawPath(IPath path, int startIndex, EntityPlayerSP player, float partialTicks, Color color) {
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
GlStateManager.color(color.getColorComponents(null)[0], color.getColorComponents(null)[1], color.getColorComponents(null)[2], 0.4F);
GL11.glLineWidth(3.0F);
GlStateManager.disableTexture2D();
GlStateManager.depthMask(false);
List<BlockPos> positions = path.positions();
int next;
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer();
for (int i = startIndex; i < positions.size() - 1; i = next) {
BlockPos start = positions.get(i);
next = i + 1;
BlockPos end = positions.get(next);
BlockPos direction = diff(start, end);
while (next + 1 < positions.size() && direction.equals(diff(end, positions.get(next + 1)))) {
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();
drawLine(player, x1, y1, z1, x2, y2, z2, partialTicks, buffer);
tessellator.draw();
}
//GlStateManager.color(0.0f, 0.0f, 0.0f, 0.4f);
GlStateManager.depthMask(true);
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
}
public static void drawLine(EntityPlayer player, double bp1x, double bp1y, double bp1z, double bp2x, double bp2y, double bp2z, float partialTicks, BufferBuilder buffer) {
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;
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();
}
public static void drawManySelectionBoxes(EntityPlayer player, Collection<BlockPos> positions, float partialTicks, Color color) {
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
GlStateManager.color(color.getColorComponents(null)[0], color.getColorComponents(null)[1], color.getColorComponents(null)[2], 0.4F);
GL11.glLineWidth(5.0F);
GlStateManager.disableTexture2D();
GlStateManager.depthMask(false);
float f = 0.002F;
//BlockPos blockpos = movingObjectPositionIn.getBlockPos();
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;
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer();
for (BlockPos pos : positions) {
IBlockState state = BlockStateInterface.get(pos);
Block block = state.getBlock();
AxisAlignedBB toDraw;
if (block.equals(Blocks.AIR)) {
toDraw = Blocks.DIRT.getSelectedBoundingBox(state, Minecraft.getMinecraft().world, pos);
} else {
toDraw = state.getSelectedBoundingBox(Minecraft.getMinecraft().world, pos);
}
toDraw = toDraw.expand(0.0020000000949949026D, 0.0020000000949949026D, 0.0020000000949949026D).offset(-d0, -d1, -d2);
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();
}
GlStateManager.depthMask(true);
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
}
}

View File

@ -21,7 +21,7 @@ import net.minecraft.util.Tuple;
public class Rotation extends Tuple<Float, Float> {
public Rotation(float yaw, float pitch) {
public Rotation(Float yaw, Float pitch) {
super(yaw, pitch);
}
}

View File

@ -30,6 +30,16 @@ import net.minecraft.world.World;
*/
public final class Utils {
/**
* Constant that a degree value is multiplied by to get the equivalent radian value
*/
public static final double DEG_TO_RAD = Math.PI / 180.0;
/**
* Constant that a radian value is multiplied by to get the equivalent degree value
*/
public static final double RAD_TO_DEG = 180.0 / Math.PI;
public static Rotation calcRotationFromCoords(BlockPos orig, BlockPos dest) {
return calcRotationFromVec3d(vec3dFromBlockPos(orig), vec3dFromBlockPos(dest));
}
@ -69,9 +79,11 @@ public final class Utils {
double xDiff = (bbox.minX + bbox.maxX) / 2;
double yDiff = (bbox.minY + bbox.maxY) / 2;
double zDiff = (bbox.minZ + bbox.maxZ) / 2;
return new Vec3d(orig.getX() + xDiff,
return new Vec3d(
orig.getX() + xDiff,
orig.getY() + yDiff,
orig.getZ() + zDiff);
orig.getZ() + zDiff
);
}
public static Vec3d getBlockPosCenter(BlockPos pos) {
@ -97,10 +109,14 @@ public final class Utils {
}
public static double degToRad(double deg) {
return deg * Math.PI / 180.0;
return deg * DEG_TO_RAD;
}
public static double radToDeg(double rad) {
return rad * 180.0 / Math.PI;
return rad * RAD_TO_DEG;
}
public static BlockPos diff(BlockPos a, BlockPos b) {
return new BlockPos(a.getX() - b.getX(), a.getY() - b.getY(), a.getZ() - b.getZ());
}
}