-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSpawnerConfig.java
More file actions
150 lines (118 loc) · 7.82 KB
/
SpawnerConfig.java
File metadata and controls
150 lines (118 loc) · 7.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package ladysnake.spawnercontrol.config;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import ladysnake.spawnercontrol.SpawnerControl;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.config.Config;
import java.util.Arrays;
import java.util.List;
public class SpawnerConfig {
@Config.Comment("Regroups config options aiming to alter mob spawners spawning conditions")
public SpawnConditions spawnConditions = new SpawnConditions();
@Config.Comment("Groups config options related to custom drops from mobs spawned by this spawner type")
public MobLoot mobLoot = new MobLoot();
@Config.Comment("When a spawner has spawned this number of mobs over this lifetime, it will get broken automatically")
public int mobThreshold = 100;
@Config.Comment("While this number of mobs from this spawner are alive, it will pause spawning")
public int aliveMobThreshold = 100;
@Config.Comment("Pause spawning if too many spawned mobs are alive")
public boolean pauseIfTooManyAlive = false;
@Config.Comment("If set to true, spawners will count mobs when they are killed rather than when they are spawned")
public boolean incrementOnMobDeath = false;
@Config.Comment("This multiplier is applied on the spawner's spawn delay each time a mob is spawned. \nCan be used to make mobs spawned exponentially faster or slower.")
public float spawnRateModifier = 1.0f;
@Config.Comment("If set to false, spawners will only be disabled when expired, not broken")
public boolean breakSpawner = true;
@Config.Comment("The minimum amount of xp dropped by a spawner when broken")
public int xpDropped = 15;
@Config.RangeInt(min = 0)
@Config.Comment("The formula used to calculate xp dropped is 'xpDropped + rand(this number) + rand(this number)'")
public int randXpVariation = 15;
@Config.Comment({"A list of item ids that a mob spawner drops when broken", "Format: 'modid:item(:count(:meta(:chance)))' (count, meta and chance are optional)"})
public String[] itemsDropped = new String[0];
public static class SpawnConditions {
@Config.Comment({"If set to true, spawners will not run mob-specific checks on any entity"})
public boolean forceSpawnerAllSpawns = false;
@Config.Comment({"If set to true, spawners will not run mob-specific checks on hostile mob entities", "This most notably prevents players from disabling a spawner with torches or other light sources"})
public boolean forceSpawnerMobSpawns = false;
@Config.Comment("If forceSpawnerMobSpawns is enabled, will prevent hostile mobs from spawning in daylight")
public boolean checkSunlight = true;
}
public static class MobLoot {
public MobLootEntry defaultValues = new MobLootEntry(1, 0, false, new String[0], new String[0]);
@Config.Comment({"Individual xp drop multiplier configuration for mobs spawned by this spawner type", "Format: 'modid:entity:xpMultiplier(:flatXp)' (flatXp is optional)"})
public String[] xpMultipliers = new String[0];
@Config.Comment({"Individual item drop removal configuration for mobs spawned by this spawner type", "Format: 'modid:entity(,modid:item(:meta))(,modid:item(:meta))...'", "Anything in parenthesis is optional, and you can enter as many items as you want", "If don't enter any items, all item drops are removed from the mob (itemDropAdditions are added afterwards)"})
public String[] itemDropRemovals = new String[0];
@Config.Comment({"Individual item drop addition configuration for mobs spawned by this spawner type", "Format: 'modid:entity,modid:item(:count(:meta(:chance)))(,modid:item(:count(:meta(:chance))))...'", "Anything in parenthesis is optional, and you can enter as many items as you want", "Eg: minecraft:skeleton,minecraft:dye:100:15:0.5,minecraft:bone:1:1:1"})
public String[] itemDropAdditions = new String[0];
@Config.Ignore
public LoadingCache<ResourceLocation, MobLootEntry> lootEntries = CacheBuilder.newBuilder().build(CacheLoader.from(rl -> {
if (rl == null) return defaultValues;
float xpMultiplier = defaultValues.xpMultiplier;
int flatXpIncrease = defaultValues.flatXpIncrease;
boolean removeAllItems = defaultValues.removeAllItems;
List<String> removedItems = Arrays.asList(defaultValues.removedItems);
List<String> addedItems = Arrays.asList(defaultValues.addedItems);
for (String s : xpMultipliers) {
String[] split = s.split(":");
if (split[0].equals(rl.getPath()) && split[1].equals(rl.getNamespace())) {
try {
xpMultiplier = Float.parseFloat(split[2]);
flatXpIncrease = split.length > 3 ? Integer.parseInt(split[3]) : defaultValues.flatXpIncrease;
} catch (NumberFormatException e) {
SpawnerControl.LOGGER.warn("Bad mob spawner loot config option : {}", s);
}
break;
}
}
for (String s : itemDropRemovals) {
String[] split = s.split(",");
String[] mobSplit = split[0].split(":");
if (mobSplit[0].equals(rl.getPath()) && mobSplit[1].equals(rl.getNamespace())) {
try {
removedItems = Arrays.asList(split);
removedItems.remove(0);
removeAllItems = removedItems.size() == 0;
} catch (Exception e) {
SpawnerControl.LOGGER.warn("Bad mob spawner loot config option : {}", s);
}
break;
}
}
for (String s : itemDropAdditions) {
String[] split = s.split(":");
if (split[0].equals(rl.getPath()) && split[1].equals(rl.getNamespace())) {
try {
addedItems = Arrays.asList(split);
addedItems.remove(0);
} catch (Exception e) {
SpawnerControl.LOGGER.warn("Bad mob spawner loot config option : {}", s);
}
break;
}
}
return new MobLootEntry(xpMultiplier, flatXpIncrease, removeAllItems, removedItems.toArray(new String[0]), addedItems.toArray(new String[0]));
}));
public static class MobLootEntry {
public MobLootEntry(float defaultXpMultiplier, int flatXpIncrease, boolean removeAllItems, String[] removedItems, String[] addedItems) {
this.xpMultiplier = defaultXpMultiplier;
this.flatXpIncrease = flatXpIncrease;
this.removeAllItems = removeAllItems;
this.removedItems = removedItems;
this.addedItems = addedItems;
}
@Config.Comment("xp drop multiplier for mobs spawned by this spawner type")
public float xpMultiplier;
@Config.Comment("Flat xp modifier that will be added to mobs spawned by this spawner type")
public int flatXpIncrease;
@Config.Comment({"Remove all existing item drops from the mobs spawned by this spawner", "'Added Items' are added afterwards"})
public boolean removeAllItems;
@Config.Comment({"Which items to remove from the drops of the mobs spawned", "Format: 'modid:item(:meta)' (meta is optional)", "If 'Remove All Items' is true, this does nothing"})
public String[] removedItems;
@Config.Comment({"Which items to add to the drops of the mobs spawned", "Format: 'modid:item(:count(:meta(:chance)))' (count, meta and chance are optional)"})
public String[] addedItems;
}
}
}