geforkt von Mirrors/FastAsyncWorldEdit
Made some masks use Extents rather than EditSessions.
Dieser Commit ist enthalten in:
Ursprung
70f409975e
Commit
e7bbd1ac53
@ -1,6 +1,7 @@
|
|||||||
package com.sk89q.worldedit.masks;
|
package com.sk89q.worldedit.masks;
|
||||||
|
|
||||||
import com.sk89q.worldedit.EditSession;
|
import com.sk89q.worldedit.EditSession;
|
||||||
|
import com.sk89q.worldedit.Extent;
|
||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||||
|
|
||||||
@ -8,7 +9,7 @@ import java.util.Collection;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class BlockMask extends AbstractMask {
|
public class BlockMask extends ExtentAwareMask {
|
||||||
|
|
||||||
private final Set<BaseBlock> blocks;
|
private final Set<BaseBlock> blocks;
|
||||||
|
|
||||||
@ -42,7 +43,8 @@ public class BlockMask extends AbstractMask {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(EditSession editSession, Vector pos) {
|
public boolean matches(EditSession editSession, Vector pos) {
|
||||||
BaseBlock block = editSession.getBlock(pos);
|
Extent extent = getExtent(editSession);
|
||||||
|
BaseBlock block = extent.getBlock(pos);
|
||||||
return blocks.contains(block)
|
return blocks.contains(block)
|
||||||
|| blocks.contains(new BaseBlock(block.getType(), -1));
|
|| blocks.contains(new BaseBlock(block.getType(), -1));
|
||||||
}
|
}
|
||||||
|
@ -23,9 +23,9 @@ import com.sk89q.worldedit.EditSession;
|
|||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
import com.sk89q.worldedit.blocks.BlockID;
|
import com.sk89q.worldedit.blocks.BlockID;
|
||||||
|
|
||||||
public class ExistingBlockMask extends AbstractMask {
|
public class ExistingBlockMask extends ExtentAwareMask {
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(EditSession editSession, Vector pos) {
|
public boolean matches(EditSession editSession, Vector pos) {
|
||||||
return editSession.getBlockType(pos) != BlockID.AIR;
|
return getExtent(editSession).getBlockType(pos) != BlockID.AIR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
71
src/main/java/com/sk89q/worldedit/masks/ExtentAwareMask.java
Normale Datei
71
src/main/java/com/sk89q/worldedit/masks/ExtentAwareMask.java
Normale Datei
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* WorldEdit, a Minecraft world manipulation toolkit
|
||||||
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
|
* Copyright (C) WorldEdit team and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.sk89q.worldedit.masks;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.EditSession;
|
||||||
|
import com.sk89q.worldedit.Extent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extended by masks to make them potentially use an {@link Extent} rather than
|
||||||
|
* the {@link EditSession}.
|
||||||
|
* </p>
|
||||||
|
* At the moment, masks are coupled to {@link EditSession} when they should
|
||||||
|
* not be. However, because a change to {@link Mask} would cause massive breakage in
|
||||||
|
* the API, that change is deferred until further notice and this class exists as
|
||||||
|
* an opt-in mixin for adding support for {@link Extent}s.
|
||||||
|
*/
|
||||||
|
public abstract class ExtentAwareMask extends AbstractMask {
|
||||||
|
|
||||||
|
private Extent extent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the extent that will be used for lookups.
|
||||||
|
*
|
||||||
|
* @return the extent, or null if the {@link EditSession} is to be used
|
||||||
|
*/
|
||||||
|
public Extent getExtent() {
|
||||||
|
return extent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the extent that will be used for lookups.
|
||||||
|
*
|
||||||
|
* @param extent the extent, or null if the {@link EditSession} is to be used
|
||||||
|
*/
|
||||||
|
public void setExtent(Extent extent) {
|
||||||
|
this.extent = extent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the extent to use for operations. Subclasses should call this method
|
||||||
|
* rather than access the passed {@link EditSession} directly.
|
||||||
|
*
|
||||||
|
* @param editSession the passed in {@link EditSession}
|
||||||
|
* @return an extent
|
||||||
|
*/
|
||||||
|
protected Extent getExtent(EditSession editSession) {
|
||||||
|
if (extent != null) {
|
||||||
|
return extent;
|
||||||
|
} else {
|
||||||
|
return editSession;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -20,6 +20,7 @@
|
|||||||
package com.sk89q.worldedit.masks;
|
package com.sk89q.worldedit.masks;
|
||||||
|
|
||||||
import com.sk89q.worldedit.EditSession;
|
import com.sk89q.worldedit.EditSession;
|
||||||
|
import com.sk89q.worldedit.Extent;
|
||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||||
|
|
||||||
@ -30,7 +31,7 @@ import java.util.Set;
|
|||||||
* Uses {@link BaseBlock#containsFuzzy(java.util.Collection, BaseBlock)} to
|
* Uses {@link BaseBlock#containsFuzzy(java.util.Collection, BaseBlock)} to
|
||||||
* match blocks.
|
* match blocks.
|
||||||
*/
|
*/
|
||||||
public class FuzzyBlockMask extends AbstractMask {
|
public class FuzzyBlockMask extends ExtentAwareMask {
|
||||||
|
|
||||||
private final Set<BaseBlock> filter;
|
private final Set<BaseBlock> filter;
|
||||||
|
|
||||||
@ -58,7 +59,8 @@ public class FuzzyBlockMask extends AbstractMask {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(EditSession editSession, Vector pos) {
|
public boolean matches(EditSession editSession, Vector pos) {
|
||||||
BaseBlock compare = new BaseBlock(editSession.getBlockType(pos), editSession.getBlockData(pos));
|
Extent extent = getExtent(editSession);
|
||||||
|
BaseBlock compare = new BaseBlock(extent.getBlockType(pos), extent.getBlockData(pos));
|
||||||
return BaseBlock.containsFuzzy(filter, compare);
|
return BaseBlock.containsFuzzy(filter, compare);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,8 +48,8 @@ public interface Mask {
|
|||||||
* that position matches the filter. Block information is not provided
|
* that position matches the filter. Block information is not provided
|
||||||
* as getting a BaseBlock has unneeded overhead in most block querying
|
* as getting a BaseBlock has unneeded overhead in most block querying
|
||||||
* situations (enumerating a chest's contents is a waste, for example).
|
* situations (enumerating a chest's contents is a waste, for example).
|
||||||
*
|
*
|
||||||
* @param editSession
|
* @param editSession
|
||||||
* @param pos
|
* @param pos
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@ -1,15 +1,17 @@
|
|||||||
package com.sk89q.worldedit.masks;
|
package com.sk89q.worldedit.masks;
|
||||||
|
|
||||||
import com.sk89q.worldedit.EditSession;
|
import com.sk89q.worldedit.EditSession;
|
||||||
|
import com.sk89q.worldedit.Extent;
|
||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
import com.sk89q.worldedit.blocks.BlockType;
|
import com.sk89q.worldedit.blocks.BlockType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Works like {@link ExistingBlockMask}, except also dealing with non-solid non-air blocks the same way as with air.
|
* Works like {@link ExistingBlockMask}, except also dealing with non-solid non-air blocks the same way as with air.
|
||||||
*/
|
*/
|
||||||
public class SolidBlockMask extends AbstractMask {
|
public class SolidBlockMask extends ExtentAwareMask {
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(EditSession editSession, Vector pos) {
|
public boolean matches(EditSession editSession, Vector pos) {
|
||||||
return !BlockType.canPassThrough(editSession.getBlockType(pos), editSession.getBlockData(pos));
|
Extent extent = getExtent(editSession);
|
||||||
|
return !BlockType.canPassThrough(extent.getBlockType(pos), extent.getBlockData(pos));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,17 +21,14 @@ package com.sk89q.worldedit.masks;
|
|||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import com.sk89q.worldedit.EditSession;
|
import com.sk89q.worldedit.*;
|
||||||
import com.sk89q.worldedit.LocalPlayer;
|
|
||||||
import com.sk89q.worldedit.LocalSession;
|
|
||||||
import com.sk89q.worldedit.Vector;
|
|
||||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author 1337
|
* @author 1337
|
||||||
*/
|
*/
|
||||||
public class UnderOverlayMask extends AbstractMask {
|
public class UnderOverlayMask extends ExtentAwareMask {
|
||||||
private final int yMod;
|
private final int yMod;
|
||||||
private Mask mask;
|
private Mask mask;
|
||||||
|
|
||||||
@ -68,6 +65,7 @@ public class UnderOverlayMask extends AbstractMask {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(EditSession editSession, Vector pos) {
|
public boolean matches(EditSession editSession, Vector pos) {
|
||||||
return !mask.matches(editSession, pos) && mask.matches(editSession, pos.add(0, yMod, 0));
|
Extent extent = getExtent(editSession);
|
||||||
|
return !mask.matches(extent, pos) && mask.matches(extent, pos.add(0, yMod, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren