Bâton de fouille
-
@‘SCAREX’:
@‘Xeolis’:
Bonjour,
Je travaille pour un projet de server AltisLife minecraft mais malheureusement nous n’avons pas réussi à faire de batons de fouilles.
Il nous en faudrait un dans les plus brèves délais car notre serveur ouvre dans 1 semaine et nous ne voyons pas comment réussir à y aboutir une bonne fois pour toutes.Pourquoi je fais ce poste ?
C’est simple parcequ’il nous faudrait de l’aide au plus vite pour faire ce baton de fouille.
Je ne vous demandes pas de me faire un plugins mais bien un script de baton de fouille permettant d’ouvrir l’inventaire de la personne quand on clique dessus mais aussi de ne pas pouvoir cliqué sour la personne quand elle est à plus de deux blocs de nous sinon il y aurai trop d’abus.Pour me contacter venir sur le TS à cette adresse: eu2.freets3.ovh:30176
Où est-ce que tu bloques ?
Je ne bloque pas je ne c’est pas faire c’est pour ca que je demande de l’aide
-
Si tu cherches quelqu’un pour faire ça pour toi, il faut aller dans la section recrutement.
-
@‘AymericRed’:
Le Container ne marchera pas, il faut que tu l’extends celui vanilla, regarde dans le GuiInventory le container qui est appelé dans le super(…) du constructeur.
Re,
Excusez moi du retard x)
Aymeric j’ai pas bien compris se que tu as dis.
Extends celui vanilla je vois pas du tout.
Et pour le super j’ai fais ça:
public class containerGui extends Container{ public containerGui(EntityPlayer p) { super(p.inventoryContainer);//prob ici } @Override public boolean canInteractWith(EntityPlayer playerIn) { return false; } @Override public ItemStack slotClick(int slotId, int clickedButton, int mode, EntityPlayer playerIn) { return null; }Mais j’ai une érreur au super "The constructor Container(Container) is undefined.
-
Je que je voulais te dire, c’est de changer
java extends Containerpar ```java
extends ContainerInventoryEDIT : ContainerPlayer au lieu de ContainerInventory. -
@‘AymericRed’:
Je que je voulais te dire, c’est de changer
java extends Containerpar ```java
extends ContainerInventoryEDIT : ContainerPlayer au lieu de ContainerInventory.D’acc ^^
Du coup j’ai ça:
public class containerGui extends ContainerPlayer{ public containerGui(InventoryPlayer playerInventory, boolean localWorld, EntityPlayer player) { super(playerInventory, localWorld, player); } @Override public boolean canInteractWith(EntityPlayer playerIn) { return false; } @Override public ItemStack slotClick(int slotId, int clickedButton, int mode, EntityPlayer playerIn) { return null; } }public class guiInv extends GuiInventory{ public guiInv(EntityPlayer p_i1094_1_) { super(p_i1094_1_); } @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { this.fontRendererObj.drawString(I18n.format("container.crafting", new Object[0]), 86, 16, 4210752); } }public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target) { if(target instanceof EntityPlayer) { EntityPlayer targetp = (EntityPlayer)target; playerIn.openGui(Main.instance, 0, playerIn.worldObj, (int) playerIn.posX, (int) playerIn.posY, (int) playerIn.posZ); playerIn.addChatComponentMessage(new ChatComponentText(EnumChatFormatting.GREEN + "Vous fouillez: " + targetp.getDisplayNameString())); targetp.addChatComponentMessage(new ChatComponentText(EnumChatFormatting.RED + playerIn.getDisplayNameString() + " vous fouille.")); } return false; }j’ai pas essayer en multi du coup je peux pas vous dire si ça marche, ça semble bon ?
Et j’ai une question, je dois pas définir la classe guiInv ou containerGui ? Simplement avec ce code ça marche ? playerIn.openGui(Main.instance, 0, playerIn.worldObj, (int) playerIn.posX, (int) playerIn.posY, (int) playerIn.posZ);
Merci

-
Ah mais en fait en repensant à tout, je suis en train de me dire que ça ne servait à rien de faire un container et un gui custom…
Quand tu fais “playerIn.openGui(Main.instance, 0, playerIn.worldObj, (int) playerIn.posX, (int) playerIn.posY, (int) playerIn.posZ);”, les fonctions getServerGuiElement et getClientGuiElement de ton GuiHandler vont être appelées, et là il faut respectivement retournerjava return new ContainerPlayer(le joueur.inventory, world.isRemote, le joueur);et ```java
return new GuiInventory(le joueur);J'espère que t'a compris car je sais pas si j'ai bien tout expliqué :) -
@‘AymericRed’:
Ah mais en fait en repensant à tout, je suis en train de me dire que ça ne servait à rien de faire un container et un gui custom…
Quand tu fais “playerIn.openGui(Main.instance, 0, playerIn.worldObj, (int) playerIn.posX, (int) playerIn.posY, (int) playerIn.posZ);”, les fonctions getServerGuiElement et getClientGuiElement de ton GuiHandler vont être appelées, et là il faut respectivement retournerjava return new ContainerPlayer(le joueur.inventory, world.isRemote, le joueur);et ```java
return new GuiInventory(le joueur);J'espère que t'a compris car je sais pas si j'ai bien tout expliqué :)Alors ouais j’ai compris je crois, par contre pour la variable pas trop je vois pas trop comment faire.
Du coup j’ai plus que le handler et la classe de l’item:
package com.CSC.net.item; import com.CSC.net.Main; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; public class bfouille extends Item { public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target) { System.out.println(Main.instance); if(target instanceof EntityPlayer) { EntityPlayer targetp = (EntityPlayer)target; playerIn.openGui(Main.instance, 0, playerIn.worldObj, (int) playerIn.posX, (int) playerIn.posY, (int) playerIn.posZ); playerIn.addChatComponentMessage(new ChatComponentText(EnumChatFormatting.GREEN + "Vous fouillez: " + targetp.getDisplayNameString())); targetp.addChatComponentMessage(new ChatComponentText(EnumChatFormatting.RED + playerIn.getDisplayNameString() + " vous fouille.")); } return false; } }package com.CSC.net.GUI; import net.minecraft.client.gui.inventory.GuiInventory; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ContainerPlayer; import net.minecraft.world.World; import net.minecraftforge.fml.common.network.IGuiHandler; public class GuiHandlerInv implements IGuiHandler{ @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { return new ContainerPlayer(player.inventory, world.isRemote, player); } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { return new GuiInventory(player); } } -
Alors là en fait le problème c’est que ça va ouvrir l’inventaire du joueur qui fait clic droit, pas de la cible, d’où l’utilité de la variable, fait une variable ```java
public static EntityPlayer currentTarget,Puis, comme il est possible que tu aies d'autres guis dans le futur, je te conseilles d'utiliser des ids uniques pour les guis (le "0" dans la ligne "playerIn.openGui(Main.instance, 0, playerIn.worldObj, (int) playerIn.posX, (int) playerIn.posY, (int) playerIn.posZ);", et de mettre un if(ID == quelquechose) dans tes fonctions "getServerGuiElement" et "getClientGuiElement". -
@‘AymericRed’:
Alors là en fait le problème c’est que ça va ouvrir l’inventaire du joueur qui fait clic droit, pas de la cible, d’où l’utilité de la variable, fait une variable ```java
public static EntityPlayer currentTarget,Puis, comme il est possible que tu aies d'autres guis dans le futur, je te conseilles d'utiliser des ids uniques pour les guis (le "0" dans la ligne "playerIn.openGui(Main.instance, 0, playerIn.worldObj, (int) playerIn.posX, (int) playerIn.posY, (int) playerIn.posZ);", et de mettre un if(ID == quelquechose) dans tes fonctions "getServerGuiElement" et "getClientGuiElement".Ah ouais! exact ^^
Merci beaucoup

Pour les id je suis obliger de faire un ; car sinon j’ai une érreur avec le return
public class GuiHandlerInv implements IGuiHandler{ public static EntityPlayer currentTarget; @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { if(ID == 0); return new ContainerPlayer(currentTarget.inventory, world.isRemote, currentTarget); } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { if(ID == 0); return new GuiInventory(currentTarget); } }Et dis moi pour register le handler j’ai fais ça:
NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandlerInv());Dans la foncton preInit de la classe principale c’est bien ça ?
Edit:
A oui aussi pour que on ne puisse pas prendre les items dans l’inv du joueur je fais comment ?
-
Pour les ids, retire le “;” après les if et met un return null à le fin des fonctions.
Pour le register oui c’est ça, tu peux aussi le mettre dans l’init.Et pour ne pas prendre les items…tu viens de me rappeler pourquoi il fallait un container, et donc un gui custom

Du coup recrées un gui custom extends GuiScreen dans lequel tu copie-colleras le contenu du “GuiInventory” en changeant bien le nom du constructeur par le nom de ta classe et en remplaçant le “super(new ContainerPlayer(…));” par un “super new ContainerPlayerCustom(…));” (ou autre nom), et ensuite, faudra créer ce container custom, extends ContainerPlayer. Puis utiliser ces deux classes dans le GuiHandler.
Enfin, dans ton container, tu fera ctrl+espace dans la classe, puis écriras “slotClick” afin de redéfinir la fonction “slotClick” pour que le clic ne fasse rien, il faudra que la fonction soit vide. -
@‘AymericRed’:
Pour les ids, retire le “;” après les if et met un return null à le fin des fonctions.
Pour le register oui c’est ça, tu peux aussi le mettre dans l’init.Et pour ne pas prendre les items…tu viens de me rappeler pourquoi il fallait un container, et donc un gui custom

Du coup recrées un gui custom extends GuiScreen dans lequel tu copie-colleras le contenu du “GuiInventory” en changeant bien le nom du constructeur par le nom de ta classe et en remplaçant le “super(new ContainerPlayer(…));” par un “super new ContainerPlayerCustom(…));” (ou autre nom), et ensuite, faudra créer ce container custom, extends ContainerPlayer. Puis utiliser ces deux classes dans le GuiHandler.
Enfin, dans ton container, tu fera ctrl+espace dans la classe, puis écriras “slotClick” afin de redéfinir la fonction “slotClick” pour que le clic ne fasse rien, il faudra que la fonction soit vide.Ah^^ okkk x)
Donc j’ai ça:
package com.CSC.net.GUI; import java.io.IOException; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.achievement.GuiAchievements; import net.minecraft.client.gui.achievement.GuiStats; import net.minecraft.client.gui.inventory.GuiContainerCreative; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.resources.I18n; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; public class GuiInv extends GuiScreen { /** The old x position of the mouse pointer */ private float oldMouseX; protected static final ResourceLocation inventoryBackground = new ResourceLocation("textures/gui/container/inventory.png"); /** The old y position of the mouse pointer */ private float oldMouseY; private static final String __OBFID = "CL_00000761"; public GuiInv(EntityPlayer player) { new ContainerPlayerCustom(player.inventory, true, player); } /** * Called from the main game loop to update the screen. */ /** * Adds the buttons (and other controls) to the screen in question. */ public void initGui() { this.buttonList.clear(); if (this.mc.playerController.isInCreativeMode()) { this.mc.displayGuiScreen(new GuiContainerCreative(this.mc.thePlayer)); } else { super.initGui(); } } /** * Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY */ protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { this.fontRendererObj.drawString(I18n.format("container.crafting", new Object[0]), 86, 16, 4210752); } /** * Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks */ public void drawScreen(int mouseX, int mouseY, float partialTicks) { super.drawScreen(mouseX, mouseY, partialTicks); this.oldMouseX = (float)mouseX; this.oldMouseY = (float)mouseY; } /** * Args : renderPartialTicks, mouseX, mouseY */ protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(inventoryBackground); int k = this.height; int l = this.width; this.drawTexturedModalRect(k, l, 0, 0, this.height, this.width); drawEntityOnScreen(k + 51, l + 75, 30, (float)(k + 51) - this.oldMouseX, (float)(l + 75 - 50) - this.oldMouseY, this.mc.thePlayer); } /** * Draws the entity to the screen. Args: xPos, yPos, scale, mouseX, mouseY, entityLiving */ public static void drawEntityOnScreen(int p_147046_0_, int p_147046_1_, int p_147046_2_, float p_147046_3_, float p_147046_4_, EntityLivingBase p_147046_5_) { GlStateManager.enableColorMaterial(); GlStateManager.pushMatrix(); GlStateManager.translate((float)p_147046_0_, (float)p_147046_1_, 50.0F); GlStateManager.scale((float)(-p_147046_2_), (float)p_147046_2_, (float)p_147046_2_); GlStateManager.rotate(180.0F, 0.0F, 0.0F, 1.0F); float f2 = p_147046_5_.renderYawOffset; float f3 = p_147046_5_.rotationYaw; float f4 = p_147046_5_.rotationPitch; float f5 = p_147046_5_.prevRotationYawHead; float f6 = p_147046_5_.rotationYawHead; GlStateManager.rotate(135.0F, 0.0F, 1.0F, 0.0F); RenderHelper.enableStandardItemLighting(); GlStateManager.rotate(-135.0F, 0.0F, 1.0F, 0.0F); GlStateManager.rotate(-((float)Math.atan((double)(p_147046_4_ / 40.0F))) * 20.0F, 1.0F, 0.0F, 0.0F); p_147046_5_.renderYawOffset = (float)Math.atan((double)(p_147046_3_ / 40.0F)) * 20.0F; p_147046_5_.rotationYaw = (float)Math.atan((double)(p_147046_3_ / 40.0F)) * 40.0F; p_147046_5_.rotationPitch = -((float)Math.atan((double)(p_147046_4_ / 40.0F))) * 20.0F; p_147046_5_.rotationYawHead = p_147046_5_.rotationYaw; p_147046_5_.prevRotationYawHead = p_147046_5_.rotationYaw; GlStateManager.translate(0.0F, 0.0F, 0.0F); RenderManager rendermanager = Minecraft.getMinecraft().getRenderManager(); rendermanager.setPlayerViewY(180.0F); rendermanager.setRenderShadow(false); rendermanager.renderEntityWithPosYaw(p_147046_5_, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F); rendermanager.setRenderShadow(true); p_147046_5_.renderYawOffset = f2; p_147046_5_.rotationYaw = f3; p_147046_5_.rotationPitch = f4; p_147046_5_.prevRotationYawHead = f5; p_147046_5_.rotationYawHead = f6; GlStateManager.popMatrix(); RenderHelper.disableStandardItemLighting(); GlStateManager.disableRescaleNormal(); GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit); GlStateManager.disableTexture2D(); GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit); } protected void actionPerformed(GuiButton button) throws IOException { if (button.id == 0) { this.mc.displayGuiScreen(new GuiAchievements(this, this.mc.thePlayer.getStatFileWriter())); } if (button.id == 1) { this.mc.displayGuiScreen(new GuiStats(this, this.mc.thePlayer.getStatFileWriter())); } } }package com.CSC.net.GUI; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.ContainerPlayer; import net.minecraft.item.ItemStack; public class ContainerPlayerCustom extends ContainerPlayer { public ContainerPlayerCustom(InventoryPlayer playerInventory, boolean localWorld, EntityPlayer player) { super(playerInventory, localWorld, player); } @Override public ItemStack slotClick(int slotId, int clickedButton, int mode, EntityPlayer playerIn) { return null; } }package com.CSC.net.item; import com.CSC.net.Main; import com.CSC.net.GUI.GuiHandlerInv; import com.CSC.net.GUI.GuiInv; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; public class bfouille extends Item { public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target) { System.out.println(Main.instance); if(target instanceof EntityPlayer) { EntityPlayer targetp = (EntityPlayer)target; GuiHandlerInv.currentTarget = targetp; playerIn.openGui(Main.instance, 0, playerIn.worldObj, (int) playerIn.posX, (int) playerIn.posY, (int) playerIn.posZ); playerIn.addChatComponentMessage(new ChatComponentText(EnumChatFormatting.GREEN + "Vous fouillez: " + targetp.getDisplayNameString())); targetp.addChatComponentMessage(new ChatComponentText(EnumChatFormatting.RED + playerIn.getDisplayNameString() + " vous fouille.")); } return false; } }package com.CSC.net.GUI; import net.minecraft.client.gui.inventory.GuiInventory; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ContainerPlayer; import net.minecraft.world.World; import net.minecraftforge.fml.common.network.IGuiHandler; public class GuiHandlerInv implements IGuiHandler{ public static EntityPlayer currentTarget; @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { if(ID == 0) return new ContainerPlayerCustom(currentTarget.inventory, world.isRemote, currentTarget); return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { if(ID == 0) return new GuiInv(currentTarget); return null; } }et le register:
NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandlerInv());Faut que j’essaye en multi j’ai pas encore essayer ^^
En tout cas super ! merci beaucoup

-
Oui c’est ça normalement ça devrait marcher