Search in sources :

Example 41 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 42 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)

Example 43 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 44 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 45 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)

Aggregations

Direction (net.minecraft.util.Direction)50 BlockState (net.minecraft.block.BlockState)18 TileEntity (net.minecraft.tileentity.TileEntity)17 BlockPos (net.minecraft.util.math.BlockPos)15 ItemStack (net.minecraft.item.ItemStack)12 Block (net.minecraft.block.Block)10 Nonnull (javax.annotation.Nonnull)8 Nullable (javax.annotation.Nullable)8 CompoundNBT (net.minecraft.nbt.CompoundNBT)6 IPowerBase (com.bluepowermod.api.power.IPowerBase)5 PlayerEntity (net.minecraft.entity.player.PlayerEntity)5 World (net.minecraft.world.World)5 Capability (net.minecraftforge.common.capabilities.Capability)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 INBT (net.minecraft.nbt.INBT)4 LazyOptional (net.minecraftforge.common.util.LazyOptional)4