Can't reload in 1.18.1
SRR8 opened this issue ยท 40 comments
Installed the mod, could fire and reload. Came back the next day with no mod changes, and now no-one can reload.
I thought so too, so I set the keybind to other keybinds with no conflicts and still no luck.
Even so it worked when first installed but when we loaded up the server the next day it won't reload at all.
I've fixed it. I removed it from the server, restarted the server without the mod, then restarted the server with the mod back on. No idea why this worked but it did.
Let me know if it happens again. Did you restart the server between the off time when the mod was installed?
I'm having this problem too, i even tried recompiling mod from src too with no luck.
@MrCrayfish i may have found out after some debugging what is the problem
The code: if(ModSyncedDataKeys.RELOADING.getValue(player)) of class ReloadTracker can't get the value of the RELOADING Key
Edit:
found out more, this time is not in the Gun Mod but in the mod used to get and set the values of RELOADING (FrameWork), in the SyncedEntityData, in the methods get and set, the DataHolder holder = this.getDataHolder(entity); is always null.
Again, with no steps given to reproduce the issue, it's a lot harder to find the issue.
Well if(holder != null && holder.set(entity, key, value))
does not mean holder is null. It's possible for set
to return false.
I just loaded up a test world and tried reloading
Btw, unloading works
For the denug, just put some System.out.println in the class
You said DataHolder holder = this.getDataHolder(entity);
is returning null but I don't get that result, even after reloading a world.
Well not all entities have a data holder, only ones that have a Synced Key registered to them.
I modified like this:
public <E extends Entity, T> void set(E entity, SyncedDataKey key, T value)
{
if(!this.registeredDataKeys.contains(key))
{
throw new IllegalArgumentException(String.format("The synced data key %s for %s is not registered!", key.id(), key.classKey().id()));
}
DataHolder holder = this.getDataHolder(entity);
System.out.println(CAPABILITY);
if(holder != null && holder.set(entity, key, value))
{
if(!entity.level.isClientSide())
{
System.out.println("Set Data:" + key + " On: " + entity);
this.dirty = true;
this.dirtyEntities.add(entity);
}
else
System.out.println("Entity is ClientSide");
}
else
System.out.println("holder is null");
}
ok, i tried some more debug, and it arrives here:
@OverRide
public void handle(MessageReload message, Supplier<NetworkEvent.Context> supplier)
{
supplier.get().enqueueWork(() ->
{
ServerPlayer player = supplier.get().getSender();
if(player != null && !player.isSpectator())
{
ModSyncedDataKeys.RELOADING.setValue(player, message.reload); // This has to be set in order to verify the packet is sent if the event is cancelled
System.out.println("Player Name: " + player + " Reload Bool: " + message.reload);
if(!message.reload)
return;
ItemStack gun = player.getMainHandItem();
System.out.println("Gun: " + gun.getDisplayName());
if(MinecraftForge.EVENT_BUS.post(new GunReloadEvent.Pre(player, gun))) <-------- HERE
{
System.out.println("GunReload Pre");
ModSyncedDataKeys.RELOADING.setValue(player, false);
return;
}
MinecraftForge.EVENT_BUS.post(new GunReloadEvent.Post(player, gun));
}
});
supplier.get().setPacketHandled(true);
}
Well if it's cancelled by the event, it's probably another mod cancelling the reloading.
Okay, it's probably the event since it's only allowing the gun to reload if the event is cancelled.
then what is that?, bc it stops there the content of the if is never executed
I added this code:
if (holder != null)
System.out.println("Key: " + key + " Value: " + holder.set(entity, key, value) + " For: " + entity + " Value2: " + value);
else
System.out.println("Key: " + key + " Value: " + "Holder Null" + " For: " + entity + " Value2: " + value);
and it gave me "Holder Null" with the key cgm:reloading.
It's possible that I misconfigured the entity capability. Since you're able to replicate the issue.
In Framework, go to SyncedEntityData
then Provider
and replace getCapability
with this below code.
@Nonnull
@Override
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side)
{
return cap == CAPABILITY ? this.optional.cast() : LazyOptional.empty();
}
then test it with the Gun Mod.
@MrCrayfish i fixed my issue, turns out that during debug i accidentally deleted @SubscribeEvent from the attachCapability function in the SyncedEntityData...