Как получить EntityPlayerMP в gui

Версия Minecraft
1.7.10
API
Forge
55
7
3
В gui по нажатию кнопки должен вызываться метод forceMorph из мода Morph, но он требует EntityPlayerMP. Как его можно получить?
Проблема в том, что я могу получить только EntityClientPlayer а он не преобразуется

Java:
protected void actionPerformed(GuiButton button) {
    super.actionPerformed(button);
    if (button.id == morphButton.id) {
        Api.forceMorph(<<СЮДА>>, new EntityCreeper(null));
    }
}

В интернете я ничего не нашёл

p.s. это гуи предмета а не блока!

Gui:
/**
 * File created on 14:13 22.09.2024 by Wertyfire
 */

package ru.wertyfiregames.craftablecreatures.inventory.gui;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import morph.api.Api;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import ru.wertyfiregames.craftablecreatures.CraftableCreatures;
import ru.wertyfiregames.craftablecreatures.inventory.InventoryTransmutator;
import ru.wertyfiregames.craftablecreatures.inventory.container.ContainerTransmutator;

@SideOnly(Side.CLIENT)
@SuppressWarnings("unchecked")
public class GuiTransmutator extends GuiContainer {
    private static final ResourceLocation transmutatorGuiTextures = new ResourceLocation(CraftableCreatures.getModId(), "textures/gui/container/transmutator.png");
    private final InventoryTransmutator inventoryTransmutator;

    private GuiButton morphButton;

    public GuiTransmutator(InventoryPlayer player, InventoryTransmutator transmutator) {
        super(new ContainerTransmutator(player, transmutator));
        ySize = 194;
        inventoryTransmutator = transmutator;
    }

    @Override
    public void initGui() {
        super.initGui();
        buttonList.clear();
        morphButton = new GuiButton(0, (width - xSize) / 2 + 7, (height - ySize) / 2 + 73, 80, 20, I18n.format("gui.transmutator.morphButton"));
        buttonList.add(morphButton);
    }

    @Override
    protected void actionPerformed(GuiButton button) {
        super.actionPerformed(button);
        if (button.id == morphButton.id) {
            Api.forceMorph(, new EntityCreeper(null));
        }
    }

    protected void drawGuiContainerForegroundLayer(int x, int y) {
        String s = inventoryTransmutator.hasCustomInventoryName() ? inventoryTransmutator.getInventoryName() : I18n.format(inventoryTransmutator.getInventoryName());
        fontRendererObj.drawString(s, xSize / 2 - fontRendererObj.getStringWidth(s) / 2, 6, 4210752);
        fontRendererObj.drawString(I18n.format("container.inventory"), 8, ySize - 96, 4210752);
    }

    protected void drawGuiContainerBackgroundLayer(float partialTicks, int x, int y) {
        GL11.glColor4f(1f, 1f, 1f, 1f);
        mc.getTextureManager().bindTexture(transmutatorGuiTextures);
        int xPos = (width - xSize) / 2;
        int yPos = (height - ySize) / 2;
        drawTexturedModalRect(xPos, yPos, 0, 0, xSize, ySize);
    }
}
Inventory:
/**
 * File created on 14:18 22.09.2024 by Wertyfire
 */

package ru.wertyfiregames.craftablecreatures.inventory;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import ru.wertyfiregames.craftablecreatures.api.ISoulElement;

public class InventoryTransmutator implements IInventory {
    // Slots: 0-8 - small storage; 9 - soul to morph
    // Total: 10
    public final EntityPlayer user;
    private final ItemStack sourceItem;

    private final ItemStack[] transmutatorItemStacks = new ItemStack[10];

    private String customName;

    public InventoryTransmutator(EntityPlayer player) {
        user = player;
        sourceItem = user.getHeldItem();
        if (!sourceItem.hasTagCompound())
            sourceItem.setTagCompound(new NBTTagCompound());

        readFromNBT(sourceItem.getTagCompound());
    }

    public int getSizeInventory() {
        return transmutatorItemStacks.length;
    }

    public ItemStack getStackInSlot(int slot) {
        return transmutatorItemStacks[slot];
    }

    public ItemStack decrStackSize(int slot, int amount) {
        if (transmutatorItemStacks[slot] != null) {
            ItemStack stack;

            if (transmutatorItemStacks[slot].stackSize <= amount) {
                stack = transmutatorItemStacks[slot];
                transmutatorItemStacks[slot] = null;
                markDirty();
            } else {
                stack = transmutatorItemStacks[slot].splitStack(amount);
                if (transmutatorItemStacks[slot].stackSize == 0) transmutatorItemStacks[slot] = null;
            }
            return stack;
        } else return null;
    }

    public ItemStack getStackInSlotOnClosing(int slot) {
        if (transmutatorItemStacks[slot] != null) {
            ItemStack stack = transmutatorItemStacks[slot];
            transmutatorItemStacks[slot] = null;
            return stack;
        } else return null;
    }

    public void setInventorySlotContents(int slot, ItemStack item) {
        transmutatorItemStacks[slot] = item;

        if (item != null && item.stackSize > getInventoryStackLimit())
            item.stackSize = getInventoryStackLimit();

        markDirty();
    }

    public String getInventoryName() {
        return hasCustomInventoryName() ? customName : "container.transmutator";
    }
    public boolean hasCustomInventoryName() {
        return !(customName == "" || customName == null);
    }
    public void setCustomName(String customName) {
        this.customName = customName;
    }

    public void readFromNBT(NBTTagCompound nbt) {
        NBTTagList nbtList = nbt.getTagList("Items", 10);

        for (int i = 0; i < nbtList.tagCount(); ++i) {
            NBTTagCompound item = nbtList.getCompoundTagAt(i);
            int slot = item.getInteger("Slot");

            if (slot >= 0 && slot < getSizeInventory())
                transmutatorItemStacks[slot] = ItemStack.loadItemStackFromNBT(item);
        }

        if (nbt.hasKey("CustomName"))
            customName = nbt.getString("CustomName");
    }

    public void writeToNBT(NBTTagCompound nbt) {
        NBTTagList nbtList = new NBTTagList();

        for (int i = 0; i < getSizeInventory(); ++i) {
            if (getStackInSlot(i) != null) {
                NBTTagCompound nbtCompound = new NBTTagCompound();
                nbtCompound.setInteger("Slot", i);
                getStackInSlot(i).writeToNBT(nbtCompound);
                nbtList.appendTag(nbtCompound);
            }
        }

        nbt.setTag("Items", nbtList);
        if (hasCustomInventoryName())
            nbt.setString("CustomName", customName);
    }

    public int getInventoryStackLimit() {
        return 64;
    }

    public void markDirty() {
        for (int i = 0; i < getSizeInventory(); i++) {
            if (getStackInSlot(i) != null && getStackInSlot(i).stackSize == 0)
                transmutatorItemStacks[i] = null;
        }

        writeToNBT(sourceItem.getTagCompound());
    }

    public boolean isUseableByPlayer(EntityPlayer player) {
        return true;
    }

    public void openInventory() {}
    public void closeInventory() {}

    public boolean isItemValidForSlot(int slot, ItemStack item) {
        return item.getItem() instanceof ISoulElement;
    }
}
 
Назад
Сверху