- 102
- 0
У меня есть гуи
и
Как мне реализовать взаимодействие со слотами, то есть что бы проверялось лежит ли в слоте определенный итем? И еще вопрос, почему у меня в инвентаре предметы не перемещаются мышкой?
Код:
package spellflex.kuroi.rpg.gui;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
import spellflex.kuroi.rpg.Setings;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
public class GuiWindow extends GuiContainer
{
int xSize = 190;
int ySize = 190;
public GuiWindow(World world, int i, int j, int k, EntityPlayer entity){
super(new GuiContainerMod((EntityPlayer)entity, world, i, j, k));
}
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.renderEngine.bindTexture(new ResourceLocation(Setings.MODID +":textures/GUI/UpWeapons.png"));
int k = (this.width - xSize) / 2;
int l = (this.height - ySize) / 2;
this.drawTexturedModalRect(k, l, 0, 0, xSize, ySize);
}
protected void drawGuiContainerForegroundLayer(int par1, int par2){
this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, 73, 4210752);
}
}
Код:
package spellflex.kuroi.rpg.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.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;
public class GuiContainerMod extends Container {
public InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3);
private World worldObj;
public GuiContainerMod (EntityPlayer player, World world, int i2, int j2, int k){
this.worldObj = world;
this.addSlotToContainer(new Slot(new TileEntitySlot(), 0, 30, 17));
this.addSlotToContainer(new Slot(new TileEntitySlot(), 1, 30+18, 17));
this.addSlotToContainer(new Slot(new TileEntitySlot(), 2, 30+9, 17+18));
bindPlayerInventory(player.inventory);
}
protected void bindPlayerInventory(InventoryPlayer inventoryPlayer) {
int i;
for(i = 0; i < 3; ++i){
for(int j = 0; j < 9; ++j){
this.addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}
for(i = 0; i < 9; ++i){
this.addSlotToContainer(new Slot(inventoryPlayer, i , 8 + i * 18 , 142));
}
}
@Override
public boolean canInteractWith(EntityPlayer p_75145_1_) {
return craftMatrix.isUseableByPlayer(p_75145_1_);
}
public void onContainerClosed(EntityPlayer p_75134_1_)
{
super.onContainerClosed(p_75134_1_);
if (!this.worldObj.isRemote)
{
for (int i = 0; i < 9; ++i)
{
ItemStack itemstack = new TileEntitySlot().getStackInSlotOnClosing(i);
if (itemstack != null)
{
p_75134_1_.dropPlayerItemWithRandomChoice(itemstack, false);
}
}
}
}
public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
return null;
}
}