Search in sources :

Example 1 with NameTagItem

use of net.minecraft.item.NameTagItem 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 NameTagItem

use of net.minecraft.item.NameTagItem 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)

Example 3 with NameTagItem

use of net.minecraft.item.NameTagItem in project ChocolateQuestRepoured by TeamChocoQuest.

the class AbstractEntityCQR method mobInteract.

@Override
protected ActionResultType mobInteract(PlayerEntity player, Hand hand) {
    if (player.getItemInHand(hand).getItem() instanceof NameTagItem) {
        return super.mobInteract(player, hand);
    }
    boolean flag = false;
    if (player instanceof ServerPlayerEntity) {
        ServerPlayerEntity spe = (ServerPlayerEntity) player;
        if (!player.isCrouching()) {
            if (player.isCreative() || this.getLeader() == player) {
                if (!this.level.isClientSide) {
                    // player.openGui(CQRMain.INSTANCE, GuiHandler.CQR_ENTITY_GUI_ID, this.level, this.getId(), 0, 0);
                    NetworkHooks.openGui(spe, new INamedContainerProvider() {

                        @Override
                        public Container createMenu(int windowId, PlayerInventory invPlayer, PlayerEntity lePlayer) {
                            PacketBuffer buf = new PacketBuffer(Unpooled.buffer(32));
                            buf.writeInt(AbstractEntityCQR.this.getId());
                            return CQRContainerTypes.CQR_ENTITY_EDITOR.get().create(windowId, invPlayer, buf);
                        }

                        @Override
                        public ITextComponent getDisplayName() {
                            return AbstractEntityCQR.this.getDisplayName();
                        }
                    });
                }
                flag = true;
            } else if (!this.getFaction().isEnemy(player) && this.hasTrades()) {
                if (!this.level.isClientSide) {
                    // player.openGui(CQRMain.INSTANCE, GuiHandler.MERCHANT_GUI_ID, this.level, this.getId(), 0, 0);
                    NetworkHooks.openGui(spe, new INamedContainerProvider() {

                        @Override
                        public Container createMenu(int windowId, PlayerInventory invPlayer, PlayerEntity lePlayer) {
                            return CQRContainerTypes.MERCHANT.get().create(windowId, invPlayer);
                        }

                        @Override
                        public ITextComponent getDisplayName() {
                            return AbstractEntityCQR.this.getDisplayName();
                        }
                    });
                }
                flag = true;
            }
        } else if (player.isCreative() || (!this.getFaction().isEnemy(player) && this.hasTrades())) {
            if (!this.level.isClientSide) {
                // player.openGui(CQRMain.INSTANCE, GuiHandler.MERCHANT_GUI_ID, this.level, this.getId(), 0, 0);
                NetworkHooks.openGui(spe, new INamedContainerProvider() {

                    @Override
                    public Container createMenu(int windowId, PlayerInventory invPlayer, PlayerEntity lePlayer) {
                        return CQRContainerTypes.MERCHANT.get().create(windowId, invPlayer);
                    }

                    @Override
                    public ITextComponent getDisplayName() {
                        return AbstractEntityCQR.this.getDisplayName();
                    }
                });
            }
            flag = true;
        }
    }
    if (flag && !this.getLookControl().isHasWanted() && !this.isPathFinding()) {
        double x1 = player.position().x() - this.position().x();
        double z1 = player.position().z() - this.position().z();
        float yaw = (float) Math.toDegrees(Math.atan2(-x1, z1));
        this.yBodyRot = yaw;
        this.yHeadRot = yaw;
        // Old 1.12.2
        // this.renderYawOffset = yaw;
        this.rotOffs = yaw;
    }
    return flag ? ActionResultType.SUCCESS : ActionResultType.PASS;
}
Also used : ITextComponent(net.minecraft.util.text.ITextComponent) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) INamedContainerProvider(net.minecraft.inventory.container.INamedContainerProvider) PlayerInventory(net.minecraft.entity.player.PlayerInventory) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Container(net.minecraft.inventory.container.Container) IHasTextureOverride(team.cqr.cqrepoured.customtextures.IHasTextureOverride) NameTagItem(net.minecraft.item.NameTagItem) PacketBuffer(net.minecraft.network.PacketBuffer) IHasTextureOverride(team.cqr.cqrepoured.customtextures.IHasTextureOverride)

Aggregations

NameTagItem (net.minecraft.item.NameTagItem)3 OpenInventoryMessage (com.minecolonies.coremod.network.messages.server.colony.OpenInventoryMessage)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 PlayerInventory (net.minecraft.entity.player.PlayerInventory)1 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1 Container (net.minecraft.inventory.container.Container)1 INamedContainerProvider (net.minecraft.inventory.container.INamedContainerProvider)1 PacketBuffer (net.minecraft.network.PacketBuffer)1 ActionResultType (net.minecraft.util.ActionResultType)1 ITextComponent (net.minecraft.util.text.ITextComponent)1 NotNull (org.jetbrains.annotations.NotNull)1 IHasTextureOverride (team.cqr.cqrepoured.customtextures.IHasTextureOverride)1