我尝试保存Chest
,因此我有一个BlockState
和一个Inventory
。 BlockState
没有问题,但在Inventory
中,他总是为0
的金额保存ItemStack
。
if (BlockState instanceof Chest) {
Chest chest = (Chest) bs;
Inventory inv = chest.getBlockInventory();
System.out.println(inv.getItem(0).getAmount());
}
编辑: 现在我有了这个:
BlockState nbs = bs.getBlock().getState();
System.out.println(((Chest) nbs).getBlockInventory().getItem(0).getAmount());
但是现在我得到了这个错误:
[21:16:25 ERROR]: null
org.bukkit.command.CommandException: Unhandled exception executing command 'set' in plugin GlobalSystem vAlpha_0.0.1
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot.jar:git-Spigot-db6de12-07c3001]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot.jar:git-Spigot-db6de12-07c3001]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) ~[spigot.jar:git-Spigot-db6de12-07c3001]
at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1162) [spigot.jar:git-Spigot-db6de12-07c3001]
at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:997) [spigot.jar:git-Spigot-db6de12-07c3001]
at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot.jar:git-Spigot-db6de12-07c3001]
at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot.jar:git-Spigot-db6de12-07c3001]
at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-db6de12-07c3001]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_73]
at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_73]
at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot.jar:git-Spigot-db6de12-07c3001]
at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [spigot.jar:git-Spigot-db6de12-07c3001]
at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot.jar:git-Spigot-db6de12-07c3001]
at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot.jar:git-Spigot-db6de12-07c3001]
at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot.jar:git-Spigot-db6de12-07c3001]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_73]
Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_8_R3.block.CraftBlockState cannot be cast to org.bukkit.block.Chest
at me.Nightfighter001.GlobalSystem.Methoden.Undo.add(Undo.java:56) ~[?:?]
at me.Nightfighter001.GlobalSystem.Commands.setzen.onCommand(setzen.java:53) ~[?:?]
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot.jar:git-Spigot-db6de12-07c3001]
... 15 more
但我没有任何CraftBlockState,我也从未导入它!
如果我更多地解释一下,也许你更容易理解:
我正在开发类似WorldEdit的东西,所以我可以选择Blocks并更改它们。对于自己的/undo
- 和/redo
- 命令,我需要保存旧块。我在HashMap中执行此操作。我正在HashMap中的ArrayList中保存BlockStates。
感谢您的帮助,抱歉我的英语不好;)
答案 0 :(得分:0)
您可以使用自定义YAML
文件并在其中保存值,然后在执行此操作时可以将值放入广告资源
如果您不知道该怎么做,您可以制作HashMap
,然后将项目槽的编号放在一个值侧,将其类型放在另一侧,您可以使用Microsoft Excel存储项目类型和快捷方式名称,然后您可以获取自定义配置文件,然后执行for循环以将值存储在HashMap
如果这对帖子有帮助评论或投票支持帖子,那么我知道我帮助了:D
答案 1 :(得分:0)
我现在通过将金额保存在另一个列表中解决了我的问题...它不是很优雅,但它有效:D
如果其他人有更好的想法,请发布!
非常感谢:)