Search in sources :

Example 1 with AbstractBuildingView

use of com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView in project minecolonies by Minecolonies.

the class GuiHandler method getClientGuiElement.

@Override
public Object getClientGuiElement(final int id, final EntityPlayer player, final World world, final int x, final int y, final int z) {
    if (id == ID.DEFAULT.ordinal()) {
        final BlockPos pos = new BlockPos(x, y, z);
        final TileEntity tileEntity = world.getTileEntity(pos);
        if (tileEntity instanceof ScarecrowTileEntity) {
            return new GuiField(player.inventory, (ScarecrowTileEntity) tileEntity, world, pos);
        } else if (tileEntity instanceof TileEntityRack) {
            return new GuiRack(player.inventory, (TileEntityRack) tileEntity, ((TileEntityRack) tileEntity).getOtherChest(), world, pos);
        } else {
            @Nullable final AbstractBuildingView building = ColonyManager.getBuildingView(new BlockPos(x, y, z));
            if (building instanceof AbstractBuildingWorker.View) {
                return new WindowGuiCrafting(player.inventory, world, (AbstractBuildingWorker.View) building);
            }
        }
    } else if (id == ID.BUILDING_INVENTORY.ordinal()) {
        final TileEntity entity = world.getTileEntity(new BlockPos(x, y, z));
        if (entity instanceof TileEntityColonyBuilding) {
            final TileEntityColonyBuilding tileEntityColonyBuilding = (TileEntityColonyBuilding) entity;
            return new GuiChest(player.inventory, tileEntityColonyBuilding);
        }
    } else if (id == ID.CITIZEN_INVENTORY.ordinal()) {
        final ColonyView view = ColonyManager.getColonyView(x);
        final CitizenDataView citizenDataView = view.getCitizen(y);
        return new GuiChest(player.inventory, citizenDataView.getInventory());
    }
    return null;
}
Also used : TileEntityColonyBuilding(com.minecolonies.coremod.tileentities.TileEntityColonyBuilding) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) AbstractBuildingView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView) TileEntity(net.minecraft.tileentity.TileEntity) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) AbstractBuildingView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView) TileEntityRack(com.minecolonies.coremod.tileentities.TileEntityRack) AbstractBuildingWorker(com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker) WindowGuiCrafting(com.minecolonies.coremod.client.gui.WindowGuiCrafting) BlockPos(net.minecraft.util.math.BlockPos) GuiChest(net.minecraft.client.gui.inventory.GuiChest)

Example 2 with AbstractBuildingView

use of com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView in project minecolonies by Minecolonies.

the class AbstractBuilding method createBuildingView.

/**
 * Create a AbstractBuilding View given it's saved NBTTagCompound.
 *
 * @param colony The owning colony.
 * @param id     Chunk coordinate of the block a view is created for.
 * @param buf    The network data.
 * @return {@link AbstractBuildingView} created from reading the buf.
 */
@Nullable
public static AbstractBuildingView createBuildingView(final ColonyView colony, final BlockPos id, @NotNull final ByteBuf buf) {
    @Nullable AbstractBuildingView view = null;
    @Nullable Class<?> oclass = null;
    try {
        final int typeHash = buf.readInt();
        oclass = classNameHashToViewClassMap.get(typeHash);
        if (oclass != null) {
            final Constructor<?> constructor = oclass.getDeclaredConstructor(ColonyView.class, BlockPos.class);
            view = (AbstractBuildingView) constructor.newInstance(colony, id);
        }
    } catch (@NotNull NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException exception) {
        Log.getLogger().error(exception);
    }
    if (view == null) {
        Log.getLogger().warn("Unknown AbstractBuilding type, missing View subclass, or missing constructor of proper format.");
        return null;
    }
    try {
        view.deserialize(buf);
    } catch (final IndexOutOfBoundsException ex) {
        Log.getLogger().error(String.format("A AbstractBuilding View (%s) has thrown an exception during deserializing, its state cannot be restored. Report this to the mod author", oclass.getName()), ex);
        return null;
    }
    return view;
}
Also used : AbstractBuildingView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView) Nullable(org.jetbrains.annotations.Nullable) InvocationTargetException(java.lang.reflect.InvocationTargetException) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with AbstractBuildingView

use of com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView in project minecolonies by Minecolonies.

the class AbstractWindowBuilding method onUpdate.

@Override
public void onUpdate() {
    super.onUpdate();
    // Or that we are on the correct page
    if (switchView == null || switchView.getCurrentView().getID().equals(PAGE_ACTIONS)) {
        final AbstractBuildingView buildingView = building.getColony().getBuilding(building.getID());
        if (buttonPrevPage != null) {
            buttonPrevPage.disable();
            buttonPrevPage.hide();
        }
        if (title != null) {
            title.setLabelText(LanguageHandler.format(getBuildingName()) + " " + buildingView.getBuildingLevel());
        }
        updateButtonBuild(buildingView);
        updateButtonRepair(buildingView);
    }
}
Also used : AbstractBuildingView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView)

Example 4 with AbstractBuildingView

use of com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView in project minecolonies by Minecolonies.

the class WindowCitizen method getOpenRequestsOfCitizenFromBuilding.

@SuppressWarnings(RAWTYPES)
private ImmutableList<IRequest> getOpenRequestsOfCitizenFromBuilding(final BlockPos buildingPos) {
    final ColonyView colonyView = ColonyManager.getClosestColonyView(FMLClientHandler.instance().getWorldClient(), buildingPos);
    if (colonyView == null) {
        return ImmutableList.of();
    }
    final AbstractBuildingView building = colonyView.getBuilding(buildingPos);
    if (building == null) {
        return ImmutableList.of();
    }
    return building.getOpenRequests(citizen);
}
Also used : AbstractBuildingView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView) ColonyView(com.minecolonies.coremod.colony.ColonyView)

Example 5 with AbstractBuildingView

use of com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView in project minecolonies by Minecolonies.

the class WindowHutBuilder method pullResourcesFromHut.

/**
 * Retrieve resources from the building to display in GUI.
 */
private void pullResourcesFromHut() {
    final AbstractBuildingView newView = builder.getColony().getBuilding(builder.getID());
    if (newView instanceof BuildingBuilderView) {
        final BuildingBuilderView updatedView = (BuildingBuilderView) newView;
        final InventoryPlayer inventory = this.mc.player.inventory;
        final boolean isCreative = this.mc.player.capabilities.isCreativeMode;
        resources.clear();
        resources.addAll(updatedView.getResources().values());
        for (final BuildingBuilderResource resource : resources) {
            final int amountToSet;
            if (isCreative) {
                amountToSet = resource.getAmount();
            } else {
                amountToSet = InventoryUtils.getItemCountInItemHandler(new InvWrapper(inventory), stack -> !ItemStackUtils.isEmpty(stack) && stack.isItemEqual(resource.getItemStack()));
            }
            resource.setPlayerAmount(amountToSet);
        }
        resources.sort(new BuildingBuilderResource.ResourceComparator());
    }
}
Also used : AbstractBuildingView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView) BuildingBuilderView(com.minecolonies.coremod.colony.buildings.views.BuildingBuilderView) TransferItemsRequestMessage(com.minecolonies.coremod.network.messages.TransferItemsRequestMessage) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) SwitchView(com.minecolonies.blockout.views.SwitchView) Button(com.minecolonies.blockout.controls.Button) Pane(com.minecolonies.blockout.Pane) InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) ItemIcon(com.minecolonies.blockout.controls.ItemIcon) ScrollingList(com.minecolonies.blockout.views.ScrollingList) Color(com.minecolonies.blockout.Color) ArrayList(java.util.ArrayList) AbstractBuildingView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView) ItemStack(net.minecraft.item.ItemStack) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) List(java.util.List) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) WindowConstants(com.minecolonies.api.util.constant.WindowConstants) MineColonies(com.minecolonies.coremod.MineColonies) InventoryUtils(com.minecolonies.api.util.InventoryUtils) MarkBuildingDirtyMessage(com.minecolonies.coremod.network.messages.MarkBuildingDirtyMessage) Label(com.minecolonies.blockout.controls.Label) Log(com.minecolonies.api.util.Log) NotNull(org.jetbrains.annotations.NotNull) Constants(com.minecolonies.api.util.constant.Constants) InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) BuildingBuilderView(com.minecolonies.coremod.colony.buildings.views.BuildingBuilderView)

Aggregations

AbstractBuildingView (com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView)5 InventoryUtils (com.minecolonies.api.util.InventoryUtils)1 ItemStackUtils (com.minecolonies.api.util.ItemStackUtils)1 Log (com.minecolonies.api.util.Log)1 Constants (com.minecolonies.api.util.constant.Constants)1 WindowConstants (com.minecolonies.api.util.constant.WindowConstants)1 Color (com.minecolonies.blockout.Color)1 Pane (com.minecolonies.blockout.Pane)1 Button (com.minecolonies.blockout.controls.Button)1 ItemIcon (com.minecolonies.blockout.controls.ItemIcon)1 Label (com.minecolonies.blockout.controls.Label)1 ScrollingList (com.minecolonies.blockout.views.ScrollingList)1 SwitchView (com.minecolonies.blockout.views.SwitchView)1 MineColonies (com.minecolonies.coremod.MineColonies)1 WindowGuiCrafting (com.minecolonies.coremod.client.gui.WindowGuiCrafting)1 ColonyView (com.minecolonies.coremod.colony.ColonyView)1 AbstractBuildingWorker (com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker)1 BuildingBuilderResource (com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource)1 BuildingBuilderView (com.minecolonies.coremod.colony.buildings.views.BuildingBuilderView)1 MarkBuildingDirtyMessage (com.minecolonies.coremod.network.messages.MarkBuildingDirtyMessage)1