Search in sources :

Example 1 with IProperty

use of net.minecraft.state.IProperty 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 2 with IProperty

use of net.minecraft.state.IProperty in project FastAsyncWorldEdit by IntellectualSites.

the class ForgeAdapter method applyProperties.

private static net.minecraft.block.BlockState applyProperties(StateContainer<Block, net.minecraft.block.BlockState> stateContainer, net.minecraft.block.BlockState newState, Map<Property<?>, Object> states) {
    for (Map.Entry<Property<?>, Object> state : states.entrySet()) {
        IProperty property = stateContainer.getProperty(state.getKey().getName());
        Comparable value = (Comparable) state.getValue();
        // we may need to adapt this value, depending on the source prop
        if (property instanceof DirectionProperty) {
            Direction dir = (Direction) value;
            value = adapt(dir);
        } else if (property instanceof net.minecraft.state.EnumProperty) {
            String enumName = (String) value;
            value = ((net.minecraft.state.EnumProperty<?>) property).parseValue((String) value).orElseGet(() -> {
                throw new IllegalStateException("Enum property " + property.getName() + " does not contain " + enumName);
            });
        }
        newState = newState.with(property, value);
    }
    return newState;
}
Also used : Direction(com.sk89q.worldedit.util.Direction) IProperty(net.minecraft.state.IProperty) DirectionProperty(net.minecraft.state.DirectionProperty) Map(java.util.Map) TreeMap(java.util.TreeMap) Property(com.sk89q.worldedit.registry.state.Property) DirectionalProperty(com.sk89q.worldedit.registry.state.DirectionalProperty) BooleanProperty(com.sk89q.worldedit.registry.state.BooleanProperty) IProperty(net.minecraft.state.IProperty) EnumProperty(com.sk89q.worldedit.registry.state.EnumProperty) IntegerProperty(com.sk89q.worldedit.registry.state.IntegerProperty) DirectionProperty(net.minecraft.state.DirectionProperty)

Example 3 with IProperty

use of net.minecraft.state.IProperty in project FastAsyncWorldEdit by IntellectualSites.

the class ForgeBlockRegistry method getProperties.

@Override
public Map<String, ? extends Property<?>> getProperties(BlockType blockType) {
    Block block = ForgeAdapter.adapt(blockType);
    Map<String, Property<?>> map = new TreeMap<>();
    Collection<IProperty<?>> propertyKeys = block.getDefaultState().getProperties();
    for (IProperty<?> key : propertyKeys) {
        map.put(key.getName(), ForgeAdapter.adaptProperty(key));
    }
    return map;
}
Also used : IProperty(net.minecraft.state.IProperty) Block(net.minecraft.block.Block) TreeMap(java.util.TreeMap) Property(com.sk89q.worldedit.registry.state.Property) IProperty(net.minecraft.state.IProperty)

Example 4 with IProperty

use of net.minecraft.state.IProperty 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)

Aggregations

IProperty (net.minecraft.state.IProperty)4 Block (net.minecraft.block.Block)3 GsonBuilder (com.google.gson.GsonBuilder)2 LiteralArgumentBuilder (com.mojang.brigadier.builder.LiteralArgumentBuilder)2 RequiredArgumentBuilder (com.mojang.brigadier.builder.RequiredArgumentBuilder)2 Property (com.sk89q.worldedit.registry.state.Property)2 TreeMap (java.util.TreeMap)2 BlockState (net.minecraft.block.BlockState)2 FlowingFluidBlock (net.minecraft.block.FlowingFluidBlock)2 Material (net.minecraft.block.material.Material)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 DynmapBlockState (org.dynmap.renderer.DynmapBlockState)2 BooleanProperty (com.sk89q.worldedit.registry.state.BooleanProperty)1 DirectionalProperty (com.sk89q.worldedit.registry.state.DirectionalProperty)1 EnumProperty (com.sk89q.worldedit.registry.state.EnumProperty)1 IntegerProperty (com.sk89q.worldedit.registry.state.IntegerProperty)1 Direction (com.sk89q.worldedit.util.Direction)1 Map (java.util.Map)1 DirectionProperty (net.minecraft.state.DirectionProperty)1