Search in sources :

Example 1 with ISetting

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");
        }
    }
}
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 ISetting

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);
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) CompoundNBT(net.minecraft.nbt.CompoundNBT) ISettingKey(com.minecolonies.api.colony.buildings.modules.settings.ISettingKey) ISetting(com.minecolonies.api.colony.buildings.modules.settings.ISetting) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 3 with ISetting

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);
    }
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) ISetting(com.minecolonies.api.colony.buildings.modules.settings.ISetting)

Example 4 with ISetting

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");
        }
    }
}
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 5 with ISetting

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));
}
Also used : TriggerSettingMessage(com.minecolonies.coremod.network.messages.server.colony.building.TriggerSettingMessage) ISetting(com.minecolonies.api.colony.buildings.modules.settings.ISetting)

Aggregations

ISetting (com.minecolonies.api.colony.buildings.modules.settings.ISetting)8 ISettingKey (com.minecolonies.api.colony.buildings.modules.settings.ISettingKey)4 CompoundNBT (net.minecraft.nbt.CompoundNBT)4 ListNBT (net.minecraft.nbt.ListNBT)4 ResourceLocation (net.minecraft.util.ResourceLocation)4 SettingKey (com.minecolonies.coremod.colony.buildings.modules.settings.SettingKey)2 TriggerSettingMessage (com.minecolonies.coremod.network.messages.server.colony.building.TriggerSettingMessage)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2