Search in sources :

Example 51 with BlockState

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

the class TileBPMultipart method markDirtyClient.

private void markDirtyClient() {
    setChanged();
    if (getLevel() != null) {
        BlockState state = getLevel().getBlockState(getBlockPos());
        getLevel().sendBlockUpdated(getBlockPos(), state, state, 3);
    }
    this.requestModelDataUpdate();
}
Also used : IForgeBlockState(net.minecraftforge.common.extensions.IForgeBlockState) BlockState(net.minecraft.block.BlockState)

Example 52 with BlockState

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

the class TileBPMultipart method onDataPacket.

@Override
public void onDataPacket(NetworkManager networkManager, SUpdateTileEntityPacket packet) {
    List<BlockState> states = getStates();
    CompoundNBT tagCompound = packet.getTag();
    super.onDataPacket(networkManager, packet);
    load(getBlockState(), tagCompound);
    if (level.isClientSide) {
        // Update if needed
        if (!getStates().equals(states)) {
            level.blockEntityChanged(getBlockPos(), this.getTileEntity());
        }
    }
}
Also used : IForgeBlockState(net.minecraftforge.common.extensions.IForgeBlockState) BlockState(net.minecraft.block.BlockState) CompoundNBT(net.minecraft.nbt.CompoundNBT)

Example 53 with BlockState

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

the class TileBlockBreaker method redstoneChanged.

@Override
protected void redstoneChanged(boolean newValue) {
    super.redstoneChanged(newValue);
    if (!level.isClientSide && newValue) {
        Direction direction = getFacingDirection();
        BlockState breakState = level.getBlockState(worldPosition.relative(direction));
        if (!canBreakBlock(breakState.getBlock(), level, breakState, worldPosition.relative(direction)))
            return;
        List<ItemStack> breakStacks = breakState.getBlock().getDrops(breakState, (ServerWorld) level, worldPosition.relative(direction), this);
        // destroyBlock
        level.destroyBlock(worldPosition.relative(direction), false);
        addItemsToOutputBuffer(breakStacks);
    }
}
Also used : BlockState(net.minecraft.block.BlockState) ItemStack(net.minecraft.item.ItemStack) Direction(net.minecraft.util.Direction)

Example 54 with BlockState

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

the class TileBattery method tick.

@Override
public void tick() {
    if (!level.isClientSide) {
        storage.resetCurrent();
        // Balance power of attached blulectric blocks.
        for (Direction facing : Direction.values()) {
            TileEntity tile = level.getBlockEntity(worldPosition.relative(facing));
            if (tile != null)
                tile.getCapability(CapabilityBlutricity.BLUTRICITY_CAPABILITY, facing.getOpposite()).ifPresent(exStorage -> EnergyHelper.balancePower(exStorage, storage));
        }
        double energy = storage.getEnergy();
        int batteryLevel = (int) ((energy / MAX_ENERGY) * 6);
        BlockState state = getBlockState();
        if (state.getValue(BlockBattery.LEVEL) != batteryLevel) {
            this.level.setBlockAndUpdate(worldPosition, state.setValue(BlockBattery.LEVEL, batteryLevel));
            markForRenderUpdate();
            setChanged();
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) 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) Capability(net.minecraftforge.common.capabilities.Capability) LazyOptional(net.minecraftforge.common.util.LazyOptional) BlutricityStorage(com.bluepowermod.api.power.BlutricityStorage) SUpdateTileEntityPacket(net.minecraft.network.play.server.SUpdateTileEntityPacket) BlockBattery(com.bluepowermod.block.power.BlockBattery) 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) Direction(net.minecraft.util.Direction)

Example 55 with BlockState

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

the class TileBlulectricCable method getCapability.

@Nonnull
@Override
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
    List<Direction> directions = new ArrayList<>(BlockBlulectricCable.FACING.getPossibleValues());
    if (level != null) {
        BlockState state = getBlockState();
        if (state.getBlock() instanceof BlockBlulectricCable) {
            // Remove upward connections
            directions.remove(state.getValue(BlockBlulectricCable.FACING));
            // Make sure the cable is on the same side of the block
            directions.removeIf(d -> level.getBlockState(worldPosition.relative(d)).getBlock() instanceof BlockBlulectricCable && level.getBlockState(worldPosition.relative(d)).getValue(BlockBlulectricCable.FACING) != state.getValue(BlockBlulectricCable.FACING));
        }
    }
    if (cap == CapabilityBlutricity.BLUTRICITY_CAPABILITY && (side == null || directions.contains(side))) {
        if (blutricityCap == null)
            blutricityCap = LazyOptional.of(() -> storage);
        return blutricityCap.cast();
    }
    return LazyOptional.empty();
}
Also used : BlockState(net.minecraft.block.BlockState) BlockBlulectricCable(com.bluepowermod.block.power.BlockBlulectricCable) ArrayList(java.util.ArrayList) Direction(net.minecraft.util.Direction) Nonnull(javax.annotation.Nonnull)

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