Search in sources :

Example 56 with Direction

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

the class TileThermopile method tick.

@Override
public void tick() {
    if (!level.isClientSide) {
        storage.resetCurrent();
        if (level.getBlockState(worldPosition.relative(Direction.DOWN)).getBlock() == Blocks.LAVA && storage.getEnergy() < MAX_VOLTAGE)
            storage.addEnergy(0.1, false);
        // 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()).isPresent()) {
                IPowerBase exStorage = tile.getCapability(CapabilityBlutricity.BLUTRICITY_CAPABILITY, facing.getOpposite()).orElse(null);
                EnergyHelper.balancePower(exStorage, storage);
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IPowerBase(com.bluepowermod.api.power.IPowerBase) Direction(net.minecraft.util.Direction)

Example 57 with Direction

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

the class WorldGenVolcano method generateLootChamber.

private void generateLootChamber(IWorld world, int middleX, int startY, int middleZ, Random rand) {
    int roomSize = 9;
    int roomHeight = 5;
    int startX = middleX - roomSize / 2;
    int startZ = middleZ - roomSize / 2;
    for (int x = startX; x < startX + roomSize; x++) {
        for (int y = startY; y < startY + roomHeight; y++) {
            for (int z = startZ; z < startZ + roomSize; z++) {
                int xOffset = Math.abs(x - middleX);
                int zOffset = Math.abs(z - middleZ);
                if (xOffset != 0 || zOffset != 0) {
                    boolean spawnGlass = xOffset <= 1 && zOffset <= 1;
                    setBlock(world, new BlockPos(x, y, z), spawnGlass ? BPBlocks.reinforced_sapphire_glass.defaultBlockState() : Blocks.AIR.defaultBlockState());
                }
            }
        }
    }
    for (Direction d : Direction.values()) {
        if (d != Direction.UP && d != Direction.DOWN) {
            if (rand.nextInt(2) == 0) {
                generateAltar(world, middleX + d.getStepX() * roomSize / 2, startY - 1, middleZ + d.getStepZ() * roomSize / 2, rand, d);
            }
        }
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) Direction(net.minecraft.util.Direction)

Example 58 with Direction

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

the class BlockBPCableBase method getStateForPos.

private BlockState getStateForPos(World world, BlockPos pos, BlockState state, Direction face) {
    List<Direction> directions = new ArrayList<>(FACING.getPossibleValues());
    List<Direction> internal = null;
    boolean connected_left = false;
    boolean connected_right = false;
    boolean connected_front = false;
    boolean connected_back = false;
    boolean join_left = false;
    boolean join_right = false;
    boolean join_front = false;
    boolean join_back = false;
    // Make sure the side we are trying to connect on isn't blocked.
    TileEntity ownTile = world.getBlockEntity(pos);
    if (ownTile instanceof TileBPMultipart) {
        directions.removeIf(d -> ((TileBPMultipart) ownTile).isSideBlocked(getCapability(), d));
        internal = ((TileBPMultipart) ownTile).getStates().stream().filter(s -> s.getBlock() == this).map(s -> s.getValue(FACING)).collect(Collectors.toList());
    }
    // Make sure the cable is on the same side of the block
    directions.removeIf(d -> {
        TileEntity t = world.getBlockEntity(pos.relative(d));
        return (world.getBlockState(pos.relative(d)).getBlock() == this && world.getBlockState(pos.relative(d)).getValue(FACING) != face) || (t instanceof TileBPMultipart && ((TileBPMultipart) t).getStates().stream().noneMatch(s -> s.getValue(FACING) == face));
    });
    // Populate all directions
    for (Direction d : directions) {
        TileEntity tileEntity = world.getBlockEntity(pos.relative(d));
        BlockState dirState = world.getBlockState(pos.relative(d));
        BlockPos dirPos = pos.relative(d);
        boolean join = false;
        // If Air look for a change in Direction
        if (world.getBlockState(pos.relative(d)).getBlock() == Blocks.AIR) {
            dirState = world.getBlockState(pos.relative(d).relative(face.getOpposite()));
            dirPos = pos.relative(d).relative(face.getOpposite());
            if (dirState.getBlock() == this && dirState.getValue(FACING) == d) {
                tileEntity = world.getBlockEntity(pos.relative(d).relative(face.getOpposite()));
                join = true;
            } else if (dirState.getBlock() instanceof BlockBPMultipart) {
                tileEntity = world.getBlockEntity(pos.relative(d).relative(face.getOpposite()));
                if (tileEntity instanceof TileBPMultipart && ((TileBPMultipart) tileEntity).getStates().stream().filter(s -> s.getBlock() == this).anyMatch(s -> s.getValue(FACING) == d)) {
                    join = true;
                } else {
                    tileEntity = null;
                }
            }
        }
        // Check Capability for Direction
        switch(state.getValue(FACING)) {
            case UP:
            case DOWN:
                switch(d) {
                    case EAST:
                        connected_right = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_right = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                    case WEST:
                        connected_left = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_left = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                    case NORTH:
                        connected_front = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_front = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                    case SOUTH:
                        connected_back = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_back = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                }
                break;
            case NORTH:
                switch(d) {
                    case WEST:
                        connected_right = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_right = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                    case EAST:
                        connected_left = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_left = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                    case UP:
                        connected_front = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_front = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                    case DOWN:
                        connected_back = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_back = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                }
                break;
            case SOUTH:
                switch(d) {
                    case EAST:
                        connected_right = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_right = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                    case WEST:
                        connected_left = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_left = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                    case UP:
                        connected_front = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_front = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                    case DOWN:
                        connected_back = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_back = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                }
                break;
            case EAST:
                switch(d) {
                    case NORTH:
                        connected_right = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_right = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                    case SOUTH:
                        connected_left = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_left = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                    case UP:
                        connected_front = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_front = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                    case DOWN:
                        connected_back = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_back = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                }
                break;
            case WEST:
                switch(d) {
                    case SOUTH:
                        connected_right = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_right = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                    case NORTH:
                        connected_left = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_left = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                    case UP:
                        connected_front = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_front = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                    case DOWN:
                        connected_back = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_back = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                }
        }
    }
    if (internal != null)
        for (Direction d : internal) {
            switch(state.getValue(FACING)) {
                case UP:
                case DOWN:
                    switch(d) {
                        case EAST:
                            connected_left = true;
                            break;
                        case WEST:
                            connected_right = true;
                            break;
                        case NORTH:
                            connected_back = true;
                            break;
                        case SOUTH:
                            connected_front = true;
                            break;
                    }
                    break;
                case NORTH:
                    switch(d) {
                        case WEST:
                            connected_left = true;
                            break;
                        case EAST:
                            connected_right = true;
                            break;
                        case UP:
                            connected_back = true;
                            break;
                        case DOWN:
                            connected_front = true;
                            break;
                    }
                    break;
                case SOUTH:
                    switch(d) {
                        case EAST:
                            connected_left = true;
                            break;
                        case WEST:
                            connected_right = true;
                            break;
                        case UP:
                            connected_back = true;
                            break;
                        case DOWN:
                            connected_front = true;
                            break;
                    }
                    break;
                case EAST:
                    switch(d) {
                        case NORTH:
                            connected_left = true;
                            break;
                        case SOUTH:
                            connected_right = true;
                            break;
                        case UP:
                            connected_back = true;
                            break;
                        case DOWN:
                            connected_front = true;
                            break;
                    }
                    break;
                case WEST:
                    switch(d) {
                        case SOUTH:
                            connected_left = true;
                            break;
                        case NORTH:
                            connected_right = true;
                            break;
                        case UP:
                            connected_back = true;
                            break;
                        case DOWN:
                            connected_front = true;
                            break;
                    }
            }
        }
    FluidState fluidstate = world.getFluidState(pos);
    return state.setValue(CONNECTED_LEFT, connected_left).setValue(CONNECTED_RIGHT, connected_right).setValue(CONNECTED_FRONT, connected_front).setValue(CONNECTED_BACK, connected_back).setValue(JOIN_LEFT, join_left).setValue(JOIN_RIGHT, join_right).setValue(JOIN_FRONT, join_front).setValue(JOIN_BACK, join_back).setValue(WATERLOGGED, fluidstate.getType() == Fluids.WATER);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidState(net.minecraft.fluid.FluidState) IWorld(net.minecraft.world.IWorld) Direction(net.minecraft.util.Direction) IWorldReader(net.minecraft.world.IWorldReader) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) StateContainer(net.minecraft.state.StateContainer) IBlockReader(net.minecraft.world.IBlockReader) net.minecraft.block(net.minecraft.block) ISelectionContext(net.minecraft.util.math.shapes.ISelectionContext) VoxelShape(net.minecraft.util.math.shapes.VoxelShape) Nullable(javax.annotation.Nullable) Fluids(net.minecraft.fluid.Fluids) BooleanProperty(net.minecraft.state.BooleanProperty) LivingEntity(net.minecraft.entity.LivingEntity) World(net.minecraft.world.World) BlockPos(net.minecraft.util.math.BlockPos) BlockItemUseContext(net.minecraft.item.BlockItemUseContext) Collectors(java.util.stream.Collectors) TileBPMultipart(com.bluepowermod.tile.TileBPMultipart) Capability(net.minecraftforge.common.capabilities.Capability) AABBUtils(com.bluepowermod.util.AABBUtils) List(java.util.List) IBPPartBlock(com.bluepowermod.api.multipart.IBPPartBlock) Material(net.minecraft.block.material.Material) TileEntity(net.minecraft.tileentity.TileEntity) VoxelShapes(net.minecraft.util.math.shapes.VoxelShapes) DirectionProperty(net.minecraft.state.DirectionProperty) BlockStateProperties(net.minecraft.state.properties.BlockStateProperties) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.util.math.BlockPos) TileBPMultipart(com.bluepowermod.tile.TileBPMultipart) Direction(net.minecraft.util.Direction) FluidState(net.minecraft.fluid.FluidState)

Example 59 with Direction

use of net.minecraft.util.Direction in project Ceramics by KnightMiner.

the class ChannelBlock method getStateForPlacement.

@Override
@Nullable
public BlockState getStateForPlacement(BlockItemUseContext context) {
    World world = context.getWorld();
    BlockPos pos = context.getPos();
    BlockState state = this.getDefaultState().with(POWERED, world.isBlockPowered(pos));
    Direction side = context.getFace();
    // we cannot connect upwards, so done here
    if (side == Direction.DOWN) {
        return state;
    }
    // if placed on the top face, try to connect down
    if (side == Direction.UP) {
        return state.with(DOWN, canConnect(world, pos, Direction.DOWN));
    }
    // if placed on a fluid handler, connect to that
    ChannelConnection connection = ChannelConnection.NONE;
    BlockPos placedOn = pos.offset(side.getOpposite());
    // on another channel means in or out
    if (world.getBlockState(placedOn).isIn(this)) {
        PlayerEntity player = context.getPlayer();
        connection = player != null && player.isSneaking() ? ChannelConnection.IN : ChannelConnection.OUT;
    } else if (isFluidHandler(world, side, placedOn)) {
        connection = ChannelConnection.OUT;
    }
    return state.with(DIRECTION_MAP.get(side.getOpposite()), connection);
}
Also used : BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) IWorld(net.minecraft.world.IWorld) World(net.minecraft.world.World) Direction(net.minecraft.util.Direction) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Nullable(javax.annotation.Nullable)

Example 60 with Direction

use of net.minecraft.util.Direction in project Ceramics by KnightMiner.

the class CisternBlock method isConnected.

/**
 * Check if the given block is something the barrel should connect to
 * @param facing       Side to check
 * @param facingState  Block on side
 * @return  True if connected, false otherwise
 */
protected boolean isConnected(Direction facing, BlockState facingState) {
    // must be in tag
    if (!facingState.isIn(CeramicsTags.Blocks.CISTERN_CONNECTIONS)) {
        return false;
    }
    // if the block has a side property, use that
    Direction opposite = facing.getOpposite();
    BooleanProperty sideProp = CONNECTIONS.get(opposite);
    if (facingState.hasProperty(sideProp)) {
        return facingState.get(sideProp);
    }
    // channel connections
    EnumProperty<ChannelConnection> channelProp = ChannelBlock.DIRECTION_MAP.get(opposite);
    if (facingState.hasProperty(channelProp)) {
        return facingState.get(channelProp) == ChannelConnection.OUT;
    }
    // if there is a face property and it is not wall, not connected
    if (facingState.hasProperty(BlockStateProperties.FACE) && facingState.get(BlockStateProperties.FACE) != AttachFace.WALL) {
        return false;
    }
    // try relevant facing properties, if any are present must be facing this
    return facingConnected(facing, facingState, BlockStateProperties.HORIZONTAL_FACING) && facingConnected(facing, facingState, BlockStateProperties.FACING) && facingConnected(facing, facingState, BlockStateProperties.FACING_EXCEPT_UP);
}
Also used : BooleanProperty(net.minecraft.state.BooleanProperty) ChannelConnection(knightminer.ceramics.blocks.ChannelBlock.ChannelConnection) 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