Search in sources :

Example 6 with AirBlock

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);
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) BlockState(net.minecraft.block.BlockState) VoxelShape(net.minecraft.util.math.shapes.VoxelShape) AirBlock(net.minecraft.block.AirBlock) BlockPos(net.minecraft.util.math.BlockPos)

Example 7 with AirBlock

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);
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) Effects(net.minecraft.potion.Effects) RayTraceResult(net.minecraft.util.math.RayTraceResult) EffectInstance(net.minecraft.potion.EffectInstance) LivingEntity(net.minecraft.entity.LivingEntity) World(net.minecraft.world.World) AirBlock(net.minecraft.block.AirBlock) CQRBlocks(team.cqr.cqrepoured.init.CQRBlocks) GeneratorVolcano(team.cqr.cqrepoured.world.structure.generation.generators.volcano.GeneratorVolcano) DungeonGenUtils(team.cqr.cqrepoured.util.DungeonGenUtils) AirBlock(net.minecraft.block.AirBlock) EffectInstance(net.minecraft.potion.EffectInstance)

Example 8 with AirBlock

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;
}
Also used : ChestTileEntity(net.minecraft.tileentity.ChestTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) AirBlock(net.minecraft.block.AirBlock) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) TileEntityColonyBuilding(com.minecolonies.api.tileentities.TileEntityColonyBuilding) AbstractBlockHut(com.minecolonies.api.blocks.AbstractBlockHut)

Example 9 with AirBlock

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());
    }
}
Also used : LanguageHandler(com.ldtteam.structurize.util.LanguageHandler) AirBlock(net.minecraft.block.AirBlock) Constants(net.minecraftforge.common.util.Constants) CompoundNBT(net.minecraft.nbt.CompoundNBT) ICitizenData(com.minecolonies.api.colony.ICitizenData) IFormattableTextComponent(net.minecraft.util.text.IFormattableTextComponent) HashMap(java.util.HashMap) Direction(net.minecraft.util.Direction) ModBlocks(com.minecolonies.api.blocks.ModBlocks) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockMinecoloniesGrave(com.minecolonies.coremod.blocks.BlockMinecoloniesGrave) Map(java.util.Map) BlockState(net.minecraft.block.BlockState) TileEntityGrave(com.minecolonies.api.tileentities.TileEntityGrave) ListNBT(net.minecraft.nbt.ListNBT) MAX_TICKRATE(com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.TickRateConstants.MAX_TICKRATE) Iterator(java.util.Iterator) Colony(com.minecolonies.coremod.colony.Colony) World(net.minecraft.world.World) GraveData(com.minecolonies.api.colony.GraveData) BlockPos(net.minecraft.util.math.BlockPos) BlockPosUtil(com.minecolonies.api.util.BlockPosUtil) Blocks(net.minecraft.block.Blocks) IGraveManager(com.minecolonies.api.colony.managers.interfaces.IGraveManager) Material(net.minecraft.block.material.Material) InventoryUtils(com.minecolonies.api.util.InventoryUtils) NbtTagConstants(com.minecolonies.api.util.constant.NbtTagConstants) IColony(com.minecolonies.api.colony.IColony) TileEntity(net.minecraft.tileentity.TileEntity) WorldUtil(com.minecolonies.api.util.WorldUtil) NotNull(org.jetbrains.annotations.NotNull) GRAVE_DECAY_BONUS(com.minecolonies.api.research.util.ResearchConstants.GRAVE_DECAY_BONUS) BlockState(net.minecraft.block.BlockState) AirBlock(net.minecraft.block.AirBlock) GraveData(com.minecolonies.api.colony.GraveData) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) TileEntityGrave(com.minecolonies.api.tileentities.TileEntityGrave) IFormattableTextComponent(net.minecraft.util.text.IFormattableTextComponent)

Example 10 with AirBlock

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;
}
Also used : BlockState(net.minecraft.block.BlockState) AirBlock(net.minecraft.block.AirBlock) ArrayList(java.util.ArrayList) AirBlock(net.minecraft.block.AirBlock) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) Nullable(org.jetbrains.annotations.Nullable) IBuilderUndestroyable(com.minecolonies.api.entity.ai.citizen.builder.IBuilderUndestroyable)

Aggregations

AirBlock (net.minecraft.block.AirBlock)21 BlockPos (net.minecraft.util.math.BlockPos)13 ItemStack (net.minecraft.item.ItemStack)9 Block (net.minecraft.block.Block)8 BlockState (net.minecraft.block.BlockState)8 AbstractBlockHut (com.minecolonies.api.blocks.AbstractBlockHut)6 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)6 NotNull (org.jetbrains.annotations.NotNull)6 TileEntity (net.minecraft.tileentity.TileEntity)5 Nullable (org.jetbrains.annotations.Nullable)5 BlockUtils (com.ldtteam.structurize.util.BlockUtils)4 Stack (com.minecolonies.api.colony.requestsystem.requestable.Stack)4 IBuilderUndestroyable (com.minecolonies.api.entity.ai.citizen.builder.IBuilderUndestroyable)4 AITarget (com.minecolonies.api.entity.ai.statemachine.AITarget)4 AIWorkerState (com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState)4 IAIState (com.minecolonies.api.entity.ai.statemachine.states.IAIState)4 Blueprint (com.ldtteam.structures.blueprints.v1.Blueprint)3 IStructureHandler (com.ldtteam.structurize.placement.structure.IStructureHandler)3 PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)3 ModBlocks (com.minecolonies.api.blocks.ModBlocks)3