use of net.minecraft.block.AirBlock in project minecolonies by ldtteam.
the class TileEntityCompostedDirt method updateTick.
/**
* Update tick running on the server world.
*
* @param worldIn the server world.
*/
private void updateTick(@NotNull final World worldIn) {
if (flower == null || flower.isEmpty()) {
this.composted = false;
return;
}
if (this.composted) {
((ServerWorld) worldIn).sendParticles(ParticleTypes.HAPPY_VILLAGER, this.getBlockPos().getX() + 0.5, this.getBlockPos().getY() + 1, this.getBlockPos().getZ() + 0.5, 1, 0.2, 0, 0.2, 0);
}
if (random.nextDouble() * 100 <= this.percentage) {
final BlockPos position = worldPosition.above();
if (worldIn.getBlockState(position).getBlock() instanceof AirBlock) {
if (flower.getItem() instanceof BlockItem) {
if (((BlockItem) flower.getItem()).getBlock() instanceof DoublePlantBlock) {
((DoublePlantBlock) ((BlockItem) flower.getItem()).getBlock()).placeAt(worldIn, position, UPDATE_FLAG);
} else {
worldIn.setBlockAndUpdate(position, ((BlockItem) flower.getItem()).getBlock().defaultBlockState());
}
} else {
worldIn.setBlockAndUpdate(position, BlockUtils.getBlockStateFromStack(flower));
}
}
}
if (this.ticker >= TICKER_LIMIT * TICKS_SECOND) {
this.ticker = 0;
this.composted = false;
}
}
use of net.minecraft.block.AirBlock in project minecolonies by Minecolonies.
the class AbstractBuilding method getTileEntity.
@Override
public AbstractTileEntityColonyBuilding getTileEntity() {
if (tileEntity != null && tileEntity.isRemoved()) {
tileEntity = null;
}
if ((tileEntity == null) && colony != null && colony.getWorld() != null && getPosition() != null && WorldUtil.isBlockLoaded(colony.getWorld(), getPosition()) && !(colony.getWorld().getBlockState(getPosition()).getBlock() instanceof AirBlock) && colony.getWorld().getBlockState(this.getPosition()).getBlock() instanceof AbstractBlockHut) {
final TileEntity te = colony.getWorld().getBlockEntity(getPosition());
if (te instanceof TileEntityColonyBuilding) {
tileEntity = (TileEntityColonyBuilding) te;
if (tileEntity.getBuilding() == null) {
tileEntity.setColony(colony);
tileEntity.setBuilding(this);
}
} else {
Log.getLogger().error("Somehow the wrong TileEntity is at the location where the building should be!", new Exception());
Log.getLogger().error("Trying to restore order!");
final AbstractTileEntityColonyBuilding tileEntityColonyBuilding = new TileEntityColonyBuilding(MinecoloniesTileEntities.BUILDING);
colony.getWorld().setBlockEntity(getPosition(), tileEntityColonyBuilding);
this.tileEntity = tileEntityColonyBuilding;
}
}
return tileEntity;
}
use of net.minecraft.block.AirBlock in project minecolonies by Minecolonies.
the class AbstractEntityAIInteract method mineBlock.
/**
* Will simulate mining a block with particles ItemDrop etc. Attention: Because it simulates delay, it has to be called 2 times. So make sure the code path up to this function
* is reachable a second time. And make sure to immediately exit the update function when this returns false.
*
* @param blockToMine the block that should be mined
* @param safeStand the block we want to stand on to do that
* @param damageTool boolean wether we want to damage the tool used
* @param getDrops boolean wether we want to get Drops
* @param blockBreakAction Runnable that is used instead of the default block break action, can be null
* @return true once we're done
*/
protected final boolean mineBlock(@NotNull final BlockPos blockToMine, @NotNull final BlockPos safeStand, final boolean damageTool, final boolean getDrops, final Runnable blockBreakAction) {
final BlockState curBlockState = world.getBlockState(blockToMine);
@Nullable final Block curBlock = curBlockState.getBlock();
if (curBlock instanceof AirBlock || curBlock instanceof IBuilderUndestroyable || curBlock == Blocks.BEDROCK) {
if (curBlockState.getMaterial().isLiquid()) {
world.removeBlock(blockToMine, false);
}
// no need to mine block...
return true;
}
if (checkMiningLocation(blockToMine, safeStand)) {
// we have to wait for delay
return false;
}
final ItemStack tool = worker.getMainHandItem();
if (getDrops) {
// calculate fortune enchantment
final int fortune = ItemStackUtils.getFortuneOf(tool);
// check if tool has Silk Touch
final boolean silkTouch = ItemStackUtils.hasSilkTouch(tool);
// create list for all item drops to be stored in
List<ItemStack> localItems = new ArrayList<ItemStack>();
// Checks to see if the equipped tool has Silk Touch AND if the blocktoMine has a viable Item SilkTouch can get.
if (silkTouch && Item.byBlock(BlockPosUtil.getBlock(world, blockToMine)) != null) {
// Stores Silk Touch Block in localItems
final ItemStack silkItem = new ItemStack(Item.byBlock(BlockPosUtil.getBlock(world, blockToMine)), 1);
localItems.add(silkItem);
} else // If Silk Touch doesn't work, get blocks with Fortune value as normal.
{
localItems.addAll(BlockPosUtil.getBlockDrops(world, blockToMine, fortune, tool, worker));
}
localItems = increaseBlockDrops(localItems);
// add the drops to the citizen
for (final ItemStack item : localItems) {
InventoryUtils.transferItemStackIntoNextBestSlotInItemHandler(item, worker.getInventoryCitizen());
}
}
triggerMinedBlock(curBlockState);
if (blockBreakAction == null) {
// Break the block
worker.getCitizenItemHandler().breakBlockWithToolInHand(blockToMine);
} else {
blockBreakAction.run();
}
if (tool != ItemStack.EMPTY && damageTool) {
tool.getItem().inventoryTick(tool, world, worker, worker.getCitizenInventoryHandler().findFirstSlotInInventoryWith(tool.getItem()), true);
}
worker.getCitizenExperienceHandler().addExperience(XP_PER_BLOCK);
this.incrementActionsDone();
return true;
}
use of net.minecraft.block.AirBlock in project minecolonies by Minecolonies.
the class BlockPosUtil method findLand.
/**
* this checks that you are not in the air or underground. If so it will look up and down for a good landing spot before TP.
*
* @param blockPos for the current block LOC.
* @param world the world to search in.
* @return blockPos to be used for the TP.
*/
public static BlockPos findLand(final BlockPos blockPos, final World world) {
int top = blockPos.getY();
int bot = 0;
int mid = blockPos.getY();
BlockPos foundland = null;
BlockPos tempPos = blockPos;
// We are doing a binary search to limit the amount of checks (usually at most 9 this way)
while (top >= bot) {
tempPos = new BlockPos(tempPos.getX(), mid, tempPos.getZ());
final Block block = world.getBlockState(tempPos).getBlock();
if (block instanceof AirBlock && world.canSeeSkyFromBelowWater(tempPos)) {
top = mid - 1;
foundland = tempPos;
} else {
bot = mid + 1;
foundland = tempPos;
}
mid = (bot + top) / 2;
}
if (world.getBlockState(tempPos).getMaterial().isSolid()) {
return foundland.above();
}
return foundland;
}
use of net.minecraft.block.AirBlock in project Structurize by ldtteam.
the class StructurePlacementUtils method unloadStructure.
/**
* Unload a structure at a certain location.
*
* @param world the world.
* @param startPos the position.
* @param name the name.
* @param rotation the rotation.
* @param mirror the mirror.
*/
public static void unloadStructure(@NotNull final World world, @NotNull final BlockPos startPos, @NotNull final String name, final Rotation rotation, @NotNull final Mirror mirror) {
@NotNull final IStructureHandler structure = new CreativeStructureHandler(world, startPos, name, new PlacementSettings(mirror, rotation), false);
structure.getBluePrint().rotateWithMirror(rotation, mirror, world);
@NotNull final StructurePlacer placer = new StructurePlacer(structure);
placer.executeStructureStep(world, null, new BlockPos(0, 0, 0), StructurePlacer.Operation.BLOCK_REMOVAL, () -> placer.getIterator().increment((info, pos, handler) -> handler.getWorld().getBlockState(pos).getBlock() instanceof AirBlock), true);
}
Aggregations