Skip to content

Commit 8a0c4e2

Browse files
TestureExaxxion
andauthored
Machine Sounds (#11)
* GregTech machines now play sounds while running (with accompanying subtitles). * Volume can be adjusted using the Block volume slider, or disabled globally in configs. * Hard Hammers now have a right-click interaction with machines to muffle/unmuffle sounds. * TOP will now display the muffled state of a machine, in the same way that it shows a machine has "Working Disabled" (by a Soft Hammer or Machine Controller). --------- Co-authored-by: Exa <[email protected]>
1 parent dd6d85e commit 8a0c4e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+941
-82
lines changed

src/main/java/gregtech/api/GregTechAPI.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import gregtech.api.block.machines.BlockMachine;
44
import gregtech.api.metatileentity.MetaTileEntity;
5+
import gregtech.api.sound.ISoundManager;
56
import gregtech.api.unification.OreDictUnifier;
67
import gregtech.api.unification.material.Materials;
78
import gregtech.api.unification.material.type.DustMaterial;
@@ -20,6 +21,7 @@ public class GregTechAPI {
2021

2122
public static BlockMachine MACHINE;
2223
public static final Map<DustMaterial, Map<StoneType, IBlockOre>> oreBlockTable = new HashMap<>();
24+
public static ISoundManager soundManager;
2325

2426
public static final BaseCreativeTab TAB_GREGTECH =
2527
new BaseCreativeTab(GTValues.MODID + ".main", () -> MetaItems.BATTERY_HULL_HV.getStackForm(), true);
@@ -35,4 +37,4 @@ public static <T extends MetaTileEntity> T registerMetaTileEntity(int id, T samp
3537
return sampleMetaTileEntity;
3638
}
3739

38-
}
40+
}

src/main/java/gregtech/api/block/machines/BlockMachine.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import gregtech.api.GregTechAPI;
1111
import gregtech.api.block.BlockCustomParticle;
1212
import gregtech.api.capability.GregtechCapabilities;
13+
import gregtech.api.capability.tool.IHardHammerItem;
1314
import gregtech.api.capability.tool.IScrewdriverItem;
1415
import gregtech.api.capability.tool.IWrenchItem;
1516
import gregtech.api.cover.CoverBehavior;
@@ -276,7 +277,7 @@ public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state,
276277
if (itemStack.hasCapability(GregtechCapabilities.CAPABILITY_SCREWDRIVER, null)) {
277278
IScrewdriverItem screwdriver = itemStack.getCapability(GregtechCapabilities.CAPABILITY_SCREWDRIVER, null);
278279

279-
if (screwdriver.damageItem(DamageValues.DAMAGE_FOR_SCREWDRIVER, true) &&
280+
if (screwdriver != null && screwdriver.damageItem(DamageValues.DAMAGE_FOR_SCREWDRIVER, true) &&
280281
metaTileEntity.onCoverScrewdriverClick(playerIn, hand, rayTraceResult)) {
281282
screwdriver.damageItem(DamageValues.DAMAGE_FOR_SCREWDRIVER, false);
282283
return true;
@@ -288,14 +289,26 @@ public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state,
288289
IWrenchItem wrenchItem = itemStack.getCapability(GregtechCapabilities.CAPABILITY_WRENCH, null);
289290
EnumFacing wrenchDirection = ICoverable.determineGridSideHit(rayTraceResult);
290291

291-
if (wrenchItem.damageItem(DamageValues.DAMAGE_FOR_WRENCH, true) &&
292+
if (wrenchItem != null && wrenchItem.damageItem(DamageValues.DAMAGE_FOR_WRENCH, true) &&
292293
metaTileEntity.onWrenchClick(playerIn, hand, wrenchDirection, rayTraceResult)) {
293294
wrenchItem.damageItem(DamageValues.DAMAGE_FOR_WRENCH, false);
294295
return true;
295296
}
296297
return false;
297298
}
298299

300+
if(itemStack.hasCapability(GregtechCapabilities.CAPABILITY_HAMMER, null)) {
301+
IHardHammerItem hammer = itemStack.getCapability(GregtechCapabilities.CAPABILITY_HAMMER, null);
302+
EnumFacing hammerDirection = ICoverable.determineGridSideHit(rayTraceResult);
303+
304+
if(hammer != null && hammer.damageItem(DamageValues.DAMAGE_FOR_HAMMER, true)) {
305+
metaTileEntity.onHammerClick(playerIn, hand, hammerDirection, rayTraceResult);
306+
hammer.damageItem(DamageValues.DAMAGE_FOR_HAMMER, false);
307+
return true;
308+
}
309+
return false;
310+
}
311+
299312
return metaTileEntity.onCoverRightClick(playerIn, hand, rayTraceResult);
300313
}
301314

src/main/java/gregtech/api/capability/GregtechCapabilities.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package gregtech.api.capability;
22

3+
import gregtech.api.capability.tool.IHardHammerItem;
34
import gregtech.api.capability.tool.IScrewdriverItem;
45
import gregtech.api.capability.tool.ISoftHammerItem;
56
import gregtech.api.capability.tool.IWrenchItem;
@@ -26,4 +27,6 @@ public class GregtechCapabilities {
2627
@CapabilityInject(IFuelable.class)
2728
public static Capability<IFuelable> CAPABILITY_FUELABLE = null;
2829

30+
@CapabilityInject(IHardHammerItem.class)
31+
public static Capability<IHardHammerItem> CAPABILITY_HAMMER = null;
2932
}

src/main/java/gregtech/api/capability/GregtechTileCapabilities.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@ public class GregtechTileCapabilities {
1818
@CapabilityInject(IActiveOutputSide.class)
1919
public static Capability<IActiveOutputSide> CAPABILITY_ACTIVE_OUTPUT_SIDE = null;
2020

21+
@CapabilityInject(IMuffleable.class)
22+
public static Capability<IMuffleable> CAPABILITY_MUFFLEABLE = null;
23+
2124
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package gregtech.api.capability;
2+
3+
public interface IMuffleable {
4+
5+
boolean isMuffled();
6+
7+
void toggleMuffled();
8+
}

src/main/java/gregtech/api/capability/SimpleCapabilityManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package gregtech.api.capability;
22

3+
import gregtech.api.capability.tool.IHardHammerItem;
34
import gregtech.api.capability.tool.IScrewdriverItem;
45
import gregtech.api.capability.tool.ISoftHammerItem;
56
import gregtech.api.capability.tool.IWrenchItem;
@@ -40,10 +41,12 @@ public static void init() {
4041
registerCapabilityWithNoDefault(IControllable.class);
4142
registerCapabilityWithNoDefault(IActiveOutputSide.class);
4243
registerCapabilityWithNoDefault(IFuelable.class);
44+
registerCapabilityWithNoDefault(IMuffleable.class);
4345

4446
registerCapabilityWithNoDefault(IWrenchItem.class);
4547
registerCapabilityWithNoDefault(IScrewdriverItem.class);
4648
registerCapabilityWithNoDefault(ISoftHammerItem.class);
49+
registerCapabilityWithNoDefault(IHardHammerItem.class);
4750

4851
//internal capabilities
4952
CapabilityManager.INSTANCE.register(GTWorldGenCapability.class, GTWorldGenCapability.STORAGE, GTWorldGenCapability.FACTORY);

src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
import gregtech.api.recipes.RecipeMap;
1111
import gregtech.api.util.GTUtility;
1212
import gregtech.common.ConfigHolder;
13+
import gregtech.common.sound.GTSoundEvents;
1314
import net.minecraft.item.ItemStack;
1415
import net.minecraft.nbt.NBTTagCompound;
1516
import net.minecraft.nbt.NBTTagList;
1617
import net.minecraft.network.PacketBuffer;
1718
import net.minecraft.util.NonNullList;
19+
import net.minecraft.util.SoundEvent;
1820
import net.minecraft.world.*;
1921
import net.minecraftforge.common.capabilities.Capability;
2022
import net.minecraftforge.common.util.Constants;
@@ -83,6 +85,13 @@ protected IMultipleTankHandler getOutputTank() {
8385
return metaTileEntity.getExportFluids();
8486
}
8587

88+
public SoundEvent getSound() {
89+
if (isActive() && isHasNotEnoughEnergy()) {
90+
return GTSoundEvents.INTERRUPTED;
91+
}
92+
return recipeMap.getSound();
93+
}
94+
8695
@Override
8796
public String getName() {
8897
return "RecipeMapWorkable";
@@ -99,6 +108,8 @@ public <T> T getCapability(Capability<T> capability) {
99108
return GregtechTileCapabilities.CAPABILITY_WORKABLE.cast(this);
100109
} else if(capability == GregtechTileCapabilities.CAPABILITY_CONTROLLABLE) {
101110
return GregtechTileCapabilities.CAPABILITY_CONTROLLABLE.cast(this);
111+
} else if(capability == GregtechTileCapabilities.CAPABILITY_MUFFLEABLE) {
112+
return GregtechTileCapabilities.CAPABILITY_MUFFLEABLE.cast(getMetaTileEntity());
102113
}
103114
return null;
104115
}
@@ -161,13 +172,14 @@ protected void updateRecipeProgress() {
161172
boolean drawEnergy = drawEnergy(recipeEUt);
162173
if (drawEnergy || (recipeEUt < 0)) {
163174
//as recipe starts with progress on 1 this has to be > only not => to compensate for it
175+
setHasNotEnoughEnergy(false);
164176
if (++progressTime > maxProgressTime) {
165177
completeRecipe();
166178
}
167179
} else if (recipeEUt > 0) {
168180
//only set hasNotEnoughEnergy if this recipe is consuming recipe
169181
//generators always have enough energy
170-
this.hasNotEnoughEnergy = true;
182+
setHasNotEnoughEnergy(true);
171183
//if current progress value is greater than 2, decrement it by 2
172184
if (progressTime >= 2) {
173185
if (ConfigHolder.insufficientEnergySupplyWipesRecipeProgress) {
@@ -176,6 +188,7 @@ protected void updateRecipeProgress() {
176188
this.progressTime = Math.max(1, progressTime - 2);
177189
}
178190
}
191+
179192
}
180193
}
181194

@@ -345,7 +358,7 @@ protected void completeRecipe() {
345358
this.recipeEUt = 0;
346359
this.fluidOutputs = null;
347360
this.itemOutputs = null;
348-
this.hasNotEnoughEnergy = false;
361+
setHasNotEnoughEnergy(false);
349362
this.wasActiveAndNeedsUpdate = true;
350363
}
351364

@@ -381,14 +394,33 @@ protected void setActive(boolean active) {
381394
metaTileEntity.markDirty();
382395
World world = metaTileEntity.getWorld();
383396
if (world != null && !world.isRemote) {
384-
writeCustomData(1, buf -> buf.writeBoolean(active));
397+
writeCustomData(1, buf -> {
398+
buf.writeBoolean(active);
399+
buf.writeBoolean(workingEnabled);
400+
});
401+
}
402+
}
403+
404+
protected void setHasNotEnoughEnergy(boolean hasNotEnoughEnergy) {
405+
this.hasNotEnoughEnergy = hasNotEnoughEnergy;
406+
metaTileEntity.markDirty();
407+
World world = metaTileEntity.getWorld();
408+
if (world != null && !world.isRemote) {
409+
writeCustomData(2, buf -> buf.writeBoolean(hasNotEnoughEnergy));
385410
}
386411
}
387412

388413
@Override
389414
public void setWorkingEnabled(boolean workingEnabled) {
390415
this.workingEnabled = workingEnabled;
391416
metaTileEntity.markDirty();
417+
World world = metaTileEntity.getWorld();
418+
if (world != null && !world.isRemote) {
419+
writeCustomData(1, buf -> {
420+
buf.writeBoolean(isActive);
421+
buf.writeBoolean(workingEnabled);
422+
});
423+
}
392424
}
393425

394426
public void setAllowOverclocking(boolean allowOverclocking) {
@@ -459,18 +491,25 @@ public void setOverclockTier(final int tier) {
459491
public void receiveCustomData(int dataId, PacketBuffer buf) {
460492
if (dataId == 1) {
461493
this.isActive = buf.readBoolean();
494+
this.workingEnabled = buf.readBoolean();
462495
getMetaTileEntity().getHolder().scheduleChunkForRenderUpdate();
496+
} else if (dataId == 2) {
497+
this.hasNotEnoughEnergy = buf.readBoolean();
463498
}
464499
}
465500

466501
@Override
467502
public void writeInitialData(PacketBuffer buf) {
468503
buf.writeBoolean(this.isActive);
504+
buf.writeBoolean(this.hasNotEnoughEnergy);
505+
buf.writeBoolean(this.workingEnabled);
469506
}
470507

471508
@Override
472509
public void receiveInitialData(PacketBuffer buf) {
473510
this.isActive = buf.readBoolean();
511+
this.hasNotEnoughEnergy = buf.readBoolean();
512+
this.workingEnabled = buf.readBoolean();
474513
}
475514

476515
@Override
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package gregtech.api.capability.tool;
2+
3+
public interface IHardHammerItem {
4+
boolean damageItem(int damage, boolean simulate);
5+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package gregtech.api.items.toolitem;
2+
3+
import gregtech.api.capability.GregtechCapabilities;
4+
import gregtech.api.capability.tool.IHardHammerItem;
5+
import gregtech.api.items.metaitem.stats.IItemCapabilityProvider;
6+
import net.minecraft.item.ItemStack;
7+
import net.minecraftforge.common.capabilities.Capability;
8+
import net.minecraftforge.common.capabilities.ICapabilityProvider;
9+
10+
public class HardHammerItemStat implements IItemCapabilityProvider {
11+
@Override
12+
public ICapabilityProvider createProvider(ItemStack itemStack) {
13+
return new HardHammerItemStat.CapabilityProvider(itemStack);
14+
}
15+
16+
private static class CapabilityProvider
17+
extends AbstractToolItemCapabilityProvider<IHardHammerItem>
18+
implements IHardHammerItem {
19+
20+
public CapabilityProvider(ItemStack itemStack) {
21+
super(itemStack);
22+
}
23+
24+
@Override
25+
protected Capability<IHardHammerItem> getCapability() {
26+
return GregtechCapabilities.CAPABILITY_HAMMER;
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)