Fix filtered filter
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package exopandora.worldhandler.builder.impl;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.impl.abstr.BuilderDoubleBlockPos;
|
||||
import exopandora.worldhandler.builder.types.Coordinate.CoordinateType;
|
||||
@@ -19,7 +21,6 @@ public class BuilderClone extends BuilderDoubleBlockPos
|
||||
this.setY(new CoordinateInt(CoordinateType.GLOBAL));
|
||||
this.setZ(new CoordinateInt(CoordinateType.GLOBAL));
|
||||
this.setMask(EnumMask.values()[0]);
|
||||
this.setNode(10, "force");
|
||||
}
|
||||
|
||||
public void setPosition(BlockPos pos)
|
||||
@@ -104,6 +105,30 @@ public class BuilderClone extends BuilderDoubleBlockPos
|
||||
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
|
||||
public String getCommandName()
|
||||
{
|
||||
@@ -133,9 +158,9 @@ public class BuilderClone extends BuilderDoubleBlockPos
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static enum EnumMask
|
||||
{
|
||||
REPLACE,
|
||||
FILTERED,
|
||||
MASKED,
|
||||
FILTERED;
|
||||
REPLACE;
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
|
||||
@@ -1,91 +1,147 @@
|
||||
package exopandora.worldhandler.command;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
|
||||
import exopandora.worldhandler.builder.impl.BuilderClone;
|
||||
import exopandora.worldhandler.builder.impl.BuilderClone.EnumMask;
|
||||
import exopandora.worldhandler.builder.impl.BuilderFill;
|
||||
import exopandora.worldhandler.builder.types.BlockResourceLocation;
|
||||
import exopandora.worldhandler.helper.BlockHelper;
|
||||
import exopandora.worldhandler.helper.CommandHelper;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.command.Commands;
|
||||
import net.minecraft.command.arguments.BlockStateArgument;
|
||||
import net.minecraft.command.arguments.BlockStateInput;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
public class CommandWH
|
||||
{
|
||||
public static void register(CommandDispatcher<CommandSource> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("wh")
|
||||
.then(Commands.literal("pos1")
|
||||
.executes(context -> pos1(context.getSource())))
|
||||
.then(Commands.literal("pos2")
|
||||
.executes(context -> pos2(context.getSource())))
|
||||
.then(Commands.literal("fill")
|
||||
.then(Commands.argument("block", BlockStateArgument.blockState())
|
||||
.executes(context -> fill(context.getSource(), BlockStateArgument.getBlockState(context, "block")))))
|
||||
.then(Commands.literal("replace")
|
||||
.then(Commands.argument("block", BlockStateArgument.blockState())
|
||||
.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("replace")
|
||||
.executes(context -> clone(context.getSource(), EnumMask.REPLACE)))
|
||||
.then(Commands.literal("masked")
|
||||
.executes(context -> clone(context.getSource(), EnumMask.MASKED)))
|
||||
.then(Commands.literal("filtered")
|
||||
.executes(context -> clone(context.getSource(), EnumMask.FILTERED)))));
|
||||
}
|
||||
|
||||
private static int pos1(CommandSource source) throws CommandSyntaxException
|
||||
{
|
||||
BlockHelper.setPos1(BlockHelper.getFocusedBlockPos());
|
||||
BlockPos pos = BlockHelper.getPos1();
|
||||
ResourceLocation block = ForgeRegistries.BLOCKS.getKey(BlockHelper.getBlock(pos));
|
||||
CommandHelper.sendFeedback(source, "Set first position to " + pos.getX() + ", " + pos.getY() + ", " + pos.getZ() + " (" + block + ")");
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int pos2(CommandSource source) throws CommandSyntaxException
|
||||
{
|
||||
BlockHelper.setPos2(BlockHelper.getFocusedBlockPos());
|
||||
BlockPos pos = BlockHelper.getPos2();
|
||||
ResourceLocation block = ForgeRegistries.BLOCKS.getKey(BlockHelper.getBlock(pos));
|
||||
CommandHelper.sendFeedback(source, "Set second position to " + pos.getX() + ", " + pos.getY() + ", " + pos.getZ() + " (" + block + ")");
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int fill(CommandSource source, BlockStateInput block)
|
||||
{
|
||||
BuilderFill builder = new BuilderFill();
|
||||
builder.setBlock1(new BlockResourceLocation(block.getState().getBlock().getRegistryName(), block.getState(), block.tag));
|
||||
CommandHelper.sendCommand(builder);
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int replace(CommandSource source, BlockStateInput block, BlockStateInput replace)
|
||||
{
|
||||
BuilderFill builder = new BuilderFill();
|
||||
builder.setPosition1(BlockHelper.getPos1());
|
||||
builder.setPosition2(BlockHelper.getPos2());
|
||||
builder.setBlock1(new BlockResourceLocation(block.getState().getBlock().getRegistryName(), block.getState(), block.tag));
|
||||
builder.setBlock2(new BlockResourceLocation(replace.getState().getBlock().getRegistryName(), replace.getState(), replace.tag));
|
||||
CommandHelper.sendCommand(builder);
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int clone(CommandSource source, EnumMask mask)
|
||||
{
|
||||
BuilderClone builder = new BuilderClone();
|
||||
builder.setPosition1(BlockHelper.getPos1());
|
||||
builder.setPosition2(BlockHelper.getPos2());
|
||||
builder.setMask(mask);
|
||||
CommandHelper.sendCommand(builder);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
package exopandora.worldhandler.command;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
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.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
|
||||
import exopandora.worldhandler.builder.impl.BuilderClone;
|
||||
import exopandora.worldhandler.builder.impl.BuilderClone.EnumMask;
|
||||
import exopandora.worldhandler.builder.impl.BuilderFill;
|
||||
import exopandora.worldhandler.builder.types.BlockResourceLocation;
|
||||
import exopandora.worldhandler.helper.BlockHelper;
|
||||
import exopandora.worldhandler.helper.CommandHelper;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.command.Commands;
|
||||
import net.minecraft.command.arguments.BlockPredicateArgument;
|
||||
import net.minecraft.command.arguments.BlockStateArgument;
|
||||
import net.minecraft.command.arguments.BlockStateInput;
|
||||
import net.minecraft.command.arguments.BlockStateParser;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
public class CommandWH
|
||||
{
|
||||
public static void register(CommandDispatcher<CommandSource> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("wh")
|
||||
.then(Commands.literal("pos1")
|
||||
.executes(context -> pos1(context.getSource())))
|
||||
.then(Commands.literal("pos2")
|
||||
.executes(context -> pos2(context.getSource())))
|
||||
.then(Commands.literal("fill")
|
||||
.requires(context -> context.hasPermissionLevel(2))
|
||||
.then(Commands.argument("block", BlockStateArgument.blockState())
|
||||
.executes(context -> fill(context.getSource(), BlockStateArgument.getBlockState(context, "block")))))
|
||||
.then(Commands.literal("replace")
|
||||
.requires(context -> context.hasPermissionLevel(2))
|
||||
.then(Commands.argument("block", BlockStateArgument.blockState())
|
||||
.then(Commands.argument("replace", BlockStateArgument.blockState())
|
||||
.executes(context -> replace(context.getSource(), BlockStateArgument.getBlockState(context, "block"), BlockStateArgument.getBlockState(context, "replace"))))))
|
||||
.then(Commands.literal("clone")
|
||||
.requires(context -> context.hasPermissionLevel(2))
|
||||
.executes(context -> clone(context.getSource(), EnumMask.MASKED))
|
||||
.then(Commands.literal("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
|
||||
{
|
||||
BlockHelper.setPos1(BlockHelper.getFocusedBlockPos());
|
||||
BlockPos pos = BlockHelper.getPos1();
|
||||
ResourceLocation block = ForgeRegistries.BLOCKS.getKey(BlockHelper.getBlock(pos));
|
||||
CommandHelper.sendFeedback(source, "Set first position to " + pos.getX() + ", " + pos.getY() + ", " + pos.getZ() + " (" + block + ")");
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int pos2(CommandSource source) throws CommandSyntaxException
|
||||
{
|
||||
BlockHelper.setPos2(BlockHelper.getFocusedBlockPos());
|
||||
BlockPos pos = BlockHelper.getPos2();
|
||||
ResourceLocation block = ForgeRegistries.BLOCKS.getKey(BlockHelper.getBlock(pos));
|
||||
CommandHelper.sendFeedback(source, "Set second position to " + pos.getX() + ", " + pos.getY() + ", " + pos.getZ() + " (" + block + ")");
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int fill(CommandSource source, BlockStateInput block)
|
||||
{
|
||||
BuilderFill builder = new BuilderFill();
|
||||
builder.setBlock1(new BlockResourceLocation(block.getState().getBlock().getRegistryName(), block.getState(), block.tag));
|
||||
CommandHelper.sendCommand(builder);
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int replace(CommandSource source, BlockStateInput block, BlockStateInput replace)
|
||||
{
|
||||
BuilderFill builder = new BuilderFill();
|
||||
builder.setPosition1(BlockHelper.getPos1());
|
||||
builder.setPosition2(BlockHelper.getPos2());
|
||||
builder.setBlock1(new BlockResourceLocation(block.getState().getBlock().getRegistryName(), block.getState(), block.tag));
|
||||
builder.setBlock2(new BlockResourceLocation(replace.getState().getBlock().getRegistryName(), replace.getState(), replace.tag));
|
||||
CommandHelper.sendCommand(builder);
|
||||
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)
|
||||
{
|
||||
BuilderClone builder = new BuilderClone();
|
||||
builder.setPosition1(BlockHelper.getPos1());
|
||||
builder.setPosition2(BlockHelper.getPos2());
|
||||
builder.setMask(mask);
|
||||
CommandHelper.sendCommand(builder);
|
||||
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.Predicates;
|
||||
import com.mojang.brigadier.StringReader;
|
||||
|
||||
import exopandora.worldhandler.builder.ICommandBuilder;
|
||||
import exopandora.worldhandler.builder.impl.BuilderClone;
|
||||
import exopandora.worldhandler.builder.impl.BuilderClone.EnumMask;
|
||||
import exopandora.worldhandler.builder.impl.BuilderFill;
|
||||
import exopandora.worldhandler.builder.impl.BuilderWH;
|
||||
import exopandora.worldhandler.command.CommandWH.StringBlockPredicateArgument;
|
||||
import exopandora.worldhandler.gui.button.GuiButtonBase;
|
||||
import exopandora.worldhandler.gui.button.GuiButtonList;
|
||||
import exopandora.worldhandler.gui.button.GuiTextFieldTooltip;
|
||||
@@ -42,12 +44,15 @@ public class ContentEditBlocks extends Content
|
||||
private GuiTextFieldTooltip block1Field;
|
||||
private GuiTextFieldTooltip block2Field;
|
||||
|
||||
private GuiTextFieldTooltip filterField;
|
||||
|
||||
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 BuilderWH builderWH = new BuilderWH();
|
||||
|
||||
private String block1;
|
||||
private String block2;
|
||||
private String filter;
|
||||
|
||||
private String selectedPage = "coordinates";
|
||||
|
||||
@@ -140,6 +145,16 @@ public class ContentEditBlocks extends Content
|
||||
this.builderFill.setBlock2(this.block2);
|
||||
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
|
||||
@@ -236,11 +251,23 @@ public class ContentEditBlocks extends Content
|
||||
{
|
||||
button4.active = false;
|
||||
|
||||
yOffset1 = 24;
|
||||
yOffset1 = 48;
|
||||
yOffset2 = 48;
|
||||
width1 = 114;
|
||||
width2 = 114;
|
||||
xOffset2 = 0;
|
||||
width1 = 56;
|
||||
width2 = 56;
|
||||
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>()
|
||||
{
|
||||
@@ -260,6 +287,7 @@ public class ContentEditBlocks extends Content
|
||||
public void onClick(EnumMask item)
|
||||
{
|
||||
ContentEditBlocks.this.builderClone.setMask(item);
|
||||
container.init();
|
||||
}
|
||||
|
||||
@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);
|
||||
}));
|
||||
|
||||
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"), () ->
|
||||
@@ -309,6 +349,13 @@ public class ContentEditBlocks extends Content
|
||||
this.block1Field.tick();
|
||||
this.block2Field.tick();
|
||||
}
|
||||
else if(this.selectedPage.equals("clone"))
|
||||
{
|
||||
if(EnumMask.FILTERED.equals(this.builderClone.getMask()))
|
||||
{
|
||||
this.filterField.tick();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -333,6 +380,13 @@ public class ContentEditBlocks extends Content
|
||||
this.block1Field.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)
|
||||
|
||||
@@ -250,6 +250,8 @@
|
||||
|
||||
"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.masked": "Maskiert",
|
||||
"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.clone.filter": "Filter",
|
||||
|
||||
"gui.worldhandler.edit_blocks.clone.mode.replace": "Replace",
|
||||
"gui.worldhandler.edit_blocks.clone.mode.masked": "Masked",
|
||||
"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.clone.filter": "滤波器",
|
||||
|
||||
"gui.worldhandler.edit_blocks.clone.mode.replace": "替换",
|
||||
"gui.worldhandler.edit_blocks.clone.mode.masked": "叠加",
|
||||
"gui.worldhandler.edit_blocks.clone.mode.filtered": "仅指定方块",
|
||||
|
||||
Reference in New Issue
Block a user