Jump to content

Mob or Entity that Explodes on Collide with other entity and blocks?


Faffreux

Recommended Posts

Hello Forge community, I'm new here, I have an issue about a mob I'm creating, I want it to explode whenever it collides with a player, another entity or a block (it's a flying mob) I tried to take some codes from the enderdragon , the one that push away other mobs on collide and the one that destroy blocks on collides, here is the deal, it doesn't work here is a part of my code used for colliding with entities: 

 

 

private void collideWithEntities(List<Entity> p_70970_1_)
    {
        for (Entity entity : p_70970_1_)
        {
            if (entity instanceof EntityLivingBase)
            {
               int i = (int) this.posX;
               int j = (int) this.posY;
               int k = (int) this.posZ;
               world.createExplosion((Entity) null, i, j, k, 4F, true);
            }
        }
    }

 

what did I get wrong?

Edited by Faffreux
Link to comment
Share on other sites

here is my entire code, I'm using Mcreator (please dont hit me) :

 

package mod.mcreator;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.common.registry.EntityRegistry;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraft.world.biome.Biome;
import java.util.List;
import net.minecraft.world.World;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.EnumHand;
import net.minecraft.util.DamageSource;
import net.minecraft.item.ItemStack;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.Item;
import net.minecraft.world.EnumDifficulty;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.entity.monster.IMob;
import net.minecraft.entity.ai.EntityAIBase;
import net.minecraft.entity.EntityFlying;
import net.minecraft.entity.ai.EntityMoveHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.client.renderer.entity.RenderLiving;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.Minecraft;
import java.util.Random;
import java.util.Iterator;
import java.util.ArrayList;
@SuppressWarnings("unchecked")
public class mcreator_bulletBill {
    public int mobid = 0;
    public static Object instance;
    public void load(FMLInitializationEvent event) {
    }
    public void generateNether(World world, Random random, int chunkX, int chunkZ) {
    }
    public void generateSurface(World world, Random random, int chunkX, int chunkZ) {
    }
    public int addFuel(ItemStack fuel) {
        return 0;
    }
    @SideOnly(Side.CLIENT)
    public void registerRenderers() {
        RenderLiving customRender = new RenderLiving(Minecraft.getMinecraft().getRenderManager(), new mcreator_bulletBill.BulletBill(), 0) {
            protected ResourceLocation getEntityTexture(Entity par1Entity) {
                return new ResourceLocation("bulletbill.png");
            }
        };
        RenderingRegistry.registerEntityRenderingHandler(mcreator_bulletBill.EntitybulletBill.class, customRender);
    }
    public void serverLoad(FMLServerStartingEvent event) {
    }
    public void preInit(FMLPreInitializationEvent event) {
        int entityID = MathHelper.getRandomUUID().hashCode();
        mobid = entityID;
        EntityRegistry.registerModEntity(new ResourceLocation("testenvironmentmod:bulletBill"), mcreator_bulletBill.EntitybulletBill.class,
                "bulletBill", entityID, instance, 64, 1, true, (0 << 16) + (0 <<  + 0, (204 << 16) + (204 <<  + 204);
        EntityRegistry.addSpawn(mcreator_bulletBill.EntitybulletBill.class, 0, 3, 30, EnumCreatureType.MONSTER, clean(Biome.REGISTRY));
    }
    public static Biome[] clean(net.minecraft.util.registry.RegistryNamespaced<ResourceLocation, Biome> in) {
        Iterator<Biome> itr = in.iterator();
        ArrayList<Biome> ls = new ArrayList<Biome>();
        while (itr.hasNext()) {
            ls.add(itr.next());
        }
        return ls.toArray(new Biome[ls.size()]);
    }
    public static class EntitybulletBill extends EntityFlying implements IMob {
        World world = null;
        public EntitybulletBill(World var1) {
            super(var1);
            world = var1;
            experienceValue = 5;
            this.isImmuneToFire = false;
            addRandomArmor();
            setNoAI(!true);
               this.tasks.addTask(5, new EntitybulletBill.AIRandomFly(this));
               this.moveHelper = new EntitybulletBill.bulletBillMoveHelper(this);
               this.tasks.addTask(7, new EntitybulletBill.AILookAround(this));
        }
        protected void applyEntityAttributes() {
            super.applyEntityAttributes();
            this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.4D);
            this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(1D);
            if (this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE) != null)
                this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(3D);
        }
        protected void addRandomArmor() {
        }
        public void onLivingUpdate() {
            super.onLivingUpdate();
            World par1World = this.world;
            int par2 = (int) this.posX;
            int par3 = (int) this.posY;
            int par4 = (int) this.posZ;
            Random par5Random = this.rand;
            if (true)
                for (int la = 0; la < 4; ++la) {
                    double d0 = (double) ((float) par2 + 0.5F) + (double) (par5Random.nextFloat() - 0.5F) * 0.0D;
                    double d1 = (double) ((float) par3 + 0.5F) + (double) (par5Random.nextFloat() - 0.5F) * 0.0D;
                    double d2 = (double) ((float) par4 + 0.5F) + (double) (par5Random.nextFloat() - 0.5F) * 0.0D;
                    double d3 = 0.2199999988079071D;
                    double d4 = 0.27000001072883606D;
                    par1World.spawnParticle(EnumParticleTypes.SMOKE_LARGE, d0 - d4, d1 + d3, d2, 0.0D, 0.0D, 0.0D);
                }
        }
        @Override
        protected Item getDropItem() {
            return null;
        }
        @Override
        protected net.minecraft.util.SoundEvent getAmbientSound() {
            return (net.minecraft.util.SoundEvent) net.minecraft.util.SoundEvent.REGISTRY.getObject(new ResourceLocation(""));
        }
        @Override
        protected net.minecraft.util.SoundEvent getHurtSound() {
            return (net.minecraft.util.SoundEvent) net.minecraft.util.SoundEvent.REGISTRY.getObject(new ResourceLocation("game.neutral.hurt"));
        }
        @Override
        protected net.minecraft.util.SoundEvent getDeathSound() {
            return (net.minecraft.util.SoundEvent) net.minecraft.util.SoundEvent.REGISTRY.getObject(new ResourceLocation("game.neutral.die"));
        }
        @Override
        public void onStruckByLightning(EntityLightningBolt entityLightningBolt) {
            super.onStruckByLightning(entityLightningBolt);
            int i = (int) this.posX;
            int j = (int) this.posY;
            int k = (int) this.posZ;
            Entity entity = this;
        }
        @Override
        public void fall(float l, float d) {
            super.fall(l, d);
            int i = (int) this.posX;
            int j = (int) this.posY;
            int k = (int) this.posZ;
            super.fall(l, d);
            Entity entity = this;
        }
         
 public void collideWithEntities(List<Entity> p_70970_1_)
    {
               int i = (int) this.posX;
               int j = (int) this.posY;
               int k = (int) this.posZ;
               world.createExplosion((Entity) null, i, j, k, 4F, true);
    }
        @Override
        public boolean processInteract(EntityPlayer entity, EnumHand hand) {
            super.processInteract(entity, hand);
            int i = (int) this.posX;
            int j = (int) this.posY;
            int k = (int) this.posZ;
            return true;
        }

        @Override
        protected float getSoundVolume() {
            return 1.0F;
        }
            static class AILookAround extends EntityAIBase
        {
            private final EntitybulletBill parentEntity;
            public AILookAround(EntitybulletBill bulletBill)
            {
                this.parentEntity = bulletBill;
                this.setMutexBits(2);
            }
            /**
             * Returns whether the EntityAIBase should begin execution.
             */
            public boolean shouldExecute()
            {
                return true;
            }
            /**
             * Updates the task
             */
            public void updateTask()
            {
                if (this.parentEntity.getAttackTarget() == null)
                {
                    this.parentEntity.rotationYaw = -((float)MathHelper.atan2(this.parentEntity.motionX, this.parentEntity.motionZ)) * (180F / (float)Math.PI);
                    this.parentEntity.renderYawOffset = this.parentEntity.rotationYaw;
                }
                else
                {
                    EntityLivingBase entitylivingbase = this.parentEntity.getAttackTarget();
                    double d0 = 64.0D;
                    if (entitylivingbase.getDistanceSqToEntity(this.parentEntity) < 4096.0D)
                    {
                        double d1 = entitylivingbase.posX - this.parentEntity.posX;
                        double d2 = entitylivingbase.posZ - this.parentEntity.posZ;
                        this.parentEntity.rotationYaw = -((float)MathHelper.atan2(d1, d2)) * (180F / (float)Math.PI);
                        this.parentEntity.renderYawOffset = this.parentEntity.rotationYaw;
                    }
                }
            }
        }
             static class AIRandomFly extends EntityAIBase
        {
            private final EntitybulletBill parentEntity;
            public AIRandomFly(EntitybulletBill bulletBill)
            {
                this.parentEntity = bulletBill;
                this.setMutexBits(1);
            }
            /**
             * Returns whether the EntityAIBase should begin execution.
             */
            public boolean shouldExecute()
            {
                EntityMoveHelper entitymovehelper = this.parentEntity.getMoveHelper();
                if (!entitymovehelper.isUpdating())
                {
                    return true;
                }
                else
                {
                    double d0 = entitymovehelper.getX() - this.parentEntity.posX;
                    double d1 = entitymovehelper.getY() - this.parentEntity.posY;
                    double d2 = entitymovehelper.getZ() - this.parentEntity.posZ;
                    double d3 = d0 * d0 + d1 * d1 + d2 * d2;
                    return d3 < 1.0D || d3 > 3600.0D;
                }
            }
            /**
             * Returns whether an in-progress EntityAIBase should continue executing
             */
            public boolean continueExecuting()
            {
                return false;
            }
            /**
             * Execute a one shot task or start executing a continuous task
             */
            public void startExecuting()
            {
                Random random = this.parentEntity.getRNG();
                double d0 = this.parentEntity.posX + (double)((random.nextFloat() * 2.0F - 1.0F) * 10.0F);
                double d1 = this.parentEntity.posY + (double)((random.nextFloat() * 2.0F - 1.0F) * 2.0F);
                double d2 = this.parentEntity.posZ + (double)((random.nextFloat() * 2.0F - 1.0F) * 10.0F);
                this.parentEntity.getMoveHelper().setMoveTo(d0, d1, d2, 1.0D);
            }
        }
    static class bulletBillMoveHelper extends EntityMoveHelper
        {
            private final EntitybulletBill parentEntity;
            private int courseChangeCooldown;
            public bulletBillMoveHelper(EntitybulletBill bulletBill)
            {
                super(bulletBill);
                this.parentEntity = bulletBill;
            }
            public void onUpdateMoveHelper()
            {

                    double d0 = this.posX - this.parentEntity.posX;
                    double d1 = this.posY - this.parentEntity.posY;
                    double d2 = this.posZ - this.parentEntity.posZ;
                    double d3 = d0 * d0 + d1 * d1 + d2 * d2;
                    
                while(d0 == 0 || d2 == 0)
                {
                    d0 = this.posX - this.parentEntity.posX;
                    d1 = this.posY - this.parentEntity.posY;
                    d2 = this.posZ - this.parentEntity.posZ;
                    d3 = d0 * d0 + d1 * d1 + d2 * d2;                
                }
                
                
                        this.courseChangeCooldown += this.parentEntity.getRNG().nextInt(5) + 2;
                        d3 = (double)MathHelper.sqrt(d3);

                            this.parentEntity.motionX += d0 / d3 * 0.07D;
                            this.parentEntity.motionY += d1 / d3 * 0.01D;
                            this.parentEntity.motionZ += d2 / d3 * 0.07D;
                
            }
            
        }
    }
    /**
     * BulletBill - Faffreux Created using Tabula 5.0.0
     */
    public static class BulletBill extends ModelBase {
        public ModelRenderer turbo;
        public ModelRenderer jointure;
        public ModelRenderer body;
        public ModelRenderer head1;
        public ModelRenderer head2;
        public ModelRenderer head3;
        public ModelRenderer Lshoulder;
        public ModelRenderer Rshoulder;
        public ModelRenderer Larm;
        public ModelRenderer Lelbow;
        public ModelRenderer Lhand;
        public ModelRenderer Rarm;
        public ModelRenderer Relbow;
        public ModelRenderer Rhand;
        public BulletBill() {
            this.textureWidth = 128;
            this.textureHeight = 64;
            this.Rshoulder = new ModelRenderer(this, 50, 20);
            this.Rshoulder.setRotationPoint(-7.0F, 15.0F, 0.0F);
            this.Rshoulder.addBox(-1.0F, -2.0F, -2.0F, 1, 4, 4, 0.0F);
            this.jointure = new ModelRenderer(this, 0, 18);
            this.jointure.setRotationPoint(0.0F, 15.0F, 5.0F);
            this.jointure.addBox(-6.0F, -6.0F, 0.0F, 12, 12, 3, 0.0F);
            this.Lhand = new ModelRenderer(this, 50, 35);
            this.Lhand.setRotationPoint(7.0F, 14.5F, 0.0F);
            this.Lhand.addBox(2.0F, -0.5F, -7.0F, 3, 4, 3, 0.0F);
            this.Rarm = new ModelRenderer(this, 50, 35);
            this.Rarm.setRotationPoint(-7.0F, 14.5F, 0.0F);
            this.Rarm.addBox(-5.0F, -1.0F, -1.0F, 5, 2, 2, 0.0F);
            this.setRotateAngle(Rarm, 0.0F, 0.0F, -0.40980330836826856F);
            this.head3 = new ModelRenderer(this, 100, 0);
            this.head3.setRotationPoint(0.0F, 15.0F, -14.0F);
            this.head3.addBox(-4.0F, -4.0F, 0.0F, 8, 8, 2, 0.0F);
            this.Larm = new ModelRenderer(this, 50, 35);
            this.Larm.setRotationPoint(7.0F, 14.5F, 0.0F);
            this.Larm.addBox(0.0F, -1.0F, -1.0F, 5, 2, 2, 0.0F);
            this.setRotateAngle(Larm, 0.0F, 0.0F, 0.40980330836826856F);
            this.Relbow = new ModelRenderer(this, 50, 35);
            this.Relbow.setRotationPoint(-7.0F, 14.5F, 0.0F);
            this.Relbow.addBox(-5.0F, -1.0F, -5.0F, 2, 2, 5, 0.0F);
            this.setRotateAngle(Relbow, 0.0F, 0.0F, -0.40980330836826856F);
            this.body = new ModelRenderer(this, 0, 33);
            this.body.setRotationPoint(0.0F, 15.0F, -8.3F);
            this.body.addBox(-7.0F, -7.0F, 0.0F, 14, 14, 15, 0.0F);
            this.Lshoulder = new ModelRenderer(this, 50, 20);
            this.Lshoulder.setRotationPoint(7.0F, 15.0F, 0.0F);
            this.Lshoulder.addBox(0.0F, -2.0F, -2.0F, 1, 4, 4, 0.0F);
            this.head1 = new ModelRenderer(this, 38, 0);
            this.head1.setRotationPoint(0.0F, 15.0F, -11.0F);
            this.head1.addBox(-6.0F, -6.0F, 0.0F, 12, 12, 4, 0.0F);
            this.Lelbow = new ModelRenderer(this, 50, 35);
            this.Lelbow.setRotationPoint(7.0F, 14.5F, 0.0F);
            this.Lelbow.addBox(3.0F, -1.0F, -5.0F, 2, 2, 5, 0.0F);
            this.setRotateAngle(Lelbow, 0.0F, 0.0F, 0.40980330836826856F);
            this.turbo = new ModelRenderer(this, 0, 0);
            this.turbo.setRotationPoint(0.0F, 15.0F, 8.0F);
            this.turbo.addBox(-7.0F, -7.0F, 0.0F, 14, 14, 4, 0.0F);
            this.Rhand = new ModelRenderer(this, 50, 35);
            this.Rhand.setRotationPoint(-7.0F, 14.5F, 0.0F);
            this.Rhand.addBox(-5.0F, -0.5F, -7.0F, 3, 4, 3, 0.0F);
            this.head2 = new ModelRenderer(this, 73, 0);
            this.head2.setRotationPoint(0.0F, 15.0F, -13.0F);
            this.head2.addBox(-5.0F, -5.0F, 0.0F, 10, 10, 3, 0.0F);
        }
        @Override
        public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) {
            this.Rshoulder.render(f5);
            this.jointure.render(f5);
            this.Lhand.render(f5);
            this.Rarm.render(f5);
            this.head3.render(f5);
            this.Larm.render(f5);
            this.Relbow.render(f5);
            this.body.render(f5);
            this.Lshoulder.render(f5);
            this.head1.render(f5);
            this.Lelbow.render(f5);
            this.turbo.render(f5);
            this.Rhand.render(f5);
            this.head2.render(f5);
        }
        /**
         * This is a helper function from Tabula to set the rotation of model
         * parts
         */
        public void setRotateAngle(ModelRenderer modelRenderer, float x, float y, float z) {
            modelRenderer.rotateAngleX = x;
            modelRenderer.rotateAngleY = y;
            modelRenderer.rotateAngleZ = z;
        }
    }
}


I used the method onCollideWithPlayer like that :


 

public void onCollideWithPlayer(EntityPlayer entityplayer)
    {
               int i = (int) this.posX;
               int j = (int) this.posY;
               int k = (int) this.posZ;
               world.createExplosion((Entity) null, i, j, k, 4F, true);
    }

and it worked perfectly fine so no need to call the method collideWithEntities right? and by the way thanks for replying

Edited by Faffreux
Link to comment
Share on other sites

please use spoilers (that eye on the tool bar of the editor) for logs and code tags (that <> mark on the toolbar) for code also while mcreator is not the best solution good thing that you are writing some of the code manually

Edited by lukas2005
Link to comment
Share on other sites

2 hours ago, diesieben07 said:

And if you checked out the original code you would see that the method is private in EntityDragon and called from the EntityDragon code.

Please learn basic programming before making a Minecraft mod.

In fact I changed the private method into a public one to see if it could work and no need to be salty. I'll do my best to find a solution and I'll post it here anyway thanks I guess

Edited by Faffreux
Link to comment
Share on other sites

  • 2 years later...
  • Guest locked this topic
Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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