Add #iddatamask pattern

Use to mask a pattern to a certain data range
e.g. #iddatamask:7:slab
This commit is contained in:
Jesse Boyd 2017-04-02 15:41:05 +10:00
parent fda69a4f33
commit b39ab79f16
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
2 changed files with 38 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -7,6 +7,7 @@ import com.boydti.fawe.object.pattern.DataPattern;
import com.boydti.fawe.object.pattern.ExistingPattern;
import com.boydti.fawe.object.pattern.ExpressionPattern;
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.Linear3DBlockPattern;
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");
}
}
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": {
return new IdPattern(Request.request().getExtent(), catchSuggestion(input, rest, context));
}