package net.mattias.cobblesnapshot.block.entity; import…
- User
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
package net.mattias.cobblesnapshot.block.entity;
import net.mattias.cobblesnapshot.block.ModBlockEntities; import net.minecraft.core.BlockPos; 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;
// Store the image data
this.imageData = tag.copy();
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();
level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), 3);
return true;
}
@Override
protected void saveAdditional(CompoundTag tag) {
super.saveAdditional(tag);
if (imageData != null) {
tag.put("ImageData", imageData);
}
tag.putString("TakenBy", takenBy);
tag.putString("TakenOn", takenOn);
tag.putString("PokemonSpecies", pokemonSpecies);
tag.putBoolean("IsShiny", isShiny);
}
@Override
public void load(CompoundTag tag) {
super.load(tag);
if (tag.contains("ImageData")) {
this.imageData = tag.getCompound("ImageData");
}
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() {
CompoundTag tag = super.getUpdateTag();
saveAdditional(tag);
return tag;
}
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;
}
} Cannot resolve method 'get()' Method does not override method from its superclass Expected 2 arguments but found 1 Method does not override method from its superclass Cannot resolve method 'load' in 'BlockEntity' Method does not override method from its superclass Expected 1 argument but found 0
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 { 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 null;
}
@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;
}
}
return InteractionResult.PASS;
}
} Method does not override method from its superclass package net.mattias.cobblesnapshot.block;
import net.mattias.cobblesnapshot.CobbleSnapshot; import net.mattias.cobblesnapshot.block.entity.ImageFrameBlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.neoforged.bus.api.IEventBus; import net.neoforged.neoforge.registries.DeferredRegister;
public class ModBlockEntities { public static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITIES = DeferredRegister.create(BlockEntityType.class, CobbleSnapshot.MOD_ID);
public static final DeferredBlockEntityType<ImageFrameBlockEntity> IMAGE_FRAME =
BLOCK_ENTITIES.register("image_frame",
() -> BlockEntityType.Builder.of(ImageFrameBlockEntity::new, ModBlocks.IMAGE_FRAME.get()).build(null));
public static void register(IEventBus eventBus) {
BLOCK_ENTITIES.register(eventBus);
}
} Cannot resolve method 'create(Class, String)' Cannot resolve symbol 'DeferredBlockEntityType' Incompatible types. Found: 'net.neoforged.neoforge.registries.DeferredHolder<net.minecraft.world.level.block.entity.BlockEntityType<?>,net.minecraft.world.level.block.entity.BlockEntityType<net.mattias.cobblesnapshot.block.entity.ImageFrameBlockEntity>>', required: 'DeferredBlockEntityType'
package net.mattias.cobblesnapshot.block;
import net.mattias.cobblesnapshot.CobbleSnapshot; import net.mattias.cobblesnapshot.block.entity.ImageFrameBlockEntity; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.material.MapColor; import net.neoforged.bus.api.IEventBus; import net.neoforged.neoforge.registries.DeferredBlock; import net.neoforged.neoforge.registries.DeferredRegister;
public class ModBlocks { public static final DeferredRegister.Blocks BLOCKS = DeferredRegister.createBlocks(CobbleSnapshot.MOD_ID);
public static final DeferredBlock<Block> IMAGE_FRAME = BLOCKS.register("image_frame",
() -> new ImageFrameBlock(BlockBehaviour.Properties.of().mapColor(MapColor.STONE).strength(2.0f).noOcclusion()));
public static void register(IEventBus eventBus) {
BLOCKS.register(eventBus);
}
}
You're encountering errors because of API changes in Minecraft and NeoForge, particularly around Block Entities (BlockEntity) serialization and Block (Block) codec registration. Minecraft 1.20.4+ (and thus NeoForge 1.20.4/1.20.6/1.21) introduced new systems for data handling and block registration.
Let's break down each file and fix the issues.
ImageFrameBlockEntity.javaErrors:
Cannot resolve method 'get()' (on ModBlockEntities.IMAGE_FRAME.get())Method does not override method from its superclass (multiple times)Expected 2 arguments but found 1 (on saveAdditional)Cannot resolve method 'load' in 'BlockEntity'Expected 1 argument but found 0 (on load)Reasoning & Fixes:
super(ModBlockEntities.IMAGE_FRAME.get(), pos, state);: When you declare a DeferredHolder (or RegistryObject) for a BlockEntityType, the object itself is the BlockEntityType once registered. You don't call .get() on it in the super() constructor of a BlockEntity.saveAdditional and load methods: These methods in BlockEntity now require an additional HolderLookup.Provider argument in Minecraft 1.20.4+ for proper data serialization, especially for future-proofing with data components.getUpdatePacket() and getUpdateTag(): These are generally fine, but ensure imports are correct. The "Method does not override" error might be a transient IDE issue if the method signatures are otherwise correct.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
// CORRECTED: Added HolderLookup.Provider argument
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;
}
}
ImageFrameBlock.javaErrors:
Method does not override method from its superclass (on codec())Reasoning & Fixes:
codec() method: In Minecraft 1.20.4+, all Block subclasses (including BaseEntityBlock) must provide a MapCodec for serialization. You need to implement this correctly. The simpleCodec helper is typically used.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<ImageFrameBlock> 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;
}
}
ModBlockEntities.javaErrors:
Cannot resolve method 'create(Class<BlockEntityType>, String)'Cannot resolve symbol 'DeferredBlockEntityType'Incompatible types. Found: 'net.neoforged.neoforge.registries.DeferredHolder<net.minecraft.world.level.block.entity.BlockEntityType<?>,net.minecraft.world.level.block.entity.BlockEntityType<net.mattias.cobblesnapshot.block.entity.ImageFrameBlockEntity>>', required: 'DeferredBlockEntityType<ImageFrameBlockEntity>'Reasoning & Fixes:
DeferredRegister.create(BlockEntityType.class, ...): The create method now takes a ResourceKey<Registry<T>> instead of a Class<T>. You should use Registries.BLOCK_ENTITY_TYPE.DeferredBlockEntityType: This class no longer exists. DeferredRegister now returns RegistryObject<T> directly.BlockEntityType.Builder.of(...).build(null): The build method for BlockEntityType.Builder now requires a Set of valid Block instances that this BlockEntityType can be assigned to. This helps with validation and potentially client-side rendering logic.package net.mattias.cobblesnapshot.block;
import net.mattias.cobblesnapshot.CobbleSnapshot;
import net.mattias.cobblesnapshot.block.entity.ImageFrameBlockEntity;
import net.minecraft.core.registries.Registries; // NEW: Import Registries
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.registries.DeferredRegister;
import net.neoforged.neoforge.registries.RegistryObject; // NEW: Import RegistryObject
import java.util.Set; // NEW: Import Set
public class ModBlockEntities {
// CORRECTED: Use Registries.BLOCK_ENTITY_TYPE
public static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITIES =
DeferredRegister.create(Registries.BLOCK_ENTITY_TYPE, CobbleSnapshot.MOD_ID);
// CORRECTED: Use RegistryObject<BlockEntityType<...>>
public static final RegistryObject<BlockEntityType<ImageFrameBlockEntity>> IMAGE_FRAME =
BLOCK_ENTITIES.register("image_frame",
() -> BlockEntityType.Builder.of(ImageFrameBlockEntity::new,
Set.of(ModBlocks.IMAGE_FRAME.get()) // CORRECTED: Pass a Set of valid blocks
).build(null)); // The 'null' here is for a custom type parameter, which isn't commonly used.
public static void register(IEventBus eventBus) {
BLOCK_ENTITIES.register(eventBus);
}
}
ModBlocks.javaThis file looks mostly correct based on the latest NeoForge MDK. No changes needed here.
package net.mattias.cobblesnapshot.block;
import net.mattias.cobblesnapshot.CobbleSnapshot;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.MapColor;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.registries.DeferredRegister; // Correct import for DeferredRegister
public class ModBlocks {
public static final DeferredRegister.Blocks BLOCKS = DeferredRegister.createBlocks(CobbleSnapshot.MOD_ID);
public static final DeferredRegister.Blocks.DeferredBlock<Block> IMAGE_FRAME = BLOCKS.register("image_frame",
() -> new ImageFrameBlock(BlockBehaviour.Properties.of().mapColor(MapColor.STONE).strength(2.0f).noOcclusion()));
public static void register(IEventBus eventBus) {
BLOCKS.register(eventBus);
}
}
After making these changes, perform a Gradle refresh in your IDE (View -> Tool Windows -> Gradle, then click the "Reload All Gradle Projects" button) to ensure the new dependencies and API changes are recognized.