Traveler's Backpack

Traveler's Backpack

32M Downloads

travelersbackpack-fabric-1.20.1-9.1.11

oleg12054 opened this issue · 2 comments

commented

package com.tiviacz.travelersbackpack.common;

import net.minecraft.entity.player.PlayerEntity;
import net.fabricmc.fabric.api.event.player.AttackEntityCallback;
import net.fabricmc.fabric.api.event.player.UseEntityCallback;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.ActionResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import com.jamieswhiteshirt.reachentityattributes.ReachEntityAttributes;
import com.tiviacz.travelersbackpack.blockentity.TravelersBackpackBlockEntity;
import com.tiviacz.travelersbackpack.component.ComponentUtils;
import com.tiviacz.travelersbackpack.init.ModBlocks;
import com.tiviacz.travelersbackpack.init.ModItems;
import com.tiviacz.travelersbackpack.inventory.ITravelersBackpackInventory;
import com.tiviacz.travelersbackpack.inventory.TravelersBackpackInventory;
import com.tiviacz.travelersbackpack.util.BackpackUtils;
import com.tiviacz.travelersbackpack.util.TimeUtils;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant;
import net.fabricmc.fabric.api.transfer.v1.storage.base.SingleVariantStorage;
import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.FluidBlock;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityPose;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.TargetPredicate;
import net.minecraft.entity.attribute.EntityAttribute;
import net.minecraft.entity.attribute.EntityAttributeInstance;
import net.minecraft.entity.attribute.EntityAttributeModifier;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.mob.GhastEntity;
import net.minecraft.entity.mob.HostileEntity;
import net.minecraft.entity.projectile.SmallFireballEntity;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.particle.BlockStateParticleEffect;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.explosion.Explosion;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import net.minecraft.entity.EntityType;
import net.minecraft.util.TypedActionResult;
import net.minecraft.entity.damage.DamageSource;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;

import javax.security.auth.Destroyable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;

public class BackpackAbilities
{
///
private static boolean isLightningStruck = false;
private static long lightningStruckTime = 0;
private static final long LIGHTNING_EFFECT_DURATION = 600; // 30 seconds (20 ticks per second)

public void onInitialize() {
    // Регистрация обратного вызова для атаки молнии
    AttackEntityCallback.EVENT.register((player, world, hand, entity, hitResult) -> {
        if (entity.getType() == EntityType.LIGHTNING_BOLT && entity.getUuidAsString().equals("some_uuid")) {
            onStruckByLightning(player);
        }
        return ActionResult.PASS;
    });

    UseEntityCallback.EVENT.register((player, world, hand, entity, hitResult) -> {
        if (entity.getType() == EntityType.LIGHTNING_BOLT && entity.getUuidAsString().equals("some_uuid")) {
            onStruckByLightning(player);
            return ActionResult.SUCCESS;
        }
        return ActionResult.PASS;
    });

    // Регистрация HUD рендера
    HudRenderCallback.EVENT.register((drawContext, tickDelta) -> renderLightningTimer(drawContext.getMatrices(), tickDelta));
}

public static void onStruckByLightning(PlayerEntity player) {
    isLightningStruck = true;
    lightningStruckTime = player.getEntityWorld().getTime();
}

public static boolean creeperAbility(PlayerEntity player) {
    TravelersBackpackInventory inv = ComponentUtils.getBackpackInv(player);

    if (inv != null && inv.getItemStack().getItem() == ModItems.CREEPER_TRAVELERS_BACKPACK && inv.getAbilityValue() && inv.getLastTime() <= 0) {
        if (player.isDead()) {
            handlePlayerDeath(player, inv);
            return true;
        }
    }
    return false;
}

private static void handlePlayerDeath(PlayerEntity player, TravelersBackpackInventory inv) {
    World world = player.getEntityWorld();
    long currentTime = world.getTime();

    boolean isEnhanced = isLightningStruck && (currentTime - lightningStruckTime) <= LIGHTNING_EFFECT_DURATION;
    float explosionPower = isEnhanced ? 6.0F : 3.0F;

    if (isEnhanced) {
        player.setHealth(1.0F);
        player.addStatusEffect(new StatusEffectInstance(StatusEffects.REGENERATION, 20 * 10 + 100, 2));
        player.addStatusEffect(new StatusEffectInstance(StatusEffects.ABSORPTION, 20 * 10 + 100, 2));
        player.addStatusEffect(new StatusEffectInstance(StatusEffects.FIRE_RESISTANCE, 20 * 35, 0));
        world.createExplosion(player, player.getX(), player.getY(), player.getZ(), explosionPower, true, Explosion.DestructionType.DESTROY);
    } else {
        player.setHealth(1.0F);
        player.addStatusEffect(new StatusEffectInstance(StatusEffects.REGENERATION, 20 * 10, 1));
        player.addStatusEffect(new StatusEffectInstance(StatusEffects.ABSORPTION, 20 * 10, 1));
        player.addStatusEffect(new StatusEffectInstance(StatusEffects.FIRE_RESISTANCE, 20 * 15, 0));
        world.createExplosion(player, player.getX(), player.getY(), player.getZ(), explosionPower, true, Explosion.DestructionType.DESTROY);
    }

    // Сброс состояния от удара молнией
    if (isEnhanced) {
        isLightningStruck = false;
        lightningStruckTime = 0;
    }
}

private static void renderLightningTimer(MatrixStack matrixStack, float tickDelta) {
    if (isLightningStruck) {
        long currentTime = MinecraftClient.getInstance().world.getTime();
        long timeLeft = LIGHTNING_EFFECT_DURATION - (currentTime - lightningStruckTime);

        if (timeLeft > 0) {
            String timerText = "Lightning Effect: " + timeLeft / 20 + "s"; // convert ticks to seconds
            MinecraftClient.getInstance().textRenderer.drawWithShadow(matrixStack, timerText, 10, 10, 0xFFFFFF);
        } else {
            isLightningStruck = false;
        }
    }
}

///
}

Помогите пожалуйста, у меня не получается правильно использовать метод:
public void onInitialize() {
// Регистрация обратного вызова для атаки молнии
AttackEntityCallback.EVENT.register((player, world, hand, entity, hitResult) -> {
if (entity.getType() == EntityType.LIGHTNING_BOLT && entity.getUuidAsString().equals("some_uuid")) {
onStruckByLightning(player);
}
return ActionResult.PASS;
});

И код вызывает ошибки:
error: cannot find symbol
MinecraftClient.getInstance().textRenderer.drawWithShadow(matrixStack, timerText, 10, 10, 0xFFFFFF);
^
symbol: method drawWithShadow(MatrixStack,String,int,int,int)
location: variable textRenderer of type TextRenderer

error: no suitable method found for createExplosion(PlayerEntity,double,double,double,float,boolean,DestructionType)
world.createExplosion(player, player.getX(), player.getY(), player.getZ(), explosionPower, true, Explosion.DestructionType.DESTROY);
^
method World.createExplosion(Entity,double,double,double,float,boolean,ExplosionSourceType) is not applicable
(argument mismatch; DestructionType cannot be converted to ExplosionSourceType)
method World.createExplosion(Entity,DamageSource,ExplosionBehavior,Vec3d,float,boolean,ExplosionSourceType) is not applicable
(argument mismatch; double cannot be converted to DamageSource)

error: no suitable method found for createExplosion(PlayerEntity,double,double,double,float,boolean,DestructionType)
world.createExplosion(player, player.getX(), player.getY(), player.getZ(), explosionPower, true, Explosion.DestructionType.DESTROY);
^
method World.createExplosion(Entity,double,double,double,float,boolean,ExplosionSourceType) is not applicable
(argument mismatch; DestructionType cannot be converted to ExplosionSourceType)
method World.createExplosion(Entity,DamageSource,ExplosionBehavior,Vec3d,float,boolean,ExplosionSourceType) is not applicable
(argument mismatch; double cannot be converted to DamageSource)

commented

*Please help me, I can't use the method correctly:

*And the code causes errors:

commented

I don't know what you want do to