最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - How to access @Unique field using @Accessor in Minecraft Modding Fabric 1.20.1? - Stack Overflow

programmeradmin0浏览0评论

Here's my Accessor:

@Mixin(targets = "com.trongthang.bettercampfires.mixin.CampfireBlockEntityMixin")
public interface CampfireBlockEntityAccessor {

    @Accessor(value = "campfireBurntime", remap = false)
    int getCampfireBurntime();

    @Accessor(value = "campfireBurntime", remap = false)
    void setCampfireBurntime(int burnTime);
}

I'm trying to access the @Unique fiels of the CampfireBlockEntityMixin

@Mixin(CampfireBlockEntity.class)
class CampfireBlockEntityMixin {

    private int buffCheckCounter = 0;
    private static int buffRadius = ModConfig.getInstance().buffRadius;

    // Add a custom burn time field
    @Unique
    private int campfireBurntime = 0;
}

Here's where i try to use the Accessor, i want players can refuel the campfire by interacting with it:

@Mixin(CampfireBlock.class)
public class CampfireBlockFuel {
    @Inject(method = "onUse", at = @At("HEAD"), cancellable = true)
    public void onPlayerInteract(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable<ActionResult> cir) {
        // Only proceed if it's not a client-side interaction and the campfire is lit
        if (!world.isClient && state.get(CampfireBlock.LIT) && !ModConfig.getInstance().campfireFuels.isEmpty() && ModConfig.getInstance().campfiresCanBurnOut) {
            ItemStack heldItem = player.getStackInHand(hand);
            String fuelId = heldItem.getItem().getTranslationKey();

            // Normalize the translation key for block or item
            String itemId = fuelId.replace("item.minecraft.", "minecraft:").replace("block.minecraft.", "minecraft:");

            boolean fuelFound = false; // Flag to track if we found the fuel
            for (ModConfig.CampfireFuels fuel : ModConfig.getInstance().campfireFuels) {
                if (fuel.fuelId.equals(itemId)) {
                    fuelFound = true;

                    if (heldItem.getCount() > 0) {
                        heldItem.decrement(1);

                        int fuelTime = fuel.addBurnTime;

                        // Update the campfire's cooldown list
                        campfiresListputeIfPresent(pos, (p, cooldown) -> {
                            cooldown.timeLeft += fuelTime;
                            return cooldown;
                        });

                        // Get the campfire BlockEntity
                        BlockEntity blockEntity = world.getBlockEntity(pos);
                        if (blockEntity instanceof CampfireBlockEntity) {

                            CampfireBlockEntityAccessor campfireBlockEntityAccessor = (CampfireBlockEntityAccessor) blockEntity;
                            int currentBurnTime = campfireBlockEntityAccessor.getCampfireBurntime();
                            campfireBlockEntityAccessor.setCampfireBurntime(currentBurnTime + fuelTime);

                            LOGGER.info("BURN TIME: " + campfireBlockEntityAccessor.getCampfireBurntime());
                        }


                        // Send network packet if needed
                        ServerPlayNetworking.send(player.getServer().getPlayerManager().getPlayer(player.getUuid()), PLAY_BLOCK_LAVA_EXTINGUISH, PacketByteBufs.empty());

                        // Set the return value to indicate success
                        cir.setReturnValue(ActionResult.SUCCESS);
                        cir.cancel();
                    }
                    break; // Exit the loop once the fuel is found
                }
            }
        }
    }
}

Here's the ERROR i keep getting:

[13:41:22] [Server thread/ERROR]: Failed to handle packet net.minecraft.class_2885@2f1a1d1d, suppressing error
java.lang.RuntimeException: Mixin transformation of com.trongthang.bettercampfires.mixin.CampfireBlockEntityAccessor failed
    at net.fabricmc.loader.impl.launch.knot.KnotClassDelegate.getPostMixinClassByteArray(KnotClassDelegate.java:427) ~[fabric-loader-0.16.10.jar:?]
    at net.fabricmc.loader.impl.launch.knot.KnotClassDelegate.tryLoadClass(KnotClassDelegate.java:323) ~[fabric-loader-0.16.10.jar:?]
    at net.fabricmc.loader.impl.launch.knot.KnotClassDelegate.loadClass(KnotClassDelegate.java:218) ~[fabric-loader-0.16.10.jar:?]
    at net.fabricmc.loader.impl.launch.knot.KnotClassLoader.loadClass(KnotClassLoader.java:119) ~[fabric-loader-0.16.10.jar:?]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:525) ~[?:?]
    at net.minecraft.class_3922.handler$zdd000$bettercampfires$onPlayerInteract(class_3922.java:556) ~[client-intermediary.jar:?]
    at net.minecraft.class_3922.method_9534(class_3922.java) ~[client-intermediary.jar:?]
    at net.minecraft.class_4970$class_4971.method_26174(class_4970.java:1133) ~[client-intermediary.jar:?]
    at net.minecraft.class_3225.method_14262(class_3225.java:343) ~[client-intermediary.jar:?]
    at net.minecraft.class_3244.method_12046(class_3244.java:1140) ~[client-intermediary.jar:?]
    at net.minecraft.class_2885.method_12547(class_2885.java:34) ~[client-intermediary.jar:?]
    at net.minecraft.class_2885.method_11054(class_2885.java:8) ~[client-intermediary.jar:?]
    at net.minecraft.class_2600.method_11072(class_2600.java:22) ~[client-intermediary.jar:?]
    at net.minecraft.class_3738.run(class_3738.java:18) ~[client-intermediary.jar:?]
    at net.minecraft.class_1255.method_18859(class_1255.java:156) ~[client-intermediary.jar:?]
    at net.minecraft.class_4093.method_18859(class_4093.java:23) ~[client-intermediary.jar:?]
    at net.minecraft.server.MinecraftServer.method_24306(MinecraftServer.java:782) ~[client-intermediary.jar:?]
    at net.minecraft.server.MinecraftServer.method_18859(MinecraftServer.java:164) ~[client-intermediary.jar:?]
    at net.minecraft.class_1255.method_16075(class_1255.java:130) ~[client-intermediary.jar:?]
    at net.minecraft.server.MinecraftServer.method_20415(MinecraftServer.java:764) ~[client-intermediary.jar:?]
    at net.minecraft.server.MinecraftServer.method_16075(MinecraftServer.java:758) ~[client-intermediary.jar:?]
    at net.minecraft.class_1255.method_5383(class_1255.java:115) ~[client-intermediary.jar:?]
    at net.minecraft.server.MinecraftServer.method_16208(MinecraftServer.java:742) ~[client-intermediary.jar:?]
    at net.minecraft.server.MinecraftServer.method_29741(MinecraftServer.java:675) ~[client-intermediary.jar:?]
    at net.minecraft.server.MinecraftServer.method_29739(MinecraftServer.java:265) ~[client-intermediary.jar:?]
    at java.lang.Thread.run(Thread.java:833) ~[?:?]
Caused by: .spongepowered.asm.mixin.transformer.throwables.IllegalClassLoadError: Illegal classload request for accessor mixin com.trongthang.bettercampfires.mixin.CampfireBlockEntityAccessor. The mixin is missing from bettercampfires.mixins.json which owns package com.trongthang.bettercampfires.mixin.* and the mixin has not been applied.
    at .spongepowered.asm.mixin.transformer.MixinProcessor.applyMixins(MixinProcessor.java:334) ~[sponge-mixin-0.15.4+mixin.0.8.7.jar:0.15.4+mixin.0.8.7]
    at .spongepowered.asm.mixin.transformer.MixinTransformer.transformClass(MixinTransformer.java:234) ~[sponge-mixin-0.15.4+mixin.0.8.7.jar:0.15.4+mixin.0.8.7]
    at .spongepowered.asm.mixin.transformer.MixinTransformer.transformClassBytes(MixinTransformer.java:202) ~[sponge-mixin-0.15.4+mixin.0.8.7.jar:0.15.4+mixin.0.8.7]
    at net.fabricmc.loader.impl.launch.knot.KnotClassDelegate.getPostMixinClassByteArray(KnotClassDelegate.java:422) ~[fabric-loader-0.16.10.jar:?]
    ... 25 more

Really hope someone can help me with this, I've been trying for few weeks now but i couldn't find the answer.

发布评论

评论列表(0)

  1. 暂无评论