Search in sources :

Example 56 with BlockState

use of net.minecraft.block.BlockState in project BluePower by Qmunity.

the class TileBlulectricCable method tick.

@Override
public void tick() {
    storage.resetCurrent();
    if (level != null && !level.isClientSide) {
        BlockState state = getBlockState();
        if (state.getBlock() instanceof BlockBlulectricCable) {
            List<Direction> directions = new ArrayList<>(BlockBlulectricCable.FACING.getPossibleValues());
            // Check the side has capability
            directions.removeIf(d -> !getCapability(CapabilityBlutricity.BLUTRICITY_CAPABILITY, d).isPresent());
            // Balance power of attached blulectric blocks.
            for (Direction facing : directions) {
                Block fBlock = level.getBlockState(worldPosition.relative(facing)).getBlock();
                if (fBlock != Blocks.AIR && fBlock != Blocks.WATER) {
                    TileEntity tile = level.getBlockEntity(worldPosition.relative(facing));
                    if (tile != null)
                        tile.getCapability(CapabilityBlutricity.BLUTRICITY_CAPABILITY, facing.getOpposite()).ifPresent(exStorage -> EnergyHelper.balancePower(exStorage, storage));
                } else {
                    TileEntity tile = level.getBlockEntity(worldPosition.relative(facing).relative(state.getValue(BlockBlulectricCable.FACING).getOpposite()));
                    if (tile != null)
                        tile.getCapability(CapabilityBlutricity.BLUTRICITY_CAPABILITY, state.getValue(BlockBlulectricCable.FACING)).ifPresent(exStorage -> EnergyHelper.balancePower(exStorage, storage));
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockBlulectricCable(com.bluepowermod.block.power.BlockBlulectricCable) IPowerBase(com.bluepowermod.api.power.IPowerBase) CompoundNBT(net.minecraft.nbt.CompoundNBT) CapabilityBlutricity(com.bluepowermod.api.power.CapabilityBlutricity) EnergyHelper(com.bluepowermod.helper.EnergyHelper) TileMachineBase(com.bluepowermod.tile.TileMachineBase) Direction(net.minecraft.util.Direction) NetworkManager(net.minecraft.network.NetworkManager) Blocks(net.minecraft.block.Blocks) Capability(net.minecraftforge.common.capabilities.Capability) LazyOptional(net.minecraftforge.common.util.LazyOptional) ArrayList(java.util.ArrayList) List(java.util.List) BlutricityStorage(com.bluepowermod.api.power.BlutricityStorage) Block(net.minecraft.block.Block) SUpdateTileEntityPacket(net.minecraft.network.play.server.SUpdateTileEntityPacket) BPTileEntityType(com.bluepowermod.tile.BPTileEntityType) TileEntity(net.minecraft.tileentity.TileEntity) BlockState(net.minecraft.block.BlockState) Nonnull(javax.annotation.Nonnull) INBT(net.minecraft.nbt.INBT) Nullable(javax.annotation.Nullable) BlockState(net.minecraft.block.BlockState) BlockBlulectricCable(com.bluepowermod.block.power.BlockBlulectricCable) ArrayList(java.util.ArrayList) Block(net.minecraft.block.Block) Direction(net.minecraft.util.Direction)

Example 57 with BlockState

use of net.minecraft.block.BlockState in project BluePower by Qmunity.

the class MultipartUtils method getClosestState.

/**
 * Returns the closest Multipart state to the Vec3 in in a given position.
 * @param world
 * @param start
 * @param end
 * @param pos
 */
@Nullable
public static BlockState getClosestState(World world, Vector3d start, Vector3d end, BlockPos pos) {
    TileEntity te = world.getBlockEntity(pos);
    BlockState state = null;
    double distance = Double.POSITIVE_INFINITY;
    if (te instanceof TileBPMultipart) {
        for (BlockState part : ((TileBPMultipart) te).getStates()) {
            RayTraceResult res = part.getVisualShape(world, pos, ISelectionContext.empty()).clip(start, end, pos);
            if (res != null) {
                double partDistance = start.distanceToSqr(res.getLocation());
                if (distance > partDistance) {
                    distance = partDistance;
                    state = part;
                }
            }
        }
    }
    return state;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockState(net.minecraft.block.BlockState) RayTraceResult(net.minecraft.util.math.RayTraceResult) TileBPMultipart(com.bluepowermod.tile.TileBPMultipart) Nullable(javax.annotation.Nullable)

Example 58 with BlockState

use of net.minecraft.block.BlockState in project Overloaded by CJ-MC-Mods.

the class TileItemInterface method updateClient.

private void updateClient() {
    BlockState state = getLevel().getBlockState(getBlockPos());
    getLevel().sendBlockUpdated(this.getBlockPos(), state, state, 3);
}
Also used : BlockState(net.minecraft.block.BlockState)

Example 59 with BlockState

use of net.minecraft.block.BlockState in project Overloaded by CJ-MC-Mods.

the class ItemMultiTool method breakAndUseEnergy.

/**
 * @return True if the break was successful, false otherwise
 */
@Nonnull
private static BlockBreakResult breakAndUseEnergy(@Nonnull ServerWorld worldIn, @Nonnull BlockPos blockPos, @Nonnull IEnergyStorage energy, @Nonnull ServerPlayerEntity player, int efficiency, int unbreaking) {
    BlockState state = worldIn.getBlockState(blockPos);
    if (!player.abilities.instabuild) {
        float hardness = state.getDestroySpeed(worldIn, blockPos);
        if (hardness < 0) {
            return BlockBreakResult.FAIL_UNBREAKABLE;
        }
        float floatBreakCost = getBreakCost(hardness, efficiency, unbreaking, getDistance(player, blockPos));
        if (Float.isInfinite(floatBreakCost) || Float.isNaN(floatBreakCost))
            return BlockBreakResult.FAIL_ENERGY;
        int breakCost = Math.round(floatBreakCost);
        if (breakCost < 0 || energy.getEnergyStored() < breakCost) {
            return BlockBreakResult.FAIL_ENERGY;
        }
    }
    if (player.distanceToSqr(blockPos.getX(), blockPos.getY(), blockPos.getZ()) > OverloadedConfig.INSTANCE.multiToolConfig.reach * OverloadedConfig.INSTANCE.multiToolConfig.reach) {
        return BlockBreakResult.FAIL_RANGE;
    }
    if (!state.getBlock().canEntityDestroy(state, worldIn, blockPos, player)) {
        return BlockBreakResult.FAIL_REMOVE;
    }
    BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(worldIn, blockPos, state, player);
    MinecraftForge.EVENT_BUS.post(event);
    if (event.isCanceled()) {
        return BlockBreakResult.FAIL_REMOVE;
    }
    boolean result = PlayerInteractionUtil.tryHarvestBlock(player, worldIn, blockPos);
    return result ? BlockBreakResult.SUCCESS : BlockBreakResult.FAIL_REMOVE;
}
Also used : BlockState(net.minecraft.block.BlockState) BlockEvent(net.minecraftforge.event.world.BlockEvent) Nonnull(javax.annotation.Nonnull)

Example 60 with BlockState

use of net.minecraft.block.BlockState in project NetherEx by LogicTechCorp.

the class ElderMushroomBlock method isValidPosition.

@Override
public boolean isValidPosition(BlockState state, IWorldReader world, BlockPos pos) {
    BlockPos posDown = pos.down();
    BlockState stateDown = world.getBlockState(posDown);
    Block blockDown = stateDown.getBlock();
    if (blockDown != Blocks.MYCELIUM && blockDown != Blocks.PODZOL) {
        return stateDown.canSustainPlant(world, posDown, Direction.UP, this);
    } else {
        return true;
    }
}
Also used : BlockState(net.minecraft.block.BlockState) Block(net.minecraft.block.Block) MushroomBlock(net.minecraft.block.MushroomBlock) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

BlockState (net.minecraft.block.BlockState)79 BlockPos (net.minecraft.util.math.BlockPos)32 TileEntity (net.minecraft.tileentity.TileEntity)19 Direction (net.minecraft.util.Direction)16 Nonnull (javax.annotation.Nonnull)12 CompoundNBT (net.minecraft.nbt.CompoundNBT)12 World (net.minecraft.world.World)12 ChunkPos (net.minecraft.util.math.ChunkPos)11 Block (net.minecraft.block.Block)10 Nullable (javax.annotation.Nullable)9 PlayerEntity (net.minecraft.entity.player.PlayerEntity)9 ItemStack (net.minecraft.item.ItemStack)9 HashSet (java.util.HashSet)4 Blocks (net.minecraft.block.Blocks)4 ResourceLocation (net.minecraft.util.ResourceLocation)4 ServerWorld (net.minecraft.world.server.ServerWorld)4 IForgeBlockState (net.minecraftforge.common.extensions.IForgeBlockState)4 TileBPMultipart (com.bluepowermod.tile.TileBPMultipart)3 AgriCraft (com.infinityraider.agricraft.AgriCraft)3 BlockRayTraceResult (net.minecraft.util.math.BlockRayTraceResult)3