Skip to content

Commit

Permalink
Adjusted backported changes to 1.18.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Majrusz committed May 28, 2023
1 parent 62a075d commit be59ade
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 24 deletions.
16 changes: 16 additions & 0 deletions src/main/java/com/majruszsdifficulty/Registries.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.majruszsdifficulty.triggers.GameStageTrigger;
import com.majruszsdifficulty.triggers.TreasureBagTrigger;
import com.majruszsdifficulty.undeadarmy.UndeadArmyManager;
import com.majruszsdifficulty.world.WorldGenHelper;
import com.mlib.Utility;
import com.mlib.annotations.AnnotationHandler;
import com.mlib.items.CreativeModeTabHelper;
Expand All @@ -23,6 +24,7 @@
import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.client.model.geom.ModelLayerLocation;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.core.Registry;
import net.minecraft.core.particles.ParticleType;
import net.minecraft.core.particles.SimpleParticleType;
import net.minecraft.resources.ResourceLocation;
Expand All @@ -47,6 +49,8 @@
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
import net.minecraft.world.level.storage.loot.functions.LootItemFunctionType;
import net.minecraftforge.common.ForgeSpawnEggItem;
import net.minecraftforge.common.MinecraftForge;
Expand Down Expand Up @@ -92,6 +96,8 @@ public class Registries {
static final DeferredRegister< SoundEvent > SOUNDS_EVENTS = HELPER.create( ForgeRegistries.Keys.SOUND_EVENTS );
static final DeferredRegister< LootItemFunctionType > LOOT_FUNCTIONS = HELPER.create( LOOT_FUNCTION_REGISTRY );
static final DeferredRegister< Potion > POTIONS = HELPER.create( ForgeRegistries.Keys.POTIONS );
static final DeferredRegister< PlacedFeature > PLACED_FEATURES = HELPER.create( Registry.PLACED_FEATURE_REGISTRY );
static final DeferredRegister< ConfiguredFeature< ?, ? > > CONFIGURED_FEATURES = HELPER.create( Registry.CONFIGURED_FEATURE_REGISTRY );

// Entities
public static final RegistryObject< EntityType< CreeperlingEntity > > CREEPERLING = ENTITY_TYPES.register( "creeperling", CreeperlingEntity.createSupplier() );
Expand Down Expand Up @@ -205,6 +211,16 @@ static RegistryObject< SoundEvent > register( String name ) {
// Game Modifiers
public static final AnnotationHandler ANNOTATION_HANDLER = new AnnotationHandler( MajruszsDifficulty.MOD_ID );

// Configured Feature
public static final RegistryObject< ConfiguredFeature< ?, ? > > ENDERIUM_ORE_SMALL_CONFIGURED = CONFIGURED_FEATURES.register( "enderium_ore_small", ()->WorldGenHelper.getEndConfigured( ENDERIUM_SHARD_ORE, 2, 0.99f ) );
public static final RegistryObject< ConfiguredFeature< ?, ? > > ENDERIUM_ORE_LARGE_CONFIGURED = CONFIGURED_FEATURES.register( "enderium_ore_large", ()->WorldGenHelper.getEndConfigured( ENDERIUM_SHARD_ORE, 3, 0.99f ) );
public static final RegistryObject< ConfiguredFeature< ?, ? > > INFESTED_END_STONE_CONFIGURED = CONFIGURED_FEATURES.register( "infested_end_stone", ()->WorldGenHelper.getEndConfigured( INFESTED_END_STONE, 4, 0.0f ) );

// Placed Feature
public static final RegistryObject< PlacedFeature > ENDERIUM_ORE_SMALL_PLACED = PLACED_FEATURES.register( "enderium_ore_small_placed", ()->WorldGenHelper.getEndPlaced( ENDERIUM_ORE_SMALL_CONFIGURED, 16 ) );
public static final RegistryObject< PlacedFeature > ENDERIUM_ORE_LARGE_PLACED = PLACED_FEATURES.register( "enderium_ore_large_placed", ()->WorldGenHelper.getEndPlaced( ENDERIUM_ORE_LARGE_CONFIGURED, 8 ) );
public static final RegistryObject< PlacedFeature > INFESTED_END_STONE_PLACED = PLACED_FEATURES.register( "infested_end_stone_placed", ()->WorldGenHelper.getEndPlaced( INFESTED_END_STONE_CONFIGURED, 128 ) );

public static UndeadArmyManager getUndeadArmyManager() {
return GAME_DATA_SAVER != null ? GAME_DATA_SAVER.getUndeadArmyManager() : UndeadArmyManager.NOT_LOADED;
}
Expand Down
89 changes: 89 additions & 0 deletions src/main/java/com/majruszsdifficulty/world/BiomeLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.majruszsdifficulty.world;

import com.majruszsdifficulty.Registries;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.MobSpawnSettings;
import net.minecraft.world.level.levelgen.GenerationStep;
import net.minecraftforge.common.world.BiomeGenerationSettingsBuilder;
import net.minecraftforge.common.world.MobSpawnSettingsBuilder;
import net.minecraftforge.event.world.BiomeLoadingEvent;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber
public class BiomeLoader {
@SubscribeEvent( priority = EventPriority.HIGH )
public static void onLoad( BiomeLoadingEvent event ) {
Biome.BiomeCategory category = event.getCategory();
MobSpawnSettingsBuilder spawnInfoBuilder = event.getSpawns();
BiomeGenerationSettingsBuilder generationSettingsBuilder = event.getGeneration();

if( doBiomeCategoryBelongsToOverworld( category ) ) {
addOverworldEntities( spawnInfoBuilder );
addOverworldStructures( generationSettingsBuilder );
} else if( doBiomeCategoryBelongsToNether( category ) ) {
addNetherEntities( spawnInfoBuilder );
} else if( doBiomeCategoryBelongsToTheEnd( category ) ) {
addEndEntities( spawnInfoBuilder );
addEndStructures( generationSettingsBuilder );
addEndOres( generationSettingsBuilder );
}
}

static void addOverworldEntities( MobSpawnSettingsBuilder spawnInfoBuilder ) {
addFreshEntity( spawnInfoBuilder, MobCategory.MONSTER, EntityType.ILLUSIONER, 20, 1, 2 );
addFreshEntity( spawnInfoBuilder, MobCategory.MONSTER, Registries.TANK.get(), 3, 1, 1 );
}

static void addOverworldStructures( BiomeGenerationSettingsBuilder generationSettingsBuilder ) {}

static void addNetherEntities( MobSpawnSettingsBuilder spawnInfoBuilder ) {}

protected static void addEndEntities( MobSpawnSettingsBuilder spawnInfoBuilder ) {}

protected static void addEndStructures( BiomeGenerationSettingsBuilder generationSettingsBuilder ) {}

protected static void addEndOres( BiomeGenerationSettingsBuilder generationSettingsBuilder ) {
generationSettingsBuilder.addFeature( GenerationStep.Decoration.UNDERGROUND_ORES, Registries.INFESTED_END_STONE_PLACED.getHolder().get() );
generationSettingsBuilder.addFeature( GenerationStep.Decoration.UNDERGROUND_ORES, Registries.ENDERIUM_ORE_SMALL_PLACED.getHolder().get() );
generationSettingsBuilder.addFeature( GenerationStep.Decoration.UNDERGROUND_ORES, Registries.ENDERIUM_ORE_LARGE_PLACED.getHolder().get() );
}

protected static boolean doBiomeCategoryBelongsToOverworld( Biome.BiomeCategory category ) {
boolean isTaiga = category == Biome.BiomeCategory.TAIGA;
boolean isExtremeHills = category == Biome.BiomeCategory.EXTREME_HILLS;
boolean isJungle = category == Biome.BiomeCategory.JUNGLE;
boolean isMesa = category == Biome.BiomeCategory.MESA;
boolean isPlains = category == Biome.BiomeCategory.PLAINS;
boolean isSavanna = category == Biome.BiomeCategory.SAVANNA;
boolean isIcy = category == Biome.BiomeCategory.ICY;
boolean isBeach = category == Biome.BiomeCategory.BEACH;
boolean isForest = category == Biome.BiomeCategory.FOREST;
boolean isOcean = category == Biome.BiomeCategory.OCEAN;
boolean isDesert = category == Biome.BiomeCategory.DESERT;
boolean isRiver = category == Biome.BiomeCategory.RIVER;
boolean isSwamp = category == Biome.BiomeCategory.SWAMP;
boolean isMushroom = category == Biome.BiomeCategory.MUSHROOM;

return isTaiga || isExtremeHills || isJungle || isMesa || isPlains || isSavanna || isIcy || isBeach || isForest || isOcean || isDesert || isRiver || isSwamp || isMushroom;
}

protected static boolean doBiomeCategoryBelongsToNether( Biome.BiomeCategory category ) {
return category == Biome.BiomeCategory.NETHER;
}

protected static boolean doBiomeCategoryBelongsToTheEnd( Biome.BiomeCategory category ) {
return category == Biome.BiomeCategory.THEEND;
}

private static void addFreshEntity( MobSpawnSettingsBuilder spawnInfoBuilder, MobCategory classification, EntityType< ? > entityType, int weight,
int minimumCount, int maximumCount
) {
MobSpawnSettings.SpawnerData spawners = new MobSpawnSettings.SpawnerData( entityType, weight, minimumCount, maximumCount );

spawnInfoBuilder.addSpawn( classification, spawners );
}
}
36 changes: 36 additions & 0 deletions src/main/java/com/majruszsdifficulty/world/WorldGenHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.majruszsdifficulty.world;

import net.minecraft.core.Holder;
import net.minecraft.data.worldgen.placement.PlacementUtils;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.configurations.OreConfiguration;
import net.minecraft.world.level.levelgen.placement.BiomeFilter;
import net.minecraft.world.level.levelgen.placement.CountPlacement;
import net.minecraft.world.level.levelgen.placement.InSquarePlacement;
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
import net.minecraft.world.level.levelgen.structure.templatesystem.BlockMatchTest;
import net.minecraftforge.registries.RegistryObject;

import java.util.List;

public class WorldGenHelper {
public static ConfiguredFeature< ?, ? > getConfigured( Block targetBlock, RegistryObject< ? extends Block > block, int count,
float airExposureDiscardChance
) {
List< OreConfiguration.TargetBlockState > target = List.of( OreConfiguration.target( new BlockMatchTest( targetBlock ), block.get()
.defaultBlockState() ) );
return new ConfiguredFeature<>( Feature.ORE, new OreConfiguration( target, count, airExposureDiscardChance ) );
}

public static ConfiguredFeature< ?, ? > getEndConfigured( RegistryObject< ? extends Block > block, int count, float airExposureDiscardChance ) {
return getConfigured( Blocks.END_STONE, block, count, airExposureDiscardChance );
}

public static PlacedFeature getEndPlaced( RegistryObject< ConfiguredFeature< ?, ? > > configuredFeature, int count ) {
Holder< ConfiguredFeature< ?, ? > > holder = configuredFeature.getHolder().get();
return new PlacedFeature( holder, List.of( CountPlacement.of( count ), InSquarePlacement.spread(), PlacementUtils.FULL_RANGE, BiomeFilter.biome() ) );
}
}

This file was deleted.

This file was deleted.

0 comments on commit be59ade

Please sign in to comment.