C:\Users\Mattias\Desktop\Mods\CobbleSnapshot\src\main\java\net\mattias\cobblesnapshot\blo…
- User
C:\Users\Mattias\Desktop\Mods\CobbleSnapshot\src\main\java\net\mattias\cobblesnapshot\block\ImageFrameBlock.java:51: error: method does not override or implement a method from a supertype @Override ^
I tried reloaded gradle and building gradle this is not a intellij error it is a code error
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; 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 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 // Changed method to public as in 1.21 the base method is declared public 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 (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; }}
- Assistant
Thanks for the clarification that this is a compile-time error from
javacand not an IDE issue. That means the method signature you are trying to override does not exist in the superclass with that exact signature.
What’s going on?
The error:
method does not override or implement a method from a supertypemeans that the method signature you wrote does not match any method in the superclass or interfaces.
Let's check the actual method signature in Minecraft 1.21 for
Block.useIn Minecraft 1.21 (and NeoForge 1.21), the
usemethod inBlockis:public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit)Note:
- It is
public, notprotected. - It takes 6 parameters:
BlockState,Level,BlockPos,Player,InteractionHand,BlockHitResult.
Your method matches this signature exactly, so it should override.
Why does the compiler say it doesn't?
Possible reasons:
-
Your
BaseEntityBlocksuperclass does NOT have this method declared.BaseEntityBlockextendsBlock.- If
BaseEntityBlockdoes not overrideuse, then your override inImageFrameBlockshould still be valid because it inherits fromBlock. - But if your
BaseEntityBlockis from a different version or is a custom class that does not have this method, the compiler will complain.
-
You are compiling against the wrong Minecraft/NeoForge version.
- Your
BlockorBaseEntityBlockclass in your classpath might be from an older version that does not have this method signature. - For example, in Minecraft 1.20.x, the
usemethod had a different signature (e.g.,protectedor fewer parameters).
- Your
How to fix this:
Step 1: Verify your Minecraft/NeoForge dependencies
Make sure your
build.gradleis targeting Minecraft 1.21 and NeoForge 1.21.Your
build.gradleshould have something like:minecraft { version = "1.21" // other config }If you are targeting 1.20.x or earlier, the method signature is different.
Step 2: Check the
BaseEntityBlockclassIf you are extending
BaseEntityBlock, check if it overridesuse. If it does, what is the signature?- If it overrides
usewith a different signature or does not declare itpublic, your override will fail. - You can fix this by either:
- Overriding the method in
BaseEntityBlockfirst, or - Changing your class to extend
Blockdirectly (if possible).
- Overriding the method in
Step 3: Adjust your override to match the superclass
If your
BaseEntityBlocksuperclass has a differentusemethod signature, you must match that exactly.For example, if
BaseEntityBlockdeclares:protected InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit)then your override must be:
@Override protected InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit)
Summary of what to do:
- Check your Minecraft/NeoForge version and ensure it is 1.21.
- Check the
BaseEntityBlockclass you are extending and see whatusemethod it declares. - Match your override method signature exactly to the one in
BaseEntityBlockorBlock. - If unsure, try extending
Blockdirectly and see if the error persists.
Example fix assuming
BaseEntityBlockhasprotecteduse method:@Override protected InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { // your code here }
If you want to be 100% sure, remove
@Overrideand compile:- Remove
@Overrideannotation temporarily. - Compile.
- If it compiles, then the method is not overriding anything.
- Then check the superclass method signature and adjust accordingly.
Final note:
If you want me to check your
BaseEntityBlockclass or yourbuild.gradleMinecraft version, please share those files or relevant parts.
TL;DR:
Your method signature is correct for Minecraft 1.21
Block.use. The error means your superclass (BaseEntityBlock) does not have that method with that signature. Fix your project dependencies or adjust the method signature to match the superclass exactly. - It is
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.