Search in sources :

Example 6 with FlowingFluidBlock

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

the class TileEntityMHeaterBase method tick.

@SuppressWarnings("deprecation")
@Override
public void tick() {
    if (!this.level.isClientSide()) {
        this.isWorking = false;
        Direction facing = getBlockState().getValue(BlockStateProperties.HORIZONTAL_FACING);
        powered = this.level.hasNeighborSignal(worldPosition) || this.level.hasNeighborSignal(worldPosition.offset(facing.getOpposite().getNormal())) || this.level.hasNeighborSignal(worldPosition.offset(facing.getClockWise().getNormal())) || this.level.hasNeighborSignal(worldPosition.offset(facing.getClockWise().getNormal()).offset(facing.getOpposite().getNormal()));
        if (powered) {
            updateWorkState();
            if (isWorking ? this.level.getGameTime() % 10 == 0 : false) {
                int xMin = Math.min(this.worldPosition.offset(facing.getOpposite().getNormal()).getX(), this.worldPosition.getX()) - 2;
                int xMax = Math.max(this.worldPosition.offset(facing.getOpposite().getNormal()).getX(), this.worldPosition.getX()) + 2;
                int zMin = Math.min(this.worldPosition.offset(facing.getClockWise().getNormal()).getZ(), this.worldPosition.getZ()) - 2;
                int zMax = Math.max(this.worldPosition.offset(facing.getClockWise().getNormal()).getZ(), this.worldPosition.getZ()) + 2;
                for (int y = 1; y <= 6; y++) {
                    for (int x = xMin; x <= xMax; x++) {
                        for (int z = zMin; z <= zMax; z++) {
                            if (this.level.random.nextInt(6) == 0) {
                                BlockPos pos2 = new BlockPos(x, this.getBlockPos().getY() + y, z);
                                FluidState sourceFluid = this.level.getFluidState(pos2);
                                if (this.level.getBlockState(pos2).getBlock() instanceof FlowingFluidBlock) {
                                    if (sourceFluid.getType() == Fluids.WATER) {
                                        if (this.level.random.nextInt(5) == 0) {
                                            BlockState bottomState = this.level.getBlockState(pos2.below());
                                            if (bottomState.getBlock() == ModItems.limestone_sheet) {
                                                this.level.setBlockAndUpdate(pos2, ModItems.limestone_sheet.defaultBlockState().setValue(BlockStateProperties.WATERLOGGED, true));
                                                this.level.setBlockAndUpdate(pos2.below(), ModItems.limestone.defaultBlockState());
                                            } else if (bottomState.getFluidState().getType() == Fluids.EMPTY && !bottomState.isAir()) {
                                                this.level.setBlockAndUpdate(pos2, ModItems.limestone_sheet.defaultBlockState().setValue(BlockStateProperties.WATERLOGGED, true));
                                            }
                                        } else {
                                            this.level.setBlockAndUpdate(pos2, ModFluids.STEAM.getPreasurized().createLegacyBlock());
                                        }
                                    } else if (sourceFluid.getType() == ModFluids.DESTILLED_WATER) {
                                        if (sourceFluid.getValue(FluidDestilledWater.HOT)) {
                                            this.level.setBlockAndUpdate(pos2, ModFluids.STEAM.getPreasurized().createLegacyBlock());
                                        } else {
                                            this.level.setBlockAndUpdate(pos2, ModFluids.DESTILLED_WATER.getHot().createLegacyBlock());
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    } else {
        MachineSoundHelper.startSoundIfNotRunning(this, ModSoundEvents.GENERATOR_LOOP);
        if (this.isWorking) {
            IParticleData paricle = ParticleTypes.FLAME;
            Direction facing = getBlockState().getValue(BlockMultipart.FACING);
            float ox = 0;
            float oz = 0;
            switch(facing) {
                default:
                case NORTH:
                    oz = 1F;
                    ox = 1F;
                    break;
                case EAST:
                    ox = 0F;
                    oz = 1F;
                    break;
                case SOUTH:
                    ox = 0F;
                    oz = 0F;
                    break;
                case WEST:
                    ox = 1F;
                    oz = 0F;
                    break;
            }
            ;
            float width = 0.9F;
            float x = this.worldPosition.getX() + ox + (level.random.nextFloat() - 0.5F) * width;
            float y = this.worldPosition.getY() + 1.1F;
            float z = this.worldPosition.getZ() + oz + (level.random.nextFloat() - 0.5F) * width;
            this.level.addParticle(paricle, x, y, z, 0, 0, 0);
        }
    }
}
Also used : BlockState(net.minecraft.block.BlockState) FlowingFluidBlock(net.minecraft.block.FlowingFluidBlock) IParticleData(net.minecraft.particles.IParticleData) BlockPos(net.minecraft.util.math.BlockPos) Direction(net.minecraft.util.Direction) FluidState(net.minecraft.fluid.FluidState)

Example 7 with FlowingFluidBlock

use of net.minecraft.block.FlowingFluidBlock in project dynmap by webbukkit.

the class DynmapExpCommand method initializeBlockStates.

/**
 * Initialize block states (org.dynmap.blockstate.DynmapBlockState)
 */
public void initializeBlockStates() {
    // Simple map - scale as needed
    stateByID = new DynmapBlockState[512 * 32];
    // Default to air
    Arrays.fill(stateByID, DynmapBlockState.AIR);
    ObjectIntIdentityMap<BlockState> bsids = Block.BLOCK_STATE_IDS;
    DynmapBlockState basebs = null;
    Block baseb = null;
    int baseidx = 0;
    Iterator<BlockState> iter = bsids.iterator();
    DynmapBlockState.Builder bld = new DynmapBlockState.Builder();
    while (iter.hasNext()) {
        BlockState bs = iter.next();
        int idx = bsids.get(bs);
        if (idx >= stateByID.length) {
            int plen = stateByID.length;
            // grow array by 10%
            stateByID = Arrays.copyOf(stateByID, idx * 11 / 10);
            Arrays.fill(stateByID, plen, stateByID.length, DynmapBlockState.AIR);
        }
        Block b = bs.getBlock();
        // If this is new block vs last, it's the base block state
        if (b != baseb) {
            basebs = null;
            baseidx = idx;
            baseb = b;
        }
        ResourceLocation ui = b.getRegistryName();
        if (ui == null) {
            continue;
        }
        String bn = ui.getNamespace() + ":" + ui.getPath();
        // Only do defined names, and not "air"
        if (!bn.equals(DynmapBlockState.AIR_BLOCK)) {
            Material mat = bs.getMaterial();
            String statename = "";
            for (IProperty p : bs.getProperties()) {
                if (statename.length() > 0) {
                    statename += ",";
                }
                statename += p.getName() + "=" + bs.get(p).toString();
            }
            int lightAtten = bs.isOpaqueCube(EmptyBlockReader.INSTANCE, BlockPos.ZERO) ? 15 : (bs.propagatesSkylightDown(EmptyBlockReader.INSTANCE, BlockPos.ZERO) ? 0 : 1);
            // Log.info("statename=" + bn + "[" + statename + "], lightAtten=" + lightAtten);
            // Fill in base attributes
            bld.setBaseState(basebs).setStateIndex(idx - baseidx).setBlockName(bn).setStateName(statename).setMaterial(mat.toString()).setLegacyBlockID(idx).setAttenuatesLight(lightAtten);
            if (mat.isSolid()) {
                bld.setSolid();
            }
            if (mat == Material.AIR) {
                bld.setAir();
            }
            if (mat == Material.WOOD) {
                bld.setLog();
            }
            if (mat == Material.LEAVES) {
                bld.setLeaves();
            }
            if ((!bs.getFluidState().isEmpty()) && !(bs.getBlock() instanceof FlowingFluidBlock)) {
                bld.setWaterlogged();
            }
            // Build state
            DynmapBlockState dbs = bld.build();
            stateByID[idx] = dbs;
            if (basebs == null) {
                basebs = dbs;
            }
        }
    }
    for (int gidx = 0; gidx < DynmapBlockState.getGlobalIndexMax(); gidx++) {
        DynmapBlockState bs = DynmapBlockState.getStateByGlobalIndex(gidx);
    // Log.info(gidx + ":" + bs.toString() + ", gidx=" + bs.globalStateIndex + ", sidx=" + bs.stateIndex);
    }
}
Also used : FlowingFluidBlock(net.minecraft.block.FlowingFluidBlock) DynmapBlockState(org.dynmap.renderer.DynmapBlockState) GsonBuilder(com.google.gson.GsonBuilder) RequiredArgumentBuilder(com.mojang.brigadier.builder.RequiredArgumentBuilder) LiteralArgumentBuilder(com.mojang.brigadier.builder.LiteralArgumentBuilder) Material(net.minecraft.block.material.Material) BlockState(net.minecraft.block.BlockState) DynmapBlockState(org.dynmap.renderer.DynmapBlockState) IProperty(net.minecraft.state.IProperty) ResourceLocation(net.minecraft.util.ResourceLocation) Block(net.minecraft.block.Block) FlowingFluidBlock(net.minecraft.block.FlowingFluidBlock)

Example 8 with FlowingFluidBlock

use of net.minecraft.block.FlowingFluidBlock in project Enigmatic-Legacy by Aizistral-Studios.

the class Megasponge method absorbWaterBlock.

public static void absorbWaterBlock(BlockPos pos, BlockState state, World world) {
    if (state.getBlock() instanceof IBucketPickupHandler && ((IBucketPickupHandler) state.getBlock()).pickupFluid(world, pos, state) != Fluids.EMPTY) {
    // Whatever
    } else if (state.getBlock() instanceof FlowingFluidBlock) {
        world.setBlockState(pos, Blocks.AIR.getDefaultState(), 3);
    } else if (state.getMaterial() == Material.OCEAN_PLANT || state.getMaterial() == Material.SEA_GRASS) {
        TileEntity tileentity = state.hasTileEntity() ? world.getTileEntity(pos) : null;
        Block.spawnDrops(state, world, pos, tileentity);
        world.setBlockState(pos, Blocks.AIR.getDefaultState(), 3);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBucketPickupHandler(net.minecraft.block.IBucketPickupHandler) FlowingFluidBlock(net.minecraft.block.FlowingFluidBlock)

Example 9 with FlowingFluidBlock

use of net.minecraft.block.FlowingFluidBlock in project FrostedHeart by TeamMoegMC.

the class BiomeMixin method doesWaterFreeze.

public boolean doesWaterFreeze(IWorldReader worldIn, BlockPos water, boolean mustBeAtEdge) {
    if (this.getTemperature(water) >= 0.15F) {
        return false;
    }
    if (water.getY() >= 0 && water.getY() < 256 && worldIn.getLightFor(LightType.BLOCK, water) < 10 && ChunkData.getTemperature(worldIn, water) < 0) {
        BlockState blockstate = worldIn.getBlockState(water);
        FluidState fluidstate = worldIn.getFluidState(water);
        if (fluidstate.getFluid() == Fluids.WATER && blockstate.getBlock() instanceof FlowingFluidBlock) {
            if (!mustBeAtEdge) {
                return true;
            }
            boolean flag = worldIn.hasWater(water.west()) && worldIn.hasWater(water.east()) && worldIn.hasWater(water.north()) && worldIn.hasWater(water.south());
            if (!flag) {
                return true;
            }
        }
    }
    return false;
}
Also used : BlockState(net.minecraft.block.BlockState) FlowingFluidBlock(net.minecraft.block.FlowingFluidBlock) FluidState(net.minecraft.fluid.FluidState)

Example 10 with FlowingFluidBlock

use of net.minecraft.block.FlowingFluidBlock in project endergetic by team-abnormals.

the class PuffBugBottleItem method use.

@Override
public ActionResult<ItemStack> use(World worldIn, PlayerEntity playerIn, Hand handIn) {
    ItemStack itemstack = playerIn.getItemInHand(handIn);
    if (worldIn.isClientSide) {
        return new ActionResult<>(ActionResultType.PASS, itemstack);
    } else {
        RayTraceResult raytraceresult = getPlayerPOVHitResult(worldIn, playerIn, RayTraceContext.FluidMode.SOURCE_ONLY);
        if (raytraceresult.getType() != RayTraceResult.Type.BLOCK) {
            return new ActionResult<>(ActionResultType.PASS, itemstack);
        } else {
            BlockRayTraceResult blockraytraceresult = (BlockRayTraceResult) raytraceresult;
            BlockPos blockpos = blockraytraceresult.getBlockPos();
            if (!(worldIn.getBlockState(blockpos).getBlock() instanceof FlowingFluidBlock)) {
                return new ActionResult<>(ActionResultType.PASS, itemstack);
            } else if (worldIn.mayInteract(playerIn, blockpos) && playerIn.mayUseItemAt(blockpos, blockraytraceresult.getDirection(), itemstack)) {
                EntityType<?> entitytype = EEEntities.PUFF_BUG.get();
                if (entitytype.spawn((ServerWorld) worldIn, itemstack, playerIn, blockpos, SpawnReason.SPAWN_EGG, false, false) == null) {
                    return new ActionResult<>(ActionResultType.PASS, itemstack);
                } else {
                    if (!playerIn.abilities.instabuild) {
                        this.emptyBottle(playerIn, handIn);
                    }
                    playerIn.awardStat(Stats.ITEM_USED.get(this));
                    return new ActionResult<>(ActionResultType.SUCCESS, itemstack);
                }
            } else {
                return new ActionResult<>(ActionResultType.FAIL, itemstack);
            }
        }
    }
}
Also used : EntityType(net.minecraft.entity.EntityType) ActionResult(net.minecraft.util.ActionResult) FlowingFluidBlock(net.minecraft.block.FlowingFluidBlock) RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) BlockPos(net.minecraft.util.math.BlockPos) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) ItemStack(net.minecraft.item.ItemStack)

Aggregations

FlowingFluidBlock (net.minecraft.block.FlowingFluidBlock)17 BlockState (net.minecraft.block.BlockState)11 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 FluidState (net.minecraft.fluid.FluidState)3 ItemStack (net.minecraft.item.ItemStack)3 TileEntity (net.minecraft.tileentity.TileEntity)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 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