Update to 1.19

This commit is contained in:
Marcel Konrad
2022-06-15 21:34:51 +02:00
parent 0f7aa3f7b0
commit 1875253f78
83 changed files with 1344 additions and 1037 deletions

View File

@@ -15,7 +15,6 @@ import net.minecraft.advancements.critereon.MinMaxBounds;
import net.minecraft.commands.arguments.EntityAnchorArgument.Anchor;
import net.minecraft.core.Direction.Axis;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.Difficulty;
import net.minecraft.world.scores.criteria.ObjectiveCriteria.RenderType;
@@ -24,7 +23,7 @@ public class Arguments
{
public static PrimitiveArgument<Short> shortArg()
{
return new PrimitiveArgument.Builder<Short>(string ->
return PrimitiveArgument.builder(string ->
{
try
{
@@ -39,7 +38,7 @@ public class Arguments
public static PrimitiveArgument<Byte> byteArg()
{
return new PrimitiveArgument.Builder<Byte>(string ->
return PrimitiveArgument.builder(string ->
{
try
{
@@ -54,7 +53,7 @@ public class Arguments
public static PrimitiveArgument<Integer> intArg()
{
return new PrimitiveArgument.Builder<Integer>(string ->
return PrimitiveArgument.builder(string ->
{
try
{
@@ -69,7 +68,7 @@ public class Arguments
public static PrimitiveArgument<Float> floatArg()
{
return new PrimitiveArgument.Builder<Float>(string ->
return PrimitiveArgument.builder(string ->
{
try
{
@@ -84,7 +83,7 @@ public class Arguments
public static PrimitiveArgument<Double> doubleArg()
{
return new PrimitiveArgument.Builder<Double>(string ->
return PrimitiveArgument.builder(string ->
{
try
{
@@ -99,7 +98,7 @@ public class Arguments
public static PrimitiveArgument<Long> longArg()
{
return new PrimitiveArgument.Builder<Long>(string ->
return PrimitiveArgument.builder(string ->
{
try
{
@@ -114,7 +113,7 @@ public class Arguments
public static PrimitiveArgument<Boolean> boolArg()
{
return new PrimitiveArgument.Builder<Boolean>(string ->
return PrimitiveArgument.builder(string ->
{
try
{
@@ -129,14 +128,14 @@ public class Arguments
public static PrimitiveArgument<String> string()
{
return new PrimitiveArgument.Builder<String>(Function.identity())
return PrimitiveArgument.builder(Function.identity())
.serializer(string -> string.isBlank() ? null : StringArgumentType.escapeIfRequired(string))
.build();
}
public static PrimitiveArgument<String> greedyString()
{
return new PrimitiveArgument.Builder<String>(string -> string == null || string.isBlank() ? null : string)
return PrimitiveArgument.builder(string -> string == null || string.isBlank() ? null : string)
.serializer(string -> string.isBlank() ? null : string)
.defaultOverride(string -> string == null || string.isBlank())
.build();
@@ -144,7 +143,7 @@ public class Arguments
public static PrimitiveArgument<String> word()
{
return new PrimitiveArgument.Builder<String>(string -> string == null || string.isBlank() ? null : string)
return PrimitiveArgument.builder(string -> string == null || string.isBlank() ? null : string)
.serializer(string -> string.isBlank() ? null : string.replaceAll("[^0-9A-Za-z_\\-.+]", "_"))
.defaultOverride(string -> string == null || string.isBlank())
.build();
@@ -152,7 +151,7 @@ public class Arguments
public static PrimitiveArgument<ResourceLocation> resourceLocation()
{
return new PrimitiveArgument.Builder<ResourceLocation>(string -> string.isEmpty() ? null : new ResourceLocation(string)).build();
return PrimitiveArgument.builder(string -> string.isEmpty() ? null : new ResourceLocation(string)).build();
}
public static ItemArgument item()
@@ -177,12 +176,12 @@ public class Arguments
public static PrimitiveArgument<Coordinate<Integer>> intCoordinate()
{
return new PrimitiveArgument.Builder<Coordinate<Integer>>(Coordinate.Ints::parse).build();
return PrimitiveArgument.<Coordinate<Integer>>builder(Coordinate.Ints::parse).build();
}
public static PrimitiveArgument<Coordinate<Double>> doubleCoordinate()
{
return new PrimitiveArgument.Builder<Coordinate<Double>>(Coordinate.Doubles::parse).build();
return PrimitiveArgument.<Coordinate<Double>>builder(Coordinate.Doubles::parse).build();
}
public static RangeArgument<Integer> intRange()
@@ -232,7 +231,7 @@ public class Arguments
public static PrimitiveArgument<Gamemode> gamemode()
{
return new PrimitiveArgument.Builder<Gamemode>(string -> EnumHelper.find(string, Gamemode.values(), Gamemode::toString)).build();
return PrimitiveArgument.builder(string -> EnumHelper.find(string, Gamemode.values(), Gamemode::toString)).build();
}
public static TimeArgument time()
@@ -247,40 +246,40 @@ public class Arguments
public static PrimitiveArgument<Axis> axis()
{
return new PrimitiveArgument.Builder<Axis>(string -> EnumHelper.find(string, Axis.values(), Axis::getName))
return PrimitiveArgument.builder(string -> EnumHelper.find(string, Axis.values(), Axis::getName))
.serializer(Axis::getName)
.build();
}
public static PrimitiveArgument<Anchor> anchor()
{
return new PrimitiveArgument.Builder<Anchor>(string -> EnumHelper.find(string, Anchor.values(), anchor -> anchor.name))
return PrimitiveArgument.builder(string -> EnumHelper.find(string, Anchor.values(), anchor -> anchor.name))
.serializer(anchor -> anchor.name)
.build();
}
public static PrimitiveArgument<Difficulty> difficulty()
{
return new PrimitiveArgument.Builder<Difficulty>(string -> EnumHelper.find(string, Difficulty.values(), Difficulty::getKey))
return PrimitiveArgument.builder(string -> EnumHelper.find(string, Difficulty.values(), Difficulty::getKey))
.serializer(Difficulty::getKey)
.build();
}
public static PrimitiveArgument<RenderType> renderType()
{
return new PrimitiveArgument.Builder<RenderType>(string -> EnumHelper.find(string, RenderType.values(), RenderType::getId))
return PrimitiveArgument.builder(string -> EnumHelper.find(string, RenderType.values(), RenderType::getId))
.serializer(RenderType::getId)
.build();
}
public static PrimitiveArgument<PrimitiveArgument.Operation> operation()
{
return new PrimitiveArgument.Builder<Operation>(string -> EnumHelper.find(string, Operation.values(), Operation::toString)).build();
return PrimitiveArgument.builder(string -> EnumHelper.find(string, Operation.values(), Operation::toString)).build();
}
public static PrimitiveArgument<Component> textComponent()
{
return new PrimitiveArgument.Builder<Component>(string ->
return PrimitiveArgument.<Component>builder(string ->
{
try
{
@@ -288,24 +287,24 @@ public class Arguments
}
catch(Exception e)
{
return new TextComponent(string);
return Component.literal(string);
}
}).serializer(Component.Serializer::toJson).build();
}
public static PrimitiveArgument<PrimitiveArgument.Relation> relation()
{
return new PrimitiveArgument.Builder<Relation>(string -> EnumHelper.find(string, Relation.values(), Relation::toString)).build();
return PrimitiveArgument.builder(string -> EnumHelper.find(string, Relation.values(), Relation::toString)).build();
}
public static PrimitiveArgument<PrimitiveArgument.Type> type()
{
return new PrimitiveArgument.Builder<Type>(string -> EnumHelper.find(string, Type.values(), Type::toString)).build();
return PrimitiveArgument.builder(string -> EnumHelper.find(string, Type.values(), Type::toString)).build();
}
public static PrimitiveArgument<PrimitiveArgument.Linkage> linkage()
{
return new PrimitiveArgument.Builder<Linkage>(string -> EnumHelper.find(string, Linkage.values(), Linkage::toString)).build();
return PrimitiveArgument.builder(string -> EnumHelper.find(string, Linkage.values(), Linkage::toString)).build();
}
public static NbtPathArgument nbtPath()
@@ -320,7 +319,7 @@ public class Arguments
public static PrimitiveArgument<String> criteria()
{
return new PrimitiveArgument.Builder<String>(string -> string == null || string.isBlank() ? null : string)
return PrimitiveArgument.builder(string -> string == null || string.isBlank() ? null : string)
.serializer(string -> string.isBlank() ? null : string.replaceAll(" ", "_"))
.defaultOverride(string -> string == null || string.isBlank())
.build();

View File

@@ -9,14 +9,14 @@ import java.util.stream.Collectors;
import javax.annotation.Nullable;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.commands.arguments.blocks.BlockStateParser;
import exopandora.worldhandler.util.BlockPredicateParser;
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 BlockPredicateArgument extends TagArgument
{
@@ -38,7 +38,7 @@ public class BlockPredicateArgument extends TagArgument
{
if(state != null)
{
this.resource = state.getBlock().getRegistryName();
this.resource = ForgeRegistries.BLOCKS.getKey(state.getBlock());
this.properties = propertiesToString(state.getValues());
}
else
@@ -128,22 +128,12 @@ public class BlockPredicateArgument extends TagArgument
{
try
{
BlockStateParser parser = new BlockStateParser(new StringReader(predicate), true).parse(true);
if(parser.getState() != null)
{
this.resource = parser.getState().getBlock().getRegistryName();
this.isTag = false;
this.properties = propertiesToString(parser.getProperties());
this.setTag(parser.getNbt());
}
else
{
this.resource = parser.getTag().location();
this.isTag = true;
this.properties = parser.getVagueProperties();
this.setTag(parser.getNbt());
}
BlockPredicateParser parser = new BlockPredicateParser(predicate);
parser.parse(true);
this.resource = parser.getResourceLocation();
this.isTag = parser.isTag();
this.properties = parser.getVagueProperties();
this.setTag(parser.getNbt());
}
catch(CommandSyntaxException e)
{
@@ -205,14 +195,14 @@ public class BlockPredicateArgument extends TagArgument
{
return properties.entrySet().stream().map(entry ->
{
Property<?> property = entry.getKey();
return new SimpleEntry<String, String>(property.getName(), getName(property, entry.getValue()));
Property<?> property = entry.getKey();
return new SimpleEntry<String, String>(property.getName(), getName(property, entry.getValue()));
}).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
}
@SuppressWarnings("unchecked")
@SuppressWarnings("unchecked")
private static <T extends Comparable<T>> String getName(Property<T> key, Comparable<?> value)
{
return key.getName((T) value);
}
{
return key.getName((T) value);
}
}

View File

@@ -2,10 +2,9 @@ package exopandora.worldhandler.builder.argument;
import javax.annotation.Nullable;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.commands.arguments.blocks.BlockStateParser;
import exopandora.worldhandler.util.BlockPredicateParser;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
@@ -63,9 +62,9 @@ public class BlockStateArgument extends TagArgument
}
@Override
public void deserialize(@Nullable String block)
public void deserialize(@Nullable String string)
{
if(block == null)
if(string == null)
{
this.reset();
}
@@ -73,9 +72,13 @@ public class BlockStateArgument extends TagArgument
{
try
{
BlockStateParser parser = new BlockStateParser(new StringReader(block), false).parse(true);
this.state = parser.getState();
this.setTag(parser.getNbt());
BlockPredicateParser parser = new BlockPredicateParser(string);
parser.parse(false);
parser.getBlock().ifPresentOrElse(block ->
{
this.state = block.defaultBlockState();
this.setTag(parser.getNbt());
}, this::reset);
}
catch(CommandSyntaxException e)
{
@@ -101,7 +104,7 @@ public class BlockStateArgument extends TagArgument
StringBuilder builder = new StringBuilder(this.state.toString());
String block = this.state.getBlock().toString();
builder.replace(0, block.length(), this.state.getBlock().getRegistryName().toString());
builder.replace(0, block.length(), ForgeRegistries.BLOCKS.getKey(this.state.getBlock()).toString());
String nbt = super.serialize();
if(nbt != null && this.state.hasBlockEntity())

View File

@@ -55,7 +55,7 @@ public class DimensionArgument implements IDeserializableArgument
return null;
}
return this.dimension.getRegistryName().toString();
return this.dimension.location().toString();
}
@Override

View File

@@ -54,7 +54,7 @@ public class EffectArgument implements IDeserializableArgument
return null;
}
return this.effect.getRegistryName().toString();
return ForgeRegistries.MOB_EFFECTS.getKey(this.effect).toString();
}
@Override

View File

@@ -54,7 +54,7 @@ public class EnchantmentArgument implements IDeserializableArgument
return null;
}
return this.enchantment.getRegistryName().toString();
return ForgeRegistries.ENCHANTMENTS.getKey(this.enchantment).toString();
}
@Override

View File

@@ -16,32 +16,32 @@ public class EntitySummonArgument implements IDeserializableArgument
{
private static final Map<String, ResourceLocation> ALIASES = Util.make(new HashMap<String, ResourceLocation>(), map ->
{
map.put("RedCow", EntityType.MOOSHROOM.getRegistryName());
map.put("ChickenJockey", EntityType.CHICKEN.getRegistryName());
map.put("Pigman", EntityType.PIGLIN.getRegistryName());
map.put("ZombiePig", EntityType.PIGLIN.getRegistryName());
map.put("ZombiePigman", EntityType.PIGLIN.getRegistryName());
map.put("Dog", EntityType.WOLF.getRegistryName());
map.put("Dragon", EntityType.ENDER_DRAGON.getRegistryName());
map.put("SnowMan", EntityType.SNOW_GOLEM.getRegistryName());
map.put("LavaCube", EntityType.MAGMA_CUBE.getRegistryName());
map.put("MagmaSlime", EntityType.MAGMA_CUBE.getRegistryName());
map.put("LavaSlime", EntityType.MAGMA_CUBE.getRegistryName());
map.put("SpiderJockey", EntityType.SPIDER.getRegistryName());
map.put("VillagerGolem", EntityType.IRON_GOLEM.getRegistryName());
map.put("Ozelot", EntityType.OCELOT.getRegistryName());
map.put("Kitty", EntityType.CAT.getRegistryName());
map.put("Kitten", EntityType.CAT.getRegistryName());
map.put("TESTIFICATE", EntityType.VILLAGER.getRegistryName());
map.put("Octopus", EntityType.SQUID.getRegistryName());
map.put("GlowingOctopus", EntityType.SQUID.getRegistryName());
map.put("Exwife", EntityType.GHAST.getRegistryName());
map.put("CommandMinecart", EntityType.COMMAND_BLOCK_MINECART.getRegistryName());
map.put("Wizard", EntityType.EVOKER.getRegistryName());
map.put("Johnny", EntityType.VINDICATOR.getRegistryName());
map.put("BabyZombie", EntityType.ZOMBIE.getRegistryName());
map.put("RedCow", ForgeRegistries.ENTITIES.getKey(EntityType.MOOSHROOM));
map.put("ChickenJockey", ForgeRegistries.ENTITIES.getKey(EntityType.CHICKEN));
map.put("Pigman", ForgeRegistries.ENTITIES.getKey(EntityType.PIGLIN));
map.put("ZombiePig", ForgeRegistries.ENTITIES.getKey(EntityType.PIGLIN));
map.put("ZombiePigman", ForgeRegistries.ENTITIES.getKey(EntityType.PIGLIN));
map.put("Dog", ForgeRegistries.ENTITIES.getKey(EntityType.WOLF));
map.put("Dragon", ForgeRegistries.ENTITIES.getKey(EntityType.ENDER_DRAGON));
map.put("SnowMan", ForgeRegistries.ENTITIES.getKey(EntityType.SNOW_GOLEM));
map.put("LavaCube", ForgeRegistries.ENTITIES.getKey(EntityType.MAGMA_CUBE));
map.put("MagmaSlime", ForgeRegistries.ENTITIES.getKey(EntityType.MAGMA_CUBE));
map.put("LavaSlime", ForgeRegistries.ENTITIES.getKey(EntityType.MAGMA_CUBE));
map.put("SpiderJockey", ForgeRegistries.ENTITIES.getKey(EntityType.SPIDER));
map.put("VillagerGolem", ForgeRegistries.ENTITIES.getKey(EntityType.IRON_GOLEM));
map.put("Ozelot", ForgeRegistries.ENTITIES.getKey(EntityType.OCELOT));
map.put("Kitty", ForgeRegistries.ENTITIES.getKey(EntityType.CAT));
map.put("Kitten", ForgeRegistries.ENTITIES.getKey(EntityType.CAT));
map.put("TESTIFICATE", ForgeRegistries.ENTITIES.getKey(EntityType.VILLAGER));
map.put("Octopus", ForgeRegistries.ENTITIES.getKey(EntityType.SQUID));
map.put("GlowingOctopus", ForgeRegistries.ENTITIES.getKey(EntityType.SQUID));
map.put("Exwife", ForgeRegistries.ENTITIES.getKey(EntityType.GHAST));
map.put("CommandMinecart", ForgeRegistries.ENTITIES.getKey(EntityType.COMMAND_BLOCK_MINECART));
map.put("Wizard", ForgeRegistries.ENTITIES.getKey(EntityType.EVOKER));
map.put("Johnny", ForgeRegistries.ENTITIES.getKey(EntityType.VINDICATOR));
map.put("BabyZombie", ForgeRegistries.ENTITIES.getKey(EntityType.ZOMBIE));
ForgeRegistries.PROFESSIONS.getKeys().stream().forEach(profession -> map.put(profession.getPath(), EntityType.VILLAGER.getRegistryName()));
ForgeRegistries.PROFESSIONS.getEntries().stream().forEach(profession -> map.put(profession.getKey().location().getPath(), profession.getKey().location()));
});
private EntityType<?> entity;
@@ -69,7 +69,7 @@ public class EntitySummonArgument implements IDeserializableArgument
{
EntityType<?> type = ForgeRegistries.ENTITIES.getValue(entity);
if(!ForgeRegistries.ENTITIES.getDefaultKey().equals(type.getRegistryName()) || type.getRegistryName().equals(entity))
if(type != null)
{
this.set(type);
}
@@ -123,7 +123,7 @@ public class EntitySummonArgument implements IDeserializableArgument
return null;
}
return this.entity.getRegistryName().toString();
return ForgeRegistries.ENTITIES.getKey(this.entity).toString();
}
@Override

View File

@@ -2,10 +2,9 @@ package exopandora.worldhandler.builder.argument;
import javax.annotation.Nullable;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.commands.arguments.item.ItemParser;
import exopandora.worldhandler.util.ItemPredicateParser;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraftforge.registries.ForgeRegistries;
@@ -42,15 +41,23 @@ public class ItemArgument extends TagArgument
}
@Override
public void deserialize(@Nullable String item)
public void deserialize(@Nullable String string)
{
if(item != null)
if(string != null)
{
try
{
ItemParser parser = new ItemParser(new StringReader(item), false).parse();
this.item = parser.getItem();
this.setTag(parser.getNbt());
ItemPredicateParser parser = new ItemPredicateParser(string);
parser.parse(false);
parser.getItem().ifPresentOrElse(item ->
{
this.item = item;
this.setTag(parser.getNbt());
}, () ->
{
this.item = null;
this.setTag(null);
});
}
catch(CommandSyntaxException e)
{
@@ -78,10 +85,10 @@ public class ItemArgument extends TagArgument
if(tag != null)
{
return this.item.getRegistryName().toString() + tag;
return ForgeRegistries.ITEMS.getKey(this.item).toString() + tag;
}
return this.item.getRegistryName().toString();
return ForgeRegistries.ITEMS.getKey(this.item).toString();
}
@Override

View File

@@ -2,12 +2,12 @@ package exopandora.worldhandler.builder.argument;
import javax.annotation.Nullable;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.commands.arguments.item.ItemParser;
import exopandora.worldhandler.util.ItemPredicateParser;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraftforge.registries.ForgeRegistries;
public class ItemPredicateArgument extends TagArgument
{
@@ -28,7 +28,7 @@ public class ItemPredicateArgument extends TagArgument
{
if(item != null)
{
this.resource = item.getRegistryName();
this.resource = ForgeRegistries.ITEMS.getKey(item);
}
else
{
@@ -60,20 +60,11 @@ public class ItemPredicateArgument extends TagArgument
{
try
{
ItemParser parser = new ItemParser(new StringReader(predicate), true).parse();
if(parser.getItem() != null)
{
this.resource = parser.getItem().getRegistryName();
this.setTag(parser.getNbt());
this.isTag = false;
}
else
{
this.resource = parser.getTag().location();
this.setTag(parser.getNbt());
this.isTag = true;
}
ItemPredicateParser parser = new ItemPredicateParser(predicate);
parser.parse(true);
this.resource = parser.getResourceLocation();
this.setTag(parser.getNbt());
this.isTag = parser.isTag();
}
catch(CommandSyntaxException e)
{

View File

@@ -69,13 +69,18 @@ public class PrimitiveArgument<T> implements IDeserializableArgument
return this.value == null;
}
public static <T> Builder<T> builder(Function<String, T> deserializer)
{
return new Builder<T>(deserializer);
}
public static class Builder<T>
{
private Function<T, Boolean> defaultOverride;
private Function<String, T> deserializer;
private Function<T, String> serializer;
public Builder(Function<String, T> deserializer)
private Builder(Function<String, T> deserializer)
{
this.deserializer = deserializer;
}

View File

@@ -9,6 +9,7 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraftforge.registries.ForgeRegistries;
public class AttributeModifiersTag extends AbstractAttributeTag
{
@@ -23,7 +24,7 @@ public class AttributeModifiersTag extends AbstractAttributeTag
if(entry.getValue() != 0)
{
CompoundTag attribute = new CompoundTag();
String id = entry.getKey().getRegistryName().toString();
String id = ForgeRegistries.ATTRIBUTES.getKey(entry.getKey()).toString();
attribute.putString("AttributeName", id);
attribute.putDouble("Amount", entry.getValue() / 100);

View File

@@ -8,6 +8,7 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraftforge.registries.ForgeRegistries;
public class AttributesTag extends AbstractAttributeTag
{
@@ -22,7 +23,7 @@ public class AttributesTag extends AbstractAttributeTag
if(entry.getValue() != 0)
{
CompoundTag attribute = new CompoundTag();
String id = entry.getKey().getRegistryName().toString();
String id = ForgeRegistries.ATTRIBUTES.getKey(entry.getKey()).toString();
attribute.putString("Name", id);
attribute.putDouble("Base", entry.getValue() / 100);

View File

@@ -1,6 +1,6 @@
package exopandora.worldhandler.builder.argument.tag;
import exopandora.worldhandler.util.MutableTextComponent;
import exopandora.worldhandler.util.UserStylableComponent;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.StringTag;
@@ -9,7 +9,7 @@ import net.minecraft.network.chat.Component;
public class DisplayTag implements ITagProvider
{
private MutableTextComponent name = new MutableTextComponent();
private UserStylableComponent name = new UserStylableComponent();
private Component[] lore = new Component[2];
@Override
@@ -45,12 +45,12 @@ public class DisplayTag implements ITagProvider
return null;
}
public void setName(MutableTextComponent name)
public void setName(String name)
{
this.name = name;
this.name.setText(name);
}
public MutableTextComponent getName()
public UserStylableComponent getName()
{
return this.name;
}

View File

@@ -10,14 +10,15 @@ import javax.annotation.Nullable;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import exopandora.worldhandler.util.MutableTextComponent;
import exopandora.worldhandler.util.NBTHelper;
import exopandora.worldhandler.util.UserStylableComponent;
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.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.entity.ai.attributes.Attribute;
@@ -34,7 +35,7 @@ public class EntityTag implements ITagProvider
private boolean isBaby;
private BlockState blockState;
private AttributesTag attribute = new AttributesTag();
private MutableTextComponent customName = new MutableTextComponent();
private UserStylableComponent customName = new UserStylableComponent();
private List<EntityTag> passengers = new ArrayList<EntityTag>();
private Item[] armorItems = {Items.AIR, Items.AIR, Items.AIR, Items.AIR};
private Item[] handItems = {Items.AIR, Items.AIR};
@@ -86,8 +87,7 @@ public class EntityTag implements ITagProvider
this.customName.setText(name);
}
@Nullable
public MutableTextComponent getCustomName()
public UserStylableComponent getCustomName()
{
return this.customName;
}
@@ -403,7 +403,10 @@ public class EntityTag implements ITagProvider
NBTHelper.append(nbt, "HandItems", NBTHelper.serialize(this.handItems));
NBTHelper.append(nbt, "BlockState", NBTHelper.serialize(this.blockState));
NBTHelper.append(nbt, "CustomName", this.customName.serialize());
if(this.customName.getText() != null && !this.customName.getText().isEmpty())
{
NBTHelper.append(nbt, "CustomName", StringTag.valueOf(Component.Serializer.toJson(this.customName)));
}
NBTHelper.append(nbt, this.potion);
NBTHelper.append(nbt, this.attribute);

View File

@@ -1,21 +1,25 @@
package exopandora.worldhandler.builder.argument.tag;
import exopandora.worldhandler.util.SignText;
import javax.annotation.Nonnull;
import exopandora.worldhandler.util.UserStylableComponent;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
public class TextTag implements ITagProvider
{
private final int id;
private final SignText text = new SignText();
private final UserStylableComponent component = new UserStylableComponent();
public TextTag(int id)
{
this.id = id;
}
public SignText getText()
public UserStylableComponent getComponent()
{
return this.text;
return this.component;
}
@Override
@@ -24,9 +28,10 @@ public class TextTag implements ITagProvider
return "Text" + this.id;
}
@Nonnull
@Override
public Tag value()
{
return this.text.serialize();
return StringTag.valueOf(Component.Serializer.toJson(this.component));
}
}