-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSpawnerConfigHolder.java
More file actions
80 lines (67 loc) · 2.64 KB
/
SpawnerConfigHolder.java
File metadata and controls
80 lines (67 loc) · 2.64 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
package ladysnake.spawnercontrol.config;
import ladysnake.spawnercontrol.SpawnerControl;
import ladysnake.spawnercontrol.controlledspawner.BlockControlledSpawner;
import ladysnake.spawnercontrol.controlledspawner.ItemBlockControlSpawner;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.config.ConfigCategory;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
public class SpawnerConfigHolder {
private Configuration configuration;
private String name;
private ResourceLocation registryName;
private SpawnerConfig configObject;
SpawnerConfigHolder(Configuration configuration, String name) {
this.configuration = configuration;
this.name = name;
// avoid errors that would be way too stupid
this.registryName = new ResourceLocation(SpawnerControl.MOD_ID, name.replaceAll(" ", "_"));
this.configObject = new SpawnerConfig();
}
public void sync() {
try {
// sync the object with the config
CustomSpawnersConfig.configManager$sync.invoke(configuration, SpawnerConfig.class, SpawnerControl.MOD_ID, name, true, configObject);
this.configObject.mobLoot.lootEntries.invalidateAll();
configuration.save();
} catch (Throwable throwable) {
SpawnerControl.LOGGER.error("Exception while synchronizing custom spawner config", throwable);
}
}
/**
*
* @return a new {@link BlockControlledSpawner} instance using this config holder and named accordingly
*/
public Block createBlock() {
return new BlockControlledSpawner(getConfigObject())
.setRegistryName(this.registryName)
.setTranslationKey("msc." + name)
.setCreativeTab(SpawnerControl.creativeTab);
}
public Item createItem() {
return new ItemBlockControlSpawner(getBlock(), getName()).setRegistryName(this.registryName);
}
public Block getBlock() {
return ForgeRegistries.BLOCKS.getValue(this.registryName);
}
public Item getItem() {
return ForgeRegistries.ITEMS.getValue(this.registryName);
}
public Configuration getConfiguration() {
return configuration;
}
public ConfigCategory getConfigCategory() {
return getConfiguration().getCategory(name);
}
public String getName() {
return name;
}
public ResourceLocation getRegistryName() {
return registryName;
}
public SpawnerConfig getConfigObject() {
return configObject;
}
}