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);
}
}

View File

@@ -8,24 +8,13 @@ import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
public class Categories
{
public static final Category MAIN;
public static final Category ENTITIES;
public static final Category ITEMS;
public static final Category BLOCKS;
public static final Category WORLD;
public static final Category PLAYER;
public static final Category SCOREBOARD;
static
{
MAIN = Categories.getRegisteredCategory("main");
ENTITIES = Categories.getRegisteredCategory("entities");
ITEMS = Categories.getRegisteredCategory("items");
BLOCKS = Categories.getRegisteredCategory("blocks");
WORLD = Categories.getRegisteredCategory("world");
PLAYER = Categories.getRegisteredCategory("player");
SCOREBOARD = Categories.getRegisteredCategory("scoreboard");
}
public static final Category MAIN = Categories.getRegisteredCategory("main");
public static final Category ENTITIES = Categories.getRegisteredCategory("entities");
public static final Category ITEMS = Categories.getRegisteredCategory("items");
public static final Category BLOCKS = Categories.getRegisteredCategory("blocks");
public static final Category WORLD = Categories.getRegisteredCategory("world");
public static final Category PLAYER = Categories.getRegisteredCategory("player");
public static final Category SCOREBOARD = Categories.getRegisteredCategory("scoreboard");
public static Category getRegisteredCategory(String name)
{

View File

@@ -93,7 +93,7 @@ public class Category extends ForgeRegistryEntry<Category>
public static void register(Register<Category> event)
{
RegistryHelper.register(event.getRegistry(), "main", new Category("main", "containers", "multiplayer"));
RegistryHelper.register(event.getRegistry(), "entities", new Category("summon"));
RegistryHelper.register(event.getRegistry(), "entities", new Category("summon", "butcher"));
RegistryHelper.register(event.getRegistry(), "items", new Category("custom_item", "enchantment", "recipes"));
RegistryHelper.register(event.getRegistry(), "blocks", new Category("edit_blocks", "sign_editor", "note_editor"));
RegistryHelper.register(event.getRegistry(), "world", new Category("world", "gamerules"));

View File

@@ -9,6 +9,7 @@ import exopandora.worldhandler.gui.content.impl.ContentAdvancements;
import exopandora.worldhandler.gui.content.impl.ContentButcher;
import exopandora.worldhandler.gui.content.impl.ContentButcherSettings;
import exopandora.worldhandler.gui.content.impl.ContentChangeWorld;
import exopandora.worldhandler.gui.content.impl.ContentCommandStack;
import exopandora.worldhandler.gui.content.impl.ContentContainers;
import exopandora.worldhandler.gui.content.impl.ContentContinue;
import exopandora.worldhandler.gui.content.impl.ContentCustomItem;
@@ -100,6 +101,7 @@ public abstract class Content extends ForgeRegistryEntry<Content> implements ICo
//NO CATEGORY
RegistryHelper.register(event.getRegistry(), "potions", new ContentPotions());
RegistryHelper.register(event.getRegistry(), "command_stack", new ContentCommandStack());
RegistryHelper.register(event.getRegistry(), "butcher", new ContentButcher());
RegistryHelper.register(event.getRegistry(), "butcher_settings", new ContentButcherSettings());
RegistryHelper.register(event.getRegistry(), "settings", new ContentSettings());
@@ -130,14 +132,6 @@ public abstract class Content extends ForgeRegistryEntry<Content> implements ICo
this.persistence = new HashMap<String, Object>();
}
if(this.persistence.containsKey(id))
{
return (T) this.persistence.get(id);
}
T object = supplier.get();
this.persistence.put(id, object);
return object;
return (T) this.persistence.computeIfAbsent(id, key -> supplier.get());
}
}

View File

@@ -10,74 +10,39 @@ import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
public class Contents
{
public static final Content MAIN;
public static final Content CONTAINERS;
public static final Content MULTIPLAYER;
public static final Content MAIN = Contents.getRegisteredContent("main");
public static final Content CONTAINERS = Contents.getRegisteredContent("containers");
public static final Content MULTIPLAYER = Contents.getRegisteredContent("multiplayer");
public static final Content SUMMON;
public static final Content SUMMON = Contents.getRegisteredContent("summon");
public static final Content CUSTOM_ITEM;
public static final Content ENCHANTMENT;
public static final Content CUSTOM_ITEM = Contents.getRegisteredContent("custom_item");
public static final Content ENCHANTMENT = Contents.getRegisteredContent("enchantment");
public static final Content EDIT_BLOCKS;
public static final Content SIGN_EDITOR;
public static final Content NOTE_EDITOR;
public static final Content EDIT_BLOCKS = Contents.getRegisteredContent("edit_blocks");
public static final Content SIGN_EDITOR = Contents.getRegisteredContent("sign_editor");
public static final Content NOTE_EDITOR = Contents.getRegisteredContent("note_editor");
public static final Content WORLD_INFO;
public static final Content GAMERULES;
public static final Content RECIPES;
public static final Content WORLD_INFO = Contents.getRegisteredContent("world");
public static final Content GAMERULES = Contents.getRegisteredContent("gamerules");
public static final Content RECIPES = Contents.getRegisteredContent("recipes");
public static final Content PLAYER;
public static final Content EXPERIENCE;
public static final Content ADVANCEMENTS;
public static final Content PLAYER = Contents.getRegisteredContent("player");
public static final Content EXPERIENCE = Contents.getRegisteredContent("experience");
public static final Content ADVANCEMENTS = Contents.getRegisteredContent("advancements");
public static final Content SCOREBOARD_OBJECTIVES;
public static final Content SCOREBOARD_TEAMS;
public static final Content SCOREBOARD_PLAYERS;
public static final Content SCOREBOARD_OBJECTIVES = Contents.getRegisteredContent("scoreboard_objectives");
public static final Content SCOREBOARD_TEAMS = Contents.getRegisteredContent("scoreboard_teams");
public static final Content SCOREBOARD_PLAYERS = Contents.getRegisteredContent("scoreboard_players");
public static final ContentChild CHANGE_WORLD;
public static final ContentContinue CONTINUE;
public static final ContentChild CHANGE_WORLD = (ContentChild) Contents.getRegisteredContent("change_world");
public static final ContentContinue CONTINUE = (ContentContinue) Contents.getRegisteredContent("continue");
public static final ContentChild POTIONS;
public static final ContentChild BUTCHER;
public static final ContentChild BUTCHER_SETTINGS;
public static final ContentChild SETTINGS;
static
{
MAIN = Contents.getRegisteredContent("main");
CONTAINERS = Contents.getRegisteredContent("containers");
MULTIPLAYER = Contents.getRegisteredContent("multiplayer");
SUMMON = Contents.getRegisteredContent("summon");
CUSTOM_ITEM = Contents.getRegisteredContent("custom_item");
ENCHANTMENT = Contents.getRegisteredContent("enchantment");
EDIT_BLOCKS = Contents.getRegisteredContent("edit_blocks");
SIGN_EDITOR = Contents.getRegisteredContent("sign_editor");
NOTE_EDITOR = Contents.getRegisteredContent("note_editor");
WORLD_INFO = Contents.getRegisteredContent("world");
GAMERULES = Contents.getRegisteredContent("gamerules");
RECIPES = Contents.getRegisteredContent("recipes");
PLAYER = Contents.getRegisteredContent("player");
EXPERIENCE = Contents.getRegisteredContent("experience");
ADVANCEMENTS = Contents.getRegisteredContent("advancements");
SCOREBOARD_OBJECTIVES = Contents.getRegisteredContent("scoreboard_objectives");
SCOREBOARD_TEAMS = Contents.getRegisteredContent("scoreboard_teams");
SCOREBOARD_PLAYERS = Contents.getRegisteredContent("scoreboard_players");
CHANGE_WORLD = (ContentChild) Contents.getRegisteredContent("change_world");
CONTINUE = (ContentContinue) Contents.getRegisteredContent("continue");
POTIONS = (ContentChild) Contents.getRegisteredContent("potions");
BUTCHER = (ContentChild) Contents.getRegisteredContent("butcher");
BUTCHER_SETTINGS = (ContentChild) Contents.getRegisteredContent("butcher_settings");
SETTINGS = (ContentChild) Contents.getRegisteredContent("settings");
}
public static final ContentChild POTIONS = (ContentChild) Contents.getRegisteredContent("potions");
public static final ContentChild COMMAND_STACK = (ContentChild) Contents.getRegisteredContent("command_stack");
public static final Content BUTCHER = Contents.getRegisteredContent("butcher");
public static final ContentChild BUTCHER_SETTINGS = (ContentChild) Contents.getRegisteredContent("butcher_settings");
public static final ContentChild SETTINGS = (ContentChild) Contents.getRegisteredContent("settings");
public static Content getRegisteredContent(String name)
{

View File

@@ -5,8 +5,11 @@ import exopandora.worldhandler.builder.impl.BuilderButcher;
import exopandora.worldhandler.config.Config;
import exopandora.worldhandler.gui.button.GuiButtonBase;
import exopandora.worldhandler.gui.button.GuiTextFieldTooltip;
import exopandora.worldhandler.gui.category.Categories;
import exopandora.worldhandler.gui.category.Category;
import exopandora.worldhandler.gui.container.Container;
import exopandora.worldhandler.gui.container.impl.GuiWorldHandler;
import exopandora.worldhandler.gui.content.Content;
import exopandora.worldhandler.gui.content.Contents;
import exopandora.worldhandler.util.ActionHelper;
import exopandora.worldhandler.util.CommandHelper;
@@ -17,7 +20,7 @@ import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
public class ContentButcher extends ContentChild
public class ContentButcher extends Content
{
private GuiTextFieldTooltip radiusField;
private String radius;
@@ -109,9 +112,27 @@ public class ContentButcher extends ContentChild
this.radiusField.renderButton(mouseX, mouseY, partialTicks);
}
@Override
public Category getCategory()
{
return Categories.ENTITIES;
}
@Override
public String getTitle()
{
return I18n.format("gui.worldhandler.title.butcher");
return I18n.format("gui.worldhandler.title.entities.butcher");
}
@Override
public String getTabTitle()
{
return I18n.format("gui.worldhandler.tab.entities.butcher");
}
@Override
public Content getActiveContent()
{
return Contents.BUTCHER;
}
}

View File

@@ -0,0 +1,271 @@
package exopandora.worldhandler.gui.content.impl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
import com.google.common.base.Predicates;
import exopandora.worldhandler.builder.ICommandBuilder;
import exopandora.worldhandler.builder.component.impl.EntityNBT;
import exopandora.worldhandler.builder.impl.BuilderButcher;
import exopandora.worldhandler.builder.impl.BuilderFill;
import exopandora.worldhandler.builder.impl.BuilderSetBlock;
import exopandora.worldhandler.builder.impl.BuilderSetBlock.EnumMode;
import exopandora.worldhandler.builder.impl.BuilderSummon;
import exopandora.worldhandler.builder.types.BlockResourceLocation;
import exopandora.worldhandler.builder.types.Coordinate.EnumType;
import exopandora.worldhandler.builder.types.CoordinateDouble;
import exopandora.worldhandler.builder.types.CoordinateInt;
import exopandora.worldhandler.gui.button.EnumIcon;
import exopandora.worldhandler.gui.button.GuiButtonBase;
import exopandora.worldhandler.gui.button.GuiButtonIcon;
import exopandora.worldhandler.gui.button.GuiButtonTooltip;
import exopandora.worldhandler.gui.button.GuiTextFieldTooltip;
import exopandora.worldhandler.gui.container.Container;
import exopandora.worldhandler.util.ActionHelper;
import net.minecraft.block.Blocks;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.EntityType;
import net.minecraft.nbt.CompoundNBT;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
public class ContentCommandStack extends ContentChild
{
private static final int HEAD_LENGTH = 1;
private static final int TAIL_LENGTH = 2;
private final List<GuiTextFieldTooltip> textfields = new ArrayList<GuiTextFieldTooltip>();
private int scroll;
private GuiButtonBase buttonCopy;
private final BuilderSummon builderCommandStack = new BuilderSummon();
public ContentCommandStack()
{
this.builderCommandStack.setEntity(EntityType.FALLING_BLOCK.getRegistryName());
this.builderCommandStack.setX(new CoordinateDouble(0.0D, EnumType.GLOBAL));
this.builderCommandStack.setY(new CoordinateDouble(0.5D, EnumType.GLOBAL));
this.builderCommandStack.setZ(new CoordinateDouble(0.0D, EnumType.GLOBAL));
this.builderCommandStack.setMotion(0.0D, 0.315D, 0.0D);
this.builderCommandStack.setTime(1);
this.builderCommandStack.setBlockState(Blocks.ACTIVATOR_RAIL.getDefaultState());
EntityNBT redstoneBlock = new EntityNBT(EntityType.FALLING_BLOCK.getRegistryName());
redstoneBlock.setTime(1);
redstoneBlock.setBlockState(Blocks.REDSTONE_BLOCK.getDefaultState());
this.builderCommandStack.addPassenger(redstoneBlock);
this.addCommand(0);
EntityNBT blockRemover = new EntityNBT(EntityType.COMMAND_BLOCK_MINECART.getRegistryName());
BuilderSetBlock builder = new BuilderSetBlock(new CoordinateInt(EnumType.GLOBAL), new CoordinateInt(-2, EnumType.GLOBAL), new CoordinateInt(EnumType.GLOBAL), Blocks.REPEATING_COMMAND_BLOCK.getRegistryName(), EnumMode.DESTROY);
CompoundNBT commandBlock = new CompoundNBT();
commandBlock.putByte("auto", (byte) 1);
commandBlock.putString("Command", new BuilderFill(new CoordinateInt(EnumType.GLOBAL), new CoordinateInt(EnumType.GLOBAL), new CoordinateInt(EnumType.GLOBAL), new CoordinateInt(EnumType.GLOBAL), new CoordinateInt(2, EnumType.GLOBAL), new CoordinateInt(EnumType.GLOBAL), new BlockResourceLocation(Blocks.AIR.getRegistryName())).toActualCommand());
builder.setBlockNBT(commandBlock);
blockRemover.setCommand(builder.toActualCommand());
this.builderCommandStack.addPassenger(blockRemover);
EntityNBT entityRemover = new EntityNBT(EntityType.COMMAND_BLOCK_MINECART.getRegistryName());
entityRemover.setCommand(new BuilderButcher(EntityType.COMMAND_BLOCK_MINECART.getRegistryName(), 1).toActualCommand());
this.builderCommandStack.addPassenger(entityRemover);
}
@Override
public ICommandBuilder getCommandBuilder()
{
return this.builderCommandStack;
}
@Override
public void initGui(Container container, int x, int y)
{
this.textfields.clear();
for(int index = 0; index < 3; index++)
{
int command = index + this.scroll;
GuiTextFieldTooltip textfield = new GuiTextFieldTooltip(x, y + 24 * index, 232 - 48, 20, I18n.format("gui.worldhandler.command_stack.command_n", command + 1));
textfield.setValidator(Predicates.notNull());
textfield.setText(command < this.getCommandCount() ? this.getCommand(command) : null);
textfield.setResponder(text ->
{
this.setCommand(command, text);
this.updateCopyButton();
});
this.textfields.add(textfield);
}
}
@Override
public void initButtons(Container container, int x, int y)
{
GuiButtonBase buttonScrollUp;
GuiButtonBase buttonScrollDown;
container.add(new GuiButtonBase(x, y + 96, 114, 20, I18n.format("gui.worldhandler.generic.back"), () -> ActionHelper.back(this)));
container.add(new GuiButtonBase(x + 118, y + 96, 114, 20, I18n.format("gui.worldhandler.generic.backToGame"), ActionHelper::backToGame));
this.iterate(index ->
{
GuiButtonBase buttonUp;
GuiButtonBase buttonDown;
GuiButtonBase buttonRemove;
container.add(buttonUp = new GuiButtonIcon(x + 232 - 20 - 24, y + index * 24 - 1, 20, 10, EnumIcon.ARROW_UP, I18n.format("gui.worldhandler.actions.move_up"), () ->
{
this.swapCommands(index + this.scroll, index + this.scroll - 1);
container.init();
}));
container.add(buttonDown = new GuiButtonIcon(x + 232 - 20 - 24, y + index * 24 + 11, 20, 10, EnumIcon.ARROW_DOWN, I18n.format("gui.worldhandler.actions.move_down"), () ->
{
this.swapCommands(index + this.scroll, index + this.scroll + 1);
container.init();
}));
container.add(buttonRemove = new GuiButtonTooltip(x + 232 - 20, y + index * 24 - 1, 20, 10, "-", I18n.format("gui.worldhandler.command_stack.remove_command"), () ->
{
int pos = index + this.scroll;
this.removeCommand(pos);
if(this.scroll + 3 > this.getCommandCount())
{
this.scrollUp();
}
container.init();
}));
container.add(new GuiButtonTooltip(x + 232 - 20, y + index * 24 + 11, 20, 10, "+", I18n.format("gui.worldhandler.command_stack.insert_command"), () ->
{
int pos = index + this.scroll + 1;
this.addCommand(pos);
if(index == 2)
{
this.scrollDown();
}
container.init();
}));
container.add(this.textfields.get(index));
buttonRemove.active = this.getCommandCount() > 1;
buttonUp.active = index + this.scroll > 0;
buttonDown.active = index + this.scroll + 1 < this.getCommandCount();
});
container.add(this.buttonCopy = new GuiButtonBase(x, y + 72, 114, 20, I18n.format("gui.worldhandler.command_stack.copy_command"), () ->
{
Minecraft.getInstance().keyboardListener.setClipboardString(this.builderCommandStack.toActualCommand());
}));
container.add(buttonScrollUp = new GuiButtonIcon(x + 118, y + 72, 56, 20, EnumIcon.ARROW_UP, I18n.format("gui.worldhandler.actions.move_up"), () ->
{
this.scrollUp();
container.init();
}));
container.add(buttonScrollDown = new GuiButtonIcon(x + 118 + 60, y + 72, 54, 20, EnumIcon.ARROW_DOWN, I18n.format("gui.worldhandler.actions.move_down"), () ->
{
this.scrollDown();
container.init();
}));
this.updateCopyButton();
buttonScrollUp.active = this.scroll > 0;
buttonScrollDown.active = this.scroll < this.getCommandCount() - 3;
}
@Override
public void tick(Container container)
{
this.iterate(index ->
{
this.textfields.get(index).tick();
});
}
@Override
public void drawScreen(Container container, int x, int y, int mouseX, int mouseY, float partialTicks)
{
this.iterate(index ->
{
this.textfields.get(index).renderButton(mouseX, mouseY, partialTicks);
});
}
private void iterate(Consumer<Integer> consumer)
{
for(int x = 0; x < this.textfields.size() && x + this.scroll < this.getCommandCount(); x++)
{
consumer.accept(x);
}
}
private void scrollUp()
{
this.scroll = Math.max(0, this.scroll - (Screen.hasShiftDown() ? 10 : 1));
}
private void scrollDown()
{
this.scroll = Math.min(this.getCommandCount() - 3, this.scroll + (Screen.hasShiftDown() ? 10 : 1));
}
private void updateCopyButton()
{
boolean active = false;
for(int x = 0; x < this.getCommandCount() && !active; x++)
{
String command = this.getCommand(x);
if(command != null && !command.isEmpty())
{
active = true;
}
}
this.buttonCopy.active = active;
}
private void setCommand(int index, String command)
{
this.builderCommandStack.getPassenger(index + HEAD_LENGTH).setCommand(command);
}
private void addCommand(int index)
{
this.builderCommandStack.addPassenger(index + HEAD_LENGTH, new EntityNBT(EntityType.COMMAND_BLOCK_MINECART.getRegistryName()));
}
private void removeCommand(int index)
{
this.builderCommandStack.removePassenger(index + HEAD_LENGTH);
}
private String getCommand(int index)
{
return this.builderCommandStack.getPassenger(index + HEAD_LENGTH).getCommand();
}
private int getCommandCount()
{
return this.builderCommandStack.getPassengerCount() - HEAD_LENGTH - TAIL_LENGTH;
}
private void swapCommands(int i, int j)
{
Collections.swap(this.builderCommandStack.getPassengers(), i + HEAD_LENGTH, j + HEAD_LENGTH);
}
@Override
public String getTitle()
{
return I18n.format("gui.worldhandler.title.command_stack");
}
}

View File

@@ -40,14 +40,14 @@ public class ContentMain extends Content
container.add(new GuiButtonIcon(x, y + 24, 22, 20, EnumIcon.WEATHER_SUN, I18n.format("gui.worldhandler.shortcuts.tooltip.weather", I18n.format("gui.worldhandler.shortcuts.tooltip.weather.clear")), ActionHelper::weatherClear));
container.add(new GuiButtonIcon(x + 26, y + 24, 22, 20, EnumIcon.WEATHER_RAIN, I18n.format("gui.worldhandler.shortcuts.tooltip.weather", I18n.format("gui.worldhandler.shortcuts.tooltip.weather.rainy")), ActionHelper::weatherRain));
container.add(new GuiButtonIcon(x + 26 * 2, y + 24, 22, 20, EnumIcon.WEATHER_STORM, I18n.format("gui.worldhandler.shortcuts.tooltip.weather", I18n.format("gui.worldhandler.shortcuts.tooltip.weather.thunder")), ActionHelper::weatherThunder));
container.add(new GuiButtonIcon(x + 26 * 3, y + 24, 23, 20, EnumIcon.BUTCHER, I18n.format("gui.worldhandler.shortcuts.tooltip.butcher"), () ->
{
Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(Contents.BUTCHER.withParent(Contents.MAIN)));
}));
container.add(new GuiButtonIcon(x + 26 * 4, y + 24, 24, 20, EnumIcon.POTION, I18n.format("gui.worldhandler.shortcuts.tooltip.potions"), () ->
container.add(new GuiButtonIcon(x + 26 * 3, y + 24, 23, 20, EnumIcon.POTION, I18n.format("gui.worldhandler.shortcuts.tooltip.potions"), () ->
{
Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(Contents.POTIONS.withParent(Contents.MAIN)));
}));
container.add(new GuiButtonIcon(x + 26 * 4, y + 24, 24, 20, EnumIcon.COMMAND_STACK, I18n.format("gui.worldhandler.shortcuts.tooltip.command_stack"), () ->
{
Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(Contents.COMMAND_STACK.withParent(Contents.MAIN)));
}));
container.add(new GuiButtonIcon(x + 26 * 5 + 2, y + 24, 23, 20, EnumIcon.GAMEMODE_SURVIVAL, I18n.format("gui.worldhandler.shortcuts.tooltip.gamemode", I18n.format("gui.worldhandler.shortcuts.tooltip.gamemode.survival")), ActionHelper::gamemodeSurvival));
container.add(new GuiButtonIcon(x + 26 * 6 + 2, y + 24, 22, 20, EnumIcon.GAMEMODE_CREATIVE, I18n.format("gui.worldhandler.shortcuts.tooltip.gamemode", I18n.format("gui.worldhandler.shortcuts.tooltip.gamemode.creative")), ActionHelper::gamemodeCreative));
container.add(new GuiButtonIcon(x + 26 * 7 + 2, y + 24, 22, 20, EnumIcon.GAMEMODE_ADVENTURE, I18n.format("gui.worldhandler.shortcuts.tooltip.gamemode", I18n.format("gui.worldhandler.shortcuts.tooltip.gamemode.adventure")), ActionHelper::gamemodeAdventure));

View File

@@ -105,7 +105,7 @@ public class ContentSummon extends Content
this.mobField.setResponder(text ->
{
this.mob = text;
this.builderSummon.setEntity(this.mob);
this.builderSummon.setName(this.mob);
container.initButtons();
});
@@ -125,7 +125,7 @@ public class ContentSummon extends Content
this.passengerField.setResponder(text ->
{
this.passenger = this.passengerField.getText();
this.builderSummon.setPassenger(this.passenger);
this.builderSummon.setPassenger(0, this.passenger);
container.initButtons();
});

View File

@@ -0,0 +1,117 @@
package exopandora.worldhandler.util;
import java.util.Arrays;
import java.util.List;
import exopandora.worldhandler.builder.INBTWritable;
import exopandora.worldhandler.builder.component.IBuilderComponent;
import exopandora.worldhandler.builder.component.impl.EntityNBT;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.DoubleNBT;
import net.minecraft.nbt.INBT;
import net.minecraft.nbt.ListNBT;
import net.minecraft.nbt.NBTUtil;
import net.minecraft.nbt.StringNBT;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
public class NBTHelper
{
public static INBT serialize(BlockState blockState)
{
return blockState != null ? NBTUtil.writeBlockState(blockState) : null;
}
public static INBT serialize(double[] vector)
{
if(vector.length == 3 && (vector[0] != 0D || vector[1] != 0D || vector[2] != 0D))
{
ListNBT list = new ListNBT();
list.add(DoubleNBT.valueOf(vector[0]));
list.add(DoubleNBT.valueOf(vector[1]));
list.add(DoubleNBT.valueOf(vector[2]));
return list;
}
return null;
}
public static INBT serialize(ResourceLocation resource)
{
if(resource != null)
{
return StringNBT.valueOf(resource.toString());
}
return null;
}
public static INBT serialize(ResourceLocation[] itemArray)
{
if(Arrays.stream(itemArray).allMatch(resource -> Blocks.AIR.getRegistryName().equals(resource)))
{
return null;
}
ListNBT list = new ListNBT();
for(ResourceLocation item : itemArray)
{
CompoundNBT compound = new CompoundNBT();
compound.putString("id", item.toString());
compound.putInt("Count", 1);
list.add(compound);
}
return list;
}
public static INBT serialize(List<EntityNBT> entities)
{
ListNBT list = new ListNBT();
for(EntityNBT entity : entities)
{
INBT nbt = entity.serialize();
if(nbt != null)
{
list.add(nbt);
}
}
if(list.isEmpty())
{
return null;
}
return list;
}
public static void append(CompoundNBT compound, String tag, INBTWritable writable)
{
NBTHelper.append(compound, tag, writable.serialize());
}
public static void append(CompoundNBT compound, IBuilderComponent component)
{
NBTHelper.append(compound, component.getTag(), component.serialize());
}
public static void append(CompoundNBT compound, String tag, INBT nbt)
{
if(nbt != null)
{
if(!compound.contains(tag))
{
compound.put(tag, nbt);
}
}
}
}