MinecraftScripterAI
Discord ↗
Link Copied to Clipboard
×
"can u make me a mod where there is a pistol"
/* This mod adds a simple pistol item to Minecraft. When right-clicked, it shoots a projectile. */ public class PistolItem extends Item { public PistolItem(Properties properties) { super(properties); } @Override public ActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) { if (!world.isClientSide) { BulletEntity bullet = new BulletEntity(world, player); bullet.shootFromRotation(player, player.xRot, player.yRot, 0.0F, 3.0F, 1.0F); world.addFreshEntity(bullet); } player.getCooldowns().addCooldown(this, 20); // 1 second cooldown return ActionResult.success(player.getItemInHand(hand)); } } public class BulletEntity extends ThrowableEntity { public BulletEntity(EntityType<? extends ThrowableEntity> type, World world) { super(type, world); } public BulletEntity(World world, LivingEntity owner) { super(YourMod.BULLET_ENTITY.get(), owner, world); } @Override protected void onHitEntity(EntityRayTraceResult result) { super.onHitEntity(result); result.getEntity().hurt(DamageSource.thrown(this, this.getOwner()), 5.0F); // 5 damage this.remove(); } /* Other necessary methods like registerAttributes, createSpawnPacket, etc. */ } /* You would also need to register these classes in your mod's main class and add the necessary assets (models, textures, etc.). */