Search in sources :

Example 11 with Direction

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

the class BlockGateBase method getSidePower.

private Map<String, Byte> getSidePower(IBlockReader worldIn, BlockState state, BlockPos pos) {
    Map<String, Byte> map = new HashMap<>();
    Direction[] dirs = DirectionHelper.ArrayFromDirection(state.getValue(FACING));
    Direction side_left = dirs[state.getValue(ROTATION) == 3 ? 0 : state.getValue(ROTATION) + 1];
    Direction side_right = side_left.getOpposite();
    Direction side_back = dirs[state.getValue(ROTATION)];
    BlockPos pos_left = pos.relative(side_left);
    BlockPos pos_right = pos.relative(side_right);
    BlockPos pos_back = pos.relative(side_back);
    BlockState state_left = worldIn.getBlockState(pos_left);
    BlockState state_right = worldIn.getBlockState(pos_right);
    BlockState state_back = worldIn.getBlockState(pos_back);
    byte left = (byte) state_left.getSignal(worldIn, pos_left, side_right);
    byte right = (byte) state_right.getSignal(worldIn, pos_right, side_left);
    byte back = (byte) state_back.getSignal(worldIn, pos_back, side_back.getOpposite());
    if (state_left.getBlock() instanceof RedstoneWireBlock) {
        left = state_left.getValue(RedstoneWireBlock.POWER).byteValue();
    }
    if (state_right.getBlock() instanceof RedstoneWireBlock) {
        right = state_right.getValue(RedstoneWireBlock.POWER).byteValue();
    }
    if (state_back.getBlock() instanceof RedstoneWireBlock) {
        back = state_back.getValue(RedstoneWireBlock.POWER).byteValue();
    }
    map.put("left", left);
    map.put("right", right);
    map.put("back", back);
    map.put("front", computeRedstone(back, left, right));
    return map;
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) Direction(net.minecraft.util.Direction)

Example 12 with Direction

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

the class ItemCropSeed method useOn.

@Override
public ActionResultType useOn(ItemUseContext itemUseContext) {
    PlayerEntity player = itemUseContext.getPlayer();
    Hand hand = itemUseContext.getHand();
    Direction facing = itemUseContext.getClickedFace();
    World world = itemUseContext.getLevel();
    BlockPos pos = itemUseContext.getClickedPos();
    ItemStack itemStack = player.getItemInHand(hand);
    if (facing.ordinal() != 1) {
        return ActionResultType.PASS;
    } else if (player.mayUseItemAt(pos, facing, itemStack) && player.mayUseItemAt(pos.above(), facing, itemStack)) {
        if (world.getBlockState(pos).getBlock().canSustainPlant(world.getBlockState(pos), world, pos, Direction.UP, this) && world.isEmptyBlock(pos.above()) && world.getBlockState(pos).getBlock() instanceof FarmlandBlock) {
            world.setBlock(pos.above(), field_150925_a.defaultBlockState(), 2);
            itemStack.setCount(itemStack.getCount() - 1);
            player.setItemInHand(hand, itemStack);
            return ActionResultType.SUCCESS;
        } else {
            return ActionResultType.PASS;
        }
    } else {
        return ActionResultType.PASS;
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) FarmlandBlock(net.minecraft.block.FarmlandBlock) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) Hand(net.minecraft.util.Hand) Direction(net.minecraft.util.Direction) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 13 with Direction

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

the class ItemBPPart method place.

@Override
public ActionResultType place(BlockItemUseContext context) {
    BlockState state = context.getLevel().getBlockState(context.getClickedPos());
    BlockState thisState = getBlock().getStateForPlacement(context);
    if (state.getBlock() instanceof IBPPartBlock && thisState != null && !AABBUtils.testOcclusion(((IBPPartBlock) thisState.getBlock()).getOcclusionShape(thisState), state.getShape(context.getLevel(), context.getClickedPos()))) {
        // Save the Tile Entity Data
        CompoundNBT nbt = new CompoundNBT();
        TileEntity tileEntity = context.getLevel().getBlockEntity(context.getClickedPos());
        if (tileEntity != null) {
            nbt = tileEntity.save(nbt);
        }
        // Replace with Multipart
        context.getLevel().setBlockAndUpdate(context.getClickedPos(), BPBlocks.multipart.defaultBlockState());
        tileEntity = context.getLevel().getBlockEntity(context.getClickedPos());
        if (tileEntity instanceof TileBPMultipart) {
            // Add the original State to the Multipart
            ((TileBPMultipart) tileEntity).addState(state);
            // Restore the Tile Entity Data
            TileEntity tile = ((TileBPMultipart) tileEntity).getTileForState(state);
            if (tile != null)
                tile.load(state, nbt);
            // Add the new State
            ((TileBPMultipart) tileEntity).addState(thisState);
            thisState.getBlock().setPlacedBy(context.getLevel(), context.getClickedPos(), thisState, context.getPlayer(), context.getItemInHand());
        }
        // Update Self
        state.neighborChanged(context.getLevel(), context.getClickedPos(), state.getBlock(), context.getClickedPos(), false);
        context.getItemInHand().shrink(1);
        // Place Sound
        context.getLevel().playSound(null, context.getClickedPos(), SoundEvents.STONE_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F);
        return ActionResultType.SUCCESS;
    } else if (state.getBlock() instanceof BlockBPMultipart && thisState != null && !AABBUtils.testOcclusion(((IBPPartBlock) thisState.getBlock()).getOcclusionShape(thisState), state.getShape(context.getLevel(), context.getClickedPos()))) {
        // Add to the Existing Multipart
        TileEntity tileEntity = context.getLevel().getBlockEntity(context.getClickedPos());
        if (tileEntity instanceof TileBPMultipart) {
            ((TileBPMultipart) tileEntity).addState(thisState);
            thisState.getBlock().setPlacedBy(context.getLevel(), context.getClickedPos(), thisState, context.getPlayer(), context.getItemInHand());
            // Update Neighbors
            for (Direction dir : Direction.values()) {
                context.getLevel().getBlockState(context.getClickedPos().relative(dir)).neighborChanged(context.getLevel(), context.getClickedPos().relative(dir), state.getBlock(), context.getClickedPos(), false);
            }
            // Update Self
            state.neighborChanged(context.getLevel(), context.getClickedPos(), state.getBlock(), context.getClickedPos(), false);
            context.getItemInHand().shrink(1);
            // Place Sound
            context.getLevel().playSound(null, context.getClickedPos(), SoundEvents.STONE_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F);
            return ActionResultType.SUCCESS;
        }
    }
    return super.place(context);
}
Also used : IBPPartBlock(com.bluepowermod.api.multipart.IBPPartBlock) TileEntity(net.minecraft.tileentity.TileEntity) BlockState(net.minecraft.block.BlockState) CompoundNBT(net.minecraft.nbt.CompoundNBT) BlockBPMultipart(com.bluepowermod.block.BlockBPMultipart) TileBPMultipart(com.bluepowermod.tile.TileBPMultipart) Direction(net.minecraft.util.Direction)

Example 14 with Direction

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

the class TileEngine method tick.

@Override
public void tick() {
    super.tick();
    storage.resetCurrent();
    // Server side capability check
    isActive = false;
    if (level != null && !level.isClientSide && (storage.getEnergyStored() > 0 && level.hasNeighborSignal(worldPosition))) {
        Direction facing = getBlockState().getValue(BlockEngine.FACING).getOpposite();
        TileEntity tileEntity = level.getBlockEntity(worldPosition.relative(facing));
        if (tileEntity != null) {
            tileEntity.getCapability(CapabilityEnergy.ENERGY, facing.getOpposite()).ifPresent(other -> {
                int simulated = storage.extractEnergy(320, true);
                int sent = other.receiveEnergy(simulated, false);
                int amount = storage.extractEnergy(sent, false);
                if (amount > 0) {
                    isActive = true;
                }
            });
        }
    }
    // Update BlockState
    if (level != null && !level.isClientSide && getBlockState().getValue(BlockEngine.ACTIVE) != isActive) {
        level.setBlockAndUpdate(worldPosition, getBlockState().setValue(BlockEngine.ACTIVE, isActive));
        markForRenderUpdate();
    }
    // Update TESR from BlockState
    if (level != null && getBlockState().getValue(BlockEngine.ACTIVE)) {
        isActive = true;
        pumpTick++;
        if (pumpTick >= pumpSpeed * 2) {
            pumpTick = 0;
            if (pumpSpeed > 4) {
                pumpSpeed--;
            }
        }
    } else {
        isActive = false;
        pumpTick = 0;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Direction(net.minecraft.util.Direction)

Example 15 with Direction

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

the class WorldGenVolcano method generateAltar.

private void generateAltar(IWorld world, int startX, int startY, int startZ, Random rand, Direction dir) {
    generateLootChest(world, new BlockPos(startX, startY + 1, startZ), rand, dir);
    Direction opDir = dir.getOpposite();
    Block altarBlock = alterBlocks.get(new Random().nextInt(alterBlocks.size()));
    setAltarBlockAndPossiblyTrap(world, startX, startY, startZ, rand, altarBlock);
    setAltarBlockAndPossiblyTrap(world, startX + opDir.getStepX(), startY, startZ + opDir.getStepZ(), rand, altarBlock);
    Direction sideDir = Direction.DOWN;
    setAltarBlockAndPossiblyTrap(world, startX + sideDir.getStepX(), startY, startZ + sideDir.getStepZ(), rand, altarBlock);
    setAltarBlockAndPossiblyTrap(world, startX + sideDir.getStepX() + opDir.getStepX(), startY, startZ + sideDir.getStepZ() + opDir.getStepZ(), rand, altarBlock);
    sideDir = sideDir.getOpposite();
    setAltarBlockAndPossiblyTrap(world, startX + sideDir.getStepX(), startY, startZ + sideDir.getStepZ(), rand, altarBlock);
    setAltarBlockAndPossiblyTrap(world, startX + sideDir.getStepX() + opDir.getStepX(), startY, startZ + sideDir.getStepZ() + opDir.getStepZ(), rand, altarBlock);
}
Also used : SharedSeedRandom(net.minecraft.util.SharedSeedRandom) Block(net.minecraft.block.Block) ChestBlock(net.minecraft.block.ChestBlock) BlockPos(net.minecraft.util.math.BlockPos) Direction(net.minecraft.util.Direction)

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