Résolu OnItemRightClick sur une entity.
-
Ouaip merci j’essaye ça je vous dis.
-
Crash réglé mais quand un joueur boit et que j’interagi avec le clic droit sa m’indique 0 et quand on inverse c’est pareil 0 aussi.
-
Tu as bien changé le code dans les autres items ?
-
J’ai j’ai changer la class At qui permet de prendre le niveau d’alcool par contre j’ai pas touché a la class LIIT qui est la class pour les boissons d’alcool est donc normalement ajouté le niveau d’alcool .
package com.AltisMine.mod; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.EnumAction; import net.minecraft.item.ItemFood; import net.minecraft.item.ItemStack; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.world.World; public class LIIT extends ItemFood { AT alcohol = new AT(); public LIIT (int itemID, int i, boolean b) { super(itemID, i, b); } public EnumAction getItemUseAction(ItemStack itemstack) { return EnumAction.drink; } public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { if (player.canEat(true)) { player.setItemInUse(stack, this.getMaxItemUseDuration(stack)); } return stack; } public int getMaxItemUseDuration(ItemStack stack) { return 32; } public ItemStack onEaten(ItemStack stack, World world, EntityPlayer player) { –stack.stackSize; ExtendedEntityPropAlcool.alcoolvl = Math.abs(ExtendedEntityPropAlcool.alcoolvl +1); player.getFoodStats().addStats(1, 2); // nombre de demi-gigots + saturation world.playSoundAtEntity(player, "random.burp", 0.5F, world.rand.nextFloat() * 0.1F + 0.9F); player.addPotionEffect(new PotionEffect(Potion.confusion.id, 315,0)); player.addPotionEffect(new PotionEffect(Potion.digSlowdown.id, 315,0)); player.addPotionEffect(new PotionEffect(Potion.hunger.id, 315,0)); player.addPotionEffect(new PotionEffect(Potion.weakness.id, 315,0)); return stack; } @Override public boolean hasEffect(ItemStack par1ItemStack){ return true; } }
-
ExtendedEntityPropAlcool prop = ExtendedEntityPropAlcool.get(player); prop.setAlcool(prop.getAlcool() + 1);
-
Et la variable alcoolvl de la classe ExtendedEntityPropAlcool ne doit pas être static. Sinon ton ExtendedEntityPropAlcool n’a plus aucun intérêt (les instances ça fait partie de la base Java vivement que le tutoriel soit publié).
-
**Hors-Sujet : ** Oui mais est-ce-que ceux qui ne prenez même pas la peine d’apprendre le Java sur OpenClassroom prendront la peine de regarder des tutoriels de Java sur MFF ? C’est la question que je me pose …
Vu que c’est du hors-sujet tu peux supprimer le message, je soulevais juste la question -
Une fois que le tutoriel sera disponible je ne vais plus m’embêter. Si quelqu’un demande de l’aide dans support pour les moddeurs et que je remarque que le minimum nécessaire pour coder en Java n’est pas acquis ça sera lock + lien vers le tutoriel.
À la base la description de la section c’est ça :Il s’agit de la section de support pour ceux qui créent des mods avec Forge. L’aide au modding va ici, cependant, gardez à l’esprit que ce n’est pas une école de programmation Java. Vous êtes censé avoir au moins certaines base de Java avant de poster ici.
-
J’ai fais comme vous avez dis mais j’ai un problème encore :
Detected ongoing potential memory leak. 4000 packets have leaked. Top offenders
[22:36:38] [Client thread/ERROR] [FML]: amm: : 4000
[22:36:38] [Client thread/ERROR] [FML]: Detected ongoing potential memory leak. 4100 packets have leaked. Top offenders
fuite de mémoire …
Class item:public class LIIT extends ItemFood { AT alcohol = new AT(); public LIIT (int itemID, int i, boolean b) { super(itemID, i, b); } public EnumAction getItemUseAction(ItemStack itemstack) { return EnumAction.drink; } public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { if (player.canEat(true)) { player.setItemInUse(stack, this.getMaxItemUseDuration(stack)); } return stack; } public int getMaxItemUseDuration(ItemStack stack) { return 32; } public ItemStack onEaten(ItemStack stack, World world, EntityPlayer player) { –stack.stackSize; ExtendedEntityPropAlcool prop = ExtendedEntityPropAlcool.get(player); prop.setAlcool(prop.getAlcool() + 1); player.getFoodStats().addStats(1, 2); // nombre de demi-gigots + saturation world.playSoundAtEntity(player, "random.burp", 0.5F, world.rand.nextFloat() * 0.1F + 0.9F); player.addPotionEffect(new PotionEffect(Potion.confusion.id, 315,0)); player.addPotionEffect(new PotionEffect(Potion.digSlowdown.id, 315,0)); player.addPotionEffect(new PotionEffect(Potion.hunger.id, 315,0)); player.addPotionEffect(new PotionEffect(Potion.weakness.id, 315,0)); return stack; } @Override public boolean hasEffect(ItemStack par1ItemStack){ return true; } }
class ExtendedEntity:
public class ExtendedEntityPropAlcool implements IExtendedEntityProperties { public final static String EXT_PROP_NAME = "ExtPropAlcool"; private int alcool = 0; private final EntityPlayer player; public ExtendedEntityPropAlcool(EntityPlayer player) { this.player = player; } @Override public void saveNBTData(NBTTagCompound compound) { NBTTagCompound properties = new NBTTagCompound(); properties.setInteger("alcool", this.alcool); compound.setTag(EXT_PROP_NAME, properties); } @Override public void loadNBTData(NBTTagCompound compound) { NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME); this.alcool = properties.getInteger("alcool"); } @Override public void init(Entity entity, World world) { // TODO Auto-generated method stub } public static final void register(EntityPlayer player) { player.registerExtendedProperties(ExtendedEntityPropAlcool.EXT_PROP_NAME, new ExtendedEntityPropAlcool(player)); } public static final ExtendedEntityPropAlcool get(EntityPlayer player) { return (ExtendedEntityPropAlcool) player.getExtendedProperties(EXT_PROP_NAME); } public final void sync() { PacketAlcool packetAlcool = new PacketAlcool(this.alcool); AltisMineMod.network.sendToServer(packetAlcool); if (!player.worldObj.isRemote) { EntityPlayerMP playerClient = (EntityPlayerMP) this.player; AltisMineMod.network.sendTo(packetAlcool, playerClient); } } private static String getSaveKey(EntityPlayer player) { return player.getDisplayName() + ":" + EXT_PROP_NAME; } public static void saveProxyData(EntityPlayer player) { ExtendedEntityPropAlcool playerData = ExtendedEntityPropAlcool.get(player); NBTTagCompound savedData = new NBTTagCompound(); playerData.saveNBTData(savedData); CommonProxy.storeEntityData(getSaveKey(player), savedData); } public static void loadProxyData(EntityPlayer player) { ExtendedEntityPropAlcool playerData = ExtendedEntityPropAlcool.get(player); NBTTagCompound savedData = CommonProxy .getEntityData(getSaveKey(player)); if (savedData != null) { playerData.loadNBTData(savedData); } playerData.sync(); } public void setAlcool(int taux) { this.alcool = taux; this.sync(); } public int getAlcool() { this.alcool = 0; if (alcool != 0) alcool = Math.abs(alcool / 2); else if (alcool == 0) { alcool = Math.abs(alcool); } return this.alcool; } }
-
public final void sync() { PacketAlcool packetAlcool = new PacketAlcool(this.alcool); AltisMineMod.network.sendToServer(packetAlcool); if (!player.worldObj.isRemote) { EntityPlayerMP playerClient = (EntityPlayerMP) this.player; AltisMineMod.network.sendTo(packetAlcool, playerClient); } }
Change en :
public final void sync() { PacketAlcool packetAlcool = new PacketAlcool(this.alcool); if (!player.worldObj.isRemote) { EntityPlayerMP playerClient = (EntityPlayerMP) this.player; AltisMineMod.network.sendTo(packetAlcool, playerClient); } else { AltisMineMod.network.sendToServer(packetAlcool); } }
-
Merci problème réglé par conte c’est exactement pareil 0 même lorsque on boit.
Edit:
Je suis sur que le problème vient d’ici:public int getAlcool() { this.alcool = 0; if (alcool != 0) alcool = Math.abs(alcool / 2); else if (alcool == 0) { alcool = Math.abs(alcool); } return this.alcool; } }
-
Mets directement return this.alcool;
-
"Je comprend pas pourquoi ça renvoie toujours 0 … : "
public int getAlcool() {
this.alcool = 0;xD
-
pareil marche toujours pas
-
Quelqu’un ?
-
Renvoies ton code actuel.
-
package com.AltisMine.mod; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import net.minecraftforge.common.IExtendedEntityProperties; import net.minecraftforge.event.entity.EntityEvent.EntityConstructing; public class ExtendedEntityPropAlcool implements IExtendedEntityProperties { public final static String EXT_PROP_NAME = "ExtPropAlcool"; private int alcool = 0; private final EntityPlayer player; public ExtendedEntityPropAlcool(EntityPlayer player) { this.player = player; } @Override public void saveNBTData(NBTTagCompound compound) { NBTTagCompound properties = new NBTTagCompound(); properties.setInteger("alcool", this.alcool); compound.setTag(EXT_PROP_NAME, properties); } @Override public void loadNBTData(NBTTagCompound compound) { NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME); this.alcool = properties.getInteger("alcool"); } @Override public void init(Entity entity, World world) { // TODO Auto-generated method stub } public static final void register(EntityPlayer player) { player.registerExtendedProperties(ExtendedEntityPropAlcool.EXT_PROP_NAME, new ExtendedEntityPropAlcool(player)); } public static final ExtendedEntityPropAlcool get(EntityPlayer player) { return (ExtendedEntityPropAlcool) player.getExtendedProperties(EXT_PROP_NAME); } public final void sync() { PacketAlcool packetAlcool = new PacketAlcool(this.alcool); if (!player.worldObj.isRemote) { EntityPlayerMP playerClient = (EntityPlayerMP) this.player; AltisMineMod.network.sendTo(packetAlcool, playerClient); } else { AltisMineMod.network.sendToServer(packetAlcool); } } private static String getSaveKey(EntityPlayer player) { return player.getDisplayName() + ":" + EXT_PROP_NAME; } public static void saveProxyData(EntityPlayer player) { ExtendedEntityPropAlcool playerData = ExtendedEntityPropAlcool.get(player); NBTTagCompound savedData = new NBTTagCompound(); playerData.saveNBTData(savedData); CommonProxy.storeEntityData(getSaveKey(player), savedData); } public static void loadProxyData(EntityPlayer player) { ExtendedEntityPropAlcool playerData = ExtendedEntityPropAlcool.get(player); NBTTagCompound savedData = CommonProxy .getEntityData(getSaveKey(player)); if (savedData != null) { playerData.loadNBTData(savedData); } playerData.sync(); } public void setAlcool(int taux) { this.alcool = taux; this.sync(); } public int getAlcool() { this.alcool = 0; if (alcool != 0) alcool = Math.abs(alcool / 2); else if (alcool == 0) { alcool = Math.abs(alcool); } return this.alcool; } }
Class bouteille d’alcool:
package com.AltisMine.mod; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.EnumAction; import net.minecraft.item.ItemFood; import net.minecraft.item.ItemStack; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.world.World; public class LIIT extends ItemFood { AT alcohol = new AT(); public LIIT (int itemID, int i, boolean b) { super(itemID, i, b); } public EnumAction getItemUseAction(ItemStack itemstack) { return EnumAction.drink; } public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { if (player.canEat(true)) { player.setItemInUse(stack, this.getMaxItemUseDuration(stack)); } return stack; } public int getMaxItemUseDuration(ItemStack stack) { return 32; } public ItemStack onEaten(ItemStack stack, World world, EntityPlayer player) { –stack.stackSize; ExtendedEntityPropAlcool prop = ExtendedEntityPropAlcool.get(player); prop.setAlcool(prop.getAlcool() + 1); player.getFoodStats().addStats(1, 2); // nombre de demi-gigots + saturation world.playSoundAtEntity(player, "random.burp", 0.5F, world.rand.nextFloat() * 0.1F + 0.9F); player.addPotionEffect(new PotionEffect(Potion.confusion.id, 315,0)); player.addPotionEffect(new PotionEffect(Potion.digSlowdown.id, 315,0)); player.addPotionEffect(new PotionEffect(Potion.hunger.id, 315,0)); player.addPotionEffect(new PotionEffect(Potion.weakness.id, 315,0)); return stack; } @Override public boolean hasEffect(ItemStack par1ItemStack){ return true; } }
-
Le getAlcool tu mets juste return alcool, c’est tout ! Pourquoi tout ce code ?
-
J’essaye ça je vous dis
-
@‘Snowy_1803’:
Le getAlcool tu mets juste return alcool, c’est tout ! Pourquoi tout ce code ?
Surtout que Robin le lui a déjà dit de mettre return this.alcool (et il l’a pas fait)
@‘robin4002’:
Mets directement return this.alcool;