diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiSpawningOptions.java b/src/main/java/noppes/npcs/client/gui/SubGuiSpawningOptions.java new file mode 100644 index 000000000..54728ec1a --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/SubGuiSpawningOptions.java @@ -0,0 +1,76 @@ +package noppes.npcs.client.gui; + +import net.minecraft.client.gui.GuiButton; +import noppes.npcs.client.gui.util.*; +import noppes.npcs.controllers.data.SpawnData; + +public class SubGuiSpawningOptions extends SubGuiInterface implements ITextfieldListener { + private SpawnData data; + + public SubGuiSpawningOptions(SpawnData data){ + this.data = data; + setBackground("menubg.png"); + xSize = 216; + ySize = 216; + closeOnEsc = true; + } + + public void initGui() { + super.initGui(); + int y = guiTop - 15; + + addButton(new GuiNpcButtonYesNo(10, guiLeft + 120, y += 22, data.animalSpawning)); + addLabel(new GuiNpcLabel(10, "spawning.animalSpawning", guiLeft + 4, y + 5)); + + addButton(new GuiNpcButtonYesNo(11, guiLeft + 120, y += 22, data.monsterSpawning)); + addLabel(new GuiNpcLabel(11, "spawning.monsterSpawning", guiLeft + 4, y + 5)); + + addButton(new GuiNpcButtonYesNo(12, guiLeft + 120, y += 22, data.liquidSpawning)); + addLabel(new GuiNpcLabel(12, "spawning.liquidSpawning", guiLeft + 4, y + 5)); + + addButton(new GuiNpcButtonYesNo(13, guiLeft + 120, y += 22, data.airSpawning)); + addLabel(new GuiNpcLabel(13, "spawning.airSpawning", guiLeft + 4, y + 5)); + + addTextField(new GuiNpcTextField(14, this, guiLeft + 120, y += 22, 40, 20, String.valueOf(data.spawnHeightMin))); + addLabel(new GuiNpcLabel(14, "spawning.minHeight", guiLeft + 4, y + 5)); + addTextField(new GuiNpcTextField(15, this, guiLeft + 120, y += 22, 40, 20, String.valueOf(data.spawnHeightMax))); + addLabel(new GuiNpcLabel(15, "spawning.maxHeight", guiLeft + 4, y + 5)); + getTextField(14).integersOnly = true; + getTextField(14).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + getTextField(15).integersOnly = true; + getTextField(15).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + + addButton(new GuiNpcButton(100, guiLeft + 154, guiTop + 192, 60, 20, "gui.done")); + } + + @Override + protected void actionPerformed(GuiButton guibutton) { + GuiNpcButton button = (GuiNpcButton) guibutton; + + if (button.id == 10) { + data.animalSpawning = button.getValue() == 1; + } + if (button.id == 11) { + data.monsterSpawning = button.getValue() == 1; + } + if (button.id == 12) { + data.liquidSpawning = button.getValue() == 1; + } + if (button.id == 13) { + data.airSpawning = button.getValue() == 1; + } + if (button.id == 100) { + close(); + } + } + + @Override + public void unFocused(GuiNpcTextField textfield) { + if (textfield.id == 14) { + data.spawnHeightMin = textfield.getInteger(); + } + if (textfield.id == 15) { + data.spawnHeightMax = textfield.getInteger(); + } + } +} diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNpcNaturalSpawns.java b/src/main/java/noppes/npcs/client/gui/global/GuiNpcNaturalSpawns.java index 6865e1a2d..2d52bd8d0 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNpcNaturalSpawns.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNpcNaturalSpawns.java @@ -9,6 +9,7 @@ import net.minecraft.util.StatCollector; import noppes.npcs.client.Client; import noppes.npcs.client.gui.GuiNpcMobSpawnerSelector; import noppes.npcs.client.gui.SubGuiNpcBiomes; +import noppes.npcs.client.gui.SubGuiSpawningOptions; import noppes.npcs.client.gui.util.GuiCustomScroll; import noppes.npcs.client.gui.util.GuiNPCInterface2; import noppes.npcs.client.gui.util.GuiNpcButton; @@ -31,6 +32,7 @@ public class GuiNpcNaturalSpawns extends GuiNPCInterface2 implements IGuiData, I private HashMap data = new HashMap(); private SpawnData spawn = new SpawnData(); + private int slotSelected; public GuiNpcNaturalSpawns(EntityNPCInterface npc) { super(npc); @@ -60,15 +62,34 @@ public class GuiNpcNaturalSpawns extends GuiNPCInterface2 implements IGuiData, I addLabel(new GuiNpcLabel(1,"gui.title", guiLeft + 4, guiTop + 8)); addTextField(new GuiNpcTextField(1, this, this.fontRendererObj, guiLeft + 60, guiTop + 3, 140, 20, spawn.name)); - addLabel(new GuiNpcLabel(3,"spawning.biomes", guiLeft + 4, guiTop + 30)); - addButton(new GuiNpcButton(3, guiLeft + 120, guiTop + 25, 50, 20, "selectServer.edit")); + int y = guiTop + 30; + addLabel(new GuiNpcLabel(3,"spawning.biomes", guiLeft + 4, y)); + addButton(new GuiNpcButton(3, guiLeft + 120, y - 5, 50, 20, "selectServer.edit")); - addSlider(new GuiNpcSlider(this, 4, guiLeft + 4, guiTop + 47, 180, 20, (float)spawn.itemWeight / 100)); + addLabel(new GuiNpcLabel(4,"spawning.options", guiLeft + 4, y += 22)); + addButton(new GuiNpcButton(4, guiLeft + 120, y - 5, 50, 20, "selectServer.edit")); - int y = guiTop + 70; - this.addButton(new GuiNpcButton(25, guiLeft + 14, y,20,20, "X")); - addLabel(new GuiNpcLabel(5, "1:", guiLeft + 4, y + 5)); - this.addButton(new GuiNpcButton(5, guiLeft + 36, y, 170, 20, getTitle(spawn.compound1))); + addSlider(new GuiNpcSlider(this, 5, guiLeft + 4, y += 17, 180, 20, (float)spawn.itemWeight / 100)); + + this.addButton(new GuiNpcButton(25, guiLeft + 14, y += 23,20,20, "X")); + addLabel(new GuiNpcLabel(6, "1:", guiLeft + 4, y + 5)); + this.addButton(new GuiNpcButton(6, guiLeft + 36, y, 170, 20, getTitle(spawn.compound1))); + + this.addButton(new GuiNpcButton(26, guiLeft + 14, y += 22,20,20, "X")); + addLabel(new GuiNpcLabel(7, "2:", guiLeft + 4, y + 5)); + this.addButton(new GuiNpcButton(7, guiLeft + 36, y, 170, 20, getTitle(spawn.compound2))); + + this.addButton(new GuiNpcButton(27, guiLeft + 14, y += 22,20,20, "X")); + addLabel(new GuiNpcLabel(8, "3:", guiLeft + 4, y + 5)); + this.addButton(new GuiNpcButton(8, guiLeft + 36, y, 170, 20, getTitle(spawn.compound3))); + + this.addButton(new GuiNpcButton(28, guiLeft + 14, y += 22,20,20, "X")); + addLabel(new GuiNpcLabel(9, "4:", guiLeft + 4, y + 5)); + this.addButton(new GuiNpcButton(9, guiLeft + 36, y, 170, 20, getTitle(spawn.compound4))); + + this.addButton(new GuiNpcButton(29, guiLeft + 14, y += 22,20,20, "X")); + addLabel(new GuiNpcLabel(10, "5:", guiLeft + 4, y + 5)); + this.addButton(new GuiNpcButton(10, guiLeft + 36, y, 170, 20, getTitle(spawn.compound5))); } private String getTitle(NBTTagCompound compound) { if(compound != null && compound.hasKey("ClonedName")) @@ -101,13 +122,35 @@ public class GuiNpcNaturalSpawns extends GuiNPCInterface2 implements IGuiData, I if(id == 3){ setSubGui(new SubGuiNpcBiomes(spawn)); } - if(id == 5){ + if(id == 4){ + setSubGui(new SubGuiSpawningOptions(spawn)); + } + + if(id >= 6 && id <= 10){ + slotSelected = id - 5; setSubGui(new GuiNpcMobSpawnerSelector()); } + if(id == 25){ spawn.compound1 = new NBTTagCompound(); initGui(); } + if(id == 26){ + spawn.compound2 = new NBTTagCompound(); + initGui(); + } + if(id == 27){ + spawn.compound3 = new NBTTagCompound(); + initGui(); + } + if(id == 28){ + spawn.compound4 = new NBTTagCompound(); + initGui(); + } + if(id == 29){ + spawn.compound5 = new NBTTagCompound(); + initGui(); + } } @@ -164,8 +207,25 @@ public class GuiNpcNaturalSpawns extends GuiNPCInterface2 implements IGuiData, I if(gui instanceof GuiNpcMobSpawnerSelector){ GuiNpcMobSpawnerSelector selector = (GuiNpcMobSpawnerSelector) gui; NBTTagCompound compound = selector.getCompound(); - if(compound != null) - spawn.compound1 = compound; + if (compound != null) { + switch (slotSelected) { + case 1: + spawn.compound1 = compound; + break; + case 2: + spawn.compound2 = compound; + break; + case 3: + spawn.compound3 = compound; + break; + case 4: + spawn.compound4 = compound; + break; + case 5: + spawn.compound5 = compound; + break; + } + } initGui(); } } diff --git a/src/main/java/noppes/npcs/controllers/data/SpawnData.java b/src/main/java/noppes/npcs/controllers/data/SpawnData.java index f377b83db..b1728404e 100644 --- a/src/main/java/noppes/npcs/controllers/data/SpawnData.java +++ b/src/main/java/noppes/npcs/controllers/data/SpawnData.java @@ -21,6 +21,10 @@ public class SpawnData extends WeightedRandom.Item implements INaturalSpawn { public int id = -1; public String name = ""; public NBTTagCompound compound1 = new NBTTagCompound(); + public NBTTagCompound compound2 = new NBTTagCompound(); + public NBTTagCompound compound3 = new NBTTagCompound(); + public NBTTagCompound compound4 = new NBTTagCompound(); + public NBTTagCompound compound5 = new NBTTagCompound(); public boolean animalSpawning = true; public boolean monsterSpawning = false; @@ -43,6 +47,10 @@ public class SpawnData extends WeightedRandom.Item implements INaturalSpawn { biomes = NBTTags.getStringList(compound.getTagList("SpawnBiomes", 10)); compound1 = compound.getCompoundTag("SpawnCompound1"); + compound2 = compound.getCompoundTag("SpawnCompound2"); + compound3 = compound.getCompoundTag("SpawnCompound3"); + compound4 = compound.getCompoundTag("SpawnCompound4"); + compound5 = compound.getCompoundTag("SpawnCompound5"); animalSpawning = compound.getBoolean("AnimalSpawning"); monsterSpawning = compound.getBoolean("MonsterSpawning"); @@ -64,6 +72,10 @@ public class SpawnData extends WeightedRandom.Item implements INaturalSpawn { compound.setTag("SpawnBiomes", NBTTags.nbtStringList(biomes)); compound.setTag("SpawnCompound1", compound1); + compound.setTag("SpawnCompound2", compound2); + compound.setTag("SpawnCompound3", compound3); + compound.setTag("SpawnCompound4", compound4); + compound.setTag("SpawnCompound5", compound5); compound.setBoolean("AnimalSpawning", animalSpawning); compound.setBoolean("MonsterSpawning", monsterSpawning); @@ -85,19 +97,68 @@ public class SpawnData extends WeightedRandom.Item implements INaturalSpawn { return this.name; } - public void setEntity(IEntity entity) { + public void setEntity(IEntity entity, int slot) { + if (slot < 1) + slot = 1; + if (slot > 5) + slot = 5; + NBTTagCompound compound = new NBTTagCompound(); if (!entity.getMCEntity().writeToNBTOptional(compound)) { throw new CustomNPCsException("Entity could not be written to NBT"); } else { - ServerCloneController.Instance.cleanTags(compound1); - compound1 = compound; + switch (slot) { + case 1: + ServerCloneController.Instance.cleanTags(compound1); + compound1 = compound; + break; + case 2: + ServerCloneController.Instance.cleanTags(compound2); + compound2 = compound; + break; + case 3: + ServerCloneController.Instance.cleanTags(compound3); + compound3 = compound; + break; + case 4: + ServerCloneController.Instance.cleanTags(compound4); + compound4 = compound; + break; + case 5: + ServerCloneController.Instance.cleanTags(compound5); + compound5 = compound; + break; + } } } - public IEntity getEntity(IWorld world) { + public IEntity getEntity(IWorld world, int slot) { + if (slot < 1) + slot = 1; + if (slot > 5) + slot = 5; + try { - Entity entity = EntityList.createEntityFromNBT(compound1, world.getMCWorld()); + NBTTagCompound compound = new NBTTagCompound(); + switch (slot) { + case 1: + compound = compound1; + break; + case 2: + compound = compound2; + break; + case 3: + compound = compound3; + break; + case 4: + compound = compound4; + break; + case 5: + compound = compound5; + break; + } + + Entity entity = EntityList.createEntityFromNBT(compound, world.getMCWorld()); return NpcAPI.Instance().getIEntity(entity); } catch (Exception e) { throw new CustomNPCsException("Error creating entity from spawn data:\n" + e.getMessage()); diff --git a/src/main/java/noppes/npcs/scripted/interfaces/handler/data/INaturalSpawn.java b/src/main/java/noppes/npcs/scripted/interfaces/handler/data/INaturalSpawn.java index f770f79dc..a37bef35b 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/handler/data/INaturalSpawn.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/handler/data/INaturalSpawn.java @@ -9,9 +9,9 @@ public interface INaturalSpawn { String getName(); - void setEntity(IEntity entity); + void setEntity(IEntity entity, int slot); - IEntity getEntity(IWorld world); + IEntity getEntity(IWorld world, int slot); void setWeight(int weight); diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index a1258798a..dffd4684b 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -230,6 +230,13 @@ spawning.availableBiomes=Available Biomes spawning.spawningBiomes=Spawning Biomes spawning.biomes=Biomes spawning.weightedChance=Weighted Chance +spawning.options=Spawning Options +spawning.animalSpawning=Spawns Like Animal +spawning.monsterSpawning=Spawns Like Monster +spawning.liquidSpawning=Spawns in Liquid +spawning.airSpawning=Spawns in Air +spawning.minHeight=Minimum Height +spawning.maxHeight=Maximum Height role.name=Role role.none=No Role