Added the muffler upgrade (#2928)

* Added flag for ability to play sound.

* Added muffler functionality

* Added muffler to upgrade advancement

* Added muffler model

* Added muffler lang entry

* Added muffler placeholder texture

* Added muffler recipe + toast

* Added muffler tooltip
This commit is contained in:
Ayutac 2022-04-28 10:52:10 +02:00 committed by GitHub
parent b14a4c72a1
commit a574c7f67e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 135 additions and 5 deletions

View file

@ -102,6 +102,12 @@ public class MachineBaseBlockEntity extends BlockEntity implements BlockEntityTi
* </ul>
*/
double powerMultiplier = 1;
/**
* <p>
* This is used to change the sound of the crafting operation.
* <p/>
*/
boolean muffled = false;
public MachineBaseBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
super(type, pos, state);
@ -187,6 +193,7 @@ public class MachineBaseBlockEntity extends BlockEntity implements BlockEntityTi
public void resetUpgrades() {
resetPowerMultiplier();
resetSpeedMultiplier();
resetMuffler();
}
protected void afterUpgradesApplication() {
@ -356,6 +363,21 @@ public class MachineBaseBlockEntity extends BlockEntity implements BlockEntityTi
}
}
@Override
public void muffle() {
muffled = true;
}
@Override
public void resetMuffler() {
muffled = false;
}
@Override
public boolean isMuffled() {
return muffled;
}
public boolean hasSlotConfig() {
return true;
}

View file

@ -43,4 +43,10 @@ public interface IUpgradeHandler {
void addSpeedMultiplier(double amount);
void muffle();
void resetMuffler();
boolean isMuffled();
}

View file

@ -187,7 +187,7 @@ public class RecipeCrafter implements IUpgradeHandler {
long useRequirement = getEuPerTick(currentRecipe.getPower());
if (energy.tryUseExact(useRequirement)) {
currentTickTime++;
if ((currentTickTime == 1 || currentTickTime % 20 == 0 && cachedWorldTime > lastSoundTime+ 10) && soundHandler != null) {
if ((currentTickTime == 1 || currentTickTime % 20 == 0 && cachedWorldTime > lastSoundTime+ 10) && soundHandler != null && !isMuffled()) {
lastSoundTime = cachedWorldTime;
soundHandler.playSound(false, blockEntity);
}
@ -416,4 +416,19 @@ public class RecipeCrafter implements IUpgradeHandler {
public void addSpeedMultiplier(double amount) {
parentUpgradeHandler.ifPresent(iUpgradeHandler -> iUpgradeHandler.addSpeedMultiplier(amount));
}
@Override
public void muffle() {
parentUpgradeHandler.ifPresent(IUpgradeHandler::muffle);
}
@Override
public void resetMuffler() {
parentUpgradeHandler.ifPresent(IUpgradeHandler::resetMuffler);
}
@Override
public boolean isMuffled() {
return parentUpgradeHandler.map(IUpgradeHandler::isMuffled).orElse(false);
}
}