Skip to content

Commit 4555104

Browse files
authored
Allow mob spawning on stone blocks (#2859)
1 parent d7f6703 commit 4555104

File tree

3 files changed

+41
-9
lines changed

3 files changed

+41
-9
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package gregtech.api.block;
2+
3+
import net.minecraft.block.state.IBlockState;
4+
import net.minecraft.entity.EntityLiving;
5+
import net.minecraft.util.math.BlockPos;
6+
import net.minecraft.world.IBlockAccess;
7+
8+
import org.jetbrains.annotations.NotNull;
9+
10+
public interface IStateSpawnControl {
11+
12+
boolean canCreatureSpawn(@NotNull IBlockState state, @NotNull IBlockAccess world, @NotNull BlockPos pos,
13+
@NotNull EntityLiving.SpawnPlacementType type);
14+
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
import net.minecraft.client.util.ITooltipFlag;
1414
import net.minecraft.creativetab.CreativeTabs;
1515
import net.minecraft.entity.Entity;
16+
import net.minecraft.entity.EntityLiving;
1617
import net.minecraft.item.ItemStack;
1718
import net.minecraft.util.IStringSerializable;
1819
import net.minecraft.util.NonNullList;
1920
import net.minecraft.util.math.BlockPos;
21+
import net.minecraft.world.IBlockAccess;
2022
import net.minecraft.world.World;
2123
import net.minecraftforge.fml.relauncher.Side;
2224
import net.minecraftforge.fml.relauncher.SideOnly;
@@ -125,6 +127,15 @@ public SoundType getSoundType(@NotNull IBlockState state, @NotNull World world,
125127
return super.getSoundType(state, world, pos, entity);
126128
}
127129

130+
@Override
131+
public boolean canCreatureSpawn(@NotNull IBlockState state, @NotNull IBlockAccess world, @NotNull BlockPos pos,
132+
@NotNull EntityLiving.SpawnPlacementType type) {
133+
if (getState(state) instanceof IStateSpawnControl stateSpawnControl) {
134+
return stateSpawnControl.canCreatureSpawn(state, world, pos, type);
135+
}
136+
return super.canCreatureSpawn(state, world, pos, type);
137+
}
138+
128139
// magic is here
129140
@SuppressWarnings("unchecked")
130141
protected static <T, R> Class<T> getActualTypeParameter(Class<? extends R> thisClass, Class<R> declaringClass) {

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

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

3+
import gregtech.api.block.IStateSpawnControl;
34
import gregtech.api.block.VariantBlock;
45
import gregtech.api.items.toolitem.ToolClasses;
56
import gregtech.api.unification.material.Material;
@@ -51,12 +52,6 @@ protected BlockStateContainer createBlockState() {
5152
return new BlockStateContainer(this, VARIANT);
5253
}
5354

54-
@Override
55-
public boolean canCreatureSpawn(@NotNull IBlockState state, @NotNull IBlockAccess world, @NotNull BlockPos pos,
56-
@NotNull EntityLiving.SpawnPlacementType type) {
57-
return false;
58-
}
59-
6055
@Override
6156
protected boolean canSilkHarvest() {
6257
return this.stoneVariant == StoneVariant.SMOOTH;
@@ -69,21 +64,27 @@ public Item getItemDropped(@NotNull IBlockState state, @NotNull Random rand, int
6964
MetaBlocks.STONE_BLOCKS.get(StoneVariant.COBBLE) : this);
7065
}
7166

72-
public enum StoneType implements IStringSerializable {
67+
public enum StoneType implements IStringSerializable, IStateSpawnControl {
7368

7469
BLACK_GRANITE("black_granite", MapColor.BLACK),
7570
RED_GRANITE("red_granite", MapColor.RED),
7671
MARBLE("marble", MapColor.QUARTZ),
7772
BASALT("basalt", MapColor.BLACK_STAINED_HARDENED_CLAY),
78-
CONCRETE_LIGHT("concrete_light", MapColor.STONE),
79-
CONCRETE_DARK("concrete_dark", MapColor.STONE);
73+
CONCRETE_LIGHT("concrete_light", MapColor.STONE, false),
74+
CONCRETE_DARK("concrete_dark", MapColor.STONE, false);
8075

8176
private final String name;
77+
private final boolean allowSpawn;
8278
public final MapColor mapColor;
8379

8480
StoneType(@NotNull String name, @NotNull MapColor mapColor) {
81+
this(name, mapColor, true);
82+
}
83+
84+
StoneType(@NotNull String name, @NotNull MapColor mapColor, boolean allowSpawn) {
8585
this.name = name;
8686
this.mapColor = mapColor;
87+
this.allowSpawn = allowSpawn;
8788
}
8889

8990
@NotNull
@@ -108,6 +109,12 @@ public Material getMaterial() {
108109
case CONCRETE_LIGHT, CONCRETE_DARK -> Materials.Concrete;
109110
};
110111
}
112+
113+
@Override
114+
public boolean canCreatureSpawn(@NotNull IBlockState state, @NotNull IBlockAccess world, @NotNull BlockPos pos,
115+
@NotNull EntityLiving.SpawnPlacementType type) {
116+
return this.allowSpawn;
117+
}
111118
}
112119

113120
public enum StoneVariant {

0 commit comments

Comments
 (0)