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;
}
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;
}
Aggregations