diff --git a/src/main/java/gregtech/api/block/IStateSpawnControl.java b/src/main/java/gregtech/api/block/IStateSpawnControl.java new file mode 100644 index 00000000000..f1c0e8f7354 --- /dev/null +++ b/src/main/java/gregtech/api/block/IStateSpawnControl.java @@ -0,0 +1,14 @@ +package gregtech.api.block; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.EntityLiving; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IBlockAccess; + +import org.jetbrains.annotations.NotNull; + +public interface IStateSpawnControl { + + boolean canCreatureSpawn(@NotNull IBlockState state, @NotNull IBlockAccess world, @NotNull BlockPos pos, + @NotNull EntityLiving.SpawnPlacementType type); +} diff --git a/src/main/java/gregtech/api/block/VariantBlock.java b/src/main/java/gregtech/api/block/VariantBlock.java index 4440d6d60b5..73edd6f052e 100644 --- a/src/main/java/gregtech/api/block/VariantBlock.java +++ b/src/main/java/gregtech/api/block/VariantBlock.java @@ -13,10 +13,12 @@ import net.minecraft.client.util.ITooltipFlag; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLiving; import net.minecraft.item.ItemStack; import net.minecraft.util.IStringSerializable; import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -125,6 +127,15 @@ public SoundType getSoundType(@NotNull IBlockState state, @NotNull World world, return super.getSoundType(state, world, pos, entity); } + @Override + public boolean canCreatureSpawn(@NotNull IBlockState state, @NotNull IBlockAccess world, @NotNull BlockPos pos, + @NotNull EntityLiving.SpawnPlacementType type) { + if (getState(state) instanceof IStateSpawnControl stateSpawnControl) { + return stateSpawnControl.canCreatureSpawn(state, world, pos, type); + } + return super.canCreatureSpawn(state, world, pos, type); + } + // magic is here @SuppressWarnings("unchecked") protected static Class getActualTypeParameter(Class thisClass, Class declaringClass) { diff --git a/src/main/java/gregtech/common/blocks/StoneVariantBlock.java b/src/main/java/gregtech/common/blocks/StoneVariantBlock.java index 72fcb6d5180..2dc1d13a527 100644 --- a/src/main/java/gregtech/common/blocks/StoneVariantBlock.java +++ b/src/main/java/gregtech/common/blocks/StoneVariantBlock.java @@ -1,5 +1,6 @@ package gregtech.common.blocks; +import gregtech.api.block.IStateSpawnControl; import gregtech.api.block.VariantBlock; import gregtech.api.items.toolitem.ToolClasses; import gregtech.api.unification.material.Material; @@ -51,12 +52,6 @@ protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, VARIANT); } - @Override - public boolean canCreatureSpawn(@NotNull IBlockState state, @NotNull IBlockAccess world, @NotNull BlockPos pos, - @NotNull EntityLiving.SpawnPlacementType type) { - return false; - } - @Override protected boolean canSilkHarvest() { return this.stoneVariant == StoneVariant.SMOOTH; @@ -69,21 +64,27 @@ public Item getItemDropped(@NotNull IBlockState state, @NotNull Random rand, int MetaBlocks.STONE_BLOCKS.get(StoneVariant.COBBLE) : this); } - public enum StoneType implements IStringSerializable { + public enum StoneType implements IStringSerializable, IStateSpawnControl { BLACK_GRANITE("black_granite", MapColor.BLACK), RED_GRANITE("red_granite", MapColor.RED), MARBLE("marble", MapColor.QUARTZ), BASALT("basalt", MapColor.BLACK_STAINED_HARDENED_CLAY), - CONCRETE_LIGHT("concrete_light", MapColor.STONE), - CONCRETE_DARK("concrete_dark", MapColor.STONE); + CONCRETE_LIGHT("concrete_light", MapColor.STONE, false), + CONCRETE_DARK("concrete_dark", MapColor.STONE, false); private final String name; + private final boolean allowSpawn; public final MapColor mapColor; StoneType(@NotNull String name, @NotNull MapColor mapColor) { + this(name, mapColor, true); + } + + StoneType(@NotNull String name, @NotNull MapColor mapColor, boolean allowSpawn) { this.name = name; this.mapColor = mapColor; + this.allowSpawn = allowSpawn; } @NotNull @@ -108,6 +109,12 @@ public Material getMaterial() { case CONCRETE_LIGHT, CONCRETE_DARK -> Materials.Concrete; }; } + + @Override + public boolean canCreatureSpawn(@NotNull IBlockState state, @NotNull IBlockAccess world, @NotNull BlockPos pos, + @NotNull EntityLiving.SpawnPlacementType type) { + return this.allowSpawn; + } } public enum StoneVariant {