Search in sources :

Example 1 with FlowingFluidBlock

use of net.minecraft.block.FlowingFluidBlock in project Arclight by IzzelAliz.

the class SpongeBlockMixin method absorb.

/**
 * @author IzzelAliz
 * @reason
 */
@SuppressWarnings("unchecked")
@Overwrite
private boolean absorb(World worldIn, BlockPos pos) {
    Queue<Tuple<BlockPos, Integer>> queue = Lists.newLinkedList();
    queue.add(new Tuple<>(pos, 0));
    int i = 0;
    BlockStateListPopulator blockList = new BlockStateListPopulator(worldIn);
    while (!queue.isEmpty()) {
        Tuple<BlockPos, Integer> tuple = queue.poll();
        BlockPos blockpos = tuple.getA();
        int j = tuple.getB();
        for (Direction direction : Direction.values()) {
            BlockPos blockpos1 = blockpos.offset(direction);
            BlockState blockstate = blockList.getBlockState(blockpos1);
            IFluidState ifluidstate = blockList.getFluidState(blockpos1);
            Material material = blockstate.getMaterial();
            if (ifluidstate.isTagged(FluidTags.WATER)) {
                if (blockstate.getBlock() instanceof IBucketPickupHandler && ((IBucketPickupHandler) blockstate.getBlock()).pickupFluid(worldIn, blockpos1, blockstate) != Fluids.EMPTY) {
                    ++i;
                    if (j < 6) {
                        queue.add(new Tuple<>(blockpos1, j + 1));
                    }
                } else if (blockstate.getBlock() instanceof FlowingFluidBlock) {
                    worldIn.setBlockState(blockpos1, Blocks.AIR.getDefaultState(), 3);
                    ++i;
                    if (j < 6) {
                        queue.add(new Tuple<>(blockpos1, j + 1));
                    }
                } else if (material == Material.OCEAN_PLANT || material == Material.SEA_GRASS) {
                    // TileEntity tileentity = blockstate.getBlock().hasTileEntity() ? worldIn.getTileEntity(blockpos1) : null;
                    // Block.spawnDrops(blockstate, worldIn, blockpos1, tileentity);
                    blockList.setBlockState(blockpos1, Blocks.AIR.getDefaultState(), 3);
                    ++i;
                    if (j < 6) {
                        queue.add(new Tuple<>(blockpos1, j + 1));
                    }
                }
            }
        }
        if (i > 64) {
            break;
        }
    }
    // Is a clone
    List<CraftBlockState> blocks = blockList.getList();
    if (!blocks.isEmpty()) {
        final org.bukkit.block.Block bblock = CraftBlock.at(worldIn, pos);
        SpongeAbsorbEvent event = new SpongeAbsorbEvent(bblock, (List<org.bukkit.block.BlockState>) (List) blocks);
        Bukkit.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            return false;
        }
        for (CraftBlockState block : blocks) {
            BlockPos blockposition2 = block.getPosition();
            BlockState iblockdata = worldIn.getBlockState(blockposition2);
            IFluidState fluid = worldIn.getFluidState(blockposition2);
            Material material = iblockdata.getMaterial();
            if (fluid.isTagged(FluidTags.WATER)) {
                if (iblockdata.getBlock() instanceof IBucketPickupHandler && ((IBucketPickupHandler) iblockdata.getBlock()).pickupFluid(blockList, blockposition2, iblockdata) != Fluids.EMPTY) {
                // NOP
                } else if (iblockdata.getBlock() instanceof FlowingFluidBlock) {
                // NOP
                } else if (material == Material.OCEAN_PLANT || material == Material.SEA_GRASS) {
                    TileEntity tileentity = iblockdata.getBlock().hasTileEntity(iblockdata) ? worldIn.getTileEntity(blockposition2) : null;
                    Block.spawnDrops(iblockdata, worldIn, blockposition2, tileentity);
                }
            }
            worldIn.setBlockState(blockposition2, block.getHandle(), block.getFlag());
        }
    }
    return i > 0;
}
Also used : IBucketPickupHandler(net.minecraft.block.IBucketPickupHandler) FlowingFluidBlock(net.minecraft.block.FlowingFluidBlock) SpongeAbsorbEvent(org.bukkit.event.block.SpongeAbsorbEvent) BlockStateListPopulator(org.bukkit.craftbukkit.v.util.BlockStateListPopulator) Material(net.minecraft.block.material.Material) Direction(net.minecraft.util.Direction) TileEntity(net.minecraft.tileentity.TileEntity) CraftBlockState(org.bukkit.craftbukkit.v.block.CraftBlockState) CraftBlockState(org.bukkit.craftbukkit.v.block.CraftBlockState) BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) List(java.util.List) Tuple(net.minecraft.util.Tuple) IFluidState(net.minecraft.fluid.IFluidState) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 2 with FlowingFluidBlock

use of net.minecraft.block.FlowingFluidBlock in project Mekanism by mekanism.

the class ThreadMinerSearch method run.

@Override
public void run() {
    state = State.SEARCHING;
    List<MinerFilter<?>> filters = tile.getFilters();
    if (!tile.getInverse() && filters.isEmpty()) {
        state = State.FINISHED;
        return;
    }
    Map<Block, MinerFilter<?>> acceptedItems = new Object2ObjectOpenHashMap<>();
    BlockPos pos = tile.getStartingPos();
    int diameter = tile.getDiameter();
    int size = tile.getTotalSize();
    Block info;
    BlockPos minerPos = tile.getBlockPos();
    for (int i = 0; i < size; i++) {
        if (tile.isRemoved()) {
            // Make sure the miner is still valid and something hasn't gone wrong
            return;
        }
        BlockPos testPos = pos.offset(i % diameter, i / diameter / diameter, (i / diameter) % diameter);
        if (minerPos.equals(testPos) || WorldUtils.getTileEntity(TileEntityBoundingBlock.class, chunkCache, testPos) != null) {
            // Skip the miner itself, and also skip any bounding blocks
            continue;
        }
        BlockState state = chunkCache.getBlockState(testPos);
        if (state.isAir(chunkCache, testPos) || state.is(MekanismTags.Blocks.MINER_BLACKLIST) || state.getDestroySpeed(chunkCache, testPos) < 0) {
            // Skip air, blacklisted blocks, and unbreakable blocks
            continue;
        }
        info = state.getBlock();
        if (info instanceof FlowingFluidBlock || info instanceof IFluidBlock) {
            // Skip liquids
            continue;
        }
        MinerFilter<?> filterFound = null;
        if (acceptedItems.containsKey(info)) {
            filterFound = acceptedItems.get(info);
        } else {
            if (tile.isReplaceTarget(info.asItem())) {
                continue;
            }
            for (MinerFilter<?> filter : filters) {
                if (filter.canFilter(state)) {
                    filterFound = filter;
                    break;
                }
            }
            acceptedItems.put(info, filterFound);
        }
        if (tile.getInverse() == (filterFound == null)) {
            long chunk = WorldUtils.getChunkPosAsLong(testPos);
            oresToMine.computeIfAbsent(chunk, k -> new BitSet()).set(i);
            found++;
        }
    }
    state = State.FINISHED;
    chunkCache = null;
    tile.updateFromSearch(oresToMine, found);
}
Also used : IHasTextComponent(mekanism.api.text.IHasTextComponent) BlockPos(net.minecraft.util.math.BlockPos) TileEntityDigitalMiner(mekanism.common.tile.machine.TileEntityDigitalMiner) FlowingFluidBlock(net.minecraft.block.FlowingFluidBlock) MathUtils(mekanism.api.math.MathUtils) ITextComponent(net.minecraft.util.text.ITextComponent) List(java.util.List) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) Block(net.minecraft.block.Block) Object2ObjectOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap) TileEntityBoundingBlock(mekanism.common.tile.TileEntityBoundingBlock) WorldUtils(mekanism.common.util.WorldUtils) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) Map(java.util.Map) Region(net.minecraft.world.Region) MekanismLang(mekanism.common.MekanismLang) MekanismTags(mekanism.common.tags.MekanismTags) Long2ObjectMap(it.unimi.dsi.fastutil.longs.Long2ObjectMap) BitSet(java.util.BitSet) ILangEntry(mekanism.api.text.ILangEntry) BlockState(net.minecraft.block.BlockState) FlowingFluidBlock(net.minecraft.block.FlowingFluidBlock) BitSet(java.util.BitSet) Object2ObjectOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap) BlockState(net.minecraft.block.BlockState) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) FlowingFluidBlock(net.minecraft.block.FlowingFluidBlock) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) Block(net.minecraft.block.Block) TileEntityBoundingBlock(mekanism.common.tile.TileEntityBoundingBlock) BlockPos(net.minecraft.util.math.BlockPos)

Example 3 with FlowingFluidBlock

use of net.minecraft.block.FlowingFluidBlock in project MCMOD-Industria by M-Marvin.

the class ServerSetup method setup.

@SubscribeEvent
@SuppressWarnings("deprecation")
public static void setup(final FMLCommonSetupEvent event) {
    // Dispenser Behaviors
    IDispenseItemBehavior placeBlockBehavior = new IDispenseItemBehavior() {

        @Override
        public ItemStack dispense(IBlockSource source, ItemStack stack) {
            BlockPos pos = source.getPos().relative(source.getBlockState().getValue(BlockStateProperties.FACING));
            Block block = Block.byItem(stack.getItem());
            if (block != null && (source.getLevel().getBlockState(pos).isAir() || source.getLevel().getBlockState(pos).getBlock() instanceof FlowingFluidBlock) && block.canSurvive(block.defaultBlockState(), source.getLevel(), pos)) {
                source.getLevel().setBlockAndUpdate(pos, block.defaultBlockState());
                stack.shrink(1);
                return stack;
            }
            return stack;
        }
    };
    Registry.BLOCK.stream().forEach((block) -> {
        Item item = Item.byBlock(block);
        if (item != null) {
            if (item != Items.TNT)
                DispenserBlock.registerBehavior(item, placeBlockBehavior);
        }
    });
// Vanilla FireInfo Overrides
// MethodHelper.addFireSetting(Blocks.ACACIA_DOOR, 5, 20);
// MethodHelper.addFireSetting(Blocks.OAK_DOOR, 5, 20);
// MethodHelper.addFireSetting(Blocks.BIRCH_DOOR, 5, 20);
// MethodHelper.addFireSetting(Blocks.DARK_OAK_DOOR, 5, 20);
// MethodHelper.addFireSetting(Blocks.SPRUCE_DOOR, 5, 20);
// MethodHelper.addFireSetting(Blocks.CHEST, 5, 20);
// MethodHelper.addFireSetting(Blocks.TRAPPED_CHEST, 5, 20);
// MethodHelper.addFireSetting(Blocks.OAK_TRAPDOOR, 5, 20);
// MethodHelper.addFireSetting(Blocks.BIRCH_TRAPDOOR, 5, 20);
// MethodHelper.addFireSetting(Blocks.ACACIA_TRAPDOOR, 5, 20);
// MethodHelper.addFireSetting(Blocks.DARK_OAK_TRAPDOOR, 5, 20);
// MethodHelper.addFireSetting(Blocks.SPRUCE_TRAPDOOR, 5, 20);
// MethodHelper.addFireSetting(Blocks.OAK_SIGN, 10, 30);
// MethodHelper.addFireSetting(Blocks.BIRCH_SIGN, 10, 30);
// MethodHelper.addFireSetting(Blocks.ACACIA_SIGN, 10, 30);
// MethodHelper.addFireSetting(Blocks.DARK_OAK_SIGN, 10, 30);
// MethodHelper.addFireSetting(Blocks.SPRUCE_SIGN, 10, 30);
// MethodHelper.addFireSetting(Blocks.OAK_PRESSURE_PLATE, 10, 30);
// MethodHelper.addFireSetting(Blocks.BIRCH_PRESSURE_PLATE, 10, 30);
// MethodHelper.addFireSetting(Blocks.ACACIA_PRESSURE_PLATE, 10, 30);
// MethodHelper.addFireSetting(Blocks.DARK_OAK_PRESSURE_PLATE, 10, 30);
// MethodHelper.addFireSetting(Blocks.SPRUCE_PRESSURE_PLATE, 10, 30);
}
Also used : Item(net.minecraft.item.Item) FlowingFluidBlock(net.minecraft.block.FlowingFluidBlock) IBlockSource(net.minecraft.dispenser.IBlockSource) IDispenseItemBehavior(net.minecraft.dispenser.IDispenseItemBehavior) Block(net.minecraft.block.Block) FlowingFluidBlock(net.minecraft.block.FlowingFluidBlock) DispenserBlock(net.minecraft.block.DispenserBlock) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 4 with FlowingFluidBlock

use of net.minecraft.block.FlowingFluidBlock in project MCMOD-Industria by M-Marvin.

the class FluidHydrofluoricAcid method randomTick.

@SuppressWarnings("deprecation")
@Override
protected void randomTick(World world, BlockPos pos, FluidState state, Random random) {
    for (Direction d : Direction.values()) {
        BlockState state1 = world.getBlockState(pos.relative(d));
        int resistance = (int) state1.getExplosionResistance(world, pos.relative(d), null);
        resistance = Math.max(1, resistance);
        if (random.nextInt(resistance * 2) == 0) {
            if (resistance < 50 && !state1.isAir() && !(state1.getBlock() instanceof FlowingFluidBlock) && !state1.is(ModTags.ACID_RESISTANT)) {
                world.setBlockAndUpdate(pos.relative(d), d == Direction.DOWN ? ModFluids.FLOWING_HYDROFLUORIC_ACID.defaultFluidState().createLegacyBlock() : Blocks.AIR.defaultBlockState());
                world.playSound(null, pos.relative(d), SoundEvents.FIRE_EXTINGUISH, SoundCategory.BLOCKS, 1, 1);
            }
        }
    }
}
Also used : BlockState(net.minecraft.block.BlockState) FlowingFluidBlock(net.minecraft.block.FlowingFluidBlock) Direction(net.minecraft.util.Direction)

Example 5 with FlowingFluidBlock

use of net.minecraft.block.FlowingFluidBlock in project MCMOD-Industria by M-Marvin.

the class FluidNatronLye method randomTick.

@SuppressWarnings("deprecation")
@Override
protected void randomTick(World world, BlockPos pos, FluidState state, Random random) {
    for (Direction d : Direction.values()) {
        BlockState state1 = world.getBlockState(pos.relative(d));
        int resistance = (int) state1.getExplosionResistance(world, pos.relative(d), null);
        resistance = Math.max(1, resistance);
        if (random.nextInt(resistance * 4) == 0 && resistance <= 1.5F) {
            if (resistance < 35 && !state1.isAir() && !(state1.getBlock() instanceof FlowingFluidBlock) && !state1.is(ModTags.ACID_RESISTANT)) {
                world.setBlockAndUpdate(pos.relative(d), d == Direction.DOWN ? ModFluids.FLOWING_NATRON_LYE.defaultFluidState().createLegacyBlock() : Blocks.AIR.defaultBlockState());
                world.playSound(null, pos.relative(d), SoundEvents.FIRE_EXTINGUISH, SoundCategory.BLOCKS, 1, 1);
            }
        }
    }
}
Also used : BlockState(net.minecraft.block.BlockState) FlowingFluidBlock(net.minecraft.block.FlowingFluidBlock) Direction(net.minecraft.util.Direction)

Aggregations

FlowingFluidBlock (net.minecraft.block.FlowingFluidBlock)15 BlockState (net.minecraft.block.BlockState)10 Block (net.minecraft.block.Block)7 BlockPos (net.minecraft.util.math.BlockPos)7 Direction (net.minecraft.util.Direction)6 Material (net.minecraft.block.material.Material)4 GsonBuilder (com.google.gson.GsonBuilder)3 LiteralArgumentBuilder (com.mojang.brigadier.builder.LiteralArgumentBuilder)3 RequiredArgumentBuilder (com.mojang.brigadier.builder.RequiredArgumentBuilder)3 List (java.util.List)3 IBucketPickupHandler (net.minecraft.block.IBucketPickupHandler)3 ItemStack (net.minecraft.item.ItemStack)3 TileEntity (net.minecraft.tileentity.TileEntity)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 FluidState (net.minecraft.fluid.FluidState)2 Item (net.minecraft.item.Item)2 IProperty (net.minecraft.state.IProperty)2 BlockRayTraceResult (net.minecraft.util.math.BlockRayTraceResult)2 ServerWorld (net.minecraft.world.server.ServerWorld)2 DynmapBlockState (org.dynmap.renderer.DynmapBlockState)2