Add #iddatamask pattern
Use to mask a pattern to a certain data range e.g. #iddatamask:7:slab
This commit is contained in:
parent
fda69a4f33
commit
b39ab79f16
@ -0,0 +1,29 @@
|
|||||||
|
package com.boydti.fawe.object.pattern;
|
||||||
|
|
||||||
|
import com.boydti.fawe.FaweCache;
|
||||||
|
import com.sk89q.worldedit.Vector;
|
||||||
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||||
|
import com.sk89q.worldedit.extent.Extent;
|
||||||
|
import com.sk89q.worldedit.function.pattern.AbstractPattern;
|
||||||
|
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||||
|
|
||||||
|
public class IdDataMaskPattern extends AbstractPattern {
|
||||||
|
private final Extent extent;
|
||||||
|
private final Pattern pattern;
|
||||||
|
private final int mask;
|
||||||
|
|
||||||
|
public IdDataMaskPattern(Extent extent, Pattern parent, int mask) {
|
||||||
|
this.extent = extent;
|
||||||
|
this.pattern = parent;
|
||||||
|
this.mask = mask;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BaseBlock apply(Vector position) {
|
||||||
|
BaseBlock oldBlock = extent.getBlock(position);
|
||||||
|
BaseBlock newBlock = pattern.apply(position);
|
||||||
|
int oldData = oldBlock.getData();
|
||||||
|
int newData = newBlock.getData() + oldData - (oldData & mask);
|
||||||
|
return FaweCache.getBlock(newBlock.getId(), newData);
|
||||||
|
}
|
||||||
|
}
|
@ -7,6 +7,7 @@ import com.boydti.fawe.object.pattern.DataPattern;
|
|||||||
import com.boydti.fawe.object.pattern.ExistingPattern;
|
import com.boydti.fawe.object.pattern.ExistingPattern;
|
||||||
import com.boydti.fawe.object.pattern.ExpressionPattern;
|
import com.boydti.fawe.object.pattern.ExpressionPattern;
|
||||||
import com.boydti.fawe.object.pattern.FullClipboardPattern;
|
import com.boydti.fawe.object.pattern.FullClipboardPattern;
|
||||||
|
import com.boydti.fawe.object.pattern.IdDataMaskPattern;
|
||||||
import com.boydti.fawe.object.pattern.IdPattern;
|
import com.boydti.fawe.object.pattern.IdPattern;
|
||||||
import com.boydti.fawe.object.pattern.Linear3DBlockPattern;
|
import com.boydti.fawe.object.pattern.Linear3DBlockPattern;
|
||||||
import com.boydti.fawe.object.pattern.LinearBlockPattern;
|
import com.boydti.fawe.object.pattern.LinearBlockPattern;
|
||||||
@ -168,6 +169,14 @@ public class HashTagPatternParser extends FaweParser<Pattern> {
|
|||||||
throw new InputParseException("No session is available, so no clipboard is available");
|
throw new InputParseException("No session is available, so no clipboard is available");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case "#iddatamask": {
|
||||||
|
String[] split = rest.split(":", 1);
|
||||||
|
if (split.length != 2) {
|
||||||
|
throw new InputParseException("#iddatamask:<mask>:<pattern>");
|
||||||
|
}
|
||||||
|
int mask = Integer.parseInt(split[0]);
|
||||||
|
return new IdDataMaskPattern(Request.request().getExtent(), catchSuggestion(input, split[1], context), mask);
|
||||||
|
}
|
||||||
case "#id": {
|
case "#id": {
|
||||||
return new IdPattern(Request.request().getExtent(), catchSuggestion(input, rest, context));
|
return new IdPattern(Request.request().getExtent(), catchSuggestion(input, rest, context));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user