Fix RecipeCrafter spamming sound every tick. Thanks to aria1th

* Fix RecipeCrafter spamming sound every tick

Recycler was able to spam sound due to this. Now its limited to twice per second

* Revert Indent changes & test code

Its Identical whitespaces but different?
Speed Multiplier was changed to verify packet speed, should be reverted
This commit is contained in:
AngelBottomless 2022-03-28 14:45:05 +09:00 committed by GitHub
parent 80ee73ddab
commit 4fc9352c76
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -92,6 +92,8 @@ public class RecipeCrafter implements IUpgradeHandler {
*/
public int[] outputSlots;
public RebornRecipe currentRecipe;
public long lastSoundTime = 0;
private long cachedWorldTime = 0;
public int currentTickTime = 0;
public int currentNeededTicks = 1;// Set to 1 to stop rare crashes
@ -129,6 +131,10 @@ public class RecipeCrafter implements IUpgradeHandler {
return;
}
ticksSinceLastChange++;
if (cachedWorldTime == 0){
cachedWorldTime = blockEntity.getWorld().getTime();
}
cachedWorldTime++;
// Force a has chanced every second
if (ticksSinceLastChange == 20) {
setInvDirty(true);
@ -181,7 +187,8 @@ public class RecipeCrafter implements IUpgradeHandler {
long useRequirement = getEuPerTick(currentRecipe.getPower());
if (energy.tryUseExact(useRequirement)) {
currentTickTime++;
if ((currentTickTime == 1 || currentTickTime % 20 == 0) && soundHandler != null) {
if ((currentTickTime == 1 || currentTickTime % 20 == 0 && cachedWorldTime > lastSoundTime+ 10) && soundHandler != null) {
lastSoundTime = cachedWorldTime;
soundHandler.playSound(false, blockEntity);
}
}