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
I understand the frustration. Let's fix this properly. The issue is that in NeoForge 1.21, the
usemethod signature has changed in theBaseEntityBlockclass. The correct signature no longer includes theInteractionHandparameter. Here's the corrected version: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.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 public 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) { // Get the hand from the player's main hand (since we can't get it from hit result anymore) ItemStack heldItem = player.getMainHandItem(); 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; } }Key changes made:
- Removed the
InteractionHandparameter from theusemethod signature - Changed
player.getItemInHand(hand)toplayer.getMainHandItem()since we can't get the hand from the hit result anymore - Kept the method as
publicsince that's what the base class expects
This should now properly override the method from
BaseEntityBlockin NeoForge 1.21. The functionality remains the same, but it's now compatible with the current API.If you need to handle both hands (main and offhand), you could modify the code to check both hands:
ItemStack mainHandItem = player.getMainHandItem(); ItemStack offHandItem = player.getOffhandItem(); if (mainHandItem.is(ModItems.IMAGE_FILM.get())) { // Handle main hand } else if (offHandItem.is(ModItems.IMAGE_FILM.get())) { // Handle offhand }- Removed the
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.