Jump to content

Recommended Posts

Posted

Hello forum.

 

So I'm coding a Mob and I'm having some problems with the attributes and AI for it.

 

For example, the first problem I'm having is that I need the mob to follow players to attack from a distance about, lets say 128 blocks.

 

So I have all this, but still seems not taking effect. Is there something I'm missing here?

Also, I made it "Giant" like a Giant Zombie, is there anything I should consider when coding a Mob like this? I added some code from the GiantZombie in Minecraft, not really sure what it does and if its really necessary.

Thanks for the help

 

The complete code is:

 

package com.mramericanmike.mymod.entity;

import net.minecraft.command.IEntitySelector;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.EnumCreatureAttribute;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIArrowAttack;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIMoveTowardsTarget;
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.boss.IBossDisplayData;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.monster.IMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;

import com.mramericanmike.mymod.Log;
import com.mramericanmike.mymod.init.ModItems;

public class EntityMyMob extends EntityMob implements IBossDisplayData, IMob
{

public EntityMyMob(World world) {
	super(world);


	this.experienceValue = 150;
	this.captureDrops = true;
	this.setCanPickUpLoot(true);
	this.isImmuneToFire = true;
	this.getNavigator().setCanSwim(true);

	this.setHealth(this.getMaxHealth());
//        this.width = 3F;
//        this.height = 8F;
        this.addPotionEffect(new PotionEffect(Potion.resistance.id, 24000, 0));
        
        
        this.yOffset *= 4.0F;
        this.setSize(this.width * 4.5F, this.height * 5.5F);
        
        
        
        //AI
        
        
        this.tasks.addTask(0, new EntityAISwimming(this));
        this.tasks.addTask(1, new EntityAIWatchClosest(this, EntityPlayer.class, 128.0F));
        this.tasks.addTask(2, new EntityAIAttackOnCollide(this, 1.75D, true));
        this.tasks.addTask(3, new EntityAIMoveTowardsTarget(this, 1.75D, 128.0F));
        
        this.targetTasks.addTask(4, new EntityAINearestAttackableTarget(this, EntityLiving.class, 0, false, true, IMob.mobSelector));
        


}

    protected void applyEntityAttributes()
    {
        super.applyEntityAttributes();
        this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(128.0D);
        this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(100.0D);
        this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(1000.0D);
        this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(1.75D);
        this.getEntityAttribute(SharedMonsterAttributes.knockbackResistance).setBaseValue(1.0D);
        
    }
    
    
    
    
    public float getBlockPathWeight(int p_70783_1_, int p_70783_2_, int p_70783_3_)
    {
        return this.worldObj.getLightBrightness(p_70783_1_, p_70783_2_, p_70783_3_) - 0.5F;
    }
    
    
    

    @Override
    protected boolean canDespawn()
    {
        return false;
    }
    
    @Override
    protected String getHurtSound()
    {
//        return "game.hostile.hurt";
    	Log.Debug("MyMob Hurt");
    	return null;
    }

    @Override
    protected String getDeathSound()
    {
//        return "game.hostile.hurt";
    	Log.Debug("MyMob Death");
    	return null;
    }
    
    @Override
    protected Item getDropItem()
    {
    	Log.Debug("MyMob Drops");
    	return ModItems.apple;
    	
    }
}

 

PS: If I'm trying to make a Boss, what attributes and AI do you recommend me to use?

 

Posted

ok dude, u need to realize that all this stuff is in vanilla mob classes. so you failed to the upmost extent.

 

you need to enable the ai..  which every other mob class in minecraft has (well pretty much).

	}

public boolean isAIEnabled() {

	return true;
}

 

and for getting ur boss bar?? look at wither or enderdragon code, seriously.

vanilla has everything you need.

 

so for the boss bar you have to make an onlivingupdate method, like this..

public void onLivingUpdate() {
	super.onLivingUpdate();

 

and to get the boss bar all you need is this line of code, which set the boss bar, believe it or not.

BossStatus.setBossStatus(this, true);

 

basically for the future. look at vanilla code first, and look for tutorials.

It will help you out ALLOT.

Im serious don't look at it!!

Posted

 

Also, I made it "Giant" like a Giant Zombie, is there anything I should consider when coding a Mob like this? I added some code from the GiantZombie in Minecraft, not really sure what it does and if its really necessary.

 

 

the witdth and the height sets the size of the hit box, a better way to do that might be this.setSize(3F, 8F)

Im serious don't look at it!!

Posted

For AI, I have some tutorials: http://jabelarminecraft.blogspot.com/p/minecraft-forge-1721710-custom-entity-ai.html

 

For attacking attributes, I have this tutorial: http://jabelarminecraft.blogspot.com/p/minecraft-forge-1721710-apply.html

 

For giant mobs, one of the main difficulties is the hit box, I think there are some limits to the size, at least in the height. This is due, I think, to the pathfinding -- it is hard for Minecraft to figure out how large hitboxes can move through terrain. In the giant entity I made, I think the maximum size I found that worked was setSize(1.0F, 4.5F).

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

BoonieQuafter-CrAfTeR Thanks a lot, yes I finally noticed I was missing that isAIEnabled()

Thanks also on the tips about the Boss Bar, that was coming after I figured the AI so thanks a lot on the tips for that aswell ;)

 

Jabelar, thanks a lot, I'm going to take a look at yours tutorials.

Also thanks with the tips on how big the Hitbox should be, I think I made mine too big as for now, so I should probably start with the same dimensions the GiantZombie has and test from there

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

    • logs too big for one pastebin https://pastebin.com/ZjUGHu3u  https://pastebin.com/RqCUZf3X  https://pastebin.com/6ZPS99nD
    • You probably used jd-gui to open it, didn't you? Nothing wrong with that, I also made that mistake, except that Notch was a smart guy and he obfuscated the code. That's why you only see files called "a", "b", "c" and then a file that combines them all. As I said, use RetroMCP to deobfuscate the code so that you will 100% understand it and be able to navigate it.
    • Decompiling minecraft indev, infdev, alpha, beta or whichever legacy version is really easy. I'm not a plug, I just also got interested in modding legacy versions (Infdev to be specific). Use https://github.com/MCPHackers/RetroMCP-Java Once you install their client and the Zulu Architecture that they say they recommend (or use your own Java). I encountered some problems, so I run it with: "java -jar RetroMCP-Java-CLI.jar". You should run it in a seperate folder (not in downloads), otherwise the files and folders will go all over the place. How to use RetroMCP: Type setup (every time you want change version), copy-paste the version number from their list (they support indev), write "decompile" and done! The code will now be deobfuscated and filenames will be normal, instead of "a", "b" and "c"! Hope I helped you, but I don't expect you to reply, as this discussion is 9 years old! What a piece of history!  
    • I know that this may be a basic question, but I am very new to modding. I am trying to have it so that I can create modified Vanilla loot tables that use a custom enchantment as a condition (i.e. enchantment present = item). However, I am having trouble trying to implement this; the LootItemRandomChanceWithEnchantedBonusCondition constructor needs a Holder<Enchantment> and I am unable to use the getOrThrow() method on the custom enchantment declared in my mod's enchantments class. Here is what I have so far in the GLM:   protected void start(HolderLookup.Provider registries) { HolderLookup.RegistryLookup<Enchantment> registrylookup = registries.lookupOrThrow(Registries.ENCHANTMENT); LootItemRandomChanceWithEnchantedBonusCondition lootItemRandomChanceWithEnchantedBonusCondition = new LootItemRandomChanceWithEnchantedBonusCondition(0.0f, LevelBasedValue.perLevel(0.07f), registrylookup.getOrThrow(*enchantment here*)); this.add("nebu_from_deepslate", new AddItemModifier(new LootItemCondition[]{ LootItemBlockStatePropertyCondition.hasBlockStateProperties(Blocks.DEEPSLATE).build(), LootItemRandomChanceCondition.randomChance(0.25f).build(), lootItemRandomChanceWithEnchantedBonusCondition }, OrichalcumItems.NEBU.get())); }   Inserting Enchantments.[vanilla enchantment here] actually works but trying to declare an enchantment from my custom enchantments class as [mod enchantment class].[custom enchantment] does not work even though they are both a ResourceKey and are registered in Registries.ENCHANTMENT. Basically, how would I go about making it so that a custom enchantment declared as a ResourceKey<Enchantment> of value ResourceKey.create(Registries.ENCHANTMENT, ResourceLocation.fromNamespaceAndPath([modid], [name])), declared in a seperate enchantments class, can be used in the LootItemRandomChanceWithEnchantedBonusCondition constructor as a Holder? I can't use getOrThrow() because there is no level or block entity/entity in the start() method and it is running as datagen. It's driving me nuts.
  • Topics

×
×
  • Create New...

Important Information

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