Jump to content
Search In
  • More options...
Find results that contain...
Find results in...


  • Posts

  • Joined

  • Last visited

Everything posted by transfarmer

  1. You can make an invisible entity that deals damage if it hits an enemy within a certain range.
  2. I am trying to update a capability on player death. I use PlayerEvent.Clone and check if isWasDeath() to send a packet to the client to update that capability. My Clone event handler first copies the original PlayerEntity's capability values to the PlayerEntity in the logical server and then sends a packet to the client, which uses Minecraft#player. The server-side capability is updated without issues, but it is not even present in the client. Both sides use LazyOptional<X>#ifPresent. links: Clone event handler, client packet Why does this occur? edit: reconnecting to a server results in the capabilty being properly synchronized
  3. I have a PlayerEntity capability and a packet class for updating that capability in clients that is sent by the server on player login. I also have a method that listens to PlayerTickEvent and removes items from PlayerEntitys' inventories if a field that they have (SoulWeapons.WeaponType weaponType) is null. When I enter a world, set the field to a non-null value, and reconnect, my capability fields are reset and the items are removed on the client side (they are still in the inventory and I can drop them, but their slots are blank), but the server has the correct information. Is the issue with my PlayerEvents? Also, are PlayerLoggedInEvent, PlayerChangedDimensionEvent and Clone server-side, client-side, or common? edit: Never mind this post. I forgot to assign the field values in the encode method of my packet class.
  4. Thank you for your assistance; your code was very helpful. I also looked at the post that you linked. My issue is now solved.
  5. I pushed my changes to the GitHub repository that I mentioned earlier. I will check these resources when I return home.
  6. Thank you. So I did. Currently, I handle packets sent to a client and packets sent to the server inside the same function, separated by a check on FMLEnvironment.dist. Is this correct? My client receives information back from the server and does what the server did (it modified a capability), based on its response, and my client appears synchronized with the server. However, when the former connects to the latter, the capability seems to have returned to its default state on the client side. Do I have to use something like a UserJoinedEvent to correct this? edit: I used PlayerLoggedInEvent to send a packet to my client and it seems to work. If what I did is acceptable would not cause problems, then this issue is solved. Otherwise, please enlighten me.
  7. I have a capability whose serializeNBT, writeNBT, deserializeNBT, and readNBT methods are called, and its information is preserved after disconnecting a server; however, the client's information is not updated. It sends a packet to the server after clicking a button in a custom GUI and the server modifies the capability attached to the sender of the packet. Should the server send a packet back? If so, then how? I tried using the shorter method described in the Forge documentation, but instead of a PlayerEntity I need a Supplier<PlayerEntity> and I doubt that I have to make a new class for it, so what should I do? My packet class is available on GitHub.
  8. Yes. Then could you explain to me what it does? I'm still not sure about why I need it. Is it a basic instance made for every object to which the capability is attached for NBT storage? Also, I think that my data are not saved after leaving and joining a world. Do I have to do it manually?
  9. I apologize. The issue with writeNBT was that I was trying to use Object.toString() on a value that was null.The provider class is shown below. I agree. Does it have to be initialized? If so, then what should it be?
  10. Loading a world produces a NullPointerExceptionagain. The ICapability instance passed to writeNBT seems to be null:
  11. I already have it: @EventBusSubscriber(modid = Main.MODID, bus = EventBusSubscriber.Bus.MOD) public class ModEventSubscriber { . . . @SubscribeEvent public static void onAttachCapabilities(AttachCapabilitiesEvent<Entity> event) { if (event.getObject() instanceof PlayerEntity) { event.addCapability(new ResourceLocation(Main.MODID, "type"), new Provider()); } } . . . } Is something wrong with this code?
  12. Is the capability non-null when it is registered and attached? Otherwise, how can I make it non-null? My PlayerEntity seems to not have it.
  13. The Forge documentation states the following: However, the return type of getCapability is LazyOptional<T>, and I want to use the methods defined in my interface. How should I use getCapability?
  14. I read again the Forge documentation about capabilities. According to the it, the capability is null because it was not registered. Then I made it non-final and tried to properly register it during common setup. The NullPointerException does not occur anymore. However, my keybinding does not load anymore (I set its registration to occur during client setup by FMLClientSetupEvent as I was cleaning up my mod setup). Previously, it loaded but did not function. (It functioned as expected before I implemented the capability.) Should I open a new thread for that? Also, the 1.15.x documentation mentions a provider hasCapability method. Is that a requirement in previous versions of Forge? It is not defined in ICapabilityProvider.java in v30.0.36.
  15. Hello. I made a custom capability that should be attached to EntityPlayer. My provider class initializes an instance of Capabilty and sets its value to null and makes a LazyOptional instance of this capability: public static final Capability<ISoulWeapon> TYPE = null; private LazyOptional<ISoulWeapon> instance = LazyOptional.of(TYPE::getDefaultInstance); I assume that this is correct because this is the only way in which I saw this done. However, the instance seems to be null. The game runs until a world is loaded, when it crashes, producing the following stacktrace: java.lang.NullPointerException: Saving entity NBT at transfarmer.adventureitems.capabilities.Storage.writeNBT(Storage.java:14) ~[?:?] {re:classloading} at transfarmer.adventureitems.capabilities.Storage.writeNBT(Storage.java:10) ~[?:?] {re:classloading} at transfarmer.adventureitems.capabilities.Provider.serializeNBT(Provider.java:23) ~[?:?] {re:classloading,pl:capability_inject_definalize:A} at net.minecraftforge.common.capabilities.CapabilityDispatcher.serializeNBT(CapabilityDispatcher.java:127) ~[?:?] {re:classloading} at net.minecraftforge.common.capabilities.CapabilityProvider.serializeCaps(CapabilityProvider.java:86) ~[?:?] {re:classloading} at net.minecraft.entity.Entity.writeWithoutTypeId(Entity.java:1527) ~[?:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.server.integrated.IntegratedPlayerList.writePlayerData(IntegratedPlayerList.java:27) ~[?:?] {re:classloading,pl:runtimedistcleaner:A} at net.minecraft.server.management.PlayerList.saveAllPlayerData(PlayerList.java:631) ~[?:?] {re:classloading} at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:112) ~[?:?] {re:classloading,pl:runtimedistcleaner:A} at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:658) ~[?:?] {re:classloading,pl:accesstransformer:B} at java.lang.Thread.run(Thread.java:748) ~[?:1.8.0_232] {} What did I do wrong? My capability is available here.
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.