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

View file

@ -89,8 +89,13 @@ public class AbstractBlockBlockEntity extends GenericMachineBlockEntity implemen
//BlockBreakerProcessable
@Override
public void playSound() {
if (RecipeCrafter.soundHandler != null) {
if (RecipeCrafter.soundHandler != null && canPlaySound()) {
RecipeCrafter.soundHandler.playSound(false, this);
}
}
@Override
public boolean canPlaySound() {
return !isMuffled();
}
}

View file

@ -23,9 +23,19 @@ public interface BlockProcessable extends IUpgradeHandler, RedstoneConfigurable,
*/
boolean consumeEnergy(int amount);
/**
* <b>Play a sound to the Minecraft world</b>
*
* @see #canPlaySound()
*/
void playSound();
/**
* <b>If a sound can be played.</b>
*
* @see #playSound()
*/
default boolean canPlaySound() {
return true;
}
}

View file

@ -1496,6 +1496,9 @@ public class TRContent {
if (aesu != null) {
aesu.superconductors += TechRebornConfig.superConductorCount;
}
}),
MUFFLER((blockEntity, handler, stack) -> {
blockEntity.muffle();
});
public String name;

View file

@ -699,6 +699,7 @@
"item.techreborn.transformer_upgrade": "Transformer Upgrade",
"item.techreborn.energy_storage_upgrade": "Energy Storage Upgrade",
"item.techreborn.superconductor_upgrade": "Superconductor Upgrade",
"item.techreborn.muffler_upgrade": "Muffler Upgrade",
"item.techreborn.bronze_sword": "Bronze Sword",
"item.techreborn.bronze_pickaxe": "Bronze Pickaxe",
@ -768,6 +769,7 @@
"techreborn.message.info.item.techreborn.transformer_upgrade": "Increase energy tier",
"techreborn.message.info.item.techreborn.energy_storage_upgrade": "Increase energy store",
"techreborn.message.info.item.techreborn.superconductor_upgrade": "Increases energy flow rate",
"techreborn.message.info.item.techreborn.muffler_upgrade": "Muffles the machine",
"techreborn.message.info.unplaceable_fluid": "Cannot be placed",

View file

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "techreborn:item/upgrade/muffler_upgrade"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 579 B

View file

@ -0,0 +1,32 @@
{
"parent": "minecraft:recipes/root",
"rewards": {
"recipes": [
"techreborn:crafting_table/upgrade/muffler_upgrade"
]
},
"criteria": {
"has_electronic_circuit": {
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{
"items": ["techreborn:electronic_circuit"]
}
]
}
},
"has_the_recipe": {
"trigger": "minecraft:recipe_unlocked",
"conditions": {
"recipe": "techreborn:crafting_table/upgrade/muffler_upgrade"
}
}
},
"requirements": [
[
"has_electronic_circuit",
"has_the_recipe"
]
]
}

View file

@ -51,9 +51,19 @@
}
]
}
},
"muffler": {
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{
"items": ["techreborn:muffler_upgrade"]
}
]
}
}
},
"requirements": [
["overclocker", "transformer","energystorage","superconductor"]
["overclocker", "transformer","energystorage","superconductor","muffler"]
]
}

View file

@ -0,0 +1,19 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
" W ",
"WCW",
" W "
],
"key": {
"C": {
"item": "techreborn:electronic_circuit"
},
"W": {
"tag": "minecraft:wool"
}
},
"result": {
"item": "techreborn:muffler_upgrade"
}
}