Search in sources :

Example 6 with ISetting

use of com.minecolonies.api.colony.buildings.modules.settings.ISetting in project minecolonies by ldtteam.

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 7 with ISetting

use of com.minecolonies.api.colony.buildings.modules.settings.ISetting in project minecolonies by ldtteam.

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)

Example 8 with ISetting

use of com.minecolonies.api.colony.buildings.modules.settings.ISetting in project minecolonies by ldtteam.

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)

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