Files
src
build.gradle
gradle.properties
manifest.kod
settings.gradle
Code
106 2,193
src/main/java/com/kodari/omegacatosty/OmegaCatosty.java
package com.kodari.omegacatosty;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.creativetab.v1.CreativeModeTabEvents;
import net.minecraft.core.Registry;
import net.minecraft.core.component.DataComponents;
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.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.animal.feline.Cat;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.ToolMaterial;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.SignText;
import net.minecraft.world.phys.AABB;
public class OmegaCatosty implements ModInitializer {
static final String MOD_ID = "omega_catosty";
static Item dust;
static Item stick;
static Item omegaSword;
static Item omegaSword2;
static Item collection;
static Item surprise;
static Item ingot;
@Override
public void onInitialize() {
ResourceKey<Item> dustKey = itemKey("catosty_dust");
dust = Registry.register(BuiltInRegistries.ITEM, dustKey, new Item(new Item.Properties().setId(dustKey)));
ResourceKey<Item> stickKey = itemKey("absolute_catosty_stick");
stick = Registry.register(BuiltInRegistries.ITEM, stickKey, new CatostyStick(new Item.Properties().setId(stickKey)));
ResourceKey<Item> swordKey = itemKey("omega_sword");
omegaSword = Registry.register(BuiltInRegistries.ITEM, swordKey,
new OmegaSword(new Item.Properties().setId(swordKey).sword(ToolMaterial.NETHERITE, 994.0F, -2.4F)));
ResourceKey<Item> sword2Key = itemKey("omega_sword_2");
omegaSword2 = Registry.register(BuiltInRegistries.ITEM, sword2Key,
new Item(new Item.Properties().setId(sword2Key).sword(ToolMaterial.NETHERITE, 3.0F, -2.4F)));
ResourceKey<Item> collectionKey = itemKey("dominator_collection");
collection = Registry.register(BuiltInRegistries.ITEM, collectionKey,
new DominatorCollection(new Item.Properties().setId(collectionKey)));
ResourceKey<Item> surpriseKey = itemKey("catosty_surprise");
surprise = Registry.register(BuiltInRegistries.ITEM, surpriseKey,
new CatostySurprise(new Item.Properties().setId(surpriseKey)));
ResourceKey<Item> ingotKey = itemKey("catosty_ingot");
ingot = Registry.register(BuiltInRegistries.ITEM, ingotKey, new Item(new Item.Properties().setId(ingotKey)));
OmegaWorkbench.initialize();
ChaosEntities.initialize();
ChaosMobs.initialize();
ChaosTemple.initialize();
ChaosLabyrinth.initialize();
ResourceKey<CreativeModeTab> tab = ResourceKey.create(Registries.CREATIVE_MODE_TAB, Identifier.withDefaultNamespace("ingredients"));
CreativeModeTabEvents.modifyOutputEvent(tab).register(output -> {
output.accept(dust);
output.accept(stick);
output.accept(omegaSword);
output.accept(omegaSword2);
output.accept(collection);
output.accept(surprise);
output.accept(ingot);
});
}
private static ResourceKey<Item> itemKey(String name) {
return ResourceKey.create(Registries.ITEM, Identifier.fromNamespaceAndPath(MOD_ID, name));
}
private static final class OmegaSword extends Item {
private OmegaSword(Properties properties) {
super(properties);
}
@Override
public void hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) {
if (!attacker.level().isClientSide() && attacker.getRandom().nextBoolean()) {
stack.shrink(1);
if (attacker instanceof ServerPlayer player) {
player.sendSystemMessage(Component.literal("Слишком много котостевости"));
}
}
}
}
private static final class DominatorCollection extends Item {
private DominatorCollection(Properties properties) {
super(properties);
}
@Override
public InteractionResult use(Level level, Player player, InteractionHand hand) {
if (!level.isClientSide()) {
ItemStack held = player.getItemInHand(hand);
held.shrink(1);
boolean boosted = OmegaWorkbench.nearBoostedWorkbench(level, player.blockPosition());
if (player.getRandom().nextFloat() < (boosted ? 0.7F : 0.5F)) {
ItemStack reward = new ItemStack(player.getRandom().nextFloat() < (boosted ? 0.7F : 0.5F) ? omegaSword : omegaSword2);
if (!player.addItem(reward) && !reward.isEmpty()) {
player.drop(reward, false, net.minecraft.util.Prediction.SERVER_ONLY);
}
} else if (player instanceof ServerPlayer serverPlayer) {
serverPlayer.sendSystemMessage(Component.literal("Котостевость поглотила"));
}
}
return InteractionResult.SUCCESS;
}
}
private static final class CatostySurprise extends Item {
private CatostySurprise(Properties properties) {
super(properties);
}
@Override
public InteractionResult use(Level level, Player player, InteractionHand hand) {
if (!level.isClientSide()) {
boolean boosted = OmegaWorkbench.nearBoostedWorkbench(level, player.blockPosition());
ItemStack reward = player.getRandom().nextInt(10) < (boosted ? 4 : 2) ? new ItemStack(omegaSword) : switch (player.getRandom().nextInt(4)) {
case 0 -> new ItemStack(collection);
case 1 -> new ItemStack(stick);
case 2 -> new ItemStack(dust, 3);
default -> {
ItemStack sign = new ItemStack(Items.OAK_SIGN);
sign.set(DataComponents.CUSTOM_NAME, Component.literal("Прости"));
sign.set(DataComponents.SIGN_TEXT_FRONT, SignText.EMPTY.asMutable()
.setLine(0, Component.literal("Прости")).asImmutable());
yield sign;
}
};
player.getItemInHand(hand).shrink(1);
if (!player.addItem(reward) && !reward.isEmpty()) {
player.drop(reward, false, net.minecraft.util.Prediction.SERVER_ONLY);
}
}
return InteractionResult.SUCCESS;
}
}
private static final class CatostyStick extends Item {
private CatostyStick(Properties properties) {
super(properties);
}
@Override
public InteractionResult use(Level level, Player player, InteractionHand hand) {
if (!level.isClientSide()) {
AABB area = new AABB(player.getX() - 5, player.getY() - 5, player.getZ() - 5,
player.getX() + 5, player.getY() + 5, player.getZ() + 5);
for (Cat cat : level.getEntitiesOfClass(Cat.class, area)) {
MobEffectInstance current = cat.getEffect(MobEffects.STRENGTH);
int amplifier = current == null ? 0 : Math.min(255, current.getAmplifier() + 1);
cat.addEffect(new MobEffectInstance(MobEffects.STRENGTH, 20 * 60 * 5, amplifier));
if (player instanceof ServerPlayer serverPlayer) {
serverPlayer.sendSystemMessage(Component.literal("Теперь он опасен"));
}
break;
}
}
return InteractionResult.SUCCESS;
}
}
}