- 24
- 1
Здравствуйте. Я сделал пользовательский инвентарь игрока. но я не могу перемещать предметы в слотах. Как мне это исправить?
2020_02_28_13_19_23_591 - Streamable
Check out this video on Streamable using your phone, tablet or desktop.
streamable.com
GuiContainer:
public class GuiSareahInventory extends GuiContainer {
public GuiSareahInventory(EntityPlayer player, InventoryPlayer inventoryPlayer) {
super(new ContainerInventory(inventoryPlayer,player));
xSize = 180;
ySize = 230;
}
@Override
public void initGui() {
super.initGui();
this.buttonList.add(new GuiCustomButton(0,guiLeft + 175,guiTop,12,32, 0));
this.buttonList.add(new GuiCustomButton(1,guiLeft + 175,guiTop + 37,12,32, 1));
}
@Override
protected void actionPerformed(GuiButton button) throws IOException {
}
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
}
@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
drawDefaultBackground();
mc.getTextureManager().bindTexture(new ResourceLocation(Sareah.MODID,"inventory_gui.png"));
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
GuiInventory.drawEntityOnScreen(guiLeft + 88, guiTop + 110, 43, (float)(guiLeft + 51) - mouseX, (float)(guiTop + 74 - 50) - mouseY, mc.player);
}
}
Container:
public class ContainerInventory extends Container {
private final EntityPlayer player;
public ContainerInventory(InventoryPlayer playerInv, EntityPlayer player) {
this.player = player;
this.addSlotToContainer(new SlotArmor(player, playerInv, 39, 16,22,3)); //head
this.addSlotToContainer(new SlotArmor(player, playerInv, 38, 16,80,2)); //chest
this.addSlotToContainer(new SlotArmor(player, playerInv, 37, 145,22,1)); //leg
this.addSlotToContainer(new SlotArmor(player, playerInv, 36, 145,80,0)); //feet
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 9; ++j)
{
this.addSlotToContainer(new Slot(playerInv, j + i * 9 + 9, 8 + j * 18, 140 + i * 18));
}
}
for (int i = 0; i < 9; ++i)
{
this.addSlotToContainer(new Slot(playerInv, i, 8 + i * 18, 202));
}
}
@Override
public boolean canInteractWith(EntityPlayer playerIn) {
return true;
}
}
Guihandler:
public class GuiHandler implements IGuiHandler {
public static final int INVENTORY_GUI_ID = 0;
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
if(ID == INVENTORY_GUI_ID) {
return new ContainerInventory(player.inventory, player);
}
return null;
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
if(ID == INVENTORY_GUI_ID) {
return new GuiSareahInventory(player, player.inventory);
}
return null;
}
}