MikeZ Posted June 3, 2014 Posted June 3, 2014 Hi! I want to make a block, that if a hostile mob (zombie, creeper, ...) collide with it, they get damage. And the player or passive mobs should'nt be hurt. Is there any way to make this block? Thanks, Mike Quote
MikeZ Posted June 3, 2014 Author Posted June 3, 2014 Override onEntityCollidedWithBlock (or whatever it's called) in your block class, check if the Entity colliding is an IMob, and if so, damage it. Ok, thank you. I changed my Block.class, but it has no effect. Heres my Block.class: package MikesMod.blocks; import java.util.Random; import MikesMod.MainClass; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.world.World; public class MikesOreBlock extends Block{ @SideOnly(Side.CLIENT) private String texture; public MikesOreBlock(int par1, Material par2Material, String texture) { super(par1, par2Material); this.texture = texture; this.setCreativeTab(MainClass.tabMikesMod); this.setHardness(6F); this.setResistance(15F); } public int idDropped(int par1, Random par2Random, int par3) { return MainClass.MikesOreBlock.blockID; } @SideOnly(Side.CLIENT) public void registerIcons(IconRegister iconRegister) { blockIcon = iconRegister.registerIcon("mike:" + texture); } @Override public void onEntityCollidedWithBlock( World world, int x, int y, int z, Entity entity ) { if (entity instanceof EntityLiving) { ((EntityLiving)entity).addPotionEffect(new PotionEffect(Potion.poison.id, 200, 1)); } } } Thanks, Mike Quote
delpi Posted June 3, 2014 Posted June 3, 2014 Away from my setup so can't give you the right setup, but I think your potion reference is wrong. Quote Long time Bukkit & Forge Programmer Happy to try and help
MikeZ Posted June 3, 2014 Author Posted June 3, 2014 Away from my setup so can't give you the right setup, but I think your potion reference is wrong. Ok, I wait for your answer Quote
delpi Posted June 3, 2014 Posted June 3, 2014 Nevermind, don't think that is it. How abuot you try to just damage the entity instead of the potion and see if you get a different result. Might also put a logger in there to make sure it is actaully getting called. Looked up one that worked for me. player.addPotionEffect(new PotionEffect(Potion.confusion.getId(), 20 * 5, 1)); vs ((EntityLiving)entity).addPotionEffect(new PotionEffect(Potion.poison.id, 200, 1)); Quote Long time Bukkit & Forge Programmer Happy to try and help
blaxout1213 Posted June 5, 2014 Posted June 5, 2014 Change EntityLiving to EntityMob, after the instanceof Quote
jabelar Posted June 5, 2014 Posted June 5, 2014 Override onEntityCollidedWithBlock (or whatever it's called) in your block class, check if the Entity colliding is an IMob, and if so, damage it. I actually think that onEntityCollidedWithBlock() method doesn't work for the idea of an entity "bumping" into a block. Rather it is intended for those types of blocks that an entity can actually "enter" into. Like a portal or a web. And arrows are allowed to "enter" blocks to trigger this method. If you think about it, most entities can't "collide" with a regular block because the path finding won't let that happen -- the movement is prevented before an actual collision occurs. It is a poorly named method, but from some other debugging I've done recently I came to the conclusion that you have to be inside the block to trigger this method. I could be wrong, but that was something I thought I previously found to be true. Anyway, it is easy enough to prove. Just put a System.out.println() statement in the method to see whether it is ever being called. Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/
delpi Posted June 5, 2014 Posted June 5, 2014 I've got some protection blocks setup. If you want this to be a very common block, it could be a bad idea, but assuming it is not a world populate block, just create a Tileentity. Then set it up to search every so many ticks for entities around it that meet your criteria, and do whatever. Quote Long time Bukkit & Forge Programmer Happy to try and help
Recommended Posts
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.