Ajouter un gui et un container à un bloc
-
@robin4002 C bon ca a marcher mais maintenant quand je pose mon block et que je click droit Il ne se passe rien (je viens de commencer les dev jsuis un gros noob mdrrr)
-
Voici mes class:
package fr.havzen.irizium.tileentity; import fr.havzen.irizium.IriMod; import fr.havzen.irizium.Reference; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityChest; import net.minecraft.util.ChatComponentText; import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.MathHelper; import net.minecraft.world.World; public class BlockEntity1 extends Block { public BlockEntity1(Material p_i45394_1_) { super(p_i45394_1_); } @Override public boolean hasTileEntity(int metadata) { return true; } @Override public TileEntity createTileEntity(World world, int metadata) { return new TileEntityIrizium(); } public boolean onBlockActivated1(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { if (world.isRemote) { return true; } else { { player.openGui(IriMod.modinstance, 0, world, x, y, z);; } return true; } } public void breakBlock(World world, int x, int y, int z, Block block, int metadata) { TileEntity tileentity = world.getTileEntity(x, y, z); IInventory inv = (IInventory)tileentity; if (tileentity instanceof IInventory) { 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 void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase living, ItemStack stack) { if(stack.getItemDamage() == 0) { TileEntity tile = world.getTileEntity(x, y, z); if(tile instanceof TileEntityIrizium) { int direction = MathHelper.floor_double((double)(living.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; ((TileEntityIrizium)tile).setDirection((byte)direction); if(stack.hasDisplayName()) { ((TileEntityIrizium)tile).setCustomName(stack.getDisplayName()); } } } } public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { TileEntity tile = world.getTileEntity(x, y, z); if(tile instanceof TileEntityIrizium) { TileEntityIrizium BlockEntityTest = (TileEntityIrizium)tile; } return false; } }
-
package fr.havzen.irizium.tileentity; 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.minecraftforge.common.util.Constants; public class TileEntityIrizium extends TileEntity implements IInventory { private int number; private byte direction; private ItemStack[] contents = new ItemStack [108]; private String customName; @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); this.direction = compound.getByte("Direction"); if (compound.hasKey("CustomName", Constants.NBT.TAG_STRING)) { this.customName = compound.getString("CustomName"); } NBTTagList nbttaglist = compound.getTagList("Items", Constants.NBT.TAG_COMPOUND); this.contents = new ItemStack[this.getSizeInventory()]; if (compound.hasKey("CustomName", 8)) { this.customName = compound.getString("CustomName"); } 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); } } } @Override public void writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); compound.setByte("Direction", this.direction); if (this.hasCustomInventoryName()) { compound.setString("CustomName", this.customName); } NBTTagList nbttaglist = new NBTTagList(); for (int i = 0; i < this.contents.length; ++i) { if (this.contents[i] != null) { NBTTagCompound nbttagcompound1 = new NBTTagCompound(); nbttagcompound1.setByte("Slot", (byte)i); this.contents[i].writeToNBT(nbttagcompound1); nbttaglist.appendTag(nbttagcompound1); } } compound.setTag("Items", nbttaglist); if (this.hasCustomInventoryName()) { compound.setString("CustomName", this.customName); } } public byte getDirection() { return direction; } public void setDirection(byte direction) { this.direction = direction; } @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 this.hasCustomInventoryName() ? this.customName : "tile.irizium.chest"; } @Override public boolean hasCustomInventoryName() { return this.customName != null && !this.customName.isEmpty(); } public void setCustomName(String customName) { this.customName = customName; } @Override public int getInventoryStackLimit() { return 240; } @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 slotIndex, ItemStack stack) { return true; } }
-
package fr.havzen.irizium.tileentity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import cpw.mods.fml.common.network.IGuiHandler; public class GuiHandlerIri implements IGuiHandler { @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world,int x, int y, int z) { TileEntity tile = world.getTileEntity(x, y, z); if(tile instanceof TileEntityIrizium) { return new ContainerIrizium((TileEntityIrizium)tile, player.inventory); } return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world,int x, int y, int z) { TileEntity tile = world.getTileEntity(x, y, z); if(tile instanceof TileEntityIrizium) { return new GuiIrizium((TileEntityIrizium)tile, player.inventory); } return null; } }
-
package fr.havzen.irizium.tileentity; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; public class GuiIrizium extends GuiContainer { public GuiIrizium(TileEntityIrizium tile, InventoryPlayer inventory) { super(new ContainerIrizium(tile, inventory)); } @Override protected void drawGuiContainerBackgroundLayer(float p_146976_1_,int p_146976_2_, int p_146976_3_) { } }
-
Et ma classe init:
public class BlockMod { public static Block Irizium_Block, Irizium_Ore, Cave_Block, testChest, BlockEntityTest; public static void init() { Irizium_Block = new BlockBasic(Material.iron).setBlockName("Irizium_Block").setCreativeTab(CreativeTabs.tabBlock).setBlockTextureName(Reference.IR_ID + ":Irizium_Block").setHardness(3.0f); Irizium_Ore = new BlockBasic(Material.iron).setBlockName("Irizium_Ore").setCreativeTab(CreativeTabs.tabBlock).setBlockTextureName(Reference.IR_ID + ":Irizium_Ore"); Cave_Block = new BlockBasic(Material.glass).setBlockName("Cave_Block").setCreativeTab(CreativeTabs.tabBlock).setBlockTextureName(Reference.IR_ID + ":Cave_Block"); BlockEntityTest = new BlockEntity1(Material.iron).setBlockName("BlockEntityTest").setCreativeTab(CreativeTabs.tabBlock); } public static void register() { GameRegistry.registerBlock(Irizium_Block, Irizium_Block.getUnlocalizedName().substring(5)); GameRegistry.addRecipe(new ItemStack(BlockMod.Irizium_Block, 1), new Object[]{"###", "###", "###", '#', ItemMod.Irizium_Ingot}); GameRegistry.registerBlock(Cave_Block, "Cave_Block"); GameRegistry.registerBlock(Irizium_Ore, "Irizium_Ore"); GameRegistry.registerBlock(BlockEntityTest, "BlockEntityTest"); GameRegistry.registerTileEntity(TileEntityIrizium.class, "BlockEntityTest"); } }
-
-
Un seul message aurait suffit et avec les balises code c’est mieux.
Aussi évites de spammer de mention …Et sinon je t’ai déjà dit que MFF ne fait plus de support pour la 1.7.10 : soit tu utilises une version moderne, soit tu te débrouilles.
-
Ok jsuis desolé mais juste aide moi sur ce truc et jte fais plus chier
je na sais pas quoi faire -
-
-
-