Search in sources :

Example 11 with BlockPos

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

the class JSONWorldDataHelper method buildGridData.

/**
     * Build a signal for the cubic block grid centred on the player.<br>
     * Default is 3x3x4. (One cube all around the player.)<br>
     * Blocks are returned as a 1D array, in order
     * along the x, then z, then y axes.<br>
     * Data will be returned in an array called "Cells"
     * @param json a JSON object into which the info for the object under the mouse will be added.
     * @param environmentDimensions object which specifies the required dimensions of the grid to be returned.
     * @param jsonName name to use for identifying the returned JSON array.
     */
public static void buildGridData(JsonObject json, GridDimensions environmentDimensions, EntityPlayerMP player, String jsonName) {
    if (player == null || json == null)
        return;
    JsonArray arr = new JsonArray();
    BlockPos pos = new BlockPos(player.posX, player.posY, player.posZ);
    for (int y = environmentDimensions.yMin; y <= environmentDimensions.yMax; y++) {
        for (int z = environmentDimensions.zMin; z <= environmentDimensions.zMax; z++) {
            for (int x = environmentDimensions.xMin; x <= environmentDimensions.xMax; x++) {
                BlockPos p;
                if (environmentDimensions.absoluteCoords)
                    p = new BlockPos(x, y, z);
                else
                    p = pos.add(x, y, z);
                String name = "";
                IBlockState state = player.worldObj.getBlockState(p);
                Object blockName = Block.blockRegistry.getNameForObject(state.getBlock());
                if (blockName instanceof ResourceLocation) {
                    name = ((ResourceLocation) blockName).getResourcePath();
                }
                JsonElement element = new JsonPrimitive(name);
                arr.add(element);
            }
        }
    }
    json.add(jsonName, arr);
}
Also used : JsonArray(com.google.gson.JsonArray) IBlockState(net.minecraft.block.state.IBlockState) JsonPrimitive(com.google.gson.JsonPrimitive) JsonElement(com.google.gson.JsonElement) ResourceLocation(net.minecraft.util.ResourceLocation) BlockPos(net.minecraft.util.BlockPos) JsonObject(com.google.gson.JsonObject)

Example 12 with BlockPos

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

the class PlanarLightMatrix method brightness.

public int brightness(int side) {
    if ((sampled & 1 << side) == 0) {
        BlockPos bp = pos.pos();
        IBlockState b = access.getBlockState(bp);
        brightness[side] = access.getCombinedLight(bp, b.getBlock().getLightValue(access, bp));
        sampled |= 1 << side;
    }
    return brightness[side];
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.BlockPos)

Example 13 with BlockPos

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

the class SimpleBrightnessModel method sample.

public int sample(int side) {
    if ((sampled & 1 << side) == 0) {
        BlockPos bp = c.set(pos).offset(side).pos();
        IBlockState b = access.getBlockState(bp);
        samples[side] = access.getCombinedLight(bp, b.getBlock().getLightValue(access, bp));
        sampled |= 1 << side;
    }
    return samples[side];
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.BlockPos)

Example 14 with BlockPos

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

the class BlockReinforcedDoor 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);
            }
        } else {
            boolean flag = hasActiveKeypadNextTo(worldIn, pos) || hasActiveKeypadNextTo(worldIn, pos.up()) || hasActiveInventoryScannerNextTo(worldIn, pos) || hasActiveInventoryScannerNextTo(worldIn, pos.up()) || hasActiveReaderNextTo(worldIn, pos) || hasActiveReaderNextTo(worldIn, pos.up()) || hasActiveScannerNextTo(worldIn, pos) || hasActiveScannerNextTo(worldIn, pos.up()) || hasActiveLaserNextTo(worldIn, pos) || hasActiveLaserNextTo(worldIn, pos.up());
            if (((flag || neighborBlock.canProvidePower())) && neighborBlock != this && flag != ((Boolean) iblockstate2.getValue(POWERED)).booleanValue()) {
                worldIn.setBlockState(blockpos2, iblockstate2.withProperty(POWERED, Boolean.valueOf(flag)), 2);
                if (flag != ((Boolean) state.getValue(OPEN)).booleanValue()) {
                    worldIn.setBlockState(pos, state.withProperty(OPEN, Boolean.valueOf(flag)), 2);
                    worldIn.markBlockRangeForRenderUpdate(pos, pos);
                    worldIn.playAuxSFXAtEntity((EntityPlayer) null, flag ? 1003 : 1006, pos, 0);
                }
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.BlockPos)

Example 15 with BlockPos

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

the class ItemModifiedBucket method onItemRightClick.

public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn) {
    boolean flag = this.containedBlock == Blocks.air;
    MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(worldIn, playerIn, flag);
    if (movingobjectposition == null) {
        return itemStackIn;
    } else {
        ItemStack ret = net.minecraftforge.event.ForgeEventFactory.onBucketUse(playerIn, worldIn, itemStackIn, movingobjectposition);
        if (ret != null)
            return ret;
        if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
            BlockPos blockpos = movingobjectposition.getBlockPos();
            if (!worldIn.isBlockModifiable(playerIn, blockpos)) {
                return itemStackIn;
            }
            if (flag) {
                if (!playerIn.canPlayerEdit(blockpos.offset(movingobjectposition.sideHit), movingobjectposition.sideHit, itemStackIn)) {
                    return itemStackIn;
                }
                IBlockState iblockstate = worldIn.getBlockState(blockpos);
                Material material = iblockstate.getBlock().getMaterial();
                if (material == Material.water && ((Integer) iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0) {
                    worldIn.setBlockToAir(blockpos);
                    playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
                    return this.fillBucket(itemStackIn, playerIn, mod_SecurityCraft.fWaterBucket);
                }
                if (material == Material.lava && ((Integer) iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0) {
                    worldIn.setBlockToAir(blockpos);
                    playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
                    return this.fillBucket(itemStackIn, playerIn, mod_SecurityCraft.fLavaBucket);
                }
            } else {
                if (this.containedBlock == Blocks.air) {
                    return new ItemStack(Items.bucket);
                }
                BlockPos blockpos1 = blockpos.offset(movingobjectposition.sideHit);
                if (!playerIn.canPlayerEdit(blockpos1, movingobjectposition.sideHit, itemStackIn)) {
                    return itemStackIn;
                }
                if (this.tryPlaceContainedLiquid(worldIn, blockpos1) && !playerIn.capabilities.isCreativeMode) {
                    playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
                    return new ItemStack(Items.bucket);
                }
            }
        }
        return itemStackIn;
    }
}
Also used : MovingObjectPosition(net.minecraft.util.MovingObjectPosition) IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.BlockPos) Material(net.minecraft.block.material.Material) ItemStack(net.minecraft.item.ItemStack)

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