Search in sources :

Example 21 with IBuildingView

use of com.minecolonies.api.colony.buildings.views.IBuildingView 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 22 with IBuildingView

use of com.minecolonies.api.colony.buildings.views.IBuildingView in project minecolonies by Minecolonies.

the class BuildingDataManager method createViewFrom.

@Override
public IBuildingView createViewFrom(final IColonyView colony, final BlockPos position, final PacketBuffer networkBuffer) {
    final ResourceLocation buildingName = new ResourceLocation(networkBuffer.readUtf(32767));
    final BuildingEntry entry = IBuildingRegistry.getInstance().getValue(buildingName);
    if (entry == null) {
        Log.getLogger().error(String.format("Unknown building type '%s'.", buildingName), new Exception());
        return null;
    }
    final IBuildingView view = entry.produceBuildingView(position, colony);
    if (view != null) {
        view.deserialize(networkBuffer);
    }
    return view;
}
Also used : BuildingEntry(com.minecolonies.api.colony.buildings.registry.BuildingEntry) ResourceLocation(net.minecraft.util.ResourceLocation) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView)

Example 23 with IBuildingView

use of com.minecolonies.api.colony.buildings.views.IBuildingView in project minecolonies by ldtteam.

the class AbstractBlockHut method use.

@NotNull
@Override
public ActionResultType use(final BlockState state, final World worldIn, final BlockPos pos, final PlayerEntity player, final Hand hand, final BlockRayTraceResult ray) {
    /*
        If the world is client, open the gui of the building
         */
    if (worldIn.isClientSide) {
        @Nullable final IBuildingView building = IColonyManager.getInstance().getBuildingView(worldIn.dimension(), pos);
        if (building == null) {
            LanguageHandler.sendPlayerMessage(player, "com.minecolonies.coremod.gui.nobuilding");
            return ActionResultType.FAIL;
        }
        if (building.getColony() == null) {
            LanguageHandler.sendPlayerMessage(player, "com.minecolonies.coremod.gui.nocolony");
            return ActionResultType.FAIL;
        }
        if (!building.getColony().getPermissions().hasPermission(player, Action.ACCESS_HUTS)) {
            LanguageHandler.sendPlayerMessage(player, "com.minecolonies.coremod.permission.no");
            return ActionResultType.FAIL;
        }
        building.openGui(player.isShiftKeyDown());
    }
    return ActionResultType.SUCCESS;
}
Also used : IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull)

Example 24 with IBuildingView

use of com.minecolonies.api.colony.buildings.views.IBuildingView in project minecolonies by ldtteam.

the class CitizenWindowUtils method updateJobPage.

/**
 * Update the job page of the citizen.
 *
 * @param citizen       the citizen.
 * @param windowCitizen the window.
 * @param colony        the colony.
 */
public static void updateJobPage(final ICitizenDataView citizen, final JobWindowCitizen windowCitizen, final IColonyView colony) {
    final IBuildingView building = colony.getBuilding(citizen.getWorkBuilding());
    if (building instanceof AbstractBuildingView && building.getBuildingType() != ModBuildings.library && citizen.getJobView() != null) {
        final WorkerBuildingModuleView moduleView = building.getModuleViewMatching(WorkerBuildingModuleView.class, m -> m.getJobEntry() == citizen.getJobView().getEntry());
        if (moduleView == null) {
            return;
        }
        windowCitizen.findPaneOfTypeByID(JOB_TITLE_LABEL, Text.class).setText(LanguageHandler.format("com.minecolonies.coremod.gui.citizen.job.label", LanguageHandler.format(citizen.getJob())));
        windowCitizen.findPaneOfTypeByID(JOB_DESC_LABEL, Text.class).setText(LanguageHandler.format("com.minecolonies.coremod.gui.citizen.job.desc"));
        final Skill primary = moduleView.getPrimarySkill();
        windowCitizen.findPaneOfTypeByID(PRIMARY_SKILL_LABEL, Text.class).setText(LanguageHandler.format("com.minecolonies.coremod.gui.citizen.job.skills." + primary.name().toLowerCase(Locale.US)) + " (100% XP)");
        windowCitizen.findPaneOfTypeByID(PRIMARY_SKILL_LABEL + IMAGE_APPENDIX, Image.class).setImage(BASE_IMG_SRC + primary.name().toLowerCase(Locale.US) + ".png");
        if (primary.getComplimentary() != null && primary.getAdverse() != null) {
            windowCitizen.findPaneOfTypeByID(PRIMARY_SKILL_COM, Text.class).setText(LanguageHandler.format("com.minecolonies.coremod.gui.citizen.job.skills." + primary.getComplimentary().name().toLowerCase(Locale.US)) + " (" + PRIMARY_DEPENDENCY_SHARE + "% XP)");
            windowCitizen.findPaneOfTypeByID(PRIMARY_SKILL_COM + IMAGE_APPENDIX, Image.class).setImage(BASE_IMG_SRC + primary.getComplimentary().name().toLowerCase(Locale.US) + ".png");
            windowCitizen.findPaneOfTypeByID(PRIMARY_SKILL_ADV, Text.class).setText(LanguageHandler.format("com.minecolonies.coremod.gui.citizen.job.skills." + primary.getAdverse().name().toLowerCase(Locale.US)) + " (-" + PRIMARY_DEPENDENCY_SHARE + "% XP)");
            windowCitizen.findPaneOfTypeByID(PRIMARY_SKILL_ADV + IMAGE_APPENDIX, Image.class).setImage(BASE_IMG_SRC + primary.getAdverse().name().toLowerCase(Locale.US) + ".png");
        }
        final Skill secondary = moduleView.getSecondarySkill();
        windowCitizen.findPaneOfTypeByID(SECONDARY_SKILL_LABEL, Text.class).setText(LanguageHandler.format("com.minecolonies.coremod.gui.citizen.job.skills." + secondary.name().toLowerCase(Locale.US)) + " (50% XP)");
        windowCitizen.findPaneOfTypeByID(SECONDARY_SKILL_LABEL + IMAGE_APPENDIX, Image.class).setImage(BASE_IMG_SRC + secondary.name().toLowerCase(Locale.US) + ".png");
        if (secondary.getComplimentary() != null && secondary.getAdverse() != null) {
            windowCitizen.findPaneOfTypeByID(SECONDARY_SKILL_COM, Text.class).setText(LanguageHandler.format("com.minecolonies.coremod.gui.citizen.job.skills." + secondary.getComplimentary().name().toLowerCase(Locale.US)) + " (" + SECONDARY_DEPENDENCY_SHARE + "% XP)");
            windowCitizen.findPaneOfTypeByID(SECONDARY_SKILL_COM + IMAGE_APPENDIX, Image.class).setImage(BASE_IMG_SRC + secondary.getComplimentary().name().toLowerCase(Locale.US) + ".png");
            windowCitizen.findPaneOfTypeByID(SECONDARY_SKILL_ADV, Text.class).setText(LanguageHandler.format("com.minecolonies.coremod.gui.citizen.job.skills." + secondary.getAdverse().name().toLowerCase(Locale.US)) + " (-" + SECONDARY_DEPENDENCY_SHARE + "% XP)");
            windowCitizen.findPaneOfTypeByID(SECONDARY_SKILL_ADV + IMAGE_APPENDIX, Image.class).setImage(BASE_IMG_SRC + secondary.getAdverse().name().toLowerCase(Locale.US) + ".png");
        }
    } else {
        windowCitizen.findPaneOfTypeByID(PRIMARY_SKILL_LABEL + IMAGE_APPENDIX, Image.class).hide();
        windowCitizen.findPaneOfTypeByID(PRIMARY_SKILL_COM + IMAGE_APPENDIX, Image.class).hide();
        windowCitizen.findPaneOfTypeByID(PRIMARY_SKILL_ADV + IMAGE_APPENDIX, Image.class).hide();
        windowCitizen.findPaneOfTypeByID(SECONDARY_SKILL_LABEL + IMAGE_APPENDIX, Image.class).hide();
        windowCitizen.findPaneOfTypeByID(SECONDARY_SKILL_COM + IMAGE_APPENDIX, Image.class).hide();
        windowCitizen.findPaneOfTypeByID(SECONDARY_SKILL_ADV + IMAGE_APPENDIX, Image.class).hide();
    }
}
Also used : AbstractBuildingView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView) Skill(com.minecolonies.api.entity.citizen.Skill) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) Text(com.ldtteam.blockout.controls.Text) WorkerBuildingModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.WorkerBuildingModuleView) Image(com.ldtteam.blockout.controls.Image)

Example 25 with IBuildingView

use of com.minecolonies.api.colony.buildings.views.IBuildingView in project minecolonies by ldtteam.

the class ClientEventHandler method handleRenderScepterGuard.

/**
 * Renders the guard scepter objects into the world.
 *
 * @param event  The caught event
 * @param world  The world in which to render
 * @param player The player for which to render
 */
private static void handleRenderScepterGuard(@NotNull final RenderWorldLastEvent event, final ClientWorld world, final PlayerEntity player) {
    final PlacementSettings settings = new PlacementSettings(Settings.instance.getMirror(), BlockPosUtil.getRotationFromRotations(Settings.instance.getRotation()));
    final ItemStack stack = player.getMainHandItem();
    if (!stack.hasTag()) {
        return;
    }
    final CompoundNBT compound = stack.getTag();
    final IColonyView colony = IColonyManager.getInstance().getColonyView(compound.getInt(TAG_ID), player.level.dimension());
    if (colony == null) {
        return;
    }
    final BlockPos guardTower = BlockPosUtil.read(compound, TAG_POS);
    final IBuildingView hut = colony.getBuilding(guardTower);
    if (hut == null) {
        return;
    }
    if (partolPointTemplate == null) {
        partolPointTemplate = new LoadOnlyStructureHandler(world, hut.getPosition(), "schematics/infrastructure/patrolpoint", settings, true).getBluePrint();
    }
    if (hut instanceof AbstractBuildingGuards.View) {
        StructureClientHandler.renderStructureAtPosList(partolPointTemplate, event.getPartialTicks(), ((AbstractBuildingGuards.View) hut).getPatrolTargets().stream().map(BlockPos::above).collect(Collectors.toList()), event.getMatrixStack());
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) BlockPos(net.minecraft.util.math.BlockPos) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) ItemStack(net.minecraft.item.ItemStack) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) IColonyView(com.minecolonies.api.colony.IColonyView) IColonyView(com.minecolonies.api.colony.IColonyView) EmptyView(com.minecolonies.coremod.colony.buildings.views.EmptyView) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView)

Aggregations

IBuildingView (com.minecolonies.api.colony.buildings.views.IBuildingView)30 Pane (com.ldtteam.blockout.Pane)14 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)14 ScrollingList (com.ldtteam.blockout.views.ScrollingList)12 Text (com.ldtteam.blockout.controls.Text)10 IColonyView (com.minecolonies.api.colony.IColonyView)10 BlockPos (net.minecraft.util.math.BlockPos)10 Button (com.ldtteam.blockout.controls.Button)8 Nullable (org.jetbrains.annotations.Nullable)8 NotNull (org.jetbrains.annotations.NotNull)7 PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)6 ICitizenDataView (com.minecolonies.api.colony.ICitizenDataView)6 LoadOnlyStructureHandler (com.minecolonies.api.util.LoadOnlyStructureHandler)6 Constants (com.minecolonies.api.util.constant.Constants)6 Network (com.minecolonies.coremod.Network)6 AbstractBuildingGuards (com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards)6 AbstractBuildingView (com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView)6 List (java.util.List)6 ItemStack (net.minecraft.item.ItemStack)6 Image (com.ldtteam.blockout.controls.Image)4