Search in sources :

Example 51 with Direction

use of net.minecraft.util.Direction 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 52 with Direction

use of net.minecraft.util.Direction 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)

Example 53 with Direction

use of net.minecraft.util.Direction 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 54 with Direction

use of net.minecraft.util.Direction in project BluePower by Qmunity.

the class TileFilter method pullItem.

@Override
protected void pullItem() {
    Direction dir = getOutputDirection().getOpposite();
    TileEntity tile = getTileCache(dir);
    Direction direction = dir.getOpposite();
    boolean everythingNull = true;
    for (ItemStack filterStack : inventory) {
        if (!filterStack.isEmpty()) {
            everythingNull = false;
            ItemStack extractedStack = IOHelper.extract(tile, direction, filterStack, true, false, fuzzySetting);
            if (!extractedStack.isEmpty()) {
                this.addItemToOutputBuffer(extractedStack, filterColor);
                break;
            }
        }
    }
    if (everythingNull) {
        ItemStack extractedStack = IOHelper.extract(tile, direction, false);
        if (!extractedStack.isEmpty()) {
            this.addItemToOutputBuffer(extractedStack, filterColor);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ItemStack(net.minecraft.item.ItemStack) Direction(net.minecraft.util.Direction)

Example 55 with Direction

use of net.minecraft.util.Direction in project BluePower by Qmunity.

the class TileTransposer method suckEntity.

private void suckEntity() {
    Direction direction = getFacingDirection();
    AxisAlignedBB box = new AxisAlignedBB(worldPosition.getX() + direction.getStepX(), worldPosition.getY() + direction.getStepY(), worldPosition.getZ() + direction.getStepZ(), worldPosition.getX() + direction.getStepX() + 1, worldPosition.getY() + direction.getStepY() + 1, worldPosition.getZ() + direction.getStepZ() + 1);
    for (ItemEntity entity : (List<ItemEntity>) level.getEntitiesOfClass(ItemEntity.class, box)) {
        ItemStack stack = entity.getItem();
        if (isItemAccepted(stack) && entity.isAlive()) {
            addItemToOutputBuffer(stack, getAcceptedItemColor(stack));
            entity.remove();
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ItemEntity(net.minecraft.entity.item.ItemEntity) List(java.util.List) ItemStack(net.minecraft.item.ItemStack) Direction(net.minecraft.util.Direction)

Aggregations

Direction (net.minecraft.util.Direction)66 BlockState (net.minecraft.block.BlockState)26 BlockPos (net.minecraft.util.math.BlockPos)21 TileEntity (net.minecraft.tileentity.TileEntity)19 ItemStack (net.minecraft.item.ItemStack)14 Block (net.minecraft.block.Block)11 Nullable (javax.annotation.Nullable)10 World (net.minecraft.world.World)9 Nonnull (javax.annotation.Nonnull)8 PlayerEntity (net.minecraft.entity.player.PlayerEntity)8 CompoundNBT (net.minecraft.nbt.CompoundNBT)6 IPowerBase (com.bluepowermod.api.power.IPowerBase)5 FluidStack (net.minecraftforge.fluids.FluidStack)5 BlutricityStorage (com.bluepowermod.api.power.BlutricityStorage)4 CapabilityBlutricity (com.bluepowermod.api.power.CapabilityBlutricity)4 EnergyHelper (com.bluepowermod.helper.EnergyHelper)4 BPTileEntityType (com.bluepowermod.tile.BPTileEntityType)4 TileMachineBase (com.bluepowermod.tile.TileMachineBase)4 ArrayList (java.util.ArrayList)4 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)4