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 public class ExplodingStickItem extends Item { public ExplodingStickItem(Properties properties) { super(properties); } -- Override the onItemRightClick method to throw the projectile @Override public ActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) { ItemStack itemStack = player.getItemInHand(hand); world.playSound(null, player.getX(), player.getY(), player.getZ(), SoundEvents.ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F); if (!world.isClientSide) { ExplodingProjectileEntity projectile = new ExplodingProjectileEntity(world, player); projectile.shootFromRotation(player, player.xRot, player.yRot, 0.0F, 1.5F, 1.0F); world.addFreshEntity(projectile); } player.getCooldowns().addCooldown(this, 20); return ActionResult.success(itemStack); } } -- Next, create a custom entity class for the projectile public class ExplodingProjectileEntity extends ThrowableEntity { public ExplodingProjectileEntity(EntityType<? extends ThrowableEntity> entityType, World world) { super(entityType, world); } public ExplodingProjectileEntity(World world, LivingEntity thrower) { super(EntityTypeInit.EXPLODING_PROJECTILE.get(), thrower, world); } -- Override the onHit method to make the mob explode @Override protected void onHitEntity(EntityRayTraceResult result) { super.onHitEntity(result); Entity entity = result.getEntity(); if (entity instanceof LivingEntity) { entity.level.explode(null, entity.getX(), entity.getY(), entity.getZ(), 3.0F, Explosion.Mode.BREAK); } this.remove(); } -- Override the onHit method to remove the projectile when it hits a block @Override protected void onHitBlock(BlockRayTraceResult result) { super.onHitBlock(result); this.remove(); } } -- Finally, register the item and entity in your registry classes