3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-05 02:50:05 +01:00

Merge pull request #438 from sk89q/feature/modular-patterns-masks

Modularise Patterns & Masks
Dieser Commit ist enthalten in:
Matthew Miller 2018-12-26 15:25:28 +10:00 committet von GitHub
Commit 4cc8e9a1c0
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
32 geänderte Dateien mit 849 neuen und 258 gelöschten Zeilen

Datei anzeigen

@ -21,6 +21,7 @@ package com.sk89q.worldedit.extension.factory;
import com.sk89q.util.StringUtil;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.factory.parser.DefaultBlockParser;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
@ -47,7 +48,7 @@ public class BlockFactory extends AbstractFactory<BlockStateHolder> {
public BlockFactory(WorldEdit worldEdit) {
super(worldEdit);
parsers.add(new DefaultBlockParser(worldEdit));
register(new DefaultBlockParser(worldEdit));
}
/**

Datei anzeigen

@ -1,185 +0,0 @@
/*
* 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 Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.extension.factory;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.NoMatchException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.BiomeMask2D;
import com.sk89q.worldedit.function.mask.BlockCategoryMask;
import com.sk89q.worldedit.function.mask.BlockMask;
import com.sk89q.worldedit.function.mask.ExistingBlockMask;
import com.sk89q.worldedit.function.mask.ExpressionMask;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.MaskIntersection;
import com.sk89q.worldedit.function.mask.Masks;
import com.sk89q.worldedit.function.mask.NoiseFilter;
import com.sk89q.worldedit.function.mask.OffsetMask;
import com.sk89q.worldedit.function.mask.RegionMask;
import com.sk89q.worldedit.function.mask.SolidBlockMask;
import com.sk89q.worldedit.internal.expression.Expression;
import com.sk89q.worldedit.internal.expression.ExpressionException;
import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.math.noise.RandomNoise;
import com.sk89q.worldedit.regions.shape.WorldEditExpressionEnvironment;
import com.sk89q.worldedit.session.request.Request;
import com.sk89q.worldedit.session.request.RequestSelection;
import com.sk89q.worldedit.world.biome.BaseBiome;
import com.sk89q.worldedit.world.biome.Biomes;
import com.sk89q.worldedit.world.block.BlockCategories;
import com.sk89q.worldedit.world.block.BlockCategory;
import com.sk89q.worldedit.world.registry.BiomeRegistry;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Parses mask input strings.
*/
class DefaultMaskParser extends InputParser<Mask> {
protected DefaultMaskParser(WorldEdit worldEdit) {
super(worldEdit);
}
@Override
public Mask parseFromInput(String input, ParserContext context) throws InputParseException {
List<Mask> masks = new ArrayList<>();
for (String component : input.split(" ")) {
if (component.isEmpty()) {
continue;
}
Mask current = getBlockMaskComponent(masks, component, context);
masks.add(current);
}
switch (masks.size()) {
case 0:
return null;
case 1:
return masks.get(0);
default:
return new MaskIntersection(masks);
}
}
private Mask getBlockMaskComponent(List<Mask> masks, String component, ParserContext context) throws InputParseException {
Extent extent = Request.request().getEditSession();
final char firstChar = component.charAt(0);
switch (firstChar) {
case '#':
if (component.equalsIgnoreCase("#existing")) {
return new ExistingBlockMask(extent);
} else if (component.equalsIgnoreCase("#solid")) {
return new SolidBlockMask(extent);
} else if (component.equalsIgnoreCase("#dregion")
|| component.equalsIgnoreCase("#dselection")
|| component.equalsIgnoreCase("#dsel")) {
return new RegionMask(new RequestSelection());
} else if (component.equalsIgnoreCase("#selection")
|| component.equalsIgnoreCase("#region")
|| component.equalsIgnoreCase("#sel")) {
try {
return new RegionMask(context.requireSession().getSelection(context.requireWorld()).clone());
} catch (IncompleteRegionException e) {
throw new InputParseException("Please make a selection first.");
}
} else if (component.startsWith("##")) {
// This means it's a tag mask.
BlockCategory category = BlockCategories.get(component.substring(2).toLowerCase());
if (category == null) {
throw new NoMatchException("Unrecognised tag '" + component.substring(2) + '\'');
} else {
return new BlockCategoryMask(extent, category);
}
} else {
throw new NoMatchException("Unrecognized mask '" + component + '\'');
}
case '>':
case '<':
Mask submask;
if (component.length() > 1) {
submask = getBlockMaskComponent(masks, component.substring(1), context);
} else {
submask = new ExistingBlockMask(extent);
}
OffsetMask offsetMask = new OffsetMask(submask, BlockVector3.at(0, firstChar == '>' ? -1 : 1, 0));
return new MaskIntersection(offsetMask, Masks.negate(submask));
case '$':
Set<BaseBiome> biomes = new HashSet<>();
String[] biomesList = component.substring(1).split(",");
BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager()
.queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry();
List<BaseBiome> knownBiomes = biomeRegistry.getBiomes();
for (String biomeName : biomesList) {
BaseBiome biome = Biomes.findBiomeByName(knownBiomes, biomeName, biomeRegistry);
if (biome == null) {
throw new InputParseException("Unknown biome '" + biomeName + '\'');
}
biomes.add(biome);
}
return Masks.asMask(new BiomeMask2D(context.requireExtent(), biomes));
case '%':
int i = Integer.parseInt(component.substring(1));
return new NoiseFilter(new RandomNoise(), ((double) i) / 100);
case '=':
try {
Expression exp = Expression.compile(component.substring(1), "x", "y", "z");
WorldEditExpressionEnvironment env = new WorldEditExpressionEnvironment(
Request.request().getEditSession(), Vector3.ONE, Vector3.ZERO);
exp.setEnvironment(env);
return new ExpressionMask(exp);
} catch (ExpressionException e) {
throw new InputParseException("Invalid expression: " + e.getMessage());
}
case '!':
if (component.length() > 1) {
return Masks.negate(getBlockMaskComponent(masks, component.substring(1), context));
}
default:
ParserContext tempContext = new ParserContext(context);
tempContext.setRestricted(false);
tempContext.setPreferringWildcard(true);
return new BlockMask(extent, worldEdit.getBlockFactory().parseFromListInput(component, tempContext));
}
}
}

Datei anzeigen

@ -21,6 +21,7 @@ package com.sk89q.worldedit.extension.factory;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.extension.factory.parser.DefaultItemParser;
import com.sk89q.worldedit.internal.registry.AbstractFactory;
public class ItemFactory extends AbstractFactory<BaseItem> {
@ -33,7 +34,7 @@ public class ItemFactory extends AbstractFactory<BaseItem> {
public ItemFactory(WorldEdit worldEdit) {
super(worldEdit);
parsers.add(new DefaultItemParser(worldEdit));
register(new DefaultItemParser(worldEdit));
}
}

Datei anzeigen

@ -20,8 +20,27 @@
package com.sk89q.worldedit.extension.factory;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.factory.parser.mask.BiomeMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.BlockCategoryMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.BlocksMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.ExistingMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.ExpressionMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.LazyRegionMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.NegateMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.NoiseMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.OffsetMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.RegionMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.SolidMaskParser;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.NoMatchException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.MaskIntersection;
import com.sk89q.worldedit.internal.registry.AbstractFactory;
import com.sk89q.worldedit.internal.registry.InputParser;
import java.util.ArrayList;
import java.util.List;
/**
* A registry of known {@link Mask}s. Provides methods to instantiate
@ -40,7 +59,45 @@ public final class MaskFactory extends AbstractFactory<Mask> {
public MaskFactory(WorldEdit worldEdit) {
super(worldEdit);
parsers.add(new DefaultMaskParser(worldEdit));
register(new ExistingMaskParser(worldEdit));
register(new SolidMaskParser(worldEdit));
register(new LazyRegionMaskParser(worldEdit));
register(new RegionMaskParser(worldEdit));
register(new BlockCategoryMaskParser(worldEdit));
register(new OffsetMaskParser(worldEdit));
register(new BiomeMaskParser(worldEdit));
register(new NoiseMaskParser(worldEdit));
register(new NegateMaskParser(worldEdit));
register(new ExpressionMaskParser(worldEdit));
register(new BlocksMaskParser(worldEdit));
}
@Override
public Mask parseFromInput(String input, ParserContext context) throws InputParseException {
List<Mask> masks = new ArrayList<>();
for (String component : input.split(" ")) {
if (component.isEmpty()) {
continue;
}
for (InputParser<Mask> parser : getParsers()) {
Mask match = parser.parseFromInput(component, context);
if (match != null) {
masks.add(match);
}
}
}
switch (masks.size()) {
case 0:
throw new NoMatchException("No match for '" + input + "'");
case 1:
return masks.get(0);
default:
return new MaskIntersection(masks);
}
}
}

Datei anzeigen

@ -20,6 +20,9 @@
package com.sk89q.worldedit.extension.factory;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.factory.parser.pattern.ClipboardPatternParser;
import com.sk89q.worldedit.extension.factory.parser.pattern.RandomPatternParser;
import com.sk89q.worldedit.extension.factory.parser.pattern.SingleBlockPatternParser;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.internal.registry.AbstractFactory;
@ -40,9 +43,9 @@ public final class PatternFactory extends AbstractFactory<Pattern> {
public PatternFactory(WorldEdit worldEdit) {
super(worldEdit);
parsers.add(new HashTagPatternParser(worldEdit));
parsers.add(new SingleBlockPatternParser(worldEdit));
parsers.add(new RandomPatternParser(worldEdit));
register(new ClipboardPatternParser(worldEdit));
register(new SingleBlockPatternParser(worldEdit));
register(new RandomPatternParser(worldEdit));
}
}

Datei anzeigen

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.extension.factory;
package com.sk89q.worldedit.extension.factory.parser;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.NotABlockException;
@ -52,9 +52,9 @@ import java.util.Map;
/**
* Parses block input strings.
*/
class DefaultBlockParser extends InputParser<BlockStateHolder> {
public class DefaultBlockParser extends InputParser<BlockStateHolder> {
protected DefaultBlockParser(WorldEdit worldEdit) {
public DefaultBlockParser(WorldEdit worldEdit) {
super(worldEdit);
}

Datei anzeigen

@ -17,20 +17,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.extension.factory;
package com.sk89q.worldedit.extension.factory.parser;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.registry.LegacyMapper;
public class DefaultItemParser extends InputParser<BaseItem> {
protected DefaultItemParser(WorldEdit worldEdit) {
public DefaultItemParser(WorldEdit worldEdit) {
super(worldEdit);
}
@ -53,8 +53,10 @@ public class DefaultItemParser extends InputParser<BaseItem> {
}
if (item == null) {
item = WorldEdit.getInstance().getPlatformManager()
.queryCapability(Capability.GAME_HOOKS).getRegistries().getItemRegistry().createFromId(input.toLowerCase());
ItemType type = ItemTypes.get(input.toLowerCase());
if (type != null) {
item = new BaseItem(type);
}
}
if (item == null) {

Datei anzeigen

@ -0,0 +1,64 @@
/*
* 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 Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.extension.factory.parser.mask;
import com.google.common.base.Splitter;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.function.mask.BiomeMask2D;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.Masks;
import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.world.biome.BaseBiome;
import com.sk89q.worldedit.world.biome.Biomes;
import com.sk89q.worldedit.world.registry.BiomeRegistry;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class BiomeMaskParser extends InputParser<Mask> {
public BiomeMaskParser(WorldEdit worldEdit) {
super(worldEdit);
}
@Override
public Mask parseFromInput(String input, ParserContext context) throws InputParseException {
if (!input.startsWith("$")) {
return null;
}
Set<BaseBiome> biomes = new HashSet<>();
BiomeRegistry biomeRegistry = worldEdit.getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry();
List<BaseBiome> knownBiomes = biomeRegistry.getBiomes();
for (String biomeName : Splitter.on(",").split(input.substring(1))) {
BaseBiome biome = Biomes.findBiomeByName(knownBiomes, biomeName, biomeRegistry);
if (biome == null) {
throw new InputParseException("Unknown biome '" + biomeName + '\'');
}
biomes.add(biome);
}
return Masks.asMask(new BiomeMask2D(context.requireExtent(), biomes));
}
}

Datei anzeigen

@ -0,0 +1,55 @@
/*
* 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 Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.extension.factory.parser.mask;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.BlockCategoryMask;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.session.request.Request;
import com.sk89q.worldedit.world.block.BlockCategories;
import com.sk89q.worldedit.world.block.BlockCategory;
public class BlockCategoryMaskParser extends InputParser<Mask> {
public BlockCategoryMaskParser(WorldEdit worldEdit) {
super(worldEdit);
}
@Override
public Mask parseFromInput(String input, ParserContext context) throws InputParseException {
if (!input.startsWith("##")) {
return null;
}
Extent extent = Request.request().getEditSession();
// This means it's a tag mask.
BlockCategory category = BlockCategories.get(input.substring(2).toLowerCase());
if (category == null) {
throw new InputParseException("Unrecognised tag '" + input.substring(2) + '\'');
} else {
return new BlockCategoryMask(extent, category);
}
}
}

Datei anzeigen

@ -0,0 +1,61 @@
/*
* 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 Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.extension.factory.parser.mask;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.NoMatchException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.BlockMask;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.session.request.Request;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import java.util.Set;
/**
* Parses mask input strings.
*/
public class BlocksMaskParser extends InputParser<Mask> {
public BlocksMaskParser(WorldEdit worldEdit) {
super(worldEdit);
}
public Mask parseFromInput(String component, ParserContext context) throws InputParseException {
Extent extent = Request.request().getEditSession();
ParserContext tempContext = new ParserContext(context);
tempContext.setRestricted(false);
tempContext.setPreferringWildcard(true);
try {
Set<BlockStateHolder> holders = worldEdit.getBlockFactory().parseFromListInput(component, tempContext);
if (holders.isEmpty()) {
return null;
}
return new BlockMask(extent, holders);
} catch (NoMatchException e) {
return null;
}
}
}

Datei anzeigen

@ -0,0 +1,51 @@
/*
* 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 Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.extension.factory.parser.mask;
import com.google.common.collect.Lists;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.ExistingBlockMask;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
import com.sk89q.worldedit.session.request.Request;
import java.util.List;
public class ExistingMaskParser extends SimpleInputParser<Mask> {
public ExistingMaskParser(WorldEdit worldEdit) {
super(worldEdit);
}
@Override
public List<String> getMatchedAliases() {
return Lists.newArrayList("#existing");
}
@Override
public Mask parseFromSimpleInput(String input, ParserContext context) throws InputParseException {
Extent extent = Request.request().getEditSession();
return new ExistingBlockMask(extent);
}
}

Datei anzeigen

@ -0,0 +1,56 @@
/*
* 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 Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.extension.factory.parser.mask;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.function.mask.ExpressionMask;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.internal.expression.Expression;
import com.sk89q.worldedit.internal.expression.ExpressionException;
import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.regions.shape.WorldEditExpressionEnvironment;
import com.sk89q.worldedit.session.request.Request;
public class ExpressionMaskParser extends InputParser<Mask> {
public ExpressionMaskParser(WorldEdit worldEdit) {
super(worldEdit);
}
@Override
public Mask parseFromInput(String input, ParserContext context) throws InputParseException {
if (!input.startsWith("=")) {
return null;
}
try {
Expression exp = Expression.compile(input.substring(1), "x", "y", "z");
WorldEditExpressionEnvironment env = new WorldEditExpressionEnvironment(
Request.request().getEditSession(), Vector3.ONE, Vector3.ZERO);
exp.setEnvironment(env);
return new ExpressionMask(exp);
} catch (ExpressionException e) {
throw new InputParseException("Invalid expression: " + e.getMessage());
}
}
}

Datei anzeigen

@ -0,0 +1,48 @@
/*
* 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 Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.extension.factory.parser.mask;
import com.google.common.collect.Lists;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.RegionMask;
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
import com.sk89q.worldedit.session.request.RequestSelection;
import java.util.List;
public class LazyRegionMaskParser extends SimpleInputParser<Mask> {
public LazyRegionMaskParser(WorldEdit worldEdit) {
super(worldEdit);
}
@Override
public List<String> getMatchedAliases() {
return Lists.newArrayList("#dregion", "#dselection", "#dsel");
}
@Override
public Mask parseFromSimpleInput(String input, ParserContext context) throws InputParseException {
return new RegionMask(new RequestSelection());
}
}

Datei anzeigen

@ -0,0 +1,47 @@
/*
* 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 Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.extension.factory.parser.mask;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.Masks;
import com.sk89q.worldedit.internal.registry.InputParser;
public class NegateMaskParser extends InputParser<Mask> {
public NegateMaskParser(WorldEdit worldEdit) {
super(worldEdit);
}
@Override
public Mask parseFromInput(String input, ParserContext context) throws InputParseException {
if (!input.startsWith("!")) {
return null;
}
if (input.length() > 1) {
return Masks.negate(worldEdit.getMaskFactory().parseFromInput(input.substring(1), context));
} else {
throw new InputParseException("Can't negate nothing!");
}
}
}

Datei anzeigen

@ -0,0 +1,45 @@
/*
* 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 Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.extension.factory.parser.mask;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.NoiseFilter;
import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.math.noise.RandomNoise;
public class NoiseMaskParser extends InputParser<Mask> {
public NoiseMaskParser(WorldEdit worldEdit) {
super(worldEdit);
}
@Override
public Mask parseFromInput(String input, ParserContext context) throws InputParseException {
if (!input.startsWith("%")) {
return null;
}
int i = Integer.parseInt(input.substring(1));
return new NoiseFilter(new RandomNoise(), ((double) i) / 100);
}
}

Datei anzeigen

@ -0,0 +1,59 @@
/*
* 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 Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.extension.factory.parser.mask;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.ExistingBlockMask;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.MaskIntersection;
import com.sk89q.worldedit.function.mask.Masks;
import com.sk89q.worldedit.function.mask.OffsetMask;
import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.session.request.Request;
public class OffsetMaskParser extends InputParser<Mask> {
public OffsetMaskParser(WorldEdit worldEdit) {
super(worldEdit);
}
@Override
public Mask parseFromInput(String input, ParserContext context) throws InputParseException {
final char firstChar = input.charAt(0);
if (firstChar != '>' && firstChar != '<') {
return null;
}
Extent extent = Request.request().getEditSession();
Mask submask;
if (input.length() > 1) {
submask = worldEdit.getMaskFactory().parseFromInput(input.substring(1), context);
} else {
submask = new ExistingBlockMask(extent);
}
OffsetMask offsetMask = new OffsetMask(submask, BlockVector3.at(0, firstChar == '>' ? -1 : 1, 0));
return new MaskIntersection(offsetMask, Masks.negate(submask));
}
}

Datei anzeigen

@ -0,0 +1,52 @@
/*
* 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 Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.extension.factory.parser.mask;
import com.google.common.collect.Lists;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.RegionMask;
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
import java.util.List;
public class RegionMaskParser extends SimpleInputParser<Mask> {
public RegionMaskParser(WorldEdit worldEdit) {
super(worldEdit);
}
@Override
public List<String> getMatchedAliases() {
return Lists.newArrayList("#region", "#selection", "#sel");
}
@Override
public Mask parseFromSimpleInput(String input, ParserContext context) throws InputParseException {
try {
return new RegionMask(context.requireSession().getSelection(context.requireWorld()).clone());
} catch (IncompleteRegionException e) {
throw new InputParseException("Please make a selection first.");
}
}
}

Datei anzeigen

@ -0,0 +1,51 @@
/*
* 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 Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.extension.factory.parser.mask;
import com.google.common.collect.Lists;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.SolidBlockMask;
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
import com.sk89q.worldedit.session.request.Request;
import java.util.List;
public class SolidMaskParser extends SimpleInputParser<Mask> {
public SolidMaskParser(WorldEdit worldEdit) {
super(worldEdit);
}
@Override
public List<String> getMatchedAliases() {
return Lists.newArrayList("#solid");
}
@Override
public Mask parseFromSimpleInput(String input, ParserContext context) throws InputParseException {
Extent extent = Request.request().getEditSession();
return new SolidBlockMask(extent);
}
}

Datei anzeigen

@ -17,8 +17,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.extension.factory;
package com.sk89q.worldedit.extension.factory.parser.pattern;
import com.google.common.collect.Lists;
import com.sk89q.worldedit.EmptyClipboardException;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
@ -27,37 +28,36 @@ import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.function.pattern.ClipboardPattern;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
import com.sk89q.worldedit.session.ClipboardHolder;
class HashTagPatternParser extends InputParser<Pattern> {
import java.util.List;
HashTagPatternParser(WorldEdit worldEdit) {
public class ClipboardPatternParser extends SimpleInputParser<Pattern> {
public ClipboardPatternParser(WorldEdit worldEdit) {
super(worldEdit);
}
@Override
public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
if (input.charAt(0) == '#') {
if (!input.equals("#clipboard") && !input.equals("#copy")) {
throw new InputParseException("#clipboard or #copy is acceptable for patterns starting with #");
}
public List<String> getMatchedAliases() {
return Lists.newArrayList("#clipboard", "#copy");
}
LocalSession session = context.requireSession();
@Override
public Pattern parseFromSimpleInput(String input, ParserContext context) throws InputParseException {
LocalSession session = context.requireSession();
if (session != null) {
try {
ClipboardHolder holder = session.getClipboard();
Clipboard clipboard = holder.getClipboard();
return new ClipboardPattern(clipboard);
} catch (EmptyClipboardException e) {
throw new InputParseException("To use #clipboard, please first copy something to your clipboard");
}
} else {
throw new InputParseException("No session is available, so no clipboard is available");
if (session != null) {
try {
ClipboardHolder holder = session.getClipboard();
Clipboard clipboard = holder.getClipboard();
return new ClipboardPattern(clipboard);
} catch (EmptyClipboardException e) {
throw new InputParseException("To use #clipboard, please first copy something to your clipboard");
}
} else {
return null;
throw new InputParseException("No session is available, so no clipboard is available");
}
}

Datei anzeigen

@ -17,10 +17,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.extension.factory;
package com.sk89q.worldedit.extension.factory.parser.pattern;
import com.sk89q.util.StringUtil;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.factory.BlockFactory;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.function.pattern.BlockPattern;
@ -29,9 +30,9 @@ import com.sk89q.worldedit.function.pattern.RandomPattern;
import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.world.block.BlockStateHolder;
class RandomPatternParser extends InputParser<Pattern> {
public class RandomPatternParser extends InputParser<Pattern> {
RandomPatternParser(WorldEdit worldEdit) {
public RandomPatternParser(WorldEdit worldEdit) {
super(worldEdit);
}

Datei anzeigen

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.extension.factory;
package com.sk89q.worldedit.extension.factory.parser.pattern;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.input.InputParseException;
@ -26,9 +26,9 @@ import com.sk89q.worldedit.function.pattern.BlockPattern;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.internal.registry.InputParser;
class SingleBlockPatternParser extends InputParser<Pattern> {
public class SingleBlockPatternParser extends InputParser<Pattern> {
SingleBlockPatternParser(WorldEdit worldEdit) {
public SingleBlockPatternParser(WorldEdit worldEdit) {
super(worldEdit);
}

Datei anzeigen

@ -21,12 +21,14 @@ package com.sk89q.worldedit.internal.registry;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.Lists;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.NoMatchException;
import com.sk89q.worldedit.extension.input.ParserContext;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
@ -38,7 +40,7 @@ import java.util.List;
public abstract class AbstractFactory<E> {
protected final WorldEdit worldEdit;
protected final List<InputParser<E>> parsers = new ArrayList<>();
private final List<InputParser<E>> parsers = new ArrayList<>();
/**
* Create a new factory.
@ -50,6 +52,17 @@ public abstract class AbstractFactory<E> {
this.worldEdit = worldEdit;
}
/**
* Gets an immutable list of parsers.
*
* To add parsers, use the register method.
*
* @return the parsers
*/
public List<InputParser<E>> getParsers() {
return Collections.unmodifiableList(parsers);
}
public E parseFromInput(String input, ParserContext context) throws InputParseException {
E match;
@ -64,4 +77,14 @@ public abstract class AbstractFactory<E> {
throw new NoMatchException("No match for '" + input + "'");
}
/**
* Registers an InputParser to this factory
*
* @param inputParser The input parser
*/
public void register(InputParser<E> inputParser) {
checkNotNull(inputParser);
parsers.add(inputParser);
}
}

Datei anzeigen

@ -23,6 +23,9 @@ import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
import java.util.Collections;
import java.util.List;
/**
* Input parser interface for {@link AbstractFactory}.
*
@ -33,10 +36,18 @@ public abstract class InputParser<E> {
protected final WorldEdit worldEdit;
protected InputParser(WorldEdit worldEdit) {
public InputParser(WorldEdit worldEdit) {
this.worldEdit = worldEdit;
}
public abstract E parseFromInput(String input, ParserContext context) throws InputParseException;
/**
* Gets a list of suggestions of input to this parser.
*
* @return a list of suggestions
*/
public List<String> getSuggestions() {
return Collections.emptyList();
}
}

Datei anzeigen

@ -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 Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.internal.registry;
import com.google.common.collect.Lists;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
import java.util.List;
/**
* An input parser that only performs a single function from aliases.
*
* @param <E> the element
*/
public abstract class SimpleInputParser<E> extends InputParser<E> {
public SimpleInputParser(WorldEdit worldEdit) {
super(worldEdit);
}
/**
* The strings this parser matches
*
* @return the matching aliases
*/
public abstract List<String> getMatchedAliases();
@Override
public E parseFromInput(String input, ParserContext context) throws InputParseException {
if (!getMatchedAliases().contains(input)) {
return null;
}
return parseFromSimpleInput(input, context);
}
public abstract E parseFromSimpleInput(String input, ParserContext context) throws InputParseException;
/**
* Gets the primary name of this matcher
*
* @return the primary match
*/
public String getPrimaryMatcher() {
return getMatchedAliases().get(0);
}
@Override
public List<String> getSuggestions() {
return Lists.newArrayList(getPrimaryMatcher());
}
}

Datei anzeigen

@ -101,11 +101,11 @@ public class BlockType {
* @return The name, or ID
*/
public String getName() {
BundledBlockData.BlockEntry entry = BundledBlockData.getInstance().findById(this.id);
if (entry == null) {
String name = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry().getName(this);
if (name == null) {
return getId();
} else {
return entry.localizedName;
return name;
}
}

Datei anzeigen

@ -19,10 +19,11 @@
package com.sk89q.worldedit.world.item;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.registry.NamespacedRegistry;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.registry.BundledItemData;
import javax.annotation.Nullable;
@ -50,11 +51,11 @@ public class ItemType {
* @return The name, or ID
*/
public String getName() {
BundledItemData.ItemEntry entry = BundledItemData.getInstance().findById(this.id);
if (entry == null) {
String name = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getItemRegistry().getName(this);
if (name == null) {
return getId();
} else {
return entry.localizedName;
return name;
}
}

Datei anzeigen

@ -31,6 +31,15 @@ import javax.annotation.Nullable;
*/
public interface BlockRegistry {
/**
* Gets the name for the given block.
*
* @param blockType the block
* @return The name, or null if it's unknown
*/
@Nullable
String getName(BlockType blockType);
/**
* Get the material for the given block.
*

Datei anzeigen

@ -33,6 +33,13 @@ import javax.annotation.Nullable;
*/
public class BundledBlockRegistry implements BlockRegistry {
@Nullable
@Override
public String getName(BlockType blockType) {
BundledBlockData.BlockEntry blockEntry = BundledBlockData.getInstance().findById(blockType.getId());
return blockEntry != null ? blockEntry.localizedName : null;
}
@Nullable
@Override
public BlockMaterial getMaterial(BlockType blockType) {

Datei anzeigen

@ -19,9 +19,7 @@
package com.sk89q.worldedit.world.registry;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import javax.annotation.Nullable;
@ -33,8 +31,8 @@ public class BundledItemRegistry implements ItemRegistry {
@Nullable
@Override
public BaseItem createFromId(String id) {
ItemType itemType = ItemTypes.get(id);
return itemType == null ? null : new BaseItem(itemType);
public String getName(ItemType itemType) {
BundledItemData.ItemEntry itemEntry = BundledItemData.getInstance().findById(itemType.getId());
return itemEntry != null ? itemEntry.localizedName : null;
}
}

Datei anzeigen

@ -19,19 +19,19 @@
package com.sk89q.worldedit.world.registry;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.world.item.ItemType;
import javax.annotation.Nullable;
public interface ItemRegistry {
/**
* Create a new item using its ID.
* Gets the name for the given item.
*
* @param id the id
* @return the item, which may be null if no item exists
* @param itemType the item
* @return The name, or null if it's unknown
*/
@Nullable
BaseItem createFromId(String id);
String getName(ItemType itemType);
}

Datei anzeigen

@ -27,16 +27,25 @@ import com.sk89q.worldedit.world.registry.BundledBlockRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.util.ResourceLocation;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
import javax.annotation.Nullable;
public class ForgeBlockRegistry extends BundledBlockRegistry {
private Map<Material, ForgeBlockMaterial> materialMap = new HashMap<>();
@Nullable
@Override
public String getName(BlockType blockType) {
return Block.REGISTRY.getObject(new ResourceLocation(blockType.getId())).getLocalizedName();
}
@Override
public BlockMaterial getMaterial(BlockType blockType) {
return materialMap.computeIfAbsent(Block.getBlockFromName(blockType.getId()).getDefaultState().getMaterial(),

Datei anzeigen

@ -19,23 +19,16 @@
package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.registry.ItemRegistry;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.registry.BundledItemRegistry;
import javax.annotation.Nullable;
public class ForgeItemRegistry implements ItemRegistry {
public class ForgeItemRegistry extends BundledItemRegistry {
@Nullable
@Override
public BaseItem createFromId(String id) {
Item match = Item.REGISTRY.getObject(new ResourceLocation(id));
if (match != null) {
return new BaseItem(ItemTypes.get(id));
} else {
return null;
}
public String getName(ItemType itemType) {
return super.getName(itemType); // TODO
}
}