use of blusunrize.immersiveengineering.common.blocks.wooden.TileEntityTurntable in project ImmersiveEngineering by BluSunrize.
the class ClientEventHandler method renderAdditionalBlockBounds.
@SubscribeEvent()
public void renderAdditionalBlockBounds(DrawBlockHighlightEvent event) {
if (event.getSubID() == 0 && event.getTarget().typeOfHit == RayTraceResult.Type.BLOCK) {
float f1 = 0.002F;
double px = -TileEntityRendererDispatcher.staticPlayerX;
double py = -TileEntityRendererDispatcher.staticPlayerY;
double pz = -TileEntityRendererDispatcher.staticPlayerZ;
TileEntity tile = event.getPlayer().worldObj.getTileEntity(event.getTarget().getBlockPos());
ItemStack stack = event.getPlayer().getHeldItem(EnumHand.MAIN_HAND);
// if(event.getPlayer().worldObj.getBlockState(event.getTarget().getBlockPos()).getBlock() instanceof IEBlockInterfaces.ICustomBoundingboxes)
if (tile instanceof IAdvancedSelectionBounds) {
// IEBlockInterfaces.ICustomBoundingboxes block = (IEBlockInterfaces.ICustomBoundingboxes) event.getPlayer().worldObj.getBlockState(event.getTarget().getBlockPos()).getBlock();
IAdvancedSelectionBounds iasb = (IAdvancedSelectionBounds) tile;
List<AxisAlignedBB> boxes = iasb.getAdvancedSelectionBounds();
if (boxes != null && !boxes.isEmpty()) {
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
GlStateManager.glLineWidth(2.0F);
GlStateManager.disableTexture2D();
GlStateManager.depthMask(false);
ArrayList<AxisAlignedBB> additionalBoxes = new ArrayList<AxisAlignedBB>();
AxisAlignedBB overrideBox = null;
for (AxisAlignedBB aabb : boxes) if (aabb != null) {
if (iasb.isOverrideBox(aabb, event.getPlayer(), event.getTarget(), additionalBoxes))
overrideBox = aabb;
}
if (overrideBox != null)
RenderGlobal.func_189697_a(overrideBox.expand(f1, f1, f1).offset(px, py, pz), 0, 0, 0, 0.4f);
else
for (AxisAlignedBB aabb : additionalBoxes.isEmpty() ? boxes : additionalBoxes) RenderGlobal.func_189697_a(aabb.expand(f1, f1, f1).offset(px, py, pz), 0, 0, 0, 0.4f);
GlStateManager.depthMask(true);
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
event.setCanceled(true);
}
}
if (Utils.isHammer(stack) && tile instanceof TileEntityTurntable) {
BlockPos pos = event.getTarget().getBlockPos();
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
GlStateManager.glLineWidth(2.0F);
GlStateManager.disableTexture2D();
GlStateManager.depthMask(false);
Tessellator tessellator = Tessellator.getInstance();
VertexBuffer vertexbuffer = tessellator.getBuffer();
EnumFacing f = ((TileEntityTurntable) tile).getFacing();
double tx = pos.getX() + .5;
double ty = pos.getY() + .5;
double tz = pos.getZ() + .5;
if (!event.getPlayer().worldObj.isAirBlock(pos.offset(f))) {
tx += f.getFrontOffsetX();
ty += f.getFrontOffsetY();
tz += f.getFrontOffsetZ();
}
vertexbuffer.setTranslation(tx + px, ty + py, tz + pz);
double angle = -event.getPlayer().ticksExisted % 80 / 40d * Math.PI;
drawRotationArrows(tessellator, vertexbuffer, f, angle, ((TileEntityTurntable) tile).invert);
vertexbuffer.setTranslation(0, 0, 0);
GlStateManager.depthMask(true);
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
}
World world = event.getPlayer().worldObj;
if (stack != null && IEContent.blockConveyor.equals(Block.getBlockFromItem(stack.getItem())) && event.getTarget().sideHit.getAxis() == Axis.Y) {
EnumFacing side = event.getTarget().sideHit;
BlockPos pos = event.getTarget().getBlockPos();
AxisAlignedBB targetedBB = world.getBlockState(pos).getSelectedBoundingBox(world, pos);
if (targetedBB != null)
targetedBB = targetedBB.offset(-pos.getX(), -pos.getY(), -pos.getZ());
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
GlStateManager.glLineWidth(2.0F);
GlStateManager.disableTexture2D();
GlStateManager.depthMask(false);
Tessellator tessellator = Tessellator.getInstance();
VertexBuffer vertexbuffer = tessellator.getBuffer();
vertexbuffer.setTranslation(pos.getX() + px, pos.getY() + py, pos.getZ() + pz);
double[][] points = new double[4][];
if (side.getAxis() == Axis.Y) {
points[0] = new double[] { 0 - f1, side == EnumFacing.DOWN ? ((targetedBB != null ? targetedBB.minY : 0) - f1) : ((targetedBB != null ? targetedBB.maxY : 1) + f1), 0 - f1 };
points[1] = new double[] { 1 + f1, side == EnumFacing.DOWN ? ((targetedBB != null ? targetedBB.minY : 0) - f1) : ((targetedBB != null ? targetedBB.maxY : 1) + f1), 1 + f1 };
points[2] = new double[] { 0 - f1, side == EnumFacing.DOWN ? ((targetedBB != null ? targetedBB.minY : 0) - f1) : ((targetedBB != null ? targetedBB.maxY : 1) + f1), 1 + f1 };
points[3] = new double[] { 1 + f1, side == EnumFacing.DOWN ? ((targetedBB != null ? targetedBB.minY : 0) - f1) : ((targetedBB != null ? targetedBB.maxY : 1) + f1), 0 - f1 };
} else if (side.getAxis() == Axis.Z) {
points[0] = new double[] { 1 + f1, 1 + f1, side == EnumFacing.NORTH ? ((targetedBB != null ? targetedBB.minZ : 0) - f1) : ((targetedBB != null ? targetedBB.maxZ : 1) + f1) };
points[1] = new double[] { 0 - f1, 0 - f1, side == EnumFacing.NORTH ? ((targetedBB != null ? targetedBB.minZ : 0) - f1) : ((targetedBB != null ? targetedBB.maxZ : 1) + f1) };
points[2] = new double[] { 0 - f1, 1 + f1, side == EnumFacing.NORTH ? ((targetedBB != null ? targetedBB.minZ : 0) - f1) : ((targetedBB != null ? targetedBB.maxZ : 1) + f1) };
points[3] = new double[] { 1 + f1, 0 - f1, side == EnumFacing.NORTH ? ((targetedBB != null ? targetedBB.minZ : 0) - f1) : ((targetedBB != null ? targetedBB.maxZ : 1) + f1) };
} else {
points[0] = new double[] { side == EnumFacing.WEST ? ((targetedBB != null ? targetedBB.minX : 0) - f1) : ((targetedBB != null ? targetedBB.maxX : 1) + f1), 1 + f1, 1 + f1 };
points[1] = new double[] { side == EnumFacing.WEST ? ((targetedBB != null ? targetedBB.minX : 0) - f1) : ((targetedBB != null ? targetedBB.maxX : 1) + f1), 0 - f1, 0 - f1 };
points[2] = new double[] { side == EnumFacing.WEST ? ((targetedBB != null ? targetedBB.minX : 0) - f1) : ((targetedBB != null ? targetedBB.maxX : 1) + f1), 1 + f1, 0 - f1 };
points[3] = new double[] { side == EnumFacing.WEST ? ((targetedBB != null ? targetedBB.minX : 0) - f1) : ((targetedBB != null ? targetedBB.maxX : 1) + f1), 0 - f1, 1 + f1 };
}
vertexbuffer.begin(1, DefaultVertexFormats.POSITION_COLOR);
for (double[] point : points) vertexbuffer.pos(point[0], point[1], point[2]).color(0, 0, 0, 0.4F).endVertex();
tessellator.draw();
vertexbuffer.begin(2, DefaultVertexFormats.POSITION_COLOR);
vertexbuffer.pos(points[0][0], points[0][1], points[0][2]).color(0, 0, 0, 0.4F).endVertex();
vertexbuffer.pos(points[2][0], points[2][1], points[2][2]).color(0, 0, 0, 0.4F).endVertex();
vertexbuffer.pos(points[1][0], points[1][1], points[1][2]).color(0, 0, 0, 0.4F).endVertex();
vertexbuffer.pos(points[3][0], points[3][1], points[3][2]).color(0, 0, 0, 0.4F).endVertex();
tessellator.draw();
float xFromMid = side.getAxis() == Axis.X ? 0 : (float) event.getTarget().hitVec.xCoord - pos.getX() - .5f;
float yFromMid = side.getAxis() == Axis.Y ? 0 : (float) event.getTarget().hitVec.yCoord - pos.getY() - .5f;
float zFromMid = side.getAxis() == Axis.Z ? 0 : (float) event.getTarget().hitVec.zCoord - pos.getZ() - .5f;
float max = Math.max(Math.abs(yFromMid), Math.max(Math.abs(xFromMid), Math.abs(zFromMid)));
Vec3d dir = new Vec3d(max == Math.abs(xFromMid) ? Math.signum(xFromMid) : 0, max == Math.abs(yFromMid) ? Math.signum(yFromMid) : 0, max == Math.abs(zFromMid) ? Math.signum(zFromMid) : 0);
if (dir != null)
drawBlockOverlayArrow(tessellator, vertexbuffer, dir, side, targetedBB);
vertexbuffer.setTranslation(0, 0, 0);
GlStateManager.depthMask(true);
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
}
if (stack != null && stack.getItem() instanceof ItemDrill && ((ItemDrill) stack.getItem()).isEffective(world.getBlockState(event.getTarget().getBlockPos()).getMaterial())) {
ItemStack head = ((ItemDrill) stack.getItem()).getHead(stack);
if (head != null) {
ImmutableList<BlockPos> blocks = ((IDrillHead) head.getItem()).getExtraBlocksDug(head, world, event.getPlayer(), event.getTarget());
drawAdditionalBlockbreak(event.getContext(), event.getPlayer(), event.getPartialTicks(), blocks);
}
}
}
}
Aggregations