Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: [java] help

  1. #1
    w_is_awesome's Avatar
    Joined
    Dec 2011
    Posts
    132
    Userbars
    1
    Thanks
    61
    Thanked
    12/11
    DL/UL
    78/0
    Mentioned
    12 times
    Time Online
    20h 24m
    Avg. Time Online
    N/A

    [java] help

    Well I'm making a minecraft mod and I don't know how to make it spawn only ###Seconds/Ticks. Can someone please help me. I'm using eclipse
    Last edited by w_is_awesome; 04-06-2012 at 11:37 PM.

  2. #2
    Zachafer's Avatar
    Joined
    Dec 2011
    Posts
    1,235
    Userbars
    11
    Thanks
    769
    Thanked
    1,466/678
    DL/UL
    98/0
    Mentioned
    512 times
    Time Online
    24d 13h 9m
    Avg. Time Online
    8m
    Why don't you start by posting what code you have and what you have tried.

  3. #3
    w_is_awesome's Avatar
    Joined
    Dec 2011
    Posts
    132
    Userbars
    1
    Thanks
    61
    Thanked
    12/11
    DL/UL
    78/0
    Mentioned
    12 times
    Time Online
    20h 24m
    Avg. Time Online
    N/A
    It is a run off of the zombie... one of my first mods... here it is.

    Code:
     package net.minecraft.src;
    
    import java.util.
    
    public class EntityGiantZombie extends EntityMob
    {
        public EntityGiantZombie(World par1World)
        {
            super(par1World);
            texture = "/mob/zombie.png";
            moveSpeed = 0.5F;
            attackStrength = 50;
            isImmuneToFire = true;
            tasks.addTask(1, new EntityAIAttackOnCollide(this, net.minecraft.src.EntityPlayer.class, moveSpeed, false));
            tasks.addTask(2, new EntityAIMoveTwardsRestriction(this, moveSpeed));
            tasks.addTask(3, new EntityAIWander(this, moveSpeed));
            tasks.addTask(4, new EntityAIWatchClosest(this, net.minecraft.src.EntityPlayer.class, 8F));
            tasks.addTask(4, new EntityAILookIdle(this));
            targetTasks.addTask(1, new EntityAIHurtByTarget(this, false));
            targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, net.minecraft.src.EntityPlayer.class, 16F, 0, true));
        }
    
        public int getMaxHealth()
        {
            return 100;
        }
        
        protected boolean isAIEnabled()
        {
            return true;
        }
    
        
        public void onLivingUpdate()
        {
            if (worldObj.isDaytime() && !worldObj.isRemote)
            {
                float f = getBrightness(1.0F);
    
                if (f > 0.5F && worldObj.canBlockSeeTheSky(MathHelper.floor_double(posX), MathHelper.floor_double(posY), MathHelper.floor_double(posZ)) && rand.nextFloat() * 30F < (f - 0.4F) * 2.0F)
                {
                    setFire(8);
                }
            }
    
            super.onLivingUpdate();
        }
    
        /**
         * Returns the sound this mob makes while it's alive.
         */
        protected String getLivingSound()
        {
            return "mob.zombie";
        }
    
        /**
         * Returns the sound this mob makes when it is hurt.
         */
        protected String getHurtSound()
        {
            return "mob.zombiehurt";
        }
    
        /**
         * Returns the sound this mob makes on death.
         */
        protected String getDeathSound()
        {
            return "mob.zombiedeath";
        }
    
        /**
         * Takes a coordinate in and returns a weight to determine how likely this creature will try to path to the block.
         * Args: x, y, z
         */
        public float getBlockPathWeight(int par1, int par2, int par3)
        {
            return worldObj.getLightBrightness(par1, par2, par3) - 0.5F;
        }
        
        protected void dropRareDrop(int par1)
        {
            switch (rand.nextInt(4))
            {
                case 0:
                    dropItem(Item.diamond.shiftedIndex, 1);
                    break;
            }
        }
    }
    Last edited by J_L_K_64; 04-07-2012 at 12:24 AM.

  4. #4
    Zachafer's Avatar
    Joined
    Dec 2011
    Posts
    1,235
    Userbars
    11
    Thanks
    769
    Thanked
    1,466/678
    DL/UL
    98/0
    Mentioned
    512 times
    Time Online
    24d 13h 9m
    Avg. Time Online
    8m
    Can you elaborate on "make it spawn only ###Seconds/Ticks" ?

    I'm unfamiliar with Minecraft

  5. #5
    w_is_awesome's Avatar
    Joined
    Dec 2011
    Posts
    132
    Userbars
    1
    Thanks
    61
    Thanked
    12/11
    DL/UL
    78/0
    Mentioned
    12 times
    Time Online
    20h 24m
    Avg. Time Online
    N/A
    well so the map doesnt overload i only want the entity to spawn/load every (lets say) 60 seconds
    ticks is another measurement in minecraft.

  6. #6
    Zachafer's Avatar
    Joined
    Dec 2011
    Posts
    1,235
    Userbars
    11
    Thanks
    769
    Thanked
    1,466/678
    DL/UL
    98/0
    Mentioned
    512 times
    Time Online
    24d 13h 9m
    Avg. Time Online
    8m
    Quote Originally Posted by w_is_awesome View Post
    well so the map doesnt overload i only want the entity to spawn/load every (lets say) 60 seconds
    ticks is another measurement in minecraft.
    60 seconds is different than ticks. I would set a variable that holds the last System.currentTimeMillis() and is set when you spawn/load the entity. Then in the code for spawning the entity, ensure that System.currentTimeMillis() - lastRespawn >= 60000 before spawning.

  7. #7
    w_is_awesome's Avatar
    Joined
    Dec 2011
    Posts
    132
    Userbars
    1
    Thanks
    61
    Thanked
    12/11
    DL/UL
    78/0
    Mentioned
    12 times
    Time Online
    20h 24m
    Avg. Time Online
    N/A
    ik ticks is like .4 seconds. but would the code look like this.
    [CODE]
    {
    System.currentTimeMillis
    {
    lastRespawn = 60000
    }
    }
    [CODE]
    tab button isn't working srry

    But i think it goes after
    [Code]
    Import java.until.[Something goes here]
    [CODE]
    Last edited by w_is_awesome; 04-07-2012 at 12:04 AM.

  8. #8
    Zachafer's Avatar
    Joined
    Dec 2011
    Posts
    1,235
    Userbars
    11
    Thanks
    769
    Thanked
    1,466/678
    DL/UL
    98/0
    Mentioned
    512 times
    Time Online
    24d 13h 9m
    Avg. Time Online
    8m
    Try something like this:
    Code:
    package net.minecraft.src;
    
    import java.util.*;
    
    public class EntityGiantZombie extends EntityMob
    {
    
    	public static long lastSpawn = -1;
    
    	public EntityGiantZombie(World par1World)
    	{
    		if(lastSpawn != -1 && System.currentTimeMillis() - EntityGiantZombie.lastSpawn < 60000)
    		{
    			return;
    		}
    		super(par1World);
    		texture = "/mob/zombie.png";
    		moveSpeed = 0.5F;
    		attackStrength = 50;
    		isImmuneToFire = true;
    		tasks.addTask(1, new EntityAIAttackOnCollide(this, net.minecraft.src.EntityPlayer.class, moveSpeed, false));
    		tasks.addTask(2, new EntityAIMoveTwardsRestriction(this, moveSpeed));
    		tasks.addTask(3, new EntityAIWander(this, moveSpeed));
    		tasks.addTask(4, new EntityAIWatchClosest(this, net.minecraft.src.EntityPlayer.class, 8F));
    		tasks.addTask(4, new EntityAILookIdle(this));
    		targetTasks.addTask(1, new EntityAIHurtByTarget(this, false));
    		targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, net.minecraft.src.EntityPlayer.class, 16F, 0, true));
    	}
    
    	public int getMaxHealth()
    	{
    		return 100;
    	}
    
    	protected boolean isAIEnabled()
    	{
    		return true;
    	}
    
    
    	public void onLivingUpdate()
    	{
    		if (worldObj.isDaytime() && !worldObj.isRemote)
    		{
    			float f = getBrightness(1.0F);
    
    			if (f > 0.5F && worldObj.canBlockSeeTheSky(MathHelper.floor_double (posX), MathHelper.floor_double(posY), MathHelper.floor_double(posZ)) &&
    				rand.nextFloat() * 30F < (f - 0.4F) * 2.0F)
    			{
    				setFire(8);
    			}
    		}
    
    		super.onLivingUpdate();
    	}
    
    	/**
    	* Returns the sound this mob makes while it's alive.
    	*/
    	protected String getLivingSound()
    	{
    		return "mob.zombie";
    	}
    
    	/**
    	* Returns the sound this mob makes when it is hurt.
    	*/
    	protected String getHurtSound()
    	{
    		return "mob.zombiehurt";
    	}
    
    	/**
    	* Returns the sound this mob makes on death.
    	*/
    	protected String getDeathSound()
    	{
    		return "mob.zombiedeath";
    	}
    
    	/**
    	* Takes a coordinate in and returns a weight to determine how likely this creature will try to path to the block.
    	* Args: x, y, z
    	*/
    	public float getBlockPathWeight(int par1, int par2, int par3)
    	{
    		return worldObj.getLightBrightness(par1, par2, par3) - 0.5F;
    	}
    
    	protected void dropRareDrop(int par1)
    	{
    		switch (rand.nextInt(4))
    		{
    			case 0:
    			dropItem(Item.diamond.shiftedIndex, 1);
    			break;
    		}
    	}
    	
    }

  9. The Following User Says Thank You to Zachafer For This Useful Post:

    w_is_awesome (04-07-2012)

  10. #9
    w_is_awesome's Avatar
    Joined
    Dec 2011
    Posts
    132
    Userbars
    1
    Thanks
    61
    Thanked
    12/11
    DL/UL
    78/0
    Mentioned
    12 times
    Time Online
    20h 24m
    Avg. Time Online
    N/A
    thank you but i have one issue.
    Code:
    	{
    		if(lastSpawn != -1 && System.currentTimeMillis() - EntityGiantZombie.lastSpawn < 690000)
    		{
    			return;
    		}
    	}

    The thing in red gives me this error: "Cannot return within and intializer"

  11. #10
    Zachafer's Avatar
    Joined
    Dec 2011
    Posts
    1,235
    Userbars
    11
    Thanks
    769
    Thanked
    1,466/678
    DL/UL
    98/0
    Mentioned
    512 times
    Time Online
    24d 13h 9m
    Avg. Time Online
    8m
    My bad, try this:
    Code:
    public static long lastSpawn = -1;
    
    	public EntityGiantZombie(World par1World)
    	{
    		if(EntityGiantZombie.lastSpawn == -1 || System.currentTimeMillis() - EntityGiantZombie.lastSpawn >= 60000)
    		{
    			super(par1World);
    			texture = "/mob/zombie.png";
    			moveSpeed = 0.5F;
    			attackStrength = 50;
    			isImmuneToFire = true;
    			tasks.addTask(1, new EntityAIAttackOnCollide(this, net.minecraft.src.EntityPlayer.class, moveSpeed, false));
    			tasks.addTask(2, new EntityAIMoveTwardsRestriction(this, moveSpeed));
    			tasks.addTask(3, new EntityAIWander(this, moveSpeed));
    			tasks.addTask(4, new EntityAIWatchClosest(this, net.minecraft.src.EntityPlayer.class, 8F));
    			tasks.addTask(4, new EntityAILookIdle(this));
    			targetTasks.addTask(1, new EntityAIHurtByTarget(this, false));
    			targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, net.minecraft.src.EntityPlayer.class, 16F, 0, true));
    			EntityGiantZombie.lastSpawn = System.currentTimeMillis();
    		}
    	}

  12. The Following User Says Thank You to Zachafer For This Useful Post:

    w_is_awesome (04-07-2012)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •