Jump to content

Jumping Mob


DoorCloser

Recommended Posts

I just want my mob to LEAP or JUMP on me when it gets as NEAR as CODE says. OTHERWISE my MOB is just going to WALK! Here is the damn code.

 

 

package halflifemod.entity.monster;

 

import net.minecraft.entity.EntityLiving;

import net.minecraft.entity.monster.IMob;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.Item;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.util.DamageSource;

import net.minecraft.util.MathHelper;

import net.minecraft.world.World;

import net.minecraft.world.WorldType;

import net.minecraft.world.biome.BiomeGenBase;

import net.minecraft.world.chunk.Chunk;

 

public class EntityHeadcrab extends EntityLiving implements IMob

{

    /** Chances for slimes to spawn in swamps for every moon phase. */

    private static final float[] spawnChances = new float[] {1.0F, 0.75F, 0.5F, 0.25F, 0.0F, 0.25F, 0.5F, 0.75F};

    public float field_70813_a;

    public float field_70811_b;

    public float field_70812_c;

 

    /** the time between each jump of the slime */

    private int slimeJumpDelay = 0;

 

    public EntityHeadcrab(World par1World)

    {

        super(par1World);

        this.texture = "/mob/HL/Headcrab.png";

        int i = 1 << this.rand.nextInt(3);

        this.yOffset = 0.0F;

        this.slimeJumpDelay = this.rand.nextInt(20) + 10;

    }

 

    protected void entityInit()

    {

        super.entityInit();

        this.dataWatcher.addObject(16, new Byte((byte)1));

    }

 

    protected void setSlimeSize(int par1)

    {

        this.dataWatcher.updateObject(16, new Byte((byte)par1));

        this.setSize(0.6F * (float)par1, 0.6F * (float)par1);

        this.setPosition(this.posX, this.posY, this.posZ);

        this.setEntityHealth(this.getMaxHealth());

        this.experienceValue = par1;

    }

 

    public int getMaxHealth()

    {

        return 3;

    }

 

 

    /**

    * (abstract) Protected helper method to write subclass entity data to NBT.

    */

    public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound)

    {

        super.writeEntityToNBT(par1NBTTagCompound);

       

    }

 

    /**

    * (abstract) Protected helper method to read subclass entity data from NBT.

    */

    public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound)

    {

        super.readEntityFromNBT(par1NBTTagCompound);

       

    }

 

    /**

    * Returns the name of a particle effect that may be randomly created by EntitySlime.onUpdate()

    */

    protected String getSlimeParticle()

    {

        return "slime";

    }

 

    /**

    * Returns the name of the sound played when the slime jumps.

    */

    protected String getJumpSound()

    {

        return "mob.slime.big";

    }

 

    /**

    * Called to update the entity's position/logic.

    */

    public void onUpdate()

    {

        if (!this.worldObj.isRemote && this.worldObj.difficultySetting == 0)

        {

            this.isDead = true;

        }

 

        this.field_70811_b += (this.field_70813_a - this.field_70811_b) * 0.5F;

        this.field_70812_c = this.field_70811_b;

        boolean flag = this.onGround;

        super.onUpdate();

        int i;

 

        if (this.onGround && !flag)

        {

 

            for (int j = 0; j < 8; ++j)

            {

                float f = this.rand.nextFloat() * (float)Math.PI * 2.0F;

                float f1 = this.rand.nextFloat() * 0.5F + 0.5F;

                float f2 = MathHelper.sin(f) * 0.5F * f1;

                float f3 = MathHelper.cos(f) * 0.5F * f1;

            }

 

            if (this.makesSoundOnLand())

            {

                this.playSound(this.getJumpSound(), this.getSoundVolume(), ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F) / 0.8F);

            }

 

            this.field_70813_a = -0.5F;

        }

        else if (!this.onGround && flag)

        {

            this.field_70813_a = 1.0F;

        }

 

        this.func_70808_l();

 

   

        }

   

 

    protected void updateEntityActionState()

    {

        this.despawnEntity();

        EntityPlayer entityplayer = this.worldObj.getClosestVulnerablePlayerToEntity(this, 3.0D);

 

        if (entityplayer != null)

        {

            this.faceEntity(entityplayer, 10.0F, 20.0F);

        }

 

        if (this.onGround && this.slimeJumpDelay-- <= 0)

        {

            this.slimeJumpDelay = this.getJumpDelay();

 

            if (entityplayer != null)

            {

                this.slimeJumpDelay /= 3;

                this.isJumping = true;

            }

 

            if (this.makesSoundOnJump())

            {

                this.playSound(this.getJumpSound(), this.getSoundVolume(), ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F) * 0.8F);

            }

 

            this.moveStrafing = 1.0F - this.rand.nextFloat() * 2.0F;

            this.moveForward = (float)(1);

        }

        else

        {

            this.isJumping = false;

 

            if (this.onGround)

            {

                this.moveSpeed = 0.5F;

            }

        }

    }

 

    protected void func_70808_l()

    {

        this.field_70813_a *= 0.6F;

    }

 

    /**

    * Gets the amount of time the slime needs to wait between jumps.

    */

    protected int getJumpDelay()

    {

        return this.rand.nextInt(20) + 10;

    }

 

    protected EntityHeadcrab createInstance()

    {

        return new EntityHeadcrab(this.worldObj);

    }

    /**

    * Called by a player entity when they collide with an entity

    */

    public void onCollideWithPlayer(EntityPlayer par1EntityPlayer)

    {

        if (this.canDamagePlayer())

        {

           

 

            if (this.canEntityBeSeen(par1EntityPlayer) && this.getDistanceSqToEntity(par1EntityPlayer) < 0.6D * 0.6D && par1EntityPlayer.attackEntityFrom(DamageSource.causeMobDamage(this), this.getAttackStrength()))

            {

                this.playSound("mob.attack", 1.0F, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);

            }

        }

    }

 

    /**

    * Indicates weather the slime is able to damage the player (based upon the slime's size)

    */

    protected boolean canDamagePlayer()

    {

        return true;

    }

 

    /**

    * Gets the amount of damage dealt to the player when "attacked" by the slime.

    */

    protected int getAttackStrength()

    {

        return 3;

    }

 

    /**

    * Returns the sound this mob makes when it is hurt.

    */

    protected String getHurtSound()

    {

        return "mob.slime.big";

    }

 

    /**

    * Returns the sound this mob makes on death.

    */

    protected String getDeathSound()

    {

        return "mob.slime.big";

    }

 

    /**

    * Returns the item ID for the item the mob drops on death.

    */

    protected int getDropItemId()

    {

        return Item.slimeBall.itemID;

    }

 

    /**

    * Returns the volume for the sounds this mob makes.

    */

    protected float getSoundVolume()

    {

        return 0.4F;

    }

 

    /**

    * The speed it takes to move the entityliving's rotationPitch through the faceEntity method. This is only currently

    * use in wolves.

    */

    public int getVerticalFaceSpeed()

    {

        return 0;

    }

 

    /**

    * Returns true if the slime makes a sound when it jumps (based upon the slime's size)

    */

    protected boolean makesSoundOnJump()

    {

        return true;

    }

 

    /**

    * Returns true if the slime makes a sound when it lands after a jump (based upon the slime's size)

    */

    protected boolean makesSoundOnLand()

    {

        return true;

    }

}

 

 

 

 

I've MADE my MOB to PERFORM JUMPING ACTIONS, but he DOESNT WALK. I TRIED to USE the moveSpeed METHOD, but that DIDNT WORKS. It only READS moveForward and moveStarfing. MAYBE thats because of AIDISABLED. I havent enabled it's AI because code WOULDNT WORK! WHAT I SUPPOSE TO DO. HOW CAN I MAKE MY MOB TO PERFORM JUMP ACTIONS WHEN HE GETS AS NEAR AS CODE SAYS, BUT OTHERWISE MOB WILL JUST WALK AFTER ME!

 

CAN ANYBODY HELP!?

Link to comment
Share on other sites

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

    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
    • It is an issue with quark - update it to this build: https://www.curseforge.com/minecraft/mc-mods/quark/files/3642325
    • Remove Instant Massive Structures Mod from your server     Add new crash-reports with sites like https://paste.ee/  
    • Update your drivers: https://www.amd.com/en/support/graphics/amd-radeon-r9-series/amd-radeon-r9-200-series/amd-radeon-r9-280x
  • Topics

×
×
  • Create New...

Important Information

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