Здравствуйте софорумцы!
Добрался я наконец до GUI и тут же ошпарился.
Решил я создать свой верстак по этому гайду.
Я уже почти десять часов бьюсь, пытаясь сократить количество слотов GUI. Сейчас оно - ровная сетка 5*5.
А мне нужно 2*1, как на наковальня. При попытке немного что то крутануть - все крашится.
Очень прошу подсказать, в какую сторону копать. И помочь по возможности.
Заранее благодарен!
Добрался я наконец до GUI и тут же ошпарился.
Решил я создать свой верстак по этому гайду.
[font=Monaco, Consolas, Courier, monospace][size=small][font=Monaco, Consolas, Courier, monospace]guiPerlTable.java[/font][/SIZE][/font][/size]]
Код:
package ru.legendary.lwmod.lwmench.gui;
import org.lwjgl.opengl.GL11;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import ru.legendary.lwmod.lwmcore.util.Logging;
import ru.legendary.lwmod.lwmench.LWMEnch;
import ru.legendary.lwmod.lwmench.container.containerPerlTable;
public class guiPerlTable extends GuiContainer {
private static final ResourceLocation texture = new ResourceLocation("lwm2/textures/gui/guiPerlTable.png");
public guiPerlTable(InventoryPlayer invPlayer, World world, int x, int y, int z) {
super(new containerPerlTable(invPlayer, world, x, y, z));
this.xSize = 176;
this.ySize = 188;
}
public void onGuiClosed(){
super.onGuiClosed();
}
protected void drawGuiContainerForegroundLayer (int i, int j) {
this.fontRendererObj.drawString(StatCollector.translateToLocal("Work Surface"), 100, 5, 0xFFFFFF);
}
@Override
protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) {
GL11.glColor4f(1F, 1F, 1F, 1F);
this.bindTexture(texture);
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
}
private void bindTexture(ResourceLocation texture2) {
//texture2 = texture;
}
}
Я уже почти десять часов бьюсь, пытаясь сократить количество слотов GUI. Сейчас оно - ровная сетка 5*5.
А мне нужно 2*1, как на наковальня. При попытке немного что то крутануть - все крашится.
Очень прошу подсказать, в какую сторону копать. И помочь по возможности.
[font=Monaco, Consolas, Courier, monospace]containerPerlTable.java[/font][/SIZE]]
Код:
package ru.legendary.lwmod.lwmench.container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ContainerWorkbench;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCraftResult;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import ru.legendary.lwmod.lwmcore.util.Logging;
import ru.legendary.lwmod.lwmench.LWMEnch;
import ru.legendary.lwmod.lwmench.core.ModBlocks;
import ru.legendary.lwmod.lwmench.crafting.PerlTableManager;
public class containerPerlTable extends Container {
public InventoryCrafting craftMatrix;
public IInventory craftResult;
private World worldObj;
private int posX;
private int posY;
private int posZ;
public containerPerlTable(InventoryPlayer invPlayer, World world, int x, int y, int z) {
craftMatrix = new InventoryCrafting(this, 5, 5);
craftResult = new InventoryCraftResult();
worldObj = world;
posX = x;
posY = y;
posZ = z;
this.addSlotToContainer(new SlotCrafting(invPlayer.player, craftMatrix, craftResult, 0, 141, 43));
for (int i = 0; i < 5; i++) {
for(int k = 0; k < 5; k++) {
this.addSlotToContainer(new Slot(craftMatrix, k + i * 5, 8 + k * 18, 7 + i * 18));
}
}
for (int i = 0; i < 3; i++) {
for(int k = 0; k < 9; k++) {
this.addSlotToContainer(new Slot(invPlayer, k + i * 9 + 9, 8 + k * 18, 106 + i * 18));
}
}
for (int i = 0; i < 9; i++) {
this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 164));
}
onCraftMatrixChanged(craftMatrix);
}
public void onCraftMatrixChanged(IInventory iiventory) {
craftResult.setInventorySlotContents(0, PerlTableManager.getInstance().findMatchingRecipe(craftMatrix, worldObj));
}
@Override
public boolean canInteractWith(EntityPlayer player) {
if(worldObj.getBlock(posX, posY, posZ) != ModBlocks.blockPerlTable) {
return false;
}else{
return player.getDistanceSq((double)posX + 0.5D, (double)posY + 0.5D, (double)posZ + 0.5D) <= 64.0D;
}
}
public void onContainerClosed(EntityPlayer par1EntityPlayer) {
super.onContainerClosed(par1EntityPlayer);
if (!this.worldObj.isRemote)
{
for (int i = 0; i < 9; ++i)
{
ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i);
if (itemstack != null)
{
par1EntityPlayer.dropPlayerItemWithRandomChoice(itemstack, false);
}
}
}
}
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) {
ItemStack itemstack = null;
Slot slot = (Slot)this.inventorySlots.get(par2);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (par2 == 0)
{
if (!this.mergeItemStack(itemstack1, 10, 46, true))
{
return null;
}
slot.onSlotChange(itemstack1, itemstack);
}
else if (par2 >= 10 && par2 < 37)
{
if (!this.mergeItemStack(itemstack1, 37, 46, false))
{
return null;
}
}
else if (par2 >= 37 && par2 < 46)
{
if (!this.mergeItemStack(itemstack1, 10, 37, false))
{
return null;
}
}
else if (!this.mergeItemStack(itemstack1, 10, 46, false))
{
return null;
}
if (itemstack1.stackSize == 0)
{
slot.putStack((ItemStack)null);
}
else
{
slot.onSlotChanged();
}
if (itemstack1.stackSize == itemstack.stackSize)
{
return null;
}
slot.onPickupFromSlot(par1EntityPlayer, itemstack1);
}
return itemstack;
}
Заранее благодарен!