Why don't you start by posting what code you have and what you have tried.
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.
Why don't you start by posting what code you have and what you have tried.
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.
Can you elaborate on "make it spawn only ###Seconds/Ticks" ?
I'm unfamiliar with Minecraft
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.
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.
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; } } }
w_is_awesome (04-07-2012)
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"
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(); } }
w_is_awesome (04-07-2012)