Search in sources :

Example 1 with GemSocketItem

use of hellfirepvp.astralsorcery.common.perk.node.socket.GemSocketItem in project AstralSorcery by HellFirePvP.

the class ScreenJournalPerkTree method drawSocketContextMenu.

private <T extends AbstractPerk & GemSocketPerk> void drawSocketContextMenu(MatrixStack renderStack) {
    this.rSocketMenu = null;
    this.slotsSocketMenu.clear();
    if (socketMenu != null) {
        T sMenuPerk = (T) socketMenu;
        Map<Integer, ItemStack> found = ItemUtils.findItemsIndexedInPlayerInventory(Minecraft.getInstance().player, stack -> {
            if (stack.isEmpty() || !(stack.getItem() instanceof GemSocketItem)) {
                return false;
            }
            GemSocketItem item = (GemSocketItem) stack.getItem();
            return item.canBeInserted(stack, sMenuPerk, Minecraft.getInstance().player, ResearchHelper.getClientProgress(), LogicalSide.CLIENT);
        });
        if (found.isEmpty()) {
            // Close then.
            closeSocketMenu();
            return;
        }
        Point.Float offset = this.sizeHandler.scalePointToGui(this, this.mousePosition, sMenuPerk.getPoint().getOffset());
        float offsetX = MathHelper.floor(offset.x);
        float offsetY = MathHelper.floor(offset.y);
        float scale = this.sizeHandler.getScalingFactor();
        float scaledSlotSize = 18F * scale;
        int realWidth = Math.min(5, found.size());
        int realHeight = (found.size() / 5 + (found.size() % 5 == 0 ? 0 : 1));
        float width = realWidth * scaledSlotSize;
        float height = realHeight * scaledSlotSize;
        this.rSocketMenu = new Rectangle.Float(offsetX + (12 * scale) - 4, offsetY - (12 * scale) - 4, width + 4, height + 4);
        if (!this.guiBox.isInBox(rSocketMenu.x - guiLeft, rSocketMenu.y - guiTop) || !this.guiBox.isInBox(rSocketMenu.x + rSocketMenu.width - guiLeft, rSocketMenu.y + rSocketMenu.height - guiTop)) {
            closeSocketMenu();
            return;
        }
        renderStack.push();
        renderStack.translate(offsetX, offsetY, getGuiZLevel());
        renderStack.scale(scale, scale, 1F);
        RenderingDrawUtils.renderBlueTooltipBox(renderStack, 0, 0, realWidth * 18, realHeight * 18);
        renderStack.pop();
        float inventoryOffsetX = offsetX + 12 * scale;
        float inventoryOffsetY = offsetY - 12 * scale;
        RenderSystem.enableBlend();
        RenderSystem.defaultBlendFunc();
        TexturesAS.TEX_GUI_MENU_SLOT_GEM_CONTEXT.bindTexture();
        RenderingUtils.draw(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR_TEX, buf -> {
            for (int index = 0; index < found.size(); index++) {
                float addedX = (index % 5) * scaledSlotSize;
                float addedY = (index / 5) * scaledSlotSize;
                RenderingGuiUtils.rect(buf, renderStack, inventoryOffsetX + addedX, inventoryOffsetY + addedY, this.getGuiZLevel(), scaledSlotSize, scaledSlotSize).draw();
            }
        });
        RenderSystem.disableBlend();
        offsetX += 12 * scale;
        offsetY -= 12 * scale;
        int index = 0;
        for (Integer slotId : found.keySet()) {
            ItemStack stack = found.get(slotId);
            float addedX = (index % 5) * scaledSlotSize;
            float addedY = (index / 5) * scaledSlotSize;
            Rectangle.Float r = new Rectangle.Float(offsetX + addedX, offsetY + addedY, scaledSlotSize, scaledSlotSize);
            renderStack.push();
            renderStack.translate(offsetX + addedX + 1, offsetY + addedY + 1, getGuiZLevel());
            renderStack.scale(scale, scale, 1F);
            RenderingUtils.renderItemStackGUI(renderStack, stack, null);
            renderStack.pop();
            slotsSocketMenu.put(r, slotId);
            index++;
        }
    }
}
Also used : GemSocketItem(hellfirepvp.astralsorcery.common.perk.node.socket.GemSocketItem) ScalingPoint(hellfirepvp.astralsorcery.client.screen.helper.ScalingPoint) PerkTreePoint(hellfirepvp.astralsorcery.common.perk.tree.PerkTreePoint) ItemStack(net.minecraft.item.ItemStack) ScalingPoint(hellfirepvp.astralsorcery.client.screen.helper.ScalingPoint) PerkTreePoint(hellfirepvp.astralsorcery.common.perk.tree.PerkTreePoint)

Example 2 with GemSocketItem

use of hellfirepvp.astralsorcery.common.perk.node.socket.GemSocketItem in project AstralSorcery by HellFirePvP.

the class PktPerkGemModification method tryInsertPerk.

private <T extends AbstractPerk & GemSocketPerk> void tryInsertPerk(AbstractPerk perk, PlayerEntity player, PktPerkGemModification packet) {
    PlayerProgress prog = ResearchHelper.getProgress(player, LogicalSide.SERVER);
    if (!prog.isValid()) {
        return;
    }
    T socketPerk = (T) perk;
    ItemStack stack = player.inventory.getStackInSlot(packet.slotId);
    if (stack.isEmpty()) {
        return;
    }
    ItemStack toInsert = ItemUtils.copyStackWithSize(stack, 1);
    if (!toInsert.isEmpty() && toInsert.getItem() instanceof GemSocketItem) {
        GemSocketItem socketItem = (GemSocketItem) toInsert.getItem();
        if (socketItem.canBeInserted(toInsert, socketPerk, player, prog, LogicalSide.SERVER) && !socketPerk.hasItem(player, LogicalSide.SERVER) && socketPerk.setContainedItem(player, LogicalSide.SERVER, toInsert)) {
            player.inventory.setInventorySlotContents(packet.slotId, ItemUtils.copyStackWithSize(stack, stack.getCount() - 1));
        }
    }
}
Also used : GemSocketItem(hellfirepvp.astralsorcery.common.perk.node.socket.GemSocketItem) ItemStack(net.minecraft.item.ItemStack) PlayerProgress(hellfirepvp.astralsorcery.common.data.research.PlayerProgress)

Example 3 with GemSocketItem

use of hellfirepvp.astralsorcery.common.perk.node.socket.GemSocketItem in project AstralSorcery by HellFirePvP.

the class ScreenJournalPerkTree method tryInsertGem.

private <T extends AbstractPerk & GemSocketPerk> boolean tryInsertGem(int slotId, GemSocketPerk perk) {
    if (!(perk instanceof AbstractPerk)) {
        return false;
    }
    T socketPerk = (T) perk;
    ItemStack potentialStack = minecraft.player.inventory.getStackInSlot(slotId);
    if (!potentialStack.isEmpty() && potentialStack.getItem() instanceof GemSocketItem) {
        GemSocketItem gemItem = (GemSocketItem) potentialStack.getItem();
        if (gemItem.canBeInserted(potentialStack, socketPerk, minecraft.player, ResearchHelper.getClientProgress(), LogicalSide.CLIENT)) {
            PktPerkGemModification pkt = PktPerkGemModification.insertItem(socketPerk, slotId);
            PacketChannel.CHANNEL.sendToServer(pkt);
            closeSocketMenu();
            SoundHelper.playSoundClient(SoundEvents.BLOCK_GLASS_PLACE, .35F, 9f);
            return true;
        }
    }
    return false;
}
Also used : GemSocketItem(hellfirepvp.astralsorcery.common.perk.node.socket.GemSocketItem) ItemStack(net.minecraft.item.ItemStack) PktPerkGemModification(hellfirepvp.astralsorcery.common.network.play.client.PktPerkGemModification)

Aggregations

GemSocketItem (hellfirepvp.astralsorcery.common.perk.node.socket.GemSocketItem)3 ItemStack (net.minecraft.item.ItemStack)3 ScalingPoint (hellfirepvp.astralsorcery.client.screen.helper.ScalingPoint)1 PlayerProgress (hellfirepvp.astralsorcery.common.data.research.PlayerProgress)1 PktPerkGemModification (hellfirepvp.astralsorcery.common.network.play.client.PktPerkGemModification)1 PerkTreePoint (hellfirepvp.astralsorcery.common.perk.tree.PerkTreePoint)1