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);
}
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];
}
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];
}
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);
}
}
}
}
}
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;
}
}
Aggregations