Jump to content

Recommended Posts

Posted

Hello all  sorry if this has already been solved  . but i have been trying  to add  attack to my mob  "Guard"

however no luck so far  maybe i haven't done enough  but this is really getting to me. 

i think Im making the mob passive  but don't  Know  how to change that please help  in new to modding and iv come back to after a while of frustration and failed attempts thanks  in advance  code  from baseMod and the GuardMod files  is below

 

 

 

BaseMod

 

 

 

ackage mcmkingdoms.mod.guard;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.entity.RenderLiving;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
public class Guard extends EntityMob
{
public Guard(World par1World)
{
     super(par1World);
     this.setSize(0.9F, 1.3F);
     this.getNavigator().setAvoidsWater(true);
     this.tasks.addTask(0, new EntityAISwimming(this));
     this.tasks.addTask(2, new EntityAIWander(this, 1.0D));
     this.tasks.addTask(3, new EntityAILookIdle(this));
     this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true));
     this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 0, true));
    

}
/**
     * Returns true if the newer Entity AI code should be run
     */
public boolean isAIEnabled()
{
     return true;
}
protected void applyEntityAttributes()
{
     super.applyEntityAttributes();
     this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setAttribute(50.0D);
     this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setAttribute(0.20000000298023224D);
     this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setAttribute(5.0D);
}

public int getTotalArmorValue()
{
     int i = super.getTotalArmorValue() + 2;
     if (i > 20)
     {
         i = 20;
     }
     return i;
}
public boolean attackEntityFrom(DamageSource par1DamageSource, float par2)
{
     if (this.isEntityInvulnerable())
     {
         return false;
     }
     else
     {
         Entity entity = par1DamageSource.getEntity();
        
         if (entity != null && !(entity instanceof EntityPlayer) && !(entity instanceof EntityArrow))
         {
             par2 = (par2 + 1.0F) / 2.0F;
         }
         return super.attackEntityFrom(par1DamageSource, par2);
     }
}
    

/**
     * Returns the sound this mob makes while it's alive.
     */
protected String getLivingSound()
{
     return "mob.cow.say";
}
/**
     * Returns the sound this mob makes when it is hurt.
     */
protected String getHurtSound()
{
     return "mob.cow.hurt";
}
/**
     * Returns the sound this mob makes on death.
     */
protected String getDeathSound()
{
     return "mob.cow.hurt";
}
/**
     * Plays step sound at given x, y, z for the entity
     */
protected void playStepSound(int par1, int par2, int par3, int par4)
{
     this.playSound("mob.cow.step", 0.15F, 1.0F);
}
/**
     * Returns the volume for the sounds this mob makes.
     */
protected float getSoundVolume()
{
     return 0.4F;
}
/**
     * Returns the item ID for the item the mob drops on death.
     */
protected int getDropItemId()
{
     return Item.legsIron.itemID;
}
// sets Armour/Weapons the mob is using
public void setCurrentItemOrArmor(int par1, ItemStack ItemStack)
{
     super.setCurrentItemOrArmor(par1,ItemStack);
}

{
     this.setCurrentItemOrArmor(0, new ItemStack(Item.swordIron));
     this.setCurrentItemOrArmor(1, new ItemStack(Item.helmetIron));
     this.setCurrentItemOrArmor(2, new ItemStack(Item.bootsIron));
     this.setCurrentItemOrArmor(3, new ItemStack(Item.plateIron));
     this.setCurrentItemOrArmor(4, new ItemStack(Item.legsIron));
    
}
}

 

 

 

 

GuardMod

 

 

 

 

package mcmkingdoms.mod;
import mcmkingdoms.mod.guard.Guard;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityEggInfo;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.item.EnumToolMaterial;
import net.minecraft.item.Item;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.common.EnumHelper;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler; // used in 1.6.2
//import cpw.mods.fml.common.Mod.PreInit; // used in 1.5.2
//import cpw.mods.fml.common.Mod.Init;     // used in 1.5.2
//import cpw.mods.fml.common.Mod.PostInit; // used in 1.5.2
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.network.NetworkMod;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

@Mod(modid= McmkingdomsInfo.ID , name= McmkingdomsInfo.NAME , version= McmkingdomsInfo.VERS)
@NetworkMod(clientSideRequired=true)
public class basemod {

public EnumToolMaterial hardenedIron = EnumHelper.addToolMaterial("Hardened Iron", 3, 20000,9.0f , 9.0f, 20);
//tools

//public final Item longSword = new LongSword(502,hardenedIron).setCreativeTab(CreativeTabs.tabCombat).setUnlocalizedName("LongSword").setTextureName("mod:strongstone");
public final static Block StrongStone = new StrongStone(500,Material.rock).setHardness(100000.f).setStepSound(Block.soundStoneFootstep).setUnlocalizedName("StrongStone").setCreativeTab(CreativeTabs.tabBlock).setTextureName("mod:strongstone");
public final static Item FirstItem = new FirstItem(5000);
public final static Item flagItem = new FlagItem(5005).setTextureName("mod:flag");
public final static Block StrongGlass = new FirstBlock(4095,Material.glass).setHardness(100000.f).setStepSound(Block.soundGlassFootstep).setUnlocalizedName("StrongGlass").setCreativeTab(CreativeTabs.tabBlock).setTextureName("mod:strongglass4");
//public final static Item HardenedIron = new FirstItem (5001).setMaxStackSize(64).setCreativeTab(CreativeTabs.tabMisc).setUnlocalizedName("HardenedIron").setTextureName("mod:test");


// The instance of your mod that Forge uses.
     @Instance(value = McmkingdomsInfo.NAME)
     public static basemod instance;
    
     // Says where the client and server 'proxy' code is loaded.
     @SidedProxy(clientSide="mcmkingdoms.mod.client.clientProxy", serverSide="mcmkingdoms.mod.CommonProxy")
     public static CommonProxy proxy;
    
     @EventHandler // used in 1.6.2
     //@PreInit // used in 1.5.2
     public void preInit(FMLPreInitializationEvent event) {
             // Stub Method
     }
    
     @EventHandler // used in 1.6.2
     //@Init     // used in 1.5.2
     public void load(FMLInitializationEvent event) {
             proxy.registerRenderers();
            
         // GameRegistry.registerItem(longSword,"LongSword");
         // LanguageRegistry.addName(longSword ,"Long Sword");
            
            
            
             GameRegistry.registerBlock(StrongStone,"StrongStone");
             LanguageRegistry.addName(StrongStone ,"Strong Stone");
            
             GameRegistry.registerItem(flagItem,"Flag");
             LanguageRegistry.addName(flagItem ,"Flag");
            
             GameRegistry.registerBlock(StrongGlass, "StrongGlass");
             LanguageRegistry.addName(StrongGlass ,"Strong Glass");
            
             MinecraftForge.setBlockHarvestLevel(StrongStone,"Pickaxe",3);
             MinecraftForge.setBlockHarvestLevel(StrongGlass,"Pickaxe",2);
            
             //mob
            
             registerEntity(Guard.class,"Gaurd",0xeaeae9, 0xc99a03);
             LanguageRegistry.instance().addStringLocalization("entity.gaurd.name","Gaurd");
     }
             public void registerEntity(Class<? extends Entity> entityClass, String entityName, int bkEggColor, int fgEggColor) {
                 int id = EntityRegistry.findGlobalUniqueEntityId();

                 EntityRegistry.registerGlobalEntityID(entityClass, entityName, id);
                 EntityList.entityEggs.put(Integer.valueOf(id), new EntityEggInfo(id, bkEggColor, fgEggColor));
         }

         public void addSpawn(Class<? extends EntityLiving> entityClass, int spawnProb, int min, int max, BiomeGenBase[] biomes) {
                 if (spawnProb > 0) {
                         EntityRegistry.addSpawn(entityClass, spawnProb, min, max, EnumCreatureType.monster, biomes);
                 }
         }
                            
     //     MinecraftForge.setBlockHarvestLevel(StrongStoneStair,"Axe",3);
     //     GameRegistry.registerBlock(StrongStoneStair,"StrongStone");
     //     LanguageRegistry.addName(StrongStoneStair ,"Strong Stone Stair");
        
//     MinecraftForge.setBlockHarvestLevel(StrongStoneStair,"Axe",3);
            
    
    
     @EventHandler // used in 1.6.2
     //@PostInit // used in 1.5.2
     public void postInit(FMLPostInitializationEvent event) {
             // Stub Method
     }
}

 

 

  • 1 month later...
Posted

Hello all  sorry if this has already been solved  . but i have been trying  to add  attack to my mob  "Guard"

however no luck so far  maybe i haven't done enough  but this is really getting to me. 

i think Im making the mob passive  but don't  Know  how to change that please help  in new to modding and iv come back to after a while of frustration and failed attempts thanks  in advance  code  from baseMod and the GuardMod files  is below

 

 

 

BaseMod

 

 

 

ackage mcmkingdoms.mod.guard;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.entity.RenderLiving;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
public class Guard extends EntityMob
{
public Guard(World par1World)
{
     super(par1World);
     this.setSize(0.9F, 1.3F);
     this.getNavigator().setAvoidsWater(true);
     this.tasks.addTask(0, new EntityAISwimming(this));
     this.tasks.addTask(2, new EntityAIWander(this, 1.0D));
     this.tasks.addTask(3, new EntityAILookIdle(this));
     this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true));
     this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 0, true));
    

}
/**
     * Returns true if the newer Entity AI code should be run
     */
public boolean isAIEnabled()
{
     return true;
}
protected void applyEntityAttributes()
{
     super.applyEntityAttributes();
     this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setAttribute(50.0D);
     this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setAttribute(0.20000000298023224D);
     this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setAttribute(5.0D);
}

public int getTotalArmorValue()
{
     int i = super.getTotalArmorValue() + 2;
     if (i > 20)
     {
         i = 20;
     }
     return i;
}
public boolean attackEntityFrom(DamageSource par1DamageSource, float par2)
{
     if (this.isEntityInvulnerable())
     {
         return false;
     }
     else
     {
         Entity entity = par1DamageSource.getEntity();
        
         if (entity != null && !(entity instanceof EntityPlayer) && !(entity instanceof EntityArrow))
         {
             par2 = (par2 + 1.0F) / 2.0F;
         }
         return super.attackEntityFrom(par1DamageSource, par2);
     }
}
    

/**
     * Returns the sound this mob makes while it's alive.
     */
protected String getLivingSound()
{
     return "mob.cow.say";
}
/**
     * Returns the sound this mob makes when it is hurt.
     */
protected String getHurtSound()
{
     return "mob.cow.hurt";
}
/**
     * Returns the sound this mob makes on death.
     */
protected String getDeathSound()
{
     return "mob.cow.hurt";
}
/**
     * Plays step sound at given x, y, z for the entity
     */
protected void playStepSound(int par1, int par2, int par3, int par4)
{
     this.playSound("mob.cow.step", 0.15F, 1.0F);
}
/**
     * Returns the volume for the sounds this mob makes.
     */
protected float getSoundVolume()
{
     return 0.4F;
}
/**
     * Returns the item ID for the item the mob drops on death.
     */
protected int getDropItemId()
{
     return Item.legsIron.itemID;
}
// sets Armour/Weapons the mob is using
public void setCurrentItemOrArmor(int par1, ItemStack ItemStack)
{
     super.setCurrentItemOrArmor(par1,ItemStack);
}

{
     this.setCurrentItemOrArmor(0, new ItemStack(Item.swordIron));
     this.setCurrentItemOrArmor(1, new ItemStack(Item.helmetIron));
     this.setCurrentItemOrArmor(2, new ItemStack(Item.bootsIron));
     this.setCurrentItemOrArmor(3, new ItemStack(Item.plateIron));
     this.setCurrentItemOrArmor(4, new ItemStack(Item.legsIron));
    
}
}

 

 

 

 

GuardMod

 

 

 

 

package mcmkingdoms.mod;
import mcmkingdoms.mod.guard.Guard;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityEggInfo;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.item.EnumToolMaterial;
import net.minecraft.item.Item;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.common.EnumHelper;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler; // used in 1.6.2
//import cpw.mods.fml.common.Mod.PreInit; // used in 1.5.2
//import cpw.mods.fml.common.Mod.Init;     // used in 1.5.2
//import cpw.mods.fml.common.Mod.PostInit; // used in 1.5.2
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.network.NetworkMod;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

@Mod(modid= McmkingdomsInfo.ID , name= McmkingdomsInfo.NAME , version= McmkingdomsInfo.VERS)
@NetworkMod(clientSideRequired=true)
public class basemod {

public EnumToolMaterial hardenedIron = EnumHelper.addToolMaterial("Hardened Iron", 3, 20000,9.0f , 9.0f, 20);
//tools

//public final Item longSword = new LongSword(502,hardenedIron).setCreativeTab(CreativeTabs.tabCombat).setUnlocalizedName("LongSword").setTextureName("mod:strongstone");
public final static Block StrongStone = new StrongStone(500,Material.rock).setHardness(100000.f).setStepSound(Block.soundStoneFootstep).setUnlocalizedName("StrongStone").setCreativeTab(CreativeTabs.tabBlock).setTextureName("mod:strongstone");
public final static Item FirstItem = new FirstItem(5000);
public final static Item flagItem = new FlagItem(5005).setTextureName("mod:flag");
public final static Block StrongGlass = new FirstBlock(4095,Material.glass).setHardness(100000.f).setStepSound(Block.soundGlassFootstep).setUnlocalizedName("StrongGlass").setCreativeTab(CreativeTabs.tabBlock).setTextureName("mod:strongglass4");
//public final static Item HardenedIron = new FirstItem (5001).setMaxStackSize(64).setCreativeTab(CreativeTabs.tabMisc).setUnlocalizedName("HardenedIron").setTextureName("mod:test");


// The instance of your mod that Forge uses.
     @Instance(value = McmkingdomsInfo.NAME)
     public static basemod instance;
    
     // Says where the client and server 'proxy' code is loaded.
     @SidedProxy(clientSide="mcmkingdoms.mod.client.clientProxy", serverSide="mcmkingdoms.mod.CommonProxy")
     public static CommonProxy proxy;
    
     @EventHandler // used in 1.6.2
     //@PreInit // used in 1.5.2
     public void preInit(FMLPreInitializationEvent event) {
             // Stub Method
     }
    
     @EventHandler // used in 1.6.2
     //@Init     // used in 1.5.2
     public void load(FMLInitializationEvent event) {
             proxy.registerRenderers();
            
         // GameRegistry.registerItem(longSword,"LongSword");
         // LanguageRegistry.addName(longSword ,"Long Sword");
            
            
            
             GameRegistry.registerBlock(StrongStone,"StrongStone");
             LanguageRegistry.addName(StrongStone ,"Strong Stone");
            
             GameRegistry.registerItem(flagItem,"Flag");
             LanguageRegistry.addName(flagItem ,"Flag");
            
             GameRegistry.registerBlock(StrongGlass, "StrongGlass");
             LanguageRegistry.addName(StrongGlass ,"Strong Glass");
            
             MinecraftForge.setBlockHarvestLevel(StrongStone,"Pickaxe",3);
             MinecraftForge.setBlockHarvestLevel(StrongGlass,"Pickaxe",2);
            
             //mob
            
             registerEntity(Guard.class,"Gaurd",0xeaeae9, 0xc99a03);
             LanguageRegistry.instance().addStringLocalization("entity.gaurd.name","Gaurd");
     }
             public void registerEntity(Class<? extends Entity> entityClass, String entityName, int bkEggColor, int fgEggColor) {
                 int id = EntityRegistry.findGlobalUniqueEntityId();

                 EntityRegistry.registerGlobalEntityID(entityClass, entityName, id);
                 EntityList.entityEggs.put(Integer.valueOf(id), new EntityEggInfo(id, bkEggColor, fgEggColor));
         }

         public void addSpawn(Class<? extends EntityLiving> entityClass, int spawnProb, int min, int max, BiomeGenBase[] biomes) {
                 if (spawnProb > 0) {
                         EntityRegistry.addSpawn(entityClass, spawnProb, min, max, EnumCreatureType.monster, biomes);
                 }
         }
                            
     //     MinecraftForge.setBlockHarvestLevel(StrongStoneStair,"Axe",3);
     //     GameRegistry.registerBlock(StrongStoneStair,"StrongStone");
     //     LanguageRegistry.addName(StrongStoneStair ,"Strong Stone Stair");
        
//     MinecraftForge.setBlockHarvestLevel(StrongStoneStair,"Axe",3);
            
    
    
     @EventHandler // used in 1.6.2
     //@PostInit // used in 1.5.2
     public void postInit(FMLPostInitializationEvent event) {
             // Stub Method
     }
}

 

 

 

Try to use that tags in your mob class:

this.tasks.addTask(1, new EntityAIFollowCalled(this, this.moveSpeed, 5.0F, 2.0F));
this.targetTasks.addTask(1, new EntityAINearestAttackableTarget(this,EntityPlayer.class, 25.0F, 0, true));

Posted

Hello all  sorry if this has already been solved  . but i have been trying  to add  attack to my mob  "Guard"

however no luck so far  maybe i haven't done enough  but this is really getting to me. 

i think Im making the mob passive  but don't  Know  how to change that please help  in new to modding and iv come back to after a while of frustration and failed attempts thanks  in advance  code  from baseMod and the GuardMod files  is below

 

 

 

BaseMod

 

 

 

ackage mcmkingdoms.mod.guard;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.entity.RenderLiving;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
public class Guard extends EntityMob
{
public Guard(World par1World)
{
     super(par1World);
     this.setSize(0.9F, 1.3F);
     this.getNavigator().setAvoidsWater(true);
     this.tasks.addTask(0, new EntityAISwimming(this));
     this.tasks.addTask(2, new EntityAIWander(this, 1.0D));
     this.tasks.addTask(3, new EntityAILookIdle(this));
     this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true));
     this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 0, true));
    

}
/**
     * Returns true if the newer Entity AI code should be run
     */
public boolean isAIEnabled()
{
     return true;
}
protected void applyEntityAttributes()
{
     super.applyEntityAttributes();
     this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setAttribute(50.0D);
     this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setAttribute(0.20000000298023224D);
     this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setAttribute(5.0D);
}

public int getTotalArmorValue()
{
     int i = super.getTotalArmorValue() + 2;
     if (i > 20)
     {
         i = 20;
     }
     return i;
}
public boolean attackEntityFrom(DamageSource par1DamageSource, float par2)
{
     if (this.isEntityInvulnerable())
     {
         return false;
     }
     else
     {
         Entity entity = par1DamageSource.getEntity();
        
         if (entity != null && !(entity instanceof EntityPlayer) && !(entity instanceof EntityArrow))
         {
             par2 = (par2 + 1.0F) / 2.0F;
         }
         return super.attackEntityFrom(par1DamageSource, par2);
     }
}
    

/**
     * Returns the sound this mob makes while it's alive.
     */
protected String getLivingSound()
{
     return "mob.cow.say";
}
/**
     * Returns the sound this mob makes when it is hurt.
     */
protected String getHurtSound()
{
     return "mob.cow.hurt";
}
/**
     * Returns the sound this mob makes on death.
     */
protected String getDeathSound()
{
     return "mob.cow.hurt";
}
/**
     * Plays step sound at given x, y, z for the entity
     */
protected void playStepSound(int par1, int par2, int par3, int par4)
{
     this.playSound("mob.cow.step", 0.15F, 1.0F);
}
/**
     * Returns the volume for the sounds this mob makes.
     */
protected float getSoundVolume()
{
     return 0.4F;
}
/**
     * Returns the item ID for the item the mob drops on death.
     */
protected int getDropItemId()
{
     return Item.legsIron.itemID;
}
// sets Armour/Weapons the mob is using
public void setCurrentItemOrArmor(int par1, ItemStack ItemStack)
{
     super.setCurrentItemOrArmor(par1,ItemStack);
}

{
     this.setCurrentItemOrArmor(0, new ItemStack(Item.swordIron));
     this.setCurrentItemOrArmor(1, new ItemStack(Item.helmetIron));
     this.setCurrentItemOrArmor(2, new ItemStack(Item.bootsIron));
     this.setCurrentItemOrArmor(3, new ItemStack(Item.plateIron));
     this.setCurrentItemOrArmor(4, new ItemStack(Item.legsIron));
    
}
}

 

 

 

 

GuardMod

 

 

 

 

package mcmkingdoms.mod;
import mcmkingdoms.mod.guard.Guard;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityEggInfo;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.item.EnumToolMaterial;
import net.minecraft.item.Item;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.common.EnumHelper;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler; // used in 1.6.2
//import cpw.mods.fml.common.Mod.PreInit; // used in 1.5.2
//import cpw.mods.fml.common.Mod.Init;     // used in 1.5.2
//import cpw.mods.fml.common.Mod.PostInit; // used in 1.5.2
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.network.NetworkMod;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

@Mod(modid= McmkingdomsInfo.ID , name= McmkingdomsInfo.NAME , version= McmkingdomsInfo.VERS)
@NetworkMod(clientSideRequired=true)
public class basemod {

public EnumToolMaterial hardenedIron = EnumHelper.addToolMaterial("Hardened Iron", 3, 20000,9.0f , 9.0f, 20);
//tools

//public final Item longSword = new LongSword(502,hardenedIron).setCreativeTab(CreativeTabs.tabCombat).setUnlocalizedName("LongSword").setTextureName("mod:strongstone");
public final static Block StrongStone = new StrongStone(500,Material.rock).setHardness(100000.f).setStepSound(Block.soundStoneFootstep).setUnlocalizedName("StrongStone").setCreativeTab(CreativeTabs.tabBlock).setTextureName("mod:strongstone");
public final static Item FirstItem = new FirstItem(5000);
public final static Item flagItem = new FlagItem(5005).setTextureName("mod:flag");
public final static Block StrongGlass = new FirstBlock(4095,Material.glass).setHardness(100000.f).setStepSound(Block.soundGlassFootstep).setUnlocalizedName("StrongGlass").setCreativeTab(CreativeTabs.tabBlock).setTextureName("mod:strongglass4");
//public final static Item HardenedIron = new FirstItem (5001).setMaxStackSize(64).setCreativeTab(CreativeTabs.tabMisc).setUnlocalizedName("HardenedIron").setTextureName("mod:test");


// The instance of your mod that Forge uses.
     @Instance(value = McmkingdomsInfo.NAME)
     public static basemod instance;
    
     // Says where the client and server 'proxy' code is loaded.
     @SidedProxy(clientSide="mcmkingdoms.mod.client.clientProxy", serverSide="mcmkingdoms.mod.CommonProxy")
     public static CommonProxy proxy;
    
     @EventHandler // used in 1.6.2
     //@PreInit // used in 1.5.2
     public void preInit(FMLPreInitializationEvent event) {
             // Stub Method
     }
    
     @EventHandler // used in 1.6.2
     //@Init     // used in 1.5.2
     public void load(FMLInitializationEvent event) {
             proxy.registerRenderers();
            
         // GameRegistry.registerItem(longSword,"LongSword");
         // LanguageRegistry.addName(longSword ,"Long Sword");
            
            
            
             GameRegistry.registerBlock(StrongStone,"StrongStone");
             LanguageRegistry.addName(StrongStone ,"Strong Stone");
            
             GameRegistry.registerItem(flagItem,"Flag");
             LanguageRegistry.addName(flagItem ,"Flag");
            
             GameRegistry.registerBlock(StrongGlass, "StrongGlass");
             LanguageRegistry.addName(StrongGlass ,"Strong Glass");
            
             MinecraftForge.setBlockHarvestLevel(StrongStone,"Pickaxe",3);
             MinecraftForge.setBlockHarvestLevel(StrongGlass,"Pickaxe",2);
            
             //mob
            
             registerEntity(Guard.class,"Gaurd",0xeaeae9, 0xc99a03);
             LanguageRegistry.instance().addStringLocalization("entity.gaurd.name","Gaurd");
     }
             public void registerEntity(Class<? extends Entity> entityClass, String entityName, int bkEggColor, int fgEggColor) {
                 int id = EntityRegistry.findGlobalUniqueEntityId();

                 EntityRegistry.registerGlobalEntityID(entityClass, entityName, id);
                 EntityList.entityEggs.put(Integer.valueOf(id), new EntityEggInfo(id, bkEggColor, fgEggColor));
         }

         public void addSpawn(Class<? extends EntityLiving> entityClass, int spawnProb, int min, int max, BiomeGenBase[] biomes) {
                 if (spawnProb > 0) {
                         EntityRegistry.addSpawn(entityClass, spawnProb, min, max, EnumCreatureType.monster, biomes);
                 }
         }
                            
     //     MinecraftForge.setBlockHarvestLevel(StrongStoneStair,"Axe",3);
     //     GameRegistry.registerBlock(StrongStoneStair,"StrongStone");
     //     LanguageRegistry.addName(StrongStoneStair ,"Strong Stone Stair");
        
//     MinecraftForge.setBlockHarvestLevel(StrongStoneStair,"Axe",3);
            
    
    
     @EventHandler // used in 1.6.2
     //@PostInit // used in 1.5.2
     public void postInit(FMLPostInitializationEvent event) {
             // Stub Method
     }
}

 

 

 

Try those tasks. Put them in your mob class

this.tasks.addTask(1, new EntityAIAttackOnCollide(this, 0.25F, true));
        this.tasks.addTask(2, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F));
        this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false));

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • To prevent dependency errors, yes  
    • All of the Dynamic Tree mods?
    • dynamictrees and dtneapolitan are the last mentioned mod - remove these
    • https://mclo.gs/9y5ciD2 anyone ever had this issue?  Internal exception illegal argument exception: unable to fit 3194354 into 3
    • Hi! I'm trying to add my custom models/textures renderer like this: public class PonyPlayerWrapperRenderer extends EntityRenderer<Player> { // wrapper class under my LivingEntityRenderer class implementation private final PonyPlayerRenderer innerRenderer; private final PonyPlayerRenderer innerSlimRenderer; public PonyPlayerWrapperRenderer(final EntityRendererProvider.Context context) { super(context); System.out.println("creating new PonyPlayerWrapperRenderer"); this.innerRenderer = new PonyPlayerRenderer(context, false); this.innerSlimRenderer = new PonyPlayerRenderer(context, true); } @Override public void render(final Player entity, final float yaw, final float partialTicks, final PoseStack poseStack, final MultiBufferSource bufferSource, final int packedLight) { System.out.println("PonyPlayerWrapperRenderer render: " + entity.toString()); if (entity instanceof AbstractClientPlayer clientPlayer) { if (clientPlayer.getModelName().contains("slim")) { innerSlimRenderer.render(clientPlayer, yaw, partialTicks, poseStack, bufferSource, packedLight); } else { innerRenderer.render(clientPlayer, yaw, partialTicks, poseStack, bufferSource, packedLight); } } } @Override public ResourceLocation getTextureLocation(final Player player) { System.out.println("PonyPlayerWrapperRenderer getTextureLocation"); if (player instanceof AbstractClientPlayer clientPlayer) { return clientPlayer.getSkinTextureLocation(); } System.out.println("player instanceof AbstractClientPlayer is false"); return getDefaultSkin(player.getUUID()); } } public class PonyPlayerRenderer extends LivingEntityRenderer<AbstractClientPlayer, PlayerModel<AbstractClientPlayer>> { private final PlayerModel<AbstractClientPlayer> earthModel; private final PlayerModel<AbstractClientPlayer> pegasusModel; private final PlayerModel<AbstractClientPlayer> unicornModel; public PonyPlayerRenderer(final EntityRendererProvider.Context context, final boolean slim) { super( context, slim ? new PonyModelSlim(context.bakeLayer(PonyModelSlim.LAYER_LOCATION)) : new PonyModel(context.bakeLayer(PonyModel.LAYER_LOCATION)), 0.5f ); System.out.println("creating new PonyPlayerRenderer"); this.earthModel = slim ? new PonyModelSlim(context.bakeLayer(PonyModelSlim.LAYER_LOCATION)) : new PonyModel(context.bakeLayer(PonyModel.LAYER_LOCATION)); this.pegasusModel = new PegasusModel(context.bakeLayer(PegasusModel.LAYER_LOCATION)); this.unicornModel = new UnicornModel(context.bakeLayer(UnicornModel.LAYER_LOCATION)); } @Override public void render(final AbstractClientPlayer player, final float entityYaw, final float partialTicks, final PoseStack poseStack, final MultiBufferSource buffer, final int packedLight) { final PonyRace race = player.getCapability(PONY_DATA) .map(data -> ofNullable(data.getRace()).orElse(PonyRace.EARTH)) .orElse(PonyRace.EARTH); this.model = switch (race) { case PEGASUS -> pegasusModel; case UNICORN -> unicornModel; case EARTH -> earthModel; }; super.render(player, entityYaw, partialTicks, poseStack, buffer, packedLight); } @Override public ResourceLocation getTextureLocation(final AbstractClientPlayer player) { final PonyRace race = player.getCapability(PONY_DATA) .map(data -> ofNullable(data.getRace()).orElse(PonyRace.EARTH)) .orElse(PonyRace.EARTH); return switch (race) { case EARTH -> fromNamespaceAndPath(MODID, "textures/entity/earth_pony.png"); case PEGASUS -> fromNamespaceAndPath(MODID, "textures/entity/pegasus.png"); case UNICORN -> fromNamespaceAndPath(MODID, "textures/entity/unicorn.png"); }; } } @Mod.EventBusSubscriber(modid = MODID, bus = MOD, value = CLIENT) public class ClientRenderers { // mod bus render registration config @SubscribeEvent public static void onRegisterLayerDefinitions(final EntityRenderersEvent.RegisterLayerDefinitions event) { event.registerLayerDefinition(PonyModel.LAYER_LOCATION, PonyModel::createBodyLayer); event.registerLayerDefinition(PonyModelSlim.LAYER_LOCATION, PonyModelSlim::createBodyLayer); event.registerLayerDefinition(PegasusModel.LAYER_LOCATION, PegasusModel::createBodyLayer); event.registerLayerDefinition(UnicornModel.LAYER_LOCATION, UnicornModel::createBodyLayer); event.registerLayerDefinition(InnerPonyArmorModel.LAYER_LOCATION, InnerPonyArmorModel::createBodyLayer); event.registerLayerDefinition(OuterPonyArmorModel.LAYER_LOCATION, OuterPonyArmorModel::createBodyLayer); } @SubscribeEvent public static void onRegisterRenderers(final EntityRenderersEvent.RegisterRenderers event) { event.registerEntityRenderer(EntityType.PLAYER, PonyPlayerWrapperRenderer::new); System.out.println("onRegisterRenderers end"); } } Method onRegisterRenderers() is called and I can see it being logged. But when I enter the world, my PonyWrapperRenderer render() method doesn't ever seem to be called. I also tried to put my renderer to EntityRenderDispatcher's playerRenderers via reflection: @Mod.EventBusSubscriber(modid = MODID, bus = MOD, value = CLIENT) public class ClientRenderers { @SubscribeEvent public static void onRegisterLayerDefinitions(final EntityRenderersEvent.RegisterLayerDefinitions event) { event.registerLayerDefinition(PonyModel.LAYER_LOCATION, PonyModel::createBodyLayer); event.registerLayerDefinition(PonyModelSlim.LAYER_LOCATION, PonyModelSlim::createBodyLayer); event.registerLayerDefinition(PegasusModel.LAYER_LOCATION, PegasusModel::createBodyLayer); event.registerLayerDefinition(UnicornModel.LAYER_LOCATION, UnicornModel::createBodyLayer); event.registerLayerDefinition(InnerPonyArmorModel.LAYER_LOCATION, InnerPonyArmorModel::createBodyLayer); event.registerLayerDefinition(OuterPonyArmorModel.LAYER_LOCATION, OuterPonyArmorModel::createBodyLayer); } @SubscribeEvent public static void onClientSetup(final FMLClientSetupEvent event) { event.enqueueWork(() -> { try { final EntityRenderDispatcher dispatcher = Minecraft.getInstance().getEntityRenderDispatcher(); final Field renderersField = getEntityRenderDispatcherField("playerRenderers"); final Field itemInHandRenderer = getEntityRenderDispatcherField("itemInHandRenderer"); @SuppressWarnings("unchecked") final Map<String, EntityRenderer<? extends Player>> playerRenderers = (Map<String, EntityRenderer<? extends Player>>)renderersField.get(dispatcher); final PonyPlayerWrapperRenderer renderer = new PonyPlayerWrapperRenderer( new EntityRendererProvider.Context( dispatcher, Minecraft.getInstance().getItemRenderer(), Minecraft.getInstance().getBlockRenderer(), (ItemInHandRenderer)itemInHandRenderer.get(dispatcher), Minecraft.getInstance().getResourceManager(), Minecraft.getInstance().getEntityModels(), Minecraft.getInstance().font ) ); playerRenderers.put("default", renderer); playerRenderers.put("slim", renderer); System.out.println("Player renderers replaced"); } catch (final Exception e) { throw new RuntimeException("Failed to replace player renderers", e); } }); } private static Field getEntityRenderDispatcherField(final String fieldName) throws NoSuchFieldException { final Field field = EntityRenderDispatcher.class.getDeclaredField(fieldName); field.setAccessible(true); return field; } } But I receive the error before Minecraft Client appears (RuntimeException: Failed to replace player renderers - from ClientRenderers onClientSetup() method - and its cause below): java.lang.IllegalArgumentException: No model for layer anotherlittlepony:earth_pony#main at net.minecraft.client.model.geom.EntityModelSet.bakeLayer(EntityModelSet.java:18) ~[forge-1.20.1-47.4.0_mapped_official_1.20.1-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A} at net.minecraft.client.renderer.entity.EntityRendererProvider$Context.bakeLayer(EntityRendererProvider.java:69) ~[forge-1.20.1-47.4.0_mapped_official_1.20.1-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A} at com.thuggeelya.anotherlittlepony.client.renderer.pony.PonyPlayerRenderer.<init>(PonyPlayerRenderer.java:32) ~[main/:?] {re:classloading} at com.thuggeelya.anotherlittlepony.client.renderer.pony.PonyPlayerWrapperRenderer.<init>(PonyPlayerWrapperRenderer.java:24) ~[main/:?] {re:classloading} at com.thuggeelya.anotherlittlepony.client.renderer.ClientRenderers.lambda$onClientSetup$0(ClientRenderers.java:79) ~[main/:?] {re:classloading} ... 33 more Problem appears when EntityRendererProvider context tries to bakeLayer with my model layer location: new PonyModel(context.bakeLayer(PonyModel.LAYER_LOCATION)); // PonyPlayerRenderer.java:32 public class PonyModel extends PlayerModel<AbstractClientPlayer> { // the model class itself public static final ModelLayerLocation LAYER_LOCATION = new ModelLayerLocation( ResourceLocation.fromNamespaceAndPath(MODID, "earth_pony"), "main" ); public PonyModel(final ModelPart root) { super(root, false); } public static LayerDefinition createBodyLayer() { // some CubeListBuilder stuff for model appearance } } Textures PNGs are placed at: resources/assets/[my mod id]/textures/entity. My forge version is 1.20.1. Would appreciate any help.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.