Problème de drop dans le gui d'un chest moddé
-
Bonjour, je me présente.
ddzouille0202 je suis asser jeune et suis débutant en java (nan mais vraiment débutant). Un ami qui crée un serveur moddé pour joué avec ses pote ma demander si je pouvais faire un mod. Je lui ai dit que je voulais bien essayer. J’ai suivi les tuto de la chaine MFF et de checconio. Jusqu’a la tout allais bien. Jusque quand j’ai eu l’idée de faire un chest.Le chest en lui même fonctionne, sauf pour le gui. Dans les deux premiere ligne (hotbar et celle au dessus) impossible de saisir les item quand je clique sa drop les item.
j’ai chercher sans rien trouver alors je vien demander a la communauté MFF.class GuiIronChest
package fr.xenofight.mod.gui; import fr.xenofight.mod.tileentity.TileEntityChestMod; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.entity.player.InventoryPlayer; public class GuiIronChest extends GuiContainer { public GuiIronChest(TileEntityChestMod tile, InventoryPlayer inventory) { super(new ContainerIronChest(tile, inventory)); } @Override protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) { } }
Class GuiHandlerChest
package fr.xenofight.mod.gui; import cpw.mods.fml.common.network.IGuiHandler; import fr.xenofight.mod.tileentity.TileEntityChestMod; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; public class GuiHandlerChest 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 TileEntityChestMod) { return new ContainerIronChest((TileEntityChestMod)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 TileEntityChestMod) { return new GuiIronChest((TileEntityChestMod)tile, player.inventory); } return null; } }
Class du container
package fr.xenofight.mod.gui; import fr.xenofight.mod.tileentity.TileEntityChestMod; 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.item.ItemStack; public class ContainerIronChest extends Container { private final TileEntityChestMod tileChest; public ContainerIronChest(TileEntityChestMod tile, InventoryPlayer inventory) { this.tileChest = tile; for (int j = 0; j < 6; ++j) { for (int k = 0; k < 9; ++k) { this.addSlotToContainer(new Slot(tile, k + j * 9, 8 + k * 18, 18 + j * 18)); } } this.bindPlayerInventory(inventory); } private void bindPlayerInventory(InventoryPlayer inv) { int j; for (j = 0; j < 3; ++j) { for (int k = 0; k < 9; ++k) { this.addSlotToContainer(new Slot(inv, k + j * 9 + 9, 8 + k * 18, 103 + j * 18 + 2 * 18)); } } for (j = 0; j < 9; ++j) { this.addSlotToContainer(new Slot(inv, j, 8 + j * 18, 161 + 2 * 18)); } } public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex) { ItemStack itemstack = null; Slot slot = (Slot)this.inventorySlots.get(slotIndex); if(slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); if(slotIndex < this.tileChest.getSizeInventory()) { if(!this.mergeItemStack(itemstack1, this.tileChest.getSizeInventory(), this.inventorySlots.size(), true)) { return null; } } else if(!this.mergeItemStack(itemstack1, 0, this.tileChest.getSizeInventory(), false)) { return null; } if(itemstack1.stackSize == 0) { slot.putStack((ItemStack)null); } else { slot.onSlotChanged(); } } return itemstack; } @Override public boolean canInteractWith(EntityPlayer player) { return this.tileChest.isUseableByPlayer(player); } public void onContainerClosed(EntityPlayer player) { super.onContainerClosed(player); this.tileChest.closeInventory(); } }
Class de tout les blocs
iron_chest = new Chest(Material.rock).setCreativeTab(Xenomod.XenoMod).setBlockName("iron_chest").setBlockTextureName(Reference.MOD_ID + ":iron_chest").setHardness(2); iron_chest.setHarvestLevel("pickaxe", 2);
Class chest
package fr.xenofight.mod.blocks; import fr.xenofight.mod.Xenomod; import fr.xenofight.mod.tileentity.TileEntityChestMod; import ibxm.Player; 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.MathHelper; import net.minecraft.world.World; public class Chest extends Block { public Chest(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 TileEntityChestMod(); } public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_) { if (world.isRemote) { return true; } else { player.openGui(Xenomod.instance, 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); 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 void onBlockPlacedBy(World p_149689_1_, int p_149689_2_, int p_149689_3_, int p_149689_4_, EntityLivingBase p_149689_5_, ItemStack p_149689_6_) { Block block = p_149689_1_.getBlock(p_149689_2_, p_149689_3_, p_149689_4_ - 1); Block block1 = p_149689_1_.getBlock(p_149689_2_, p_149689_3_, p_149689_4_ + 1); Block block2 = p_149689_1_.getBlock(p_149689_2_ - 1, p_149689_3_, p_149689_4_); Block block3 = p_149689_1_.getBlock(p_149689_2_ + 1, p_149689_3_, p_149689_4_); byte b0 = 0; int l = MathHelper.floor_double((double) (p_149689_5_.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; if (l == 0) { b0 = 2; } if (l == 1) { b0 = 5; } if (l == 2) { b0 = 3; } if (l == 3) { b0 = 4; } if (block != this && block1 != this && block2 != this && block3 != this) { p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_, b0, 3); } else { if ((block == this || block1 == this) && (b0 == 4 || b0 == 5)) { if (block == this) { p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_ - 1, b0, 3); } else { p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_ + 1, b0, 3); } p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_, b0, 3); } if ((block2 == this || block3 == this) && (b0 == 2 || b0 == 3)) { if (block2 == this) { p_149689_1_.setBlockMetadataWithNotify(p_149689_2_ - 1, p_149689_3_, p_149689_4_, b0, 3); } else { p_149689_1_.setBlockMetadataWithNotify(p_149689_2_ + 1, p_149689_3_, p_149689_4_, b0, 3); } p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_, b0, 3); } } if (p_149689_6_.hasDisplayName()) { ((TileEntityChest) p_149689_1_.getTileEntity(p_149689_2_, p_149689_3_, p_149689_4_)) .func_145976_a(p_149689_6_.getDisplayName()); } } }
PS : Si je suis encore en 1.7.10 ses par exigence de mon amis !
PS2 : Je m’excuse pour toutes les fautes ! -
Yo, Je veut pas dire mais https://www.youtube.com/watch?v=CHw5ri-QU6o
et regarde bien aussi a bien import les bonnes class car ca “[font=monospaceimport][font=monospace ibxm][font=monospace.][font=monospacePlayer][font=monospace;]” c’est pas un joueur minecraft mdr
et envoi aussi la class du TileEntity
Et Aussi le GuiHandler c’est un PAR MOD et non PAR BLOCK ok ? sinon ca va pas fonctionner
ou sinon ya le mod Ironchest que je pense tu connais (si tu connais pas, bah…. arrete minecraft et ne plus jamais me mot “forge” )
https://github.com/cpw/ironchest ta le code source la -
Merci pour ta réponse !
Oui je connais ironchest. Je recherchais justement le code source je te remercie.
Si j’arrive a réglé mon problème je passe en résolu.