use of net.minecraft.block.AirBlock in project mxTune by AeronicaMC.
the class RootedEntity method standOnBlock.
public static void standOnBlock(World world, BlockPos pos, PlayerEntity playerIn, double yOffSet, boolean shouldSit) {
if (!world.isClientSide()) {
BlockPos blockPosFeet = blockUnderFoot(playerIn);
BlockState blockStateBelowFoot = world.getBlockState(blockPosFeet);
String className = blockStateBelowFoot.getBlock().getClass().getSimpleName();
VoxelShape voxelShape = world.getBlockState(blockPosFeet).getShape(world, blockPosFeet);
double blockHeight = !voxelShape.isEmpty() ? voxelShape.bounds().maxY : 0;
LOGGER.debug("bpuf: {}, bstate: {}, bclass: {}, blockHeight: {}", blockPosFeet, blockStateBelowFoot, className, blockHeight);
List<RootedEntity> rootedEntities = world.getEntitiesOfClass(RootedEntity.class, new AxisAlignedBB(pos.getX(), pos.getY(), pos.getZ(), pos.getX() + 1.0, pos.getY() + 1.0, pos.getZ() + 1.0));
if (rootedEntities.isEmpty() && !((blockStateBelowFoot.getBlock() instanceof AirBlock | !(blockStateBelowFoot.getFluidState().isEmpty())))) {
double ridingOffset = shouldSit ? -1 * 0.0625D : playerIn.getMyRidingOffset();
RootedEntity stand = new RootedEntity(world, blockUnderFoot(playerIn), shouldSit);
world.addFreshEntity(stand);
playerIn.startRiding(stand, true);
}
}
}
use of net.minecraft.block.AirBlock in project ChocolateQuestRepoured by TeamChocoQuest.
the class ProjectileWeb method onHit.
@Override
protected void onHit(RayTraceResult result) {
if (!this.world.isRemote) {
if (result.typeOfHit == RayTraceResult.Type.ENTITY) {
if (result.entityHit instanceof LivingEntity) {
LivingEntity entity = (LivingEntity) result.entityHit;
if (result.entityHit == this.shooter) {
return;
}
entity.addPotionEffect(new EffectInstance(Effects.POISON, 60, 0));
entity.setInWeb();
this.world.setBlockState(entity.getPosition(), CQRBlocks.TEMPORARY_WEB.getDefaultState());
this.setDead();
}
} else if (DungeonGenUtils.percentageRandom(75)) {
GeneratorVolcano.forEachSpherePosition(this.getPosition(), DungeonGenUtils.randomBetween(1, 3), t -> {
if (ProjectileWeb.this.world.getBlockState(t).getBlock() instanceof AirBlock) {
ProjectileWeb.this.world.setBlockState(t, CQRBlocks.TEMPORARY_WEB.getDefaultState());
}
});
}
super.onHit(result);
}
}
use of net.minecraft.block.AirBlock in project minecolonies by ldtteam.
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 ldtteam.
the class GraveManager method createCitizenGrave.
/**
* Attempt to create a TileEntityGrave at @pos containing the specific @citizenData
* <p>
* On failure: drop all the citizen inventory on the ground.
*
* @param world The world.
* @param pos The position where to spawn a grave
* @param citizenData The citizenData
*/
@Override
public void createCitizenGrave(final World world, final BlockPos pos, final ICitizenData citizenData) {
final BlockState here = world.getBlockState(pos);
if (here.getBlock() == Blocks.LAVA) {
LanguageHandler.sendPlayersMessage(colony.getImportantMessageEntityPlayers(), "com.minecolonies.coremod.grave.lava");
return;
}
BlockPos firstValidPosition = null;
if (here.getBlock() == Blocks.WATER) {
for (int i = 1; i <= 10; i++) {
if (world.getBlockState(pos.above(i)).getBlock() instanceof AirBlock) {
firstValidPosition = searchShore(world, pos.above(i));
break;
}
}
if (firstValidPosition == null) {
LanguageHandler.sendPlayersMessage(colony.getImportantMessageEntityPlayers(), "com.minecolonies.coremod.grave.water");
}
} else {
firstValidPosition = BlockPosUtil.findAround(world, pos, 10, 10, (blockAccess, current) -> blockAccess.getBlockState(current).getMaterial() == Material.AIR && blockAccess.getBlockState(current.below()).getMaterial().isSolid());
}
if (firstValidPosition != null) {
world.setBlockAndUpdate(firstValidPosition, BlockMinecoloniesGrave.getPlacementState(ModBlocks.blockGrave.defaultBlockState(), new TileEntityGrave(), firstValidPosition));
final TileEntityGrave graveEntity = (TileEntityGrave) world.getBlockEntity(firstValidPosition);
if (!InventoryUtils.transferAllItemHandler(citizenData.getInventory(), graveEntity.getInventory())) {
InventoryUtils.dropItemHandler(citizenData.getInventory(), world, pos.getX(), pos.getY(), pos.getZ());
}
graveEntity.delayDecayTimer(colony.getResearchManager().getResearchEffects().getEffectStrength(GRAVE_DECAY_BONUS));
GraveData graveData = new GraveData();
graveData.setCitizenName(citizenData.getName());
if (citizenData.getJob() != null) {
final IFormattableTextComponent jobName = new TranslationTextComponent(citizenData.getJob().getJobRegistryEntry().getTranslationKey().toLowerCase());
graveData.setCitizenJobName(jobName.getString());
}
graveData.setCitizenDataNBT(citizenData.serializeNBT());
graveEntity.setGraveData(graveData);
colony.getGraveManager().addNewGrave(firstValidPosition);
LanguageHandler.sendPlayersMessage(colony.getImportantMessageEntityPlayers(), "com.minecolonies.coremod.gravespawned");
} else {
InventoryUtils.dropItemHandler(citizenData.getInventory(), world, pos.getX(), pos.getY(), pos.getZ());
}
}
use of net.minecraft.block.AirBlock in project minecolonies by ldtteam.
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;
}
Aggregations