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);
}
}
I'll help you update these classes for NeoForge 1.21. Here are the corrected versions:
ImageFrameBlockEntity.javapackage 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();
if (level != null) {
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 loadAdditional(CompoundTag tag) {
super.loadAdditional(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;
}
}
ImageFrameBlock.javapackage 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<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, 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;
}
}
ModBlockEntities.javapackage 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;
import net.neoforged.neoforge.registries.NeoForgeRegistries;
public class ModBlockEntities {
public static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITIES =
DeferredRegister.create(NeoForgeRegistries.BLOCK_ENTITY_TYPES, CobbleSnapshot.MOD_ID);
public static final DeferredRegister.Holder<BlockEntityType<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);
}
}
ModBlocks.javapackage 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.state.BlockBehaviour;
import net.minecraft.world.level.material.MapColor;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.registries.DeferredRegister;
public class ModBlocks {
public static final DeferredRegister.Blocks BLOCKS = DeferredRegister.createBlocks(CobbleSnapshot.MOD_ID);
public static final DeferredRegister.Holder<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);
}
}
Key changes:
In ImageFrameBlockEntity:
load() to loadAdditional() to match the new NeoForge method signaturelevel in setImageFromFilm()In ImageFrameBlock:
CODEC for the block, which is now requiredcodec() method to return the block's codecIn ModBlockEntities:
NeoForgeRegistries.BLOCK_ENTITY_TYPES for registrationDeferredRegister.Holder<> instead of a custom typeIn ModBlocks:
DeferredRegister.Holder<Block> for consistent registrationThese changes should resolve the compilation errors and make your code compatible with NeoForge 1.21.