已解决 1.21.4 将 String blockid 与Block匹配
-
rt, 想要实现以下功能:
- 获取玩家当前的钓鱼浮漂位置
- 比较浮漂位置的方块与给定的String blockID
我现在是这样写的。。。有没有更简洁的方法(((
client.world.getBlockState(client.player.fishHook.getBlockPos()).getBlock().toString().contains("minecraft:water");
-
补充:如果这里的blockid是动态的,可以这样
Identifier targetId = new Identifier("minecraft:water"); boolean isWater = client.world.getBlockState(bobberPos).isOf(Registry.BLOCK.get(targetId));
别忘了null检测
if (client.player != null && client.player.fishHook != null && client.world != null) { // 检查逻辑 }
-
@Wudji java 1.21.4 fabric
-
@Wudji 为什么不用blocktype比较呢,为什么不用注册表呢,为什么不用tag呢
-
BlockPos bobberPos = client.player.fishHook.getBlockPos(); boolean isWater = client.world.getBlockState(bobberPos).getBlock() == Blocks.WATER;
-
补充:如果这里的blockid是动态的,可以这样
Identifier targetId = new Identifier("minecraft:water"); boolean isWater = client.world.getBlockState(bobberPos).isOf(Registry.BLOCK.get(targetId));
别忘了null检测
if (client.player != null && client.player.fishHook != null && client.world != null) { // 检查逻辑 }
-
W Wudji 将这个主题标记为已解决