- 608
- 5
- 15
В GuiHandler есть 2 метода. getServerGuiElement, getClientGuiElement
Я так понял, что это сделано для синхронизации?
Сделал я gui, container, всё как обычно. Но при перемещении/закрытии открытии происходит какая-то фигня. То в слоты для брони залетят предметы, то продаблятся, и прочие аномалии.
Или надо как-то вручную синхронизировать?
Я так понял, что это сделано для синхронизации?
Сделал я gui, container, всё как обычно. Но при перемещении/закрытии открытии происходит какая-то фигня. То в слоты для брони залетят предметы, то продаблятся, и прочие аномалии.
Или надо как-то вручную синхронизировать?
Код:
package ua.svk.WipeChest.gui;
import cpw.mods.fml.common.network.IGuiHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import ua.svk.WipeChest.base.MainMod;
public class GuiHandler implements IGuiHandler
{
public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z)
{
ItemStack stack = player.getCurrentEquippedItem();
if(id == 0 && stack != null && stack.hasTagCompound())
{
System.out.println("+");
return new ContainerWipeChest(player.inventory, new InventoryWipeChest());
}
else
{
return null;
}
}
public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z)
{
ItemStack stack = player.getCurrentEquippedItem();
if(id == 0 && stack != null && stack.hasTagCompound())
{
System.out.println("+");
return new GuiWipeChest(player.inventory, new InventoryWipeChest());
}
else
{
return null;
}
}
}
Код:
package ua.svk.WipeChest.gui;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class ContainerWipeChest extends Container
{
public ContainerWipeChest(InventoryPlayer playerInventory, InventoryWipeChest inv)
{
for(int i = 0; i < 9; i++)
{
this.addSlotToContainer(new Slot(playerInventory, i, 106+i*18, 110+57));
}
for(int i = 0;i < 3; i++)
{
for(int j = 0; j < 9;j++)
{
this.addSlotToContainer(new Slot(playerInventory, 9+j+i*9, 106+18*j, 110+i*18));
}
}
}
@Override
public boolean canInteractWith(EntityPlayer player)
{
return true;
}
}
Код:
package ua.svk.WipeChest.gui;
import org.lwjgl.opengl.GL11;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import ua.svk.WipeChest.RenderHelper;
import ua.svk.WipeChest.base.ModInfo;
public class GuiWipeChest extends GuiContainer
{
ResourceLocation texture = new ResourceLocation(ModInfo.MODID, "textures/gui/bg.png");
public GuiWipeChest(InventoryPlayer playerInventory, InventoryWipeChest inv)
{
super(new ContainerWipeChest(playerInventory, inv));
}
@Override
protected void drawGuiContainerBackgroundLayer(float f, int x, int y)
{
GL11.glTranslatef(0, 0.2F, 0);
RenderHelper.drawTextureRect(texture, this.guiLeft, this.guiTop, this.xSize, this.ySize);
GL11.glTranslatef(0, -0.2F, 0);
}
@Override
public void initGui()
{
super.xSize = 374;
super.ySize = 203;
super.guiLeft = (this.width - this.xSize) / 2;
super.guiTop = (this.height - this.ySize) / 2;
}
}