Java源码示例:org.spongepowered.api.data.property.block.MatterProperty

示例1
@Listener(order = Order.FIRST, beforeModifications = true)
public void onFlow(ChangeBlockEvent.Pre e, @First LocatableBlock locatable) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "Is BlockListener - onFlow event");

    BlockState sourceState = locatable.getBlockState();

    //liquid check
    MatterProperty mat = sourceState.getProperty(MatterProperty.class).orElse(null);
    if (mat != null && mat.getValue() == MatterProperty.Matter.LIQUID) {
        e.getLocations().forEach(loc -> {
            Region r = RedProtect.get().rm.getTopRegion(loc, this.getClass().getName());
            if (r == null) {
                boolean flow = RedProtect.get().config.globalFlagsRoot().worlds.get(locatable.getLocation().getExtent().getName()).allow_changes_of.liquid_flow;
                boolean allowWater = RedProtect.get().config.globalFlagsRoot().worlds.get(locatable.getLocation().getExtent().getName()).allow_changes_of.water_flow;
                boolean allowLava = RedProtect.get().config.globalFlagsRoot().worlds.get(locatable.getLocation().getExtent().getName()).allow_changes_of.lava_flow;

                if (!flow)
                    e.setCancelled(true);
                if (!allowWater && (loc.getBlockType() == BlockTypes.WATER || loc.getBlockType() == BlockTypes.FLOWING_WATER))
                    e.setCancelled(true);
                if (!allowLava && (loc.getBlockType() == BlockTypes.LAVA || loc.getBlockType() == BlockTypes.FLOWING_LAVA))
                    e.setCancelled(true);
            }
        });
    }
}
 
示例2
@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockBreakGeneric(ChangeBlockEvent.Break e) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "GlobalListener - Is onBlockBreakGeneric event");

    LocatableBlock locatable = e.getCause().first(LocatableBlock.class).orElse(null);
    if (locatable != null) {
        BlockState sourceState = locatable.getBlockState();

        //liquid check
        MatterProperty mat = sourceState.getProperty(MatterProperty.class).orElse(null);
        if (mat != null && mat.getValue() == MatterProperty.Matter.LIQUID) {
            boolean allowdamage = RedProtect.get().config.globalFlagsRoot().worlds.get(locatable.getLocation().getExtent().getName()).allow_changes_of.flow_damage;

            Region r = RedProtect.get().rm.getTopRegion(locatable.getLocation(), this.getClass().getName());
            if (r == null && !allowdamage && locatable.getLocation().getBlockType() != BlockTypes.AIR) {
                e.setCancelled(true);
            }
        }
    }
}
 
示例3
@Listener(order = Order.FIRST, beforeModifications = true)
public void onFlow(ChangeBlockEvent.Pre e, @First LocatableBlock locatable) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "Is BlockListener - onFlow event");

    BlockState sourceState = locatable.getBlockState();

    //liquid check
    MatterProperty mat = sourceState.getProperty(MatterProperty.class).orElse(null);
    if (mat != null && mat.getValue() == MatterProperty.Matter.LIQUID) {
        e.getLocations().forEach(loc -> {
            Region r = RedProtect.get().rm.getTopRegion(loc, this.getClass().getName());
            if (r != null && !r.canFlow()) {
                e.setCancelled(true);
            }
        });
    }
}
 
示例4
/**
 * Get a list of all LIQUID block types.
 *
 * @return List<BlockType>
 */
public static List<BlockType> getLiquidBlockTypes() {
    List<BlockType> liquids = new ArrayList<>();

    Collection<BlockType> types = Sponge.getRegistry().getAllOf(BlockType.class);
    for (BlockType type : types) {
        Optional<MatterProperty> property = type.getProperty(MatterProperty.class);
        if (property.isPresent() && Objects.equals(property.get().getValue(), Matter.LIQUID)) {
            liquids.add(type);
        }
    }

    // @todo Sponge has not yet implemented the MatterProperties...
    liquids.add(BlockTypes.LAVA);
    liquids.add(BlockTypes.FLOWING_LAVA);
    liquids.add(BlockTypes.WATER);
    liquids.add(BlockTypes.FLOWING_WATER);

    return liquids;
}
 
示例5
private static boolean isTransparent(BlockState blockstate, boolean waterIsTransparent) {
    if (blockstate.getType() == BlockTypes.SNOW_LAYER) {
        return false;
    }

    IBlockState iblockstate = (IBlockState)(Object) blockstate;
    Optional<MatterProperty> matterProperty = blockstate.getProperty(MatterProperty.class);
    if (!waterIsTransparent && matterProperty.isPresent() && matterProperty.get().getValue() == MatterProperty.Matter.LIQUID) {
        return false;
    }
    return !iblockstate.isOpaqueCube();
}
 
示例6
private void addClaimElements(int height, Location<World> locality, GPPlayerData playerData) {
    this.initBlockVisualTypes(type);
    Location<World> lesser = this.claim.getLesserBoundaryCorner();
    Location<World> greater = this.claim.getGreaterBoundaryCorner();
    World world = lesser.getExtent();
    boolean liquidTransparent = locality.getBlock().getType().getProperty(MatterProperty.class).isPresent() ? false : true;

    this.smallx = lesser.getBlockX();
    this.smally = this.useCuboidVisual() ? lesser.getBlockY() : 0;
    this.smallz = lesser.getBlockZ();
    this.bigx = greater.getBlockX();
    this.bigy = this.useCuboidVisual() ? greater.getBlockY() : 0;
    this.bigz = greater.getBlockZ();
    this.minx = this.claim.cuboid ? this.smallx : locality.getBlockX() - 75;
    this.minz = this.claim.cuboid ? this.smallz : locality.getBlockZ() - 75;
    this.maxx = this.claim.cuboid ? this.bigx : locality.getBlockX() + 75;
    this.maxz = this.claim.cuboid ? this.bigz : locality.getBlockZ() + 75;

    // initialize visualization elements without Y values and real data
    // that will be added later for only the visualization elements within
    // visualization range

    if (this.smallx == this.bigx && this.smally == this.bigy && this.smallz == this.bigz) {
        BlockSnapshot blockClicked =
                snapshotBuilder.from(new Location<World>(world, this.smallx, this.smally, this.smallz)).blockState(this.cornerMaterial.getDefaultState()).build();
        elements.add(new Transaction<BlockSnapshot>(blockClicked.getLocation().get().createSnapshot(), blockClicked));
        return;
    }

    // check CUI support
    if (GriefPreventionPlugin.instance.worldEditProvider != null && playerData != null
            && GriefPreventionPlugin.instance.worldEditProvider.hasCUISupport(playerData.getPlayerName())) {
        playerData.showVisualFillers = false;
        STEP = 0;
    }

    if (this.useCuboidVisual()) {
        this.addVisuals3D(claim, playerData);
    } else {
        this.addVisuals2D(claim, height, liquidTransparent);
    }
}