9 mai 2019, 12:56

bon tout est in the title
Bloc

package com.daichmff.modaichmod;

import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

public class BlockBlueIngot extends BlockContainer
{

    public BlockBlueIngot(Material materialIn)
    {
        super(materialIn);
        // TODO Auto-generated constructor stub
    }

	   @Override
	    public TileEntity createNewTileEntity(World worldIn, int meta) {
	        return new TileEntityE();
	    }
	   
	  
	    
}

Tile

package com.daichmff.modaichmod;

import cofh.api.energy.IEnergyProvider;
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;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IChatComponent;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants;

public class TileEntityE extends TileEntity implements IEnergyProvider,IInventory, net.minecraft.util.ITickable{

	private static int iPC = 200;
	
	    private ItemStack[] contents = new ItemStack[1];
	    private String customName;
	    

	
	private int maxRF = 100000;
	private int currentRF = 0;

	
	
	
	@Override
	public void readFromNBT(NBTTagCompound compound) {
	    super.readFromNBT(compound); // exécute ce qui se trouve dans la fonction readFromNBT de la classe mère (lecture de la position du tile entity)
        if(compound.hasKey("CustomName", Constants.NBT.TAG_STRING)) // si un tag custom name de type string existe
        {
            this.customName = compound.getString("CustomName"); // on le lit
        }
 
        NBTTagList nbttaglist = compound.getTagList("Items", Constants.NBT.TAG_COMPOUND); // on obtient la liste de tags nommée Items
        this.contents = new ItemStack[this.getSizeInventory()]; // on réinitialise le tableau
        for(int i = 0; i < nbttaglist.tagCount(); ++i) // i varie de 0 à la taille la liste
        {
            NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); // on lit le tag nbt
            int j = nbttagcompound1.getByte("Slot") & 255; // on lit à quel slot se trouve l'item stack
 
            if(j >= 0 && j < this.contents.length)
            {
                this.contents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1); // on lit l'item stack qui se trouve dans le tag
            }
        }
	    super.readFromNBT(compound);

	    this.currentRF = compound.getInteger("currentRF");

	}
	 
	@Override
	public void writeToNBT(NBTTagCompound compound) {
        super.writeToNBT(compound); // exécute se qui se trouve dans la fonction writeToNBT de la classe mère (écriture de la position du tile entity)
        if(this.hasCustomName()) // s'il y a un nom custom
        {
            compound.setString("CustomName", this.customName); // on le met dans le tag nbt
        }
 
        NBTTagList nbttaglist = new NBTTagList(); // on créé une nouvelle liste de tags
        for(int i = 0; i < this.contents.length; ++i) // i varie de 0 à la taille de notre tableau
        {
            if(this.contents[ i] != null) // si l'item stack à l'emplacement i du tableau n'est pas null
            {
                NBTTagCompound nbttagcompound1 = new NBTTagCompound(); // on créé un tag nbt
                nbttagcompound1.setByte("Slot", (byte)i); // on enregistre son emplacement dans le tableau
                this.contents[ i].writeToNBT(nbttagcompound1); // on écrit l'item dans le tag
                nbttaglist.appendTag(nbttagcompound1); // on ajoute le tab à la liste
            }
        }
        compound.setTag("Items", nbttaglist); // on enregistre la liste dans le tag nbt

	    super.writeToNBT(compound);
	    compound.setInteger("currentRF", this.currentRF);

	}
	
	@Override
	public int getEnergyStored(EnumFacing from) {
		// TODO Auto-generated method stub
		return this.currentRF;
	}

	@Override
	public int getMaxEnergyStored(EnumFacing from) {
		// TODO Auto-generated method stub
		return maxRF;
	}

	@Override
	public boolean canConnectEnergy(EnumFacing from) {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public int extractEnergy(EnumFacing from, int maxExtract, boolean simulate) {
		// TODO Auto-generated method stub
		currentRF -=maxExtract;
		return maxExtract;
	}

    @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) // si le contenu dans l'emplacement n'est pas null
        {
            ItemStack itemstack;
 
            if(this.contents[slotIndex].stackSize <= amount) // si la quantité est inférieur où égale à ce qu'on souhaite retirer
            {
                itemstack = this.contents[slotIndex]; // la variable itemstack prends la valeur du contenu
                this.contents[slotIndex] = null; // on retire ce qui est dans la variable contents
                this.markDirty(); // met à jour le tile entity
                return itemstack; // renvoie itemstack
            }
            else // sinon
            {
                itemstack = this.contents[slotIndex].splitStack(amount); // la fonction splitStack(quantité) retire dans this.contents[slotIndex] le contenu et le met dans itemstack
 
                if(this.contents[slotIndex].stackSize == 0) // au cas où la quantité passe à 0 (ce qui ne devrait pas arriver en temps normal)
                {
                    this.contents[slotIndex] = null; // on met sur null, ça évite de se retrouver avec des itemstack bugué qui contiennent 0
                }
                this.markDirty(); // met à jour le tile entity
                return itemstack; // renvoie itemstack
            }
        }
        else // sinon si le contenu dans cette emplacement est null
        {
            return null; // renvoie null, puisqu'il n'y a rien dans cette emplacement
        }
    }

	@Override
	public String getName() {
		// TODO Auto-generated method stub
		return this.hasCustomName() ? this.customName : "tile.cupboard";
	}

	@Override
	public boolean hasCustomName() {
		// TODO Auto-generated method stub
		return false;
	}
	  public void setCustomName(String customName)
	    {
	        this.customName = customName;
	    }
	   @Override
	    public boolean isUseableByPlayer(EntityPlayer player)
	    {
	        return true;
	    }
	   @Override
	    public boolean isItemValidForSlot(int slotIndex, ItemStack stack)
	    {
	        return stack.getItem() == MoDaichMod.ingotblue || stack.getItem() == MoDaichMod.blueBow || stack.getItem() == MoDaichMod.bootsTuto || stack.getItem() == MoDaichMod.leggingsTuto || stack.getItem() == MoDaichMod.chestPlateTuto || stack.getItem() == MoDaichMod.helmetTuto;
	    }
	   @Override
	    public int getInventoryStackLimit()
	    {
	        return 64;
	    }

	@Override
	public IChatComponent getDisplayName() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ItemStack removeStackFromSlot(int index) {
		// TODO Auto-generated method stub
		return null;
	}

	




	@Override
	public void openInventory(EntityPlayer player) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void closeInventory(EntityPlayer player) {
	
	}

	
	@Override
	public int getField(int id) {
	switch(id)
	{
	case 0:
		return this.currentRF;
	case 1:
		return this.maxRF;


	}
	return 0;
	}

	@Override
	public void setField(int id, int value) {
	switch(id)
	{
	case 0:
		this.currentRF = value;
	case 1:
		this.maxRF = value;
	
	}
		
	}

	@Override
	public int getFieldCount() {
		// TODO Auto-generated method stub
		return 2;
	}
	 

	 

	@Override
	public void clear() {
		// TODO Auto-generated method stub
		
	}
	   @Override
	    public void setInventorySlotContents(int slotIndex, ItemStack stack)
	    {
	        this.contents[slotIndex] = stack; // met l'item stack dans le tableau
	 
	        if(stack != null && stack.stackSize > this.getInventoryStackLimit()) // si la taille de l'item stack dépasse la limite maximum de l'inventaire
	        {
	            stack.stackSize = this.getInventoryStackLimit(); // on le remet sur la limite
	        }
	 
	        this.markDirty(); // met à jour le tile entity
	    }

	@Override
	public void update() {
      
		if(worldObj.isRemote)
		{
			if(this.currentRF == 9999999)
			{
				
			}
			else
			{
				System.out.println("Your RF level is : " + currentRF);
			}
			
			if(worldObj.canSeeSky(pos))
			{
				this.iPC =+1;
				
			}
			else
			{
				this.iPC =-1;
				
			}
			if(currentRF == 1)
			{
				System.out.println("[14:00:26] [Client thread/INFO]: [CHAT] <PlayerBambi> lol you have 1 rf lol you are a giant lol");
			}
		}
		this.currentRF += iPC;
		this.markDirty();
		// TODO Auto-generated method stu   
}

}