Fix filtered filter
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
package exopandora.worldhandler.builder.impl;
|
package exopandora.worldhandler.builder.impl;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import exopandora.worldhandler.builder.Syntax;
|
import exopandora.worldhandler.builder.Syntax;
|
||||||
import exopandora.worldhandler.builder.impl.abstr.BuilderDoubleBlockPos;
|
import exopandora.worldhandler.builder.impl.abstr.BuilderDoubleBlockPos;
|
||||||
import exopandora.worldhandler.builder.types.Coordinate.CoordinateType;
|
import exopandora.worldhandler.builder.types.Coordinate.CoordinateType;
|
||||||
@@ -19,7 +21,6 @@ public class BuilderClone extends BuilderDoubleBlockPos
|
|||||||
this.setY(new CoordinateInt(CoordinateType.GLOBAL));
|
this.setY(new CoordinateInt(CoordinateType.GLOBAL));
|
||||||
this.setZ(new CoordinateInt(CoordinateType.GLOBAL));
|
this.setZ(new CoordinateInt(CoordinateType.GLOBAL));
|
||||||
this.setMask(EnumMask.values()[0]);
|
this.setMask(EnumMask.values()[0]);
|
||||||
this.setNode(10, "force");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPosition(BlockPos pos)
|
public void setPosition(BlockPos pos)
|
||||||
@@ -104,6 +105,30 @@ public class BuilderClone extends BuilderDoubleBlockPos
|
|||||||
return EnumHelper.valueOf(this.getNodeAsString(9), EnumMask.class);
|
return EnumHelper.valueOf(this.getNodeAsString(9), EnumMask.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setFilter(String filter)
|
||||||
|
{
|
||||||
|
if(filter != null)
|
||||||
|
{
|
||||||
|
this.setMask(EnumMask.FILTERED);
|
||||||
|
this.setNode(10, filter);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.setNode(10, filter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public String getFilter()
|
||||||
|
{
|
||||||
|
if(EnumMask.FILTERED.equals(this.getMask()))
|
||||||
|
{
|
||||||
|
return this.getNodeAsString(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCommandName()
|
public String getCommandName()
|
||||||
{
|
{
|
||||||
@@ -133,9 +158,9 @@ public class BuilderClone extends BuilderDoubleBlockPos
|
|||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public static enum EnumMask
|
public static enum EnumMask
|
||||||
{
|
{
|
||||||
REPLACE,
|
FILTERED,
|
||||||
MASKED,
|
MASKED,
|
||||||
FILTERED;
|
REPLACE;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
|
|||||||
@@ -1,7 +1,14 @@
|
|||||||
package exopandora.worldhandler.command;
|
package exopandora.worldhandler.command;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
|
import com.mojang.brigadier.StringReader;
|
||||||
|
import com.mojang.brigadier.arguments.ArgumentType;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import com.mojang.brigadier.suggestion.Suggestions;
|
||||||
|
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||||
|
|
||||||
import exopandora.worldhandler.builder.impl.BuilderClone;
|
import exopandora.worldhandler.builder.impl.BuilderClone;
|
||||||
import exopandora.worldhandler.builder.impl.BuilderClone.EnumMask;
|
import exopandora.worldhandler.builder.impl.BuilderClone.EnumMask;
|
||||||
@@ -11,8 +18,10 @@ import exopandora.worldhandler.helper.BlockHelper;
|
|||||||
import exopandora.worldhandler.helper.CommandHelper;
|
import exopandora.worldhandler.helper.CommandHelper;
|
||||||
import net.minecraft.command.CommandSource;
|
import net.minecraft.command.CommandSource;
|
||||||
import net.minecraft.command.Commands;
|
import net.minecraft.command.Commands;
|
||||||
|
import net.minecraft.command.arguments.BlockPredicateArgument;
|
||||||
import net.minecraft.command.arguments.BlockStateArgument;
|
import net.minecraft.command.arguments.BlockStateArgument;
|
||||||
import net.minecraft.command.arguments.BlockStateInput;
|
import net.minecraft.command.arguments.BlockStateInput;
|
||||||
|
import net.minecraft.command.arguments.BlockStateParser;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
@@ -27,19 +36,24 @@ public class CommandWH
|
|||||||
.then(Commands.literal("pos2")
|
.then(Commands.literal("pos2")
|
||||||
.executes(context -> pos2(context.getSource())))
|
.executes(context -> pos2(context.getSource())))
|
||||||
.then(Commands.literal("fill")
|
.then(Commands.literal("fill")
|
||||||
.then(Commands.argument("block", BlockStateArgument.blockState())
|
.requires(context -> context.hasPermissionLevel(2))
|
||||||
.executes(context -> fill(context.getSource(), BlockStateArgument.getBlockState(context, "block")))))
|
.then(Commands.argument("block", BlockStateArgument.blockState())
|
||||||
|
.executes(context -> fill(context.getSource(), BlockStateArgument.getBlockState(context, "block")))))
|
||||||
.then(Commands.literal("replace")
|
.then(Commands.literal("replace")
|
||||||
.then(Commands.argument("block", BlockStateArgument.blockState())
|
.requires(context -> context.hasPermissionLevel(2))
|
||||||
.then(Commands.argument("replace", BlockStateArgument.blockState())
|
.then(Commands.argument("block", BlockStateArgument.blockState())
|
||||||
.executes(context -> replace(context.getSource(), BlockStateArgument.getBlockState(context, "block"), BlockStateArgument.getBlockState(context, "replace"))))))
|
.then(Commands.argument("replace", BlockStateArgument.blockState())
|
||||||
|
.executes(context -> replace(context.getSource(), BlockStateArgument.getBlockState(context, "block"), BlockStateArgument.getBlockState(context, "replace"))))))
|
||||||
.then(Commands.literal("clone")
|
.then(Commands.literal("clone")
|
||||||
.then(Commands.literal("replace")
|
.requires(context -> context.hasPermissionLevel(2))
|
||||||
.executes(context -> clone(context.getSource(), EnumMask.REPLACE)))
|
.executes(context -> clone(context.getSource(), EnumMask.MASKED))
|
||||||
.then(Commands.literal("masked")
|
|
||||||
.executes(context -> clone(context.getSource(), EnumMask.MASKED)))
|
|
||||||
.then(Commands.literal("filtered")
|
.then(Commands.literal("filtered")
|
||||||
.executes(context -> clone(context.getSource(), EnumMask.FILTERED)))));
|
.then(Commands.argument("filter", StringBlockPredicateArgument.blockPredicate())
|
||||||
|
.executes(context -> clone(context.getSource(), StringBlockPredicateArgument.getBlockPredicate(context, "filter")))))
|
||||||
|
.then(Commands.literal("masked")
|
||||||
|
.executes(context -> clone(context.getSource(), EnumMask.MASKED)))
|
||||||
|
.then(Commands.literal("replace")
|
||||||
|
.executes(context -> clone(context.getSource(), EnumMask.REPLACE)))));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int pos1(CommandSource source) throws CommandSyntaxException
|
private static int pos1(CommandSource source) throws CommandSyntaxException
|
||||||
@@ -79,6 +93,16 @@ public class CommandWH
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int clone(CommandSource source, String filter)
|
||||||
|
{
|
||||||
|
BuilderClone builder = new BuilderClone();
|
||||||
|
builder.setPosition1(BlockHelper.getPos1());
|
||||||
|
builder.setPosition2(BlockHelper.getPos2());
|
||||||
|
builder.setFilter(filter);
|
||||||
|
CommandHelper.sendCommand(builder);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
private static int clone(CommandSource source, EnumMask mask)
|
private static int clone(CommandSource source, EnumMask mask)
|
||||||
{
|
{
|
||||||
BuilderClone builder = new BuilderClone();
|
BuilderClone builder = new BuilderClone();
|
||||||
@@ -88,4 +112,36 @@ public class CommandWH
|
|||||||
CommandHelper.sendCommand(builder);
|
CommandHelper.sendCommand(builder);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class StringBlockPredicateArgument implements ArgumentType<String>
|
||||||
|
{
|
||||||
|
public static StringBlockPredicateArgument blockPredicate()
|
||||||
|
{
|
||||||
|
return new StringBlockPredicateArgument();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String parse(StringReader reader) throws CommandSyntaxException
|
||||||
|
{
|
||||||
|
BlockStateParser blockstateparser = new BlockStateParser(reader, true).parse(true);
|
||||||
|
|
||||||
|
if(blockstateparser.getState() != null)
|
||||||
|
{
|
||||||
|
return new BlockResourceLocation(blockstateparser.getState().getBlock().getRegistryName(), blockstateparser.getState(), blockstateparser.getNbt()).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return "#" + blockstateparser.getTag();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getBlockPredicate(CommandContext<CommandSource> context, String name) throws CommandSyntaxException
|
||||||
|
{
|
||||||
|
return context.getArgument(name, String.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder)
|
||||||
|
{
|
||||||
|
return BlockPredicateArgument.blockPredicate().listSuggestions(context, builder);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,12 +4,14 @@ import java.util.Arrays;
|
|||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Predicates;
|
import com.google.common.base.Predicates;
|
||||||
|
import com.mojang.brigadier.StringReader;
|
||||||
|
|
||||||
import exopandora.worldhandler.builder.ICommandBuilder;
|
import exopandora.worldhandler.builder.ICommandBuilder;
|
||||||
import exopandora.worldhandler.builder.impl.BuilderClone;
|
import exopandora.worldhandler.builder.impl.BuilderClone;
|
||||||
import exopandora.worldhandler.builder.impl.BuilderClone.EnumMask;
|
import exopandora.worldhandler.builder.impl.BuilderClone.EnumMask;
|
||||||
import exopandora.worldhandler.builder.impl.BuilderFill;
|
import exopandora.worldhandler.builder.impl.BuilderFill;
|
||||||
import exopandora.worldhandler.builder.impl.BuilderWH;
|
import exopandora.worldhandler.builder.impl.BuilderWH;
|
||||||
|
import exopandora.worldhandler.command.CommandWH.StringBlockPredicateArgument;
|
||||||
import exopandora.worldhandler.gui.button.GuiButtonBase;
|
import exopandora.worldhandler.gui.button.GuiButtonBase;
|
||||||
import exopandora.worldhandler.gui.button.GuiButtonList;
|
import exopandora.worldhandler.gui.button.GuiButtonList;
|
||||||
import exopandora.worldhandler.gui.button.GuiTextFieldTooltip;
|
import exopandora.worldhandler.gui.button.GuiTextFieldTooltip;
|
||||||
@@ -42,12 +44,15 @@ public class ContentEditBlocks extends Content
|
|||||||
private GuiTextFieldTooltip block1Field;
|
private GuiTextFieldTooltip block1Field;
|
||||||
private GuiTextFieldTooltip block2Field;
|
private GuiTextFieldTooltip block2Field;
|
||||||
|
|
||||||
|
private GuiTextFieldTooltip filterField;
|
||||||
|
|
||||||
private final BuilderFill builderFill = BlockHelper.addPositionObservers(new BuilderFill(), builder -> builder::setPosition1, builder -> builder::setPosition2);
|
private final BuilderFill builderFill = BlockHelper.addPositionObservers(new BuilderFill(), builder -> builder::setPosition1, builder -> builder::setPosition2);
|
||||||
private final BuilderClone builderClone = BlockHelper.addPositionObservers(new BuilderClone(), builder -> builder::setPosition1, builder -> builder::setPosition2);
|
private final BuilderClone builderClone = BlockHelper.addPositionObservers(new BuilderClone(), builder -> builder::setPosition1, builder -> builder::setPosition2);
|
||||||
private final BuilderWH builderWH = new BuilderWH();
|
private final BuilderWH builderWH = new BuilderWH();
|
||||||
|
|
||||||
private String block1;
|
private String block1;
|
||||||
private String block2;
|
private String block2;
|
||||||
|
private String filter;
|
||||||
|
|
||||||
private String selectedPage = "coordinates";
|
private String selectedPage = "coordinates";
|
||||||
|
|
||||||
@@ -140,6 +145,16 @@ public class ContentEditBlocks extends Content
|
|||||||
this.builderFill.setBlock2(this.block2);
|
this.builderFill.setBlock2(this.block2);
|
||||||
container.initButtons();
|
container.initButtons();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.filterField = new GuiTextFieldTooltip(x + 118, y + 24, 114, 20, I18n.format("gui.worldhandler.edit_blocks.clone.filter"));
|
||||||
|
this.filterField.setValidator(Predicates.notNull());
|
||||||
|
this.filterField.setText(this.filter);
|
||||||
|
this.filterField.func_212954_a(text ->
|
||||||
|
{
|
||||||
|
this.filter = text;
|
||||||
|
this.builderClone.setFilter(this.filter);
|
||||||
|
container.initButtons();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -236,11 +251,23 @@ public class ContentEditBlocks extends Content
|
|||||||
{
|
{
|
||||||
button4.active = false;
|
button4.active = false;
|
||||||
|
|
||||||
yOffset1 = 24;
|
yOffset1 = 48;
|
||||||
yOffset2 = 48;
|
yOffset2 = 48;
|
||||||
width1 = 114;
|
width1 = 56;
|
||||||
width2 = 114;
|
width2 = 56;
|
||||||
xOffset2 = 0;
|
xOffset2 = 58;
|
||||||
|
|
||||||
|
if(EnumMask.FILTERED.equals(this.builderClone.getMask()))
|
||||||
|
{
|
||||||
|
this.builderClone.setFilter(this.filter);
|
||||||
|
container.add(this.filterField);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.builderClone.setFilter(null);
|
||||||
|
container.add(button1 = new GuiButtonBase(x + 118, y + 24, 114, 20, null, null));
|
||||||
|
button1.active = false;
|
||||||
|
}
|
||||||
|
|
||||||
container.add(new GuiButtonList<EnumMask>(x + 118, y, Arrays.asList(EnumMask.values()), 114, 20, container, new ILogicMapped<EnumMask>()
|
container.add(new GuiButtonList<EnumMask>(x + 118, y, Arrays.asList(EnumMask.values()), 114, 20, container, new ILogicMapped<EnumMask>()
|
||||||
{
|
{
|
||||||
@@ -260,6 +287,7 @@ public class ContentEditBlocks extends Content
|
|||||||
public void onClick(EnumMask item)
|
public void onClick(EnumMask item)
|
||||||
{
|
{
|
||||||
ContentEditBlocks.this.builderClone.setMask(item);
|
ContentEditBlocks.this.builderClone.setMask(item);
|
||||||
|
container.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -269,10 +297,22 @@ public class ContentEditBlocks extends Content
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
container.add(new GuiButtonBase(x + 118, y + 72, 114, 20, I18n.format("gui.worldhandler.edit_blocks.clone"), () ->
|
container.add(button2 = new GuiButtonBase(x + 118, y + 72, 114, 20, I18n.format("gui.worldhandler.edit_blocks.clone"), () ->
|
||||||
{
|
{
|
||||||
CommandHelper.sendCommand(this.builderClone);
|
CommandHelper.sendCommand(this.builderClone);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if(EnumMask.FILTERED.equals(this.builderClone.getMask()))
|
||||||
|
{
|
||||||
|
StringBlockPredicateArgument.blockPredicate().parse(new StringReader(this.builderClone.getFilter()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
button2.active = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
container.add(new GuiButtonBase(x + 118, y + yOffset1, width1, 20, I18n.format("gui.worldhandler.edit_blocks.pos.set_pos_1"), () ->
|
container.add(new GuiButtonBase(x + 118, y + yOffset1, width1, 20, I18n.format("gui.worldhandler.edit_blocks.pos.set_pos_1"), () ->
|
||||||
@@ -309,6 +349,13 @@ public class ContentEditBlocks extends Content
|
|||||||
this.block1Field.tick();
|
this.block1Field.tick();
|
||||||
this.block2Field.tick();
|
this.block2Field.tick();
|
||||||
}
|
}
|
||||||
|
else if(this.selectedPage.equals("clone"))
|
||||||
|
{
|
||||||
|
if(EnumMask.FILTERED.equals(this.builderClone.getMask()))
|
||||||
|
{
|
||||||
|
this.filterField.tick();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -333,6 +380,13 @@ public class ContentEditBlocks extends Content
|
|||||||
this.block1Field.renderButton(mouseX, mouseY, partialTicks);
|
this.block1Field.renderButton(mouseX, mouseY, partialTicks);
|
||||||
this.block2Field.renderButton(mouseX, mouseY, partialTicks);
|
this.block2Field.renderButton(mouseX, mouseY, partialTicks);
|
||||||
}
|
}
|
||||||
|
else if(this.selectedPage.equals("clone"))
|
||||||
|
{
|
||||||
|
if(EnumMask.FILTERED.equals(this.builderClone.getMask()))
|
||||||
|
{
|
||||||
|
this.filterField.renderButton(mouseX, mouseY, partialTicks);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Predicate<String> getCoordinatePredicate(String coordinate)
|
private Predicate<String> getCoordinatePredicate(String coordinate)
|
||||||
|
|||||||
@@ -250,6 +250,8 @@
|
|||||||
|
|
||||||
"gui.worldhandler.edit_blocks.fill.block_id_to_fill": "Block ID Füllen",
|
"gui.worldhandler.edit_blocks.fill.block_id_to_fill": "Block ID Füllen",
|
||||||
|
|
||||||
|
"gui.worldhandler.edit_blocks.clone.filter": "Filter",
|
||||||
|
|
||||||
"gui.worldhandler.edit_blocks.clone.mode.replace": "Ersetzen",
|
"gui.worldhandler.edit_blocks.clone.mode.replace": "Ersetzen",
|
||||||
"gui.worldhandler.edit_blocks.clone.mode.masked": "Maskiert",
|
"gui.worldhandler.edit_blocks.clone.mode.masked": "Maskiert",
|
||||||
"gui.worldhandler.edit_blocks.clone.mode.filtered": "Gefiltert",
|
"gui.worldhandler.edit_blocks.clone.mode.filtered": "Gefiltert",
|
||||||
|
|||||||
@@ -249,6 +249,8 @@
|
|||||||
|
|
||||||
"gui.worldhandler.edit_blocks.fill.block_id_to_fill": "Block ID To Fill",
|
"gui.worldhandler.edit_blocks.fill.block_id_to_fill": "Block ID To Fill",
|
||||||
|
|
||||||
|
"gui.worldhandler.edit_blocks.clone.filter": "Filter",
|
||||||
|
|
||||||
"gui.worldhandler.edit_blocks.clone.mode.replace": "Replace",
|
"gui.worldhandler.edit_blocks.clone.mode.replace": "Replace",
|
||||||
"gui.worldhandler.edit_blocks.clone.mode.masked": "Masked",
|
"gui.worldhandler.edit_blocks.clone.mode.masked": "Masked",
|
||||||
"gui.worldhandler.edit_blocks.clone.mode.filtered": "Filtered",
|
"gui.worldhandler.edit_blocks.clone.mode.filtered": "Filtered",
|
||||||
|
|||||||
@@ -250,6 +250,8 @@
|
|||||||
|
|
||||||
"gui.worldhandler.edit_blocks.fill.block_id_to_fill": "填充方块 ID",
|
"gui.worldhandler.edit_blocks.fill.block_id_to_fill": "填充方块 ID",
|
||||||
|
|
||||||
|
"gui.worldhandler.edit_blocks.clone.filter": "滤波器",
|
||||||
|
|
||||||
"gui.worldhandler.edit_blocks.clone.mode.replace": "替换",
|
"gui.worldhandler.edit_blocks.clone.mode.replace": "替换",
|
||||||
"gui.worldhandler.edit_blocks.clone.mode.masked": "叠加",
|
"gui.worldhandler.edit_blocks.clone.mode.masked": "叠加",
|
||||||
"gui.worldhandler.edit_blocks.clone.mode.filtered": "仅指定方块",
|
"gui.worldhandler.edit_blocks.clone.mode.filtered": "仅指定方块",
|
||||||
|
|||||||
Reference in New Issue
Block a user