Skip to content

Commit

Permalink
Merge pull request #126 from paulevsGitch/1.18.2
Browse files Browse the repository at this point in the history
1.18.2
  • Loading branch information
paulevsGitch authored Apr 8, 2022
2 parents 1fd01a5 + ea999a9 commit ff7eda1
Show file tree
Hide file tree
Showing 97 changed files with 1,282 additions and 1,133 deletions.
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ loom_version=0.10-SNAPSHOT

# Fabric Properties
# check these on https://fabricmc.net/versions.html
minecraft_version= 1.18.1
loader_version= 0.12.12
fabric_version = 0.46.2+1.18
minecraft_version= 1.18.2
loader_version= 0.13.3
fabric_version = 0.48.0+1.18.2

# Mod Properties
mod_version = 1.3.5
mod_version = 1.4.2
maven_group = ru.bclib
archives_base_name = bclib

# Dependencies
patchouli_version = 50-FABRIC
modmenu_version=3.0.1
modmenu_version=3.1.0
2 changes: 2 additions & 0 deletions src/main/java/ru/bclib/BCLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import ru.bclib.api.dataexchange.handler.autosync.SendFiles;
import ru.bclib.api.tag.TagAPI;
import ru.bclib.config.Configs;
import ru.bclib.recipes.AnvilRecipe;
import ru.bclib.recipes.CraftingRecipes;
import ru.bclib.registry.BaseBlockEntities;
import ru.bclib.registry.BaseRegistry;
Expand All @@ -38,6 +39,7 @@ public void onInitialize() {
CraftingRecipes.init();
WorldDataAPI.registerModCache(MOD_ID);
DataExchangeAPI.registerMod(MOD_ID);
AnvilRecipe.register();

DataExchangeAPI.registerDescriptors(List.of(
HelloClient.DESCRIPTOR,
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/ru/bclib/api/LifeCycleAPI.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ru.bclib.api;

import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.MinecraftServer;
Expand Down Expand Up @@ -49,7 +50,7 @@ void onLoad(
LevelStorageSource.LevelStorageAccess levelStorageAccess,
ServerLevelData serverLevelData,
ResourceKey<Level> resourceKey,
DimensionType dimensionType,
Holder<DimensionType> dimensionType,
ChunkProgressListener chunkProgressListener,
ChunkGenerator chunkGenerator,
boolean bl,
Expand Down Expand Up @@ -114,7 +115,7 @@ public static void _runLevelLoad(ServerLevel world,
LevelStorageSource.LevelStorageAccess levelStorageAccess,
ServerLevelData serverLevelData,
ResourceKey<Level> resourceKey,
DimensionType dimensionType,
Holder<DimensionType> dimensionType,
ChunkProgressListener chunkProgressListener,
ChunkGenerator chunkGenerator,
boolean bl,
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/ru/bclib/api/PostInitAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.world.level.block.Block;
import ru.bclib.BCLib;
import ru.bclib.api.biomes.BiomeAPI;
import ru.bclib.api.tag.NamedMineableTags;
import ru.bclib.api.tag.TagAPI;
import ru.bclib.api.tag.TagAPI.TagLocation;
import ru.bclib.blocks.BaseBarrelBlock;
Expand All @@ -23,6 +24,7 @@
import ru.bclib.interfaces.PostInitable;
import ru.bclib.interfaces.RenderLayerProvider;
import ru.bclib.interfaces.TagProvider;
import ru.bclib.interfaces.tools.*;
import ru.bclib.registry.BaseBlockEntities;

import java.util.List;
Expand Down Expand Up @@ -111,6 +113,29 @@ else if (block instanceof BaseBarrelBlock) {
else if (block instanceof BaseFurnaceBlock) {
BaseBlockEntities.FURNACE.registerBlock(block);
}
if (!(block instanceof PreventMineableAdd)) {
if (block instanceof AddMineableShears) {
TagAPI.addBlockTags(block, NamedMineableTags.SHEARS);
}
if (block instanceof AddMineableAxe) {
TagAPI.addBlockTags(block, NamedMineableTags.AXE);
}
if (block instanceof AddMineablePickaxe) {
TagAPI.addBlockTags(block, NamedMineableTags.PICKAXE);
}
if (block instanceof AddMineableShovel) {
TagAPI.addBlockTags(block, NamedMineableTags.SHOVEL);
}
if (block instanceof AddMineableHoe) {
TagAPI.addBlockTags(block, NamedMineableTags.HOE);
}
if (block instanceof AddMineableSword) {
TagAPI.addBlockTags(block, NamedMineableTags.SWORD);
}
if (block instanceof AddMineableHammer) {
TagAPI.addBlockTags(block, NamedMineableTags.HAMMER);
}
}
if (block instanceof TagProvider) {
TagProvider.class.cast(block).addTags(blockTags, itemTags);
blockTags.forEach(tag -> TagAPI.addBlockTag(tag, block));
Expand Down
101 changes: 51 additions & 50 deletions src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
package ru.bclib.api.biomes;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderSet;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.data.BuiltinRegistries;
import net.minecraft.data.worldgen.BiomeDefaultFeatures;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.Music;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.tags.TagKey;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.level.biome.AmbientAdditionsSettings;
import net.minecraft.world.level.biome.AmbientMoodSettings;
import net.minecraft.world.level.biome.AmbientParticleSettings;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.*;
import net.minecraft.world.level.biome.Biome.BiomeBuilder;
import net.minecraft.world.level.biome.Biome.BiomeCategory;
import net.minecraft.world.level.biome.Biome.Precipitation;
import net.minecraft.world.level.biome.BiomeGenerationSettings;
import net.minecraft.world.level.biome.BiomeSpecialEffects;
import net.minecraft.world.level.biome.MobSpawnSettings;
import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
Expand All @@ -28,25 +27,24 @@
import net.minecraft.world.level.levelgen.Noises;
import net.minecraft.world.level.levelgen.SurfaceRules;
import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver;
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
import ru.bclib.api.surface.SurfaceRuleBuilder;
import ru.bclib.entity.BCLEntityWrapper;
import ru.bclib.mixin.common.BiomeGenerationSettingsAccessor;
import ru.bclib.util.CollectionsUtil;
import ru.bclib.util.ColorUtil;
import ru.bclib.util.Pair;
import ru.bclib.util.TriFunction;
import ru.bclib.world.biomes.BCLBiome;
import ru.bclib.world.biomes.BCLBiomeSettings;
import ru.bclib.world.features.BCLFeature;
import ru.bclib.world.structures.BCLStructureFeature;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.stream.Collectors;

public class BCLBiomeBuilder {
Expand All @@ -57,7 +55,8 @@ public interface BiomeSupplier<T> extends TriFunction<ResourceLocation, Biome, B
private static final BCLBiomeBuilder INSTANCE = new BCLBiomeBuilder();
private static final SurfaceRules.ConditionSource SURFACE_NOISE = SurfaceRules.noiseCondition(Noises.SOUL_SAND_LAYER, -0.012);

private List<ConfiguredStructureFeature> structures = new ArrayList<>(16);
private List<TagKey<Biome>> structureTags = new ArrayList<>(8);
private List<Pair<GenerationStep.Carving, Holder<? extends ConfiguredWorldCarver<?>>>> carvers = new ArrayList<>(1);
private BiomeGenerationSettings.Builder generationSettings;
private BiomeSpecialEffects.Builder effectsBuilder;
private MobSpawnSettings.Builder spawnSettings;
Expand Down Expand Up @@ -87,7 +86,7 @@ public static BCLBiomeBuilder start(ResourceLocation biomeID) {
INSTANCE.generationSettings = null;
INSTANCE.effectsBuilder = null;
INSTANCE.spawnSettings = null;
INSTANCE.structures.clear();
INSTANCE.structureTags.clear();
INSTANCE.temperature = 1.0F;
INSTANCE.fogDensity = 1.0F;
INSTANCE.edgeSize = 0;
Expand All @@ -96,6 +95,7 @@ public static BCLBiomeBuilder start(ResourceLocation biomeID) {
INSTANCE.height = 0.1F;
INSTANCE.vertical = false;
INSTANCE.edge = null;
INSTANCE.carvers.clear();
return INSTANCE;
}

Expand Down Expand Up @@ -500,7 +500,7 @@ public BCLBiomeBuilder additions(SoundEvent additions) {
* @param feature {@link PlacedFeature}.
* @return same {@link BCLBiomeBuilder} instance.
*/
public BCLBiomeBuilder feature(Decoration decoration, PlacedFeature feature) {
public BCLBiomeBuilder feature(Decoration decoration, Holder<PlacedFeature> feature) {
getGeneration().addFeature(decoration, feature);
return this;
}
Expand Down Expand Up @@ -542,11 +542,11 @@ public BCLBiomeBuilder feature(BCLFeature feature) {

/**
* Adds new structure feature into the biome.
* @param structure {@link ConfiguredStructureFeature} to add.
* @param structureTag {@link TagKey} to add.
* @return same {@link BCLBiomeBuilder} instance.
*/
public BCLBiomeBuilder structure(ConfiguredStructureFeature<?, ?> structure) {
structures.add(structure);
public BCLBiomeBuilder structure(TagKey<Biome> structureTag) {
structureTags.add(structureTag);
return this;
}

Expand All @@ -557,19 +557,21 @@ public BCLBiomeBuilder structure(ConfiguredStructureFeature<?, ?> structure) {
*/
public BCLBiomeBuilder structure(BCLStructureFeature structure) {
structure.addInternalBiome(biomeID);
return structure(structure.getFeatureConfigured());
return structure(structure.biomeTag);
}

/**
* Adds new world carver into the biome.
* @param carver {@link ConfiguredWorldCarver} to add.
* @return same {@link BCLBiomeBuilder} instance.
*/
public BCLBiomeBuilder carver(GenerationStep.Carving step, ConfiguredWorldCarver<?> carver) {
public BCLBiomeBuilder carver(GenerationStep.Carving step, Holder<? extends ConfiguredWorldCarver<?>> carver) {
final ResourceLocation immutableID = biomeID;
BuiltinRegistries.CONFIGURED_CARVER
.getResourceKey(carver)
.ifPresent(key -> BiomeModifications.addCarver(ctx -> ctx.getBiomeKey().location().equals(immutableID), step, key));
var oKey = carver.unwrapKey();
if (oKey.isPresent()) {
BiomeModifications.addCarver(ctx -> ctx.getBiomeKey().location().equals(immutableID), step, (ResourceKey<ConfiguredWorldCarver<?>>) oKey.get());
}
//carvers.add(new Pair<>(step, carver));
return this;
}

Expand Down Expand Up @@ -625,8 +627,8 @@ public BCLBiomeBuilder terrainHeight(float height) {
this.height = height;
return this;
}



/**
* Make this a vertical Biome
Expand All @@ -645,7 +647,7 @@ public BCLBiomeBuilder vertical() {
public BCLBiome build() {
return build((BiomeSupplier<BCLBiome>)BCLBiome::new);
}

/**
* Finalize biome creation.
* @param biomeConstructor {@link BiFunction} biome constructor.
Expand All @@ -655,7 +657,22 @@ public BCLBiome build() {
public <T extends BCLBiome> T build(BiFunction<ResourceLocation, Biome, T> biomeConstructor) {
return build((id, biome, settings)->biomeConstructor.apply(id, biome));
}


private static BiomeGenerationSettings fixGenerationSettings(BiomeGenerationSettings settings){
//Fabric Biome Modification API can not handle an empty carver map, thus we will create one with
//an empty HolderSet for every possible step:
//https://github.com/FabricMC/fabric/issues/2079
//TODO: Remove, once fabric gets fixed
if (settings instanceof BiomeGenerationSettingsAccessor acc){
Map<GenerationStep.Carving, HolderSet<ConfiguredWorldCarver<?>>> carvers = CollectionsUtil.getMutable(acc.bclib_getCarvers());
for (GenerationStep.Carving step : GenerationStep.Carving.values()){
carvers.computeIfAbsent(step, __->HolderSet.direct(Lists.newArrayList()));
}
acc.bclib_setCarvers(carvers);
}
return settings;
}

/**
* Finalize biome creation.
* @param biomeConstructor {@link BiomeSupplier} biome constructor.
Expand All @@ -670,26 +687,8 @@ public <T extends BCLBiome> T build(BiomeSupplier<T> biomeConstructor) {

builder.mobSpawnSettings(getSpawns().build());
builder.specialEffects(getEffects().build());

Map<Decoration, List<Supplier<PlacedFeature>>> defferedFeatures = new HashMap<>();
BiomeGenerationSettingsAccessor acc = BiomeGenerationSettingsAccessor.class.cast(getGeneration().build());
if (acc != null) {
builder.generationSettings(new BiomeGenerationSettings.Builder().build());
var decorations = acc.bclib_getFeatures();
for (Decoration d : Decoration.values()) {
int i = d.ordinal();
if (i >= 0 && i < decorations.size()) {
var features = decorations.get(i);
defferedFeatures.put(d, features.stream().collect(Collectors.toList()));
}
else {
defferedFeatures.put(d, new ArrayList<>(0));
}
}
}
else {
builder.generationSettings(getGeneration().build());
}

builder.generationSettings(fixGenerationSettings(getGeneration().build()));

BCLBiomeSettings settings = BCLBiomeSettings.createBCL()
.setTerrainHeight(height)
Expand All @@ -699,11 +698,13 @@ public <T extends BCLBiome> T build(BiomeSupplier<T> biomeConstructor) {
.setEdge(edge)
.setVertical(vertical)
.build();

final T res = biomeConstructor.apply(biomeID, builder.build(), settings);
res.attachStructures(structures);

final Biome biome = builder.build();
final T res = biomeConstructor.apply(biomeID, biome, settings);
res.attachStructures(structureTags);
res.setSurface(surfaceRule);
res.setFeatures(defferedFeatures);

//carvers.forEach(cfg -> BiomeAPI.addBiomeCarver(biome, cfg.second, cfg.first));
return res;
}

Expand Down
Loading

0 comments on commit ff7eda1

Please sign in to comment.