Search in sources :

Example 1 with OpenInventoryMessage

use of com.minecolonies.coremod.network.messages.server.colony.OpenInventoryMessage in project minecolonies by Minecolonies.

the class EntityCitizen method checkAndHandleImportantInteractions.

/**
 * Called when a player tries to interact with a citizen.
 *
 * @param player which interacts with the citizen.
 * @return If citizen should interact or not.
 */
@NotNull
@Override
public ActionResultType checkAndHandleImportantInteractions(final PlayerEntity player, @NotNull final Hand hand) {
    final IColonyView iColonyView = IColonyManager.getInstance().getColonyView(citizenColonyHandler.getColonyId(), player.level.dimension());
    if (iColonyView != null && !iColonyView.getPermissions().hasPermission(player, Action.ACCESS_HUTS)) {
        return ActionResultType.FAIL;
    }
    if (!ItemStackUtils.isEmpty(player.getItemInHand(hand)) && player.getItemInHand(hand).getItem() instanceof NameTagItem) {
        return super.checkAndHandleImportantInteractions(player, hand);
    }
    final ActionResultType result = directPlayerInteraction(player, hand);
    if (result != null) {
        return result;
    }
    if (CompatibilityUtils.getWorldFromCitizen(this).isClientSide && iColonyView != null) {
        if (player.isShiftKeyDown() && !isInvisible()) {
            Network.getNetwork().sendToServer(new OpenInventoryMessage(iColonyView, this.getName().getString(), this.getId()));
        } else {
            final ICitizenDataView citizenDataView = getCitizenDataView();
            if (citizenDataView != null && !isInvisible()) {
                MineColonies.proxy.showCitizenWindow(citizenDataView);
            }
        }
    }
    return ActionResultType.SUCCESS;
}
Also used : OpenInventoryMessage(com.minecolonies.coremod.network.messages.server.colony.OpenInventoryMessage) NameTagItem(net.minecraft.item.NameTagItem) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with OpenInventoryMessage

use of com.minecolonies.coremod.network.messages.server.colony.OpenInventoryMessage in project minecolonies by Minecolonies.

the class VisitorCitizen method checkAndHandleImportantInteractions.

/**
 * Called when a player tries to interact with a citizen.
 *
 * @param player which interacts with the citizen.
 * @return If citizen should interact or not.
 */
@Override
public ActionResultType checkAndHandleImportantInteractions(final PlayerEntity player, @NotNull final Hand hand) {
    final IColonyView iColonyView = IColonyManager.getInstance().getColonyView(citizenColonyHandler.getColonyId(), player.level.dimension());
    if (iColonyView != null && !iColonyView.getPermissions().hasPermission(player, Action.ACCESS_HUTS)) {
        return ActionResultType.FAIL;
    }
    if (!ItemStackUtils.isEmpty(player.getItemInHand(hand)) && player.getItemInHand(hand).getItem() instanceof NameTagItem) {
        return super.checkAndHandleImportantInteractions(player, hand);
    }
    final ActionResultType result = directPlayerInteraction(player, hand);
    if (result != null) {
        return result;
    }
    if (CompatibilityUtils.getWorldFromCitizen(this).isClientSide) {
        if (player.isShiftKeyDown()) {
            Network.getNetwork().sendToServer(new OpenInventoryMessage(iColonyView, this.getName().getString(), this.getId()));
        } else {
            final ICitizenDataView citizenDataView = getCitizenDataView();
            if (citizenDataView != null) {
                MineColonies.proxy.showCitizenWindow(citizenDataView);
            }
        }
    }
    return ActionResultType.SUCCESS;
}
Also used : ActionResultType(net.minecraft.util.ActionResultType) OpenInventoryMessage(com.minecolonies.coremod.network.messages.server.colony.OpenInventoryMessage) NameTagItem(net.minecraft.item.NameTagItem)

Aggregations

OpenInventoryMessage (com.minecolonies.coremod.network.messages.server.colony.OpenInventoryMessage)2 NameTagItem (net.minecraft.item.NameTagItem)2 ActionResultType (net.minecraft.util.ActionResultType)1 NotNull (org.jetbrains.annotations.NotNull)1