Skip to content
TheChatArchiveThe Chat Archive
Geminigemini-2.5-pro· GoogleHugging Face LMArena Human Preference 140K

package net.mattias.cobblesnapshot.block.entity; import…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Mistralmistral-medium-2505’s answer.
  1. User

    package net.mattias.cobblesnapshot.block.entity;

    import net.mattias.cobblesnapshot.block.ModBlockEntities; import net.minecraft.core.BlockPos; import net.minecraft.core.HolderLookup; // NEW: Import HolderLookup import net.minecraft.core.component.DataComponents; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.component.CustomData; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState;

    public class ImageFrameBlockEntity extends BlockEntity { private CompoundTag imageData; // Stores the raw NBT from the film private String takenBy = ""; private String takenOn = ""; private String pokemonSpecies = ""; private boolean isShiny = false;

    public ImageFrameBlockEntity(BlockPos pos, BlockState state) {
        // CORRECTED: Removed .get() here. ModBlockEntities.IMAGE_FRAME is already the BlockEntityType instance.
        super(ModBlockEntities.IMAGE_FRAME.get(), pos, state);
    }
    
    public boolean setImageFromFilm(ItemStack filmItem) {
        CustomData customData = filmItem.get(DataComponents.CUSTOM_DATA);
        if (customData == null) return false;
    
        CompoundTag tag = customData.copyTag();
        if (!tag.contains("PokemonSpecies")) return false; // Essential data check
    
        // Store the image data and extract specific fields
        this.imageData = tag.copy(); // Keep a copy of the full NBT
        this.takenBy = tag.getString("TakenBy");
        this.takenOn = tag.getString("TakenOn");
        this.pokemonSpecies = tag.getString("PokemonSpecies");
        this.isShiny = tag.getBoolean("IsShiny");
    
        // Mark the block entity as changed
        setChanged();
        // Send updates to clients to ensure they see the new data
        if (level != null && !level.isClientSide()) { // Only send packet from server
            level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), 3);
        }
        return true;
    }
    
    @Override
    // CORRECTED: Added HolderLookup.Provider argument
    protected void saveAdditional(CompoundTag tag, HolderLookup.Provider provider) {
        super.saveAdditional(tag, provider); // Call super with both arguments
        if (imageData != null) {
            tag.put("ImageData", imageData); // Save the entire image data NBT
        }
        // Save individual fields for easier access and clarity in NBT
        tag.putString("TakenBy", takenBy);
        tag.putString("TakenOn", takenOn);
        tag.putString("PokemonSpecies", pokemonSpecies);
        tag.putBoolean("IsShiny", isShiny);
    }
    
    @Override
    public void load(CompoundTag tag, HolderLookup.Provider provider) {
        super.load(tag, provider); // Call super with both arguments
        if (tag.contains("ImageData")) {
            this.imageData = tag.getCompound("ImageData"); // Load the entire image data NBT
        } else {
            this.imageData = new CompoundTag(); // Initialize if not present
        }
        // Load individual fields
        this.takenBy = tag.getString("TakenBy");
        this.takenOn = tag.getString("TakenOn");
        this.pokemonSpecies = tag.getString("PokemonSpecies");
        this.isShiny = tag.getBoolean("IsShiny");
    }
    
    @Override
    public ClientboundBlockEntityDataPacket getUpdatePacket() {
        // getUpdateTag() internally calls saveAdditional, so it includes all data for client sync
        return ClientboundBlockEntityDataPacket.create(this);
    }
    
    @Override
    public CompoundTag getUpdateTag(HolderLookup.Provider provider) { // NEW: added HolderLookup.Provider argument
        CompoundTag tag = super.getUpdateTag(provider); // Call super with argument
        saveAdditional(tag, provider); // Pass provider to saveAdditional
        return tag;
    }
    
    // Getters remain the same
    public CompoundTag getImageData() {
        return imageData;
    }
    
    public String getTakenBy() {
        return takenBy;
    }
    
    public String getTakenOn() {
        return takenOn;
    }
    
    public String getPokemonSpecies() {
        return pokemonSpecies;
    }
    
    public boolean isShiny() {
        return isShiny;
    }
    

    } Method does not override method from its superclass Cannot resolve method 'load' in 'BlockEntity'

    package net.mattias.cobblesnapshot.block;

    import com.mojang.serialization.MapCodec; // NEW: Import MapCodec import net.mattias.cobblesnapshot.block.entity.ImageFrameBlockEntity; import net.mattias.cobblesnapshot.item.ModItems; import net.minecraft.core.BlockPos; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.BaseEntityBlock; import net.minecraft.world.level.block.RenderShape; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; import org.jetbrains.annotations.Nullable;

    public class ImageFrameBlock extends BaseEntityBlock { // NEW: Define the MapCodec for the block public static final MapCodec CODEC = simpleCodec(ImageFrameBlock::new);

    private static final VoxelShape SHAPE = box(0, 0, 0, 16, 16, 1);
    
    public ImageFrameBlock(Properties properties) {
        super(properties);
    }
    
    @Override
    // CORRECTED: Return the defined CODEC
    protected MapCodec<? extends BaseEntityBlock> codec() {
        return CODEC;
    }
    
    @Override
    public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
        return SHAPE;
    }
    
    @Override
    public RenderShape getRenderShape(BlockState state) {
        return RenderShape.MODEL;
    }
    
    @Nullable
    @Override
    public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
        return new ImageFrameBlockEntity(pos, state);
    }
    
    @Override
    public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
        if (level.isClientSide()) {
            return InteractionResult.SUCCESS;
        }
    
        BlockEntity blockEntity = level.getBlockEntity(pos);
        if (blockEntity instanceof ImageFrameBlockEntity imageFrame) {
            ItemStack heldItem = player.getItemInHand(hand);
    
            // If player is holding an Image Film, set the frame's image
            if (heldItem.is(ModItems.IMAGE_FILM.get())) {
                boolean success = imageFrame.setImageFromFilm(heldItem);
                if (success && !player.getAbilities().instabuild) {
                    heldItem.shrink(1);
                }
                return InteractionResult.CONSUME; // Use CONSUME on server side to reflect changes
            }
        }
    
        return InteractionResult.PASS;
    }
    

    } Method does not override method from its superclass

  2. Gemini Assistant

    Of course! You're very close. These errors are due to subtle but important API changes in recent Minecraft/NeoForge versions for how block entities save/load data and how blocks handle interactions.

    Let's fix them one by one.


    1. ImageFrameBlockEntity.java

    Errors:

    • Method does not override method from its superclass
    • Cannot resolve method 'load' in 'BlockEntity'

    Reason: In Minecraft 1.20.5+, the load(CompoundTag, ...) method in BlockEntity was renamed to loadAdditional(...) and made protected. The base BlockEntity class now has its own final load method which handles loading the block entity's ID and position, and then it calls loadAdditional for your custom data. You need to override loadAdditional instead.

    Fix: Simply rename your load method to loadAdditional and make sure it is protected.

    package net.mattias.cobblesnapshot.block.entity;
    
    import net.mattias.cobblesnapshot.block.ModBlockEntities;
    import net.minecraft.core.BlockPos;
    import net.minecraft.core.HolderLookup;
    import net.minecraft.core.component.DataComponents;
    import net.minecraft.nbt.CompoundTag;
    import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
    import net.minecraft.world.item.ItemStack;
    import net.minecraft.world.item.component.CustomData;
    import net.minecraft.world.level.block.entity.BlockEntity;
    import net.minecraft.world.level.block.state.BlockState;
    
    public class ImageFrameBlockEntity extends BlockEntity {
        private CompoundTag imageData;
        private String takenBy = "";
        private String takenOn = "";
        private String pokemonSpecies = "";
        private boolean isShiny = false;
    
        public ImageFrameBlockEntity(BlockPos pos, BlockState state) {
            super(ModBlockEntities.IMAGE_FRAME.get(), pos, state);
        }
    
        public boolean setImageFromFilm(ItemStack filmItem) {
            CustomData customData = filmItem.get(DataComponents.CUSTOM_DATA);
            if (customData == null) return false;
    
            CompoundTag tag = customData.copyTag();
            if (!tag.contains("PokemonSpecies")) return false;
    
            this.imageData = tag.copy();
            this.takenBy = tag.getString("TakenBy");
            this.takenOn = tag.getString("TakenOn");
            this.pokemonSpecies = tag.getString("PokemonSpecies");
            this.isShiny = tag.getBoolean("IsShiny");
    
            setChanged();
            if (level != null && !level.isClientSide()) {
                level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), 3);
            }
            return true;
        }
    
        @Override
        protected void saveAdditional(CompoundTag tag, HolderLookup.Provider provider) {
            super.saveAdditional(tag, provider);
            if (imageData != null) {
                tag.put("ImageData", imageData);
            }
            tag.putString("TakenBy", takenBy);
            tag.putString("TakenOn", takenOn);
            tag.putString("PokemonSpecies", pokemonSpecies);
            tag.putBoolean("IsShiny", isShiny);
        }
    
        @Override
        // RENAMED: from 'load' to 'loadAdditional' to match the superclass method
        // Also changed to 'protected' to match the override signature
        protected void loadAdditional(CompoundTag tag, HolderLookup.Provider provider) {
            super.loadAdditional(tag, provider);
            if (tag.contains("ImageData")) {
                this.imageData = tag.getCompound("ImageData");
            } else {
                this.imageData = new CompoundTag();
            }
            this.takenBy = tag.getString("TakenBy");
            this.takenOn = tag.getString("TakenOn");
            this.pokemonSpecies = tag.getString("PokemonSpecies");
            this.isShiny = tag.getBoolean("IsShiny");
        }
    
        @Override
        public ClientboundBlockEntityDataPacket getUpdatePacket() {
            return ClientboundBlockEntityDataPacket.create(this);
        }
    
        @Override
        public CompoundTag getUpdateTag(HolderLookup.Provider provider) {
            CompoundTag tag = super.getUpdateTag(provider);
            saveAdditional(tag, provider);
            return tag;
        }
    
        // Getters
        public CompoundTag getImageData() {
            return imageData;
        }
        public String getTakenBy() {
            return takenBy;
        }
        public String getTakenOn() {
            return takenOn;
        }
        public String getPokemonSpecies() {
            return pokemonSpecies;
        }
        public boolean isShiny() {
            return isShiny;
        }
    }
    

    2. ImageFrameBlock.java

    Error:

    • Method does not override method from its superclass (on the use method)

    Reason: The signature of the use method in Block was changed in Minecraft 1.21. It is now protected and no longer takes an InteractionHand as a direct parameter. The hand is now retrieved from the BlockHitResult.

    Fix:

    1. Change the method visibility from public to protected.
    2. Remove the InteractionHand hand parameter from the method signature.
    3. Inside the method, get the hand from the hit result using hit.getHand().
    package net.mattias.cobblesnapshot.block;
    
    import com.mojang.serialization.MapCodec;
    import net.mattias.cobblesnapshot.block.entity.ImageFrameBlockEntity;
    import net.mattias.cobblesnapshot.item.ModItems;
    import net.minecraft.core.BlockPos;
    import net.minecraft.world.InteractionHand; // Keep this import for the variable
    import net.minecraft.world.InteractionResult;
    import net.minecraft.world.entity.player.Player;
    import net.minecraft.world.item.ItemStack;
    import net.minecraft.world.level.BlockGetter;
    import net.minecraft.world.level.Level;
    import net.minecraft.world.level.block.BaseEntityBlock;
    import net.minecraft.world.level.block.RenderShape;
    import net.minecraft.world.level.block.entity.BlockEntity;
    import net.minecraft.world.level.block.state.BlockState;
    import net.minecraft.world.phys.BlockHitResult;
    import net.minecraft.world.phys.shapes.CollisionContext;
    import net.minecraft.world.phys.shapes.VoxelShape;
    import org.jetbrains.annotations.Nullable;
    
    public class ImageFrameBlock extends BaseEntityBlock {
        public static final MapCodec<ImageFrameBlock> CODEC = simpleCodec(ImageFrameBlock::new);
    
        private static final VoxelShape SHAPE = box(0, 0, 0, 16, 16, 1);
    
        public ImageFrameBlock(Properties properties) {
            super(properties);
        }
    
        @Override
        protected MapCodec<? extends BaseEntityBlock> codec() {
            return CODEC;
        }
    
        @Override
        public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
            return SHAPE;
        }
    
        @Override
        public RenderShape getRenderShape(BlockState state) {
            return RenderShape.MODEL;
        }
    
        @Nullable
        @Override
        public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
            return new ImageFrameBlockEntity(pos, state);
        }
    
        @Override
        // CORRECTED: Signature changed to 'protected' and InteractionHand parameter removed
        protected InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult hit) {
            if (level.isClientSide()) {
                return InteractionResult.SUCCESS;
            }
    
            BlockEntity blockEntity = level.getBlockEntity(pos);
            if (blockEntity instanceof ImageFrameBlockEntity imageFrame) {
                // NEW: Get the hand from the BlockHitResult
                InteractionHand hand = hit.getHand();
                ItemStack heldItem = player.getItemInHand(hand);
    
                if (heldItem.is(ModItems.IMAGE_FILM.get())) {
                    boolean success = imageFrame.setImageFromFilm(heldItem);
                    if (success && !player.getAbilities().instabuild) {
                        heldItem.shrink(1);
                    }
                    return InteractionResult.CONSUME;
                }
            }
    
            return InteractionResult.PASS;
        }
    }
    

    After applying these corrections, your code should compile and run correctly. Remember to do a Gradle Refresh in your IDE to ensure it recognizes the changes.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.