Search in sources :

Example 26 with BlockPos

use of net.minecraft.util.BlockPos in project malmo by Microsoft.

the class PositionHelper method getTouchingBlocks.

public static List<BlockPos> getTouchingBlocks(EntityPlayerSP player) {
    // Determine which blocks we are touching.
    // This code is adapted from Entity, where it is used to fire the Block.onEntityCollidedWithBlock methods.
    BlockPos blockposmin = new BlockPos(player.getEntityBoundingBox().minX - 0.001D, player.getEntityBoundingBox().minY - 0.001D, player.getEntityBoundingBox().minZ - 0.001D);
    BlockPos blockposmax = new BlockPos(player.getEntityBoundingBox().maxX + 0.001D, player.getEntityBoundingBox().maxY + 0.001D, player.getEntityBoundingBox().maxZ + 0.001D);
    List<BlockPos> blocks = new ArrayList<BlockPos>();
    if (player.worldObj.isAreaLoaded(blockposmin, blockposmax)) {
        for (int i = blockposmin.getX(); i <= blockposmax.getX(); ++i) {
            for (int j = blockposmin.getY(); j <= blockposmax.getY(); ++j) {
                for (int k = blockposmin.getZ(); k <= blockposmax.getZ(); ++k) {
                    blocks.add(new BlockPos(i, j, k));
                }
            }
        }
    }
    return blocks;
}
Also used : ArrayList(java.util.ArrayList) BlockPos(net.minecraft.util.BlockPos)

Example 27 with BlockPos

use of net.minecraft.util.BlockPos in project malmo by Microsoft.

the class BlockDrawingHelper method DrawPrimitive.

/**
     * Dumb code to draw a solid line made up of Minecraft blocks.<br>
     * (Doesn't do any fancy Bresenham stuff because the cost of computing the points on the line
     * presumably pales into insignificance compared to the cost of turning each point into a Minecraft block.)
     * @param l Contains information about the line to be drawn.
     * @param w The world in which to draw.
     * @throws Exception Throws an exception if the block type is not recognised.
     */
private void DrawPrimitive(DrawLine l, World w) throws Exception {
    // Set up the blocktype for the main blocks of the line:
    XMLBlockState blockType = new XMLBlockState(l.getType(), l.getColour(), l.getFace(), l.getVariant());
    if (!blockType.isValid())
        throw new Exception("Unrecognised block type: " + l.getType().value());
    // Set up the blocktype for the steps of the line, if one has been specified:
    XMLBlockState stepType = blockType;
    if (l.getSteptype() != null) {
        stepType = new XMLBlockState(l.getSteptype(), l.getColour(), l.getFace(), l.getVariant());
        if (!stepType.isValid())
            throw new Exception("Unrecognised block type: " + l.getSteptype().value());
    }
    float dx = (l.getX2() - l.getX1());
    float dy = (l.getY2() - l.getY1());
    float dz = (l.getZ2() - l.getZ1());
    float steps = (int) Math.max(Math.max(Math.abs(dx), Math.abs(dy)), Math.abs(dz));
    if (steps < 1)
        steps = 1;
    dx /= steps;
    dy /= steps;
    dz /= steps;
    int prevY = l.getY1();
    int prevZ = l.getZ1();
    int prevX = l.getX1();
    for (int i = 0; i <= steps; i++) {
        int x = Math.round(l.getX1() + (float) i * dx);
        int y = Math.round(l.getY1() + (float) i * dy);
        int z = Math.round(l.getZ1() + (float) i * dz);
        BlockPos pos = new BlockPos(x, y, z);
        clearEntities(w, x - 0.5, y - 0.5, z - 0.5, x + 0.5, y + 0.5, z + 0.5);
        setBlockState(w, pos, y == prevY ? blockType : stepType);
        // Ensure 4-connected:
        if (x != prevX && z != prevZ) {
            pos = new BlockPos(x, y, prevZ);
            clearEntities(w, x - 0.5, y - 0.5, prevZ - 0.5, x + 0.5, y + 0.5, prevZ + 0.5);
            setBlockState(w, pos, y == prevY ? blockType : stepType);
        }
        prevY = y;
        prevX = x;
        prevZ = z;
    }
}
Also used : BlockPos(net.minecraft.util.BlockPos)

Example 28 with BlockPos

use of net.minecraft.util.BlockPos in project CodeChickenLib by Chicken-Bones.

the class LightMatrix method sample.

public void sample(int i) {
    if ((sampled & 1 << i) == 0) {
        BlockPos bp = new BlockPos(pos.x + (i % 3) - 1, pos.y + (i / 9) - 1, pos.z + (i / 3 % 3) - 1);
        IBlockState b = access.getBlockState(bp);
        bSamples[i] = access.getCombinedLight(bp, b.getBlock().getLightValue(access, bp));
        aSamples[i] = b.getBlock().getAmbientOcclusionLightValue();
        sampled |= 1 << i;
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.BlockPos)

Example 29 with BlockPos

use of net.minecraft.util.BlockPos in project SecurityCraft by Geforce132.

the class BlockKeypad method shouldSideBeRendered.

@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockAccess worldIn, BlockPos pos, EnumFacing side) {
    BlockPos keypadPos = pos.offset(side.getOpposite());
    if (worldIn.getTileEntity(keypadPos) == null)
        return true;
    CustomizableSCTE tileEntity = (CustomizableSCTE) worldIn.getTileEntity(keypadPos);
    if (tileEntity.hasModule(EnumCustomModules.DISGUISE)) {
        ItemStack disguiseModule = tileEntity.getModule(EnumCustomModules.DISGUISE);
        List<Block> blocks = ((ItemModule) disguiseModule.getItem()).getBlockAddons(disguiseModule.getTagCompound());
        if (blocks.size() != 0) {
            Block blockToDisguiseAs = blocks.get(0);
            // If the keypad has a disguise module added with a transparent block inserted.
            if (!blockToDisguiseAs.isOpaqueCube() || !blockToDisguiseAs.isFullCube()) {
                return checkForSideTransparency(worldIn, keypadPos, worldIn.getBlockState(keypadPos.offset(side)).getBlock(), side);
            }
        }
    }
    return true;
}
Also used : CustomizableSCTE(net.geforcemods.securitycraft.api.CustomizableSCTE) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.BlockPos) ItemStack(net.minecraft.item.ItemStack) ItemModule(net.geforcemods.securitycraft.items.ItemModule) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 30 with BlockPos

use of net.minecraft.util.BlockPos in project SecurityCraft by Geforce132.

the class BlockScannerDoor method onNeighborBlockChange.

/**
	 * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
	 * their own) Args: x, y, z, neighbor Block
	 */
public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock) {
    if (state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER) {
        BlockPos blockpos1 = pos.down();
        IBlockState iblockstate1 = worldIn.getBlockState(blockpos1);
        if (iblockstate1.getBlock() != this)
            worldIn.setBlockToAir(pos);
        else if (neighborBlock != this)
            this.onNeighborBlockChange(worldIn, blockpos1, iblockstate1, neighborBlock);
    } else {
        boolean flag1 = false;
        BlockPos blockpos2 = pos.up();
        IBlockState iblockstate2 = worldIn.getBlockState(blockpos2);
        if (iblockstate2.getBlock() != this) {
            worldIn.setBlockToAir(pos);
            flag1 = true;
        }
        if (!World.doesBlockHaveSolidTopSurface(worldIn, pos.down())) {
            worldIn.setBlockToAir(pos);
            flag1 = true;
            if (iblockstate2.getBlock() == this)
                worldIn.setBlockToAir(blockpos2);
        }
        if (flag1) {
            if (!worldIn.isRemote)
                this.dropBlockAsItem(worldIn, pos, state, 0);
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.BlockPos)

Aggregations

BlockPos (net.minecraft.util.BlockPos)30 IBlockState (net.minecraft.block.state.IBlockState)11 EntityPlayerSP (net.minecraft.client.entity.EntityPlayerSP)6 Entity (net.minecraft.entity.Entity)5 BlockDrawingHelper (com.microsoft.Malmo.Utils.BlockDrawingHelper)4 XMLBlockState (com.microsoft.Malmo.Utils.BlockDrawingHelper.XMLBlockState)4 ArrayList (java.util.ArrayList)4 ItemStack (net.minecraft.item.ItemStack)4 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)3 EntityTypes (com.microsoft.Malmo.Schemas.EntityTypes)2 HashMap (java.util.HashMap)2 Block (net.minecraft.block.Block)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)2 Vec3 (net.minecraft.util.Vec3)2 World (net.minecraft.world.World)2 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonPrimitive (com.google.gson.JsonPrimitive)1