Replace passenger with custom nbt field, Add submenu for custom name formatting

This commit is contained in:
Marcel Konrad
2020-11-06 20:08:10 +01:00
parent 3daf607656
commit fd95baf5f7
12 changed files with 656 additions and 565 deletions

View File

@@ -8,6 +8,8 @@ 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.MutableStringTextComponent;
import exopandora.worldhandler.util.NBTHelper;
@@ -21,6 +23,7 @@ import net.minecraft.nbt.ByteNBT;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.INBT;
import net.minecraft.nbt.IntNBT;
import net.minecraft.nbt.JsonToNBT;
import net.minecraft.nbt.StringNBT;
import net.minecraft.potion.Effect;
import net.minecraft.util.ResourceLocation;
@@ -43,6 +46,7 @@ public class EntityNBT implements IBuilderComponent
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 CompoundNBT nbt;
public EntityNBT()
{
@@ -300,7 +304,7 @@ public class EntityNBT implements IBuilderComponent
{
return this.potion.getAmplifier(potion);
}
public int getSeconds(Effect potion)
{
return this.potion.getSeconds(potion);
@@ -381,6 +385,28 @@ public class EntityNBT implements IBuilderComponent
return this.command;
}
public void setNBT(CompoundNBT nbt)
{
this.nbt = nbt;
}
public CompoundNBT getNBT()
{
return this.nbt;
}
public void setNBT(String nbt)
{
try
{
this.nbt = JsonToNBT.getTagFromJson("{" + nbt + "}");
}
catch(CommandSyntaxException e)
{
this.nbt = null;
}
}
@Override
public CompoundNBT serialize()
{
@@ -414,6 +440,11 @@ public class EntityNBT implements IBuilderComponent
NBTHelper.append(nbt, this.potion);
NBTHelper.append(nbt, this.attribute);
if(this.nbt != null)
{
nbt.merge(this.nbt);
}
if(nbt.isEmpty())
{
return null;

View File

@@ -0,0 +1,509 @@
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.MutableStringTextComponent;
import exopandora.worldhandler.util.ResourceHelper;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ai.attributes.Attribute;
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.IntNBT;
import net.minecraft.nbt.ListNBT;
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 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 MutableStringTextComponent 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(Effect potion, byte amplifier)
{
this.nbt.setAmplifier(potion, amplifier);
}
public void setSeconds(Effect potion, int seconds)
{
this.nbt.setSeconds(potion, seconds);
}
public void setMinutes(Effect potion, int minutes)
{
this.nbt.setMinutes(potion, minutes);
}
public void setHours(Effect potion, int hours)
{
this.nbt.setHours(potion, hours);
}
public void setShowParticles(Effect potion, boolean showParticles)
{
this.nbt.setShowParticles(potion, showParticles);
}
public void setAmbient(Effect potion, boolean ambient)
{
this.nbt.setAmbient(potion, ambient);
}
public byte getAmplifier(Effect potion)
{
return this.nbt.getAmplifier(potion);
}
public int getSeconds(Effect potion)
{
return this.nbt.getSeconds(potion);
}
public int getMinutes(Effect potion)
{
return this.nbt.getMinutes(potion);
}
public int getHours(Effect potion)
{
return this.nbt.getHours(potion);
}
public boolean getShowParticles(Effect potion)
{
return this.nbt.getShowParticles(potion);
}
public boolean getAmbient(Effect potion)
{
return this.nbt.getAmbient(potion);
}
public Set<Effect> getEffects()
{
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(CompoundNBT nbt)
{
this.nbt.setNBT(nbt);
}
public CompoundNBT getEntityNBT()
{
return this.nbt.getNBT();
}
@Override
protected CompoundNBT 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", IntNBT.valueOf(new Random().nextInt(11)));
}
else if(entity.equals(EntityType.VILLAGER.getRegistryName()))
{
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(entity.equals(EntityType.ZOMBIE.getRegistryName()))
{
if(StringUtils.containsIgnoreCase(name, "Baby"))
{
this.nbt.setCustomComponent("IsBaby", ByteNBT.valueOf((byte) 1));
}
}
else if(entity.equals(EntityType.CHICKEN.getRegistryName()))
{
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(entity.equals(EntityType.SPIDER.getRegistryName()))
{
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);
if(name == null || name.isEmpty())
{
return null;
}
for(EntityType<?> type : ForgeRegistries.ENTITIES.getValues())
{
if(type.isSummonable() && entityName.equalsIgnoreCase(I18n.format(type.getTranslationKey())))
{
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,44 +1,17 @@
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.CommandSyntax;
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.BlockState;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ai.attributes.Attribute;
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.IntNBT;
import net.minecraft.nbt.ListNBT;
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
public class BuilderSummon extends BuilderEntity
{
private final EntityNBT nbt = new EntityNBT();
public BuilderSummon()
{
this.setX(new CoordinateDouble(0.0, EnumType.LOCAL));
@@ -46,18 +19,6 @@ public class BuilderSummon extends CommandBuilderNBT
this.setZ(new CoordinateDouble(2.0, EnumType.LOCAL));
}
public void setName(String name)
{
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);
@@ -98,284 +59,6 @@ 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(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 MutableStringTextComponent getCustomName()
{
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.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(Effect potion, byte amplifier)
{
this.nbt.setAmplifier(potion, amplifier);
}
public void setSeconds(Effect potion, int seconds)
{
this.nbt.setSeconds(potion, seconds);
}
public void setMinutes(Effect potion, int minutes)
{
this.nbt.setMinutes(potion, minutes);
}
public void setHours(Effect potion, int hours)
{
this.nbt.setHours(potion, hours);
}
public void setShowParticles(Effect potion, boolean showParticles)
{
this.nbt.setShowParticles(potion, showParticles);
}
public void setAmbient(Effect potion, boolean ambient)
{
this.nbt.setAmbient(potion, ambient);
}
public byte getAmplifier(Effect potion)
{
return this.nbt.getAmplifier(potion);
}
public int getSeconds(Effect potion)
{
return this.nbt.getSeconds(potion);
}
public int getMinutes(Effect potion)
{
return this.nbt.getMinutes(potion);
}
public int getHours(Effect potion)
{
return this.nbt.getHours(potion);
}
public boolean getShowParticles(Effect potion)
{
return this.nbt.getShowParticles(potion);
}
public boolean getAmbient(Effect potion)
{
return this.nbt.getAmbient(potion);
}
public Set<Effect> getEffects()
{
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();
}
@Override
protected CompoundNBT buildNBT()
{
return this.nbt.serialize();
}
@Override
public void setNBT(CompoundNBT nbt)
{
@@ -401,167 +84,4 @@ public class BuilderSummon extends CommandBuilderNBT
return syntax;
}
private void updateCustomComponent(String name)
{
ResourceLocation entity = this.getEntity();
if(name != null && entity != null)
{
if(entity.equals(EntityType.CAT.getRegistryName()))
{
this.nbt.setCustomComponent("CatType", IntNBT.valueOf(new Random().nextInt(11)));
}
else if(entity.equals(EntityType.VILLAGER.getRegistryName()))
{
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(entity.equals(EntityType.ZOMBIE.getRegistryName()))
{
if(StringUtils.containsIgnoreCase(name, "Baby"))
{
this.nbt.setCustomComponent("IsBaby", ByteNBT.valueOf((byte) 1));
}
}
else if(entity.equals(EntityType.CHICKEN.getRegistryName()))
{
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(entity.equals(EntityType.SPIDER.getRegistryName()))
{
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);
if(name == null || name.isEmpty())
{
return null;
}
for(EntityType<?> type : ForgeRegistries.ENTITIES.getValues())
{
if(type.isSummonable() && entityName.equalsIgnoreCase(I18n.format(type.getTranslationKey())))
{
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

@@ -132,7 +132,7 @@ public class ContentSignEditor extends Content
if(this.editColor)
{
container.add(new GuiButtonBase(x + 118, y + 72, 114, 20, new TranslationTextComponent("gui.worldhandler.blocks.sign_editor.done"), () -> this.toggleEditColor(container)));
container.add(new GuiButtonBase(x + 118, y + 72, 114, 20, new TranslationTextComponent("gui.worldhandler.generic.done"), () -> this.toggleEditColor(container)));
}
else
{

View File

@@ -17,7 +17,9 @@ import exopandora.worldhandler.gui.category.Category;
import exopandora.worldhandler.gui.container.Container;
import exopandora.worldhandler.gui.content.Content;
import exopandora.worldhandler.gui.content.Contents;
import exopandora.worldhandler.gui.menu.impl.ILogicColorMenu;
import exopandora.worldhandler.gui.menu.impl.ILogicPageList;
import exopandora.worldhandler.gui.menu.impl.MenuColorField;
import exopandora.worldhandler.gui.menu.impl.MenuPageList;
import exopandora.worldhandler.gui.widget.button.EnumIcon;
import exopandora.worldhandler.gui.widget.button.GuiButtonBase;
@@ -51,16 +53,14 @@ import net.minecraftforge.registries.ForgeRegistries;
public class ContentSummon extends Content
{
private GuiTextFieldTooltip mobField;
private GuiTextFieldTooltip customNameField;
private GuiTextFieldTooltip passengerField;
private GuiTextFieldTooltip nbtField;
private int potionPage = 0;
private boolean editColor;
private Page page = Page.START;
private String mob;
private String name;
private String passenger;
private String nbt;
private final BuilderSummon builderSummon = new BuilderSummon();
@@ -157,7 +157,7 @@ public class ContentSummon extends Content
@Override
public void initGui(Container container, int x, int y)
{
this.mobField = new GuiTextFieldTooltip(x + 118, y, 114, 20, new StringTextComponent(I18n.format("gui.worldhandler.entities.summon.start.mob_id") + " (" + I18n.format("gui.worldhandler.generic.name") + ")"));
this.mobField = new GuiTextFieldTooltip(x + 118, y, 114, 20, new TranslationTextComponent("gui.worldhandler.entities.summon.start.mob_id"));
this.mobField.setValidator(Predicates.notNull());
this.mobField.setText(this.mob);
this.mobField.setResponder(text ->
@@ -167,27 +167,42 @@ public class ContentSummon extends Content
container.initButtons();
});
this.customNameField = new GuiTextFieldTooltip(x + 118, y + 24, 114, 20, new TranslationTextComponent("gui.worldhandler.entities.summon.start.custom_name"));
this.customNameField.setValidator(Predicates.notNull());
this.customNameField.setText(this.name);
this.customNameField.setResponder(text ->
this.nbtField = new GuiTextFieldTooltip(x + 118, y + 48, 114, 20, new TranslationTextComponent("gui.worldhandler.entities.summon.start.custom_nbt"));
this.nbtField.setValidator(Predicates.notNull());
this.nbtField.setText(this.nbt);
this.nbtField.setResponder(text ->
{
this.name = text;
this.builderSummon.setCustomName(this.name);
this.nbt = text;
this.builderSummon.setEntityNBT(this.nbt);
container.initButtons();
});
this.passengerField = new GuiTextFieldTooltip(x + 118, y + 48, 114, 20, new TranslationTextComponent("gui.worldhandler.entities.summon.start.passenger_mob_id"));
this.passengerField.setValidator(Predicates.notNull());
this.passengerField.setText(this.passenger);
this.passengerField.setResponder(text ->
if(Page.START.equals(this.page))
{
this.passenger = this.passengerField.getText();
this.builderSummon.setPassenger(0, this.passenger);
container.initButtons();
});
if(Page.ATTRIBUTES.equals(this.page))
MenuColorField customName = new MenuColorField(x, y, "gui.worldhandler.entities.summon.start.custom_name", this.builderSummon.getCustomName(), new ILogicColorMenu()
{
@Override
public boolean doDrawButtons()
{
return ContentSummon.this.editColor;
}
@Override
public boolean doDrawTextField()
{
return ContentSummon.this.editColor;
}
@Override
public String getId()
{
return "custom_name";
}
});
container.add(customName);
}
else if(Page.ATTRIBUTES.equals(this.page))
{
MenuPageList<Attribute> attributes = new MenuPageList<Attribute>(x + 118, y, ComponentAttribute.ATTRIBUTES, 114, 20, 3, container, new ILogicPageList<Attribute>()
{
@@ -246,48 +261,39 @@ public class ContentSummon extends Content
GuiButtonBase button6;
GuiButtonBase button7;
container.add(new GuiButtonBase(x, y + 96, 114, 20, new TranslationTextComponent("gui.worldhandler.generic.back"), () -> ActionHelper.back(this)));
container.add(new GuiButtonBase(x + 118, y + 96, 114, 20, new TranslationTextComponent("gui.worldhandler.generic.backToGame"), ActionHelper::backToGame));
container.add(new GuiButtonBase(x, y + 96, 114, 20, "gui.worldhandler.generic.back", () -> ActionHelper.back(this)));
container.add(new GuiButtonBase(x + 118, y + 96, 114, 20, "gui.worldhandler.generic.backToGame", ActionHelper::backToGame));
container.add(button4 = new GuiButtonBase(x, y, 114, 20, new TranslationTextComponent("gui.worldhandler.entities.summon.start"), () ->
{
this.page = Page.START;
container.init();
}));
container.add(button5 = new GuiButtonBase(x, y + 24, 114, 20, new TranslationTextComponent("gui.worldhandler.entities.summon.potion_effects"), () ->
{
this.page = Page.POTIONS;
container.init();
}));
container.add(button6 = new GuiButtonBase(x, y + 48, 114, 20, new TranslationTextComponent("gui.worldhandler.entities.summon.attributes"), () ->
{
this.page = Page.ATTRIBUTES;
container.init();
}));
container.add(button7 = new GuiButtonBase(x, y + 72, 114, 20, new TranslationTextComponent("gui.worldhandler.entities.summon.equipment"), () ->
{
this.page = Page.EQUIPMENT;
container.init();
}));
container.add(button4 = new GuiButtonBase(x, y, 114, 20, "gui.worldhandler.entities.summon.start", () -> this.changePage(container, Page.START)));
container.add(button5 = new GuiButtonBase(x, y + 24, 114, 20, "gui.worldhandler.entities.summon.potion_effects", () -> this.changePage(container, Page.POTIONS)));
container.add(button6 = new GuiButtonBase(x, y + 48, 114, 20, "gui.worldhandler.entities.summon.attributes", () -> this.changePage(container, Page.ATTRIBUTES)));
container.add(button7 = new GuiButtonBase(x, y + 72, 114, 20, "gui.worldhandler.entities.summon.equipment", () -> this.changePage(container, Page.EQUIPMENT)));
if(Page.START.equals(this.page))
{
button4.active = false;
container.add(this.mobField);
container.add(this.customNameField);
container.add(this.passengerField);
if(!this.builderSummon.needsCommandBlock() && !this.builderSummon.getCustomName().isSpecial())
if(this.editColor)
{
container.add(button3 = new GuiButtonBase(x + 118, y + 72, 114, 20, new TranslationTextComponent("gui.worldhandler.title.entities.summon"), () -> this.send(container.getPlayer())));
container.add(new GuiButtonBase(x + 118, y + 72, 114, 20, "gui.worldhandler.generic.done", () -> this.toggleEditColor(container)));
}
else
{
container.add(button3 = new GuiButtonBase(x + 118, y + 72, 114, 20, new TranslationTextComponent("gui.worldhandler.actions.place_command_block"), () -> this.send(container.getPlayer())));
container.add(this.mobField);
container.add(new GuiButtonBase(x + 118, y + 24, 114, 20, "gui.worldhandler.entities.summon.start.custom_name", () -> this.toggleEditColor(container)));
container.add(this.nbtField);
if(!this.builderSummon.needsCommandBlock() && !this.builderSummon.getCustomName().isSpecial())
{
container.add(button3 = new GuiButtonBase(x + 118, y + 72, 114, 20, "gui.worldhandler.title.entities.summon", () -> this.send(container.getPlayer())));
}
else
{
container.add(button3 = new GuiButtonBase(x + 118, y + 72, 114, 20, "gui.worldhandler.actions.place_command_block", () -> this.send(container.getPlayer())));
}
button3.active = ForgeRegistries.ENTITIES.containsKey(this.builderSummon.getEntity());
}
button3.active = ForgeRegistries.ENTITIES.containsKey(this.builderSummon.getEntity());
}
else if(Page.POTIONS.equals(this.page))
{
@@ -306,7 +312,7 @@ public class ContentSummon extends Content
int count = 0;
for(ResourceLocation location : this.getSortedPotionList())
for(ResourceLocation location : this.sortedPotions())
{
Effect potion = ForgeRegistries.POTIONS.getValue(location);
@@ -402,9 +408,11 @@ public class ContentSummon extends Content
{
if(Page.START.equals(this.page))
{
this.mobField.tick();
this.customNameField.tick();
this.passengerField.tick();
if(!this.editColor)
{
this.mobField.tick();
this.nbtField.tick();
}
}
}
@@ -413,9 +421,11 @@ public class ContentSummon extends Content
{
if(Page.START.equals(this.page))
{
this.mobField.renderButton(matrix, mouseX, mouseY, partialTicks);
this.customNameField.renderButton(matrix, mouseX, mouseY, partialTicks);
this.passengerField.renderButton(matrix, mouseX, mouseY, partialTicks);
if(!this.editColor)
{
this.mobField.renderButton(matrix, mouseX, mouseY, partialTicks);
this.nbtField.renderButton(matrix, mouseX, mouseY, partialTicks);
}
}
else if(Page.POTIONS.equals(this.page))
{
@@ -445,13 +455,25 @@ public class ContentSummon extends Content
}
}
private List<ResourceLocation> getSortedPotionList()
private List<ResourceLocation> sortedPotions()
{
return ForgeRegistries.POTIONS.getKeys().stream()
.sorted((a, b) -> I18n.format(ForgeRegistries.POTIONS.getValue(a).getName()).compareTo(I18n.format(ForgeRegistries.POTIONS.getValue(b).getName())))
.collect(Collectors.toList());
}
private void toggleEditColor(Container container)
{
this.editColor = !this.editColor;
container.init();
}
private void changePage(Container container, Page page)
{
this.page = page;
container.init();
}
@Override
public Category getCategory()
{

View File

@@ -17,6 +17,11 @@ public interface ILogicColorMenu extends ILogic
return true;
}
default boolean doDrawTextField()
{
return true;
}
@Override
default String getId()
{

View File

@@ -79,7 +79,10 @@ public class MenuColorField extends Menu
@Override
public void initButtons(Container container)
{
container.add(this.textField);
if(this.logic.doDrawTextField())
{
container.add(this.textField);
}
if(this.logic.doDrawButtons())
{
@@ -147,12 +150,18 @@ public class MenuColorField extends Menu
@Override
public void tick()
{
this.textField.tick();
if(this.logic.doDrawTextField())
{
this.textField.tick();
}
}
@Override
public void draw(MatrixStack matrix, int mouseX, int mouseY, float partialTicks)
{
this.textField.renderButton(matrix, mouseX, mouseY, partialTicks);
if(this.logic.doDrawTextField())
{
this.textField.renderButton(matrix, mouseX, mouseY, partialTicks);
}
}
}