Add command stack, Move butcher to entities category

This commit is contained in:
Marcel Konrad
2020-05-24 20:48:09 +02:00
parent 0de447fe3a
commit 21eb3e1407
17 changed files with 1338 additions and 535 deletions

View File

@@ -1,149 +1,41 @@
package exopandora.worldhandler.builder.component.impl;
import java.util.Random;
import javax.annotation.Nullable;
import org.apache.commons.lang3.StringUtils;
import exopandora.worldhandler.builder.component.IBuilderComponent;
import exopandora.worldhandler.util.ResourceHelper;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.EntityType;
import net.minecraft.nbt.ByteNBT;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.INBT;
import net.minecraft.nbt.IntNBT;
import net.minecraft.nbt.ListNBT;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.registries.ForgeRegistries;
@OnlyIn(Dist.CLIENT)
public class ComponentSummon implements IBuilderComponent
public class ComponentCustom implements IBuilderComponent
{
private final Random random = new Random();
private INBT nbt;
private String tag;
private String name;
private ResourceLocation entity;
private boolean hasPassenger;
public void setEntity(ResourceLocation entityName)
public void setNBT(INBT nbt)
{
this.entity = entityName;
this.nbt = nbt;
}
public ResourceLocation getEntity()
public void setTag(String tag)
{
return this.entity;
this.tag = tag;
}
public void set(String tag, INBT nbt)
{
this.setTag(tag);
this.setNBT(nbt);
}
public void setHasPassenger(boolean hasPassenger)
public void reset()
{
this.hasPassenger = hasPassenger;
}
public boolean hasPassenger()
{
return this.hasPassenger;
}
public String getName()
{
return this.name;
}
public void setName(String name)
{
this.name = name;
this.set(null, null);
}
@Override
public INBT serialize()
{
if(this.name != null)
{
if(this.name.equalsIgnoreCase("Cat"))
{
this.tag = "CatType";
return IntNBT.valueOf(this.random.nextInt(3) + 1);
}
else if(this.name.equalsIgnoreCase("Farmer") || this.name.equalsIgnoreCase("Fisherman") || this.name.equalsIgnoreCase("Shepherd") || this.name.equalsIgnoreCase("Fletcher"))
{
this.tag = "Profession";
return IntNBT.valueOf(0);
}
else if(this.name.equalsIgnoreCase("Librarian") || this.name.equalsIgnoreCase("Carthographer"))
{
this.tag = "Profession";
return IntNBT.valueOf(1);
}
else if(this.name.equalsIgnoreCase("Cleric") || this.name.equalsIgnoreCase("Priest"))
{
this.tag = "Profession";
return IntNBT.valueOf(2);
}
else if(this.name.equalsIgnoreCase("Armorer") || this.name.equalsIgnoreCase("Blacksmith") || this.name.equalsIgnoreCase("WeaponSmith") || this.name.equalsIgnoreCase("ToolSmith"))
{
this.tag = "Profession";
return IntNBT.valueOf(3);
}
else if(this.name.equalsIgnoreCase("Butcher") || this.name.equalsIgnoreCase("Leatherworker"))
{
this.tag = "Profession";
return IntNBT.valueOf(4);
}
else if(this.name.equalsIgnoreCase("Nitwit"))
{
this.tag = "Profession";
return IntNBT.valueOf(5);
}
if(this.entity != null)
{
if(this.entity.equals(EntityType.ZOMBIE.getRegistryName()))
{
if(StringUtils.containsIgnoreCase(this.name, "Baby"))
{
this.tag = "IsBaby";
return ByteNBT.valueOf((byte) 1);
}
}
else if(this.entity.equals(EntityType.CHICKEN.getRegistryName()))
{
if(StringUtils.containsIgnoreCase(this.name, "Jockey") && !this.hasPassenger)
{
CompoundNBT passenger = new CompoundNBT();
ListNBT list = new ListNBT();
passenger.putString("id", EntityType.ZOMBIE.getRegistryName().toString());
passenger.putBoolean("IsBaby", true);
list.add(passenger);
this.tag = "Passengers";
return list;
}
}
else if(this.entity.equals(EntityType.SPIDER.getRegistryName()))
{
if(StringUtils.containsIgnoreCase(this.name, "Jockey") && !this.hasPassenger)
{
CompoundNBT passenger = new CompoundNBT();
ListNBT list = new ListNBT();
passenger.putString("id", EntityType.SKELETON.getRegistryName().toString());
list.add(passenger);
this.tag = "Passengers";
return list;
}
}
}
}
return null;
return this.nbt;
}
@Override
@@ -151,128 +43,4 @@ public class ComponentSummon implements IBuilderComponent
{
return this.tag;
}
@Nullable
public static ResourceLocation resolve(String entityName)
{
String name = ResourceHelper.stripToResourceLocation(entityName);
for(EntityType<?> type : ForgeRegistries.ENTITIES.getValues())
{
if(type.isSummonable() && entityName.equalsIgnoreCase(I18n.format(type.getTranslationKey())))
{
return type.getRegistryName();
}
}
String entity = name.replaceAll("_", "");
if(entity.equalsIgnoreCase("RedCow"))
{
return EntityType.MOOSHROOM.getRegistryName();
}
else if(entity.equalsIgnoreCase("ChickenJockey"))
{
return EntityType.CHICKEN.getRegistryName();
}
else if(entity.equalsIgnoreCase("Pigman") || entity.equalsIgnoreCase("ZombiePig") || entity.equalsIgnoreCase("ZombiePigman"))
{
return EntityType.ZOMBIE_PIGMAN.getRegistryName();
}
else if(entity.equalsIgnoreCase("Wither"))
{
return EntityType.WITHER.getRegistryName();
}
else if(entity.equalsIgnoreCase("Dog"))
{
return EntityType.WOLF.getRegistryName();
}
else if(entity.equalsIgnoreCase("Dragon"))
{
return EntityType.ENDER_DRAGON.getRegistryName();
}
else if(entity.equalsIgnoreCase("minecraft:SnowGolem"))
{
return EntityType.SNOW_GOLEM.getRegistryName();
}
else if(entity.equalsIgnoreCase("Horse") || entity.equalsIgnoreCase("ZombieHorse") || entity.equalsIgnoreCase("SkeletonHorse"))
{
return EntityType.HORSE.getRegistryName();
}
else if(entity.equalsIgnoreCase("LavaCube")|| entity.equalsIgnoreCase("MagmaSlime") || entity.equalsIgnoreCase("MagmaCube"))
{
return EntityType.MAGMA_CUBE.getRegistryName();
}
else if(entity.equalsIgnoreCase("SpiderJockey"))
{
return EntityType.SPIDER.getRegistryName();
}
else if(entity.equalsIgnoreCase("IronGolem"))
{
return EntityType.IRON_GOLEM.getRegistryName();
}
else if(entity.equalsIgnoreCase("Ozelot") || entity.equals("Ocelot") || entity.equalsIgnoreCase("Cat") || entity.equalsIgnoreCase("Kitty") || entity.equalsIgnoreCase("Kitten"))
{
return EntityType.OCELOT.getRegistryName();
}
else if(entity.equalsIgnoreCase("TESTIFICATE") || entity.equalsIgnoreCase("Blacksmith") || entity.equalsIgnoreCase("Farmer") || entity.equalsIgnoreCase("Fisherman") || entity.equalsIgnoreCase("Shepherd") || entity.equalsIgnoreCase("Fletcher") || entity.equalsIgnoreCase("Librarian") || entity.equalsIgnoreCase("Cleric") || entity.equalsIgnoreCase("Priest") || entity.equalsIgnoreCase("Armorer") || entity.equalsIgnoreCase("WeaponSmith") || entity.equalsIgnoreCase("ToolSmith") || entity.equalsIgnoreCase("Butcher") || entity.equalsIgnoreCase("Leatherworker") || entity.equalsIgnoreCase("Carthographer") || entity.equalsIgnoreCase("Nitwit"))
{
return EntityType.VILLAGER.getRegistryName();
}
else if(entity.equalsIgnoreCase("Octopus") || entity.equalsIgnoreCase("Kraken"))
{
return EntityType.SQUID.getRegistryName();
}
else if(entity.equalsIgnoreCase("Exwife"))
{
return EntityType.GHAST.getRegistryName();
}
else if(entity.equalsIgnoreCase("TNTMinecart"))
{
return EntityType.TNT_MINECART.getRegistryName();
}
else if(entity.equalsIgnoreCase("Minecart"))
{
return EntityType.MINECART.getRegistryName();
}
else if(entity.equalsIgnoreCase("HopperMinecart"))
{
return EntityType.HOPPER_MINECART.getRegistryName();
}
else if(entity.equalsIgnoreCase("ChestMinecart"))
{
return EntityType.CHEST_MINECART.getRegistryName();
}
else if(entity.equalsIgnoreCase("SpawnerMinecart"))
{
return EntityType.SPAWNER_MINECART.getRegistryName();
}
else if(entity.equalsIgnoreCase("FurnaceMinecart"))
{
return EntityType.FURNACE_MINECART.getRegistryName();
}
else if(entity.equalsIgnoreCase("CommandBlockMinecart") || entity.equalsIgnoreCase("MinecartCommand") || entity.equalsIgnoreCase("CommandMinecart"))
{
return EntityType.COMMAND_BLOCK_MINECART.getRegistryName();
}
else if(entity.equalsIgnoreCase("Wizard"))
{
return EntityType.EVOKER.getRegistryName();
}
else if(entity.equalsIgnoreCase("Johnny"))
{
return EntityType.VINDICATOR.getRegistryName();
}
else if(entity.equalsIgnoreCase("BabyZombie"))
{
return EntityType.ZOMBIE.getRegistryName();
}
if(entity == null || entity.isEmpty())
{
return null;
}
return ResourceHelper.stringToResourceLocation(name);
}
}

View File

@@ -0,0 +1,430 @@
package exopandora.worldhandler.builder.component.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.apache.commons.lang3.ArrayUtils;
import exopandora.worldhandler.builder.component.IBuilderComponent;
import exopandora.worldhandler.builder.impl.EnumAttributes;
import exopandora.worldhandler.builder.impl.EnumAttributes.Applyable;
import exopandora.worldhandler.util.MutableStringTextComponent;
import exopandora.worldhandler.util.NBTHelper;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.item.Item;
import net.minecraft.nbt.ByteNBT;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.INBT;
import net.minecraft.nbt.IntNBT;
import net.minecraft.nbt.StringNBT;
import net.minecraft.potion.Effect;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
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(attribute -> attribute.getApplyable().equals(Applyable.BOTH) || attribute.getApplyable().equals(Applyable.MOB));
private MutableStringTextComponent customName = new MutableStringTextComponent();
private List<EntityNBT> passengers = new ArrayList<EntityNBT>();
private ResourceLocation[] armorItems = {Blocks.AIR.getRegistryName(), Blocks.AIR.getRegistryName(), Blocks.AIR.getRegistryName(), Blocks.AIR.getRegistryName()};
private ResourceLocation[] handItems = {Blocks.AIR.getRegistryName(), Blocks.AIR.getRegistryName()};
private ComponentPotionMob potion = new ComponentPotionMob();
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(EnumAttributes attribute, double ammount)
{
this.attribute.set(attribute, ammount);
}
public void removeAttribute(EnumAttributes attribute)
{
this.attribute.remove(attribute);
}
public double getAttributeAmmount(EnumAttributes attribute)
{
return this.attribute.getAmmount(attribute);
}
public Set<EnumAttributes> getAttributes()
{
return this.attribute.getAttributes();
}
public void setCustomName(String name)
{
this.customName.setText(name);
}
@Nullable
public MutableStringTextComponent 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(ArrayUtils.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(ArrayUtils.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(ArrayUtils.isArrayIndexValid(this.handItems, index) && location != null)
{
this.handItems[index] = location;
}
}
@Nonnull
public ResourceLocation getHandItem(int slot)
{
if(ArrayUtils.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(Effect potion, byte amplifier)
{
this.potion.setAmplifier(potion, amplifier);
}
public void setSeconds(Effect potion, int seconds)
{
this.potion.setSeconds(potion, seconds);
}
public void setMinutes(Effect potion, int minutes)
{
this.potion.setMinutes(potion, minutes);
}
public void setHours(Effect potion, int hours)
{
this.potion.setHours(potion, hours);
}
public void setShowParticles(Effect potion, boolean showParticles)
{
this.potion.setShowParticles(potion, showParticles);
}
public void setAmbient(Effect potion, boolean ambient)
{
this.potion.setAmbient(potion, ambient);
}
public byte getAmplifier(Effect potion)
{
return this.potion.getAmplifier(potion);
}
public int getSeconds(Effect potion)
{
return this.potion.getSeconds(potion);
}
public int getMinutes(Effect potion)
{
return this.potion.getMinutes(potion);
}
public int getHours(Effect potion)
{
return this.potion.getHours(potion);
}
public boolean getShowParticles(Effect potion)
{
return this.potion.getShowParticles(potion);
}
public boolean getAmbient(Effect potion)
{
return this.potion.getAmbient(potion);
}
public Set<Effect> getEffects()
{
return this.potion.getEffects();
}
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, INBT 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;
}
@Override
public CompoundNBT serialize()
{
CompoundNBT nbt = new CompoundNBT();
if(this.time != null)
{
NBTHelper.append(nbt, "Time", IntNBT.valueOf(this.time));
}
if(this.command != null)
{
NBTHelper.append(nbt, "Command", StringNBT.valueOf(this.command));
}
if(this.isBaby)
{
NBTHelper.append(nbt, "IsBaby", ByteNBT.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, "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(nbt.isEmpty())
{
return null;
}
return nbt;
}
@Override
public String getTag()
{
return null;
}
}

View File

@@ -1,69 +1,65 @@
package exopandora.worldhandler.builder.impl;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.function.Consumer;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.apache.commons.lang3.StringUtils;
import exopandora.worldhandler.builder.CommandBuilderNBT;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.component.impl.ComponentAttributeMob;
import exopandora.worldhandler.builder.component.impl.ComponentPotionMob;
import exopandora.worldhandler.builder.component.impl.ComponentSummon;
import exopandora.worldhandler.builder.component.impl.ComponentTag;
import exopandora.worldhandler.builder.impl.EnumAttributes.Applyable;
import exopandora.worldhandler.builder.types.Coordinate.CoordinateType;
import exopandora.worldhandler.util.MutableStringTextComponent;
import exopandora.worldhandler.builder.types.CoordinateDouble;
import exopandora.worldhandler.builder.component.impl.EntityNBT;
import exopandora.worldhandler.builder.types.ArgumentType;
import exopandora.worldhandler.builder.types.Coordinate.EnumType;
import exopandora.worldhandler.builder.types.CoordinateDouble;
import exopandora.worldhandler.util.MutableStringTextComponent;
import exopandora.worldhandler.util.ResourceHelper;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.block.BlockState;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.merchant.villager.VillagerProfession;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.nbt.ByteNBT;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.INBT;
import net.minecraft.nbt.IntNBT;
import net.minecraft.nbt.ListNBT;
import net.minecraft.nbt.StringNBT;
import net.minecraft.potion.Effect;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.registries.ForgeRegistries;
@OnlyIn(Dist.CLIENT)
public class BuilderSummon extends CommandBuilderNBT
{
private final ComponentAttributeMob attribute;
private final ComponentTag<MutableStringTextComponent> customName;
private final ComponentTag<ListNBT> passengers;
private final ComponentTag<ListNBT> armorItems;
private final ComponentTag<ListNBT> handItems;
private final ComponentPotionMob potion;
private final ComponentSummon summon;
private final ResourceLocation[] armorItemsArray = {Blocks.AIR.getRegistryName(), Blocks.AIR.getRegistryName(), Blocks.AIR.getRegistryName(), Blocks.AIR.getRegistryName()};
private final ResourceLocation[] handItemsArray = {Blocks.AIR.getRegistryName(), Blocks.AIR.getRegistryName()};
private final EntityNBT nbt = new EntityNBT();
public BuilderSummon()
{
this.attribute = this.registerNBTComponent(new ComponentAttributeMob(attribute -> attribute.getApplyable().equals(Applyable.BOTH) || attribute.getApplyable().equals(Applyable.MOB)));
this.customName = this.registerNBTComponent(new ComponentTag<MutableStringTextComponent>("CustomName", new MutableStringTextComponent(), this::textComponentSerializer));
this.passengers = this.registerNBTComponent(new ComponentTag<ListNBT>("Passengers"));
this.armorItems = this.registerNBTComponent(new ComponentTag<ListNBT>("ArmorItems", this::itemListSerializer));
this.handItems = this.registerNBTComponent(new ComponentTag<ListNBT>("HandItems", this::itemListSerializer));
this.summon = this.registerNBTComponent(new ComponentSummon(), "summon");
this.potion = this.registerNBTComponent(new ComponentPotionMob());
this.setX(new CoordinateDouble(0.0, CoordinateType.LOCAL));
this.setY(new CoordinateDouble(0.0, CoordinateType.LOCAL));
this.setZ(new CoordinateDouble(2.0, CoordinateType.LOCAL));
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(String entityName)
public void setName(String name)
{
ResourceLocation location = ComponentSummon.resolve(entityName);
this.summon.setName(entityName);
this.summon.setEntity(location);
this.setNode(0, location);
this.setEntity(BuilderSummon.parseEntityName(name));
this.updateCustomComponent(name);
}
public void setNameAndId(String name)
{
this.setName(name);
this.nbt.setId(this.getEntity());
}
public void setEntity(ResourceLocation entity)
{
this.setNode(0, entity);
}
public ResourceLocation getEntity()
@@ -101,258 +97,282 @@ public class BuilderSummon extends CommandBuilderNBT
return this.getNodeAsCoordinateDouble(3);
}
public void setId(ResourceLocation resource)
{
this.nbt.setId(resource);
}
public ResourceLocation getId()
{
return this.nbt.getId();
}
public void setAttribute(EnumAttributes attribute, double ammount)
{
this.attribute.set(attribute, ammount);
this.nbt.setAttribute(attribute, ammount);
}
public void removeAttribute(EnumAttributes attribute)
{
this.attribute.remove(attribute);
this.nbt.removeAttribute(attribute);
}
public double getAttributeAmmount(EnumAttributes attribute)
{
return this.attribute.getAmmount(attribute);
return this.nbt.getAttributeAmmount(attribute);
}
public Set<EnumAttributes> getAttributes()
{
return this.attribute.getAttributes();
}
public void setCustomName(MutableStringTextComponent name)
{
this.customName.setValue(name);
return this.nbt.getAttributes();
}
public void setCustomName(String name)
{
this.customName.getValue().setText(name);
}
@Nonnull
public MutableStringTextComponent getCustomName()
{
if(this.customName.getValue() != null)
{
return this.customName.getValue();
}
return null;
}
public void setPassenger(String entityName)
{
this.setPassenger(ComponentSummon.resolve(entityName));
}
public void setPassenger(ResourceLocation entityName)
{
if(entityName != null)
{
CompoundNBT passenger = new CompoundNBT();
passenger.putString("id", entityName.toString());
ListNBT list = new ListNBT();
list.add(passenger);
this.passengers.setValue(list);
}
else
{
this.passengers.setValue(null);
}
this.nbt.setCustomName(name);
}
@Nullable
public ResourceLocation getPassenger()
public MutableStringTextComponent getCustomName()
{
ListNBT list = this.passengers.getValue();
if(list != null && !list.isEmpty())
{
return new ResourceLocation(list.getCompound(0).getString("id"));
}
return null;
return this.nbt.getCustomName();
}
public void setPassenger(int index, String name)
{
this.nbt.setPassenger(index, BuilderSummon.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.setArmorItem(index, block.getRegistryName());
this.nbt.setArmorItem(index, block);
}
public void setArmorItem(int index, Item item)
{
this.setArmorItem(index, item.getRegistryName());
this.nbt.setArmorItem(index, item);
}
public void setArmorItem(int index, ResourceLocation location)
{
this.changeNBTList(index, location, this.armorItemsArray, this::setArmorItems);
this.nbt.setArmorItem(index, location);
}
public void setArmorItems(ResourceLocation[] armor)
{
ListNBT list = new ListNBT();
for(ResourceLocation item : armor)
{
CompoundNBT compound = new CompoundNBT();
compound.putString("id", item.toString());
compound.putInt("Count", 1);
list.add(compound);
}
this.armorItems.setValue(list);
this.nbt.setArmorItems(armor);
}
public ResourceLocation getArmorItem(int slot)
{
if(slot < this.armorItemsArray.length)
{
return this.armorItemsArray[slot];
}
return Blocks.AIR.getRegistryName();
return this.nbt.getArmorItem(slot);
}
public void setHandItem(int index, Block block)
{
this.setHandItem(index, block.getRegistryName());
this.nbt.setHandItem(index, block);
}
public void setHandItem(int index, Item item)
{
this.setHandItem(index, item.getRegistryName());
this.nbt.setHandItem(index, item);
}
public void setHandItem(int index, ResourceLocation location)
{
this.changeNBTList(index, location, this.handItemsArray, this::setHandItems);
}
private void changeNBTList(int index, ResourceLocation location, ResourceLocation[] array, Consumer<ResourceLocation[]> consumer)
{
if(index < array.length)
{
array[index] = location;
consumer.accept(array);
}
}
public void setHandItems(ResourceLocation[] armor)
{
ListNBT list = new ListNBT();
for(ResourceLocation item : armor)
{
CompoundNBT compound = new CompoundNBT();
compound.putString("id", item.toString());
compound.putInt("Count", 1);
list.add(compound);
}
this.handItems.setValue(list);
this.nbt.setHandItem(index, location);
}
public ResourceLocation getHandItem(int slot)
{
if(slot < this.handItemsArray.length)
{
return this.handItemsArray[slot];
}
return Blocks.AIR.getRegistryName();
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(Effect potion, byte amplifier)
{
this.potion.setAmplifier(potion, amplifier);
this.nbt.setAmplifier(potion, amplifier);
}
public void setSeconds(Effect potion, int seconds)
{
this.potion.setSeconds(potion, seconds);
this.nbt.setSeconds(potion, seconds);
}
public void setMinutes(Effect potion, int minutes)
{
this.potion.setMinutes(potion, minutes);
this.nbt.setMinutes(potion, minutes);
}
public void setHours(Effect potion, int hours)
{
this.potion.setHours(potion, hours);
this.nbt.setHours(potion, hours);
}
public void setShowParticles(Effect potion, boolean showParticles)
{
this.potion.setShowParticles(potion, showParticles);
this.nbt.setShowParticles(potion, showParticles);
}
public void setAmbient(Effect potion, boolean ambient)
{
this.potion.setAmbient(potion, ambient);
this.nbt.setAmbient(potion, ambient);
}
public byte getAmplifier(Effect potion)
{
return this.potion.getAmplifier(potion);
return this.nbt.getAmplifier(potion);
}
public int getSeconds(Effect potion)
{
return this.potion.getSeconds(potion);
return this.nbt.getSeconds(potion);
}
public int getMinutes(Effect potion)
{
return this.potion.getMinutes(potion);
return this.nbt.getMinutes(potion);
}
public int getHours(Effect potion)
{
return this.potion.getHours(potion);
return this.nbt.getHours(potion);
}
public boolean getShowParticles(Effect potion)
{
return this.potion.getShowParticles(potion);
return this.nbt.getShowParticles(potion);
}
public boolean getAmbient(Effect potion)
{
return this.potion.getAmbient(potion);
return this.nbt.getAmbient(potion);
}
public Set<Effect> getEffects()
{
return this.potion.getEffects();
return this.nbt.getEffects();
}
private INBT itemListSerializer(ListNBT list)
public void setBlockState(BlockState blockState)
{
for(int x = 0; x < list.size(); x++)
{
if(!list.getCompound(x).getString("id").equals(Blocks.AIR.getRegistryName().toString()))
{
return list;
}
}
return null;
this.nbt.setBlockState(blockState);
}
private INBT textComponentSerializer(MutableStringTextComponent string)
public BlockState getBlockState()
{
if(string.getUnformattedComponentText() != null && !string.getUnformattedComponentText().isEmpty())
{
return StringNBT.valueOf(string.serialize());
}
return null;
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();
}
@Override
protected CompoundNBT buildNBT()
{
return this.nbt.serialize();
}
@Override
@@ -381,12 +401,196 @@ public class BuilderSummon extends CommandBuilderNBT
return syntax;
}
@Override
public String toCommand()
private void updateCustomComponent(String name)
{
this.summon.setEntity(this.getEntity());
this.summon.setHasPassenger(this.getPassenger() != null);
if(name != null && this.getEntity() != null)
{
if(EntityType.CAT.getRegistryName().equals(this.getEntity()))
{
this.nbt.setCustomComponent("CatType", IntNBT.valueOf(new Random().nextInt(11)));
}
else if(EntityType.VILLAGER.getRegistryName().equals(this.getEntity()))
{
for(VillagerProfession profession : ForgeRegistries.PROFESSIONS)
{
if(StringUtils.equalsIgnoreCase(name, profession.toString()))
{
CompoundNBT villagerData = new CompoundNBT();
villagerData.putString("profession", profession.getRegistryName().toString());
this.nbt.setCustomComponent("VillagerData", villagerData);
break;
}
}
}
else if(EntityType.ZOMBIE.getRegistryName().equals(this.getEntity()))
{
if(StringUtils.containsIgnoreCase(name, "Baby"))
{
this.nbt.setCustomComponent("IsBaby", ByteNBT.valueOf((byte) 1));
}
}
else if(EntityType.CHICKEN.getRegistryName().equals(this.getEntity()))
{
if(StringUtils.containsIgnoreCase(name, "Jockey") && !this.nbt.hasPassengers())
{
ListNBT list = new ListNBT();
EntityNBT zombie = new EntityNBT(EntityType.ZOMBIE.getRegistryName());
zombie.setIsBaby(true);
list.add(zombie.serialize());
this.nbt.setCustomComponent("Passengers", list);
}
}
else if(EntityType.SPIDER.getRegistryName().equals(this.getEntity()))
{
if(StringUtils.containsIgnoreCase(name, "Jockey") && !this.nbt.hasPassengers())
{
ListNBT list = new ListNBT();
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);
return super.toCommand();
for(EntityType<?> type : ForgeRegistries.ENTITIES.getValues())
{
if(type.isSummonable() && entityName.equalsIgnoreCase(I18n.format(type.getTranslationKey())))
{
return type.getRegistryName();
}
}
String entity = name.replaceAll("_", "");
if(entity.equalsIgnoreCase("RedCow"))
{
return EntityType.MOOSHROOM.getRegistryName();
}
else if(entity.equalsIgnoreCase("ChickenJockey"))
{
return EntityType.CHICKEN.getRegistryName();
}
else if(entity.equalsIgnoreCase("Pigman") || entity.equalsIgnoreCase("ZombiePig") || entity.equalsIgnoreCase("ZombiePigman"))
{
return EntityType.ZOMBIE_PIGMAN.getRegistryName();
}
else if(entity.equalsIgnoreCase("Wither"))
{
return EntityType.WITHER.getRegistryName();
}
else if(entity.equalsIgnoreCase("Dog"))
{
return EntityType.WOLF.getRegistryName();
}
else if(entity.equalsIgnoreCase("Dragon"))
{
return EntityType.ENDER_DRAGON.getRegistryName();
}
else if(entity.equalsIgnoreCase("SnowMan"))
{
return EntityType.SNOW_GOLEM.getRegistryName();
}
else if(entity.equalsIgnoreCase("Horse") || entity.equalsIgnoreCase("ZombieHorse") || entity.equalsIgnoreCase("SkeletonHorse"))
{
return EntityType.HORSE.getRegistryName();
}
else if(entity.equalsIgnoreCase("LavaCube")|| entity.equalsIgnoreCase("MagmaSlime") || entity.equalsIgnoreCase("MagmaCube"))
{
return EntityType.MAGMA_CUBE.getRegistryName();
}
else if(entity.equalsIgnoreCase("SpiderJockey"))
{
return EntityType.SPIDER.getRegistryName();
}
else if(entity.equalsIgnoreCase("IronGolem"))
{
return EntityType.IRON_GOLEM.getRegistryName();
}
else if(entity.equalsIgnoreCase("Ozelot") || entity.equals("Ocelot"))
{
return EntityType.OCELOT.getRegistryName();
}
else if(entity.equalsIgnoreCase("Kitty") || entity.equalsIgnoreCase("Kitten"))
{
return EntityType.CAT.getRegistryName();
}
else if(entity.equalsIgnoreCase("TESTIFICATE") || entity.equalsIgnoreCase("Blacksmith") || entity.equalsIgnoreCase("Farmer") || entity.equalsIgnoreCase("Fisherman") || entity.equalsIgnoreCase("Shepherd") || entity.equalsIgnoreCase("Fletcher") || entity.equalsIgnoreCase("Librarian") || entity.equalsIgnoreCase("Cleric") || entity.equalsIgnoreCase("Priest") || entity.equalsIgnoreCase("Armorer") || entity.equalsIgnoreCase("WeaponSmith") || entity.equalsIgnoreCase("ToolSmith") || entity.equalsIgnoreCase("Butcher") || entity.equalsIgnoreCase("Leatherworker") || entity.equalsIgnoreCase("Carthographer") || entity.equalsIgnoreCase("Nitwit"))
{
return EntityType.VILLAGER.getRegistryName();
}
else if(entity.equalsIgnoreCase("Octopus") || entity.equalsIgnoreCase("Kraken"))
{
return EntityType.SQUID.getRegistryName();
}
else if(entity.equalsIgnoreCase("Exwife"))
{
return EntityType.GHAST.getRegistryName();
}
else if(entity.equalsIgnoreCase("TNTMinecart"))
{
return EntityType.TNT_MINECART.getRegistryName();
}
else if(entity.equalsIgnoreCase("Minecart"))
{
return EntityType.MINECART.getRegistryName();
}
else if(entity.equalsIgnoreCase("HopperMinecart"))
{
return EntityType.HOPPER_MINECART.getRegistryName();
}
else if(entity.equalsIgnoreCase("ChestMinecart"))
{
return EntityType.CHEST_MINECART.getRegistryName();
}
else if(entity.equalsIgnoreCase("SpawnerMinecart"))
{
return EntityType.SPAWNER_MINECART.getRegistryName();
}
else if(entity.equalsIgnoreCase("FurnaceMinecart"))
{
return EntityType.FURNACE_MINECART.getRegistryName();
}
else if(entity.equalsIgnoreCase("CommandBlockMinecart") || entity.equalsIgnoreCase("MinecartCommand") || entity.equalsIgnoreCase("CommandMinecart"))
{
return EntityType.COMMAND_BLOCK_MINECART.getRegistryName();
}
else if(entity.equalsIgnoreCase("Wizard"))
{
return EntityType.EVOKER.getRegistryName();
}
else if(entity.equalsIgnoreCase("Johnny"))
{
return EntityType.VINDICATOR.getRegistryName();
}
else if(entity.equalsIgnoreCase("BabyZombie"))
{
return EntityType.ZOMBIE.getRegistryName();
}
if(entity == null || entity.isEmpty())
{
return null;
}
return ResourceHelper.stringToResourceLocation(name);
}
}