Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid/catch problems setting up a StructureBlockRegistry #592

Merged
merged 3 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"minestuck:heat"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"minestuck:heat"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ protected void addTags(HolderLookup.Provider provider)
this.tag(ROCK).add(LandTypes.ROCK.get(), LandTypes.PETRIFICATION.get());
this.tag(SAND).add(LandTypes.SAND.get(), LandTypes.RED_SAND.get(), LandTypes.LUSH_DESERTS.get());
this.tag(SANDSTONE).add(LandTypes.SANDSTONE.get(), LandTypes.RED_SANDSTONE.get());
this.tag(IS_DANGEROUS).add(LandTypes.HEAT.get());
this.tag(IS_FLUID_IMPORTANT).add(LandTypes.HEAT.get());
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/mraof/minestuck/util/MSTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ public static class TerrainLandTypes
public static final TagKey<TerrainLandType> ROCK = tag("rock");
public static final TagKey<TerrainLandType> SAND = tag("sand");
public static final TagKey<TerrainLandType> SANDSTONE = tag("sandstone");
public static final TagKey<TerrainLandType> IS_DANGEROUS = tag("is_dangerous");
public static final TagKey<TerrainLandType> IS_FLUID_IMPORTANT = tag("is_fluid_important");

private static TagKey<TerrainLandType> tag(String name)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ public final class LandGenSettings
{
this.landTypes = landTypes;

blockRegistry = new StructureBlockRegistry();
landTypes.getTerrain().registerBlocks(blockRegistry);
landTypes.getTitle().registerBlocks(blockRegistry);
blockRegistry = StructureBlockRegistry.init(landTypes);

landTypes.getTerrain().setGenSettings(this);
landTypes.getTitle().setGenSettings(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mraof.minestuck.block.MSBlocks;
import com.mraof.minestuck.world.gen.LandChunkGenerator;
import com.mraof.minestuck.world.lands.LandTypePair;
import net.minecraft.core.Direction;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.level.block.Block;
Expand All @@ -16,13 +17,16 @@
import net.minecraft.world.level.levelgen.structure.templatesystem.BlockStateMatchTest;
import net.minecraft.world.level.levelgen.structure.templatesystem.RuleTest;
import net.minecraft.world.level.levelgen.structure.templatesystem.TagMatchTest;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;

public final class StructureBlockRegistry
{
private static final Logger LOGGER = LogManager.getLogger();

private static final Map<String, BlockEntry> staticRegistry = new HashMap<>();
private static final Map<Block, String> templateBlockMap = new HashMap<>();
Expand Down Expand Up @@ -130,6 +134,21 @@ public static StructureBlockRegistry getOrDefault(ChunkGenerator generator)
else return defaultRegistry;
}

public static StructureBlockRegistry init(LandTypePair landTypes)
{
try
{
StructureBlockRegistry blockRegistry = new StructureBlockRegistry();
landTypes.getTerrain().registerBlocks(blockRegistry);
landTypes.getTitle().registerBlocks(blockRegistry);
return blockRegistry;
} catch(RuntimeException e)
{
LOGGER.error("Caught exception while setting up StructureBlockRegistry.", e);
return defaultRegistry;
}
}

private static class BlockEntry
{
//TODO define restriction with a set of block state properties instead of base class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mraof.minestuck.entity.MSEntityTypes;
import com.mraof.minestuck.util.MSSoundEvents;
import com.mraof.minestuck.util.MSTags;
import com.mraof.minestuck.world.biome.LandBiomeSetType;
import com.mraof.minestuck.world.biome.LandBiomeType;
import com.mraof.minestuck.world.gen.feature.MSPlacedFeatures;
Expand All @@ -13,7 +14,6 @@
import net.minecraft.world.level.biome.MobSpawnSettings;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.levelgen.GenerationStep;
import net.minecraft.world.level.material.Fluids;

public class FrogsLandType extends TitleLandType
{
Expand Down Expand Up @@ -61,9 +61,7 @@ public void addBiomeGeneration(LandBiomeGenBuilder builder, StructureBlockRegist
@Override
public boolean isAspectCompatible(TerrainLandType otherType)
{
StructureBlockRegistry registry = new StructureBlockRegistry();
otherType.registerBlocks(registry);
return !registry.getBlockState("ocean").getFluidState().is(Fluids.LAVA);
return !otherType.is(MSTags.TerrainLandTypes.IS_DANGEROUS);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mraof.minestuck.block.MSBlocks;
import com.mraof.minestuck.util.MSSoundEvents;
import com.mraof.minestuck.util.MSTags;
import com.mraof.minestuck.world.biome.LandBiomeSetType;
import com.mraof.minestuck.world.biome.LandBiomeType;
import com.mraof.minestuck.world.gen.LandGenSettings;
Expand All @@ -15,7 +16,6 @@
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.levelgen.GenerationStep;
import net.minecraft.world.level.levelgen.blockpredicates.BlockPredicate;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.phys.Vec3;

public class PulseLandType extends TitleLandType
Expand Down Expand Up @@ -66,9 +66,7 @@ public void addBiomeGeneration(LandBiomeGenBuilder builder, StructureBlockRegist
@Override
public boolean isAspectCompatible(TerrainLandType otherType)
{
StructureBlockRegistry registry = new StructureBlockRegistry();
otherType.registerBlocks(registry);
return !registry.getBlockState("ocean").getFluidState().is(Fluids.LAVA); //Lava is likely a too important part of the terrain aspect to be replaced
return !otherType.is(MSTags.TerrainLandTypes.IS_FLUID_IMPORTANT);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mraof.minestuck.world.lands.title;

import com.mraof.minestuck.util.MSSoundEvents;
import com.mraof.minestuck.util.MSTags;
import com.mraof.minestuck.world.biome.LandBiomeSetType;
import com.mraof.minestuck.world.biome.LandBiomeType;
import com.mraof.minestuck.world.gen.feature.MSPlacedFeatures;
Expand All @@ -10,7 +11,6 @@
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.levelgen.GenerationStep;
import net.minecraft.world.level.material.Fluids;

public class RabbitsLandType extends TitleLandType
{
Expand Down Expand Up @@ -44,9 +44,7 @@ public void addBiomeGeneration(LandBiomeGenBuilder builder, StructureBlockRegist
@Override
public boolean isAspectCompatible(TerrainLandType otherType)
{
StructureBlockRegistry registry = new StructureBlockRegistry();
otherType.registerBlocks(registry);
return !registry.getBlockState("ocean").getFluidState().is(Fluids.LAVA);
return !otherType.is(MSTags.TerrainLandTypes.IS_DANGEROUS);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mraof.minestuck.block.MSBlocks;
import com.mraof.minestuck.util.MSSoundEvents;
import com.mraof.minestuck.util.MSTags;
import com.mraof.minestuck.world.biome.LandBiomeSetType;
import com.mraof.minestuck.world.biome.LandBiomeType;
import com.mraof.minestuck.world.gen.LandGenSettings;
Expand All @@ -13,7 +14,6 @@
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.levelgen.GenerationStep;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.phys.Vec3;

public class ThoughtLandType extends TitleLandType
Expand Down Expand Up @@ -60,9 +60,7 @@ public void addBiomeGeneration(LandBiomeGenBuilder builder, StructureBlockRegist
@Override
public boolean isAspectCompatible(TerrainLandType otherType)
{
StructureBlockRegistry registry = new StructureBlockRegistry();
otherType.registerBlocks(registry);
return !registry.getBlockState("ocean").getFluidState().is(Fluids.LAVA);
return !otherType.is(MSTags.TerrainLandTypes.IS_FLUID_IMPORTANT);
}

@Override
Expand Down