Search in sources :

Example 11 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.getId(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 (net.minecraft.state.Property<?> p : bs.getProperties()) {
                if (statename.length() > 0) {
                    statename += ",";
                }
                statename += p.getName() + "=" + bs.get(p).toString();
            }
            int lightAtten = 15;
            try {
                // Workaround for mods with broken block state logic...
                lightAtten = bs.isOpaqueCube(EmptyBlockReader.INSTANCE, BlockPos.ZERO) ? 15 : (bs.propagatesSkylightDown(EmptyBlockReader.INSTANCE, BlockPos.ZERO) ? 0 : 1);
            } catch (Exception x) {
                Log.warning(String.format("Exception while checking lighting data for block state: %s[%s]", bn, statename));
                Log.verboseinfo("Exception: " + x.toString());
            }
            // 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) CommandException(net.minecraft.command.CommandException) CancellationException(java.util.concurrent.CancellationException) ExecutionException(java.util.concurrent.ExecutionException) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) JsonParseException(com.google.gson.JsonParseException) BlockState(net.minecraft.block.BlockState) DynmapBlockState(org.dynmap.renderer.DynmapBlockState) ResourceLocation(net.minecraft.util.ResourceLocation) Block(net.minecraft.block.Block) FlowingFluidBlock(net.minecraft.block.FlowingFluidBlock)

Example 12 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 13 with FlowingFluidBlock

use of net.minecraft.block.FlowingFluidBlock in project Spackenmobs by ACGaming.

the class CustomSpawnEggItem method use.

public ActionResult<ItemStack> use(World worldIn, PlayerEntity playerIn, Hand handIn) {
    ItemStack itemstack = playerIn.getItemInHand(handIn);
    BlockRayTraceResult raytraceresult = getPlayerPOVHitResult(worldIn, playerIn, RayTraceContext.FluidMode.SOURCE_ONLY);
    if (raytraceresult.getType() != RayTraceResult.Type.BLOCK) {
        return ActionResult.pass(itemstack);
    } else if (worldIn.isClientSide) {
        return ActionResult.success(itemstack);
    } else {
        BlockPos blockpos = raytraceresult.getBlockPos();
        if (!(worldIn.getBlockState(blockpos).getBlock() instanceof FlowingFluidBlock)) {
            return ActionResult.pass(itemstack);
        } else if (worldIn.mayInteract(playerIn, blockpos) && playerIn.mayUseItemAt(blockpos, raytraceresult.getDirection(), itemstack)) {
            EntityType<?> entitytype = this.getType(itemstack.getTag());
            if (entitytype.spawn((ServerWorld) worldIn, itemstack, playerIn, blockpos, SpawnReason.SPAWN_EGG, false, false) == null) {
                return ActionResult.pass(itemstack);
            } else {
                if (!playerIn.abilities.instabuild) {
                    itemstack.shrink(1);
                }
                playerIn.awardStat(Stats.ITEM_USED.get(this));
                return ActionResult.success(itemstack);
            }
        } else {
            return ActionResult.fail(itemstack);
        }
    }
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) FlowingFluidBlock(net.minecraft.block.FlowingFluidBlock) BlockPos(net.minecraft.util.math.BlockPos) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) ItemStack(net.minecraft.item.ItemStack)

Example 14 with FlowingFluidBlock

use of net.minecraft.block.FlowingFluidBlock in project AntimatterAPI by GregTech-Intergalactical.

the class AntimatterFluid method onRegistryBuild.

@Override
public void onRegistryBuild(IForgeRegistry<?> registry) {
    if (registry == ForgeRegistries.ITEMS) {
        AntimatterAPI.register(Item.class, getId() + "_bucket", containerItem = new BucketItem(this::getFluid, new Item.Properties().maxStackSize(1).containerItem(Items.BUCKET).group(ItemGroup.MISC)).setRegistryName(domain, getId() + "_bucket"));
    } else if (registry == ForgeRegistries.BLOCKS) {
        this.fluidBlock = new FlowingFluidBlock(this::getFluid, blockProperties);
        this.fluidBlock.setRegistryName(domain, "block_fluid_".concat(getId()));
        AntimatterAPI.register(Block.class, "block_fluid_".concat(getId()), fluidBlock);
    } else if (registry == ForgeRegistries.FLUIDS) {
        this.source = new Source(this.fluidProperties);
        this.flowing = new Flowing(this.fluidProperties);
        this.source.setRegistryName(domain, getId());
        this.flowing.setRegistryName(domain, "flowing_".concat(getId()));
    }
}
Also used : BucketItem(net.minecraft.item.BucketItem) Item(net.minecraft.item.Item) FlowingFluidBlock(net.minecraft.block.FlowingFluidBlock) BucketItem(net.minecraft.item.BucketItem) FlowingFluidBlock(net.minecraft.block.FlowingFluidBlock) Block(net.minecraft.block.Block)

Example 15 with FlowingFluidBlock

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

the class FluidSulfuricAcid 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 < 35 && !state1.isAir() && !(state1.getBlock() instanceof FlowingFluidBlock) && !state1.is(BlockTags.BASE_STONE_NETHER) && !state1.is(BlockTags.NYLIUM) && !state1.is(ModItems.sulfur_crust_block) && !state1.is(ModTags.ACID_RESISTANT)) {
                world.setBlockAndUpdate(pos.relative(d), d == Direction.DOWN ? ModFluids.FLOWING_SULFURIC_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)

Aggregations

FlowingFluidBlock (net.minecraft.block.FlowingFluidBlock)18 BlockState (net.minecraft.block.BlockState)11 BlockPos (net.minecraft.util.math.BlockPos)8 Block (net.minecraft.block.Block)7 Direction (net.minecraft.util.Direction)6 Material (net.minecraft.block.material.Material)4 ItemStack (net.minecraft.item.ItemStack)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 TileEntity (net.minecraft.tileentity.TileEntity)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 BlockRayTraceResult (net.minecraft.util.math.BlockRayTraceResult)3 ServerWorld (net.minecraft.world.server.ServerWorld)3 Item (net.minecraft.item.Item)2 IProperty (net.minecraft.state.IProperty)2 RayTraceResult (net.minecraft.util.math.RayTraceResult)2