Recently I have started making a mod for fun. The mod is basically just me adding anything that comes to my mind. One of the ideas was an explosive, throwable pusheen. The problem is that when you throw it while moving it just blows up the player. I tried to do it like in the ender pearl code (which ignores the thrower) and it does not work.
Here is my PusheenEntity class
package com.davide_24.uselessmod.objects.entities;package com.davide_24.uselessmod.objects.entities;
import com.davide_24.uselessmod.lists.EntityList;import com.davide_24.uselessmod.lists.ItemList;
import net.minecraft.entity.Entity;import net.minecraft.entity.EntityType;import net.minecraft.entity.LivingEntity;import net.minecraft.entity.projectile.ProjectileItemEntity;import net.minecraft.item.Item;import net.minecraft.network.IPacket;import net.minecraft.util.math.EntityRayTraceResult;import net.minecraft.util.math.RayTraceResult;import net.minecraft.world.Explosion;import net.minecraft.world.World;import net.minecraftforge.fml.network.NetworkHooks;
public class PusheenEntity extends ProjectileItemEntity { private LivingEntity pusheenThrower; public PusheenEntity(EntityType<PusheenEntity> type, World world) { super(type, world); } public PusheenEntity(LivingEntity entity, World world) { super(EntityList.PUSHEEN_PROJECTILE.get(), entity, world); } public PusheenEntity(double x, double y, double z, World world) { super(EntityList.PUSHEEN_PROJECTILE.get(), x, y , z, world); } @Override protected Item getDefaultItem() { return ItemList.PUSHEEN.get(); } @Override public IPacket<?> createSpawnPacket() { return NetworkHooks.getEntitySpawningPacket(this); } @Override protected void onImpact(RayTraceResult result) { if (result.getType() == RayTraceResult.Type.ENTITY) { Entity entity = ((EntityRayTraceResult)result).getEntity(); if (entity == this.pusheenThrower) { return; } else { world.createExplosion(this, this.getPosX(), this.getPosY(), this.getPosZ(), 2.0F, Explosion.Mode.DESTROY); } } if (result.getType() == RayTraceResult.Type.BLOCK) { world.createExplosion(this, this.getPosX(), this.getPosY(), this.getPosZ(), 2.0F, Explosion.Mode.DESTROY); } if (!this.world.isRemote) { this.world.setEntityState(this, (byte)3); this.remove(); } }
Recently I have started making a mod for fun. The mod is basically just me adding anything that comes to my mind. One of the ideas was an explosive, throwable pusheen. The problem is that when you throw it while moving it just blows up the player. I tried to do it like in the ender pearl code (which ignores the thrower) and it does not work.
Here is my PusheenEntity class