use of com.minecolonies.api.colony.buildings.modules.settings.ISetting in project minecolonies by Minecolonies.
the class SettingsModule method deserializeNBT.
@Override
public void deserializeNBT(final CompoundNBT compound) {
final CompoundNBT settingsCompound = compound.getCompound("settings");
final ListNBT list = settingsCompound.getList("settingslist", Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < list.size(); i++) {
final CompoundNBT entryCompound = list.getCompound(i);
final ResourceLocation key = new ResourceLocation(entryCompound.getString("key"));
try {
final ISetting setting = StandardFactoryController.getInstance().deserialize(entryCompound.getCompound("value"));
final ISettingKey<?> settingsKey = new SettingKey<>(setting.getClass(), key);
if (settings.containsKey(settingsKey)) {
settings.put(settingsKey, setting);
}
} catch (final IllegalArgumentException ex) {
Log.getLogger().warn("Detected Removed Setting");
}
}
}
use of com.minecolonies.api.colony.buildings.modules.settings.ISetting in project minecolonies by Minecolonies.
the class SettingsModule method serializeNBT.
@Override
public void serializeNBT(final CompoundNBT compound) {
final CompoundNBT settingsCompound = new CompoundNBT();
final ListNBT list = new ListNBT();
for (final Map.Entry<ISettingKey<?>, ISetting> setting : settings.entrySet()) {
final CompoundNBT entryCompound = new CompoundNBT();
entryCompound.putString("key", setting.getKey().getUniqueId().toString());
entryCompound.put("value", StandardFactoryController.getInstance().serialize(setting.getValue()));
list.add(entryCompound);
}
settingsCompound.put("settingslist", list);
compound.put("settings", settingsCompound);
}
use of com.minecolonies.api.colony.buildings.modules.settings.ISetting in project minecolonies by Minecolonies.
the class SettingsModuleView method deserialize.
@Override
public void deserialize(@NotNull final PacketBuffer buf) {
settings.clear();
final int size = buf.readInt();
for (int i = 0; i < size; i++) {
final ResourceLocation key = buf.readResourceLocation();
final ISetting setting = StandardFactoryController.getInstance().deserialize(buf);
settings.put(new SettingKey<>(setting.getClass(), key), setting);
}
}
use of com.minecolonies.api.colony.buildings.modules.settings.ISetting in project minecolonies by ldtteam.
the class SettingsModule method deserializeNBT.
@Override
public void deserializeNBT(final CompoundNBT compound) {
final CompoundNBT settingsCompound = compound.getCompound("settings");
final ListNBT list = settingsCompound.getList("settingslist", Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < list.size(); i++) {
final CompoundNBT entryCompound = list.getCompound(i);
final ResourceLocation key = new ResourceLocation(entryCompound.getString("key"));
try {
final ISetting setting = StandardFactoryController.getInstance().deserialize(entryCompound.getCompound("value"));
final ISettingKey<?> settingsKey = new SettingKey<>(setting.getClass(), key);
if (settings.containsKey(settingsKey)) {
settings.put(settingsKey, setting);
}
} catch (final IllegalArgumentException ex) {
Log.getLogger().warn("Detected Removed Setting");
}
}
}
use of com.minecolonies.api.colony.buildings.modules.settings.ISetting in project minecolonies by Minecolonies.
the class SettingsModuleView method trigger.
@Override
public void trigger(final ISettingKey<?> key) {
final ISetting setting = settings.get(key);
setting.trigger();
Network.getNetwork().sendToServer(new TriggerSettingMessage(buildingView, key, setting));
}
Aggregations