MinecraftScripterAI
Discord ↗
Link Copied to Clipboard
×
"do a stick that throwing a projectile that projectile if touch a mob mob will explode"
/* First, create a custom item class for the stick that will throw the projectile */ public class ExplodingStickItem extends Item { public ExplodingStickItem(Properties properties) { super(properties); } @Override public ActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) { ItemStack stack = player.getItemInHand(hand); /* Create and spawn the custom projectile */ ExplodingProjectileEntity projectile = new ExplodingProjectileEntity(world, player); projectile.shootFromRotation(player, player.xRot, player.yRot, 0.0F, 1.5F, 1.0F); world.addFreshEntity(projectile); /* Reduce the item stack size by 1 */ if (!player.abilities.instabuild) { stack.shrink(1); } return ActionResult.success(stack); } } /* Now, create a custom projectile class that will explode when it touches a mob */ public class ExplodingProjectileEntity extends ThrowableEntity { public ExplodingProjectileEntity(EntityType<? extends ThrowableEntity> type, World world) { super(type, world); } public ExplodingProjectileEntity(World world, LivingEntity thrower) { super(EntityType.SNOWBALL, thrower, world); } @Override protected void onHitEntity(EntityRayTraceResult result) { super.onHitEntity(result); /* Check if the hit entity is a mob, then create an explosion */ if (result.getEntity() instanceof MobEntity) { this.level.explode(this, this.getX(), this.getY(), this.getZ(), 2.0F, Explosion.Mode.NONE); this.remove(); } } @Override protected void onHit(RayTraceResult result) { super.onHit(result); if (!this.level.isClientSide) { this.remove(); } } } /* Don't forget to register your custom item and projectile entity in your mod's registry */