Posted May 9, 201411 yr Hey people, how can I make that a block kills all mobs in a radius of x blocks? Please answer me
May 9, 201411 yr Yes, but you would need to have a tile entity to do so constantly. Another option is to have a non-tile entity block that kills all mobs in x radius whenever it is randomly ticked.
May 9, 201411 yr import java.util.Iterator; import java.util.List; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.monster.EntityMob; import net.minecraft.entity.monster.IMob; import net.minecraft.world.World; public class KillerBlock extends Block { public KillerBlock(Material p_i45394_1_) { super(p_i45394_1_); this.setTickRandomly(true); } public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random) { double u=10;//change this to whatever you want to do List l=par1World.selectEntitiesWithinAABB(EntityLivingBase.class, this.getCollisionBoundingBoxFromPool(par1World, par2, par3, par4).expand(u, u, u),IMob.mobSelector);//this won't kill creepers as Imob.mobSelector doesn't select them. //List l=par1World.getEntitiesWithinAABB(EntityMob.class, this.getCollisionBoundingBoxFromPool(par1World, par2, par3, par4).expand(u, u, u));//this will select all hostile creatures. replace EntityMob with EntityLiving to kill all non-Player living entitys, and replace it with entitylivingbase to kill all living entites including players. Iterator i=l.iterator(); while (i.hasNext()) { ((EntityLivingBase)i.next()).setHealth(0); } } } MC's random tick speed it a little slow, so in order to get a frequent kill burst you might need to use multiple blocks.
May 9, 201411 yr Author And what about a tile entity? It works with random tick but its very slow. Are you so nice and give me an example?
May 9, 201411 yr GameRegistry.registerTileEntity(TileEntityKillStuff.class, baseclass.modid+"killerTileEntity"); import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; public class TileEntityKillStuff extends TileEntity{ @Override public void writeToNBT(NBTTagCompound par1) { super.writeToNBT(par1); } public void updateEntity() { if(this.worldObj.rand.nextInt(5)==0)/*Change the value of the 5 to increase or decrees the chance of an update tick, or remove the entire if statement to give a 100% chance*/ { this.blockType.updateTick(worldObj, xCoord, yCoord, zCoord, this.worldObj.rand); } } @Override public void readFromNBT(NBTTagCompound par1) { super.readFromNBT(par1); } } import java.util.Iterator; import java.util.List; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.monster.EntityMob; import net.minecraft.entity.monster.IMob; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; public class KillerBlock extends Block { public KillerBlock(Material p_i45394_1_) { super(p_i45394_1_); this.setTickRandomly(true); } public TileEntity createTileEntity(World world, int metadata) { return new TileEntityKillStuff(); } public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random) { double u=10;//change this to whatever you want to do List l=par1World.selectEntitiesWithinAABB(EntityLivingBase.class, this.getCollisionBoundingBoxFromPool(par1World, par2, par3, par4).expand(u, u, u),IMob.mobSelector);//this won't kill creepers as Imob.mobSelector doesn't select them. //List l=par1World.getEntitiesWithinAABB(EntityMob.class, this.getCollisionBoundingBoxFromPool(par1World, par2, par3, par4).expand(u, u, u));//this will select all hostile creatures. replace EntityMob with EntityLiving to kill all non-Player living entitys, and replace it with entitylivingbase to kill all living entites including players. Iterator i=l.iterator(); while (i.hasNext()) { ((EntityLivingBase)i.next()).setHealth(0); } } }
May 9, 201411 yr Author I don't know why, but it doesn't work . When I place the block and skeletons there, they don't die. What value I have to set (this.worldObj.rand.nextInt(5) if I want that the block kills the mobs every second?
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.