et la une Class surgit
package com.adamitemod.mod;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
public class TileEntityMachineCraft extends TileEntity implements IInventory {
private ItemStack[] contents = new ItemStack[2]; // #SCAREX : tu n'as que 2 slots
private int workingTime = 0;
private int workingTimeNeeded = 60;
@SideOnly(Side.CLIENT)
public int getCookProgress()
{
return this.workingTime * 17 / this.workingTimeNeeded;
}
@Override
public void writeToNBT(NBTTagCompound compound)
{
super.writeToNBT(compound);
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < this.contents.length; ++i)
{
if (this.contents* != null)
{
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.setByte("Slot", (byte)i);
this.contents*.writeToNBT(nbttagcompound1);
nbttaglist.appendTag(nbttagcompound1);
}
}
compound.setTag("Items", nbttaglist);
compound.setShort("workingTime",(short)this.workingTime);
compound.setShort("workingTimeNeeded", (short)this.workingTimeNeeded);
}
@Override
public void readFromNBT(NBTTagCompound compound)
{
super.readFromNBT(compound);
NBTTagList nbttaglist = compound.getTagList("Items", 10);
this.contents = new ItemStack[this.getSizeInventory()];
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
int j = nbttagcompound1.getByte("Slot") & 255;
if (j >= 0 && j < this.contents.length)
{
this.contents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
}
}
this.workingTime = compound.getShort("workingTime");
this.workingTimeNeeded = compound.getShort("workingTimeNeeded");
}
@Override
public int getSizeInventory() {
return this.contents.length;
}
@Override
public ItemStack getStackInSlot(int slotIndex) {
return this.contents[slotIndex];
}
@Override
public ItemStack decrStackSize(int slotIndex, int amount) {
if (this.contents[slotIndex] != null)
{
ItemStack itemstack;
if (this.contents[slotIndex].stackSize <= amount)
{
itemstack = this.contents[slotIndex];
this.contents[slotIndex] = null;
this.markDirty();
return itemstack;
}
else
{
itemstack = this.contents[slotIndex].splitStack(amount);
if (this.contents[slotIndex].stackSize == 0)
{
this.contents[slotIndex] = null;
}
this.markDirty();
return itemstack;
}
}
else
{
return null;
}
}
@Override
public ItemStack getStackInSlotOnClosing(int slotIndex) {
if (this.contents[slotIndex] != null)
{
ItemStack itemstack = this.contents[slotIndex];
this.contents[slotIndex] = null;
return itemstack;
}
else
{
return null;
}
}
@Override
public void setInventorySlotContents(int slotIndex, ItemStack stack) {
this.contents[slotIndex] = stack;
if (stack != null && stack.stackSize > this.getInventoryStackLimit())
{
stack.stackSize = this.getInventoryStackLimit();
}
this.markDirty();
}
@Override
public String getInventoryName() {
return "tile.machineTuto";
}
@Override
public boolean hasCustomInventoryName() {
return false;
}
@Override
public int getInventoryStackLimit() {
return 64;
}
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : player.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D;
}
@Override
public void openInventory() {
}
@Override
public void closeInventory() {
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack) {
return slot == 3 ? false : true;
}
public boolean isBurning()
{
return this.workingTime > 0;
}
private boolean canSmelt()
{
if (this.contents[0] == null) // #SCAREX : tu n'as qu'un seul slot ici
{
return false;
}
else
{
ItemStack itemstack = MachineRecipesCraft.smelting().getSmeltingResult(this.contents[0]); // #SCAREX : un seul slot
if (itemstack == null) return false;
if (this.contents[3] == null) return true;
if (!this.contents[3].isItemEqual(itemstack)) return false;
int result = contents[3].stackSize + itemstack.stackSize;
return result <= getInventoryStackLimit() && result <= this.contents[3].getMaxStackSize();
}
}
public void updateEntity()
{
if(this.isBurning() && this.canSmelt())
{
++this.workingTime;
}
if(this.canSmelt() && !this.isBurning())
{
this.workingTime = 1;
}
if(this.canSmelt() && this.workingTime == this.workingTimeNeeded)
{
this.smeltItem();
this.workingTime = 0;
}
if(!this.canSmelt())
{
this.workingTime= 0;
}
}
public void smeltItem()
{
if (this.canSmelt())
{
ItemStack itemstack = MachineRecipesCraft.smelting().getSmeltingResult(this.contents[0]); // #SCAREX : tu n'as qu'un seul input
if (this.contents[1] == null) // #SCAREX : ton slot d'output devient 1
{
this.contents[1] = itemstack.copy();
}
else if (this.contents[1].getItem() == itemstack.getItem())
{
this.contents[1].stackSize += itemstack.stackSize;
}
–this.contents[0].stackSize;
if (this.contents[0].stackSize <= 0)
{
this.contents[0] = null;
}
}
}
}
Voilla