Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/main/java/gregtech/api/block/IStateSpawnControl.java
Original file line number Diff line number Diff line change
@@ -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);
}
11 changes: 11 additions & 0 deletions src/main/java/gregtech/api/block/VariantBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 <T, R> Class<T> getActualTypeParameter(Class<? extends R> thisClass, Class<R> declaringClass) {
Expand Down
25 changes: 16 additions & 9 deletions src/main/java/gregtech/common/blocks/StoneVariantBlock.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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 {
Expand Down
Loading