Files
src
build.gradle
gradle.properties
settings.gradle
staffs&sunken
Code
15 174
src/main/java/com/kodari/tidestaffs/TideStaffs.java
package com.kodari.tidestaffs;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.creativetab.v1.CreativeModeTabEvents;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.Identifier;
import net.minecraft.resources.ResourceKey;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.hurtingprojectile.DragonFireball;
import net.minecraft.world.entity.projectile.throwableitemprojectile.ThrownSplashPotion;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.alchemy.PotionContents;
import net.minecraft.world.item.alchemy.Potions;
import net.minecraft.world.level.Level;
public class TideStaffs implements ModInitializer {
private static final String MOD_ID = "tidestaffs";
private static final Item DRAGON_STAFF = register("dragon_staff", true);
private static final Item TIDAL_STAFF = register("tidal_staff", false);
private static Item register(String name, boolean dragon) {
Identifier id = Identifier.fromNamespaceAndPath(MOD_ID, name);
ResourceKey<Item> key = ResourceKey.create(Registries.ITEM, id);
return Registry.register(BuiltInRegistries.ITEM, key, new Staff(new Item.Properties().setId(key).stacksTo(1), dragon));
}
@Override
public void onInitialize() {
CreativeModeTabEvents.modifyOutputEvent(ResourceKey.create(Registries.CREATIVE_MODE_TAB, Identifier.withDefaultNamespace("combat")))
.register(output -> {
output.prepend(new ItemStack(DRAGON_STAFF));
output.prepend(new ItemStack(TIDAL_STAFF));
});
}
private static class Staff extends Item {
private final boolean dragon;
private Staff(Properties properties, boolean dragon) {
super(properties);
this.dragon = dragon;
}
@Override
public InteractionResult use(Level level, Player player, InteractionHand hand) {
if (!level.isClientSide()) {
if (dragon) {
DragonFireball fireball = new DragonFireball(level, player, player.getLookAngle());
fireball.setPos(player.getEyePosition().add(player.getLookAngle().scale(1.5)));
level.addFreshEntity(fireball);
player.playSound(SoundEvents.FIRECHARGE_USE, 1.0F, 1.0F);
} else {
ItemStack water = PotionContents.createItemStack(Items.SPLASH_POTION, Potions.WATER);
ThrownSplashPotion projectile = new ThrownSplashPotion(level, player, water);
projectile.shootFromRotation(player, player.getXRot(), player.getYRot(), 0.0F, 1.5F, 0.5F);
level.addFreshEntity(projectile);
player.playSound(SoundEvents.SNOWBALL_THROW, 1.0F, 1.0F);
}
player.getCooldowns().addCooldown(player.getItemInHand(hand), dragon ? 60 : 10);
}
return InteractionResult.SUCCESS;
}
}
}