Jump to content

Block kills mobs?


SantacreeperLP

Recommended Posts

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.

Link to comment
Share on other sites

    	   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);
    	}
    }

}

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



×
×
  • Create New...

Important Information

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