Skip to content

Commit 225ce76

Browse files
committed
feat: assign proper soundtype for metablocks
1 parent 8f9e7b9 commit 225ce76

File tree

4 files changed

+59
-8
lines changed

4 files changed

+59
-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/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
}

0 commit comments

Comments
 (0)