Everything posted by Squander
-
[1.18.2] Error when attaching capabilities
Should I assign a new instance to the IItemHandler field
-
[1.18.2] Error when attaching capabilities
Everything works, repository on github updated.
-
[1.18.2] Error when attaching capabilities
Ok
-
[1.18.2] Error when attaching capabilities
Does my IItemHandler extension interface need to be registered with RegisterCapabilityEvent?
-
[1.18.2] Error when attaching capabilities
Oh, thank you so much!
-
[1.18.2] Error when attaching capabilities
This is not a backpack, I open it with an event (only for the test) in the ClickBlock class
-
[1.18.2] Error when attaching capabilities
- [1.18.2] Error when attaching capabilities
When I turn on the menu, the items that I have in the hotbar appear in 9 slots form my capability, and I want more space- [1.18.2] Error when attaching capabilities
https://github.com/Squander12/Backpack-1.18.2 I think it should work.- [1.18.2] Error when attaching capabilities
My config in my mod project [core] repositoryformatversion = 0 filemode = false bare = false logallrefupdates = true symlinks = false ignorecase = true [remote "origin"] url = [email protected]:/Squander12/Backpack1.18.2.git fetch = +refs/heads/*:refs/remotes/origin/* [remote "github"] url = [email protected]:/Squander12/Backpack_1.18.2.git fetch = +refs/heads/*:refs/remotes/github/* [lfs] repositoryformatversion = 0 [remote "githubh"] url = [email protected]:/Squander12/Backpack_1.18.2.git fetch = +refs/heads/*:refs/remotes/githubh/* [remote "githubasd"] url = [email protected]:/Squander12/Backpack1.18.2123.git fetch = +refs/heads/*:refs/remotes/githubasd/* [remote "originn"] url = [email protected]:/Squander12/Backpack-1.18.2.git fetch = +refs/heads/*:refs/remotes/originn/* [remote "githubheunyrty"] url = [email protected]:/Squander12/aaaa.git fetch = +refs/heads/*:refs/remotes/githubheunyrty/* [commit] gpgsign = false- [1.18.2] Error when attaching capabilities
okay i run github desktop then file tab then add local repository i gave the path of my mod, all files are like loaded but i don't really know what to do now.- [1.18.2] Error when attaching capabilities
Github Desktop- [1.18.2] Error when attaching capabilities
error: cannot spawn gpg: No such file or directory error: gpg failed to sign the data fatal: failed to write commit object- [1.18.2] Error when attaching capabilities
Okay, I don't have the strength to bother with this anymore. Nothing works. Screw it.- [1.18.2] Error when attaching capabilities
https://github.com/Squander12/Backpack_1.18.2- [1.18.2] Error when attaching capabilities
I think it's the first- [1.18.2] Error when attaching capabilities
Can't finish GitHub sharing process Successfully created project 'Backpack1.18.2' on GitHub, but initial commit failed: gpg: skipped "Squander12 <[email protected]>": No secret key gpg: signing failed: No secret key gpg failed to sign the data failed to write commit object I get this error all the time.- [1.18.2] Error when attaching capabilities
public ExtraStorageMenu(int pContainerId, Inventory inventory, FriendlyByteBuf buffer) { this(pContainerId, inventory, new ItemStackHandler(buffer.readVarInt())); } public ExtraStorageMenu(int pContainerId, Inventory inventory, IItemHandler handler) { super(MenuTypeInit.EXTRA_STORAGE.get(), pContainerId); for(int i = 0; i < 9; ++i) { this.addSlot(new SlotItemHandler(handler, i, 1 + i * 18, 1)); } this.addPlayerInventory(inventory); this.addPlayerHotbar(inventory); } private void addPlayerInventory(Inventory inventory){ for(int i = 0; i < 3; ++i) { for(int j = 0; j < 9; ++j) { this.addSlot(new Slot(inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); } } } private void addPlayerHotbar(Inventory inventory){ for(int k = 0; k < 9; ++k) { this.addSlot(new Slot(inventory, k, 8 + k * 18, 142)); } }- [1.18.2] Error when attaching capabilities
I did a new capability but still have items from the hotbar. public static final Capability<IItemHandler> EXTRA_STORAGE = CapabilityManager.get(new CapabilityToken<>(){}); private final LazyOptional<IItemHandler> optional = LazyOptional.of(() -> this); public ExtraStorageInventory(int size){ this.setSize(size); } @NotNull @Override public <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) { return cap == EXTRA_STORAGE ? optional.cast() : LazyOptional.empty(); } player.getCapability(ExtraStorageInventory.EXTRA_STORAGE).ifPresent(handler -> { NetworkHooks.openGui((ServerPlayer) player, new SimpleMenuProvider((id, inv, plr) -> new ExtraStorageMenu(id, inv, handler), new TextComponent("EXTRA STORAGE")), buffer -> buffer.writeVarInt(9)); });- [1.18.2] Error when attaching capabilities
public class ExtraStorageInventory extends ItemStackHandler implements ICapabilityProvider { private final LazyOptional<IItemHandler> optional = LazyOptional.of(() -> this); public ExtraStorageInventory(int size){ this.setSize(size); } @NotNull @Override public <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) { return cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY ? optional.cast() : LazyOptional.empty(); } }- [1.18.2] Error when attaching capabilities
Okay, after opening the menu, the items in the slots are the same as in the hotbar.- [1.18.2] Error when attaching capabilities
Attempts to attach capabilities to the player but receives this error. [10:27:23] [Server thread/ERROR] [ne.mi.ev.EventBus/EVENTBUS]: Exception caught during firing event: Cannot invoke "net.minecraftforge.common.util.LazyOptional.cast()" because "this.playerJoinedHandler" is null Index: 1 Listeners: 0: NORMAL 1: ASM: class me.squander.backpack.event.AttachCapabilities onAttachCapabilities(Lnet/minecraftforge/event/AttachCapabilitiesEvent;)V java.lang.NullPointerException: Cannot invoke "net.minecraftforge.common.util.LazyOptional.cast()" because "this.playerJoinedHandler" is null at TRANSFORMER/[email protected]/net.minecraft.world.entity.player.Player.getCapability(Player.java:2228) at TRANSFORMER/[email protected]/net.minecraftforge.common.capabilities.ICapabilityProvider.getCapability(ICapabilityProvider.java:34) at TRANSFORMER/[email protected]/me.squander.backpack.event.AttachCapabilities.onAttachCapabilities(AttachCapabilities.java:19) at net.minecraftforge.eventbus.ASMEventHandler_1_AttachCapabilities_onAttachCapabilities_AttachCapabilitiesEvent.invoke(.dynamic) at MC-BOOTSTRAP/[email protected]/net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:85) at MC-BOOTSTRAP/[email protected]/net.minecraftforge.eventbus.EventBus.post(EventBus.java:302) at MC-BOOTSTRAP/[email protected]/net.minecraftforge.eventbus.EventBus.post(EventBus.java:283) at TRANSFORMER/[email protected]/net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(ForgeEventFactory.java:593) at TRANSFORMER/[email protected]/net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(ForgeEventFactory.java:587) at TRANSFORMER/[email protected]/net.minecraftforge.common.capabilities.CapabilityProvider.doGatherCapabilities(CapabilityProvider.java:73) at TRANSFORMER/[email protected]/net.minecraftforge.common.capabilities.CapabilityProvider.gatherCapabilities(CapabilityProvider.java:68) at TRANSFORMER/[email protected]/net.minecraftforge.common.capabilities.CapabilityProvider.gatherCapabilities(CapabilityProvider.java:52) at TRANSFORMER/[email protected]/net.minecraft.world.entity.Entity.<init>(Entity.java:257) at TRANSFORMER/[email protected]/net.minecraft.world.entity.LivingEntity.<init>(LivingEntity.java:234) at TRANSFORMER/[email protected]/net.minecraft.world.entity.player.Player.<init>(Player.java:172) at TRANSFORMER/[email protected]/net.minecraft.server.level.ServerPlayer.<init>(ServerPlayer.java:238) at TRANSFORMER/[email protected]/net.minecraft.server.players.PlayerList.getPlayerForLogin(PlayerList.java:412) at TRANSFORMER/[email protected]/net.minecraft.server.network.ServerLoginPacketListenerImpl.handleAcceptedLogin(ServerLoginPacketListenerImpl.java:124) at TRANSFORMER/[email protected]/net.minecraft.server.network.ServerLoginPacketListenerImpl.tick(ServerLoginPacketListenerImpl.java:70) at TRANSFORMER/[email protected]/net.minecraft.network.Connection.tick(Connection.java:267) at TRANSFORMER/[email protected]/net.minecraft.server.network.ServerConnectionListener.tick(ServerConnectionListener.java:160) at TRANSFORMER/[email protected]/net.minecraft.server.MinecraftServer.tickChildren(MinecraftServer.java:947) at TRANSFORMER/[email protected]/net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:873) at TRANSFORMER/[email protected]/net.minecraft.client.server.IntegratedServer.tickServer(IntegratedServer.java:90) at TRANSFORMER/[email protected]/net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:704) at TRANSFORMER/[email protected]/net.minecraft.server.MinecraftServer.lambda$spin$2(MinecraftServer.java:262) at java.base/java.lang.Thread.run(Thread.java:833) [10:27:23] [Server thread/ERROR] [minecraft/ServerLoginPacketListenerImpl]: Couldn't place player in world java.lang.NullPointerException: Cannot invoke "net.minecraftforge.common.util.LazyOptional.cast()" because "this.playerJoinedHandler" is null at net.minecraft.world.entity.player.Player.getCapability(Player.java:2228) ~[forge-1.18.2-40.1.68_mapped_parchment_2022.07.17-1.18.2-recomp.jar%2379!/:?] {re:classloading,pl:accesstransformer:B} at net.minecraftforge.common.capabilities.ICapabilityProvider.getCapability(ICapabilityProvider.java:34) ~[forge-1.18.2-40.1.68_mapped_parchment_2022.07.17-1.18.2-recomp.jar%2378%2385!/:?] {re:classloading} at me.squander.backpack.event.AttachCapabilities.onAttachCapabilities(AttachCapabilities.java:19) ~[%2384!/:?] {re:classloading} at net.minecraftforge.eventbus.ASMEventHandler_1_AttachCapabilities_onAttachCapabilities_AttachCapabilitiesEvent.invoke(.dynamic) ~[?:?] {} at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:85) ~[eventbus-5.0.7.jar%2310!/:?] {} at net.minecraftforge.eventbus.EventBus.post(EventBus.java:302) ~[eventbus-5.0.7.jar%2310!/:?] {} at net.minecraftforge.eventbus.EventBus.post(EventBus.java:283) ~[eventbus-5.0.7.jar%2310!/:?] {} at net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(ForgeEventFactory.java:593) ~[forge-1.18.2-40.1.68_mapped_parchment_2022.07.17-1.18.2-recomp.jar%2378%2385!/:?] {re:classloading} at net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(ForgeEventFactory.java:587) ~[forge-1.18.2-40.1.68_mapped_parchment_2022.07.17-1.18.2-recomp.jar%2378%2385!/:?] {re:classloading} at net.minecraftforge.common.capabilities.CapabilityProvider.doGatherCapabilities(CapabilityProvider.java:73) ~[forge-1.18.2-40.1.68_mapped_parchment_2022.07.17-1.18.2-recomp.jar%2378%2385!/:?] {re:classloading} at net.minecraftforge.common.capabilities.CapabilityProvider.gatherCapabilities(CapabilityProvider.java:68) ~[forge-1.18.2-40.1.68_mapped_parchment_2022.07.17-1.18.2-recomp.jar%2378%2385!/:?] {re:classloading} at net.minecraftforge.common.capabilities.CapabilityProvider.gatherCapabilities(CapabilityProvider.java:52) ~[forge-1.18.2-40.1.68_mapped_parchment_2022.07.17-1.18.2-recomp.jar%2378%2385!/:?] {re:classloading} at net.minecraft.world.entity.Entity.<init>(Entity.java:257) ~[forge-1.18.2-40.1.68_mapped_parchment_2022.07.17-1.18.2-recomp.jar%2379!/:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.world.entity.LivingEntity.<init>(LivingEntity.java:234) ~[forge-1.18.2-40.1.68_mapped_parchment_2022.07.17-1.18.2-recomp.jar%2379!/:?] {re:classloading} at net.minecraft.world.entity.player.Player.<init>(Player.java:172) ~[forge-1.18.2-40.1.68_mapped_parchment_2022.07.17-1.18.2-recomp.jar%2379!/:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.server.level.ServerPlayer.<init>(ServerPlayer.java:238) ~[forge-1.18.2-40.1.68_mapped_parchment_2022.07.17-1.18.2-recomp.jar%2379!/:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.server.players.PlayerList.getPlayerForLogin(PlayerList.java:412) ~[forge-1.18.2-40.1.68_mapped_parchment_2022.07.17-1.18.2-recomp.jar%2379!/:?] {re:classloading} at net.minecraft.server.network.ServerLoginPacketListenerImpl.handleAcceptedLogin(ServerLoginPacketListenerImpl.java:124) ~[forge-1.18.2-40.1.68_mapped_parchment_2022.07.17-1.18.2-recomp.jar%2379!/:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.server.network.ServerLoginPacketListenerImpl.tick(ServerLoginPacketListenerImpl.java:70) ~[forge-1.18.2-40.1.68_mapped_parchment_2022.07.17-1.18.2-recomp.jar%2379!/:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.network.Connection.tick(Connection.java:267) ~[forge-1.18.2-40.1.68_mapped_parchment_2022.07.17-1.18.2-recomp.jar%2379!/:?] {re:classloading} at net.minecraft.server.network.ServerConnectionListener.tick(ServerConnectionListener.java:160) ~[forge-1.18.2-40.1.68_mapped_parchment_2022.07.17-1.18.2-recomp.jar%2379!/:?] {re:classloading} at net.minecraft.server.MinecraftServer.tickChildren(MinecraftServer.java:947) ~[forge-1.18.2-40.1.68_mapped_parchment_2022.07.17-1.18.2-recomp.jar%2379!/:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:873) ~[forge-1.18.2-40.1.68_mapped_parchment_2022.07.17-1.18.2-recomp.jar%2379!/:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.client.server.IntegratedServer.tickServer(IntegratedServer.java:90) ~[forge-1.18.2-40.1.68_mapped_parchment_2022.07.17-1.18.2-recomp.jar%2379!/:?] {re:classloading,pl:runtimedistcleaner:A} at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:704) ~[forge-1.18.2-40.1.68_mapped_parchment_2022.07.17-1.18.2-recomp.jar%2379!/:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.server.MinecraftServer.lambda$spin$2(MinecraftServer.java:262) ~[forge-1.18.2-40.1.68_mapped_parchment_2022.07.17-1.18.2-recomp.jar%2379!/:?] {re:classloading,pl:accesstransformer:B} at java.lang.Thread.run(Thread.java:833) [?:?] {} [10:27:23] [Server thread/INFO] [minecraft/ServerLoginPacketListenerImpl]: com.mojang.authlib.GameProfile@5e18a6a7[id=380df991-f603-344c-a090-369bad2a924a,name=Dev,properties={},legacy=false] (local:E:d56832b6) lost connection: Invalid player data [10:27:23] [Server thread/WARN] [minecraft/Connection]: handleDisconnection() called twice @SubscribeEvent public static void onAttachCapabilities(AttachCapabilitiesEvent<Entity> event){ if(event.getObject() instanceof Player){ if(!event.getObject().getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).isPresent()){ event.addCapability(new ResourceLocation(BackpackMod.MODID, "extra_storage"), new ExtraStorageInventory(9)); } } }- [1.18.2] Capability
Okay I changed my code and looked at Jorrit Tyberghein's tutorial though I'm still not sure if that's the right way. public class MoneyPacketSyncS2C { private final int playerMoney; public MoneyPacketSyncS2C(int playerMoney) { this.playerMoney = playerMoney; } public MoneyPacketSyncS2C(FriendlyByteBuf buf) { this.playerMoney = buf.readVarInt(); } public void encode(FriendlyByteBuf buf){ buf.writeVarInt(this.playerMoney); } public boolean handle(Supplier<NetworkEvent.Context> supplier){ NetworkEvent.Context ctx = supplier.get(); ctx.enqueueWork(() -> { ClientMoneyData.setMoney(this.playerMoney); }); return true; } public static void register(int id){ PacketHandler.INSTANCE.messageBuilder(MoneyPacketSyncS2C.class, id, NetworkDirection.PLAY_TO_CLIENT) .encoder(MoneyPacketSyncS2C::encode) .decoder(MoneyPacketSyncS2C::new) .consumer(MoneyPacketSyncS2C::handle).add(); } } public class ClientMoneyData { private static int playerMoney; public static void setMoney(int money){ ClientMoneyData.playerMoney = money; } public static int getMonet(){ return playerMoney; } }- [1.18.2] Capability
My helper class and packet class I don't really know what to do now. public class MoneyHelper { public static void add(Player player, int amount){ player.getCapability(CapabilityMoney.MONEY).ifPresent(money -> { money.setMoney(money.getMoney() + amount); sendSyncPacket(player); }); } public static void remove(Player player, int amount){ player.getCapability(CapabilityMoney.MONEY).ifPresent(money -> { money.setMoney(money.getMoney() - amount); sendSyncPacket(player); }); } public static void messageMoney(Player player){ player.getCapability(CapabilityMoney.MONEY).ifPresent(x -> { player.sendMessage(new TextComponent("Money: " + x.getMoney()).withStyle(ChatFormatting.GREEN), player.getUUID()); }); } private static void sendSyncPacket(Player player){ PacketHandler.sendToClient(new MoneyPacketSyncS2C(), (ServerPlayer) player); } } public class MoneyPacketSyncS2C { public MoneyPacketSyncS2C() {} public MoneyPacketSyncS2C(FriendlyByteBuf buf) {} public void encode(FriendlyByteBuf buf){} public boolean handle(Supplier<NetworkEvent.Context> supplier){ NetworkEvent.Context ctx = supplier.get(); ctx.enqueueWork(() -> { }); return true; } public static void register(int id){ PacketHandler.INSTANCE.messageBuilder(MoneyPacketSyncS2C.class, id, NetworkDirection.PLAY_TO_CLIENT) .encoder(MoneyPacketSyncS2C::encode) .decoder(MoneyPacketSyncS2C::new) .consumer(MoneyPacketSyncS2C::handle).add(); } }- [1.18.2] Capability
I attach my capability to player. - [1.18.2] Error when attaching capabilities
IPS spam blocked by CleanTalk.
Important Information
By using this site, you agree to our Terms of Use.