Update to 1.18

Rewrite command builders
Usercontent api v2
This commit is contained in:
Marcel Konrad
2021-12-02 12:45:25 +01:00
parent 915ce2cad2
commit 7951c13bc5
153 changed files with 1821 additions and 8360 deletions

View File

@@ -1,323 +1,77 @@
package exopandora.worldhandler.builder;
import java.util.AbstractMap.SimpleEntry;
import java.util.List;
import java.util.Map.Entry;
import java.util.function.BiFunction;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import exopandora.worldhandler.WorldHandler;
import exopandora.worldhandler.builder.CommandSyntax.Argument;
import exopandora.worldhandler.builder.types.ArgumentType;
import exopandora.worldhandler.builder.types.BlockResourceLocation;
import exopandora.worldhandler.builder.types.CoordinateDouble;
import exopandora.worldhandler.builder.types.CoordinateInt;
import exopandora.worldhandler.builder.types.GreedyString;
import exopandora.worldhandler.builder.types.ItemResourceLocation;
import exopandora.worldhandler.builder.types.TargetSelector;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
public abstract class CommandBuilder implements ICommandBuilderSyntax
public abstract class CommandBuilder implements ICommandBuilder
{
private List<Entry<Argument, String>> command;
protected abstract CommandNodeLiteral root();
public CommandBuilder()
public String toCommand(Object label, boolean preview)
{
this.updateSyntax(this.getSyntax());
}
protected void setNode(int index, String node)
{
this.set(index, node != null && !node.isEmpty() ? node : null, ArgumentType.STRING);
}
protected void setNode(int index, GreedyString node)
{
this.set(index, node != null && !node.isEmpty() ? node : null, ArgumentType.GREEDY_STRING);
}
protected void setNode(int index, boolean node)
{
this.set(index, node, ArgumentType.BOOLEAN);
}
protected void setNode(int index, short node)
{
this.set(index, node, ArgumentType.SHORT);
}
protected void setNode(int index, byte node)
{
this.set(index, node, ArgumentType.BYTE);
}
protected void setNode(int index, int node)
{
this.set(index, node, ArgumentType.INT);
}
protected void setNode(int index, float node)
{
this.set(index, node, ArgumentType.FLOAT);
}
protected void setNode(int index, double node)
{
this.set(index, node, ArgumentType.DOUBLE);
}
protected void setNode(int index, long node)
{
this.set(index, node, ArgumentType.LONG);
}
protected void setNode(int index, ResourceLocation node)
{
this.set(index, node, ArgumentType.RESOURCE_LOCATION);
}
protected void setNode(int index, CoordinateInt coordinate)
{
this.set(index, coordinate, ArgumentType.COORDINATE_INT);
}
protected void setNode(int index, CoordinateDouble coordinate)
{
this.set(index, coordinate, ArgumentType.COORDINATE_DOUBLE);
}
protected void setNode(int index, TargetSelector target)
{
this.set(index, target, ArgumentType.TARGET_SELECTOR);
}
protected void setNode(int index, ItemResourceLocation resource)
{
this.set(index, resource, ArgumentType.ITEM_RESOURCE_LOCATION);
}
protected void setNode(int index, BlockResourceLocation resource)
{
this.set(index, resource, ArgumentType.BLOCK_RESOURCE_LOCATION);
}
protected void setNode(int index, CompoundTag nbt)
{
this.set(index, nbt, ArgumentType.NBT);
}
protected void setPlayerName(int index, String username)
{
this.set(index, username != null && !username.isEmpty() ? username : null, ArgumentType.PLAYER);
}
private void set(int index, Object value, ArgumentType type)
{
if(index < this.command.size())
CommandNode<?> node = this.root().find(label).orElse(this.root());
if(preview)
{
Argument entry = this.command.get(index).getKey();
ArgumentType expectedType = entry.getType();
boolean typeMatch = expectedType.equals(type);
if(value != null && typeMatch)
{
this.command.get(index).setValue(value.toString());
}
else
{
this.command.get(index).setValue(entry.toString());
if(!typeMatch)
{
this.warn("set", expectedType, type, index);
}
}
}
else
{
WorldHandler.LOGGER.warn("Tried to set invalid index \"" + index + "\" for command \"" + this.getCommandName() + "\"");
}
}
@Nullable
protected String getNodeAsString(int index)
{
return this.get(index, ArgumentType.STRING);
}
@Nullable
protected String getNodeAsGreedyString(int index)
{
return this.get(index, ArgumentType.GREEDY_STRING);
}
protected boolean getNodeAsBoolean(int index)
{
return this.get(index, ArgumentType.BOOLEAN);
}
protected short getNodeAsShort(int index)
{
return this.get(index, ArgumentType.SHORT);
}
protected byte getNodeAsByte(int index)
{
return this.get(index, ArgumentType.BYTE);
}
protected int getNodeAsInt(int index)
{
return this.get(index, ArgumentType.INT);
}
protected float getNodeAsFloat(int index)
{
return this.get(index, ArgumentType.FLOAT);
}
protected double getNodeAsDouble(int index)
{
return this.get(index, ArgumentType.DOUBLE);
}
protected long getNodeAsLong(int index)
{
return this.get(index, ArgumentType.LONG);
}
@Nonnull
protected CoordinateInt getNodeAsCoordinateInt(int index)
{
return this.get(index, ArgumentType.COORDINATE_INT);
}
@Nonnull
protected CoordinateDouble getNodeAsCoordinateDouble(int index)
{
return this.get(index, ArgumentType.COORDINATE_DOUBLE);
}
@Nullable
protected ResourceLocation getNodeAsResourceLocation(int index)
{
return this.get(index, ArgumentType.RESOURCE_LOCATION);
}
@Nonnull
protected TargetSelector getNodeAsTargetSelector(int index)
{
return this.get(index, ArgumentType.TARGET_SELECTOR);
}
@Nullable
protected ItemResourceLocation getNodeAsItemResourceLocation(int index)
{
return this.get(index, ArgumentType.ITEM_RESOURCE_LOCATION);
}
@Nullable
protected BlockResourceLocation getNodeAsBlockResourceLocation(int index)
{
return this.get(index, ArgumentType.BLOCK_RESOURCE_LOCATION);
}
@Nullable
protected CompoundTag getNodeAsNBT(int index)
{
return this.get(index, ArgumentType.NBT);
}
@Nullable
private <T> T get(int index, ArgumentType type)
{
if(index < this.command.size())
{
Entry<Argument, String> entry = this.command.get(index);
ArgumentType expected = entry.getKey().getType();
String value = entry.getValue();
if(expected.equals(type))
{
if(value.equals(entry.getKey().toString()))
{
return null;
}
return expected.<T>parse(value);
}
this.warn("get", expected, type, index);
return type.<T>parse(value);
return this.buildForward(node, label, CommandNode::toValue).toString();
}
return null;
return this.buildReverse(node, label, CommandNode::toValue, false).toString();
}
private void warn(String function, ArgumentType expected, ArgumentType type, int index)
protected StringBuilder buildForward(CommandNode<?> node, Object label, BiFunction<CommandNode<?>, Object, String> valueMapper)
{
WorldHandler.LOGGER.warn("[" + function.toUpperCase() + "] Expected \"" + expected + "\" instead of \"" + type + "\" at index \"" + index + "\" for command \"" + this.getCommandName() + "\"");
}
private boolean isDefaultArgument(Argument argument, String value)
{
return argument.getDefault() != null ? value.equals(argument.getDefault().toString()) : value == null;
}
protected void updateSyntax(CommandSyntax syntax)
{
if(syntax != null)
{
this.command = syntax.getArguments().stream().map(entry -> new SimpleEntry<Argument, String>(entry, entry.toString())).collect(Collectors.toList());
}
}
@Override
public String toCommand()
{
CommandString command = new CommandString(this.getCommandName());
StringBuilder builder = this.buildReverse(node, label, valueMapper, true);
for(Entry<Argument, String> entry : this.command)
if(builder.isEmpty())
{
if(this.isDefaultArgument(entry.getKey(), entry.getValue()))
return builder;
}
if(node != null)
{
List<CommandNode<?>> children = node.getChildren();
while(children != null && children.size() == 1)
{
command.append(entry.getKey().toString());
node = children.get(0);
builder.append(" ");
builder.append(valueMapper.apply(children.get(0), label));
children = node.getChildren();
}
else
if(children != null && children.size() > 0)
{
command.append(entry.getValue());
builder.append(children.stream().map(child -> valueMapper.apply(child, label)).collect(Collectors.joining("|", " [", "]")));
}
}
return command.toString();
return builder;
}
@Override
public String toActualCommand()
protected StringBuilder buildReverse(@Nullable CommandNode<?> node, Object label, BiFunction<CommandNode<?>, Object, String> valueMapper, boolean includeOptionals)
{
CommandString command = new CommandString(this.getCommandName());
StringBuilder builder = new StringBuilder();
for(Entry<Argument, String> entry : this.command)
while(node != null)
{
if(!entry.getKey().isRequired() && (entry.getKey().toString().equals(entry.getValue()) || this.isDefaultArgument(entry.getKey(), entry.getValue())))
CommandNode<?> parent = node.getParent();
if(parent == null)
{
break;
builder.insert(0, "/" + valueMapper.apply(node, label));
}
else if(includeOptionals || !builder.isEmpty() || !node.isOptional(label) || !node.isDefault(label))
{
builder.insert(0, " " + valueMapper.apply(node, label));
}
if(entry.getKey().isRequired() && entry.getKey().toString().equals(entry.getValue()) && entry.getKey().getDefault() != null)
{
command.append(entry.getKey().getDefault().toString());
}
else
{
command.append(entry.getValue());
}
node = parent;
}
return command.toString();
return builder;
}
}

View File

@@ -1,71 +0,0 @@
package exopandora.worldhandler.builder;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.component.IBuilderComponent;
import exopandora.worldhandler.util.NBTHelper;
import net.minecraft.nbt.CompoundTag;
public abstract class CommandBuilderNBT extends CommandBuilder implements ICommandBuilderNBT
{
private final List<IBuilderComponent> TAG_TO_COMPONENT = new ArrayList<IBuilderComponent>();
@Override
public String toCommand()
{
return this.toCommand(true);
}
public String toCommand(boolean rebuildNBT)
{
if(rebuildNBT)
{
this.setNBT(this.buildNBT());
}
return super.toCommand();
}
@Override
public String toActualCommand()
{
return this.toActualCommand(true);
}
public String toActualCommand(boolean rebuildNBT)
{
if(rebuildNBT)
{
this.setNBT(this.buildNBT());
}
return super.toActualCommand();
}
@Nullable
protected CompoundTag buildNBT()
{
CompoundTag nbt = new CompoundTag();
for(IBuilderComponent component : this.TAG_TO_COMPONENT)
{
NBTHelper.append(nbt, component);
}
if(nbt.isEmpty())
{
return null;
}
return nbt;
}
public <T extends IBuilderComponent> T registerNBTComponent(T component)
{
this.TAG_TO_COMPONENT.add(component);
return component;
}
}

View File

@@ -1,48 +0,0 @@
package exopandora.worldhandler.builder;
import net.minecraft.ChatFormatting;
public class CommandString
{
private final StringBuilder command = new StringBuilder("/");
public CommandString(String name)
{
this.command.append(name);
}
public CommandString(String name, String... arguments)
{
this(name);
this.append(arguments);
}
public void append(String argument)
{
if(argument != null && !argument.isEmpty())
{
this.command.append(" " + argument);
}
else
{
this.command.append(" " + ChatFormatting.RED + "[error]" + ChatFormatting.RESET);
}
}
public void append(String... arguments)
{
if(arguments != null)
{
for(String argument : arguments)
{
this.append(argument);
}
}
}
@Override
public String toString()
{
return this.command.toString();
}
}

View File

@@ -1,108 +0,0 @@
package exopandora.worldhandler.builder;
import java.util.ArrayList;
import java.util.List;
import com.google.gson.annotations.SerializedName;
import exopandora.worldhandler.builder.types.ArgumentType;
public class CommandSyntax
{
private List<Argument> syntax = new ArrayList<Argument>();
public CommandSyntax()
{
super();
}
public CommandSyntax(List<Argument> syntax)
{
this.syntax = syntax;
}
public CommandSyntax addRequired(String key, ArgumentType type)
{
this.syntax.add(new Argument(key, type, true, null));
return this;
}
public CommandSyntax addRequired(String key, ArgumentType type, Object def)
{
this.syntax.add(new Argument(key, type, true, def));
return this;
}
public CommandSyntax addOptional(String key, ArgumentType type)
{
this.syntax.add(new Argument(key, type, false, null));
return this;
}
public CommandSyntax addOptional(String key, ArgumentType type, Object def)
{
this.syntax.add(new Argument(key, type, false, def));
return this;
}
public List<Argument> getArguments()
{
return this.syntax;
}
public static class Argument
{
@SerializedName("name")
private final String key;
@SerializedName("type")
private final ArgumentType type;
@SerializedName("required")
private final boolean required;
@SerializedName("default")
private final Object def;
public Argument(String key, ArgumentType type, boolean required, Object def)
{
this.key = key;
this.type = type;
this.required = required;
this.def = def;
}
public String getKey()
{
return this.key;
}
public ArgumentType getType()
{
return this.type;
}
public boolean isRequired()
{
return this.required;
}
public Object getDefault()
{
return this.def;
}
@Override
public String toString()
{
if(this.required)
{
return "<" + this.key + ">";
}
else
{
return "[" + this.key + "]";
}
}
}
}

View File

@@ -4,10 +4,10 @@ public interface ICommandBuilder
{
static final int MAX_COMMAND_LENGTH = 256;
String toCommand();
String toCommand(Object label, boolean preview);
default boolean needsCommandBlock()
default boolean needsCommandBlock(Object label, boolean preview)
{
return this.toCommand().length() > MAX_COMMAND_LENGTH;
return this.toCommand(label, preview).length() > MAX_COMMAND_LENGTH;
}
}

View File

@@ -1,8 +0,0 @@
package exopandora.worldhandler.builder;
import net.minecraft.nbt.CompoundTag;
public interface ICommandBuilderNBT extends ICommandBuilder
{
void setNBT(CompoundTag nbt);
}

View File

@@ -1,14 +0,0 @@
package exopandora.worldhandler.builder;
public interface ICommandBuilderSyntax extends ICommandBuilder
{
String getCommandName();
String toActualCommand();
CommandSyntax getSyntax();
@Override
default boolean needsCommandBlock()
{
return this.toActualCommand().length() > MAX_COMMAND_LENGTH;
}
}

View File

@@ -1,11 +0,0 @@
package exopandora.worldhandler.builder;
import javax.annotation.Nullable;
import net.minecraft.nbt.Tag;
public interface INBTWritable
{
@Nullable
Tag serialize();
}

View File

@@ -0,0 +1,106 @@
package exopandora.worldhandler.builder.argument.tag;
public class EffectInstance
{
private byte amplifier;
private int seconds;
private int minutes;
private int hours;
private boolean showParticles;
private boolean ambient;
public EffectInstance()
{
this((byte) 0, 0, 0, 0, true, false);
}
public EffectInstance(byte amplifier, int seconds, int minutes, int hours, boolean showParticles, boolean ambient)
{
this.amplifier = amplifier;
this.seconds = seconds;
this.minutes = minutes;
this.hours = hours;
this.showParticles = showParticles;
this.ambient = ambient;
}
public byte getAmplifier()
{
return this.amplifier;
}
public void setAmplifier(byte amplifier)
{
this.amplifier = amplifier;
}
public int getSeconds()
{
return this.seconds;
}
public void setSeconds(int seconds)
{
this.seconds = seconds;
}
public int getMinutes()
{
return this.minutes;
}
public void setMinutes(int minutes)
{
this.minutes = minutes;
}
public int getHours()
{
return this.hours;
}
public void setHours(int hours)
{
this.hours = hours;
}
public boolean doShowParticles()
{
return this.showParticles;
}
public void setShowParticles(boolean showParticles)
{
this.showParticles = showParticles;
}
public boolean isAmbient()
{
return this.ambient;
}
public void setAmbient(boolean ambient)
{
this.ambient = ambient;
}
public int toTicks()
{
return EffectInstance.toTicks(this.seconds, this.minutes, this.hours);
}
public int toSeconds()
{
return EffectInstance.toSeconds(this.seconds, this.minutes, this.hours);
}
public static int toTicks(int seconds, int minutes, int hours)
{
return seconds * 20 + minutes * 1200 + hours * 72000;
}
public static int toSeconds(int seconds, int minutes, int hours)
{
return seconds + minutes * 60 + hours * 3600;
}
}

View File

@@ -1,8 +0,0 @@
package exopandora.worldhandler.builder.component;
import exopandora.worldhandler.builder.INBTWritable;
public interface IBuilderComponent extends INBTWritable
{
String getTag();
}

View File

@@ -1,44 +0,0 @@
package exopandora.worldhandler.builder.component.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import exopandora.worldhandler.builder.component.IBuilderComponent;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraftforge.registries.ForgeRegistries;
public abstract class ComponentAttribute implements IBuilderComponent
{
public static final List<Attribute> ATTRIBUTES = ForgeRegistries.ATTRIBUTES.getValues().stream().filter(attribute -> !attribute.getDescriptionId().equals(I18n.get(attribute.getDescriptionId()))).collect(Collectors.toList());
protected Map<Attribute, Double> attributes = new HashMap<Attribute, Double>();
public void set(Attribute attribute, double ammount)
{
this.attributes.put(attribute, ammount);
}
public double getAmmount(Attribute attribute)
{
if(this.attributes.containsKey(attribute))
{
return this.attributes.get(attribute);
}
return 0;
}
public void remove(Attribute attribute)
{
this.attributes.remove(attribute);
}
public Set<Attribute> getAttributes()
{
return this.attributes.keySet();
}
}

View File

@@ -1,50 +0,0 @@
package exopandora.worldhandler.builder.component.impl;
import java.util.Map.Entry;
import java.util.UUID;
import javax.annotation.Nullable;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.minecraft.world.entity.ai.attributes.Attribute;
public class ComponentAttributeItem extends ComponentAttribute
{
@Override
@Nullable
public Tag serialize()
{
ListTag attributes = new ListTag();
for(Entry<Attribute, Double> entry : this.attributes.entrySet())
{
if(entry.getValue() != 0)
{
CompoundTag attribute = new CompoundTag();
String id = entry.getKey().getRegistryName().toString();
attribute.putString("AttributeName", id);
attribute.putDouble("Amount", entry.getValue() / 100);
attribute.putInt("Operation", 1); // 0 = additive, 1 = percentage
attribute.putUUID("UUID", UUID.nameUUIDFromBytes(id.getBytes()));
attributes.add(attribute);
}
}
if(attributes.isEmpty())
{
return null;
}
return attributes;
}
@Override
public String getTag()
{
return "AttributeModifiers";
}
}

View File

@@ -1,47 +0,0 @@
package exopandora.worldhandler.builder.component.impl;
import java.util.Map.Entry;
import javax.annotation.Nullable;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.minecraft.world.entity.ai.attributes.Attribute;
public class ComponentAttributeMob extends ComponentAttribute
{
@Override
@Nullable
public Tag serialize()
{
ListTag attributes = new ListTag();
for(Entry<Attribute, Double> entry : this.attributes.entrySet())
{
if(entry.getValue() != 0)
{
CompoundTag attribute = new CompoundTag();
String id = entry.getKey().getRegistryName().toString();
attribute.putString("Name", id);
attribute.putDouble("Base", entry.getValue() / 100);
attributes.add(attribute);
}
}
if(attributes.isEmpty())
{
return null;
}
return attributes;
}
@Override
public String getTag()
{
return "Attributes";
}
}

View File

@@ -1,43 +0,0 @@
package exopandora.worldhandler.builder.component.impl;
import exopandora.worldhandler.builder.component.IBuilderComponent;
import net.minecraft.nbt.Tag;
public class ComponentCustom implements IBuilderComponent
{
private Tag nbt;
private String tag;
public void setNBT(Tag nbt)
{
this.nbt = nbt;
}
public void setTag(String tag)
{
this.tag = tag;
}
public void set(String tag, Tag nbt)
{
this.setTag(tag);
this.setNBT(nbt);
}
public void reset()
{
this.set(null, null);
}
@Override
public Tag serialize()
{
return this.nbt;
}
@Override
public String getTag()
{
return this.tag;
}
}

View File

@@ -1,94 +0,0 @@
package exopandora.worldhandler.builder.component.impl;
import exopandora.worldhandler.builder.component.IBuilderComponent;
import exopandora.worldhandler.util.MutableTextComponent;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
public class ComponentDisplay implements IBuilderComponent
{
private MutableTextComponent name = new MutableTextComponent();
private Component[] lore = new Component[2];
@Override
public Tag serialize()
{
CompoundTag display = new CompoundTag();
if(this.name.getText() != null && !this.name.getText().isEmpty())
{
display.putString("Name", Component.Serializer.toJson(this.name));
}
ListTag lore = new ListTag();
for(int x = 0; x < this.lore.length; x++)
{
if(this.lore[x] != null && !this.lore[x].getString().isEmpty())
{
lore.add(StringTag.valueOf(Component.Serializer.toJson(this.lore[x])));
}
}
if(!lore.isEmpty())
{
display.put("Lore", lore);
}
if(!display.isEmpty())
{
return display;
}
return null;
}
public void setName(MutableTextComponent name)
{
this.name = name;
}
public MutableTextComponent getName()
{
return this.name;
}
public void setLore(Component[] lore)
{
this.lore = lore;
}
public Component[] getLore()
{
return this.lore;
}
public void setLore1(Component lore)
{
this.lore[0] = lore;
}
public Component getLore1()
{
return this.lore[0];
}
public void setLore2(Component lore)
{
this.lore[1] = lore;
}
public Component getLore2()
{
return this.lore[1];
}
@Override
public String getTag()
{
return "display";
}
}

View File

@@ -1,75 +0,0 @@
package exopandora.worldhandler.builder.component.impl;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.component.IBuilderComponent;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraftforge.registries.ForgeRegistries;
public class ComponentEnchantment implements IBuilderComponent
{
private Map<Enchantment, Short> enchantments = new HashMap<Enchantment, Short>();
@Override
@Nullable
public Tag serialize()
{
ListTag enchantments = new ListTag();
for(Entry<Enchantment, Short> entry : this.enchantments.entrySet())
{
if(entry.getValue() > 0)
{
CompoundTag enchantment = new CompoundTag();
enchantment.putString("id", ForgeRegistries.ENCHANTMENTS.getKey(entry.getKey()).toString());
enchantment.putShort("lvl", entry.getValue());
enchantments.add(enchantment);
}
}
if(enchantments.isEmpty())
{
return null;
}
return enchantments;
}
public void setLevel(Enchantment enchantment, short level)
{
if(level == 0)
{
this.enchantments.remove(enchantment);
}
else
{
this.enchantments.put(enchantment, level);
}
}
public short getLevel(Enchantment enchantment)
{
return this.enchantments.get(enchantment);
}
public Set<Enchantment> getEnchantments()
{
return this.enchantments.keySet();
}
@Override
public String getTag()
{
return "Enchantments";
}
}

View File

@@ -1,120 +0,0 @@
package exopandora.worldhandler.builder.component.impl;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.component.IBuilderComponent;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.minecraft.world.effect.MobEffect;
public abstract class ComponentPotion implements IBuilderComponent
{
protected final Map<MobEffect, EffectNBT> potions = new HashMap<MobEffect, EffectNBT>();
@Override
@Nullable
public Tag serialize()
{
ListTag list = new ListTag();
for(Entry<MobEffect, EffectNBT> entry : this.potions.entrySet())
{
EffectNBT effect = entry.getValue();
if(effect.getAmplifier() > 0)
{
CompoundTag compound = effect.serialize();
compound.putByte("Id", (byte) MobEffect.getId(entry.getKey()));
list.add(compound);
}
}
if(list.isEmpty())
{
return null;
}
return list;
}
public void setAmplifier(MobEffect potion, byte amplifier)
{
this.get(potion).setAmplifier(amplifier);
}
public byte getAmplifier(MobEffect potion)
{
return this.get(potion).getAmplifier();
}
public void setSeconds(MobEffect potion, int seconds)
{
this.get(potion).setSeconds(seconds);
}
public int getSeconds(MobEffect potion)
{
return this.get(potion).getSeconds();
}
public void setMinutes(MobEffect potion, int minutes)
{
this.get(potion).setMinutes(minutes);
}
public int getMinutes(MobEffect potion)
{
return this.get(potion).getMinutes();
}
public void setHours(MobEffect potion, int hours)
{
this.get(potion).setHours(hours);
}
public int getHours(MobEffect potion)
{
return this.get(potion).getHours();
}
public void setShowParticles(MobEffect potion, boolean showParticles)
{
this.get(potion).setShowParticles(showParticles);
}
public boolean getShowParticles(MobEffect potion)
{
return this.get(potion).getShowParticles();
}
public void setAmbient(MobEffect potion, boolean ambient)
{
this.get(potion).setAmbient(ambient);
}
public boolean getAmbient(MobEffect potion)
{
return this.get(potion).getAmbient();
}
private EffectNBT get(MobEffect potion)
{
return this.potions.computeIfAbsent(potion, key -> new EffectNBT());
}
public Set<MobEffect> getMobEffects()
{
return this.potions.keySet();
}
public void remove(MobEffect potion)
{
this.potions.remove(potion);
}
}

View File

@@ -1,10 +0,0 @@
package exopandora.worldhandler.builder.component.impl;
public class ComponentPotionItem extends ComponentPotion
{
@Override
public String getTag()
{
return "CustomPotionEffects";
}
}

View File

@@ -1,10 +0,0 @@
package exopandora.worldhandler.builder.component.impl;
public class ComponentPotionMob extends ComponentPotion
{
@Override
public String getTag()
{
return "ActiveEffects";
}
}

View File

@@ -1,146 +0,0 @@
package exopandora.worldhandler.builder.component.impl;
import java.util.Collection;
import java.util.function.Function;
import javax.annotation.Nullable;
import exopandora.worldhandler.WorldHandler;
import exopandora.worldhandler.builder.component.IBuilderComponent;
import net.minecraft.nbt.ByteArrayTag;
import net.minecraft.nbt.ByteTag;
import net.minecraft.nbt.DoubleTag;
import net.minecraft.nbt.FloatTag;
import net.minecraft.nbt.IntArrayTag;
import net.minecraft.nbt.IntTag;
import net.minecraft.nbt.LongArrayTag;
import net.minecraft.nbt.LongTag;
import net.minecraft.nbt.ShortTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
public class ComponentTag<T> implements IBuilderComponent
{
private final Function<T, Tag> serializer;
private final String tag;
private T value;
public ComponentTag(String tag, T value, Function<T, Tag> serializer)
{
this.tag = tag;
this.value = value;
this.serializer = serializer;
}
public ComponentTag(String tag, Function<T, Tag> serializer)
{
this(tag, null, serializer);
}
public ComponentTag(String tag, T value)
{
this(tag, value, null);
}
public ComponentTag(String tag)
{
this(tag, null, null);
}
public void setValue(T value)
{
this.value = value;
}
@Nullable
public T getValue()
{
return this.value;
}
@Override
@Nullable
public Tag serialize()
{
if(this.value != null)
{
if(this.serializer != null)
{
return this.serializer.apply(this.value);
}
else if(this.value instanceof String)
{
String string = (String) this.value;
if(string.isEmpty())
{
return null;
}
return StringTag.valueOf(string);
}
else if(this.value instanceof Tag)
{
if(this.value instanceof Collection<?>)
{
Collection<?> collection = (Collection<?>) this.value;
if(collection.isEmpty())
{
return null;
}
}
return (Tag) this.value;
}
else if(this.value instanceof Integer)
{
return IntTag.valueOf((Integer) this.value);
}
else if(this.value instanceof Byte)
{
return ByteTag.valueOf((Byte) this.value);
}
else if(this.value instanceof Float)
{
return FloatTag.valueOf((Float) this.value);
}
else if(this.value instanceof Double)
{
return DoubleTag.valueOf((Double) this.value);
}
else if(this.value instanceof Long)
{
return LongTag.valueOf((Long) this.value);
}
else if(this.value instanceof Short)
{
return ShortTag.valueOf((Short) this.value);
}
else if(this.value instanceof Byte[])
{
return new ByteArrayTag((byte[]) this.value);
}
else if(this.value instanceof Integer[])
{
return new IntArrayTag((int[]) this.value);
}
else if(this.value instanceof Long[])
{
return new LongArrayTag((long[]) this.value);
}
else
{
WorldHandler.LOGGER.warn("Tag \"" + this.tag + "\" has no serializer");
}
}
return null;
}
@Override
public String getTag()
{
return this.tag;
}
}

View File

@@ -1,166 +0,0 @@
package exopandora.worldhandler.builder.component.impl;
import exopandora.worldhandler.builder.INBTWritable;
import net.minecraft.nbt.CompoundTag;
public class EffectNBT implements INBTWritable
{
private byte amplifier;
private int seconds;
private int minutes;
private int hours;
private boolean showParticles;
private boolean ambient;
public EffectNBT()
{
this((byte) 0, 0, 0, 0, true, false);
}
public EffectNBT(byte amplifier, int seconds, int minutes, int hours, boolean showParticles, boolean ambient)
{
this.amplifier = amplifier;
this.seconds = seconds;
this.minutes = minutes;
this.hours = hours;
this.showParticles = showParticles;
this.ambient = ambient;
}
public byte getAmplifier()
{
return this.amplifier;
}
public void setAmplifier(byte amplifier)
{
this.amplifier = amplifier;
}
public int getSeconds()
{
return this.seconds;
}
public void setSeconds(int seconds)
{
this.seconds = seconds;
}
public int getMinutes()
{
return this.minutes;
}
public void setMinutes(int minutes)
{
this.minutes = minutes;
}
public int getHours()
{
return this.hours;
}
public void setHours(int hours)
{
this.hours = hours;
}
public boolean getShowParticles()
{
return this.showParticles;
}
public void setShowParticles(boolean showParticles)
{
this.showParticles = showParticles;
}
public boolean getAmbient()
{
return this.ambient;
}
public void setAmbient(boolean ambient)
{
this.ambient = ambient;
}
public int toTicks()
{
return EffectNBT.toTicks(this.seconds, this.minutes, this.hours);
}
public int toSeconds()
{
return EffectNBT.toSeconds(this.seconds, this.minutes, this.hours);
}
@Override
public CompoundTag serialize()
{
CompoundTag compound = new CompoundTag();
int ticks = this.toTicks();
compound.putByte("Amplifier", (byte) (this.amplifier - 1));
compound.putInt("Duration", ticks > 0 ? ticks : 1000000);
compound.putBoolean("Ambient", this.ambient);
compound.putBoolean("ShowParticles", this.showParticles);
return compound;
}
public static int toTicks(int seconds, int minutes, int hours)
{
return seconds * 20 + minutes * 1200 + hours * 72000;
}
public static int toSeconds(int seconds, int minutes, int hours)
{
return seconds + minutes * 60 + hours * 3600;
}
public EffectNBT withAmplifier(byte amplifier)
{
this.amplifier = amplifier;
return this;
}
public EffectNBT withShowParticles(boolean showParticles)
{
this.showParticles = showParticles;
return this;
}
public EffectNBT withSeconds(int seconds)
{
this.seconds = seconds;
return this;
}
public EffectNBT withMinutes(int minutes)
{
this.minutes = minutes;
return this;
}
public EffectNBT withHours(int hours)
{
this.hours = hours;
return this;
}
public EffectNBT withAmbient(boolean ambient)
{
this.ambient = ambient;
return this;
}
@Override
public String toString()
{
return "EffectNBT [amplifier=" + amplifier + ", seconds=" + seconds + ", minutes=" + minutes + ", hours=" + hours + ", showParticles=" + showParticles + ", ambient=" + ambient + "]";
}
}

View File

@@ -1,468 +0,0 @@
package exopandora.worldhandler.builder.component.impl;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import exopandora.worldhandler.builder.component.IBuilderComponent;
import exopandora.worldhandler.util.MutableTextComponent;
import exopandora.worldhandler.util.NBTHelper;
import net.minecraft.nbt.ByteTag;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.IntTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.TagParser;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
public class EntityNBT implements IBuilderComponent
{
private ResourceLocation id;
private String command;
private Integer time;
private double[] motion = {0.0, 0.0, 0.0};
private boolean isBaby;
private BlockState blockState;
private ComponentCustom entity = new ComponentCustom();
private ComponentAttributeMob attribute = new ComponentAttributeMob();
private MutableTextComponent customName = new MutableTextComponent();
private List<EntityNBT> passengers = new ArrayList<EntityNBT>();
private ResourceLocation[] armorItems = {Items.AIR.getRegistryName(), Items.AIR.getRegistryName(), Items.AIR.getRegistryName(), Items.AIR.getRegistryName()};
private ResourceLocation[] handItems = {Items.AIR.getRegistryName(), Items.AIR.getRegistryName()};
private ComponentPotionMob potion = new ComponentPotionMob();
private CompoundTag nbt;
public EntityNBT()
{
super();
}
public EntityNBT(ResourceLocation id)
{
this.id = id;
}
public void setId(ResourceLocation id)
{
this.id = id;
}
public ResourceLocation getId()
{
return this.id;
}
public void setAttribute(Attribute attribute, double ammount)
{
this.attribute.set(attribute, ammount);
}
public void removeAttribute(Attribute attribute)
{
this.attribute.remove(attribute);
}
public double getAttributeAmmount(Attribute attribute)
{
return this.attribute.getAmmount(attribute);
}
public Set<Attribute> getAttributes()
{
return this.attribute.getAttributes();
}
public void setCustomName(String name)
{
this.customName.setText(name);
}
@Nullable
public MutableTextComponent getCustomName()
{
return this.customName;
}
public void setPassenger(int index, EntityNBT entity)
{
if(index < 0 || index >= this.passengers.size())
{
this.passengers.add(entity);
}
else
{
this.passengers.set(index, entity);
}
}
public void setPassenger(int index, ResourceLocation id)
{
this.setPassenger(index, new EntityNBT(id));
}
public void addPassenger(EntityNBT entity)
{
this.passengers.add(entity);
}
public void addPassenger(int index, EntityNBT entity)
{
this.passengers.add(index, entity);
}
public void removePassenger(int index)
{
this.passengers.remove(index);
}
public int getPassengerCount()
{
return this.passengers.size();
}
public List<EntityNBT> getPassengers()
{
return this.passengers;
}
@Nullable
public EntityNBT getPassenger(int index)
{
if(index >= 0 && index <= this.passengers.size())
{
return this.passengers.get(index);
}
return null;
}
public boolean hasPassengers()
{
for(EntityNBT entity : this.passengers)
{
if(entity.serialize() != null)
{
return true;
}
}
return false;
}
public void setArmorItem(int index, Block block)
{
this.setArmorItem(index, block.getRegistryName());
}
public void setArmorItem(int index, Item item)
{
this.setArmorItem(index, item.getRegistryName());
}
public void setArmorItem(int index, ResourceLocation location)
{
if(EntityNBT.isArrayIndexValid(this.armorItems, index) && location != null)
{
this.armorItems[index] = location;
}
}
public void setArmorItems(ResourceLocation[] armor)
{
this.armorItems = armor;
}
@Nonnull
public ResourceLocation getArmorItem(int slot)
{
if(EntityNBT.isArrayIndexValid(this.armorItems, slot))
{
return this.armorItems[slot];
}
return Blocks.AIR.getRegistryName();
}
public void setHandItem(int index, Block block)
{
this.setHandItem(index, block.getRegistryName());
}
public void setHandItem(int index, Item item)
{
this.setHandItem(index, item.getRegistryName());
}
public void setHandItem(int index, ResourceLocation location)
{
if(EntityNBT.isArrayIndexValid(this.handItems, index) && location != null)
{
this.handItems[index] = location;
}
}
@Nonnull
public ResourceLocation getHandItem(int slot)
{
if(EntityNBT.isArrayIndexValid(this.handItems, slot))
{
return this.handItems[slot];
}
return Blocks.AIR.getRegistryName();
}
public double[] getMotion()
{
return this.motion;
}
public void setMotion(double x, double y, double z)
{
this.setMotionX(x);
this.setMotionY(y);
this.setMotionZ(z);
}
public double getMotionX()
{
return this.motion[0];
}
public double getMotionY()
{
return this.motion[1];
}
public double getMotionZ()
{
return this.motion[2];
}
public void setMotionX(double x)
{
this.motion[0] = x;
}
public void setMotionY(double y)
{
this.motion[1] = y;
}
public void setMotionZ(double z)
{
this.motion[2] = z;
}
public void setAmplifier(MobEffect potion, byte amplifier)
{
this.potion.setAmplifier(potion, amplifier);
}
public void setSeconds(MobEffect potion, int seconds)
{
this.potion.setSeconds(potion, seconds);
}
public void setMinutes(MobEffect potion, int minutes)
{
this.potion.setMinutes(potion, minutes);
}
public void setHours(MobEffect potion, int hours)
{
this.potion.setHours(potion, hours);
}
public void setShowParticles(MobEffect potion, boolean showParticles)
{
this.potion.setShowParticles(potion, showParticles);
}
public void setAmbient(MobEffect potion, boolean ambient)
{
this.potion.setAmbient(potion, ambient);
}
public byte getAmplifier(MobEffect potion)
{
return this.potion.getAmplifier(potion);
}
public int getSeconds(MobEffect potion)
{
return this.potion.getSeconds(potion);
}
public int getMinutes(MobEffect potion)
{
return this.potion.getMinutes(potion);
}
public int getHours(MobEffect potion)
{
return this.potion.getHours(potion);
}
public boolean getShowParticles(MobEffect potion)
{
return this.potion.getShowParticles(potion);
}
public boolean getAmbient(MobEffect potion)
{
return this.potion.getAmbient(potion);
}
public Set<MobEffect> getEffects()
{
return this.potion.getMobEffects();
}
public void setBlockState(BlockState blockState)
{
this.blockState = blockState;
}
public BlockState getBlockState()
{
return this.blockState;
}
public void setTime(int time)
{
this.time = time;
}
public int getTime()
{
return this.time;
}
public void setCustomComponent(String tag, Tag nbt)
{
this.entity.set(tag, nbt);
}
public void resetCustomComponent()
{
this.entity.set(null, null);
}
public void setIsBaby(boolean baby)
{
this.isBaby = baby;
}
public boolean isBaby()
{
return this.isBaby;
}
public void setCommand(String command)
{
this.command = command;
}
public String getCommand()
{
return this.command;
}
public void setNBT(CompoundTag nbt)
{
this.nbt = nbt;
}
public CompoundTag getNBT()
{
return this.nbt;
}
public void setNBT(String nbt)
{
try
{
this.nbt = TagParser.parseTag("{" + nbt + "}");
}
catch(CommandSyntaxException e)
{
this.nbt = null;
}
}
@Override
public CompoundTag serialize()
{
CompoundTag nbt = new CompoundTag();
if(this.time != null)
{
NBTHelper.append(nbt, "Time", IntTag.valueOf(this.time));
}
if(this.command != null)
{
NBTHelper.append(nbt, "Command", StringTag.valueOf(this.command));
}
if(this.isBaby)
{
NBTHelper.append(nbt, "IsBaby", ByteTag.valueOf(true));
}
NBTHelper.append(nbt, "id", NBTHelper.serialize(this.id));
NBTHelper.append(nbt, "Motion", NBTHelper.serialize(this.motion));
NBTHelper.append(nbt, "Passengers", NBTHelper.serialize(this.passengers));
NBTHelper.append(nbt, "ArmorItems", NBTHelper.serialize(this.armorItems));
NBTHelper.append(nbt, "HandItems", NBTHelper.serialize(this.handItems));
NBTHelper.append(nbt, "BlockState", NBTHelper.serialize(this.blockState));
NBTHelper.append(nbt, "CustomName", this.customName);
NBTHelper.append(nbt, this.entity);
NBTHelper.append(nbt, this.potion);
NBTHelper.append(nbt, this.attribute);
if(this.nbt != null)
{
nbt.merge(this.nbt);
}
if(nbt.isEmpty())
{
return null;
}
return nbt;
}
@Override
public String getTag()
{
return null;
}
private static boolean isArrayIndexValid(Object[] array, int index)
{
if(array != null && (Array.getLength(array) == 0 || array.length <= index))
{
return false;
}
return index >= 0;
}
}

View File

@@ -1,125 +0,0 @@
package exopandora.worldhandler.builder.impl;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.CommandBuilder;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
import exopandora.worldhandler.util.EnumHelper;
import net.minecraft.resources.ResourceLocation;
public class BuilderAdvancement extends CommandBuilder
{
public BuilderAdvancement(EnumMode mode)
{
this.setMode(mode);
}
public BuilderAdvancement(EnumActionType action, String player, EnumMode mode, ResourceLocation advancement)
{
this(mode);
this.setActionType(action);
this.setPlayer(player);
this.setAdvancement(advancement);
}
public void setActionType(EnumActionType action)
{
this.setNode(0, action != null ? action.toString() : null);
}
@Nullable
public EnumActionType getActionType()
{
return EnumHelper.valueOf(this.getNodeAsString(1), EnumActionType.class);
}
public void setPlayer(String player)
{
this.setNode(1, player);
}
@Nullable
public String getPlayer()
{
return this.getNodeAsString(1);
}
public void setMode(EnumMode mode)
{
this.setNode(2, mode != null ? mode.toString() : null);
}
@Nullable
public EnumMode getMode()
{
return EnumHelper.valueOf(this.getNodeAsString(2), EnumMode.class);
}
public void setAdvancement(ResourceLocation advancement)
{
this.setNode(3, advancement);
}
@Nullable
public ResourceLocation getAdvancement()
{
return this.getNodeAsResourceLocation(3);
}
public BuilderAdvancement build(EnumActionType action)
{
return this.build(action, this.getMode());
}
public BuilderAdvancement build(EnumActionType action, EnumMode mode)
{
return new BuilderAdvancement(action, this.getPlayer(), mode, !EnumMode.EVERYTHING.equals(mode) ? this.getAdvancement() : null);
}
@Override
public String getCommandName()
{
return "advancement";
}
@Override
public final CommandSyntax getSyntax()
{
CommandSyntax syntax = new CommandSyntax();
syntax.addRequired("grant|revoke|test", ArgumentType.STRING);
syntax.addRequired("player", ArgumentType.STRING);
syntax.addRequired("only|until|from|through|everything", ArgumentType.STRING);
syntax.addOptional("advancement", ArgumentType.RESOURCE_LOCATION);
return syntax;
}
public static enum EnumActionType
{
GRANT,
REVOKE;
@Override
public String toString()
{
return this.name().toLowerCase();
}
}
public static enum EnumMode
{
ONLY,
UNTIL,
FROM,
THROUGH,
EVERYTHING;
@Override
public String toString()
{
return this.name().toLowerCase();
}
}
}

View File

@@ -1,87 +0,0 @@
package exopandora.worldhandler.builder.impl;
import exopandora.worldhandler.builder.CommandBuilderNBT;
import exopandora.worldhandler.builder.types.CoordinateInt;
import net.minecraft.core.BlockPos;
public abstract class BuilderBlockPos extends CommandBuilderNBT
{
private final int offset;
public BuilderBlockPos(int offset)
{
this.offset = offset;
}
public void setPosition(BlockPos pos)
{
this.setX(pos.getX());
this.setY(pos.getY());
this.setZ(pos.getZ());
}
public void setX(int x)
{
this.setX(new CoordinateInt(x));
}
public void setY(int y)
{
this.setY(new CoordinateInt(y));
}
public void setZ(int z)
{
this.setZ(new CoordinateInt(z));
}
public void setX(CoordinateInt x)
{
this.setNode(this.offset, x);
}
public void setY(CoordinateInt y)
{
this.setNode(this.offset + 1, y);
}
public void setZ(CoordinateInt z)
{
this.setNode(this.offset + 2, z);
}
public CoordinateInt getXCoordinate()
{
return this.getNodeAsCoordinateInt(this.offset);
}
public CoordinateInt getYCoordinate()
{
return this.getNodeAsCoordinateInt(this.offset + 1);
}
public CoordinateInt getZCoordinate()
{
return this.getNodeAsCoordinateInt(this.offset + 2);
}
public int getX()
{
return this.getXCoordinate().getValue();
}
public int getY()
{
return this.getYCoordinate().getValue();
}
public int getZ()
{
return this.getZCoordinate().getValue();
}
public BlockPos getBlockPos()
{
return new BlockPos(this.getX(), this.getY(), this.getZ());
}
}

View File

@@ -1,78 +0,0 @@
package exopandora.worldhandler.builder.impl;
import javax.annotation.Nonnull;
import exopandora.worldhandler.builder.CommandBuilder;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
import exopandora.worldhandler.builder.types.TargetSelector;
import net.minecraft.resources.ResourceLocation;
public class BuilderButcher extends CommandBuilder
{
private final TargetSelector targetSelector = new TargetSelector();
public BuilderButcher()
{
this("<entity_name>", 0);
}
public BuilderButcher(ResourceLocation entity, int distance)
{
this(entity.toString(), distance);
}
private BuilderButcher(String entity, int distance)
{
this.setEntity(entity);
this.setDistance(distance);
}
public void setDistance(int distance)
{
this.targetSelector.set("distance", "0.." + distance);
this.setNode(0, this.targetSelector);
}
public int getDistance()
{
return Integer.parseInt(this.targetSelector.<String>get("distance").substring(3));
}
private void setEntity(String entity)
{
if(entity != null)
{
this.targetSelector.set("type", entity);
}
this.setNode(0, this.targetSelector);
}
public void setEntity(ResourceLocation entity)
{
this.setEntity(entity.toString());
}
@Nonnull
public ResourceLocation getEntity()
{
return this.targetSelector.<ResourceLocation>get("type");
}
@Override
public String getCommandName()
{
return "kill";
}
@Override
public CommandSyntax getSyntax()
{
CommandSyntax syntax = new CommandSyntax();
syntax.addRequired("entity_name", ArgumentType.TARGET_SELECTOR);
return syntax;
}
}

View File

@@ -1,168 +0,0 @@
package exopandora.worldhandler.builder.impl;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
import exopandora.worldhandler.builder.types.Coordinate.EnumType;
import exopandora.worldhandler.builder.types.CoordinateInt;
import exopandora.worldhandler.util.EnumHelper;
import net.minecraft.core.BlockPos;
public class BuilderClone extends BuilderDoubleBlockPos
{
public BuilderClone()
{
this.setX(new CoordinateInt(EnumType.GLOBAL));
this.setY(new CoordinateInt(EnumType.GLOBAL));
this.setZ(new CoordinateInt(EnumType.GLOBAL));
this.setMask(EnumMask.values()[0]);
}
public void setPosition(BlockPos pos)
{
this.setX(pos.getX());
this.setY(pos.getY());
this.setZ(pos.getZ());
}
public void setX(int x)
{
this.setX(new CoordinateInt(x));
}
public void setY(int y)
{
this.setY(new CoordinateInt(y));
}
public void setZ(int z)
{
this.setZ(new CoordinateInt(z));
}
public void setX(CoordinateInt x)
{
this.setNode(6, x);
}
public void setY(CoordinateInt y)
{
this.setNode(7, y);
}
public void setZ(CoordinateInt z)
{
this.setNode(8, z);
}
@Nonnull
public CoordinateInt getXCoordiante()
{
return this.getNodeAsCoordinateInt(6);
}
@Nonnull
public CoordinateInt getYCoordiante()
{
return this.getNodeAsCoordinateInt(7);
}
@Nonnull
public CoordinateInt getZCoordiante()
{
return this.getNodeAsCoordinateInt(8);
}
public double getX()
{
return this.getXCoordiante().getValue();
}
public double getY()
{
return this.getYCoordiante().getValue();
}
public double getZ()
{
return this.getZCoordiante().getValue();
}
public BlockPos getBlockPos()
{
return new BlockPos(this.getX(), this.getY(), this.getZ());
}
public void setMask(EnumMask mask)
{
this.setNode(9, mask != null ? mask.toString() : null);
}
@Nullable
public EnumMask getMask()
{
return EnumHelper.valueOf(this.getNodeAsString(9), EnumMask.class);
}
public void setFilter(String filter)
{
if(filter != null)
{
this.setMask(EnumMask.FILTERED);
}
this.setNode(10, filter);
}
@Nullable
public String getFilter()
{
if(EnumMask.FILTERED.equals(this.getMask()))
{
return this.getNodeAsString(10);
}
return null;
}
@Override
public String getCommandName()
{
return "clone";
}
@Override
public final CommandSyntax getSyntax()
{
CommandSyntax syntax = new CommandSyntax();
syntax.addRequired("x1", ArgumentType.COORDINATE_INT);
syntax.addRequired("y1", ArgumentType.COORDINATE_INT);
syntax.addRequired("z1", ArgumentType.COORDINATE_INT);
syntax.addRequired("x2", ArgumentType.COORDINATE_INT);
syntax.addRequired("y2", ArgumentType.COORDINATE_INT);
syntax.addRequired("z2", ArgumentType.COORDINATE_INT);
syntax.addRequired("x", ArgumentType.COORDINATE_INT);
syntax.addRequired("y", ArgumentType.COORDINATE_INT);
syntax.addRequired("z", ArgumentType.COORDINATE_INT);
syntax.addOptional("mask", ArgumentType.STRING);
syntax.addOptional("filter", ArgumentType.STRING);
return syntax;
}
public static enum EnumMask
{
FILTERED,
MASKED,
REPLACE;
@Override
public String toString()
{
return this.name().toLowerCase();
}
}
}

View File

@@ -1,97 +0,0 @@
package exopandora.worldhandler.builder.impl;
import java.util.Set;
import exopandora.worldhandler.builder.component.impl.ComponentAttributeItem;
import exopandora.worldhandler.builder.component.impl.ComponentDisplay;
import exopandora.worldhandler.builder.component.impl.ComponentEnchantment;
import exopandora.worldhandler.util.MutableTextComponent;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.item.enchantment.Enchantment;
public class BuilderCustomItem extends BuilderGive
{
private final ComponentAttributeItem attribute;
private final ComponentDisplay display;
private final ComponentEnchantment enchantment;
public BuilderCustomItem()
{
this(null, null);
}
public BuilderCustomItem(String player, ResourceLocation item)
{
super(player, item);
this.attribute = this.registerNBTComponent(new ComponentAttributeItem());
this.display = this.registerNBTComponent(new ComponentDisplay());
this.enchantment = this.registerNBTComponent(new ComponentEnchantment());
}
public void setEnchantment(Enchantment enchantment, short level)
{
this.enchantment.setLevel(enchantment, level);
}
public short getEnchantmentLevel(Enchantment enchantment)
{
return this.enchantment.getLevel(enchantment);
}
public Set<Enchantment> getEnchantments()
{
return this.enchantment.getEnchantments();
}
public void setAttribute(Attribute attribute, double ammount)
{
this.attribute.set(attribute, ammount);
}
public void removeAttribute(Attribute attribute)
{
this.attribute.remove(attribute);
}
public double getAttributeAmmount(Attribute attribute)
{
return this.attribute.getAmmount(attribute);
}
public Set<Attribute> getAttributes()
{
return this.attribute.getAttributes();
}
public void setName(MutableTextComponent name)
{
this.display.setName(name);
}
public MutableTextComponent getName()
{
return this.display.getName();
}
public void setLore1(Component lore)
{
this.display.setLore1(lore);
}
public Component getLore1()
{
return this.display.getLore1();
}
public void setLore2(Component lore)
{
this.display.setLore2(lore);
}
public Component getLore2()
{
return this.display.getLore2();
}
}

View File

@@ -1,323 +0,0 @@
package exopandora.worldhandler.builder.impl;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
import exopandora.worldhandler.builder.types.CoordinateInt;
import exopandora.worldhandler.builder.types.TargetSelector;
import exopandora.worldhandler.util.EnumHelper;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
public class BuilderData extends BuilderBlockPos
{
private final TargetSelector targetSelector = new TargetSelector();
public BuilderData()
{
super(2);
}
public BuilderData(EnumMode mode, ResourceLocation entity, CompoundTag nbt)
{
this();
this.setMode(mode);
this.setEntity(entity);
this.setNBT(nbt);
}
public BuilderData(EnumMode mode, BlockPos pos, CompoundTag nbt)
{
this();
this.setMode(mode);
this.setPosition(pos);
this.setNBT(nbt);
}
public void setMode(EnumMode mode)
{
EnumTarget target = this.getTarget();
this.updateSyntax(this.getSyntax(mode, target));
this.setMode0(mode);
this.setTarget0(target);
}
private void setMode0(EnumMode mode)
{
if(mode != null)
{
this.setNode(0, mode.toString());
}
}
@Nullable
public EnumMode getMode()
{
return EnumHelper.valueOf(this.getNodeAsString(0), EnumMode.class);
}
public void setTarget(EnumTarget target)
{
EnumMode mode = this.getMode();
this.updateSyntax(this.getSyntax(mode, target));
this.setMode0(mode);
this.setTarget0(target);
}
private void setTarget0(EnumTarget target)
{
if(target != null)
{
this.setNode(1, target.toString());
}
}
@Nullable
public EnumTarget getTarget()
{
return EnumHelper.valueOf(this.getNodeAsString(1), EnumTarget.class);
}
private void setEntity(String entity)
{
this.ensureTarget(EnumTarget.ENTITY);
if(entity != null)
{
this.targetSelector.set("type", entity);
}
this.setNode(2, this.targetSelector);
}
public void setEntity(ResourceLocation entity)
{
this.setEntity(entity.toString());
}
@Nonnull
public ResourceLocation getEntity()
{
return this.targetSelector.<ResourceLocation>get("type");
}
public void setPath(String path)
{
if(this.getMode() == null || !this.getMode().equals(EnumMode.REMOVE))
{
this.setMode(EnumMode.REMOVE);
}
switch(this.getTarget())
{
case BLOCK:
this.setNode(5, path);
break;
case ENTITY:
this.setNode(3, path);
break;
default:
break;
}
}
@Override
public void setNBT(CompoundTag nbt)
{
if(this.getMode() == null || !this.getMode().equals(EnumMode.MERGE))
{
this.setMode(EnumMode.MERGE);
}
EnumTarget target = this.getTarget();
if(target != null)
{
switch(target)
{
case BLOCK:
this.setNode(5, nbt);
break;
case ENTITY:
this.setNode(3, nbt);
break;
default:
break;
}
}
}
@Nullable
public CompoundTag getNBT()
{
if(this.getMode() != null && this.getMode().equals(EnumMode.MERGE))
{
switch(this.getTarget())
{
case BLOCK:
return this.getNodeAsNBT(5);
case ENTITY:
return this.getNodeAsNBT(3);
default:
break;
}
}
return null;
}
@Override
public String getCommandName()
{
return "data";
}
@Nullable
private final CommandSyntax getSyntax(EnumMode mode, EnumTarget target)
{
CommandSyntax syntax = new CommandSyntax();
syntax.addRequired(mode != null ? mode.toString() : "mode", ArgumentType.STRING);
syntax.addRequired(target != null ? target.toString() : "target", ArgumentType.STRING);
if(target != null)
{
switch(target)
{
case BLOCK:
syntax.addRequired("x", ArgumentType.COORDINATE_INT);
syntax.addRequired("y", ArgumentType.COORDINATE_INT);
syntax.addRequired("z", ArgumentType.COORDINATE_INT);
break;
case ENTITY:
syntax.addRequired("entity", ArgumentType.TARGET_SELECTOR);
break;
default:
break;
}
switch(mode)
{
case GET:
break;
case MERGE:
syntax.addRequired("nbt", ArgumentType.NBT);
break;
case REMOVE:
syntax.addRequired("path", ArgumentType.STRING);
break;
default:
break;
}
}
else
{
syntax.addOptional("...", ArgumentType.STRING);
}
return syntax;
}
private void ensureTarget(EnumTarget target)
{
if(this.getTarget() == null || !target.equals(this.getTarget()))
{
this.setTarget(target);
}
}
@Override
public void setX(CoordinateInt x)
{
this.ensureTarget(EnumTarget.BLOCK);
super.setX(x);
}
@Override
public void setY(CoordinateInt y)
{
this.ensureTarget(EnumTarget.BLOCK);
super.setY(y);
}
@Override
public void setZ(CoordinateInt z)
{
this.ensureTarget(EnumTarget.BLOCK);
super.setZ(z);
}
@Override
@Nonnull
public CoordinateInt getXCoordinate()
{
this.ensureTarget(EnumTarget.BLOCK);
return super.getXCoordinate();
}
@Override
@Nonnull
public CoordinateInt getYCoordinate()
{
this.ensureTarget(EnumTarget.BLOCK);
return super.getYCoordinate();
}
@Override
@Nonnull
public CoordinateInt getZCoordinate()
{
this.ensureTarget(EnumTarget.BLOCK);
return super.getZCoordinate();
}
@Override
@Nonnull
public BlockPos getBlockPos()
{
this.ensureTarget(EnumTarget.BLOCK);
return super.getBlockPos();
}
@Override
public final CommandSyntax getSyntax()
{
CommandSyntax syntax = new CommandSyntax();
syntax.addRequired("get|merge|remove", ArgumentType.STRING);
syntax.addRequired("block|entity", ArgumentType.STRING);
syntax.addOptional("...", ArgumentType.STRING);
return syntax;
}
public static enum EnumMode
{
GET,
MERGE,
REMOVE;
@Override
public String toString()
{
return this.name().toLowerCase();
}
}
public static enum EnumTarget
{
BLOCK,
ENTITY;
@Override
public String toString()
{
return this.name().toLowerCase();
}
}
}

View File

@@ -1,43 +0,0 @@
package exopandora.worldhandler.builder.impl;
import exopandora.worldhandler.builder.CommandBuilder;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
import net.minecraft.world.Difficulty;
public class BuilderDifficulty extends CommandBuilder
{
public BuilderDifficulty()
{
super();
}
public BuilderDifficulty(Difficulty difficulty)
{
this.setDifficulty(difficulty);
}
public void setDifficulty(Difficulty difficulty)
{
if(difficulty != null)
{
this.setNode(0, difficulty.getKey());
}
}
@Override
public String getCommandName()
{
return "difficulty";
}
@Override
public final CommandSyntax getSyntax()
{
CommandSyntax syntax = new CommandSyntax();
syntax.addRequired("peaceful|easy|normal|hard", ArgumentType.STRING);
return syntax;
}
}

View File

@@ -1,167 +0,0 @@
package exopandora.worldhandler.builder.impl;
import javax.annotation.Nonnull;
import exopandora.worldhandler.builder.CommandBuilder;
import exopandora.worldhandler.builder.types.CoordinateInt;
import exopandora.worldhandler.util.BlockHelper;
import net.minecraft.core.BlockPos;
public abstract class BuilderDoubleBlockPos extends CommandBuilder
{
public BuilderDoubleBlockPos()
{
this.setPosition1(BlockHelper.getPos1());
this.setPosition2(BlockHelper.getPos2());
}
public void setPosition1(BlockPos pos)
{
this.setX1(pos.getX());
this.setY1(pos.getY());
this.setZ1(pos.getZ());
}
public void setX1(int x)
{
this.setX1(new CoordinateInt(x));
}
public void setY1(int y)
{
this.setY1(new CoordinateInt(y));
}
public void setZ1(int z)
{
this.setZ1(new CoordinateInt(z));
}
public void setX1(CoordinateInt x)
{
this.setNode(0, x);
}
public void setY1(CoordinateInt y)
{
this.setNode(1, y);
}
public void setZ1(CoordinateInt z)
{
this.setNode(2, z);
}
@Nonnull
public CoordinateInt getX1Coordiante()
{
return this.getNodeAsCoordinateInt(0);
}
@Nonnull
public CoordinateInt getY1Coordiante()
{
return this.getNodeAsCoordinateInt(1);
}
@Nonnull
public CoordinateInt getZ1Coordiante()
{
return this.getNodeAsCoordinateInt(2);
}
public double getX1()
{
return this.getX1Coordiante().getValue();
}
public double getY1()
{
return this.getY1Coordiante().getValue();
}
public double getZ1()
{
return this.getZ1Coordiante().getValue();
}
public BlockPos getBlockPos1()
{
return new BlockPos(this.getX1(), this.getY1(), this.getZ1());
}
public void setPosition2(BlockPos pos)
{
this.setX2(pos.getX());
this.setY2(pos.getY());
this.setZ2(pos.getZ());
}
public void setX2(int x)
{
this.setX2(new CoordinateInt(x));
}
public void setY2(int y)
{
this.setY2(new CoordinateInt(y));
}
public void setZ2(int z)
{
this.setZ2(new CoordinateInt(z));
}
public void setX2(CoordinateInt x)
{
this.setNode(3, x);
}
public void setY2(CoordinateInt y)
{
this.setNode(4, y);
}
public void setZ2(CoordinateInt z)
{
this.setNode(5, z);
}
@Nonnull
public CoordinateInt getX2Coordiante()
{
return this.getNodeAsCoordinateInt(3);
}
@Nonnull
public CoordinateInt getY2Coordiante()
{
return this.getNodeAsCoordinateInt(4);
}
@Nonnull
public CoordinateInt getZ2Coordiante()
{
return this.getNodeAsCoordinateInt(5);
}
public double getX2()
{
return this.getX2Coordiante().getValue();
}
public double getY2()
{
return this.getY2Coordiante().getValue();
}
public double getZ2()
{
return this.getZ2Coordiante().getValue();
}
public BlockPos getBlockPos2()
{
return new BlockPos(this.getX2(), this.getY2(), this.getZ2());
}
}

View File

@@ -1,67 +0,0 @@
package exopandora.worldhandler.builder.impl;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.CommandBuilder;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.enchantment.Enchantment;
public class BuilderEnchantment extends CommandBuilder
{
@Nullable
public String getPlayer()
{
return this.getNodeAsString(0);
}
public void setPlayer(String player)
{
this.setNode(0, player);
}
@Nullable
public ResourceLocation getEnchantment()
{
return this.getNodeAsResourceLocation(1);
}
public void setEnchantment(Enchantment enchantment)
{
this.setEnchantment(enchantment.getRegistryName());
}
public void setEnchantment(ResourceLocation enchantment)
{
this.setNode(1, enchantment);
}
public void setLevel(int level)
{
this.setNode(2, level);
}
public int getLevel()
{
return this.getNodeAsInt(2);
}
@Override
public String getCommandName()
{
return "enchant";
}
@Override
public CommandSyntax getSyntax()
{
CommandSyntax syntax = new CommandSyntax();
syntax.addRequired("player", ArgumentType.STRING);
syntax.addRequired("enchantment", ArgumentType.RESOURCE_LOCATION);
syntax.addOptional("level", ArgumentType.INT, 1);
return syntax;
}
}

View File

@@ -1,506 +0,0 @@
package exopandora.worldhandler.builder.impl;
import java.util.List;
import java.util.Random;
import java.util.Set;
import javax.annotation.Nullable;
import org.apache.commons.lang3.StringUtils;
import exopandora.worldhandler.builder.CommandBuilderNBT;
import exopandora.worldhandler.builder.component.impl.EntityNBT;
import exopandora.worldhandler.util.MutableTextComponent;
import exopandora.worldhandler.util.ResourceHelper;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.nbt.ByteTag;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.IntTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.npc.VillagerProfession;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.registries.ForgeRegistries;
public abstract class BuilderEntity extends CommandBuilderNBT
{
private final EntityNBT nbt = new EntityNBT();
public abstract void setEntity(ResourceLocation entity);
public abstract ResourceLocation getEntity();
public void setName(String name)
{
this.setEntity(BuilderEntity.parseEntityName(name));
this.updateCustomComponent(name);
}
public void setNameAndId(String name)
{
this.setName(name);
this.nbt.setId(this.getEntity());
}
public void setId(ResourceLocation resource)
{
this.nbt.setId(resource);
}
public ResourceLocation getId()
{
return this.nbt.getId();
}
public void setAttribute(Attribute attribute, double ammount)
{
this.nbt.setAttribute(attribute, ammount);
}
public void removeAttribute(Attribute attribute)
{
this.nbt.removeAttribute(attribute);
}
public double getAttributeAmmount(Attribute attribute)
{
return this.nbt.getAttributeAmmount(attribute);
}
public Set<Attribute> getAttributes()
{
return this.nbt.getAttributes();
}
public void setCustomName(String name)
{
this.nbt.setCustomName(name);
}
@Nullable
public MutableTextComponent getCustomName()
{
return this.nbt.getCustomName();
}
public void setPassenger(int index, String name)
{
this.nbt.setPassenger(index, BuilderEntity.parseEntityName(name));
}
public void setPassenger(int index, EntityNBT entity)
{
this.nbt.setPassenger(index, entity);
}
public void setPassenger(int index, ResourceLocation id)
{
this.setPassenger(index, new EntityNBT(id));
}
public void addPassenger(EntityNBT entity)
{
this.nbt.addPassenger(entity);
}
public void addPassenger(int index, EntityNBT entity)
{
this.nbt.addPassenger(index, entity);
}
public void removePassenger(int index)
{
this.nbt.removePassenger(index);
}
public int getPassengerCount()
{
return this.nbt.getPassengerCount();
}
public List<EntityNBT> getPassengers()
{
return this.nbt.getPassengers();
}
@Nullable
public EntityNBT getPassenger(int index)
{
return this.nbt.getPassenger(index);
}
public boolean hasPassengers()
{
return this.nbt.hasPassengers();
}
public void setArmorItem(int index, Block block)
{
this.nbt.setArmorItem(index, block);
}
public void setArmorItem(int index, Item item)
{
this.nbt.setArmorItem(index, item);
}
public void setArmorItem(int index, ResourceLocation location)
{
this.nbt.setArmorItem(index, location);
}
public void setArmorItems(ResourceLocation[] armor)
{
this.nbt.setArmorItems(armor);
}
public ResourceLocation getArmorItem(int slot)
{
return this.nbt.getArmorItem(slot);
}
public void setHandItem(int index, Block block)
{
this.nbt.setHandItem(index, block);
}
public void setHandItem(int index, Item item)
{
this.nbt.setHandItem(index, item);
}
public void setHandItem(int index, ResourceLocation location)
{
this.nbt.setHandItem(index, location);
}
public ResourceLocation getHandItem(int slot)
{
return this.nbt.getHandItem(slot);
}
public double[] getMotion()
{
return this.nbt.getMotion();
}
public void setMotion(double x, double y, double z)
{
this.nbt.setMotion(x, y, z);
}
public double getMotionX()
{
return this.nbt.getMotionX();
}
public double getMotionY()
{
return this.nbt.getMotionY();
}
public double getMotionZ()
{
return this.nbt.getMotionZ();
}
public void setMotionX(double x)
{
this.nbt.setMotionX(x);
}
public void setMotionY(double y)
{
this.nbt.setMotionY(y);
}
public void setMotionZ(double z)
{
this.nbt.setMotionZ(z);
}
public void setAmplifier(MobEffect potion, byte amplifier)
{
this.nbt.setAmplifier(potion, amplifier);
}
public void setSeconds(MobEffect potion, int seconds)
{
this.nbt.setSeconds(potion, seconds);
}
public void setMinutes(MobEffect potion, int minutes)
{
this.nbt.setMinutes(potion, minutes);
}
public void setHours(MobEffect potion, int hours)
{
this.nbt.setHours(potion, hours);
}
public void setShowParticles(MobEffect potion, boolean showParticles)
{
this.nbt.setShowParticles(potion, showParticles);
}
public void setAmbient(MobEffect potion, boolean ambient)
{
this.nbt.setAmbient(potion, ambient);
}
public byte getAmplifier(MobEffect potion)
{
return this.nbt.getAmplifier(potion);
}
public int getSeconds(MobEffect potion)
{
return this.nbt.getSeconds(potion);
}
public int getMinutes(MobEffect potion)
{
return this.nbt.getMinutes(potion);
}
public int getHours(MobEffect potion)
{
return this.nbt.getHours(potion);
}
public boolean getShowParticles(MobEffect potion)
{
return this.nbt.getShowParticles(potion);
}
public boolean getAmbient(MobEffect potion)
{
return this.nbt.getAmbient(potion);
}
public Set<MobEffect> getMobEffects()
{
return this.nbt.getEffects();
}
public void setBlockState(BlockState blockState)
{
this.nbt.setBlockState(blockState);
}
public BlockState getBlockState()
{
return this.nbt.getBlockState();
}
public void setTime(int time)
{
this.nbt.setTime(time);
}
public int getTime()
{
return this.nbt.getTime();
}
public void setCommand(String command)
{
this.nbt.setCommand(command);
}
public String getCommand()
{
return this.nbt.getCommand();
}
public void setEntityNBT(String nbt)
{
this.nbt.setNBT(nbt);
}
public void setEntityNBT(CompoundTag nbt)
{
this.nbt.setNBT(nbt);
}
public CompoundTag getEntityNBT()
{
return this.nbt.getNBT();
}
@Override
protected CompoundTag buildNBT()
{
return this.nbt.serialize();
}
private void updateCustomComponent(String name)
{
ResourceLocation entity = this.getEntity();
if(name != null && entity != null)
{
if(entity.equals(EntityType.CAT.getRegistryName()))
{
this.nbt.setCustomComponent("CatType", IntTag.valueOf(new Random().nextInt(11)));
}
else if(entity.equals(EntityType.VILLAGER.getRegistryName()))
{
for(VillagerProfession profession : ForgeRegistries.PROFESSIONS)
{
if(StringUtils.equalsIgnoreCase(name, profession.toString()))
{
CompoundTag villagerData = new CompoundTag();
villagerData.putString("profession", profession.getRegistryName().toString());
this.nbt.setCustomComponent("VillagerData", villagerData);
break;
}
}
}
else if(entity.equals(EntityType.ZOMBIE.getRegistryName()))
{
if(StringUtils.containsIgnoreCase(name, "Baby"))
{
this.nbt.setCustomComponent("IsBaby", ByteTag.valueOf((byte) 1));
}
}
else if(entity.equals(EntityType.CHICKEN.getRegistryName()))
{
if(StringUtils.containsIgnoreCase(name, "Jockey") && !this.nbt.hasPassengers())
{
ListTag list = new ListTag();
EntityNBT zombie = new EntityNBT(EntityType.ZOMBIE.getRegistryName());
zombie.setIsBaby(true);
list.add(zombie.serialize());
this.nbt.setCustomComponent("Passengers", list);
}
}
else if(entity.equals(EntityType.SPIDER.getRegistryName()))
{
if(StringUtils.containsIgnoreCase(name, "Jockey") && !this.nbt.hasPassengers())
{
ListTag list = new ListTag();
EntityNBT skeleton = new EntityNBT(EntityType.SKELETON.getRegistryName());
skeleton.setHandItem(0, Items.BOW);
list.add(skeleton.serialize());
this.nbt.setCustomComponent("Passengers", list);
}
}
else
{
this.nbt.resetCustomComponent();
}
}
else
{
this.nbt.resetCustomComponent();
}
}
@Nullable
public static ResourceLocation parseEntityName(String entityName)
{
String name = ResourceHelper.stripToResourceLocation(entityName);
if(name == null || name.isEmpty())
{
return null;
}
for(EntityType<?> type : ForgeRegistries.ENTITIES.getValues())
{
if(type.canSummon() && entityName.equalsIgnoreCase(I18n.get(type.getDescriptionId())))
{
return type.getRegistryName();
}
}
String entity = name.replaceAll("_", "");
if("RedCow".equalsIgnoreCase(entity))
{
return EntityType.MOOSHROOM.getRegistryName();
}
else if("ChickenJockey".equalsIgnoreCase(entity))
{
return EntityType.CHICKEN.getRegistryName();
}
else if("Pigman".equalsIgnoreCase(entity) || "ZombiePig".equalsIgnoreCase(entity) || "ZombiePigman".equalsIgnoreCase(entity))
{
return EntityType.PIGLIN.getRegistryName();
}
else if("Dog".equalsIgnoreCase(entity))
{
return EntityType.WOLF.getRegistryName();
}
else if("Dragon".equalsIgnoreCase(entity))
{
return EntityType.ENDER_DRAGON.getRegistryName();
}
else if("SnowMan".equalsIgnoreCase(entity))
{
return EntityType.SNOW_GOLEM.getRegistryName();
}
else if("LavaCube".equalsIgnoreCase(entity)|| "MagmaSlime".equalsIgnoreCase(entity) || "LavaSlime".equalsIgnoreCase(entity))
{
return EntityType.MAGMA_CUBE.getRegistryName();
}
else if("SpiderJockey".equalsIgnoreCase(entity))
{
return EntityType.SPIDER.getRegistryName();
}
else if("VillagerGolem".equalsIgnoreCase(entity))
{
return EntityType.IRON_GOLEM.getRegistryName();
}
else if("Ozelot".equalsIgnoreCase(entity))
{
return EntityType.OCELOT.getRegistryName();
}
else if("Kitty".equalsIgnoreCase(entity) || "Kitten".equalsIgnoreCase(entity))
{
return EntityType.CAT.getRegistryName();
}
else if("TESTIFICATE".equalsIgnoreCase(entity) || ForgeRegistries.PROFESSIONS.getKeys().stream().anyMatch(profession -> profession.getPath().equalsIgnoreCase(entity)))
{
return EntityType.VILLAGER.getRegistryName();
}
else if("Octopus".equalsIgnoreCase(entity) || "Kraken".equalsIgnoreCase(entity))
{
return EntityType.SQUID.getRegistryName();
}
else if("Exwife".equalsIgnoreCase(entity))
{
return EntityType.GHAST.getRegistryName();
}
else if("CommandMinecart".equalsIgnoreCase(entity))
{
return EntityType.COMMAND_BLOCK_MINECART.getRegistryName();
}
else if("Wizard".equalsIgnoreCase(entity))
{
return EntityType.EVOKER.getRegistryName();
}
else if("Johnny".equalsIgnoreCase(entity))
{
return EntityType.VINDICATOR.getRegistryName();
}
else if("BabyZombie".equalsIgnoreCase(entity))
{
return EntityType.ZOMBIE.getRegistryName();
}
return ResourceHelper.stringToResourceLocation(name);
}
}

View File

@@ -1,97 +0,0 @@
package exopandora.worldhandler.builder.impl;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.CommandBuilder;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
import exopandora.worldhandler.util.EnumHelper;
public class BuilderExecute extends CommandBuilder
{
public void setMode1(EnumMode mode)
{
this.setNode(0, mode.toString());
}
@Nullable
public EnumMode getMode1()
{
return EnumHelper.valueOf(this.getNodeAsString(0), EnumMode.class);
}
public void setTarget(String target)
{
this.setNode(1, target);
}
@Nullable
public String getTarget()
{
return this.getNodeAsString(1);
}
public void setMode2(EnumMode mode)
{
this.setNode(2, mode.toString());
}
@Nullable
public EnumMode getMode2()
{
return EnumHelper.valueOf(this.getNodeAsString(2), EnumMode.class);
}
public void setCommand(String command)
{
if(command != null && command.startsWith("/"))
{
this.setNode(3, command.substring(1));
}
else
{
this.setNode(3, command);
}
}
@Nullable
public String getCommand()
{
return this.getNodeAsString(3);
}
@Override
public String getCommandName()
{
return "execute";
}
@Override
public CommandSyntax getSyntax()
{
CommandSyntax syntax = new CommandSyntax();
syntax.addRequired("modifier", ArgumentType.STRING);
syntax.addRequired("targets", ArgumentType.STRING);
syntax.addRequired("action", ArgumentType.STRING);
syntax.addRequired("command", ArgumentType.STRING);
return syntax;
}
public static enum EnumMode
{
ALIGN,
ANCHORED,
AS,
AT,
IN,
RUN;
@Override
public String toString()
{
return this.name().toLowerCase();
}
}
}

View File

@@ -1,127 +0,0 @@
package exopandora.worldhandler.builder.impl;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.CommandBuilder;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
import exopandora.worldhandler.util.EnumHelper;
public class BuilderExperience extends CommandBuilder
{
public BuilderExperience()
{
this.setLevel(0);
}
public BuilderExperience(EnumMode mode, int level, String player, EnumUnit unit)
{
this.setMode(mode);
this.setLevel(level);
this.setPlayer(player);
this.setUnit(unit);
}
public void setMode(EnumMode mode)
{
this.setNode(0, mode.toString());
}
@Nullable
public EnumMode getMode()
{
return EnumHelper.valueOf(this.getNodeAsString(0), EnumMode.class);
}
public void setPlayer(String player)
{
this.setNode(1, player);
}
@Nullable
public String getPlayer()
{
return this.getNodeAsString(1);
}
public void setLevel(int level)
{
this.setNode(2, level);
}
@Nullable
public int getLevel()
{
return this.getNodeAsInt(2);
}
public void setUnit(EnumUnit unit)
{
this.setNode(3, unit.toString());
}
@Nullable
public EnumUnit getUnit()
{
return EnumHelper.valueOf(this.getNodeAsString(3), EnumUnit.class);
}
@Override
public String getCommandName()
{
return "experience";
}
@Override
public CommandSyntax getSyntax()
{
CommandSyntax syntax = new CommandSyntax();
syntax.addRequired("add|set|query", ArgumentType.STRING);
syntax.addRequired("player", ArgumentType.STRING);
syntax.addRequired("amount", ArgumentType.INT);
syntax.addOptional("levels|points", ArgumentType.STRING);
return syntax;
}
public BuilderExperience buildAdd()
{
return new BuilderExperience(EnumMode.ADD, this.getLevel(), this.getPlayer(), EnumUnit.LEVELS);
}
public BuilderExperience buildRemove()
{
return new BuilderExperience(EnumMode.ADD, -this.getLevel(), this.getPlayer(), EnumUnit.LEVELS);
}
public BuilderExperience buildReset()
{
return new BuilderExperience(EnumMode.SET, 0, this.getPlayer(), EnumUnit.LEVELS);
}
public static enum EnumMode
{
ADD,
SET,
QUERY;
@Override
public String toString()
{
return this.name().toLowerCase();
}
}
public static enum EnumUnit
{
LEVELS,
POINTS;
@Override
public String toString()
{
return this.name().toLowerCase();
}
}
}

View File

@@ -1,136 +0,0 @@
package exopandora.worldhandler.builder.impl;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
import exopandora.worldhandler.builder.types.BlockResourceLocation;
import exopandora.worldhandler.builder.types.CoordinateInt;
import exopandora.worldhandler.util.BlockHelper;
import exopandora.worldhandler.util.EnumHelper;
import net.minecraft.core.BlockPos;
public class BuilderFill extends BuilderDoubleBlockPos
{
public BuilderFill()
{
super();
}
public BuilderFill(BlockResourceLocation block1, EnumBlockFilter filter, BlockResourceLocation block2)
{
this(BlockHelper.getPos1(), BlockHelper.getPos2(), block1, filter, block2);
}
public BuilderFill(BlockPos pos1, BlockPos pos2, BlockResourceLocation block1, EnumBlockFilter handling, BlockResourceLocation block2)
{
this.setPosition1(pos1);
this.setPosition2(pos2);
this.setBlock1(block1);
this.setBlockHandling(handling);
this.setBlock2(block2);
}
public BuilderFill(CoordinateInt x1, CoordinateInt y1, CoordinateInt z1, CoordinateInt x2, CoordinateInt y2, CoordinateInt z2, BlockResourceLocation block1)
{
this.setX1(x1);
this.setY1(y1);
this.setZ1(z1);
this.setX2(x2);
this.setY2(y2);
this.setZ2(z2);
this.setBlock1(block1);
}
public void setBlock1(String block)
{
this.setBlock1(BlockResourceLocation.valueOf(block));
}
public void setBlock1(BlockResourceLocation resource)
{
this.setNode(6, resource);
}
@Nullable
public BlockResourceLocation getBlock1()
{
return this.getNodeAsBlockResourceLocation(6);
}
public void setBlockHandling(EnumBlockFilter filter)
{
this.setNode(7, filter != null ? filter.toString() : null);
}
public void setBlock2(String block)
{
this.setBlock2(BlockResourceLocation.valueOf(block));
}
public void setBlock2(BlockResourceLocation resource)
{
this.setNode(8, resource);
}
@Nullable
public BlockResourceLocation getBlock2()
{
return this.getNodeAsBlockResourceLocation(8);
}
@Nullable
public EnumBlockFilter getBlockFilter()
{
return EnumHelper.valueOf(this.getNodeAsString(7), EnumBlockFilter.class);
}
public BuilderFill build()
{
return new BuilderFill(this.getBlock1(), null, null);
}
public BuilderFill buildReplace()
{
return new BuilderFill(this.getBlock2(), EnumBlockFilter.REPLACE, this.getBlock1());
}
@Override
public String getCommandName()
{
return "fill";
}
@Override
public final CommandSyntax getSyntax()
{
CommandSyntax syntax = new CommandSyntax();
syntax.addRequired("x1", ArgumentType.COORDINATE_INT);
syntax.addRequired("y1", ArgumentType.COORDINATE_INT);
syntax.addRequired("z1", ArgumentType.COORDINATE_INT);
syntax.addRequired("x2", ArgumentType.COORDINATE_INT);
syntax.addRequired("y2", ArgumentType.COORDINATE_INT);
syntax.addRequired("z2", ArgumentType.COORDINATE_INT);
syntax.addRequired("block", ArgumentType.BLOCK_RESOURCE_LOCATION);
syntax.addOptional("filter", ArgumentType.STRING);
syntax.addOptional("block", ArgumentType.BLOCK_RESOURCE_LOCATION, "block");
return syntax;
}
public static enum EnumBlockFilter
{
REPLACE,
DESTROY,
KEEP,
HOLLOW,
OUTLINE;
@Override
public String toString()
{
return this.name().toLowerCase();
}
}
}

View File

@@ -1,65 +0,0 @@
package exopandora.worldhandler.builder.impl;
import exopandora.worldhandler.builder.CommandBuilder;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
public class BuilderGamemode extends CommandBuilder
{
public BuilderGamemode()
{
super();
}
public BuilderGamemode(EnumGamemode mode)
{
this.setMode(mode);
}
public BuilderGamemode(EnumGamemode mode, String player)
{
this(mode);
this.setPlayer(player);
}
public void setMode(EnumGamemode mode)
{
this.setNode(0, mode.toString());
}
public void setPlayer(String player)
{
this.setNode(1, player);
}
@Override
public String getCommandName()
{
return "gamemode";
}
@Override
public final CommandSyntax getSyntax()
{
CommandSyntax syntax = new CommandSyntax();
syntax.addRequired("mode", ArgumentType.STRING);
syntax.addOptional("player", ArgumentType.STRING);
return syntax;
}
public static enum EnumGamemode
{
SURVIVAL,
CREATIVE,
ADVENTURE,
SPECTATOR;
@Override
public String toString()
{
return this.name().toLowerCase();
}
}
}

View File

@@ -1,61 +0,0 @@
package exopandora.worldhandler.builder.impl;
import exopandora.worldhandler.builder.CommandBuilder;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
public class BuilderGamerule extends CommandBuilder
{
public BuilderGamerule()
{
super();
}
public BuilderGamerule(String rule, String value)
{
this.setRule(rule);
this.setValue(value);
}
public void setRule(String rule)
{
this.setNode(0, rule);
}
public String getRule()
{
return this.getNodeAsString(0);
}
public void setValue(String value)
{
this.setNode(1, value);
}
public String getValue()
{
return this.getNodeAsString(1);
}
public BuilderGamerule build(String value)
{
return new BuilderGamerule(this.getRule(), value);
}
@Override
public String getCommandName()
{
return "gamerule";
}
@Override
public final CommandSyntax getSyntax()
{
CommandSyntax syntax = new CommandSyntax();
syntax.addOptional("rule", ArgumentType.STRING);
syntax.addOptional("true|false|value", ArgumentType.STRING);
return syntax;
}
}

View File

@@ -1,27 +0,0 @@
package exopandora.worldhandler.builder.impl;
import exopandora.worldhandler.builder.CommandString;
import exopandora.worldhandler.builder.ICommandBuilder;
public class BuilderGeneric implements ICommandBuilder
{
private final String command;
private final String[] arguments;
public BuilderGeneric(String command, String... arguments)
{
this.command = command;
this.arguments = arguments;
}
@Override
public String toCommand()
{
return new CommandString(this.command, this.arguments).toString();
}
public String toActualCommand()
{
return this.toCommand();
}
}

View File

@@ -1,105 +0,0 @@
package exopandora.worldhandler.builder.impl;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.CommandBuilderNBT;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
import exopandora.worldhandler.builder.types.ItemResourceLocation;
import exopandora.worldhandler.util.ResourceHelper;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.registries.ForgeRegistries;
public class BuilderGive extends CommandBuilderNBT
{
private final ItemResourceLocation itemResourceLocation = new ItemResourceLocation();
public BuilderGive()
{
this(null, null);
}
public BuilderGive(String player, ResourceLocation item)
{
this.setPlayer(player);
this.setItem(item);
this.setCount(1);
}
public void setPlayer(String username)
{
this.setNode(0, username);
}
@Nullable
public String getPlayer()
{
return this.getNodeAsString(0);
}
public void setItem(String item)
{
this.setItem(ResourceHelper.assertRegistered(ResourceHelper.stringToResourceLocation(item), ForgeRegistries.ITEMS));
}
public void setItem(ResourceLocation item)
{
this.itemResourceLocation.setResourceLocation(item);
this.setNode(1, this.itemResourceLocation);
}
@Nullable
public ItemResourceLocation getItem()
{
return this.getNodeAsItemResourceLocation(1);
}
public void setCount(int count)
{
this.setNode(2, count);
}
public int getCount()
{
return this.getNodeAsInt(2);
}
@Override
public void setNBT(CompoundTag nbt)
{
this.itemResourceLocation.setNBT(nbt);
this.setNode(1, this.itemResourceLocation);
}
@Nullable
public CompoundTag getNBT()
{
ItemResourceLocation item = this.getItem();
if(item != null)
{
return item.getNBT();
}
return null;
}
@Override
public String getCommandName()
{
return "give";
}
@Override
public final CommandSyntax getSyntax()
{
CommandSyntax syntax = new CommandSyntax();
syntax.addRequired("player", ArgumentType.STRING);
syntax.addRequired("item", ArgumentType.ITEM_RESOURCE_LOCATION);
syntax.addRequired("count", ArgumentType.INT);
return syntax;
}
}

View File

@@ -1,21 +0,0 @@
package exopandora.worldhandler.builder.impl;
import java.util.Arrays;
import exopandora.worldhandler.builder.ICommandBuilder;
public class BuilderMultiCommand implements ICommandBuilder
{
private final ICommandBuilder[] builders;
public BuilderMultiCommand(ICommandBuilder... builders)
{
this.builders = builders;
}
@Override
public String toCommand()
{
return String.join(" | ", Arrays.stream(this.builders).map(ICommandBuilder::toCommand).toArray(String[]::new));
}
}

View File

@@ -1,39 +0,0 @@
package exopandora.worldhandler.builder.impl;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.NoteBlockInstrument;
public class BuilderNoteEditor extends BuilderSetBlock
{
public BuilderNoteEditor()
{
this.setBlock(Blocks.NOTE_BLOCK.getRegistryName());
this.setMode(EnumMode.REPLACE);
}
public BuilderNoteEditor(int note)
{
this();
this.setNote(note);
}
public BuilderNoteEditor(int note, BlockPos pos)
{
this(note);
this.setPosition(pos);
this.setState(BlockStateProperties.NOTEBLOCK_INSTRUMENT, NoteBlockInstrument.byState(Minecraft.getInstance().level.getBlockState(pos.below())));
}
public void setNote(int note)
{
this.setState(BlockStateProperties.NOTE, note);
}
public BuilderNoteEditor build(int note)
{
return new BuilderNoteEditor(note, this.getBlockPos());
}
}

View File

@@ -1,44 +0,0 @@
package exopandora.worldhandler.builder.impl;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.CommandBuilder;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
public class BuilderPlayer extends CommandBuilder
{
private final String command;
public BuilderPlayer(String command)
{
this.command = command;
}
public void setPlayer(String player)
{
this.setNode(0, player);
}
@Nullable
public String getPlayer()
{
return this.getNodeAsString(0);
}
@Override
public String getCommandName()
{
return this.command;
}
@Override
public final CommandSyntax getSyntax()
{
CommandSyntax syntax = new CommandSyntax();
syntax.addRequired("player", ArgumentType.STRING);
return syntax;
}
}

View File

@@ -1,56 +0,0 @@
package exopandora.worldhandler.builder.impl;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.CommandBuilder;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
public class BuilderPlayerReason extends CommandBuilder
{
private final String command;
public BuilderPlayerReason(String command)
{
this.command = command;
}
public void setPlayer(String player)
{
this.setNode(0, player);
}
@Nullable
public String getPlayer()
{
return this.getNodeAsString(0);
}
public void setReason(String reason)
{
this.setNode(1, reason);
}
@Nullable
public String getReason()
{
return this.getNodeAsString(1);
}
@Override
public String getCommandName()
{
return this.command;
}
@Override
public final CommandSyntax getSyntax()
{
CommandSyntax syntax = new CommandSyntax();
syntax.addRequired("player", ArgumentType.STRING);
syntax.addOptional("reason", ArgumentType.STRING);
return syntax;
}
}

View File

@@ -1,197 +0,0 @@
package exopandora.worldhandler.builder.impl;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.CommandBuilder;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.component.impl.EffectNBT;
import exopandora.worldhandler.builder.types.ArgumentType;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.effect.MobEffect;
import net.minecraftforge.registries.ForgeRegistries;
public class BuilderPotionEffect extends CommandBuilder
{
private int seconds;
private int minutes;
private int hours;
public BuilderPotionEffect()
{
this(null, null, null);
}
public BuilderPotionEffect(EnumMode mode, String player, ResourceLocation effect)
{
this(mode, player, effect, 0, (byte) 0, false);
}
public BuilderPotionEffect(EnumMode mode, String player, ResourceLocation effect, int duration, byte amplifier, boolean hideParticles)
{
this.setMode(mode);
this.setPlayer(player);
this.setMobEffect(effect);
this.setDuration(duration);
this.setAmplifier(amplifier);
this.setHideParticles(hideParticles);
}
public void setMode(EnumMode mode)
{
if(mode != null)
{
this.setNode(0, mode.toString());
}
}
public void setPlayer(String player)
{
this.setNode(1, player);
}
@Nullable
public String getPlayer()
{
return this.getNodeAsString(1);
}
public void setMobEffect(MobEffect effect)
{
this.setMobEffect(effect.getRegistryName());
}
public void setMobEffect(ResourceLocation effect)
{
this.setNode(2, effect);
}
@Nullable
public MobEffect getMobEffectAsPotion()
{
ResourceLocation location = this.getNodeAsResourceLocation(2);
if(location != null)
{
return ForgeRegistries.MOB_EFFECTS.getValue(location);
}
return null;
}
@Nullable
public ResourceLocation getMobEffect()
{
return this.getNodeAsResourceLocation(2);
}
public void setDuration(int duration)
{
this.setNode(3, Math.min(duration, 1000000));
}
public int getDuration()
{
return this.getNodeAsInt(3);
}
public void setAmplifier(byte amplifier)
{
this.setNode(4, (byte) (amplifier - 1));
}
public int getAmplifier()
{
return this.getNodeAsByte(4);
}
public void setHideParticles(boolean hideParticles)
{
this.setNode(5, hideParticles);
}
public boolean getHideParticles()
{
return this.getNodeAsBoolean(5);
}
public int getSeconds()
{
return this.seconds;
}
public void setSeconds(int seconds)
{
this.seconds = seconds;
this.setDuration(EffectNBT.toSeconds(this.seconds, this.minutes, this.hours));
}
public int getMinutes()
{
return this.minutes;
}
public void setMinutes(int minutes)
{
this.minutes = minutes;
this.setDuration(EffectNBT.toSeconds(this.seconds, this.minutes, this.hours));
}
public int getHours()
{
return this.hours;
}
public void setHours(int hours)
{
this.hours = hours;
this.setDuration(EffectNBT.toSeconds(this.seconds, this.minutes, this.hours));
}
public BuilderGeneric buildGive()
{
return new BuilderGeneric(this.getCommandName(), EnumMode.GIVE.toString(), this.getPlayer(), this.getMobEffect().toString(), String.valueOf(this.getDuration()), String.valueOf(this.getAmplifier()), String.valueOf(this.getHideParticles()));
}
public BuilderGeneric buildRemove()
{
return new BuilderGeneric(this.getCommandName(), EnumMode.CLEAR.toString(), this.getPlayer(), this.getMobEffect().toString());
}
public BuilderGeneric buildClear()
{
return new BuilderGeneric(this.getCommandName(), EnumMode.CLEAR.toString(), this.getPlayer());
}
@Override
public String getCommandName()
{
return "effect";
}
@Override
public final CommandSyntax getSyntax()
{
CommandSyntax syntax = new CommandSyntax();
syntax.addRequired("give|clear", ArgumentType.STRING);
syntax.addRequired("player", ArgumentType.STRING);
syntax.addRequired("effect", ArgumentType.RESOURCE_LOCATION);
syntax.addOptional("seconds", ArgumentType.INT, 0);
syntax.addOptional("amplifier", ArgumentType.BYTE, (byte) -1);
syntax.addOptional("hideParticles", ArgumentType.BOOLEAN, false);
return syntax;
}
public static enum EnumMode
{
GIVE,
CLEAR;
@Override
public String toString()
{
return this.name().toLowerCase();
}
}
}

View File

@@ -1,94 +0,0 @@
package exopandora.worldhandler.builder.impl;
import java.util.Set;
import exopandora.worldhandler.builder.component.impl.ComponentPotionItem;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.item.Item;
public class BuilderPotionItem extends BuilderGive
{
private final ComponentPotionItem potion;
public BuilderPotionItem()
{
this(null, null, new ComponentPotionItem());
}
public BuilderPotionItem(ResourceLocation item, String player, ComponentPotionItem potion)
{
super(player, item);
this.potion = this.registerNBTComponent(potion);
}
public void setAmplifier(MobEffect potion, byte amplifier)
{
this.potion.setAmplifier(potion, amplifier);
}
public void setSeconds(MobEffect potion, int seconds)
{
this.potion.setSeconds(potion, seconds);
}
public void setMinutes(MobEffect potion, int minutes)
{
this.potion.setMinutes(potion, minutes);
}
public void setHours(MobEffect potion, int hours)
{
this.potion.setHours(potion, hours);
}
public void setShowParticles(MobEffect potion, boolean showParticles)
{
this.potion.setShowParticles(potion, showParticles);
}
public void setAmbient(MobEffect potion, boolean ambient)
{
this.potion.setAmbient(potion, ambient);
}
public byte getAmplifier(MobEffect potion)
{
return this.potion.getAmplifier(potion);
}
public int getSeconds(MobEffect potion)
{
return this.potion.getSeconds(potion);
}
public int getMinutes(MobEffect potion)
{
return this.potion.getMinutes(potion);
}
public int getHours(MobEffect potion)
{
return this.potion.getHours(potion);
}
public boolean getShowParticles(MobEffect potion)
{
return this.potion.getShowParticles(potion);
}
public boolean getAmbient(MobEffect potion)
{
return this.potion.getAmbient(potion);
}
public Set<MobEffect> getMobEffects()
{
return this.potion.getMobEffects();
}
public BuilderPotionItem build(Item item)
{
return new BuilderPotionItem(item.getRegistryName(), this.getPlayer(), this.potion);
}
}

View File

@@ -1,98 +0,0 @@
package exopandora.worldhandler.builder.impl;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.CommandBuilder;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
import exopandora.worldhandler.util.EnumHelper;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.crafting.Recipe;
public class BuilderRecipe extends CommandBuilder
{
public BuilderRecipe()
{
this(null, null, null);
}
public BuilderRecipe(EnumMode mode, String player, ResourceLocation recipe)
{
this.setMode(mode);
this.setPlayer(player);
this.setRecipe(recipe);
}
public void setMode(EnumMode mode)
{
this.setNode(0, mode != null ? mode.toString() : null);
}
@Nullable
public EnumMode getMode()
{
return EnumHelper.valueOf(this.getNodeAsString(0), EnumMode.class);
}
public void setPlayer(String player)
{
this.setNode(1, player);
}
@Nullable
public String getPlayer()
{
return this.getNodeAsString(1);
}
public void setRecipe(Recipe<?> recipe)
{
this.setRecipe(recipe.getId());
}
public void setRecipe(ResourceLocation recipe)
{
this.setNode(2, recipe);
}
@Nullable
public ResourceLocation getRecipe()
{
return this.getNodeAsResourceLocation(2);
}
public BuilderRecipe build(EnumMode mode)
{
return new BuilderRecipe(mode, this.getPlayer(), this.getRecipe());
}
@Override
public String getCommandName()
{
return "recipe";
}
@Override
public CommandSyntax getSyntax()
{
CommandSyntax syntax = new CommandSyntax();
syntax.addRequired("give|take", ArgumentType.STRING);
syntax.addOptional("player", ArgumentType.STRING);
syntax.addOptional("recipe", ArgumentType.RESOURCE_LOCATION);
return syntax;
}
public static enum EnumMode
{
GIVE,
TAKE;
@Override
public String toString()
{
return this.name().toLowerCase();
}
}
}

View File

@@ -1,12 +0,0 @@
package exopandora.worldhandler.builder.impl;
import exopandora.worldhandler.builder.CommandBuilder;
public abstract class BuilderScoreboard extends CommandBuilder
{
@Override
public String getCommandName()
{
return "scoreboard";
}
}

View File

@@ -1,173 +0,0 @@
package exopandora.worldhandler.builder.impl;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
import exopandora.worldhandler.builder.types.GreedyString;
import exopandora.worldhandler.util.EnumHelper;
public class BuilderScoreboardObjectives extends BuilderScoreboard
{
public BuilderScoreboardObjectives()
{
this.init();
}
private void init()
{
this.setNode(0, "objectives");
}
public void setMode(EnumMode mode)
{
String objective = this.getObjective();
this.updateSyntax(this.getSyntax(mode));
this.setNode(1, mode.toString());
if(objective != null)
{
this.setObjective(objective);
}
this.init();
}
@Nullable
public EnumMode getMode()
{
return EnumHelper.valueOf(this.getNodeAsString(1), EnumMode.class);
}
public void setObjective(String name)
{
String objective = name != null ? name.replaceAll(" ", "_") : null;
EnumMode mode = this.getMode();
if(mode != null)
{
switch(mode)
{
case ADD:
this.setNode(4, new GreedyString(name));
case REMOVE:
this.setNode(2, objective);
break;
case SETDISPLAY:
this.setNode(3, objective);
break;
default:
break;
}
}
}
public void setCriteria(String criteria)
{
if(this.getMode() == null || !this.getMode().equals(EnumMode.ADD))
{
this.setMode(EnumMode.ADD);
}
this.setNode(3, criteria);
}
public void setSlot(String slot)
{
if(this.getMode() == null || !this.getMode().equals(EnumMode.SETDISPLAY))
{
this.setMode(EnumMode.SETDISPLAY);
}
this.setNode(2, slot);
}
@Nullable
public String getSlot()
{
if(this.getMode() != null && this.getMode().equals(EnumMode.SETDISPLAY))
{
return this.getNodeAsString(2);
}
return null;
}
@Nullable
public String getObjective()
{
EnumMode mode = this.getMode();
if(mode != null)
{
switch(mode)
{
case ADD: case REMOVE:
return this.getNodeAsString(2);
case SETDISPLAY:
return this.getNodeAsString(3);
default:
break;
}
}
return null;
}
@Nullable
private CommandSyntax getSyntax(EnumMode mode)
{
CommandSyntax syntax = new CommandSyntax();
switch(mode)
{
case ADD:
syntax.addRequired("objectives", ArgumentType.STRING);
syntax.addRequired("add", ArgumentType.STRING);
syntax.addRequired("name", ArgumentType.STRING);
syntax.addRequired("criteria_type", ArgumentType.STRING);
syntax.addOptional("display_name...", ArgumentType.GREEDY_STRING);
return syntax;
case REMOVE:
syntax.addRequired("objectives", ArgumentType.STRING);
syntax.addRequired("remove", ArgumentType.STRING);
syntax.addRequired("name", ArgumentType.STRING);
return syntax;
case SETDISPLAY:
syntax.addRequired("objectives", ArgumentType.STRING);
syntax.addRequired("setdisplay", ArgumentType.STRING);
syntax.addRequired("slot", ArgumentType.STRING);
syntax.addOptional("objective", ArgumentType.STRING);
return syntax;
default:
return null;
}
}
@Override
public final CommandSyntax getSyntax()
{
CommandSyntax syntax = new CommandSyntax();
syntax.addRequired("objectives", ArgumentType.STRING);
syntax.addRequired("list|add|remove|setdisplay", ArgumentType.STRING);
syntax.addOptional("...", ArgumentType.STRING);
return syntax;
}
public static enum EnumMode
{
ADD,
REMOVE,
SETDISPLAY;
@Override
public String toString()
{
return this.name().toLowerCase();
}
}
}

View File

@@ -1,169 +0,0 @@
package exopandora.worldhandler.builder.impl;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
import exopandora.worldhandler.util.EnumHelper;
public class BuilderScoreboardPlayers extends BuilderScoreboard
{
public BuilderScoreboardPlayers()
{
this.init();
}
private void init()
{
this.setNode(0, "players");
}
@Nullable
public EnumMode getMode()
{
return EnumHelper.valueOf(this.getNodeAsString(1), EnumMode.class);
}
public void setMode(String mode)
{
String objective = this.getObjective();
String player = this.getPlayer();
int points = this.getPoints();
this.updateSyntax(this.getSyntax(mode));
this.setNode(1, mode);
this.setNode(2, player);
this.setObjective(objective);
if(!mode.equals("enable"))
{
this.setPoints(points);
}
this.init();
}
public void setPlayer(String player)
{
this.setNode(2, player);
}
@Nullable
public String getPlayer()
{
return this.getNodeAsString(2);
}
public void setObjective(String name)
{
if(this.getMode() != null)
{
this.setNode(3, name != null ? name.replaceAll(" ", "_") : null);
}
}
@Nullable
public String getObjective()
{
if(this.getMode() != null)
{
return this.getNodeAsString(3);
}
return null;
}
public void setPoints(int points)
{
this.setNode(4, points);
}
public int getPoints()
{
EnumMode mode = this.getMode();
if(mode != null && !EnumMode.ENABLE.equals(mode))
{
return this.getNodeAsInt(4);
}
return 0;
}
private CommandSyntax getSyntax(String mode)
{
CommandSyntax syntax = new CommandSyntax();
if(mode.equals("enable"))
{
syntax.addRequired("players", ArgumentType.STRING);
syntax.addRequired("enable", ArgumentType.STRING);
syntax.addRequired("player", ArgumentType.STRING);
syntax.addRequired("objective", ArgumentType.STRING);
return syntax;
}
syntax.addRequired("players", ArgumentType.STRING);
syntax.addRequired("add|set|remove", ArgumentType.STRING, "add|set|remove");
syntax.addRequired("player", ArgumentType.STRING);
syntax.addRequired("objective", ArgumentType.STRING);
syntax.addRequired("score", ArgumentType.INT, 0);
return syntax;
}
public BuilderScoreboardPlayers buildPoints(EnumMode mode)
{
return this.buildPoints(mode, this.getPoints());
}
public BuilderScoreboardPlayers buildPoints(EnumMode mode, int points)
{
BuilderScoreboardPlayers builder = new BuilderScoreboardPlayers();
builder.setMode(mode.toString());
builder.setPlayer(this.getPlayer());
builder.setObjective(this.getObjective());
builder.setPoints(points);
return builder;
}
public BuilderScoreboardPlayers buildEnable()
{
BuilderScoreboardPlayers builder = new BuilderScoreboardPlayers();
builder.setMode(EnumMode.ENABLE.toString());
builder.setPlayer(this.getPlayer());
builder.setObjective(this.getObjective());
return builder;
}
@Override
public final CommandSyntax getSyntax()
{
CommandSyntax syntax = new CommandSyntax();
syntax.addRequired("players", ArgumentType.STRING);
syntax.addRequired("add|enable|get|list|operation|remove|reset|set", ArgumentType.STRING);
syntax.addOptional("...", ArgumentType.STRING);
return syntax;
}
public static enum EnumMode
{
ADD,
REMOVE,
ENABLE,
SET;
@Override
public String toString()
{
return this.name().toLowerCase();
}
}
}

View File

@@ -1,105 +0,0 @@
package exopandora.worldhandler.builder.impl;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
import exopandora.worldhandler.builder.types.BlockResourceLocation;
import exopandora.worldhandler.builder.types.CoordinateInt;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.state.properties.Property;
public class BuilderSetBlock extends BuilderBlockPos
{
private final BlockResourceLocation blockResourceLocation = new BlockResourceLocation();
public BuilderSetBlock()
{
super(0);
}
public BuilderSetBlock(BlockPos pos, ResourceLocation block, EnumMode mode)
{
this();
this.setPosition(pos);
this.setBlock(block);
this.setMode(mode);
}
public <T extends Comparable<T>> BuilderSetBlock(CoordinateInt x, CoordinateInt y, CoordinateInt z, ResourceLocation block, EnumMode mode)
{
this();
this.setX(x);
this.setY(y);
this.setZ(z);
this.setBlock(block);
this.setMode(mode);
}
public <T extends Comparable<T>> void setState(Property<T> property, T value)
{
this.blockResourceLocation.setProperty(property, value);
this.setBlock(this.blockResourceLocation);
}
public void setBlock(ResourceLocation block)
{
this.blockResourceLocation.setResourceLocation(block);
this.setBlock(this.blockResourceLocation);
}
public void setMode(EnumMode mode)
{
this.setNode(4, mode.toString());
}
public void setBlockNBT(CompoundTag nbt)
{
this.blockResourceLocation.setNBT(nbt);
this.setBlock(this.blockResourceLocation);
}
protected void setBlock(BlockResourceLocation block)
{
this.setNode(3, this.blockResourceLocation);
}
@Override
public void setNBT(CompoundTag nbt)
{
}
@Override
public String getCommandName()
{
return "setblock";
}
@Override
public final CommandSyntax getSyntax()
{
CommandSyntax syntax = new CommandSyntax();
syntax.addRequired("x", ArgumentType.COORDINATE_INT);
syntax.addRequired("y", ArgumentType.COORDINATE_INT);
syntax.addRequired("z", ArgumentType.COORDINATE_INT);
syntax.addRequired("block", ArgumentType.BLOCK_RESOURCE_LOCATION);
syntax.addOptional("mode", ArgumentType.STRING);
return syntax;
}
public static enum EnumMode
{
KEEP,
REPLACE,
DESTROY;
@Override
public String toString()
{
return this.name().toLowerCase();
}
}
}

View File

@@ -1,73 +0,0 @@
package exopandora.worldhandler.builder.impl;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.component.impl.ComponentTag;
import exopandora.worldhandler.util.MutableTextComponent;
import exopandora.worldhandler.util.SignText;
public class BuilderSignEditor extends BuilderData
{
@SuppressWarnings("unchecked")
private final ComponentTag<SignText>[] sign = new ComponentTag[4];
public BuilderSignEditor()
{
this.setMode(EnumMode.MERGE);
this.setTarget(EnumTarget.BLOCK);
for(int x = 0; x < 4; x++)
{
this.sign[x] = this.registerNBTComponent(new ComponentTag<SignText>("Text" + (x + 1), new SignText(), SignText::serialize));
}
}
public boolean isSpecial()
{
for(int x = 0; x < this.sign.length; x++)
{
if(this.getColoredString(x).isSpecial())
{
return true;
}
}
return false;
}
@Nullable
public MutableTextComponent getColoredString(int line)
{
if(this.checkBounds(line))
{
return this.sign[line].getValue();
}
return null;
}
@Nullable
public String getCommand(int line)
{
if(this.checkBounds(line))
{
return this.sign[line].getValue().getCommand();
}
return null;
}
@Nullable
public void setCommand(int line, String command)
{
if(this.checkBounds(line))
{
this.sign[line].getValue().setCommand(command);
}
}
private boolean checkBounds(int line)
{
return line >= 0 && line < this.sign.length;
}
}

View File

@@ -1,56 +0,0 @@
package exopandora.worldhandler.builder.impl;
import exopandora.worldhandler.builder.CommandBuilder;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
import exopandora.worldhandler.builder.types.Coordinate.EnumType;
import exopandora.worldhandler.builder.types.CoordinateInt;
public class BuilderSpawnpoint extends CommandBuilder
{
public BuilderSpawnpoint()
{
this.setX(new CoordinateInt(EnumType.GLOBAL));
this.setY(new CoordinateInt(EnumType.GLOBAL));
this.setZ(new CoordinateInt(EnumType.GLOBAL));
}
@Override
public String getCommandName()
{
return "spawnpoint";
}
public void setPlayer(String player)
{
this.setNode(0, player);
}
public void setX(CoordinateInt x)
{
this.setNode(1, x);
}
public void setY(CoordinateInt y)
{
this.setNode(2, y);
}
public void setZ(CoordinateInt z)
{
this.setNode(3, z);
}
@Override
public final CommandSyntax getSyntax()
{
CommandSyntax syntax = new CommandSyntax();
syntax.addRequired("player", ArgumentType.STRING);
syntax.addRequired("x", ArgumentType.COORDINATE_INT);
syntax.addRequired("y", ArgumentType.COORDINATE_INT);
syntax.addRequired("z", ArgumentType.COORDINATE_INT);
return syntax;
}
}

View File

@@ -1,84 +0,0 @@
package exopandora.worldhandler.builder.impl;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
import exopandora.worldhandler.builder.types.Coordinate.EnumType;
import exopandora.worldhandler.builder.types.CoordinateDouble;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
public class BuilderSummon extends BuilderEntity
{
public BuilderSummon()
{
this.setX(new CoordinateDouble(0.0, EnumType.LOCAL));
this.setY(new CoordinateDouble(0.0, EnumType.LOCAL));
this.setZ(new CoordinateDouble(2.0, EnumType.LOCAL));
}
public void setEntity(ResourceLocation entity)
{
this.setNode(0, entity);
}
public ResourceLocation getEntity()
{
return this.getNodeAsResourceLocation(0);
}
public void setX(CoordinateDouble x)
{
this.setNode(1, x);
}
public CoordinateDouble getX()
{
return this.getNodeAsCoordinateDouble(1);
}
public void setY(CoordinateDouble y)
{
this.setNode(2, y);
}
public CoordinateDouble getY()
{
return this.getNodeAsCoordinateDouble(2);
}
public void setZ(CoordinateDouble z)
{
this.setNode(3, z);
}
public CoordinateDouble getZ()
{
return this.getNodeAsCoordinateDouble(3);
}
@Override
public void setNBT(CompoundTag nbt)
{
this.setNode(4, nbt);
}
@Override
public String getCommandName()
{
return "summon";
}
@Override
public CommandSyntax getSyntax()
{
CommandSyntax syntax = new CommandSyntax();
syntax.addRequired("entity_name", ArgumentType.RESOURCE_LOCATION);
syntax.addOptional("x", ArgumentType.COORDINATE_DOUBLE);
syntax.addOptional("y", ArgumentType.COORDINATE_DOUBLE);
syntax.addOptional("z", ArgumentType.COORDINATE_DOUBLE);
syntax.addOptional("nbt", ArgumentType.NBT);
return syntax;
}
}

View File

@@ -1,88 +0,0 @@
package exopandora.worldhandler.builder.impl;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.CommandBuilder;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
public class BuilderTag extends CommandBuilder
{
public BuilderTag()
{
super();
}
public BuilderTag(String player, EnumMode mode, String name)
{
this.setPlayer(player);
this.setMode(mode);
this.setName(name);
}
public void setPlayer(String player)
{
this.setNode(0, player);
}
@Nullable
public String getPlayer()
{
return this.getNodeAsString(0);
}
public void setMode(EnumMode mode)
{
if(mode != null)
{
this.setNode(1, mode.toString());
}
}
public void setName(String name)
{
this.setNode(2, name);
}
@Nullable
public String getName()
{
return this.getNodeAsString(2);
}
@Override
public String getCommandName()
{
return "tag";
}
@Override
public CommandSyntax getSyntax()
{
CommandSyntax syntax = new CommandSyntax();
syntax.addRequired("player", ArgumentType.STRING);
syntax.addRequired("add|list|remove", ArgumentType.STRING);
syntax.addRequired("name", ArgumentType.STRING);
return syntax;
}
public BuilderTag build(EnumMode mode)
{
return new BuilderTag(this.getPlayer(), mode, this.getName());
}
public static enum EnumMode
{
ADD,
LIST,
REMOVE;
@Override
public String toString()
{
return this.name().toLowerCase();
}
}
}

View File

@@ -1,254 +0,0 @@
package exopandora.worldhandler.builder.impl;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.CommandBuilder;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
import exopandora.worldhandler.builder.types.GreedyString;
import exopandora.worldhandler.util.EnumHelper;
public class BuilderTeams extends CommandBuilder
{
public void setTeam(String name)
{
String team = name != null ? name.replaceAll(" ", "_") : null;
if(EnumMode.ADD.equals(this.getMode()))
{
this.setNode(2, new GreedyString(name));
}
this.setNode(1, team);
}
@Nullable
public EnumMode getMode()
{
return EnumHelper.valueOf(this.getNodeAsString(0), EnumMode.class);
}
@Nullable
public String getTeam()
{
return this.getNodeAsString(1);
}
public void setMode(EnumMode mode)
{
String team = this.getTeam();
String player = this.getPlayer();
this.updateSyntax(this.getSyntax(mode));
this.setNode(0, mode.toString());
if(team != null)
{
this.setTeam(team);
}
if(player != null && (EnumMode.JOIN.equals(mode) || EnumMode.LEAVE.equals(mode) || EnumMode.JOIN_OR_LEAVE.equals(mode)))
{
this.setPlayer(player);
}
}
public void setPlayer(String player)
{
EnumMode mode = this.getMode();
if(EnumMode.JOIN.equals(mode) || EnumMode.LEAVE.equals(mode) || EnumMode.JOIN_OR_LEAVE.equals(mode))
{
this.setNode(2, player);
}
}
@Nullable
public String getPlayer()
{
EnumMode mode = this.getMode();
if(EnumMode.JOIN.equals(mode) || EnumMode.LEAVE.equals(mode) || EnumMode.JOIN_OR_LEAVE.equals(mode))
{
return this.getNodeAsString(2);
}
return null;
}
public void setRule(String rule)
{
if(!EnumMode.MODIFY.equals(this.getMode()))
{
this.setMode(EnumMode.MODIFY);
}
this.setNode(2, rule);
}
@Nullable
public String getRule()
{
EnumMode mode = this.getMode();
if(mode == null || EnumMode.MODIFY.equals(mode))
{
return this.getNodeAsString(2);
}
return null;
}
public void setValue(String value)
{
if(!EnumMode.MODIFY.equals(this.getMode()))
{
this.setMode(EnumMode.MODIFY);
}
this.setNode(3, value);
}
@Nullable
public String getValue()
{
EnumMode mode = this.getMode();
if(mode == null || EnumMode.MODIFY.equals(mode))
{
return this.getNodeAsString(3);
}
return null;
}
@Nullable
private CommandSyntax getSyntax(EnumMode mode)
{
if(EnumMode.ADD.equals(mode))
{
CommandSyntax syntax = new CommandSyntax();
syntax.addRequired("add", ArgumentType.STRING);
syntax.addRequired("name", ArgumentType.STRING);
syntax.addOptional("display_name...", ArgumentType.GREEDY_STRING);
return syntax;
}
else if(EnumMode.REMOVE.equals(mode) || EnumMode.EMPTY.equals(mode) || EnumMode.REMOVE_OR_EMPTY.equals(mode))
{
CommandSyntax syntax = new CommandSyntax();
syntax.addRequired("remove|empty", ArgumentType.STRING, "remove|empty");
syntax.addRequired("name", ArgumentType.STRING);
return syntax;
}
else if(EnumMode.JOIN.equals(mode) || EnumMode.LEAVE.equals(mode) || EnumMode.JOIN_OR_LEAVE.equals(mode))
{
CommandSyntax syntax = new CommandSyntax();
syntax.addRequired("join|leave", ArgumentType.STRING, "join|leave");
syntax.addRequired("player|team", ArgumentType.STRING);
syntax.addOptional("player", ArgumentType.STRING);
return syntax;
}
else if(EnumMode.MODIFY.equals(mode))
{
CommandSyntax syntax = new CommandSyntax();
syntax.addRequired("modify", ArgumentType.STRING);
syntax.addRequired("team", ArgumentType.STRING);
syntax.addRequired("friendlyfire|color|seeFriendlyInvisibles|nametagVisibility|deathMessageVisibility|collisionRule", ArgumentType.STRING);
syntax.addRequired("value", ArgumentType.STRING);
return syntax;
}
return null;
}
public BuilderTeams build(EnumMode mode)
{
BuilderTeams builder = new BuilderTeams();
switch(mode)
{
case JOIN_OR_LEAVE:
case JOIN:
builder.setNode(0, mode.toString());
builder.setTeam(this.getTeam());
builder.setNode(2, this.getPlayer());
break;
case LEAVE:
builder.setNode(0, mode.toString());
builder.setNode(1, this.getPlayer());
break;
case REMOVE_OR_EMPTY:
case REMOVE:
case EMPTY:
builder.setNode(0, mode.toString());
builder.setTeam(this.getTeam());
break;
case ADD:
builder.setMode(mode);
builder.setTeam(this.getTeam());
break;
case MODIFY:
builder.setMode(mode);
builder.setTeam(this.getTeam());
builder.setRule(this.getRule());
builder.setValue(this.getValue());
break;
default:
break;
}
return builder;
}
@Override
public final CommandSyntax getSyntax()
{
CommandSyntax syntax = new CommandSyntax();
syntax.addRequired("list|add|remove|empty|join|leave|modify", ArgumentType.STRING);
syntax.addOptional("...", ArgumentType.STRING);
return syntax;
}
@Override
public String getCommandName()
{
return "team";
}
public static enum EnumMode
{
JOIN,
LEAVE,
REMOVE,
EMPTY,
ADD,
MODIFY,
JOIN_OR_LEAVE,
REMOVE_OR_EMPTY;
@Override
public String toString()
{
if(EnumMode.JOIN_OR_LEAVE.equals(this))
{
return "join|leave";
}
else if(EnumMode.REMOVE_OR_EMPTY.equals(this))
{
return "remove|empty";
}
return this.name().toLowerCase();
}
}
}

View File

@@ -1,64 +0,0 @@
package exopandora.worldhandler.builder.impl;
import exopandora.worldhandler.builder.CommandBuilder;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
public class BuilderTime extends CommandBuilder
{
public BuilderTime()
{
super();
}
public BuilderTime(EnumMode mode)
{
this.setMode(mode);
}
public BuilderTime(EnumMode mode, int value)
{
this(mode);
this.setValue(value);
}
public void setMode(EnumMode mode)
{
this.setNode(0, mode.toString());
}
public void setValue(int value)
{
this.setNode(1, value);
}
@Override
public String getCommandName()
{
return "time";
}
@Override
public final CommandSyntax getSyntax()
{
CommandSyntax syntax = new CommandSyntax();
syntax.addRequired("set|add|query", ArgumentType.STRING);
syntax.addOptional("value", ArgumentType.INT);
return syntax;
}
public static enum EnumMode
{
ADD,
SET,
QUERY;
@Override
public String toString()
{
return this.name().toLowerCase();
}
}
}

View File

@@ -1,93 +0,0 @@
package exopandora.worldhandler.builder.impl;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.CommandBuilder;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
import exopandora.worldhandler.util.EnumHelper;
public class BuilderTrigger extends CommandBuilder
{
public BuilderTrigger()
{
this.setValue(0);
}
public BuilderTrigger(String objective, EnumMode mode, int value)
{
this.setObjective(objective);
this.setMode(mode);
this.setValue(value);
}
public void setObjective(String name)
{
this.setNode(0, name != null ? name.replaceAll(" ", "_") : null);
}
@Nullable
public String getObjective()
{
return this.getNodeAsString(0);
}
public void setMode(EnumMode mode)
{
if(mode != null)
{
this.setNode(1, mode.toString());
}
}
@Nullable
public EnumMode getMode()
{
return EnumHelper.valueOf(this.getNodeAsString(1), EnumMode.class);
}
public void setValue(int value)
{
this.setNode(2, value);
}
public int getValue()
{
return this.getNodeAsInt(2);
}
@Override
public String getCommandName()
{
return "trigger";
}
@Override
public CommandSyntax getSyntax()
{
CommandSyntax syntax = new CommandSyntax();
syntax.addRequired("objective", ArgumentType.STRING);
syntax.addRequired("add|set", ArgumentType.STRING);
syntax.addRequired("value", ArgumentType.INT);
return syntax;
}
public BuilderTrigger build(EnumMode mode)
{
return new BuilderTrigger(this.getObjective(), mode, this.getValue());
}
public static enum EnumMode
{
ADD,
SET;
@Override
public String toString()
{
return this.name().toLowerCase();
}
}
}

View File

@@ -1,164 +0,0 @@
package exopandora.worldhandler.builder.impl;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.CommandBuilder;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.CommandSyntax.Argument;
import exopandora.worldhandler.builder.types.ArgumentType;
import exopandora.worldhandler.builder.types.BlockResourceLocation;
import exopandora.worldhandler.builder.types.CoordinateDouble;
import exopandora.worldhandler.builder.types.CoordinateInt;
import exopandora.worldhandler.builder.types.GreedyString;
import exopandora.worldhandler.builder.types.ItemResourceLocation;
import exopandora.worldhandler.builder.types.TargetSelector;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
public class BuilderUsercontent extends CommandBuilder
{
private final String name;
private final CommandSyntax syntax;
public BuilderUsercontent(String name, CommandSyntax syntax)
{
this.name = name;
this.syntax = syntax;
this.updateSyntax(this.syntax);
}
public void set(int index, String object)
{
if(index < this.syntax.getArguments().size() && index >= 0)
{
Argument argument = this.syntax.getArguments().get(index);
ArgumentType type = argument.getType();
switch(type)
{
case STRING:
this.setNode(index, type.<String>parseOfDefault(object, (String) argument.getDefault()));
break;
case BLOCK_RESOURCE_LOCATION:
this.setNode(index, type.<BlockResourceLocation>parseOfDefault(object, type.parse((String) argument.getDefault())));
break;
case BOOLEAN:
this.setNode(index, type.<Boolean>parseOfDefault(object, (Boolean) argument.getDefault()));
break;
case BYTE:
this.setNode(index, type.<Byte>parseOfDefault(object, ((Double) argument.getDefault()).byteValue()));
break;
case COORDINATE_DOUBLE:
this.setNode(index, type.<CoordinateDouble>parseOfDefault(object, type.parse((String) argument.getDefault())));
break;
case COORDINATE_INT:
this.setNode(index, type.<CoordinateInt>parseOfDefault(object, type.parse((String) argument.getDefault())));
break;
case DOUBLE:
this.setNode(index, type.<Double>parseOfDefault(object, (Double) argument.getDefault()));
break;
case FLOAT:
this.setNode(index, type.<Float>parseOfDefault(object, ((Double) argument.getDefault()).floatValue()));
break;
case GREEDY_STRING:
this.setNode(index, type.<GreedyString>parseOfDefault(object, type.parse((String) argument.getDefault())));
break;
case INT:
this.setNode(index, type.<Integer>parseOfDefault(object, ((Double) argument.getDefault()).intValue()));
break;
case ITEM_RESOURCE_LOCATION:
this.setNode(index, type.<ItemResourceLocation>parseOfDefault(object, type.parse((String) argument.getDefault())));
break;
case LONG:
this.setNode(index, type.<Long>parseOfDefault(object, ((Double) argument.getDefault()).longValue()));
break;
case NBT:
this.setNode(index, type.<CompoundTag>parseOfDefault(object, type.parse((String) argument.getDefault())));
break;
case RESOURCE_LOCATION:
this.setNode(index, type.<ResourceLocation>parseOfDefault(object, type.parse((String) argument.getDefault())));
break;
case SHORT:
this.setNode(index, type.<Short>parseOfDefault(object, ((Double) argument.getDefault()).shortValue()));
break;
case TARGET_SELECTOR:
this.setNode(index, type.<TargetSelector>parseOfDefault(object, type.<TargetSelector>parse((String) argument.getDefault())));
break;
default:
break;
}
}
}
@Nullable
public String get(int index)
{
if(index < this.syntax.getArguments().size() && index >= 0)
{
Argument argument = this.syntax.getArguments().get(index);
switch(argument.getType())
{
case BLOCK_RESOURCE_LOCATION:
return this.getNodeAsBlockResourceLocation(index).toString();
case BOOLEAN:
return String.valueOf(this.getNodeAsBoolean(index));
case BYTE:
return String.valueOf(this.getNodeAsByte(index));
case COORDINATE_DOUBLE:
return this.getNodeAsCoordinateDouble(index).toString();
case COORDINATE_INT:
return this.getNodeAsCoordinateInt(index).toString();
case DOUBLE:
return String.valueOf(this.getNodeAsDouble(index));
case FLOAT:
return String.valueOf(this.getNodeAsFloat(index));
case GREEDY_STRING:
return this.getNodeAsGreedyString(index);
case INT:
return String.valueOf(this.getNodeAsInt(index));
case ITEM_RESOURCE_LOCATION:
return this.getNodeAsItemResourceLocation(index).toString();
case LONG:
return String.valueOf(this.getNodeAsLong(index));
case NBT:
return this.getNodeAsNBT(index).toString();
case RESOURCE_LOCATION:
return this.getNodeAsResourceLocation(index).toString();
case SHORT:
return String.valueOf(this.getNodeAsShort(index));
case STRING:
return this.getNodeAsString(index);
case TARGET_SELECTOR:
return this.getNodeAsTargetSelector(index).toString();
default:
break;
}
}
return null;
}
public void setPlayerName(String username)
{
for(int x = 0; x < this.syntax.getArguments().size(); x++)
{
if(ArgumentType.PLAYER.equals(this.syntax.getArguments().get(x).getType()))
{
this.setPlayerName(x, username);
}
}
}
@Override
public String getCommandName()
{
return this.name;
}
@Override
public CommandSyntax getSyntax()
{
return this.syntax;
}
}

View File

@@ -1,24 +0,0 @@
package exopandora.worldhandler.builder.impl;
import exopandora.worldhandler.builder.CommandBuilder;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
public class BuilderWH extends CommandBuilder
{
@Override
public String getCommandName()
{
return "wh";
}
@Override
public CommandSyntax getSyntax()
{
CommandSyntax syntax = new CommandSyntax();
syntax.addRequired("pos1|pos2|fill|replace", ArgumentType.STRING);
return syntax;
}
}

View File

@@ -1,64 +0,0 @@
package exopandora.worldhandler.builder.impl;
import exopandora.worldhandler.builder.CommandBuilder;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
public class BuilderWeather extends CommandBuilder
{
public BuilderWeather()
{
super();
}
public BuilderWeather(EnumWeather weather)
{
this.setWeather(weather);
}
public BuilderWeather(EnumWeather weather, int value)
{
this(weather);
this.setValue(value);
}
public void setWeather(EnumWeather weather)
{
this.setNode(0, weather.toString());
}
public void setValue(int value)
{
this.setNode(1, value);
}
@Override
public String getCommandName()
{
return "weather";
}
@Override
public final CommandSyntax getSyntax()
{
CommandSyntax syntax = new CommandSyntax();
syntax.addRequired("clear|rain|thunde", ArgumentType.STRING);
syntax.addOptional("duration", ArgumentType.INT);
return syntax;
}
public static enum EnumWeather
{
CLEAR,
RAIN,
THUNDER;
@Override
public String toString()
{
return this.name().toLowerCase();
}
}
}

View File

@@ -1,91 +0,0 @@
package exopandora.worldhandler.builder.impl;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.CommandBuilder;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
public class BuilderWhitelist extends CommandBuilder
{
public BuilderWhitelist()
{
super();
}
public BuilderWhitelist(EnumMode mode)
{
this.setMode(mode);
}
public BuilderWhitelist(EnumMode mode, String player)
{
this(mode);
this.setPlayer(player);
}
public void setMode(EnumMode mode)
{
this.setNode(0, mode.toString());
}
public void setPlayer(String player)
{
this.setNode(1, player);
}
@Nullable
public String getPlayer()
{
return this.getNodeAsString(1);
}
@Override
public String getCommandName()
{
return "whitelist";
}
@Nullable
public BuilderWhitelist build(EnumMode mode)
{
switch(mode)
{
case ADD:
case REMOVE:
return new BuilderWhitelist(mode, this.getPlayer());
case RELOAD:
case ON:
case OFF:
return new BuilderWhitelist(mode);
default:
return null;
}
}
@Override
public final CommandSyntax getSyntax()
{
CommandSyntax syntax = new CommandSyntax();
syntax.addRequired("add|remove|reload|on|off", ArgumentType.STRING);
syntax.addOptional("player", ArgumentType.STRING);
return syntax;
}
public static enum EnumMode
{
ADD,
REMOVE,
RELOAD,
ON,
OFF;
@Override
public String toString()
{
return this.name().toLowerCase();
}
}
}

View File

@@ -1,24 +0,0 @@
package exopandora.worldhandler.builder.impl;
import exopandora.worldhandler.builder.CommandBuilder;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
public class BuilderWorldHandler extends CommandBuilder
{
@Override
public String getCommandName()
{
return "worldhandler";
}
@Override
public final CommandSyntax getSyntax()
{
CommandSyntax syntax = new CommandSyntax();
syntax.addRequired("help|display|version", ArgumentType.STRING);
return syntax;
}
}

View File

@@ -1,82 +0,0 @@
package exopandora.worldhandler.builder.types;
import java.util.function.Function;
import javax.annotation.Nullable;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.TagParser;
import net.minecraft.resources.ResourceLocation;
public enum ArgumentType
{
SHORT(Short::valueOf),
BYTE(Byte::valueOf),
INT(Integer::valueOf),
FLOAT(Float::valueOf),
DOUBLE(Double::valueOf),
LONG(Long::valueOf),
BOOLEAN(Boolean::valueOf),
STRING(String::valueOf),
GREEDY_STRING(GreedyString::valueOf),
RESOURCE_LOCATION(ArgumentType::parseResourceLocation),
ITEM_RESOURCE_LOCATION(ItemResourceLocation::valueOf),
BLOCK_RESOURCE_LOCATION(BlockResourceLocation::valueOf),
NBT(ArgumentType::parseCompoundNBT),
COORDINATE_INT(CoordinateInt::valueOf),
COORDINATE_DOUBLE(CoordinateDouble::valueOf),
TARGET_SELECTOR(TargetSelector::valueOf),
PLAYER(String::valueOf);
private final Function<String, Object> parser;
private ArgumentType(Function<String, Object> parser)
{
this.parser = parser;
}
@Nullable
@SuppressWarnings("unchecked")
public <T> T parse(String object)
{
return (T) this.parser.apply(object);
}
public <T> T parseOfDefault(String object, T def)
{
try
{
return this.<T>parse(object);
}
catch(Exception e)
{
return def;
}
}
@Nullable
public static ResourceLocation parseResourceLocation(String value)
{
return value != null && !value.isEmpty() ? new ResourceLocation(value) : null;
}
@Nullable
public static CompoundTag parseCompoundNBT(String value)
{
if(value != null)
{
try
{
return TagParser.parseTag(value);
}
catch(CommandSyntaxException e)
{
return null;
}
}
return null;
}
}

View File

@@ -1,125 +0,0 @@
package exopandora.worldhandler.builder.types;
import javax.annotation.Nullable;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.commands.arguments.blocks.BlockStateParser;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraftforge.registries.ForgeRegistries;
public class BlockResourceLocation extends ItemResourceLocation
{
private BlockState state;
public BlockResourceLocation()
{
this(null);
}
public BlockResourceLocation(ResourceLocation resource)
{
this(resource, null, null);
}
public BlockResourceLocation(ResourceLocation resource, BlockState state, CompoundTag nbt)
{
super(resource, nbt);
this.state = this.findState(state, resource);
}
private BlockState findState(BlockState state, ResourceLocation resource)
{
boolean matchOld = this.state != null && this.state.getBlock().getRegistryName().equals(resource);
boolean matchNew = state != null && state.getBlock().getRegistryName().equals(resource);
if(matchNew)
{
return state;
}
if(matchOld)
{
return this.state;
}
if(resource != null && ForgeRegistries.BLOCKS.containsKey(resource))
{
return ForgeRegistries.BLOCKS.getValue(resource).defaultBlockState();
}
return null;
}
@Override
public void setResourceLocation(ResourceLocation resource)
{
super.setResourceLocation(resource);
this.state = this.findState(null, resource);
}
@Nullable
public BlockState getState()
{
return this.state;
}
public <T extends Comparable<T>> void setProperty(Property<T> property, T value)
{
if(this.state != null && this.state.hasProperty(property))
{
this.state = this.state.setValue(property, value);
}
}
@Nullable
public static BlockResourceLocation valueOf(String input)
{
if(input != null)
{
BlockStateParser parser = new BlockStateParser(new StringReader(input), false);
try
{
parser.parse(true);
}
catch(CommandSyntaxException e)
{
return null;
}
BlockState state = parser.getState();
if(state != null)
{
return new BlockResourceLocation(state.getBlock().getRegistryName(), state, parser.getNbt());
}
}
return null;
}
@Override
public String toString()
{
if(this.resource != null && this.state != null)
{
StringBuilder builder = new StringBuilder(this.state.toString());
String block = this.state.getBlock().toString();
builder.replace(0, block.length(), this.resource.toString());
if(this.nbt != null)
{
builder.append(this.nbt.toString());
}
return builder.toString();
}
return null;
}
}

View File

@@ -1,105 +0,0 @@
package exopandora.worldhandler.builder.types;
import java.util.function.Function;
public abstract class Coordinate<T extends Number> implements ICoordinate<T>
{
protected T value;
protected EnumType type;
public Coordinate(T value)
{
this(value, EnumType.ABSOLUTE);
}
public Coordinate(T value, EnumType type)
{
this.value = value;
this.type = type;
}
public void setValue(T value)
{
this.value = value;
}
public T getValue()
{
return this.value;
}
public void setType(EnumType type)
{
this.type = type;
}
public EnumType getType()
{
return this.type;
}
@Override
public String toString()
{
return this.type.format(this.value, this.zero());
}
public static <S extends Number, U extends Coordinate<S>> U parse(U coordiante, String input, Function<String, S> parser)
{
for(EnumType type : EnumType.values())
{
if(!type.prefix.isEmpty() && input.startsWith(type.prefix))
{
String numbers = input.substring(type.prefix.length());
coordiante.setType(type);
coordiante.setValue(numbers.isEmpty() ? coordiante.zero() : parser.apply(numbers));
return coordiante;
}
}
coordiante.setType(EnumType.ABSOLUTE);
coordiante.setValue(parser.apply(input));
return coordiante;
}
public static enum EnumType
{
/**
* Prefix: <code>None</code>
*/
ABSOLUTE(""),
/**
* Prefix: <code>"~"</code>
*/
GLOBAL("~"),
/**
* Prefix: <code>"^"</code>
*/
LOCAL("^");
private final String prefix;
private EnumType(String prefix)
{
this.prefix = prefix;
}
public <T extends Number> String format(T value, T zero)
{
if(value == null || value.equals(zero))
{
if(this.prefix.isEmpty())
{
return zero.toString();
}
return this.prefix;
}
return this.prefix + value;
}
}
}

View File

@@ -1,35 +0,0 @@
package exopandora.worldhandler.builder.types;
public class CoordinateDouble extends Coordinate<Double>
{
public CoordinateDouble()
{
super(0.0);
}
public CoordinateDouble(Double value)
{
super(value);
}
public CoordinateDouble(EnumType type)
{
super(0.0, type);
}
public CoordinateDouble(Double value, EnumType type)
{
super(value, type);
}
public static CoordinateDouble valueOf(String value)
{
return Coordinate.parse(new CoordinateDouble(), value, Double::parseDouble);
}
@Override
public Double zero()
{
return 0.0;
}
}

View File

@@ -1,35 +0,0 @@
package exopandora.worldhandler.builder.types;
public class CoordinateInt extends Coordinate<Integer>
{
public CoordinateInt()
{
super(0);
}
public CoordinateInt(Integer value)
{
super(value);
}
public CoordinateInt(EnumType type)
{
super(0, type);
}
public CoordinateInt(Integer value, EnumType type)
{
super(value, type);
}
public static CoordinateInt valueOf(String value)
{
return Coordinate.parse(new CoordinateInt(), value, Integer::parseInt);
}
@Override
public Integer zero()
{
return 0;
}
}

View File

@@ -1,50 +0,0 @@
package exopandora.worldhandler.builder.types;
import javax.annotation.Nullable;
public class GreedyString
{
private String string;
public GreedyString(String string)
{
this.string = string;
}
public String getString()
{
return this.string;
}
public void setString(String string)
{
this.string = string;
}
public boolean isEmpty()
{
if(this.string == null)
{
return true;
}
return this.string.isEmpty();
}
@Nullable
public static GreedyString valueOf(String string)
{
if(string != null && string.matches("\"(.*)\""))
{
return new GreedyString(string.substring(1, string.length() - 1));
}
return null;
}
@Override
public String toString()
{
return "\"" + this.string + "\"";
}
}

View File

@@ -1,6 +0,0 @@
package exopandora.worldhandler.builder.types;
public interface ICoordinate<T extends Number>
{
T zero();
}

View File

@@ -1,91 +0,0 @@
package exopandora.worldhandler.builder.types;
import javax.annotation.Nullable;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.TagParser;
import net.minecraft.resources.ResourceLocation;
public class ItemResourceLocation
{
protected ResourceLocation resource;
protected CompoundTag nbt;
public ItemResourceLocation()
{
this(null, null);
}
public ItemResourceLocation(ResourceLocation resource)
{
this(resource, null);
}
public ItemResourceLocation(ResourceLocation resource, CompoundTag nbt)
{
this.resource = resource;
this.nbt = nbt;
}
public ResourceLocation getResourceLocation()
{
return this.resource;
}
public void setResourceLocation(ResourceLocation resource)
{
this.resource = resource;
}
public CompoundTag getNBT()
{
return this.nbt;
}
public void setNBT(CompoundTag nbt)
{
this.nbt = nbt;
}
@Nullable
public static ItemResourceLocation valueOf(String input)
{
int start = input.indexOf("{");
ResourceLocation resource = new ResourceLocation(input.substring(0, start));
CompoundTag nbt = null;
if(start > 0)
{
try
{
nbt = TagParser.parseTag(input.substring(start, input.lastIndexOf("}") + 1));
}
catch(CommandSyntaxException e)
{
return null;
}
}
return new ItemResourceLocation(resource, nbt);
}
@Override
public String toString()
{
if(this.resource != null)
{
StringBuilder builder = new StringBuilder(this.resource.toString());
if(this.nbt != null)
{
builder.append(this.nbt.toString());
}
return builder.toString();
}
return null;
}
}

View File

@@ -1,58 +0,0 @@
package exopandora.worldhandler.builder.types;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class TargetSelector
{
private final Map<String, Object> values = new HashMap<String, Object>();
private static final String REGEX = "@e\\[(.*)\\]";
public void set(String id, Object value)
{
this.values.put(id.toLowerCase(), value);
}
@Nullable
@SuppressWarnings("unchecked")
public <T> T get(String id)
{
return (T) this.values.get(id);
}
public Object remove(String id)
{
return this.values.remove(id.toLowerCase());
}
@Nonnull
public static TargetSelector valueOf(String input)
{
if(input.matches(REGEX));
{
TargetSelector result = new TargetSelector();
for(String keys : input.replaceFirst(REGEX, "$1").split(","))
{
String[] pair = keys.split("=");
if(pair.length > 1)
{
result.set(pair[0], pair[1]);
}
}
}
return new TargetSelector();
}
@Override
public String toString()
{
return "@e[" + String.join(",", this.values.entrySet().stream().map(entry -> entry.getKey() + "=" + entry.getValue().toString()).collect(Collectors.toList())) + "]";
}
}