Created
May 20, 2015 16:08
-
-
Save anonymous/05dc3b9bcbbfdd998d17 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package fr.ah26.futura.common; | |
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 ContainerXFurnace extends Container | |
{ | |
private IInventory tileXFurnace; | |
public ContainerXFurnace(TileEntityXFurnace tile, InventoryPlayer inventory) | |
{ | |
this.addSlotToContainer(new Slot(tileXFurnace, 0, 49, 75)); //Lancez votre jeu en debug pour calibrer vos slots | |
this.addSlotToContainer(new Slot(tileXFurnace, 1, 89, 75)); | |
this.addSlotToContainer(new Slot(tileXFurnace, 2, 129, 75)); | |
this.addSlotToContainer(new SlotResult(tileXFurnace, 3, 89, 135)); //Ici c'est un slot que j'ai créer, on le fera après | |
this.bindPlayerInventory(inventory); //Les containers ont été vus dans un tutoriel de robin, merci de d'y référer | |
} | |
@Override | |
public boolean canInteractWith(EntityPlayer player) { | |
return this.tileXFurnace.isUseableByPlayer(player); | |
} | |
private void bindPlayerInventory(InventoryPlayer inventory) | |
{ | |
int i; | |
for (i = 0; i < 3; ++i) | |
{ | |
for (int j = 0; j < 9; ++j) | |
{ | |
this.addSlotToContainer(new Slot(inventory, j + i * 9 + 9, 17 + j * 18, 171 + i * 18)); | |
} | |
} | |
for (i = 0; i < 9; ++i) | |
{ | |
this.addSlotToContainer(new Slot(inventory, i, 17 + i * 18, 229)); | |
} | |
} | |
public ItemStack transferStackInSlot(EntityPlayer player, int quantity) | |
{ | |
ItemStack itemstack = null; | |
Slot slot = (Slot)this.inventorySlots.get(quantity); | |
if (slot != null && slot.getHasStack()) | |
{ | |
ItemStack itemstack1 = slot.getStack(); | |
itemstack = itemstack1.copy(); | |
if (quantity < this.tileXFurnace.getSizeInventory()) | |
{ | |
if (!this.mergeItemStack(itemstack1, this.tileXFurnace.getSizeInventory(), this.inventorySlots.size(), true)) | |
{ | |
return null; | |
} | |
} | |
else if (!this.mergeItemStack(itemstack1, 0, this.tileXFurnace.getSizeInventory(), false)) | |
{ | |
return null; | |
} | |
if (itemstack1.stackSize == 0) | |
{ | |
slot.putStack((ItemStack)null); | |
} | |
else | |
{ | |
slot.onSlotChanged(); | |
} | |
} | |
return itemstack; | |
} | |
public void onContainerClosed(EntityPlayer player) | |
{ | |
super.onContainerClosed(player); | |
this.tileXFurnace.closeInventory(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment