Search in sources :

Example 1 with ISettingKey

use of com.minecolonies.api.colony.buildings.modules.settings.ISettingKey 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 ISettingKey

use of com.minecolonies.api.colony.buildings.modules.settings.ISettingKey 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 ISettingKey

use of com.minecolonies.api.colony.buildings.modules.settings.ISettingKey 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 4 with ISettingKey

use of com.minecolonies.api.colony.buildings.modules.settings.ISettingKey in project minecolonies by Minecolonies.

the class GuardTaskSetting method render.

@Override
public void render(final ISettingKey<?> key, final Pane pane, final ISettingsModuleView settingsModuleView, final IBuildingView building, final Window window) {
    final String setting = getSettings().get(getCurrentIndex());
    final ButtonImage targetButton = pane.findPaneOfTypeByID("setTarget", ButtonImage.class);
    final Text mineLabel = pane.findPaneOfTypeByID("minePos", Text.class);
    if (setting.equals(PATROL_MINE) && building instanceof AbstractBuildingGuards.View) {
        mineLabel.setVisible(true);
        if (((AbstractBuildingGuards.View) building).getMinePos() != null) {
            mineLabel.setText(new TranslationTextComponent("com.minecolonies.coremod.gui.worherhuts.patrollingmine", ((AbstractBuildingGuards.View) building).getMinePos().toShortString()));
        } else {
            mineLabel.setText(new TranslationTextComponent("com.minecolonies.coremod.job.guard.assignmine"));
        }
        targetButton.setVisible(false);
    } else if (!setting.equals(FOLLOW)) {
        mineLabel.setVisible(false);
        targetButton.setVisible(true);
        if (setting.equals(PATROL)) {
            if (!settingsModuleView.getSetting(AbstractBuildingGuards.PATROL_MODE).getValue().equals(PatrolModeSetting.MANUAL)) {
                targetButton.setVisible(false);
            } else {
                targetButton.setText(new TranslationTextComponent("com.minecolonies.coremod.gui.workerhuts.targetpatrol"));
            }
        } else {
            targetButton.setText(new TranslationTextComponent("com.minecolonies.coremod.gui.workerhuts.targetguard"));
        }
        targetButton.setHandler(button -> building.getModuleView(ToolModuleView.class).getWindow().open());
    } else {
        mineLabel.setVisible(false);
        targetButton.setVisible(false);
    }
    pane.findPaneOfTypeByID("trigger", ButtonImage.class).setText(new TranslationTextComponent(setting));
}
Also used : ISettingsModuleView(com.minecolonies.api.colony.buildings.modules.settings.ISettingsModuleView) Window(com.ldtteam.blockout.views.Window) AbstractBuildingGuards(com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) ISettingKey(com.minecolonies.api.colony.buildings.modules.settings.ISettingKey) Pane(com.ldtteam.blockout.Pane) View(com.ldtteam.blockout.views.View) Text(com.ldtteam.blockout.controls.Text) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) Dist(net.minecraftforge.api.distmarker.Dist) Loader(com.ldtteam.blockout.Loader) List(java.util.List) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) ButtonImage(com.ldtteam.blockout.controls.ButtonImage) ToolModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.ToolModuleView) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) AbstractBuildingGuards(com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards) ButtonImage(com.ldtteam.blockout.controls.ButtonImage) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) Text(com.ldtteam.blockout.controls.Text)

Example 5 with ISettingKey

use of com.minecolonies.api.colony.buildings.modules.settings.ISettingKey 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)

Aggregations

ISettingKey (com.minecolonies.api.colony.buildings.modules.settings.ISettingKey)6 ISetting (com.minecolonies.api.colony.buildings.modules.settings.ISetting)4 CompoundNBT (net.minecraft.nbt.CompoundNBT)4 ListNBT (net.minecraft.nbt.ListNBT)4 Loader (com.ldtteam.blockout.Loader)2 Pane (com.ldtteam.blockout.Pane)2 ButtonImage (com.ldtteam.blockout.controls.ButtonImage)2 Text (com.ldtteam.blockout.controls.Text)2 View (com.ldtteam.blockout.views.View)2 Window (com.ldtteam.blockout.views.Window)2 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)2 ISettingsModuleView (com.minecolonies.api.colony.buildings.modules.settings.ISettingsModuleView)2 IBuildingView (com.minecolonies.api.colony.buildings.views.IBuildingView)2 AbstractBuildingGuards (com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards)2 SettingKey (com.minecolonies.coremod.colony.buildings.modules.settings.SettingKey)2 ToolModuleView (com.minecolonies.coremod.colony.buildings.moduleviews.ToolModuleView)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2