Search in sources :

Example 16 with BlockLocation

use of riskyken.armourersWorkshop.common.blocks.BlockLocation in project Armourers-Workshop by RiskyKen.

the class ItemSkin method canPlaceChildren.

private boolean canPlaceChildren(World world, EntityPlayer player, int side, ItemStack stack, int x, int y, int z, Skin skin, SkinPointer skinPointer, ArrayList<BlockLocation> relatedBlocks) {
    ForgeDirection dir = UtilPlayer.getDirectionSide(player).getOpposite();
    for (int ix = 0; ix < 3; ix++) {
        for (int iy = 0; iy < 3; iy++) {
            for (int iz = 0; iz < 3; iz++) {
                float[] bounds = TileEntitySkinnable.getBlockBounds(skin, -ix + 2, iy, iz, dir);
                if (bounds != null) {
                    int childX = x;
                    int childY = y;
                    int childZ = z;
                    childX += ix - 1 - dir.offsetX * 1;
                    childY += iy;
                    childZ += iz - 1 - dir.offsetZ * 1;
                    relatedBlocks.add(new BlockLocation(childX, childY, childZ));
                    Block replaceBlock = world.getBlock(childX, childY, childZ);
                    if (!replaceBlock.isReplaceable(world, childX, childY, childZ)) {
                        return false;
                    }
                }
            }
        }
    }
    return true;
}
Also used : ForgeDirection(net.minecraftforge.common.util.ForgeDirection) Block(net.minecraft.block.Block) BlockLocation(riskyken.armourersWorkshop.common.blocks.BlockLocation)

Example 17 with BlockLocation

use of riskyken.armourersWorkshop.common.blocks.BlockLocation 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)

Example 18 with BlockLocation

use of riskyken.armourersWorkshop.common.blocks.BlockLocation in project Armourers-Workshop by RiskyKen.

the class ItemBlendingTool method onItemUse.

@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
    Block block = world.getBlock(x, y, z);
    if (block instanceof IPantableBlock) {
        if (!world.isRemote) {
            UndoManager.begin(player);
            usedOnBlockSide(stack, player, world, new BlockLocation(x, y, z), block, side);
            UndoManager.end(player);
            world.playSoundEffect(x + 0.5D, y + 0.5D, z + 0.5D, LibSounds.BURN, 1.0F, 1.0F);
        }
        return true;
    }
    if (block == ModBlocks.armourerBrain & player.isSneaking()) {
        if (!world.isRemote) {
            TileEntity te = world.getTileEntity(x, y, z);
            if (te != null && te instanceof TileEntityArmourer) {
                ((TileEntityArmourer) te).toolUsedOnArmourer(this, world, stack, player);
            }
        }
        return true;
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityArmourer(riskyken.armourersWorkshop.common.tileentities.TileEntityArmourer) Block(net.minecraft.block.Block) IPantableBlock(riskyken.armourersWorkshop.api.common.painting.IPantableBlock) BlockLocation(riskyken.armourersWorkshop.common.blocks.BlockLocation) IPantableBlock(riskyken.armourersWorkshop.api.common.painting.IPantableBlock)

Example 19 with BlockLocation

use of riskyken.armourersWorkshop.common.blocks.BlockLocation in project Armourers-Workshop by RiskyKen.

the class ItemBurnTool method onItemUse.

@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
    Block block = world.getBlock(x, y, z);
    if (block instanceof IPantableBlock) {
        if (!world.isRemote) {
            UndoManager.begin(player);
        }
        if ((Boolean) ToolOptions.FULL_BLOCK_MODE.readFromNBT(stack.getTagCompound())) {
            for (int i = 0; i < 6; i++) {
                usedOnBlockSide(stack, player, world, new BlockLocation(x, y, z), block, i);
            }
        } else {
            usedOnBlockSide(stack, player, world, new BlockLocation(x, y, z), block, side);
        }
        if (!world.isRemote) {
            UndoManager.end(player);
            world.playSoundEffect(x + 0.5D, y + 0.5D, z + 0.5D, LibSounds.BURN, 1.0F, 1.0F);
        }
        return true;
    }
    if (block == ModBlocks.armourerBrain & player.isSneaking()) {
        if (!world.isRemote) {
            TileEntity te = world.getTileEntity(x, y, z);
            if (te != null && te instanceof TileEntityArmourer) {
                ((TileEntityArmourer) te).toolUsedOnArmourer(this, world, stack, player);
            }
        }
        return true;
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityArmourer(riskyken.armourersWorkshop.common.tileentities.TileEntityArmourer) MessageClientToolPaintBlock(riskyken.armourersWorkshop.common.network.messages.client.MessageClientToolPaintBlock) Block(net.minecraft.block.Block) IPantableBlock(riskyken.armourersWorkshop.api.common.painting.IPantableBlock) BlockLocation(riskyken.armourersWorkshop.common.blocks.BlockLocation) IPantableBlock(riskyken.armourersWorkshop.api.common.painting.IPantableBlock)

Example 20 with BlockLocation

use of riskyken.armourersWorkshop.common.blocks.BlockLocation in project Armourers-Workshop by RiskyKen.

the class ItemPaintbrush method onItemUse.

@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
    Block block = world.getBlock(x, y, z);
    if (player.isSneaking() & block == ModBlocks.colourMixer) {
        TileEntity te = world.getTileEntity(x, y, z);
        if (te != null && te instanceof IPantable) {
            if (!world.isRemote) {
                int colour = ((IPantable) te).getColour(0);
                PaintType paintType = ((IPantable) te).getPaintType(0);
                setToolColour(stack, colour);
                setToolPaintType(stack, paintType);
            }
        }
        return true;
    }
    if (block instanceof IPantableBlock) {
        int newColour = getToolColour(stack);
        if (!world.isRemote) {
            UndoManager.begin(player);
            if ((Boolean) ToolOptions.FULL_BLOCK_MODE.readFromNBT(stack.getTagCompound())) {
                for (int i = 0; i < 6; i++) {
                    usedOnBlockSide(stack, player, world, new BlockLocation(x, y, z), block, i);
                }
            } else {
                usedOnBlockSide(stack, player, world, new BlockLocation(x, y, z), block, side);
            }
            UndoManager.end(player);
            if ((Boolean) ToolOptions.FULL_BLOCK_MODE.readFromNBT(stack.getTagCompound())) {
                world.playSoundEffect(x + 0.5D, y + 0.5D, z + 0.5D, LibSounds.PAINT, 1.0F, world.rand.nextFloat() * 0.1F + 0.9F);
            } else {
                world.playSoundEffect(x + 0.5D, y + 0.5D, z + 0.5D, LibSounds.PAINT, 1.0F, world.rand.nextFloat() * 0.1F + 1.5F);
            }
        } else {
            spawnPaintParticles(world, x, y, z, side, newColour);
        }
        return true;
    }
    if (block == ModBlocks.armourerBrain & player.isSneaking()) {
        if (!world.isRemote) {
            TileEntity te = world.getTileEntity(x, y, z);
            if (te != null && te instanceof TileEntityArmourer) {
                ((TileEntityArmourer) te).toolUsedOnArmourer(this, world, stack, player);
            }
        }
        ModLogger.log("armourer");
        return true;
    }
    if (block == ModBlocks.mannequin) {
        if (!world.isRemote) {
            TileEntity te = ((BlockMannequin) block).getMannequinTileEntity(world, x, y, z);
            if (te != null && te instanceof TileEntityMannequin) {
                int newColour = getToolColour(stack);
                if (player.isSneaking()) {
                    ((TileEntityMannequin) te).setHairColour(newColour);
                } else {
                    ((TileEntityMannequin) te).setSkinColour(newColour);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockMannequin(riskyken.armourersWorkshop.common.blocks.BlockMannequin) TileEntityArmourer(riskyken.armourersWorkshop.common.tileentities.TileEntityArmourer) Block(net.minecraft.block.Block) IPantableBlock(riskyken.armourersWorkshop.api.common.painting.IPantableBlock) IPantable(riskyken.armourersWorkshop.api.common.painting.IPantable) PaintType(riskyken.armourersWorkshop.common.painting.PaintType) BlockLocation(riskyken.armourersWorkshop.common.blocks.BlockLocation) TileEntityMannequin(riskyken.armourersWorkshop.common.tileentities.TileEntityMannequin) IPantableBlock(riskyken.armourersWorkshop.api.common.painting.IPantableBlock)

Aggregations

BlockLocation (riskyken.armourersWorkshop.common.blocks.BlockLocation)21 Block (net.minecraft.block.Block)14 IPantableBlock (riskyken.armourersWorkshop.api.common.painting.IPantableBlock)10 TileEntity (net.minecraft.tileentity.TileEntity)8 TileEntityArmourer (riskyken.armourersWorkshop.common.tileentities.TileEntityArmourer)7 MessageClientToolPaintBlock (riskyken.armourersWorkshop.common.network.messages.client.MessageClientToolPaintBlock)5 ArrayList (java.util.ArrayList)4 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 IPantable (riskyken.armourersWorkshop.api.common.painting.IPantable)2 BlockColourable (riskyken.armourersWorkshop.common.blocks.BlockColourable)2 BlockSkinnable (riskyken.armourersWorkshop.common.blocks.BlockSkinnable)2 PaintType (riskyken.armourersWorkshop.common.painting.PaintType)2 TileEntitySkinnable (riskyken.armourersWorkshop.common.tileentities.TileEntitySkinnable)2 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)1 SideOnly (cpw.mods.fml.relauncher.SideOnly)1 Color (java.awt.Color)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1