Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix unlimited ammo bug #458

Merged
merged 3 commits into from
Sep 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public boolean startReloadWithoutTrigger(EntityWrapper entityWrapper, String wea

int ammoLeft = getAmmoLeft(weaponStack, weaponTitle);
if (ammoLeft == -1) { // This shouldn't be -1 at this point since reload should be used, perhaps ammo was added for weapon
// in configs later in server...
// in configs later in server...
CustomTag.AMMO_LEFT.setInteger(weaponStack, 0);
ammoLeft = 0;
}
Expand All @@ -144,7 +144,6 @@ public boolean startReloadWithoutTrigger(EntityWrapper entityWrapper, String wea
if (ammoLeft + tempAmmoToAdd > tempMagazineSize) {
tempAmmoToAdd = tempMagazineSize - ammoLeft;
}

} else {
tempAmmoToAdd = tempMagazineSize - ammoLeft;
}
Expand All @@ -169,7 +168,6 @@ public boolean startReloadWithoutTrigger(EntityWrapper entityWrapper, String wea
// AND
// Is revolver or ammo is 0
if (!isReloadLoop && (isRevolver || ammoLeft <= 0)) {

firearmOpenTime = firearmAction.getOpenTime();
firearmCloseTime = firearmAction.getCloseTime();

Expand Down Expand Up @@ -215,14 +213,12 @@ public boolean startReloadWithoutTrigger(EntityWrapper entityWrapper, String wea

AmmoConfig ammo = playerWrapper != null ? config.getObject(weaponTitle + ".Reload.Ammo", AmmoConfig.class) : null;
if (ammo != null && !ammo.hasAmmo(weaponTitle, weaponStack, playerWrapper)) {

// Creative mode bypass... #176
if (playerWrapper.getPlayer().getGameMode() != GameMode.CREATIVE || !getBasicConfigurations().getBool("Creative_Mode_Bypass_Ammo")) {
if (ammo.getOutOfAmmoMechanics() != null)
ammo.getOutOfAmmoMechanics().use(new CastData(shooter, weaponTitle, weaponStack));
return false;
}

}

Mechanics reloadStartMechanics = config.getObject(weaponTitle + ".Reload.Start_Mechanics", Mechanics.class);
Expand Down Expand Up @@ -250,6 +246,14 @@ public boolean startReloadWithoutTrigger(EntityWrapper entityWrapper, String wea

@Override
public void task() {
// Check if the slot is still the same
ItemStack currentItem = mainhand ? entityWrapper.getEntity().getEquipment().getItemInMainHand() : entityWrapper.getEntity().getEquipment().getItemInOffHand();
if (!currentItem.isSimilar(weaponStack)) {
// if weapon changes, it stops the task
handData.stopReloadingTasks();
return;
}

ItemStack taskReference = mainhand ? entityWrapper.getEntity().getEquipment().getItemInMainHand() : entityWrapper.getEntity().getEquipment().getItemInOffHand();
if (!taskReference.hasItemMeta()) {
handData.stopReloadingTasks();
Expand All @@ -263,7 +267,6 @@ public void task() {
int ammoToAdd = finalAmmoToAdd + unloadedAmount;

if (ammo != null) {

int removedAmount = ammo.removeAmmo(taskReference, playerWrapper, ammoToAdd, magazineSize);

// Just check if for some reason ammo disappeared from entity before reaching reload "complete"
Expand Down
Loading