Search in sources :

Example 1 with BlockColourable

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;
}
Also used : ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ArrayList(java.util.ArrayList) Block(net.minecraft.block.Block) BlockLocation(riskyken.armourersWorkshop.common.blocks.BlockLocation) BlockColourable(riskyken.armourersWorkshop.common.blocks.BlockColourable)

Example 2 with BlockColourable

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);
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) World(net.minecraft.world.World) BlockLocation(riskyken.armourersWorkshop.common.blocks.BlockLocation) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Block(net.minecraft.block.Block) IPantableBlock(riskyken.armourersWorkshop.api.common.painting.IPantableBlock) ItemStack(net.minecraft.item.ItemStack) BlockColourable(riskyken.armourersWorkshop.common.blocks.BlockColourable) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent) SideOnly(cpw.mods.fml.relauncher.SideOnly)

Aggregations

Block (net.minecraft.block.Block)2 BlockColourable (riskyken.armourersWorkshop.common.blocks.BlockColourable)2 BlockLocation (riskyken.armourersWorkshop.common.blocks.BlockLocation)2 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)1 SideOnly (cpw.mods.fml.relauncher.SideOnly)1 ArrayList (java.util.ArrayList)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)1 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)1 World (net.minecraft.world.World)1 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)1 IPantableBlock (riskyken.armourersWorkshop.api.common.painting.IPantableBlock)1