gpt4 book ai didi

java - onBlockActivated block GUI

转载 作者:行者123 更新时间:2023-12-01 18:09:31 26 4
gpt4 key购买 nike

我正在尝试遵循有关如何在 1.15.2 中使用 GUI 对 block 进行编程的教程,但是在创建 onBlockActivated 时,它希望我删除 @Override 注释,但这样做会使其无法工作。

public class BasicGenerator extends Block {

public BasicGenerator() {
super(Properties.create(Material.IRON).sound(SoundType.METAL).hardnessAndResistance(2.0f).lightValue(14));
setRegistryName("basicgen");
}

@Override
public boolean hasTileEntity(BlockState state) {
return true;
}

@Nullable
@Override
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
return new BasicGenTile();
}

@Override
public void onBlockPlacedBy(World world, BlockPos pos, BlockState state, @Nullable LivingEntity entity, ItemStack stack) {
if (entity != null) {
world.setBlockState(pos, state.with(BlockStateProperties.FACING, getFacingFromEntity(pos, entity)), 2);
}
}


@Override
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult trace) {
if (!world.isRemote) {
TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity instanceof INamedContainerProvider) {
NetworkHooks.openGui((ServerPlayerEntity) player, (INamedContainerProvider) tileEntity, tileEntity.getPos());
} else {
throw new IllegalStateException("Our named container provider is missing!");
}
return ActionResultType.SUCCESS;
}
return super.onBlockActivated(state, world, pos, player, hand, trace);
}

public static Direction getFacingFromEntity(BlockPos clickedBlock, LivingEntity entity) {
Vec3d vec = entity.getPositionVec();
return Direction.getFacingFromVector((float) (vec.x - clickedBlock.getX()), (float) (vec.y - clickedBlock.getY()), (float) (vec.z - clickedBlock.getZ()));
}

@Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
builder.add(BlockStateProperties.FACING);
}
}

最佳答案

您可能需要更新映射(在 build.gradle 文件中)。看http://export.mcpbot.bspk.rs获取最新的映射,并替换 build.gradle 中的行。

关于java - onBlockActivated block GUI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60492578/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com