Bonjour j’ai un souci, mon gui s’affiche 1 tick et se referme, auriez-vous une idée d’où celà pourrait venir ??
:::
| public class BlockTethMachine extends Block { |
| |
| public BlockTethMachine(Material p_i45394_1_) { |
| super(p_i45394_1_); |
| |
| } |
| |
| @Override |
| public TileEntity createTileEntity(World world, int metadata) |
| { |
| return new TileEntityTethMachine(); |
| } |
| |
| @Override |
| public boolean hasTileEntity(int metadata) |
| { |
| return true; |
| } |
| |
| public void breakBlock(World world, int x, int y, int z, Block block, int metadata) |
| { |
| TileEntity tileentity = world.getTileEntity(x, y, z); |
| |
| if (tileentity instanceof IInventory) |
| { |
| IInventory inv = (IInventory)tileentity; |
| for (int i1 = 0; i1 < inv.getSizeInventory(); ++i1) |
| { |
| ItemStack itemstack = inv.getStackInSlot(i1); |
| |
| if (itemstack != null) |
| { |
| float f = world.rand.nextFloat() * 0.8F + 0.1F; |
| float f1 = world.rand.nextFloat() * 0.8F + 0.1F; |
| EntityItem entityitem; |
| |
| for (float f2 = world.rand.nextFloat() * 0.8F + 0.1F; itemstack.stackSize > 0; world.spawnEntityInWorld(entityitem)) |
| { |
| int j1 = world.rand.nextInt(21) + 10; |
| |
| if (j1 > itemstack.stackSize) |
| { |
| j1 = itemstack.stackSize; |
| } |
| |
| itemstack.stackSize -= j1; |
| entityitem = new EntityItem(world, (double)((float)x + f), (double)((float)y + f1), (double)((float)z + f2), new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage())); |
| float f3 = 0.05F; |
| entityitem.motionX = (double)((float)world.rand.nextGaussian() * f3); |
| entityitem.motionY = (double)((float)world.rand.nextGaussian() * f3 + 0.2F); |
| entityitem.motionZ = (double)((float)world.rand.nextGaussian() * f3); |
| |
| if (itemstack.hasTagCompound()) |
| { |
| entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy()); |
| } |
| } |
| } |
| } |
| |
| world.func_147453_f(x, y, z, block); |
| } |
| |
| super.breakBlock(world, x, y, z, block, metadata); |
| } |
| |
| public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) |
| { |
| |
| player.openGui(CiolMod.instance, 10, world, x, y, z); |
| return true; |
| |
| } |
| |
| } |
| |
:::
:::
| package com.mod.ciolmod.blocks.tileentities; |
| |
| import com.mod.ciolmod.gui.GuiMachineTeth; |
| |
| import cpw.mods.fml.common.network.IGuiHandler; |
| import net.minecraft.entity.player.EntityPlayer; |
| import net.minecraft.tileentity.TileEntity; |
| import net.minecraft.world.World; |
| |
| public class GuiTethMachineHandler implements IGuiHandler { |
| |
| @Override |
| public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) |
| { |
| switch (ID) |
| { |
| case 10: |
| return new ContainerMachineTeth(world.getTileEntity(x, y, z), player.inventory); |
| } |
| return null; |
| |
| } |
| |
| @Override |
| public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) |
| { |
| switch (ID) |
| { |
| case 10: |
| return new GuiMachineTeth((TileEntityTethMachine)world.getTileEntity(x, y, z), player.inventory); |
| } |
| return null; |
| } |
| |
| } |
| |
:::
Mon Init :
:::
| @EventHandler |
| public void Init(FMLInitializationEvent event) |
| { |
| proxy.registerRenders(); |
| |
| proxy.registerRenderers(); |
| proxy.registerEntities(); |
| |
| EntityRegistry.registerGlobalEntityID(EntityTethanium.class, "mobBlackKoala", EntityRegistry.findGlobalUniqueEntityId(), new Color(255, 255, 255).getRGB(), new Color(0, 0, 165).getRGB()); |
| EntityRegistry.registerModEntity(EntityTethanium.class, "mobBlackKoala", EntityRegistry.findGlobalUniqueEntityId(), this.instance, 40, 1, true); |
| EntityRegistry.registerGlobalEntityID(EntityKoala.class, "mobKoala", EntityRegistry.findGlobalUniqueEntityId(), new Color(0, 0, 0).getRGB(), new Color(165, 0, 0).getRGB()); |
| EntityRegistry.registerModEntity(EntityKoala.class, "mobKoala", EntityRegistry.findGlobalUniqueEntityId(), this.instance, 40, 1, true); |
| |
| |
| |
| GameRegistry.registerTileEntity(TileEntityBlockFDC.class, Reference.MOD_ID + ":teBlockFDC"); |
| GameRegistry.registerTileEntity(TileEntityXPParticuler.class, Reference.MOD_ID + ":teXPPARTICULER"); |
| |
| EntityRegistry.registerModEntity(EntityDynamite.class, "dynamite", 451, CiolMod.instance, 32, 20, true); |
| |
| GameRegistry.registerTileEntity(TileEntityTethaniumISpawner.class, Reference.MOD_ID + ":tileentityispawner"); |
| |
| GameRegistry.registerTileEntity(TileEntityTethMachine.class, Reference.MOD_ID + ":TethMachineTE"); |
| |
| NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiTethMachineHandler()); |
| |
| |
| |
| } |
:::
:::
| package com.mod.ciolmod.blocks.tileentities; |
| |
| import net.minecraft.entity.player.EntityPlayer; |
| import net.minecraft.entity.player.InventoryPlayer; |
| import net.minecraft.inventory.Container; |
| import net.minecraft.inventory.Slot; |
| import net.minecraft.tileentity.TileEntity; |
| |
| public class ContainerMachineTeth extends Container{ |
| |
| private TileEntityTethMachine tileMachineTuto; |
| |
| @Override |
| public boolean canInteractWith(EntityPlayer p_75145_1_) { |
| |
| return false; |
| } |
| |
| public ContainerMachineTeth(TileEntityTethMachine tile, InventoryPlayer inventory) |
| { |
| this.tileMachineTuto = tile; |
| this.addSlotToContainer(new Slot(tile, 0, 49, 75)); |
| this.addSlotToContainer(new Slot(tile, 1, 89, 75)); |
| this.addSlotToContainer(new Slot(tile, 2, 129, 75)); |
| this.addSlotToContainer(new SlotResult(tile, 3, 89, 135)); |
| this.bindPlayerInventory(inventory); |
| } |
| |
| public ContainerMachineTeth(TileEntity tileEntity, InventoryPlayer inventory) { |
| |
| } |
| |
| private void bindPlayerInventory(InventoryPlayer inventory) { |
| |
| |
| } |
| |
| } |
:::
:::
package com.mod.ciolmod.blocks.tileentities;
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 TileEntityTethMachine extends TileEntity implements IInventory {
private ItemStack[] contents = new ItemStack[4];
private int workingTime = 0;
private int workingTimeNeeded = 60;
@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");
}
public int getSizeInventory() {
return this.contents.length;
}
public ItemStack getStackInSlot(int slotIndex) {
return this.contents[slotIndex];
}
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;
}
}
public ItemStack getStackInSlotOnClosing(int slotIndex) {
if (this.contents[slotIndex] != null)
{
ItemStack itemstack = this.contents[slotIndex];
this.contents[slotIndex] = null;
return itemstack;
}
else
{
return null;
}
}
public void setInventorySlotContents(int slotIndex, ItemStack stack) {
this.contents[slotIndex] = stack;
if (stack != null && stack.stackSize > this.getInventoryStackLimit())
{
stack.stackSize = this.getInventoryStackLimit();
}
this.markDirty();
}
public String getInventoryName() {
return "ttt";
}
public boolean hasCustomInventoryName() {
return false;
}
public int getInventoryStackLimit() {
return 64;
}
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;
}
public void openInventory() {
}
public void closeInventory() {
}
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 || this.contents[1] == null || this.contents[2] == null)
{
return false;
}
else
{
ItemStack itemstack = MachineTethRecipes.smelting().getSmeltingResult(new ItemStack[]{this.contents[0], this.contents[1], this.contents[2]});
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 = MachineTethRecipes.smelting().getSmeltingResult(new ItemStack[]{this.contents[0], this.contents[1], this.contents[2]});
if (this.contents[3] == null)
{
this.contents[3] = itemstack.copy();
}
else if (this.contents[3].getItem() == itemstack.getItem())
{
this.contents[3].stackSize += itemstack.stackSize;
}
–this.contents[0].stackSize;
–this.contents[1].stackSize;
–this.contents[2].stackSize;
if (this.contents[0].stackSize <= 0)
{
this.contents[0] = null;
}
if (this.contents[1].stackSize <= 0)
{
this.contents[1] = null;
}
if (this.contents[2].stackSize <= 0)
{
this.contents[2] = null;
}
}
}
}
:::
:::
package com.mod.ciolmod.gui;
import org.lwjgl.opengl.GL11;
import com.mod.ciolmod.Reference;
import com.mod.ciolmod.blocks.tileentities.ContainerMachineTeth;
import com.mod.ciolmod.blocks.tileentities.TileEntityTethMachine;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.util.ResourceLocation;
public class GuiMachineTeth extends GuiContainer {
private static final ResourceLocation texture = new ResourceLocation(Reference.MOD_ID ,"textures/gui/guitethmachine.png");
private TileEntityTethMachine tileMachineTuto;
private IInventory playerInv;
public GuiMachineTeth(TileEntityTethMachine tile, InventoryPlayer inventory)
{
super(new ContainerMachineTeth(tile, inventory));
this.tileMachineTuto = tile;
this.playerInv = inventory;
this.allowUserInput = false;
this.ySize = 256;
this.xSize = 256;
}
@Override
protected void drawGuiContainerBackgroundLayer(float partialRenderTick, int x, int y)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(texture);
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
this.drawTexturedModalRect(0, 0, 176, 14, 100 + 1, 16);
}
protected void drawGuiContainerForegroundLayer(int x, int y)
{
this.fontRendererObj.drawString(this.playerInv.hasCustomInventoryName() ? this.playerInv.getInventoryName() : I18n.format(this.playerInv.getInventoryName()), 10, this.ySize - 98, 4210752);
}
}
:::
Merci de votre réponse :
et bonne soirée