Files
src
build.gradle
gradle.properties
settings.gradle
Code
10 178
src/main/java/com/nullarmy/NullArmyMod.java
package com.nullarmy;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.creativetab.v1.CreativeModeTabEvents;
import net.minecraft.core.Registry;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.Identifier;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.EntitySpawnReason;
import net.minecraft.world.entity.EntityTypes;
import net.minecraft.world.entity.animal.wolf.Wolf;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.Level;
public class NullArmyMod implements ModInitializer {
public static final String MOD_ID = "nullarmy";
private static final Identifier NULL_RECRUIT_SEAL_ID = Identifier.fromNamespaceAndPath(MOD_ID, "null_recruit_seal");
private static final ResourceKey<CreativeModeTab> TOOLS_AND_UTILITIES = ResourceKey.create(
Registries.CREATIVE_MODE_TAB,
Identifier.fromNamespaceAndPath("minecraft", "tools_and_utilities")
);
public static final Item NULL_RECRUIT_SEAL = Registry.register(
BuiltInRegistries.ITEM,
NULL_RECRUIT_SEAL_ID,
new NullRecruitSealItem(new Item.Properties().setId(ResourceKey.create(Registries.ITEM, NULL_RECRUIT_SEAL_ID)))
);
@Override
public void onInitialize() {
CreativeModeTabEvents.modifyOutputEvent(TOOLS_AND_UTILITIES).register(output -> output.prepend(NULL_RECRUIT_SEAL));
}
private static final class NullRecruitSealItem extends Item {
private NullRecruitSealItem(final Item.Properties properties) {
super(properties);
}
@Override
public InteractionResult use(final Level level, final Player player, final InteractionHand hand) {
if (!level.isClientSide() && level instanceof ServerLevel serverLevel) {
Wolf recruit = EntityTypes.WOLF.create(level, EntitySpawnReason.TRIGGERED);
if (recruit != null) {
recruit.setPos(player.getX() + 1.0, player.getY(), player.getZ());
recruit.tame(player);
recruit.setCustomName(Component.literal("Null Recruit"));
recruit.setPersistenceRequired();
if (serverLevel.addFreshEntity(recruit)) {
player.getItemInHand(hand).consume(1, player);
recruit.playSound(SoundEvents.ENDERMAN_TELEPORT, 0.8F, 1.2F);
serverLevel.sendParticles(
ParticleTypes.PORTAL,
recruit.getX(),
recruit.getY() + 0.8,
recruit.getZ(),
18,
0.35,
0.5,
0.35,
0.02
);
}
}
}
return InteractionResult.SUCCESS;
}
}
}