MrCrayfish's Gun Mod

MrCrayfish's Gun Mod

25M Downloads

Can't reload in 1.18.1

SRR8 opened this issue ยท 40 comments

commented

Installed the mod, could fire and reload. Came back the next day with no mod changes, and now no-one can reload.

commented

You probably installed a mod that overrides the R button.

commented

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.

commented

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.

commented

Let me know if it happens again. Did you restart the server between the off time when the mod was installed?

commented

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.

commented

Can you tell me the steps to reproduce?

commented

Again, with no steps given to reproduce the issue, it's a lot harder to find the issue.

commented

Well if(holder != null && holder.set(entity, key, value)) does not mean holder is null. It's possible for set to return false.

commented

then, what is causing the not reload bug?

commented

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

commented

You said DataHolder holder = this.getDataHolder(entity); is returning null but I don't get that result, even after reloading a world.

commented

idk, i get null if i set a println in that

commented

Well not all entities have a data holder, only ones that have a Synced Key registered to them.

commented

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");
}

commented

and it only give result when i press R to reload

commented

Read the code

commented

can you reload if you run from src?

commented

Yes, I developed the mod.

commented

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);
}
commented

is it normal?

commented

Well if it's cancelled by the event, it's probably another mod cancelling the reloading.

commented

what other mod?

commented

i have only the three required

commented

oh wait, maybe JEI?

commented

Okay, it's probably the event since it's only allowing the gun to reload if the event is cancelled.

commented

ah

commented

Actually it's not the event. I didn't read the code completely.

commented

then what is that?, bc it stops there the content of the if is never executed

commented

ah yes, it stops reloading, my bad

commented

Btw, now i can confirm that my holder is null when i try to reload

commented

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.

commented

Again Holder is not null for me.

commented

idk then

commented

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.

commented

gimme a sec

commented

nope

commented

@MrCrayfish i fixed my issue, turns out that during debug i accidentally deleted @SubscribeEvent from the attachCapability function in the SyncedEntityData...

commented

now it all works, and that fix should fix the previous bug

commented

idk what to do i have the same prob but i have no idea what to do ;w;

commented

Fixed in latest versions of 1.18.2 and above