Skip to content

Commit ff6de03

Browse files
authored
Allow giving mtes custom soundtypes (#2853)
1 parent 8bc2ba5 commit ff6de03

17 files changed

+155
-8
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package gregtech.api.block;
2+
3+
import net.minecraft.block.SoundType;
4+
import net.minecraft.block.state.IBlockState;
5+
6+
import org.jetbrains.annotations.NotNull;
7+
8+
public interface IStateSoundType {
9+
10+
@NotNull
11+
SoundType getSoundType(@NotNull IBlockState state);
12+
}

src/main/java/gregtech/api/block/VariantBlock.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@
44
import gregtech.common.creativetab.GTCreativeTabs;
55

66
import net.minecraft.block.Block;
7+
import net.minecraft.block.SoundType;
78
import net.minecraft.block.material.Material;
89
import net.minecraft.block.properties.PropertyEnum;
910
import net.minecraft.block.state.BlockStateContainer;
1011
import net.minecraft.block.state.IBlockState;
1112
import net.minecraft.client.resources.I18n;
1213
import net.minecraft.client.util.ITooltipFlag;
1314
import net.minecraft.creativetab.CreativeTabs;
15+
import net.minecraft.entity.Entity;
1416
import net.minecraft.item.ItemStack;
1517
import net.minecraft.util.IStringSerializable;
1618
import net.minecraft.util.NonNullList;
19+
import net.minecraft.util.math.BlockPos;
1720
import net.minecraft.world.World;
1821
import net.minecraftforge.fml.relauncher.Side;
1922
import net.minecraftforge.fml.relauncher.SideOnly;
@@ -112,6 +115,16 @@ public int getMetaFromState(IBlockState state) {
112115
return state.getValue(VARIANT).ordinal();
113116
}
114117

118+
@NotNull
119+
@Override
120+
public SoundType getSoundType(@NotNull IBlockState state, @NotNull World world, @NotNull BlockPos pos,
121+
@Nullable Entity entity) {
122+
if (getState(state) instanceof IStateSoundType stateSoundType) {
123+
return stateSoundType.getSoundType(state);
124+
}
125+
return super.getSoundType(state, world, pos, entity);
126+
}
127+
115128
// magic is here
116129
@SuppressWarnings("unchecked")
117130
protected static <T, R> Class<T> getActualTypeParameter(Class<? extends R> thisClass, Class<R> declaringClass) {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,4 +590,13 @@ public void randomDisplayTick(@NotNull IBlockState stateIn, @NotNull World world
590590
MetaTileEntity metaTileEntity = getMetaTileEntity(worldIn, pos);
591591
if (metaTileEntity != null) metaTileEntity.randomDisplayTick();
592592
}
593+
594+
@NotNull
595+
@Override
596+
public SoundType getSoundType(@NotNull IBlockState state, @NotNull World world, @NotNull BlockPos pos,
597+
@Nullable Entity entity) {
598+
MetaTileEntity metaTileEntity = getMetaTileEntity(world, pos);
599+
if (metaTileEntity == null) return getSoundType();
600+
return metaTileEntity.getSoundType();
601+
}
593602
}

src/main/java/gregtech/api/metatileentity/MetaTileEntity.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import gregtech.common.items.MetaItems;
4242

4343
import net.minecraft.block.Block;
44+
import net.minecraft.block.SoundType;
4445
import net.minecraft.block.state.BlockFaceShape;
4546
import net.minecraft.block.state.IBlockState;
4647
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
@@ -908,6 +909,14 @@ private void updateSound() {
908909
}
909910
}
910911

912+
/**
913+
* @return The sound type used when this block is broken, placed, stepped on, hit, or fallen on.
914+
*/
915+
@NotNull
916+
public SoundType getSoundType() {
917+
return SoundType.METAL;
918+
}
919+
911920
public final @NotNull ItemStack getStackForm(int amount) {
912921
int metaTileEntityIntId = registry.getIdByObjectName(metaTileEntityId);
913922
return new ItemStack(registry.getBlock(), amount, metaTileEntityIntId);

src/main/java/gregtech/common/blocks/BlockMetalCasing.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package gregtech.common.blocks;
22

33
import gregtech.api.block.IStateHarvestLevel;
4+
import gregtech.api.block.IStateSoundType;
45
import gregtech.api.block.VariantBlock;
56
import gregtech.api.items.toolitem.ToolClasses;
67

@@ -31,27 +32,33 @@ public boolean canCreatureSpawn(@NotNull IBlockState state, @NotNull IBlockAcces
3132
return false;
3233
}
3334

34-
public enum MetalCasingType implements IStringSerializable, IStateHarvestLevel {
35+
public enum MetalCasingType implements IStringSerializable, IStateHarvestLevel, IStateSoundType {
3536

3637
BRONZE_BRICKS("bronze_bricks", 1),
37-
PRIMITIVE_BRICKS("primitive_bricks", 1),
38+
PRIMITIVE_BRICKS("primitive_bricks", 1, SoundType.STONE),
3839
INVAR_HEATPROOF("invar_heatproof", 1),
3940
ALUMINIUM_FROSTPROOF("aluminium_frostproof", 1),
4041
STEEL_SOLID("steel_solid", 2),
4142
STAINLESS_CLEAN("stainless_clean", 2),
4243
TITANIUM_STABLE("titanium_stable", 2),
4344
TUNGSTENSTEEL_ROBUST("tungstensteel_robust", 3),
44-
COKE_BRICKS("coke_bricks", 1),
45+
COKE_BRICKS("coke_bricks", 1, SoundType.STONE),
4546
PTFE_INERT_CASING("ptfe_inert", 0),
4647
HSSE_STURDY("hsse_sturdy", 3),
4748
PALLADIUM_SUBSTATION("palladium_substation", 3);
4849

4950
private final String name;
5051
private final int harvestLevel;
52+
private final SoundType soundType;
5153

52-
MetalCasingType(String name, int harvestLevel) {
54+
MetalCasingType(String name, int harvestLevel, SoundType soundType) {
5355
this.name = name;
5456
this.harvestLevel = harvestLevel;
57+
this.soundType = soundType;
58+
}
59+
60+
MetalCasingType(String name, int harvestLevel) {
61+
this(name, harvestLevel, SoundType.METAL);
5562
}
5663

5764
@NotNull
@@ -69,5 +76,11 @@ public int getHarvestLevel(IBlockState state) {
6976
public String getHarvestTool(IBlockState state) {
7077
return ToolClasses.WRENCH;
7178
}
79+
80+
@NotNull
81+
@Override
82+
public SoundType getSoundType(@NotNull IBlockState state) {
83+
return soundType;
84+
}
7285
}
7386
}

src/main/java/gregtech/common/blocks/BlockSteamCasing.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package gregtech.common.blocks;
22

33
import gregtech.api.block.IStateHarvestLevel;
4+
import gregtech.api.block.IStateSoundType;
45
import gregtech.api.block.VariantBlock;
56
import gregtech.api.items.toolitem.ToolClasses;
67

@@ -51,21 +52,27 @@ public void addInformation(@NotNull ItemStack stack, @Nullable World player, @No
5152
}
5253
}
5354

54-
public enum SteamCasingType implements IStringSerializable, IStateHarvestLevel {
55+
public enum SteamCasingType implements IStringSerializable, IStateHarvestLevel, IStateSoundType {
5556

5657
BRONZE_HULL("bronze_hull", 1),
5758
BRONZE_BRICKS_HULL("bronze_bricks_hull", 1),
5859
STEEL_HULL("steel_hull", 2),
5960
STEEL_BRICKS_HULL("steel_bricks_hull", 2),
60-
PUMP_DECK("pump_deck", 1),
61-
WOOD_WALL("wood_wall", 0);
61+
PUMP_DECK("pump_deck", 1, SoundType.WOOD),
62+
WOOD_WALL("wood_wall", 0, SoundType.WOOD);
6263

6364
private final String name;
6465
private final int harvestLevel;
66+
private final SoundType soundType;
6567

66-
SteamCasingType(String name, int harvestLevel) {
68+
SteamCasingType(String name, int harvestLevel, SoundType soundType) {
6769
this.name = name;
6870
this.harvestLevel = harvestLevel;
71+
this.soundType = soundType;
72+
}
73+
74+
SteamCasingType(String name, int harvestLevel) {
75+
this(name, harvestLevel, SoundType.METAL);
6976
}
7077

7178
@Override
@@ -83,5 +90,11 @@ public int getHarvestLevel(IBlockState state) {
8390
public String getHarvestTool(IBlockState state) {
8491
return ToolClasses.WRENCH;
8592
}
93+
94+
@NotNull
95+
@Override
96+
public SoundType getSoundType(@NotNull IBlockState state) {
97+
return soundType;
98+
}
8699
}
87100
}

src/main/java/gregtech/common/metatileentities/MetaTileEntityClipboard.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import gregtech.core.network.packets.PacketClipboardNBTUpdate;
2222

2323
import net.minecraft.block.Block;
24+
import net.minecraft.block.SoundType;
2425
import net.minecraft.block.state.IBlockState;
2526
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
2627
import net.minecraft.creativetab.CreativeTabs;
@@ -548,4 +549,10 @@ public boolean showToolUsages() {
548549
public ItemStack getPickItem(EntityPlayer player) {
549550
return this.getClipboard();
550551
}
552+
553+
@NotNull
554+
@Override
555+
public SoundType getSoundType() {
556+
return SoundType.WOOD;
557+
}
551558
}

src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityCokeOven.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import gregtech.common.metatileentities.MetaTileEntities;
2222
import gregtech.common.mui.widget.GTFluidSlot;
2323

24+
import net.minecraft.block.SoundType;
2425
import net.minecraft.block.state.IBlockState;
2526
import net.minecraft.entity.player.EntityPlayer;
2627
import net.minecraft.entity.player.EntityPlayerMP;
@@ -168,4 +169,10 @@ public boolean onRightClick(EntityPlayer playerIn, EnumHand hand, EnumFacing fac
168169
}
169170
return super.onRightClick(playerIn, hand, facing, hitResult);
170171
}
172+
173+
@NotNull
174+
@Override
175+
public SoundType getSoundType() {
176+
return SoundType.STONE;
177+
}
171178
}

src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityCokeOvenHatch.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import gregtech.client.renderer.texture.Textures;
1313
import gregtech.common.metatileentities.multi.multiblockpart.MetaTileEntityMultiblockPart;
1414

15+
import net.minecraft.block.SoundType;
1516
import net.minecraft.client.resources.I18n;
1617
import net.minecraft.entity.player.EntityPlayer;
1718
import net.minecraft.item.ItemStack;
@@ -30,6 +31,7 @@
3031
import codechicken.lib.render.CCRenderState;
3132
import codechicken.lib.render.pipeline.IVertexOperation;
3233
import codechicken.lib.vec.Matrix4;
34+
import org.jetbrains.annotations.NotNull;
3335
import org.jetbrains.annotations.Nullable;
3436

3537
import java.util.List;
@@ -127,4 +129,10 @@ public boolean onRightClick(EntityPlayer playerIn, EnumHand hand, EnumFacing fac
127129
}
128130
return super.onRightClick(playerIn, hand, facing, hitResult);
129131
}
132+
133+
@NotNull
134+
@Override
135+
public SoundType getSoundType() {
136+
return SoundType.STONE;
137+
}
130138
}

src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityMultiblockTank.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import gregtech.common.metatileentities.MetaTileEntities;
2121
import gregtech.common.mui.widget.GTFluidSlot;
2222

23+
import net.minecraft.block.SoundType;
2324
import net.minecraft.block.state.IBlockState;
2425
import net.minecraft.client.resources.I18n;
2526
import net.minecraft.entity.player.EntityPlayer;
@@ -191,4 +192,10 @@ public <T> T getCapability(Capability<T> capability, EnumFacing side) {
191192
}
192193
return super.getCapability(capability, side);
193194
}
195+
196+
@NotNull
197+
@Override
198+
public SoundType getSoundType() {
199+
return this.isMetal ? SoundType.METAL : SoundType.WOOD;
200+
}
194201
}

0 commit comments

Comments
 (0)