Skip to content

Commit 06d8f60

Browse files
committed
ban spawning on concrete blocks
1 parent a670589 commit 06d8f60

File tree

3 files changed

+36
-3
lines changed

3 files changed

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

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);
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: 15 additions & 3 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;
@@ -60,21 +61,27 @@ public Item getItemDropped(@NotNull IBlockState state, @NotNull Random rand, int
6061
MetaBlocks.STONE_BLOCKS.get(StoneVariant.COBBLE) : this);
6162
}
6263

63-
public enum StoneType implements IStringSerializable {
64+
public enum StoneType implements IStringSerializable, IStateSpawnControl {
6465

6566
BLACK_GRANITE("black_granite", MapColor.BLACK),
6667
RED_GRANITE("red_granite", MapColor.RED),
6768
MARBLE("marble", MapColor.QUARTZ),
6869
BASALT("basalt", MapColor.BLACK_STAINED_HARDENED_CLAY),
69-
CONCRETE_LIGHT("concrete_light", MapColor.STONE),
70-
CONCRETE_DARK("concrete_dark", MapColor.STONE);
70+
CONCRETE_LIGHT("concrete_light", MapColor.STONE, false),
71+
CONCRETE_DARK("concrete_dark", MapColor.STONE, false);
7172

7273
private final String name;
74+
private final boolean allowSpawn;
7375
public final MapColor mapColor;
7476

7577
StoneType(@NotNull String name, @NotNull MapColor mapColor) {
78+
this(name, mapColor, true);
79+
}
80+
81+
StoneType(@NotNull String name, @NotNull MapColor mapColor, boolean allowSpawn) {
7682
this.name = name;
7783
this.mapColor = mapColor;
84+
this.allowSpawn = allowSpawn;
7885
}
7986

8087
@NotNull
@@ -99,6 +106,11 @@ public Material getMaterial() {
99106
case CONCRETE_LIGHT, CONCRETE_DARK -> Materials.Concrete;
100107
};
101108
}
109+
110+
@Override
111+
public boolean canCreatureSpawn(@NotNull IBlockState state) {
112+
return this.allowSpawn;
113+
}
102114
}
103115

104116
public enum StoneVariant {

0 commit comments

Comments
 (0)