Search in sources :

Example 6 with BlockBounding

use of mekanism.common.block.BlockBounding in project Mekanism by mekanism.

the class WorldUtils method makeAdvancedBoundingBlock.

/**
 * Places a fake advanced bounding block at the defined location.
 *
 * @param world            world to place block in
 * @param boundingLocation coordinates of bounding block
 * @param orig             original block position
 */
public static void makeAdvancedBoundingBlock(IWorld world, BlockPos boundingLocation, BlockPos orig) {
    BlockBounding boundingBlock = MekanismBlocks.ADVANCED_BOUNDING_BLOCK.getBlock();
    BlockState newState = BlockStateHelper.getStateForPlacement(boundingBlock, boundingBlock.defaultBlockState(), world, boundingLocation, null, Direction.NORTH);
    world.setBlock(boundingLocation, newState, BlockFlags.DEFAULT);
    if (!world.isClientSide()) {
        TileEntityAdvancedBoundingBlock tile = getTileEntity(TileEntityAdvancedBoundingBlock.class, world, boundingLocation);
        if (tile != null) {
            tile.setMainLocation(orig);
        } else {
            Mekanism.logger.warn("Unable to find Advanced Bounding Block Tile at: {}", boundingLocation);
        }
    }
}
Also used : TileEntityAdvancedBoundingBlock(mekanism.common.tile.TileEntityAdvancedBoundingBlock) BlockState(net.minecraft.block.BlockState) BlockBounding(mekanism.common.block.BlockBounding)

Example 7 with BlockBounding

use of mekanism.common.block.BlockBounding in project Mekanism by mekanism.

the class ItemMekaTool method onBlockStartBreak.

@Override
public boolean onBlockStartBreak(ItemStack stack, BlockPos pos, PlayerEntity player) {
    if (player.level.isClientSide || player.isCreative()) {
        return super.onBlockStartBreak(stack, pos, player);
    }
    IEnergyContainer energyContainer = StorageUtils.getEnergyContainer(stack, 0);
    if (energyContainer != null) {
        World world = player.level;
        BlockState state = world.getBlockState(pos);
        boolean silk = isModuleEnabled(stack, MekanismModules.SILK_TOUCH_UNIT);
        FloatingLong energyRequired = getDestroyEnergy(stack, state.getDestroySpeed(world, pos), silk);
        if (energyContainer.extract(energyRequired, Action.SIMULATE, AutomationType.MANUAL).greaterOrEqual(energyRequired)) {
            IModule<ModuleVeinMiningUnit> veinMiningUnit = getModule(stack, MekanismModules.VEIN_MINING_UNIT);
            // Even though we now handle breaking bounding blocks properly, don't allow vein mining them
            if (veinMiningUnit != null && veinMiningUnit.isEnabled() && !(state.getBlock() instanceof BlockBounding)) {
                boolean isOre = state.is(MekanismTags.Blocks.ATOMIC_DISASSEMBLER_ORE);
                // If it is extended or should be treated as an ore
                if (isOre || veinMiningUnit.getCustomInstance().isExtended()) {
                    // Don't include bonus energy required by efficiency modules when calculating energy of vein mining targets
                    FloatingLong baseDestroyEnergy = getDestroyEnergy(silk);
                    Set<BlockPos> found = ModuleVeinMiningUnit.findPositions(state, pos, world, isOre ? -1 : veinMiningUnit.getCustomInstance().getExcavationRange());
                    MekanismUtils.veinMineArea(energyContainer, world, pos, (ServerPlayerEntity) player, stack, this, found, isModuleEnabled(stack, MekanismModules.SHEARING_UNIT), hardness -> getDestroyEnergy(baseDestroyEnergy, hardness), distance -> 0.5 * Math.pow(distance, isOre ? 1.5 : 2), state);
                }
            }
        }
    }
    return super.onBlockStartBreak(stack, pos, player);
}
Also used : FloatingLong(mekanism.api.math.FloatingLong) IEnergyContainer(mekanism.api.energy.IEnergyContainer) BlockState(net.minecraft.block.BlockState) BlockBounding(mekanism.common.block.BlockBounding) ModuleVeinMiningUnit(mekanism.common.content.gear.mekatool.ModuleVeinMiningUnit) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World)

Example 8 with BlockBounding

use of mekanism.common.block.BlockBounding in project Mekanism by mekanism.

the class ItemAtomicDisassembler method onBlockStartBreak.

@Override
public boolean onBlockStartBreak(ItemStack stack, BlockPos pos, PlayerEntity player) {
    if (player.level.isClientSide || player.isCreative()) {
        return super.onBlockStartBreak(stack, pos, player);
    }
    IEnergyContainer energyContainer = StorageUtils.getEnergyContainer(stack, 0);
    if (energyContainer != null && getMode(stack) == DisassemblerMode.VEIN) {
        World world = player.level;
        BlockState state = world.getBlockState(pos);
        FloatingLong baseDestroyEnergy = getDestroyEnergy(stack);
        FloatingLong energyRequired = getDestroyEnergy(baseDestroyEnergy, state.getDestroySpeed(world, pos));
        if (energyContainer.extract(energyRequired, Action.SIMULATE, AutomationType.MANUAL).greaterOrEqual(energyRequired)) {
            // only allow mining things that are considered an ore
            if (!(state.getBlock() instanceof BlockBounding) && state.is(MekanismTags.Blocks.ATOMIC_DISASSEMBLER_ORE)) {
                List<BlockPos> found = findPositions(state, pos, world);
                MekanismUtils.veinMineArea(energyContainer, world, pos, (ServerPlayerEntity) player, stack, this, found, false, hardness -> getDestroyEnergy(baseDestroyEnergy, hardness), distance -> 0.5 * Math.pow(distance, 1.5), state);
            }
        }
    }
    return super.onBlockStartBreak(stack, pos, player);
}
Also used : FloatingLong(mekanism.api.math.FloatingLong) IEnergyContainer(mekanism.api.energy.IEnergyContainer) BlockState(net.minecraft.block.BlockState) BlockBounding(mekanism.common.block.BlockBounding) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World)

Aggregations

BlockBounding (mekanism.common.block.BlockBounding)8 BlockState (net.minecraft.block.BlockState)5 BlockPos (net.minecraft.util.math.BlockPos)4 ItemStack (net.minecraft.item.ItemStack)3 World (net.minecraft.world.World)3 ArrayList (java.util.ArrayList)2 IEnergyContainer (mekanism.api.energy.IEnergyContainer)2 FloatingLong (mekanism.api.math.FloatingLong)2 TileEntityBoundingBlock (mekanism.common.tile.TileEntityBoundingBlock)2 BlockItem (net.minecraft.item.BlockItem)2 Item (net.minecraft.item.Item)2 TileEntity (net.minecraft.tileentity.TileEntity)2 MatrixStack (com.mojang.blaze3d.matrix.MatrixStack)1 IWireFrameRenderer (mekanism.client.render.tileentity.IWireFrameRenderer)1 AttributeCustomSelectionBox (mekanism.common.block.attribute.AttributeCustomSelectionBox)1 ModuleVeinMiningUnit (mekanism.common.content.gear.mekatool.ModuleVeinMiningUnit)1 ItemConfigurator (mekanism.common.item.ItemConfigurator)1 ConfiguratorMode (mekanism.common.item.ItemConfigurator.ConfiguratorMode)1 TransmissionType (mekanism.common.lib.transmitter.TransmissionType)1 TileEntityAdvancedBoundingBlock (mekanism.common.tile.TileEntityAdvancedBoundingBlock)1