Search in sources :

Example 1 with SettingKey

use of com.minecolonies.coremod.colony.buildings.modules.settings.SettingKey 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");
        }
    }
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) CompoundNBT(net.minecraft.nbt.CompoundNBT) ResourceLocation(net.minecraft.util.ResourceLocation) ISetting(com.minecolonies.api.colony.buildings.modules.settings.ISetting) SettingKey(com.minecolonies.coremod.colony.buildings.modules.settings.SettingKey) ISettingKey(com.minecolonies.api.colony.buildings.modules.settings.ISettingKey)

Example 2 with SettingKey

use of com.minecolonies.coremod.colony.buildings.modules.settings.SettingKey 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");
        }
    }
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) CompoundNBT(net.minecraft.nbt.CompoundNBT) ResourceLocation(net.minecraft.util.ResourceLocation) ISetting(com.minecolonies.api.colony.buildings.modules.settings.ISetting) SettingKey(com.minecolonies.coremod.colony.buildings.modules.settings.SettingKey) ISettingKey(com.minecolonies.api.colony.buildings.modules.settings.ISettingKey)

Aggregations

ISetting (com.minecolonies.api.colony.buildings.modules.settings.ISetting)2 ISettingKey (com.minecolonies.api.colony.buildings.modules.settings.ISettingKey)2 SettingKey (com.minecolonies.coremod.colony.buildings.modules.settings.SettingKey)2 CompoundNBT (net.minecraft.nbt.CompoundNBT)2 ListNBT (net.minecraft.nbt.ListNBT)2 ResourceLocation (net.minecraft.util.ResourceLocation)2