use of riskyken.armourersWorkshop.common.blocks.BlockColourable in project Armourers-Workshop by RiskyKen.
the class BlockUtils method findTouchingBlockFaces.
public static ArrayList<BlockLocation> findTouchingBlockFaces(World world, int x, int y, int z, int side, int radius) {
ForgeDirection dir = ForgeDirection.getOrientation(side);
ArrayList<BlockLocation> blockFaces = new ArrayList<BlockLocation>();
ArrayList<BlockLocation> openList = new ArrayList<BlockLocation>();
ArrayList<BlockLocation> closedList = new ArrayList<BlockLocation>();
openList.add(new BlockLocation(x, y, z).offset(dir));
ForgeDirection[] sides = ForgeDirection.VALID_DIRECTIONS;
while (!openList.isEmpty()) {
BlockLocation loc = openList.get(0);
openList.remove(0);
Block block = world.getBlock(loc.x, loc.y, loc.z);
if (block instanceof BlockColourable) {
blockFaces.add(loc);
}
if (world.isAirBlock(loc.x, loc.y, loc.z)) {
for (int i = 0; i < sides.length; i++) {
BlockLocation sideLoc = loc.offset(sides[i]);
Block sideBlock = world.getBlock(sideLoc.x, sideLoc.y, sideLoc.z);
if (!closedList.contains(sideLoc)) {
closedList.add(sideLoc);
boolean validCube = false;
for (int ix = 0; ix < 3; ix++) {
for (int iy = 0; iy < 3; iy++) {
for (int iz = 0; iz < 3; iz++) {
Block validBlock = world.getBlock(sideLoc.x + ix - 1, sideLoc.y + iy - 1, sideLoc.z + iz - 1);
if (validBlock instanceof BlockColourable) {
validCube = true;
}
}
}
}
if (sideLoc.getDistance(x, y, z) < radius & validCube) {
openList.add(sideLoc);
// blocks.add(sideLoc);
}
}
}
}
if (closedList.size() > 5000) {
break;
}
}
return blockFaces;
}
use of riskyken.armourersWorkshop.common.blocks.BlockColourable in project Armourers-Workshop by RiskyKen.
the class ItemBlendingTool method onDrawBlockHighlightEvent.
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void onDrawBlockHighlightEvent(DrawBlockHighlightEvent event) {
EntityPlayer player = event.player;
World world = event.player.worldObj;
MovingObjectPosition target = event.target;
if (target != null && target.typeOfHit != MovingObjectType.BLOCK) {
return;
}
int x = target.blockX;
int y = target.blockY;
int z = target.blockZ;
int side = target.sideHit;
Block block = world.getBlock(x, y, z);
ItemStack stack = player.getCurrentEquippedItem();
if (stack == null || stack.getItem() != this) {
return;
}
if (!(block instanceof BlockColourable)) {
return;
}
int radiusSample = (Integer) ToolOptions.RADIUS_SAMPLE.readFromNBT(stack.getTagCompound(), 2);
int radiusEffect = (Integer) ToolOptions.RADIUS_EFFECT.readFromNBT(stack.getTagCompound(), 1);
ArrayList<BlockLocation> blockSamples = BlockUtils.findTouchingBlockFaces(world, x, y, z, side, radiusSample);
ArrayList<BlockLocation> blockEffects = BlockUtils.findTouchingBlockFaces(world, x, y, z, side, radiusEffect);
double xOff = player.lastTickPosX + (player.posX - player.lastTickPosX) * event.partialTicks;
double yOff = player.lastTickPosY + (player.posY - player.lastTickPosY) * event.partialTicks;
double zOff = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * event.partialTicks;
float f1 = 0.002F;
for (int i = 0; i < blockSamples.size(); i++) {
int colour = 0xFF0000;
BlockLocation blockLoc = blockSamples.get(i);
AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(blockLoc.x, blockLoc.y, blockLoc.z, blockLoc.x + 1, blockLoc.y + 1, blockLoc.z + 1);
aabb.offset(-xOff, -yOff, -zOff);
GL11.glEnable(GL11.GL_BLEND);
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
GL11.glColor4f(0.0F, 0.0F, 0.0F, 0.2F);
GL11.glLineWidth(2.0F);
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glDepthMask(false);
GL11.glDisable(GL11.GL_DEPTH_TEST);
RenderGlobal.drawOutlinedBoundingBox(aabb.expand(f1, f1, f1), colour);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glDepthMask(true);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_BLEND);
}
for (int i = 0; i < blockEffects.size(); i++) {
BlockLocation blockLoc = blockEffects.get(i);
AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(blockLoc.x + 0.10F, blockLoc.y + 0.10F, blockLoc.z + 0.10F, blockLoc.x + 0.90F, blockLoc.y + 0.90F, blockLoc.z + 0.90F);
aabb.offset(-xOff, -yOff, -zOff);
GL11.glEnable(GL11.GL_BLEND);
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
GL11.glColor4f(0.0F, 0.0F, 0.0F, 0.2F);
GL11.glLineWidth(2.0F);
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_DEPTH_TEST);
// GL11.glDepthMask(false);
RenderGlobal.drawOutlinedBoundingBox(aabb.expand(f1, f1, f1), 0x00FF00);
// GL11.glDepthMask(true);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_BLEND);
}
event.setCanceled(true);
}
Aggregations