From 21d603ce4e63f7475bc6cd817a8eaefce90b906f Mon Sep 17 00:00:00 2001 From: aumgn Date: Wed, 29 Aug 2012 11:28:25 +0200 Subject: [PATCH] Add RandomMask (not sure if really useful) --- .../java/com/sk89q/worldedit/WorldEdit.java | 4 ++++ .../com/sk89q/worldedit/masks/RandomMask.java | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/main/java/com/sk89q/worldedit/masks/RandomMask.java diff --git a/src/main/java/com/sk89q/worldedit/WorldEdit.java b/src/main/java/com/sk89q/worldedit/WorldEdit.java index 31fa7748d..d2443a168 100644 --- a/src/main/java/com/sk89q/worldedit/WorldEdit.java +++ b/src/main/java/com/sk89q/worldedit/WorldEdit.java @@ -632,6 +632,10 @@ public class WorldEdit { } return new BiomeTypeMask(biomes); + case '%': + int i = Integer.parseInt(component.substring(1)); + return new RandomMask(((double) i) / 100); + case '!': if (component.length() > 1) { return new InvertedMask(getBlockMaskComponent(player, session, masks, component.substring(1))); diff --git a/src/main/java/com/sk89q/worldedit/masks/RandomMask.java b/src/main/java/com/sk89q/worldedit/masks/RandomMask.java new file mode 100644 index 000000000..22fd8428a --- /dev/null +++ b/src/main/java/com/sk89q/worldedit/masks/RandomMask.java @@ -0,0 +1,24 @@ +package com.sk89q.worldedit.masks; + +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.LocalPlayer; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.Vector; + +public class RandomMask implements Mask { + + private final double ratio; + + public RandomMask(double ratio) { + this.ratio = ratio; + } + + @Override + public void prepare(LocalSession session, LocalPlayer player, Vector target) { + } + + @Override + public boolean matches(EditSession editSession, Vector pos) { + return Math.random() < ratio; + } +}