Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-09 13:00:05 +01:00
Added overlay and underlay masks
Dieser Commit ist enthalten in:
Ursprung
750d6dd1d0
Commit
43bba317e5
@ -26,14 +26,8 @@ import java.lang.reflect.Method;
|
||||
|
||||
import javax.script.ScriptException;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissionsException;
|
||||
import com.sk89q.minecraft.util.commands.CommandUsageException;
|
||||
import com.sk89q.minecraft.util.commands.CommandsManager;
|
||||
import com.sk89q.minecraft.util.commands.Logging;
|
||||
import com.sk89q.minecraft.util.commands.MissingNestedCommandException;
|
||||
import com.sk89q.minecraft.util.commands.UnhandledCommandException;
|
||||
import com.sk89q.minecraft.util.commands.WrappedCommandException;
|
||||
import com.sk89q.minecraft.util.commands.*;
|
||||
|
||||
import com.sk89q.util.StringUtil;
|
||||
import com.sk89q.worldedit.bags.BlockBag;
|
||||
import com.sk89q.worldedit.blocks.*;
|
||||
@ -467,7 +461,7 @@ public class WorldEdit {
|
||||
return new RandomFillPattern(blockChances);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get a block mask. Block masks are used to determine which
|
||||
* blocks to include when replacing.
|
||||
*
|
||||
@ -480,11 +474,10 @@ public class WorldEdit {
|
||||
public Mask getBlockMask(LocalPlayer player, LocalSession session,
|
||||
String maskString) throws WorldEditException {
|
||||
Mask mask = null;
|
||||
|
||||
|
||||
for (String component : maskString.split(" ")) {
|
||||
Mask current = null;
|
||||
|
||||
if (component.length() == 0) {
|
||||
if (component.length() == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -495,10 +488,82 @@ public class WorldEdit {
|
||||
|| component.equalsIgnoreCase("#region")
|
||||
|| component.equalsIgnoreCase("#sel")) {
|
||||
current = new RegionMask(session.getSelection(player.getWorld()));
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
throw new UnknownItemException(component);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else if (component.charAt(0) == '>') {
|
||||
LocalWorld world = player.getWorld();
|
||||
Set<Integer> set = new HashSet<Integer>();
|
||||
String ids = component.replaceAll(">,", "");
|
||||
if(ids.equalsIgnoreCase("*")){
|
||||
current = new UnderOverlayMask(set,true,true);
|
||||
}
|
||||
else{
|
||||
String[] split = ids.split(",");
|
||||
for(String sid :split){
|
||||
try{
|
||||
int pid = Integer.parseInt(sid);
|
||||
if(!world.isValidBlockType(pid)){
|
||||
throw new UnknownItemException(sid);
|
||||
}
|
||||
else{
|
||||
set.add(pid);
|
||||
}
|
||||
}catch(NumberFormatException e){
|
||||
BlockType type = BlockType.lookup(sid);
|
||||
int id = type.getID();
|
||||
if(!world.isValidBlockType(id)){
|
||||
throw new UnknownItemException(sid);
|
||||
}
|
||||
else{
|
||||
set.add(id);
|
||||
}
|
||||
}
|
||||
current = new UnderOverlayMask(set, true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (component.charAt(0) == '<') {
|
||||
LocalWorld world = player.getWorld();
|
||||
Set<Integer> set = new HashSet<Integer>();
|
||||
|
||||
|
||||
String ids = component.replaceAll("<,", "");
|
||||
if(ids.equalsIgnoreCase("*")){
|
||||
current = new UnderOverlayMask(set,false,true);
|
||||
}
|
||||
else{
|
||||
String[] split = ids.split(",");
|
||||
for(String sid :split){
|
||||
try{
|
||||
int pid = Integer.parseInt(sid);
|
||||
if(!world.isValidBlockType(pid)){
|
||||
throw new UnknownItemException(sid);
|
||||
}
|
||||
else{
|
||||
set.add(pid);
|
||||
}
|
||||
}catch(NumberFormatException e){
|
||||
BlockType type = BlockType.lookup(sid);
|
||||
int id = type.getID();
|
||||
if(!world.isValidBlockType(id)){
|
||||
throw new UnknownItemException(sid);
|
||||
}
|
||||
else{
|
||||
set.add(id);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
current = new UnderOverlayMask(set, false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
if (component.charAt(0) == '!' && component.length() > 1) {
|
||||
current = new InvertedBlockTypeMask(
|
||||
getBlockIDs(player, component.substring(1), true));
|
||||
@ -519,7 +584,6 @@ public class WorldEdit {
|
||||
|
||||
return mask;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of blocks as a set.
|
||||
*
|
||||
|
46
src/main/java/com/sk89q/worldedit/masks/UnderOverlayMask.java
Normale Datei
46
src/main/java/com/sk89q/worldedit/masks/UnderOverlayMask.java
Normale Datei
@ -0,0 +1,46 @@
|
||||
|
||||
package com.sk89q.worldedit.masks;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 1337
|
||||
*/
|
||||
public class UnderOverlayMask implements Mask{
|
||||
boolean overlay;
|
||||
boolean wildcard;
|
||||
Set<Integer> ids = new HashSet<Integer>();
|
||||
public UnderOverlayMask(Set<Integer> ids,boolean overlay,boolean wildcard){
|
||||
addAll(ids);
|
||||
this.overlay = overlay;
|
||||
this.wildcard = wildcard;
|
||||
|
||||
}
|
||||
public void addAll(Set<Integer> ids){
|
||||
this.ids.addAll(ids);
|
||||
}
|
||||
public boolean matches(EditSession editSession, Vector pos) {
|
||||
if(!wildcard){
|
||||
int id = editSession.getBlock(pos.setY(pos.getBlockY() + (overlay ? -1 :1))).getType();
|
||||
if(overlay){
|
||||
return ids.contains(id);
|
||||
}
|
||||
else if(!overlay){
|
||||
return ids.contains(id);
|
||||
}
|
||||
}
|
||||
else{
|
||||
return (overlay ? editSession.getBlock(pos.setY(pos.getBlockY() + 1)).getType() != 0: editSession.getBlock(pos.setY(pos.getBlockY() - 1)).getType() != 0);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren