Mob attiré vers un bloc
-
Tu as bien mis ton bloc dans un rayon de 9 blocs autour de l’entité et à la même hauteur ? Car le code que plaigon t’as donné ne prend pas en compte le bloc si il n’a pas la même coordonnée “y” que l’entité.
-
En effet, je n’ai pas pris en compte la hauteur. Il suffirait donc de rajouter une for loop, avec un int yOffset, bref c’est le même principe.
-
Oui j’ai bien mis le bloc a la meme hauteur et dans un rayon de 9
-
J’ai testé chez moi, tout marchait nikel. File entièrement la classe de ton entité, peut-être que le problème vient d’autre part. Essaie sinon de debug la task pour voir si le startExecuting est bien appelé…
-
@‘Plaigon’:
J’ai testé chez moi, tout marchait nikel. File entièrement la classe de ton entité, peut-être que le problème vient d’autre part. Essaie sinon de debug la task pour voir si le startExecuting est bien appelé…
Ok j’essaye
EDIT : Rien n’est appelé, pourrais tu m’envoyer tes fichier peut être que j’ai oublié quelque chose
-
Envoie plutôt ta classe Entity, je vais comparé avec la mienne.
As-tu également pensé à override cette méthode ?@Override protected boolean isAIEnabled() { return true; } -
@‘Plaigon’:
Envoie plutôt ta classe Entity, je vais comparé avec la mienne.
As-tu également pensé à override cette méthode ?@Override protected boolean isAIEnabled() { return true; }La classe de mon entité :
package fr.clashofclan.common; import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityCreature; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.init.Blocks; import net.minecraft.world.World; import net.minecraftforge.event.entity.EntityEvent; public class Barbare extends EntityCreature{ public Barbare(World world) { super(world); this.tasks.addTask(0, new EntityAIMoveToCustomBlock(this, 2.0D, ClashOfClan.blockTarget, 20)); //Pour bouger } public void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20D); this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.8D); } public Entity getEntityToAttack() { return null; } @Override protected boolean isAIEnabled() { return true; } }P.S. J’ai rajouté ce que tu as dis dans ton dernier post et maintenant il ne bouge plus :s
-
Rajoute une tâche pour wander.
-
@‘Plaigon’:
Rajoute une tâche pour wander.
Desolé je ne comprend pas

-
Alors ?
-
Faut pas marquer le sujet comme résolu si il n’y est pas u_u
Il t’a conseillé d’ajouter l’ “EntityAIWander” à la liste “tasks” de ton entitée, afin que celle-ci erre (de déplace d’elle même). -
@‘AymericRed’:
Faut pas marquer le sujet comme résolu si il n’y est pas u_u
Il t’a conseillé d’ajouter l’ “EntityAIWander” à la liste “tasks” de ton entitée, afin que celle-ci erre (de déplace d’elle même).1° Merci j’avais pas compris je vais essayer
2° j’ai pas fait exprès de le marquer en resolu o_o
3° je viens d’essayer et il bouge un peu une fois et apres plus rien il reste figéP.S. J’arrive pas a le mettre en non resolu
P.S.2 maintenant l’entite bouge des que je pose le block mais il fait des tours ( il bouge en rond) et il a une vitesse affolante alors que je l’ai mis a 0.8D -
File ta classe entière, on va jamais s’en sortir sinon…
-
@‘Plaigon’:
File ta classe entière, on va jamais s’en sortir sinon…
:::
package fr.clashofclan.common; import java.awt.Color; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.registry.EntityRegistry; import cpw.mods.fml.common.registry.GameRegistry; import fr.clashofclan.proxy.CommonProxy; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; @Mod(modid = "clashofclan", name = "Clash Of Clan", version = "1.0.0") public class ClashOfClan { @Instance("clashofclan") public static ClashOfClan instance; public static final String MODID = "clashofclan"; @SidedProxy(clientSide = "fr.clashofclan.proxy.ClientProxy", serverSide = "fr.clashofclan.proxy.CommonProxy") public static CommonProxy proxy; public static Block blockOr, blockElixir, blockTarget; @EventHandler public void preInit(FMLPreInitializationEvent event) { blockOr = new BlockOr().setBlockName("BlockOr").setCreativeTab(CreativeTabs.tabBlock); GameRegistry.registerBlock(blockOr, ItemBlockOr.class, "BlockOr"); blockElixir = new BlockElixir().setBlockName("BlockElixir").setCreativeTab(CreativeTabs.tabBlock); GameRegistry.registerBlock(blockElixir, ItemBlockElixir.class, "BlockElixir"); blockTarget = new BlockTarget().setBlockName("BlockTarget").setBlockTextureName("clashofclan:BlockTarget").setCreativeTab(CreativeTabs.tabBlock); GameRegistry.registerBlock(blockTarget, "BlockTarget"); } @EventHandler public void init(FMLInitializationEvent event) { proxy.registerRender(); // Mob : Constructeur EntityRegistry.registerGlobalEntityID(Constructeur.class, "Constructeur", EntityRegistry.findGlobalUniqueEntityId(), new Color(0, 255, 0).getRGB(), new Color(255, 0, 0).getRGB()); EntityRegistry.registerModEntity(Constructeur.class, "Constructeur", 420, this.instance, 40, 1, true); // Mob : Barbare EntityRegistry.registerGlobalEntityID(Barbare.class, "Barbare", EntityRegistry.findGlobalUniqueEntityId(), new Color(0, 255, 0).getRGB(), new Color(255, 0, 0).getRGB()); EntityRegistry.registerModEntity(Barbare.class, "Barbare", 421, this.instance, 40, 1, true); // Mob : Archer EntityRegistry.registerGlobalEntityID(Archer.class, "Archer", EntityRegistry.findGlobalUniqueEntityId(), new Color(0, 255, 0).getRGB(), new Color(255, 0, 0).getRGB()); EntityRegistry.registerModEntity(Archer.class, "Archer", 422, this.instance, 40, 1, true); // Mob : Chevaucheurcochon EntityRegistry.registerGlobalEntityID(Chevaucheurcochon.class, "Chevaucheurcochon", EntityRegistry.findGlobalUniqueEntityId(), new Color(0, 255, 0).getRGB(), new Color(255, 0, 0).getRGB()); EntityRegistry.registerModEntity(Chevaucheurcochon.class, "Chevaucheurcochon", 423, this.instance, 40, 1, true); } @EventHandler public void postInit(FMLPostInitializationEvent event) { } }::::::
package fr.clashofclan.proxy; import cpw.mods.fml.client.registry.RenderingRegistry; import fr.clashofclan.client.RenderArcher; import fr.clashofclan.client.RenderBarbare; import fr.clashofclan.client.RenderChevaucheurcochon; import fr.clashofclan.client.RenderConstructeur; import fr.clashofclan.common.Archer; import fr.clashofclan.common.Barbare; import fr.clashofclan.common.Chevaucheurcochon; import fr.clashofclan.common.Constructeur; import net.minecraft.client.model.ModelBiped; public class ClientProxy extends CommonProxy { @Override public void registerRender() { System.out.println("méthode côté client"); RenderingRegistry.registerEntityRenderingHandler(Constructeur.class, new RenderConstructeur(new ModelBiped(), 0.5F)); RenderingRegistry.registerEntityRenderingHandler(Archer.class, new RenderArcher(new ModelBiped(), 0.5F)); RenderingRegistry.registerEntityRenderingHandler(Barbare.class, new RenderBarbare(new ModelBiped(), 0.5F)); RenderingRegistry.registerEntityRenderingHandler(Chevaucheurcochon.class, new RenderChevaucheurcochon(new ModelBiped(), 0.5F)); } }::::::
package fr.clashofclan.common; import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityCreature; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.EntityAIWander; import net.minecraft.init.Blocks; import net.minecraft.world.World; import net.minecraftforge.event.entity.EntityEvent; public class Archer extends EntityCreature{ public Archer(World world) { super(world); this.tasks.addTask(0, new EntityAIMoveToCustomBlock(this, 0.5D, ClashOfClan.blockTarget, 9)); this.tasks.addTask(1, new EntityAIWander(this, 1.0D)); } public void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20D); this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.5D); } public Entity getEntityToAttack() { return null; } @Override protected boolean isAIEnabled() { return true; } }::::::
package fr.clashofclan.client; import fr.clashofclan.common.Archer; import fr.clashofclan.common.ClashOfClan; import net.minecraft.client.model.ModelBiped; import net.minecraft.client.renderer.entity.RenderBiped; import net.minecraft.entity.EntityLiving; import net.minecraft.util.ResourceLocation; public class RenderArcher extends RenderBiped { public final ResourceLocation texture = new ResourceLocation(ClashOfClan.MODID, "textures/entity/Archer.png"); public RenderArcher(ModelBiped model, float shadow) { super(model, shadow); } protected ResourceLocation getEntityTexture(EntityLiving living) { return this.getArcherTexture((Archer)living); } private ResourceLocation getArcherTexture(Archer Archer) { return texture; } }::::::
package fr.clashofclan.common; import net.minecraft.block.Block; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.ai.EntityAIBase; public class EntityAIMoveToCustomBlock extends EntityAIBase { private EntityLiving livingEntity; private double xPosition; private double yPosition; private double zPosition; private double speed; private Block targetBlockType; private int radiusDetection; public EntityAIMoveToCustomBlock(EntityLiving p_i1648_1_, double p_i1648_2_, Block targetBlockType, int radiusDetection) { this.livingEntity = p_i1648_1_; this.speed = p_i1648_2_; this.targetBlockType = targetBlockType; this.radiusDetection = radiusDetection; this.setMutexBits(1); } /** * Returns whether the EntityAIBase should begin execution. */ public boolean shouldExecute() { for(int xOffset = -radiusDetection; xOffset < radiusDetection; xOffset++)//On remonte l'axe des X { for(int yOffset = -radiusDetection; yOffset < radiusDetection; yOffset++)//On remonte l'axe des Y { for(int zOffset = -radiusDetection; zOffset < radiusDetection; zOffset++)//On remonte l'axe des Z { if(livingEntity.worldObj.getBlock((int)livingEntity.posX + xOffset, (int)livingEntity.posY, (int)livingEntity.posZ + zOffset) == targetBlockType)//Si le block situé à un couple spécifique de coordonnées (précédemment remontées via les for loops), correspond à ton block recherché { //Alors on affecte au couple de positions que l'entity va devoir suivre this.xPosition = livingEntity.posX + xOffset; this.yPosition = livingEntity.posY + yOffset; this.zPosition = livingEntity.posZ + zOffset; return true; } } } } return false; } /** * Returns whether an in-progress EntityAIBase should continue executing */ public boolean continueExecuting() { return !this.livingEntity.getNavigator().noPath();//On continue tant que l'entity a un PathNavigate d'instancié } /** * Execute a one shot task or start executing a continuous task */ public void startExecuting() { this.livingEntity.getNavigator().tryMoveToXYZ(this.xPosition, this.yPosition, this.zPosition, this.speed);//On la fait se déplacer si shouldExecute a renvoyé true, donc si le couple de positions a forcément été reset à de bonnes valeurs } public void resetTask() { super.resetTask(); } public void updateTask() { this.livingEntity.getNavigator().tryMoveToXYZ(this.xPosition, this.yPosition, this.zPosition, this.speed); } }::::::
package fr.clashofclan.common; import java.util.List; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; public class BlockTarget extends Block { protected BlockTarget() { super(Material.rock); } }:::
Voila je crois qu’il y a tousEDIT: Finalement j’ai reussi j’ai maj les codes pour ce qui les veulent
-
Vous avez trouvé l’erreur(s) ?