From 557e69080bc1ca52befa006b48a4121f456744fa Mon Sep 17 00:00:00 2001 From: Frank Date: Mon, 7 Mar 2022 20:23:57 +0100 Subject: [PATCH 01/34] Updated loom versions for 1.18.2 --- gradle.properties | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gradle.properties b/gradle.properties index 9f36e135..ea6a1b6e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,12 +6,12 @@ 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.47.10+1.18.2 # Mod Properties -mod_version = 1.3.5 +mod_version = 1.4.0 maven_group = ru.bclib archives_base_name = bclib From 48db196c7b5c42aa8045c7a3be426b8a11700263 Mon Sep 17 00:00:00 2001 From: Frank Date: Mon, 7 Mar 2022 22:09:57 +0100 Subject: [PATCH 02/34] *WIP:* Started code migration --- .../java/ru/bclib/api/biomes/BiomeAPI.java | 232 +++++------------- src/main/java/ru/bclib/api/tag/TagAPI.java | 54 ++-- .../ru/bclib/blocks/BaseDoublePlantBlock.java | 4 +- .../java/ru/bclib/blocks/BaseOreBlock.java | 5 +- .../java/ru/bclib/blocks/BasePlantBlock.java | 4 +- .../bclib/blocks/BaseStripableLogBlock.java | 7 +- .../ru/bclib/blocks/BaseTerrainBlock.java | 8 +- .../java/ru/bclib/blocks/BaseVineBlock.java | 4 +- .../ru/bclib/blocks/StripableBarkBlock.java | 7 +- .../ru/bclib/blocks/UnderwaterPlantBlock.java | 4 +- .../ru/bclib/blocks/UpDownPlantBlock.java | 4 +- .../complexmaterials/ComplexMaterial.java | 5 +- .../ru/bclib/integration/ModIntegration.java | 13 +- .../interfaces/ChunkGeneratorAccessor.java | 8 + .../SimpleReloadableResourceManagerMixin.java | 68 ++--- .../BiomeGenerationSettingsAccessor.java | 4 +- .../mixin/common/ChunkGeneratorMixin.java | 12 +- .../mixin/common/DiggerItemAccessor.java | 21 ++ .../SimpleReloadableResourceManagerMixin.java | 52 ++-- .../common/StructureSettingsAccessor.java | 32 --- .../common/SurfaceRulesContextAccessor.java | 6 +- src/main/resources/bclib.mixins.common.json | 2 +- 22 files changed, 233 insertions(+), 323 deletions(-) create mode 100644 src/main/java/ru/bclib/interfaces/ChunkGeneratorAccessor.java create mode 100644 src/main/java/ru/bclib/mixin/common/DiggerItemAccessor.java delete mode 100644 src/main/java/ru/bclib/mixin/common/StructureSettingsAccessor.java diff --git a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java index 686cf96c..77ec7654 100644 --- a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java @@ -1,19 +1,15 @@ package ru.bclib.api.biomes; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import com.google.common.collect.Multimap; import com.google.common.collect.Sets; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.impl.biome.NetherBiomeData; import net.fabricmc.fabric.impl.biome.TheEndBiomeData; -import net.fabricmc.fabric.impl.structure.FabricStructureImpl; import net.minecraft.client.Minecraft; import net.minecraft.core.BlockPos; +import net.minecraft.core.Holder; import net.minecraft.core.Registry; import net.minecraft.data.BuiltinRegistries; import net.minecraft.resources.ResourceKey; @@ -26,11 +22,7 @@ import net.minecraft.world.entity.MobCategory; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.WorldGenLevel; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.BiomeGenerationSettings; -import net.minecraft.world.level.biome.BiomeSource; -import net.minecraft.world.level.biome.Biomes; -import net.minecraft.world.level.biome.Climate; +import net.minecraft.world.level.biome.*; import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; @@ -41,27 +33,20 @@ import net.minecraft.world.level.levelgen.GenerationStep.Carving; import net.minecraft.world.level.levelgen.GenerationStep.Decoration; import net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator; import net.minecraft.world.level.levelgen.NoiseGeneratorSettings; -import net.minecraft.world.level.levelgen.StructureSettings; import net.minecraft.world.level.levelgen.SurfaceRules; import net.minecraft.world.level.levelgen.SurfaceRules.RuleSource; import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; -import net.minecraft.world.level.levelgen.feature.StructureFeature; -import net.minecraft.world.level.levelgen.feature.configurations.StructureFeatureConfiguration; import net.minecraft.world.level.levelgen.placement.PlacedFeature; +import net.minecraft.world.level.levelgen.structure.StructureSet; import org.apache.commons.lang3.mutable.MutableInt; import org.jetbrains.annotations.Nullable; import ru.bclib.BCLib; import ru.bclib.entity.BCLEntityWrapper; -import ru.bclib.interfaces.BiomeSourceAccessor; -import ru.bclib.interfaces.NoiseGeneratorSettingsProvider; -import ru.bclib.interfaces.SurfaceMaterialProvider; -import ru.bclib.interfaces.SurfaceProvider; -import ru.bclib.interfaces.SurfaceRuleProvider; +import ru.bclib.interfaces.*; import ru.bclib.mixin.common.BiomeGenerationSettingsAccessor; import ru.bclib.mixin.common.MobSpawnSettingsAccessor; -import ru.bclib.mixin.common.StructureSettingsAccessor; import ru.bclib.util.CollectionsUtil; import ru.bclib.util.MHelper; import ru.bclib.world.biomes.BCLBiome; @@ -69,18 +54,9 @@ import ru.bclib.world.biomes.FabricBiomesData; import ru.bclib.world.biomes.VanillaBiomeSettings; import ru.bclib.world.features.BCLFeature; import ru.bclib.world.generator.BiomePicker; -import ru.bclib.world.structures.BCLStructureFeature; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; -import java.util.Objects; -import java.util.Optional; -import java.util.Random; -import java.util.Set; import java.util.function.BiConsumer; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -102,8 +78,7 @@ public class BiomeAPI { private static final Map FEATURE_ORDER = Maps.newHashMap(); private static final MutableInt FEATURE_ORDER_ID = new MutableInt(0); - - private final static Map, Multimap, ResourceKey>>, Map, StructureFeatureConfiguration>>> STRUCTURE_STARTS = new HashMap<>(); + private static final Map>> MODIFICATIONS = Maps.newHashMap(); private static final Map SURFACE_RULES = Maps.newHashMap(); private static final Set MODIFIED_SURFACE_PROVIDERS = new HashSet<>(8); @@ -161,8 +136,6 @@ public class BiomeAPI { * called from {@link ru.bclib.mixin.client.MinecraftMixin} */ public static void prepareNewLevel(){ - STRUCTURE_STARTS.clear(); - MODIFIED_SURFACE_PROVIDERS.forEach(p->p.bclib_clearBiomeSources()); MODIFIED_SURFACE_PROVIDERS.clear(); } @@ -375,6 +348,19 @@ public class BiomeAPI { } return id == null ? EMPTY_BIOME.getID() : id; } + + /** + * Get biome {@link ResourceLocation} from given {@link Biome}. + * @param biome - {@link Holder} from server world. + * @return biome {@link ResourceLocation}. + */ + public static ResourceLocation getBiomeID(Holder biome) { + var oKey = biome.unwrapKey(); + if (oKey.isPresent()){ + return oKey.get().location(); + } + return null; + } /** * Get {@link BCLBiome} from given {@link ResourceLocation}. @@ -393,6 +379,15 @@ public class BiomeAPI { public static BCLBiome getBiome(Biome biome) { return getBiome(BiomeAPI.getBiomeID(biome)); } + + /** + * Get {@link BCLBiome} from given {@link Biome}. + * @param biome - biome {@link Biome}. + * @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}. + */ + public static BCLBiome getBiome(Holder biome) { + return getBiome(BiomeAPI.getBiomeID(biome)); + } /** * Check if biome with {@link ResourceLocation} exists in API registry. @@ -491,40 +486,54 @@ public class BiomeAPI { * @param level */ public static void applyModifications(ServerLevel level) { - final BiomeSource source = level.getChunkSource().getGenerator().getBiomeSource(); - final StructureSettings settings = level.getChunkSource().getGenerator().getSettings(); - final Set biomes = source.possibleBiomes(); + NoiseGeneratorSettings noiseGeneratorSettings = null; + final ChunkGenerator chunkGenerator = level.getChunkSource().getGenerator(); + final BiomeSource source = chunkGenerator.getBiomeSource(); + final Set> biomes = source.possibleBiomes(); - NoiseGeneratorSettings generator = level + //TODO: 1.18.2 Is this stilla valid way to determine the correct noiseGeneratorSettings for the level? + + final Registry structureSetRegistry; + if (chunkGenerator instanceof ChunkGeneratorAccessor acc) { + structureSetRegistry = acc.bclib_getStructureSetsRegistry(); + } else { + structureSetRegistry = null; + } + + + noiseGeneratorSettings = level .getServer() .getWorldData() .worldGenSettings() .dimensions() .stream() .map(dim->dim.generator()) - .filter(gen->(gen instanceof NoiseGeneratorSettingsProvider) && gen.getSettings()==settings) + .filter(gen-> structureSetRegistry!=null && (gen instanceof NoiseGeneratorSettingsProvider) && (gen instanceof ChunkGeneratorAccessor) && ((ChunkGeneratorAccessor)gen).bclib_getStructureSetsRegistry()==structureSetRegistry) .map(gen->((NoiseGeneratorSettingsProvider)gen).bclib_getNoiseGeneratorSettings()) .findFirst() .orElse(null); + // Datapacks (like Amplified Nether)will change the GeneratorSettings upon load, so we will // only use the default Setting for Nether/End if we were unable to find a settings object - if (generator==null){ + if (noiseGeneratorSettings==null){ if (level.dimension() == Level.NETHER) { - generator = BuiltinRegistries.NOISE_GENERATOR_SETTINGS.get(NoiseGeneratorSettings.NETHER); + noiseGeneratorSettings = BuiltinRegistries.NOISE_GENERATOR_SETTINGS.get(NoiseGeneratorSettings.NETHER); } else if (level.dimension() == Level.END) { - generator = BuiltinRegistries.NOISE_GENERATOR_SETTINGS.get(NoiseGeneratorSettings.END); + noiseGeneratorSettings = BuiltinRegistries.NOISE_GENERATOR_SETTINGS.get(NoiseGeneratorSettings.END); } } List> modifications = MODIFICATIONS.get(level.dimension()); - for (Biome biome : biomes) { - applyModificationsAndUpdateFeatures(modifications, biome); + for (Holder biomeHolder : biomes) { + if (biomeHolder.isBound()) { + applyModificationsAndUpdateFeatures(modifications, biomeHolder.value()); + } } - if (generator != null) { - final SurfaceRuleProvider provider = SurfaceRuleProvider.class.cast(generator); + if (noiseGeneratorSettings != null) { + final SurfaceRuleProvider provider = SurfaceRuleProvider.class.cast(noiseGeneratorSettings); // Multiple Biomes can use the same generator. So we need to keep track of all Biomes that are // Provided by all the BiomeSources that use the same generator. // This happens for example when using the MiningDimensions, which reuses the generator for the @@ -535,16 +544,6 @@ public class BiomeAPI { BCLib.LOGGER.warning("No generator for " + source); } - if (settings!=null){ - final StructureSettingsAccessor settingsAccessor = (StructureSettingsAccessor)settings; - final Set biomeIDs = biomes.stream().map(BiomeAPI::getBiomeID).collect(Collectors.toSet()); - for (Entry, Multimap, ResourceKey>>, Map, StructureFeatureConfiguration>>> e : STRUCTURE_STARTS.entrySet()) { - if (biomeIDs.contains(e.getKey().biomeID)) { - applyStructureStarts(settingsAccessor, e.getValue()); - } - } - } - ((BiomeSourceAccessor) source).bclRebuildFeatures(); } @@ -581,7 +580,7 @@ public class BiomeAPI { accessor.bclib_setFeatures(featureList); } - private static List getRuleSourcesForBiomes(Set biomes) { + private static List getRuleSourcesForBiomes(Set> biomes) { Set biomeIDs = biomes .stream() .map(biome -> getBiomeID(biome)) @@ -600,7 +599,7 @@ public class BiomeAPI { * @return A list of {@link RuleSource}-Objects that are needed to create those Biomes */ public static List getRuleSources(Set sources) { - final Set biomes = new HashSet<>(); + final Set> biomes = new HashSet<>(); for (BiomeSource s : sources) { biomes.addAll(s.possibleBiomes()); } @@ -683,68 +682,6 @@ public class BiomeAPI { accessor.bclib_setFeatureSet(set); } - /** - * Adds new structure feature to existing biome. - * @param biomeKey {@link ResourceKey} for the {@link Biome} to add structure feature in. - * @param structure {@link ConfiguredStructureFeature} to add. - */ - public static void addBiomeStructure(ResourceKey biomeKey, ConfiguredStructureFeature structure) { - if (biomeKey == null){ - BCLib.LOGGER.error("null is not a valid biomeKey for " + structure); - return; - } - changeStructureStarts(biomeKey.location(), structure, (structureMap, configMap) -> { - Multimap, ResourceKey> configuredMap = structureMap.computeIfAbsent(structure.feature, k -> HashMultimap.create()); - configuredMap.put(structure, biomeKey); - - StructureFeatureConfiguration config = FabricStructureImpl.STRUCTURE_TO_CONFIG_MAP.get(structure.feature); - if (config != null){ - configMap.put(structure.feature, config); - } - }); - } - - /** - * Add an existing StructureFeature to a Biome - * @param biome The {@link Biome} you want to add teh feature to - * @param structure The {@link ConfiguredStructureFeature} to add - */ - public static void addBiomeStructure(Biome biome, ConfiguredStructureFeature structure) { - changeStructureStarts(BiomeAPI.getBiomeID(biome), structure, (structureMap, configMap) -> { - Multimap, ResourceKey> configuredMap = structureMap.computeIfAbsent(structure.feature, k -> HashMultimap.create()); - var key = getBiomeKey(biome); - if (key != null) { - StructureFeatureConfiguration config = FabricStructureImpl.STRUCTURE_TO_CONFIG_MAP.get(structure.feature); - if (config != null) { - configMap.put(structure.feature, config); - } - configuredMap.put(structure, key); - } else { - BCLib.LOGGER.warning("Unable to find Biome " + getBiomeID(biome)); - } - }); - } - - /** - * Adds new structure feature to existing biome. - * @param biomeKey {@link ResourceKey} for the {@link Biome} to add structure feature in. - * @param structure {@link BCLStructureFeature} to add. - */ - public static void addBiomeStructure(ResourceKey biomeKey, BCLStructureFeature structure) { - addBiomeStructure(biomeKey, structure.getFeatureConfigured()); - } - - /** - * Adds new structure features to existing biome. - * @param biomeKey {@link ResourceKey} for the {@link Biome} to add structure features in. - * @param structures array of {@link BCLStructureFeature} to add. - */ - public static void addBiomeStructures(ResourceKey biomeKey, BCLStructureFeature... structures) { - for (BCLStructureFeature structure: structures) { - addBiomeStructure(biomeKey, structure.getFeatureConfigured()); - } - } - /** * Adds new carver into existing biome. * @param biome {@link Biome} to add carver in. @@ -862,11 +799,11 @@ public class BiomeAPI { * Set biome in chunk at specified position. * @param chunk {@link ChunkAccess} chunk to set biome in. * @param pos {@link BlockPos} biome position. - * @param biome {@link Biome} instance. Should be biome from world. + * @param biome {@link Holder} instance. Should be biome from world. */ - public static void setBiome(ChunkAccess chunk, BlockPos pos, Biome biome) { + public static void setBiome(ChunkAccess chunk, BlockPos pos, Holder biome) { int sectionY = (pos.getY() - chunk.getMinBuildHeight()) >> 4; - PalettedContainer biomes = chunk.getSection(sectionY).getBiomes(); + PalettedContainer> biomes = chunk.getSection(sectionY).getBiomes(); biomes.set((pos.getX() & 15) >> 2, (pos.getY() & 15) >> 2, (pos.getZ() & 15) >> 2, biome); } @@ -874,9 +811,9 @@ public class BiomeAPI { * Set biome in world at specified position. * @param level {@link LevelAccessor} world to set biome in. * @param pos {@link BlockPos} biome position. - * @param biome {@link Biome} instance. Should be biome from world. + * @param biome {@link Holder} instance. Should be biome from world. */ - public static void setBiome(LevelAccessor level, BlockPos pos, Biome biome) { + public static void setBiome(LevelAccessor level, BlockPos pos, Holder biome) { ChunkAccess chunk = level.getChunk(pos); setBiome(chunk, pos, biome); } @@ -909,23 +846,6 @@ public class BiomeAPI { } } - private static void changeStructureStarts(ResourceLocation biomeID, ConfiguredStructureFeature structure, BiConsumer, Multimap, ResourceKey>>, Map, StructureFeatureConfiguration>> modifier) { - STRUCTURE_STARTS.put(new StructureID(biomeID, structure), modifier); - } - - private static void applyStructureStarts(StructureSettingsAccessor access, BiConsumer, Multimap, ResourceKey>>, Map, StructureFeatureConfiguration>> modifier) { - Map, Multimap, ResourceKey>> structureMap; - Map, StructureFeatureConfiguration> configMap; - - structureMap = getMutableConfiguredStructures(access); - configMap = getMutableStructureConfig(access); - - modifier.accept(structureMap, configMap); - - setMutableConfiguredStructures(access, structureMap); - setMutableStructureConfig(access, configMap); - } - private static void sortFeatures(List> features) { initFeatureOrder(); @@ -976,34 +896,4 @@ public class BiomeAPI { features.set(index, mutable); return mutable; } - - //inspired by net.fabricmc.fabric.impl.biome.modification.BiomeStructureStartsImpl - private static Map, Multimap, ResourceKey>> getMutableConfiguredStructures(StructureSettingsAccessor access) { - ImmutableMap, ImmutableMultimap, ResourceKey>> configuredStructures = access.bcl_getConfiguredStructures(); - Map, Multimap, ResourceKey>> result = new HashMap<>(configuredStructures.size()); - - for (Map.Entry, ImmutableMultimap, ResourceKey>> entry : configuredStructures.entrySet()) { - result.put(entry.getKey(), HashMultimap.create(entry.getValue())); - } - - return result; - } - - //inspired by net.fabricmc.fabric.impl.biome.modification.BiomeStructureStartsImpl - private static void setMutableConfiguredStructures(StructureSettingsAccessor access, Map, Multimap, ResourceKey>> structureStarts) { - access.bcl_setConfiguredStructures( - structureStarts - .entrySet() - .stream() - .collect(ImmutableMap.toImmutableMap(Map.Entry::getKey, e -> ImmutableMultimap.copyOf(e.getValue()))) - ); - } - - private static Map, StructureFeatureConfiguration> getMutableStructureConfig(StructureSettingsAccessor access) { - return CollectionsUtil.getMutable(access.bcl_getStructureConfig()); - } - - private static void setMutableStructureConfig(StructureSettingsAccessor access, Map, StructureFeatureConfiguration> structureConfig) { - access.bcl_setStructureConfig(structureConfig); - } } diff --git a/src/main/java/ru/bclib/api/tag/TagAPI.java b/src/main/java/ru/bclib/api/tag/TagAPI.java index 3c055087..126a8b7e 100644 --- a/src/main/java/ru/bclib/api/tag/TagAPI.java +++ b/src/main/java/ru/bclib/api/tag/TagAPI.java @@ -2,21 +2,20 @@ package ru.bclib.api.tag; import com.google.common.collect.Maps; import com.google.common.collect.Sets; -import net.fabricmc.fabric.api.tag.TagFactory; -import net.fabricmc.fabric.impl.tag.extension.TagDelegate; import net.minecraft.core.Registry; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.resources.ResourceManager; import net.minecraft.tags.BlockTags; import net.minecraft.tags.ItemTags; +import net.minecraft.tags.TagKey; import net.minecraft.tags.Tag; -import net.minecraft.tags.Tag.Named; -import net.minecraft.tags.TagCollection; import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; +import ru.bclib.mixin.common.DiggerItemAccessor; import java.util.List; import java.util.Map; @@ -29,44 +28,44 @@ public class TagAPI { private static final Map> TAGS_ITEM = Maps.newConcurrentMap(); /** - * Get or create {@link Tag.Named}. + * Get or create {@link TagNamed}. * * @param containerSupplier - {@link TagCollection} {@link Supplier} tag collection; * @param id - {@link ResourceLocation} tag id. - * @return {@link Tag.Named}. + * @return {@link TagNamed}. */ public static TagNamed makeTag(Supplier> containerSupplier, TagLocation id) { Tag tag = containerSupplier.get().getTag(id); - return tag == null ? new Delegate<>(id, containerSupplier) : CommonDelegate.proxy((Named) tag); + return tag == null ? new Delegate<>(id, containerSupplier) : CommonDelegate.proxy((TagKey) tag); } /** - * Get or create {@link Block} {@link Tag.Named} with mod namespace. + * Get or create {@link Block} {@link TagNamed} with mod namespace. * * @param modID - {@link String} mod namespace (mod id); * @param name - {@link String} tag name. - * @return {@link Block} {@link Tag.Named}. + * @return {@link Block} {@link TagNamed}. */ public static TagNamed makeBlockTag(String modID, String name) { return makeTag(BlockTags::getAllTags, new TagLocation<>(modID, name)); } /** - * Get or create {@link Item} {@link Tag.Named} with mod namespace. + * Get or create {@link Item} {@link TagNamed} with mod namespace. * * @param modID - {@link String} mod namespace (mod id); * @param name - {@link String} tag name. - * @return {@link Item} {@link Tag.Named}. + * @return {@link Item} {@link TagNamed}. */ public static TagNamed makeItemTag(String modID, String name) { return makeTag(ItemTags::getAllTags, new TagLocation<>(modID, name)); } /** - * Get or create {@link Block} {@link Tag.Named}. + * Get or create {@link Block} {@link TagNamed}. * * @param name - {@link String} tag name. - * @return {@link Block} {@link Tag.Named}. + * @return {@link Block} {@link TagNamed}. * @see Fabric Wiki (Tags) */ public static TagNamed makeCommonBlockTag(String name) { @@ -74,10 +73,10 @@ public class TagAPI { } /** - * Get or create {@link Item} {@link Tag.Named}. + * Get or create {@link Item} {@link TagNamed}. * * @param name - {@link String} tag name. - * @return {@link Item} {@link Tag.Named}. + * @return {@link Item} {@link TagNamed}. * @see Fabric Wiki (Tags) */ public static TagNamed makeCommonItemTag(String name) { @@ -85,16 +84,16 @@ public class TagAPI { } /** - * Get or create Minecraft {@link Block} {@link Tag.Named}. + * Get or create Minecraft {@link Block} {@link TagNamed}. * * @param name - {@link String} tag name. - * @return {@link Block} {@link Tag.Named}. + * @return {@link Block} {@link TagNamed}. */ @Deprecated(forRemoval = true) public static TagNamed getMCBlockTag(String name) { ResourceLocation id = new ResourceLocation(name); Tag tag = BlockTags.getAllTags().getTag(id); - return CommonDelegate.proxy(tag == null ? (Named) TagFactory.BLOCK.create(id): (Named) tag); + return CommonDelegate.proxy(tag == null ? (TagKey) TagFactory.BLOCK.create(id): (TagKey) tag); } /** @@ -217,11 +216,11 @@ public class TagAPI { } /** - * Extends {@link Tag.Named} to return a type safe {@link TagLocation}. This Type was introduced to + * Extends {@link TagNamed} to return a type safe {@link TagLocation}. This Type was introduced to * allow type-safe definition of Tags using their ResourceLocation. * @param The Type of the underlying {@link Tag} */ - public interface TagNamed extends Tag.Named{ + public interface TagNamed extends TagKey{ TagLocation getName(); } @@ -243,18 +242,18 @@ public class TagAPI { super(location.getNamespace(), location.getPath()); } - public static TagLocation of(Tag.Named tag){ + public static TagLocation of(TagKey tag){ return new TagLocation(tag.getName()); } } private abstract static class CommonDelegate implements TagNamed { - protected final Tag.Named delegate; - protected CommonDelegate(Tag.Named source){ + protected final TagKey delegate; + protected CommonDelegate(TagKey source){ this.delegate = source; } - public static TagNamed proxy(Tag.Named source){ + public static TagNamed proxy(TagKey source){ if (source instanceof TagNamed typed) return typed; return new ProxyDelegate<>(source); } @@ -298,4 +297,11 @@ public class TagAPI { return (TagLocation)delegate.getName(); } } + + public static boolean isToolWithMineableTag(ItemStack stack, TagLocation tag){ + if (stack.getItem() instanceof DiggerItemAccessor dig){ + return dig.bclib_getBlockTag().location().equals(tag); + } + return false; + } } diff --git a/src/main/java/ru/bclib/blocks/BaseDoublePlantBlock.java b/src/main/java/ru/bclib/blocks/BaseDoublePlantBlock.java index 7c80d49e..02ae6b35 100644 --- a/src/main/java/ru/bclib/blocks/BaseDoublePlantBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseDoublePlantBlock.java @@ -2,7 +2,6 @@ package ru.bclib.blocks; import com.google.common.collect.Lists; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.server.level.ServerLevel; @@ -45,7 +44,8 @@ public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements R public BaseDoublePlantBlock() { this( FabricBlockSettings.of(Material.PLANT) - .breakByHand(true) + //TODO: 1.18.2 make sure this works with the new tag system + //.breakByHand(true) .sound(SoundType.GRASS) .noCollission() ); diff --git a/src/main/java/ru/bclib/blocks/BaseOreBlock.java b/src/main/java/ru/bclib/blocks/BaseOreBlock.java index abe61807..8b0573bf 100644 --- a/src/main/java/ru/bclib/blocks/BaseOreBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseOreBlock.java @@ -1,8 +1,6 @@ package ru.bclib.blocks; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.fabricmc.fabric.impl.object.builder.FabricBlockInternals; import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; @@ -60,7 +58,8 @@ public class BaseOreBlock extends OreBlock implements BlockModelProvider { } private static Properties makeProps(Properties properties, int level){ - FabricBlockInternals.computeExtraData(properties).addMiningLevel(FabricToolTags.PICKAXES, level); + //TODO: 1.18.2 make sure this works with the new tag system + //FabricBlockInternals.computeExtraData(properties).addMiningLevel(FabricToolTags.PICKAXES, level); return properties; } diff --git a/src/main/java/ru/bclib/blocks/BasePlantBlock.java b/src/main/java/ru/bclib/blocks/BasePlantBlock.java index e469ccd7..eaffbcdc 100644 --- a/src/main/java/ru/bclib/blocks/BasePlantBlock.java +++ b/src/main/java/ru/bclib/blocks/BasePlantBlock.java @@ -4,7 +4,6 @@ import com.google.common.collect.Lists; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -60,7 +59,8 @@ public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderL this( FabricBlockSettings .of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT) - .breakByHand(true) + //TODO: 1.18.2 make sure this works with the new tag system + //.breakByHand(true) .sound(SoundType.GRASS) .noCollission() ); diff --git a/src/main/java/ru/bclib/blocks/BaseStripableLogBlock.java b/src/main/java/ru/bclib/blocks/BaseStripableLogBlock.java index 28127de4..84864803 100644 --- a/src/main/java/ru/bclib/blocks/BaseStripableLogBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseStripableLogBlock.java @@ -1,7 +1,6 @@ package ru.bclib.blocks; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvents; @@ -15,6 +14,8 @@ import net.minecraft.world.level.block.RotatedPillarBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.phys.BlockHitResult; +import ru.bclib.api.tag.NamedMineableTags; +import ru.bclib.api.tag.TagAPI; public class BaseStripableLogBlock extends BaseRotatedPillarBlock { private final Block striped; @@ -27,7 +28,9 @@ public class BaseStripableLogBlock extends BaseRotatedPillarBlock { @Override @SuppressWarnings("deprecation") public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { - if (FabricToolTags.AXES.contains(player.getMainHandItem().getItem())) { + //TODO: 1.18.2 check + if (TagAPI.isToolWithMineableTag(player.getMainHandItem(), NamedMineableTags.AXE)){ + //if (FabricToolTags.AXES.contains(player.getMainHandItem().getItem())) { world.playSound(player, pos, SoundEvents.AXE_STRIP, SoundSource.BLOCKS, 1.0F, 1.0F); if (!world.isClientSide) { world.setBlock(pos, diff --git a/src/main/java/ru/bclib/blocks/BaseTerrainBlock.java b/src/main/java/ru/bclib/blocks/BaseTerrainBlock.java index 96b77c0e..aa98e969 100644 --- a/src/main/java/ru/bclib/blocks/BaseTerrainBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseTerrainBlock.java @@ -3,8 +3,8 @@ package ru.bclib.blocks; import com.google.common.collect.Maps; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.client.resources.model.UnbakedModel; import net.minecraft.core.BlockPos; @@ -33,6 +33,8 @@ import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.phys.BlockHitResult; import org.jetbrains.annotations.Nullable; +import ru.bclib.api.tag.NamedMineableTags; +import ru.bclib.api.tag.TagAPI; import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.PatternsHelper; @@ -69,7 +71,9 @@ public class BaseTerrainBlock extends BaseBlock { @Override public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { - if (pathBlock != null && FabricToolTags.SHOVELS.contains(player.getMainHandItem().getItem())) { + //TODO: 1.18.2 check + if (pathBlock != null && TagAPI.isToolWithMineableTag(player.getMainHandItem(), NamedMineableTags.SHOVEL)){ + //if (pathBlock != null && FabricTagProvider.SHOVELS.contains(player.getMainHandItem().getItem())) { world.playSound(player, pos, SoundEvents.SHOVEL_FLATTEN, SoundSource.BLOCKS, 1.0F, 1.0F); if (!world.isClientSide) { world.setBlockAndUpdate(pos, pathBlock.defaultBlockState()); diff --git a/src/main/java/ru/bclib/blocks/BaseVineBlock.java b/src/main/java/ru/bclib/blocks/BaseVineBlock.java index 6e156b43..2b36688c 100644 --- a/src/main/java/ru/bclib/blocks/BaseVineBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseVineBlock.java @@ -2,7 +2,6 @@ package ru.bclib.blocks; import com.google.common.collect.Lists; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.server.level.ServerLevel; @@ -53,7 +52,8 @@ public class BaseVineBlock extends BaseBlockNotFull implements RenderLayerProvid this( FabricBlockSettings .of(Material.PLANT) - .breakByHand(true) + //TODO: 1.18.2 make sure this works with the new tag system + //.breakByHand(true) .sound(SoundType.GRASS) .lightLevel((state) -> bottomOnly ? state.getValue(SHAPE) == TripleShape.BOTTOM ? light : 0 : light) .noCollission() diff --git a/src/main/java/ru/bclib/blocks/StripableBarkBlock.java b/src/main/java/ru/bclib/blocks/StripableBarkBlock.java index 328c6f1d..9118f66b 100644 --- a/src/main/java/ru/bclib/blocks/StripableBarkBlock.java +++ b/src/main/java/ru/bclib/blocks/StripableBarkBlock.java @@ -1,7 +1,6 @@ package ru.bclib.blocks; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvents; @@ -15,6 +14,8 @@ import net.minecraft.world.level.block.RotatedPillarBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.phys.BlockHitResult; +import ru.bclib.api.tag.NamedMineableTags; +import ru.bclib.api.tag.TagAPI; public class StripableBarkBlock extends BaseBarkBlock { private final Block striped; @@ -27,7 +28,9 @@ public class StripableBarkBlock extends BaseBarkBlock { @Override @SuppressWarnings("deprecation") public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { - if (FabricToolTags.AXES.contains(player.getMainHandItem().getItem())) { + //TODO: 1.18.2 check + if (TagAPI.isToolWithMineableTag(player.getMainHandItem(), NamedMineableTags.AXE)){ + //if (FabricToolTags.AXES.contains(player.getMainHandItem().getItem())) { world.playSound(player, pos, SoundEvents.AXE_STRIP, SoundSource.BLOCKS, 1.0F, 1.0F); if (!world.isClientSide) { world.setBlock(pos, diff --git a/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java b/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java index 486b96ac..5f71bf5d 100644 --- a/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java +++ b/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java @@ -2,7 +2,6 @@ package ru.bclib.blocks; import com.google.common.collect.Lists; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.server.level.ServerLevel; @@ -47,7 +46,8 @@ public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements R this( FabricBlockSettings .of(Material.WATER_PLANT) - .breakByHand(true) + //TODO: 1.18.2 make sure this works with the new tag system + //.breakByHand(true) .sound(SoundType.WET_GRASS) .noCollission() ); diff --git a/src/main/java/ru/bclib/blocks/UpDownPlantBlock.java b/src/main/java/ru/bclib/blocks/UpDownPlantBlock.java index f58e5526..9fdfe7e6 100644 --- a/src/main/java/ru/bclib/blocks/UpDownPlantBlock.java +++ b/src/main/java/ru/bclib/blocks/UpDownPlantBlock.java @@ -2,7 +2,6 @@ package ru.bclib.blocks; import com.google.common.collect.Lists; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.entity.player.Player; @@ -39,7 +38,8 @@ public abstract class UpDownPlantBlock extends BaseBlockNotFull implements Rende public UpDownPlantBlock() { this(FabricBlockSettings .of(Material.PLANT) - .breakByHand(true) + //TODO: 1.18.2 make sure this works with the new tag system + //.breakByHand(true) .sound(SoundType.GRASS) .noCollission() ); diff --git a/src/main/java/ru/bclib/complexmaterials/ComplexMaterial.java b/src/main/java/ru/bclib/complexmaterials/ComplexMaterial.java index 022e5eaf..1684c162 100644 --- a/src/main/java/ru/bclib/complexmaterials/ComplexMaterial.java +++ b/src/main/java/ru/bclib/complexmaterials/ComplexMaterial.java @@ -7,6 +7,7 @@ import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.registry.FlammableBlockRegistry; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.Tag; +import net.minecraft.tags.TagKey; import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; import org.jetbrains.annotations.Nullable; @@ -32,8 +33,8 @@ public abstract class ComplexMaterial { private final List defaultBlockEntries = Lists.newArrayList(); private final List defaultItemEntries = Lists.newArrayList(); - private final Map> blockTags = Maps.newHashMap(); - private final Map> itemTags = Maps.newHashMap(); + private final Map> blockTags = Maps.newHashMap(); + private final Map> itemTags = Maps.newHashMap(); private final Map blocks = Maps.newHashMap(); private final Map items = Maps.newHashMap(); diff --git a/src/main/java/ru/bclib/integration/ModIntegration.java b/src/main/java/ru/bclib/integration/ModIntegration.java index e1d93576..ddfb76a6 100644 --- a/src/main/java/ru/bclib/integration/ModIntegration.java +++ b/src/main/java/ru/bclib/integration/ModIntegration.java @@ -1,6 +1,5 @@ package ru.bclib.integration; -import net.fabricmc.fabric.api.tag.TagFactory; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.core.Registry; import net.minecraft.data.BuiltinRegistries; @@ -9,7 +8,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.BlockTags; import net.minecraft.tags.ItemTags; import net.minecraft.tags.Tag; -import net.minecraft.tags.Tag.Named; +import net.minecraft.tags.TagKey; import net.minecraft.world.item.Item; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.block.Block; @@ -197,18 +196,18 @@ public abstract class ModIntegration { return null; } - public Tag.Named getItemTag(String name) { + public TagKey getItemTag(String name) { ResourceLocation id = getID(name); Tag tag = ItemTags.getAllTags().getTag(id); - //return tag == null ? (Named) TagRegistry.item(id) : (Named) tag; - return tag == null ? (Named) TagFactory.ITEM.create(id) : (Named) tag; + //return tag == null ? (TagKey) TagRegistry.item(id) : (TagKey) tag; + return tag == null ? (TagKey) TagFactory.ITEM.create(id) : (TagKey) tag; } - public Tag.Named getBlockTag(String name) { + public TagKey getBlockTag(String name) { ResourceLocation id = getID(name); Tag tag = BlockTags.getAllTags().getTag(id); //return tag == null ? (Named) TagRegistry.block(id) : (Named) tag; - return tag == null ? (Named) TagFactory.BLOCK.create(id) : (Named) tag; + return tag == null ? (TagKey) TagFactory.BLOCK.create(id) : (TagKey) tag; } } diff --git a/src/main/java/ru/bclib/interfaces/ChunkGeneratorAccessor.java b/src/main/java/ru/bclib/interfaces/ChunkGeneratorAccessor.java new file mode 100644 index 00000000..cb20ad10 --- /dev/null +++ b/src/main/java/ru/bclib/interfaces/ChunkGeneratorAccessor.java @@ -0,0 +1,8 @@ +package ru.bclib.interfaces; + +import net.minecraft.core.Registry; +import net.minecraft.world.level.levelgen.structure.StructureSet; + +public interface ChunkGeneratorAccessor { + Registry bclib_getStructureSetsRegistry(); +} diff --git a/src/main/java/ru/bclib/mixin/client/SimpleReloadableResourceManagerMixin.java b/src/main/java/ru/bclib/mixin/client/SimpleReloadableResourceManagerMixin.java index ed209646..594d71f2 100644 --- a/src/main/java/ru/bclib/mixin/client/SimpleReloadableResourceManagerMixin.java +++ b/src/main/java/ru/bclib/mixin/client/SimpleReloadableResourceManagerMixin.java @@ -4,7 +4,6 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.resources.FallbackResourceManager; import net.minecraft.server.packs.resources.Resource; import net.minecraft.server.packs.resources.ResourceManager; -import net.minecraft.server.packs.resources.SimpleReloadableResourceManager; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -18,36 +17,37 @@ import ru.bclib.client.render.EmissiveTextureInfo; import java.io.IOException; import java.util.Map; -@Mixin(SimpleReloadableResourceManager.class) -public class SimpleReloadableResourceManagerMixin { - @Final - @Shadow - private Map namespacedPacks; - - private ResourceLocation bclib_alphaEmissionMaterial = BCLib.makeID("materialmaps/block/alpha_emission.json"); - - @Inject(method = "getResource", at = @At("HEAD"), cancellable = true) - private void bclib_getResource(ResourceLocation resourceLocation, CallbackInfoReturnable info) throws IOException { - if (!ModIntegrationAPI.hasCanvas()) { - return; - } - if (!resourceLocation.getPath().startsWith("materialmaps")) { - return; - } - if (!resourceLocation.getPath().contains("/block/")) { - return; - } - - String name = resourceLocation.getPath().replace("materialmaps/block/", "").replace(".json", ""); - ResourceLocation blockID = new ResourceLocation(resourceLocation.getNamespace(), name); - - if (!EmissiveTextureInfo.isEmissiveBlock(blockID)) { - return; - } - - ResourceManager resourceManager = this.namespacedPacks.get(resourceLocation.getNamespace()); - if (resourceManager != null && !resourceManager.hasResource(resourceLocation)) { - info.setReturnValue(resourceManager.getResource(bclib_alphaEmissionMaterial)); - } - } -} +//TODO: 1.18.2 Disabled to have a compilable Version +//@Mixin(SimpleReloadableResourceManager.class) +//public class SimpleReloadableResourceManagerMixin { +// @Final +// @Shadow +// private Map namespacedPacks; +// +// private ResourceLocation bclib_alphaEmissionMaterial = BCLib.makeID("materialmaps/block/alpha_emission.json"); +// +// @Inject(method = "getResource", at = @At("HEAD"), cancellable = true) +// private void bclib_getResource(ResourceLocation resourceLocation, CallbackInfoReturnable info) throws IOException { +// if (!ModIntegrationAPI.hasCanvas()) { +// return; +// } +// if (!resourceLocation.getPath().startsWith("materialmaps")) { +// return; +// } +// if (!resourceLocation.getPath().contains("/block/")) { +// return; +// } +// +// String name = resourceLocation.getPath().replace("materialmaps/block/", "").replace(".json", ""); +// ResourceLocation blockID = new ResourceLocation(resourceLocation.getNamespace(), name); +// +// if (!EmissiveTextureInfo.isEmissiveBlock(blockID)) { +// return; +// } +// +// ResourceManager resourceManager = this.namespacedPacks.get(resourceLocation.getNamespace()); +// if (resourceManager != null && !resourceManager.hasResource(resourceLocation)) { +// info.setReturnValue(resourceManager.getResource(bclib_alphaEmissionMaterial)); +// } +// } +//} diff --git a/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java b/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java index fcb6ec6f..92e3d099 100644 --- a/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java +++ b/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java @@ -24,10 +24,10 @@ public interface BiomeGenerationSettingsAccessor { void bclib_setFeatures(List>> value); @Accessor("featureSet") - Set bclib_getFeatureSet(); + Supplier> bclib_getFeatureSet(); @Accessor("featureSet") - void bclib_setFeatureSet(Set features); + void bclib_setFeatureSet(Supplier> features); @Accessor("carvers") Map>>> bclib_getCarvers(); diff --git a/src/main/java/ru/bclib/mixin/common/ChunkGeneratorMixin.java b/src/main/java/ru/bclib/mixin/common/ChunkGeneratorMixin.java index 9c6058ac..c72d2676 100644 --- a/src/main/java/ru/bclib/mixin/common/ChunkGeneratorMixin.java +++ b/src/main/java/ru/bclib/mixin/common/ChunkGeneratorMixin.java @@ -1,17 +1,23 @@ package ru.bclib.mixin.common; +import net.minecraft.core.Registry; import net.minecraft.world.level.StructureFeatureManager; import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.chunk.ChunkAccess; import net.minecraft.world.level.chunk.ChunkGenerator; +import net.minecraft.world.level.levelgen.structure.StructureSet; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import ru.bclib.interfaces.ChunkGeneratorAccessor; @Mixin(ChunkGenerator.class) -public class ChunkGeneratorMixin { +public class ChunkGeneratorMixin implements ChunkGeneratorAccessor { + @Shadow @Final protected Registry structureSets; private int bclib_featureIteratorSeed; @ModifyArg(method = "applyBiomeDecoration", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/levelgen/WorldgenRandom;setFeatureSeed(JII)V")) @@ -23,4 +29,8 @@ public class ChunkGeneratorMixin { private void bclib_obBiomeGenerate(WorldGenLevel worldGenLevel, ChunkAccess chunkAccess, StructureFeatureManager structureFeatureManager, CallbackInfo ci) { bclib_featureIteratorSeed = 0; } + + public Registry bclib_getStructureSetsRegistry(){ + return structureSets; + } } diff --git a/src/main/java/ru/bclib/mixin/common/DiggerItemAccessor.java b/src/main/java/ru/bclib/mixin/common/DiggerItemAccessor.java new file mode 100644 index 00000000..8102ce94 --- /dev/null +++ b/src/main/java/ru/bclib/mixin/common/DiggerItemAccessor.java @@ -0,0 +1,21 @@ +package ru.bclib.mixin.common; + +import net.minecraft.tags.TagKey; +import net.minecraft.world.item.DiggerItem; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.levelgen.placement.PlacedFeature; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.List; +import java.util.function.Supplier; + +@Mixin(DiggerItem.class) +public interface DiggerItemAccessor { + @Accessor("blocks") + @Mutable + TagKey bclib_getBlockTag(); +} diff --git a/src/main/java/ru/bclib/mixin/common/SimpleReloadableResourceManagerMixin.java b/src/main/java/ru/bclib/mixin/common/SimpleReloadableResourceManagerMixin.java index d2ff94df..3b78fdbc 100644 --- a/src/main/java/ru/bclib/mixin/common/SimpleReloadableResourceManagerMixin.java +++ b/src/main/java/ru/bclib/mixin/common/SimpleReloadableResourceManagerMixin.java @@ -2,7 +2,6 @@ package ru.bclib.mixin.common; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.resources.FallbackResourceManager; -import net.minecraft.server.packs.resources.SimpleReloadableResourceManager; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -12,28 +11,29 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.Map; -@Mixin(SimpleReloadableResourceManager.class) -public class SimpleReloadableResourceManagerMixin { - @Final - @Shadow - private Map namespacedPacks; - - private static final String[] BCLIB_MISSING_RESOURCES = new String[] { - "dimension/the_end.json", - "dimension/the_nether.json", - "dimension_type/the_end.json", - "dimension_type/the_nether.json" - }; - - @Inject(method = "hasResource", at = @At("HEAD"), cancellable = true) - private void bclib_hasResource(ResourceLocation resourceLocation, CallbackInfoReturnable info) { - if (resourceLocation.getNamespace().equals("minecraft")) { - for (String key: BCLIB_MISSING_RESOURCES) { - if (resourceLocation.getPath().equals(key)) { - info.setReturnValue(false); - return; - } - } - } - } -} +//TODO: 1.18.2 Disabled to have a compilable Version +//@Mixin(SimpleReloadableResourceManager.class) +//public class SimpleReloadableResourceManagerMixin { +// @Final +// @Shadow +// private Map namespacedPacks; +// +// private static final String[] BCLIB_MISSING_RESOURCES = new String[] { +// "dimension/the_end.json", +// "dimension/the_nether.json", +// "dimension_type/the_end.json", +// "dimension_type/the_nether.json" +// }; +// +// @Inject(method = "hasResource", at = @At("HEAD"), cancellable = true) +// private void bclib_hasResource(ResourceLocation resourceLocation, CallbackInfoReturnable info) { +// if (resourceLocation.getNamespace().equals("minecraft")) { +// for (String key: BCLIB_MISSING_RESOURCES) { +// if (resourceLocation.getPath().equals(key)) { +// info.setReturnValue(false); +// return; +// } +// } +// } +// } +//} diff --git a/src/main/java/ru/bclib/mixin/common/StructureSettingsAccessor.java b/src/main/java/ru/bclib/mixin/common/StructureSettingsAccessor.java deleted file mode 100644 index bd3dc67a..00000000 --- a/src/main/java/ru/bclib/mixin/common/StructureSettingsAccessor.java +++ /dev/null @@ -1,32 +0,0 @@ -package ru.bclib.mixin.common; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMultimap; -import net.minecraft.resources.ResourceKey; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.levelgen.StructureSettings; -import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; -import net.minecraft.world.level.levelgen.feature.StructureFeature; -import net.minecraft.world.level.levelgen.feature.configurations.StructureFeatureConfiguration; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Mutable; -import org.spongepowered.asm.mixin.gen.Accessor; - -import java.util.Map; - -@Mixin(StructureSettings.class) -public interface StructureSettingsAccessor { - @Accessor("configuredStructures") - ImmutableMap, ImmutableMultimap, ResourceKey>> bcl_getConfiguredStructures(); - - @Accessor("structureConfig") - Map, StructureFeatureConfiguration> bcl_getStructureConfig(); - - @Accessor("configuredStructures") - @Mutable - void bcl_setConfiguredStructures(ImmutableMap, ImmutableMultimap, ResourceKey>> configuredStructures); - - @Accessor("structureConfig") - @Mutable - void bcl_setStructureConfig(Map, StructureFeatureConfiguration> structureConfig); -} diff --git a/src/main/java/ru/bclib/mixin/common/SurfaceRulesContextAccessor.java b/src/main/java/ru/bclib/mixin/common/SurfaceRulesContextAccessor.java index b1bd7a6b..2e2e93be 100644 --- a/src/main/java/ru/bclib/mixin/common/SurfaceRulesContextAccessor.java +++ b/src/main/java/ru/bclib/mixin/common/SurfaceRulesContextAccessor.java @@ -1,5 +1,6 @@ package ru.bclib.mixin.common; +import net.minecraft.core.Holder; import net.minecraft.resources.ResourceKey; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.chunk.ChunkAccess; @@ -25,10 +26,7 @@ public interface SurfaceRulesContextAccessor { int getSurfaceDepth(); @Accessor("biome") - Supplier getBiome(); - - @Accessor("biomeKey") - Supplier> getBiomeKey(); + Supplier> getBiome(); @Accessor("chunk") ChunkAccess getChunk(); diff --git a/src/main/resources/bclib.mixins.common.json b/src/main/resources/bclib.mixins.common.json index 98e434cd..7c96df98 100644 --- a/src/main/resources/bclib.mixins.common.json +++ b/src/main/resources/bclib.mixins.common.json @@ -13,7 +13,6 @@ "NoiseGeneratorSettingsMixin", "SurfaceRulesContextAccessor", "shears.TripWireBlockMixin", - "StructureSettingsAccessor", "MobSpawnSettingsAccessor", "shears.BeehiveBlockMixin", "shears.PumpkinBlockMixin", @@ -21,6 +20,7 @@ "ComposterBlockAccessor", "PotionBrewingAccessor", "RecipeManagerAccessor", + "DiggerItemAccessor", "shears.SnowGolemMixin", "EnchantmentMenuMixin", "MinecraftServerMixin", From 2dbbfe04d8bd7a83a0158804a3abd423eba81934 Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 8 Mar 2022 11:47:32 +0100 Subject: [PATCH 03/34] *WIP:* Adapted TagAPI to new TagKey's --- .../ru/bclib/api/tag/CommonBlockTags.java | 34 ++-- .../java/ru/bclib/api/tag/CommonItemTags.java | 26 +-- src/main/java/ru/bclib/api/tag/TagAPI.java | 178 ++++++------------ .../ru/bclib/mixin/common/TagLoaderMixin.java | 5 +- 4 files changed, 95 insertions(+), 148 deletions(-) diff --git a/src/main/java/ru/bclib/api/tag/CommonBlockTags.java b/src/main/java/ru/bclib/api/tag/CommonBlockTags.java index 1f18172d..e6b42095 100644 --- a/src/main/java/ru/bclib/api/tag/CommonBlockTags.java +++ b/src/main/java/ru/bclib/api/tag/CommonBlockTags.java @@ -1,23 +1,23 @@ package ru.bclib.api.tag; +import net.minecraft.tags.TagKey; import net.minecraft.world.level.block.Block; -import ru.bclib.api.tag.TagAPI.TagNamed; public class CommonBlockTags { - public static final TagNamed BARREL = TagAPI.makeCommonBlockTag("barrel"); - public static final TagNamed BOOKSHELVES = TagAPI.makeCommonBlockTag("bookshelves"); - public static final TagNamed CHEST = TagAPI.makeCommonBlockTag("chest"); - public static final TagNamed END_STONES = TagAPI.makeCommonBlockTag("end_stones"); - public static final TagNamed GEN_END_STONES = END_STONES; - public static final TagNamed IMMOBILE = TagAPI.makeCommonBlockTag("immobile"); - public static final TagNamed LEAVES = TagAPI.makeCommonBlockTag("leaves"); - public static final TagNamed NETHERRACK = TagAPI.makeCommonBlockTag("netherrack"); - public static final TagNamed NETHER_MYCELIUM = TagAPI.makeCommonBlockTag("nether_mycelium"); - public static final TagNamed NETHER_PORTAL_FRAME = TagAPI.makeCommonBlockTag("nether_pframe"); - public static final TagNamed NETHER_STONES = TagAPI.makeCommonBlockTag("nether_stones"); - public static final TagNamed SAPLINGS = TagAPI.makeCommonBlockTag("saplings"); - public static final TagNamed SOUL_GROUND = TagAPI.makeCommonBlockTag("soul_ground"); - public static final TagNamed WOODEN_BARREL = TagAPI.makeCommonBlockTag("wooden_barrels"); - public static final TagNamed WOODEN_CHEST = TagAPI.makeCommonBlockTag("wooden_chests"); - public static final TagNamed WORKBENCHES = TagAPI.makeCommonBlockTag("workbench"); + public static final TagKey BARREL = TagAPI.makeCommonBlockTag("barrel"); + public static final TagKey BOOKSHELVES = TagAPI.makeCommonBlockTag("bookshelves"); + public static final TagKey CHEST = TagAPI.makeCommonBlockTag("chest"); + public static final TagKey END_STONES = TagAPI.makeCommonBlockTag("end_stones"); + public static final TagKey GEN_END_STONES = END_STONES; + public static final TagKey IMMOBILE = TagAPI.makeCommonBlockTag("immobile"); + public static final TagKey LEAVES = TagAPI.makeCommonBlockTag("leaves"); + public static final TagKey NETHERRACK = TagAPI.makeCommonBlockTag("netherrack"); + public static final TagKey NETHER_MYCELIUM = TagAPI.makeCommonBlockTag("nether_mycelium"); + public static final TagKey NETHER_PORTAL_FRAME = TagAPI.makeCommonBlockTag("nether_pframe"); + public static final TagKey NETHER_STONES = TagAPI.makeCommonBlockTag("nether_stones"); + public static final TagKey SAPLINGS = TagAPI.makeCommonBlockTag("saplings"); + public static final TagKey SOUL_GROUND = TagAPI.makeCommonBlockTag("soul_ground"); + public static final TagKey WOODEN_BARREL = TagAPI.makeCommonBlockTag("wooden_barrels"); + public static final TagKey WOODEN_CHEST = TagAPI.makeCommonBlockTag("wooden_chests"); + public static final TagKey WORKBENCHES = TagAPI.makeCommonBlockTag("workbench"); } diff --git a/src/main/java/ru/bclib/api/tag/CommonItemTags.java b/src/main/java/ru/bclib/api/tag/CommonItemTags.java index 9fb7bfd4..eb96d373 100644 --- a/src/main/java/ru/bclib/api/tag/CommonItemTags.java +++ b/src/main/java/ru/bclib/api/tag/CommonItemTags.java @@ -1,19 +1,19 @@ package ru.bclib.api.tag; +import net.minecraft.tags.TagKey; import net.minecraft.world.item.Item; -import ru.bclib.api.tag.TagAPI.TagNamed; public class CommonItemTags { - public final static TagNamed HAMMERS = TagAPI.makeCommonItemTag("hammers"); - public static final TagNamed BARREL = TagAPI.makeCommonItemTag("barrel"); - public static final TagNamed CHEST = TagAPI.makeCommonItemTag("chest"); - public static final TagNamed SHEARS = TagAPI.makeCommonItemTag("shears"); - public static final TagNamed FURNACES = TagAPI.makeCommonItemTag("furnaces"); - public static final TagNamed IRON_INGOTS = TagAPI.makeCommonItemTag("iron_ingots"); - public static final TagNamed LEAVES = TagAPI.makeCommonItemTag("leaves"); - public static final TagNamed SAPLINGS = TagAPI.makeCommonItemTag("saplings"); - public static final TagNamed SOUL_GROUND = TagAPI.makeCommonItemTag("soul_ground"); - public static final TagNamed WOODEN_BARREL = TagAPI.makeCommonItemTag("wooden_barrels"); - public static final TagNamed WOODEN_CHEST = TagAPI.makeCommonItemTag("wooden_chests"); - public static final TagNamed WORKBENCHES = TagAPI.makeCommonItemTag("workbench"); + public final static TagKey HAMMERS = TagAPI.makeCommonItemTag("hammers"); + public static final TagKey BARREL = TagAPI.makeCommonItemTag("barrel"); + public static final TagKey CHEST = TagAPI.makeCommonItemTag("chest"); + public static final TagKey SHEARS = TagAPI.makeCommonItemTag("shears"); + public static final TagKey FURNACES = TagAPI.makeCommonItemTag("furnaces"); + public static final TagKey IRON_INGOTS = TagAPI.makeCommonItemTag("iron_ingots"); + public static final TagKey LEAVES = TagAPI.makeCommonItemTag("leaves"); + public static final TagKey SAPLINGS = TagAPI.makeCommonItemTag("saplings"); + public static final TagKey SOUL_GROUND = TagAPI.makeCommonItemTag("soul_ground"); + public static final TagKey WOODEN_BARREL = TagAPI.makeCommonItemTag("wooden_barrels"); + public static final TagKey WOODEN_CHEST = TagAPI.makeCommonItemTag("wooden_chests"); + public static final TagKey WORKBENCHES = TagAPI.makeCommonItemTag("workbench"); } diff --git a/src/main/java/ru/bclib/api/tag/TagAPI.java b/src/main/java/ru/bclib/api/tag/TagAPI.java index 126a8b7e..a1977efd 100644 --- a/src/main/java/ru/bclib/api/tag/TagAPI.java +++ b/src/main/java/ru/bclib/api/tag/TagAPI.java @@ -5,10 +5,8 @@ import com.google.common.collect.Sets; import net.minecraft.core.Registry; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.resources.ResourceManager; -import net.minecraft.tags.BlockTags; -import net.minecraft.tags.ItemTags; -import net.minecraft.tags.TagKey; import net.minecraft.tags.Tag; +import net.minecraft.tags.TagKey; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; @@ -17,94 +15,83 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import ru.bclib.mixin.common.DiggerItemAccessor; -import java.util.List; import java.util.Map; -import java.util.Random; import java.util.Set; -import java.util.function.Supplier; +import java.util.function.BiConsumer; public class TagAPI { private static final Map> TAGS_BLOCK = Maps.newConcurrentMap(); private static final Map> TAGS_ITEM = Maps.newConcurrentMap(); /** - * Get or create {@link TagNamed}. + * Get or create {@link TagKey}. * - * @param containerSupplier - {@link TagCollection} {@link Supplier} tag collection; + * @param registry - {@link Registry} tag collection; * @param id - {@link ResourceLocation} tag id. - * @return {@link TagNamed}. + * @return {@link TagKey}. */ - public static TagNamed makeTag(Supplier> containerSupplier, TagLocation id) { - Tag tag = containerSupplier.get().getTag(id); - return tag == null ? new Delegate<>(id, containerSupplier) : CommonDelegate.proxy((TagKey) tag); + public static TagKey makeTag(Registry registry, TagLocation id) { + //TODO: 1.18.2 check if registry.key() gets the correct result + return registry + .getTagNames() + .filter(tagKey -> tagKey.location().equals(id)) + .findAny() + .orElse(TagKey.create(registry.key(), id)); } /** - * Get or create {@link Block} {@link TagNamed} with mod namespace. + * Get or create {@link Block} {@link TagKey} with mod namespace. * * @param modID - {@link String} mod namespace (mod id); * @param name - {@link String} tag name. - * @return {@link Block} {@link TagNamed}. + * @return {@link Block} {@link TagKey}. */ - public static TagNamed makeBlockTag(String modID, String name) { - return makeTag(BlockTags::getAllTags, new TagLocation<>(modID, name)); + public static TagKey makeBlockTag(String modID, String name) { + return makeTag(Registry.BLOCK, new TagLocation<>(modID, name)); } /** - * Get or create {@link Item} {@link TagNamed} with mod namespace. + * Get or create {@link Item} {@link TagKey} with mod namespace. * * @param modID - {@link String} mod namespace (mod id); * @param name - {@link String} tag name. - * @return {@link Item} {@link TagNamed}. + * @return {@link Item} {@link TagKey}. */ - public static TagNamed makeItemTag(String modID, String name) { - return makeTag(ItemTags::getAllTags, new TagLocation<>(modID, name)); + public static TagKey makeItemTag(String modID, String name) { + return makeTag(Registry.ITEM, new TagLocation<>(modID, name)); } /** - * Get or create {@link Block} {@link TagNamed}. + * Get or create {@link Block} {@link TagKey}. * * @param name - {@link String} tag name. - * @return {@link Block} {@link TagNamed}. + * @return {@link Block} {@link TagKey}. * @see Fabric Wiki (Tags) */ - public static TagNamed makeCommonBlockTag(String name) { - return makeTag(BlockTags::getAllTags, new TagLocation<>("c", name)); + public static TagKey makeCommonBlockTag(String name) { + return makeTag(Registry.BLOCK, new TagLocation<>("c", name)); } /** - * Get or create {@link Item} {@link TagNamed}. + * Get or create {@link Item} {@link TagKey}. * * @param name - {@link String} tag name. - * @return {@link Item} {@link TagNamed}. + * @return {@link Item} {@link TagKey}. * @see Fabric Wiki (Tags) */ - public static TagNamed makeCommonItemTag(String name) { - return makeTag(ItemTags::getAllTags, new TagLocation<>("c", name)); - } - - /** - * Get or create Minecraft {@link Block} {@link TagNamed}. - * - * @param name - {@link String} tag name. - * @return {@link Block} {@link TagNamed}. - */ - @Deprecated(forRemoval = true) - public static TagNamed getMCBlockTag(String name) { - ResourceLocation id = new ResourceLocation(name); - Tag tag = BlockTags.getAllTags().getTag(id); - return CommonDelegate.proxy(tag == null ? (TagKey) TagFactory.BLOCK.create(id): (TagKey) tag); + public static TagKey makeCommonItemTag(String name) { + return makeTag(Registry.ITEM, new TagLocation<>("c", name)); } /** * Initializes basic tags. Should be called only in BCLib main class. */ public static void init() { - addBlockTag(CommonBlockTags.BOOKSHELVES.getName(), Blocks.BOOKSHELF); - addBlockTag(CommonBlockTags.CHEST.getName(), Blocks.CHEST); - addItemTag(CommonItemTags.CHEST.getName(), Items.CHEST); - addItemTag(CommonItemTags.IRON_INGOTS.getName(), Items.IRON_INGOT); - addItemTag(CommonItemTags.FURNACES.getName(), Blocks.FURNACE); + addBlockTag(CommonBlockTags.BOOKSHELVES, Blocks.BOOKSHELF); + addBlockTag(CommonBlockTags.CHEST, Blocks.CHEST); + addItemTag(CommonItemTags.CHEST, Items.CHEST); + addItemTag(CommonItemTags.IRON_INGOTS, Items.IRON_INGOT); + addItemTag(CommonItemTags.FURNACES, Blocks.FURNACE); } /** @@ -127,6 +114,15 @@ public class TagAPI { public static void addBlockTag(TagLocation tagID, Block... blocks) { addBlockTagUntyped(tagID, blocks); } + + /** + * Adds one Tag to multiple Blocks. + * @param tagID {@link TagKey} tag ID. + * @param blocks array of {@link Block} to add into tag. + */ + public static void addBlockTag(TagKey tagID, Block... blocks) { + addBlockTagUntyped(tagID.location(), blocks); + } /** * Adds one Tag to multiple Blocks. @@ -163,6 +159,15 @@ public class TagAPI { public static void addItemTag(TagLocation tagID, ItemLike... items) { addItemTagUntyped(tagID, items); } + + /** + * Adds one Tag to multiple Items. + * @param tagID {@link TagKey} tag ID. + * @param items array of {@link ItemLike} to add into tag. + */ + public static void addItemTag(TagKey tagID, ItemLike... items) { + addItemTagUntyped(tagID.location(), items); + } /** * Adds one Tag to multiple Items. @@ -189,16 +194,14 @@ public class TagAPI { * @param tagsMap The map that will hold the registered Tags * @return The {@code tagsMap} Parameter. */ - public static Map apply(String directory, Map tagsMap) { - Map> tagMap = null; + public static Map apply(String directory, Map tagsMap) { + final BiConsumer> consumer; + consumer = (id, ids) -> apply(tagsMap.computeIfAbsent(id, key -> Tag.Builder.tag()), ids); if ("tags/blocks".equals(directory)) { - tagMap = TAGS_BLOCK; + TAGS_BLOCK.forEach(consumer); } else if ("tags/items".equals(directory)) { - tagMap = TAGS_ITEM; - } - if (tagMap != null) { - tagMap.forEach((id, ids) -> apply(tagsMap.computeIfAbsent(id, key -> Tag.Builder.tag()), ids)); + TAGS_ITEM.forEach(consumer); } return tagsMap; } @@ -214,16 +217,8 @@ public class TagAPI { ids.forEach(value -> builder.addElement(value, "BCLib Code")); return builder; } - - /** - * Extends {@link TagNamed} to return a type safe {@link TagLocation}. This Type was introduced to - * allow type-safe definition of Tags using their ResourceLocation. - * @param The Type of the underlying {@link Tag} - */ - public interface TagNamed extends TagKey{ - TagLocation getName(); - } - + + /** * Extends (without changing) {@link ResourceLocation}. This Type was introduced to allow type-safe definition af * Tags using their ResourceLocation. @@ -233,68 +228,17 @@ public class TagAPI { public TagLocation(String string) { super(string); } - + public TagLocation(String string, String string2) { super(string, string2); } - + public TagLocation(ResourceLocation location) { super(location.getNamespace(), location.getPath()); } public static TagLocation of(TagKey tag){ - return new TagLocation(tag.getName()); - } - } - - private abstract static class CommonDelegate implements TagNamed { - protected final TagKey delegate; - protected CommonDelegate(TagKey source){ - this.delegate = source; - } - - public static TagNamed proxy(TagKey source){ - if (source instanceof TagNamed typed) return typed; - return new ProxyDelegate<>(source); - } - - @Override - public boolean contains(T object) { - return delegate.contains(object); - } - - @Override - public List getValues() { - return delegate.getValues(); - } - - @Override - public T getRandomElement(Random random) { - return delegate.getRandomElement(random); - } - } - - private static final class ProxyDelegate extends CommonDelegate{ - private final TagLocation id; - private ProxyDelegate(Tag.Named source) { - super( source); - id = new TagLocation<>(source.getName() - .getNamespace(), source.getName() - .getPath()); - } - @Override - public TagLocation getName(){ - return id; - } - } - - private static final class Delegate extends CommonDelegate{ - public Delegate(TagLocation id, Supplier> containerSupplier) { - super( new TagDelegate<>(id, containerSupplier)); - } - @Override - public TagLocation getName(){ - return (TagLocation)delegate.getName(); + return new TagLocation(tag.location()); } } diff --git a/src/main/java/ru/bclib/mixin/common/TagLoaderMixin.java b/src/main/java/ru/bclib/mixin/common/TagLoaderMixin.java index a5fd7f45..cf5722e8 100644 --- a/src/main/java/ru/bclib/mixin/common/TagLoaderMixin.java +++ b/src/main/java/ru/bclib/mixin/common/TagLoaderMixin.java @@ -3,6 +3,7 @@ package ru.bclib.mixin.common; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.Tag; import net.minecraft.tags.TagLoader; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -13,11 +14,13 @@ import java.util.Map; @Mixin(TagLoader.class) public class TagLoaderMixin { + @Final @Shadow private String directory; - @ModifyArg(method = "loadAndBuild", at = @At(value = "INVOKE", target = "Lnet/minecraft/tags/TagLoader;build(Ljava/util/Map;)Lnet/minecraft/tags/TagCollection;")) + @ModifyArg(method = "loadAndBuild", at = @At(value = "INVOKE", target = "Lnet/minecraft/tags/TagLoader;build(Ljava/util/Map;)Ljava/util/Map;")) public Map be_modifyTags(Map tagsMap) { + //TODO: 1.18.2 Check if this still works as expected return TagAPI.apply(directory, tagsMap); } } From 305ac05ac182a24116e7cf84107b9afb0464e422 Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 8 Mar 2022 21:26:34 +0100 Subject: [PATCH 04/34] Some more Changes for 1.18.2 --- .../java/ru/bclib/api/biomes/BiomeAPI.java | 12 ++-- src/main/java/ru/bclib/api/tag/TagAPI.java | 8 +++ .../complexmaterials/ComplexMaterial.java | 27 ++++---- .../WoodenComplexMaterial.java | 4 +- .../ru/bclib/interfaces/SurfaceProvider.java | 3 +- .../java/ru/bclib/items/tool/BaseAxeItem.java | 18 +---- .../ru/bclib/items/tool/BasePickaxeItem.java | 29 +------- .../ru/bclib/items/tool/BaseShearsItem.java | 9 ++- .../ru/bclib/items/tool/BaseShovelItem.java | 29 +------- .../ru/bclib/items/tool/BaseSwordItem.java | 3 +- .../ru/bclib/mixin/client/MinecraftMixin.java | 22 +++---- .../bclib/mixin/client/WorldPresetMixin.java | 4 +- .../ru/bclib/mixin/common/BiomeAccessor.java | 13 ++++ .../bclib/mixin/common/BiomeSourceMixin.java | 6 +- .../mixin/common/DimensionTypeMixin.java | 66 ++++++++++--------- .../mixin/common/MinecraftServerMixin.java | 9 ++- .../common/NoiseBasedChunkGeneratorMixin.java | 23 ++++--- .../shears/ItemPredicateBuilderMixin.java | 4 +- .../world/generator/BCLibEndBiomeSource.java | 11 +--- .../generator/BCLibNetherBiomeSource.java | 28 +++++--- src/main/resources/bclib.accesswidener | 1 + src/main/resources/bclib.mixins.client.json | 1 - src/main/resources/bclib.mixins.common.json | 4 +- 23 files changed, 148 insertions(+), 186 deletions(-) create mode 100644 src/main/java/ru/bclib/mixin/common/BiomeAccessor.java diff --git a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java index 77ec7654..53fa2988 100644 --- a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java @@ -646,14 +646,14 @@ public class BiomeAPI { private static void addBiomeFeature(Biome biome, Decoration step, List featureList) { BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings(); List>> allFeatures = CollectionsUtil.getMutable(accessor.bclib_getFeatures()); - Set set = CollectionsUtil.getMutable(accessor.bclib_getFeatureSet()); + Set set = CollectionsUtil.getMutable(accessor.bclib_getFeatureSet().get()); List> features = getFeaturesList(allFeatures, step); for (var feature : featureList) { features.add(() -> feature); set.add(feature); } accessor.bclib_setFeatures(allFeatures); - accessor.bclib_setFeatureSet(set); + accessor.bclib_setFeatureSet(()-> set); } /** @@ -667,7 +667,7 @@ public class BiomeAPI { private static void addStepFeaturesToBiome(Biome biome, Map>> featureMap) { BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings(); List>> allFeatures = CollectionsUtil.getMutable(accessor.bclib_getFeatures()); - Set set = CollectionsUtil.getMutable(accessor.bclib_getFeatureSet()); + Set set = CollectionsUtil.getMutable(accessor.bclib_getFeatureSet().get()); for (Decoration step: featureMap.keySet()) { List> features = getFeaturesList(allFeatures, step); @@ -679,7 +679,7 @@ public class BiomeAPI { } } accessor.bclib_setFeatures(allFeatures); - accessor.bclib_setFeatureSet(set); + accessor.bclib_setFeatureSet(() -> set); } /** @@ -752,11 +752,11 @@ public class BiomeAPI { /** * Get biome surface block. Can be used to get terrain material for features or other things. * @param pos {@link BlockPos} position to get block. - * @param biome {@link Biome} to get block from. + * @param biome {@link Holder} to get block from. * @param level {@link ServerLevel} current server level. * @return {@link BlockState} with the biome surface or AIR if it fails. */ - public static BlockState getBiomeSurfaceBlock(BlockPos pos, Biome biome, ServerLevel level) { + public static BlockState getBiomeSurfaceBlock(BlockPos pos, Holder biome, ServerLevel level) { ChunkGenerator generator = level.getChunkSource().getGenerator(); if (generator instanceof NoiseBasedChunkGenerator) { SurfaceProvider provider = SurfaceProvider.class.cast(generator); diff --git a/src/main/java/ru/bclib/api/tag/TagAPI.java b/src/main/java/ru/bclib/api/tag/TagAPI.java index a1977efd..f5312f20 100644 --- a/src/main/java/ru/bclib/api/tag/TagAPI.java +++ b/src/main/java/ru/bclib/api/tag/TagAPI.java @@ -242,7 +242,15 @@ public class TagAPI { } } + public static boolean isToolWithMineableTag(ItemStack stack, TagKey tag){ + return isToolWithUntypedMineableTag(stack, tag.location()); + } + public static boolean isToolWithMineableTag(ItemStack stack, TagLocation tag){ + return isToolWithUntypedMineableTag(stack, tag); + } + + private static boolean isToolWithUntypedMineableTag(ItemStack stack, ResourceLocation tag){ if (stack.getItem() instanceof DiggerItemAccessor dig){ return dig.bclib_getBlockTag().location().equals(tag); } diff --git a/src/main/java/ru/bclib/complexmaterials/ComplexMaterial.java b/src/main/java/ru/bclib/complexmaterials/ComplexMaterial.java index 1684c162..2fc08408 100644 --- a/src/main/java/ru/bclib/complexmaterials/ComplexMaterial.java +++ b/src/main/java/ru/bclib/complexmaterials/ComplexMaterial.java @@ -6,7 +6,6 @@ import net.fabricmc.fabric.api.item.v1.FabricItemSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.registry.FlammableBlockRegistry; import net.minecraft.resources.ResourceLocation; -import net.minecraft.tags.Tag; import net.minecraft.tags.TagKey; import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; @@ -106,39 +105,39 @@ public abstract class ComplexMaterial { /** * Adds custom block tag for this {@link ComplexMaterial}, tag can be created with {@link TagAPI} or you can use one of already created tags. - * @param tag {@link Tag.Named} for {@link Block} + * @param tag {@link TagKey} for {@link Block} */ - protected void addBlockTag(Tag.Named tag) { - String key = tag.getName().getPath().replace(getBaseName() + "_", ""); + protected void addBlockTag(TagKey tag) { + String key = tag.location().getPath().replace(getBaseName() + "_", ""); blockTags.put(key, tag); } /** - * Adds custom iten tag for this {@link ComplexMaterial}, tag can be created with {@link TagAPI} or you can use one of already created tags. - * @param tag {@link Tag.Named} for {@link Item} + * Adds custom item tag for this {@link ComplexMaterial}, tag can be created with {@link TagAPI} or you can use one of already created tags. + * @param tag {@link TagKey} for {@link Item} */ - protected void addItemTag(Tag.Named tag) { - String key = tag.getName().getPath().replace(getBaseName() + "_", ""); + protected void addItemTag(TagKey tag) { + String key = tag.location().getPath().replace(getBaseName() + "_", ""); itemTags.put(key, tag); } /** - * Get custom {@link Block} {@link Tag.Named} from this {@link ComplexMaterial}. + * Get custom {@link Block} {@link TagKey} from this {@link ComplexMaterial}. * @param key {@link String} tag name (path of its {@link ResourceLocation}), for inner tags created inside material its tag suffix. - * @return {@link Tag.Named} for {@link Block} or {@code null} if nothing is stored. + * @return {@link TagKey} for {@link Block} or {@code null} if nothing is stored. */ @Nullable - public Tag.Named getBlockTag(String key) { + public TagKey getBlockTag(String key) { return blockTags.get(key); } /** - * Get custom {@link Item} {@link Tag.Named} from this {@link ComplexMaterial}. + * Get custom {@link Item} {@link TagKey} from this {@link ComplexMaterial}. * @param key {@link String} tag name (path of its {@link ResourceLocation}), for inner tags created inside material its tag suffix. - * @return {@link Tag.Named} for {@link Item} or {@code null} if nothing is stored. + * @return {@link TagKey} for {@link Item} or {@code null} if nothing is stored. */ @Nullable - public Tag.Named getItemTag(String key) { + public TagKey getItemTag(String key) { return itemTags.get(key); } diff --git a/src/main/java/ru/bclib/complexmaterials/WoodenComplexMaterial.java b/src/main/java/ru/bclib/complexmaterials/WoodenComplexMaterial.java index 7d99b3d2..c405ef4b 100644 --- a/src/main/java/ru/bclib/complexmaterials/WoodenComplexMaterial.java +++ b/src/main/java/ru/bclib/complexmaterials/WoodenComplexMaterial.java @@ -100,8 +100,8 @@ public class WoodenComplexMaterial extends ComplexMaterial { } final protected void initBase(FabricBlockSettings blockSettings, FabricItemSettings itemSettings) { - TagLocation tagBlockLog = new TagLocation<>(getBlockTag(TAG_LOGS).getName()); - TagLocation tagItemLog = new TagLocation<>(getItemTag(TAG_LOGS).getName()); + TagLocation tagBlockLog = TagLocation.of(getBlockTag(TAG_LOGS)); + TagLocation tagItemLog = TagLocation.of(getItemTag(TAG_LOGS)); addBlockEntry( new BlockEntry(BLOCK_STRIPPED_LOG, (complexMaterial, settings) -> new BaseRotatedPillarBlock(settings)) diff --git a/src/main/java/ru/bclib/interfaces/SurfaceProvider.java b/src/main/java/ru/bclib/interfaces/SurfaceProvider.java index 143e6499..26426edf 100644 --- a/src/main/java/ru/bclib/interfaces/SurfaceProvider.java +++ b/src/main/java/ru/bclib/interfaces/SurfaceProvider.java @@ -1,10 +1,11 @@ package ru.bclib.interfaces; import net.minecraft.core.BlockPos; +import net.minecraft.core.Holder; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.block.state.BlockState; public interface SurfaceProvider { - public BlockState bclib_getSurface(BlockPos pos, Biome biome, ServerLevel level); + public BlockState bclib_getSurface(BlockPos pos, Holder biome, ServerLevel level); } diff --git a/src/main/java/ru/bclib/items/tool/BaseAxeItem.java b/src/main/java/ru/bclib/items/tool/BaseAxeItem.java index f0543c0f..32c6d0b3 100644 --- a/src/main/java/ru/bclib/items/tool/BaseAxeItem.java +++ b/src/main/java/ru/bclib/items/tool/BaseAxeItem.java @@ -2,33 +2,19 @@ package ru.bclib.items.tool; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.fabricmc.fabric.api.tool.attribute.v1.DynamicAttributeTool; -import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.resources.ResourceLocation; -import net.minecraft.tags.Tag; -import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.item.AxeItem; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Tier; -import net.minecraft.world.level.block.state.BlockState; import ru.bclib.client.models.ModelsHelper; import ru.bclib.interfaces.ItemModelProvider; -public class BaseAxeItem extends AxeItem implements DynamicAttributeTool, ItemModelProvider { +//TODO: 1.18.2 See if mining speed is still ok. +public class BaseAxeItem extends AxeItem implements ItemModelProvider { public BaseAxeItem(Tier material, float attackDamage, float attackSpeed, Properties settings) { super(material, attackDamage, attackSpeed, settings); } - @Override - public int getMiningLevel(Tag tag, BlockState state, ItemStack stack, LivingEntity user) { - if (tag.equals(FabricToolTags.AXES)) { - return this.getTier().getLevel(); - } - return 0; - } - @Override @Environment(EnvType.CLIENT) public BlockModel getItemModel(ResourceLocation resourceLocation) { diff --git a/src/main/java/ru/bclib/items/tool/BasePickaxeItem.java b/src/main/java/ru/bclib/items/tool/BasePickaxeItem.java index 53be6e2d..7fe12455 100644 --- a/src/main/java/ru/bclib/items/tool/BasePickaxeItem.java +++ b/src/main/java/ru/bclib/items/tool/BasePickaxeItem.java @@ -2,44 +2,19 @@ package ru.bclib.items.tool; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.fabricmc.fabric.api.tool.attribute.v1.DynamicAttributeTool; -import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.fabricmc.fabric.impl.tool.attribute.ToolManagerImpl; -import net.fabricmc.fabric.impl.tool.attribute.ToolManagerImpl.Entry; import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.resources.ResourceLocation; -import net.minecraft.tags.Tag; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.PickaxeItem; import net.minecraft.world.item.Tier; -import net.minecraft.world.level.block.state.BlockState; import ru.bclib.client.models.ModelsHelper; import ru.bclib.interfaces.ItemModelProvider; -public class BasePickaxeItem extends PickaxeItem implements DynamicAttributeTool, ItemModelProvider { +//TODO: 1.18.2 See if mining speed is still ok. +public class BasePickaxeItem extends PickaxeItem implements ItemModelProvider { public BasePickaxeItem(Tier material, int attackDamage, float attackSpeed, Properties settings) { super(material, attackDamage, attackSpeed, settings); } - @Override - public int getMiningLevel(Tag tag, BlockState state, ItemStack stack, LivingEntity user) { - if (tag.equals(FabricToolTags.PICKAXES)) { - return getTier().getLevel(); - } - return 0; - } - - @Override - public float getDestroySpeed(ItemStack stack, BlockState state) { - Entry entry = ToolManagerImpl.entryNullable(state.getBlock()); - return (entry != null && entry.getMiningLevel(FabricToolTags.PICKAXES) >= 0) ? speed : super.getDestroySpeed( - stack, - state - ); - } - @Override @Environment(EnvType.CLIENT) public BlockModel getItemModel(ResourceLocation resourceLocation) { diff --git a/src/main/java/ru/bclib/items/tool/BaseShearsItem.java b/src/main/java/ru/bclib/items/tool/BaseShearsItem.java index 002b46bf..4d6bc549 100644 --- a/src/main/java/ru/bclib/items/tool/BaseShearsItem.java +++ b/src/main/java/ru/bclib/items/tool/BaseShearsItem.java @@ -1,11 +1,13 @@ package ru.bclib.items.tool; -import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; + +import net.fabricmc.fabric.api.mininglevel.v1.FabricMineableTags; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.item.ShearsItem; import ru.bclib.api.tag.CommonItemTags; +import ru.bclib.api.tag.TagAPI; public class BaseShearsItem extends ShearsItem { public BaseShearsItem(Properties properties) { @@ -13,12 +15,13 @@ public class BaseShearsItem extends ShearsItem { } public static boolean isShear(ItemStack tool){ - return tool.is(Items.SHEARS) | tool.is(CommonItemTags.SHEARS) || tool.is(FabricToolTags.SHEARS); + return tool.is(Items.SHEARS) | tool.is(CommonItemTags.SHEARS) || TagAPI.isToolWithMineableTag(tool, FabricMineableTags.SHEARS_MINEABLE); } public static boolean isShear(ItemStack itemStack, Item item){ if (item == Items.SHEARS){ - return itemStack.is(item) | itemStack.is(CommonItemTags.SHEARS) || itemStack.is(FabricToolTags.SHEARS); + //TODO: 1.18.2 see if removing SHEARS_MINEABLE causes any problems... It should not, since it is a Block-Tag + return itemStack.is(item) | itemStack.is(CommonItemTags.SHEARS); } else { return itemStack.is(item); } diff --git a/src/main/java/ru/bclib/items/tool/BaseShovelItem.java b/src/main/java/ru/bclib/items/tool/BaseShovelItem.java index a987b68b..1795d74b 100644 --- a/src/main/java/ru/bclib/items/tool/BaseShovelItem.java +++ b/src/main/java/ru/bclib/items/tool/BaseShovelItem.java @@ -2,44 +2,19 @@ package ru.bclib.items.tool; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.fabricmc.fabric.api.tool.attribute.v1.DynamicAttributeTool; -import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.fabricmc.fabric.impl.tool.attribute.ToolManagerImpl; -import net.fabricmc.fabric.impl.tool.attribute.ToolManagerImpl.Entry; import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.resources.ResourceLocation; -import net.minecraft.tags.Tag; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ShovelItem; import net.minecraft.world.item.Tier; -import net.minecraft.world.level.block.state.BlockState; import ru.bclib.client.models.ModelsHelper; import ru.bclib.interfaces.ItemModelProvider; -public class BaseShovelItem extends ShovelItem implements DynamicAttributeTool, ItemModelProvider { +//TODO: 1.18.2 See if mining speed is still ok. +public class BaseShovelItem extends ShovelItem implements ItemModelProvider { public BaseShovelItem(Tier material, float attackDamage, float attackSpeed, Properties settings) { super(material, attackDamage, attackSpeed, settings); } - @Override - public int getMiningLevel(Tag tag, BlockState state, ItemStack stack, LivingEntity user) { - if (tag.equals(FabricToolTags.SHOVELS)) { - return this.getTier().getLevel(); - } - return 0; - } - - @Override - public float getDestroySpeed(ItemStack stack, BlockState state) { - Entry entry = ToolManagerImpl.entryNullable(state.getBlock()); - return (entry != null && entry.getMiningLevel(FabricToolTags.SHOVELS) >= 0) ? speed : super.getDestroySpeed( - stack, - state - ); - } - @Override @Environment(EnvType.CLIENT) public BlockModel getItemModel(ResourceLocation resourceLocation) { diff --git a/src/main/java/ru/bclib/items/tool/BaseSwordItem.java b/src/main/java/ru/bclib/items/tool/BaseSwordItem.java index c32addac..18aed8f7 100644 --- a/src/main/java/ru/bclib/items/tool/BaseSwordItem.java +++ b/src/main/java/ru/bclib/items/tool/BaseSwordItem.java @@ -2,7 +2,6 @@ package ru.bclib.items.tool; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.fabricmc.fabric.api.tool.attribute.v1.DynamicAttributeTool; import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.SwordItem; @@ -10,7 +9,7 @@ import net.minecraft.world.item.Tier; import ru.bclib.client.models.ModelsHelper; import ru.bclib.interfaces.ItemModelProvider; -public class BaseSwordItem extends SwordItem implements DynamicAttributeTool, ItemModelProvider { +public class BaseSwordItem extends SwordItem implements ItemModelProvider { public BaseSwordItem(Tier material, int attackDamage, float attackSpeed, Properties settings) { super(material, attackDamage, attackSpeed, settings); } diff --git a/src/main/java/ru/bclib/mixin/client/MinecraftMixin.java b/src/main/java/ru/bclib/mixin/client/MinecraftMixin.java index 87bce5f6..9ae7e755 100644 --- a/src/main/java/ru/bclib/mixin/client/MinecraftMixin.java +++ b/src/main/java/ru/bclib/mixin/client/MinecraftMixin.java @@ -1,6 +1,5 @@ package ru.bclib.mixin.client; -import com.mojang.datafixers.util.Function4; import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft.ExperimentalDialogType; import net.minecraft.client.color.block.BlockColors; @@ -8,14 +7,11 @@ import net.minecraft.client.color.item.ItemColors; import net.minecraft.client.main.GameConfig; import net.minecraft.core.Registry; import net.minecraft.core.RegistryAccess; -import net.minecraft.core.RegistryAccess.RegistryHolder; -import net.minecraft.server.packs.resources.ResourceManager; -import net.minecraft.world.level.DataPackConfig; +import net.minecraft.server.WorldStem; import net.minecraft.world.level.LevelSettings; import net.minecraft.world.level.levelgen.WorldGenSettings; import net.minecraft.world.level.storage.LevelStorageSource; import net.minecraft.world.level.storage.LevelStorageSource.LevelStorageAccess; -import net.minecraft.world.level.storage.WorldData; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -44,17 +40,15 @@ public abstract class MinecraftMixin { @Inject(method = "*", at = @At("TAIL")) private void bclib_onMCInit(GameConfig args, CallbackInfo info) { Registry.BLOCK.forEach(block -> { - if (block instanceof CustomColorProvider) { - CustomColorProvider provider = (CustomColorProvider) block; + if (block instanceof CustomColorProvider provider) { blockColors.register(provider.getProvider(), block); itemColors.register(provider.getItemProvider(), block.asItem()); } }); } - - @Shadow - protected abstract void doLoadLevel(String string, RegistryHolder registryHolder, Function function, Function4 function4, boolean bl, ExperimentalDialogType experimentalDialogType); - + + @Shadow protected abstract void doLoadLevel(String string, Function function, Function function2, boolean bl, ExperimentalDialogType experimentalDialogType); + @Shadow @Final private LevelStorageSource levelSource; @@ -66,7 +60,7 @@ public abstract class MinecraftMixin { if (DataFixerAPI.fixData(this.levelSource, levelID, true, (appliedFixes) -> { LifeCycleAPI._runBeforeLevelLoad(); - this.doLoadLevel(levelID, RegistryAccess.builtin(), Minecraft::loadDataPacks, Minecraft::loadWorldData, false, appliedFixes ? ExperimentalDialogType.NONE : ExperimentalDialogType.BACKUP); + this.doLoadLevel(levelID, WorldStem.DataPackConfigSupplier::loadFromWorld, WorldStem.WorldDataSupplier::loadFromWorld, false, appliedFixes ? ExperimentalDialogType.NONE : ExperimentalDialogType.BACKUP); })) { //cancle call when fix-screen is presented ci.cancel(); @@ -74,7 +68,7 @@ public abstract class MinecraftMixin { else { LifeCycleAPI._runBeforeLevelLoad(); if (Configs.CLIENT_CONFIG.suppressExperimentalDialog()) { - this.doLoadLevel(levelID, RegistryAccess.builtin(), Minecraft::loadDataPacks, Minecraft::loadWorldData, false, ExperimentalDialogType.NONE); + this.doLoadLevel(levelID, WorldStem.DataPackConfigSupplier::loadFromWorld, WorldStem.WorldDataSupplier::loadFromWorld, false, ExperimentalDialogType.NONE); //cancle call as we manually start the level load here ci.cancel(); } @@ -82,7 +76,7 @@ public abstract class MinecraftMixin { } @Inject(method = "createLevel", at = @At("HEAD")) - private void bclib_initPatchData(String levelID, LevelSettings levelSettings, RegistryHolder registryHolder, WorldGenSettings worldGenSettings, CallbackInfo ci) { + private void bclib_initPatchData(String levelID, LevelSettings levelSettings, RegistryAccess registryAccess, WorldGenSettings worldGenSettings, CallbackInfo ci) { DataExchangeAPI.prepareServerside(); BiomeAPI.prepareNewLevel(); diff --git a/src/main/java/ru/bclib/mixin/client/WorldPresetMixin.java b/src/main/java/ru/bclib/mixin/client/WorldPresetMixin.java index b634e8ad..45021583 100644 --- a/src/main/java/ru/bclib/mixin/client/WorldPresetMixin.java +++ b/src/main/java/ru/bclib/mixin/client/WorldPresetMixin.java @@ -13,7 +13,7 @@ import ru.bclib.api.biomes.BiomeAPI; @Mixin(WorldPreset.class) public class WorldPresetMixin { @Inject(method = "create", at = @At("HEAD")) - private void bclib_create(RegistryAccess.RegistryHolder registryHolder, long l, boolean bl, boolean bl2, CallbackInfoReturnable info) { - BiomeAPI.initRegistry(registryHolder.registryOrThrow(Registry.BIOME_REGISTRY)); + private void bclib_create(RegistryAccess registryAccess, long l, boolean bl, boolean bl2, CallbackInfoReturnable info) { + BiomeAPI.initRegistry(registryAccess.registryOrThrow(Registry.BIOME_REGISTRY)); } } diff --git a/src/main/java/ru/bclib/mixin/common/BiomeAccessor.java b/src/main/java/ru/bclib/mixin/common/BiomeAccessor.java new file mode 100644 index 00000000..7d99eb24 --- /dev/null +++ b/src/main/java/ru/bclib/mixin/common/BiomeAccessor.java @@ -0,0 +1,13 @@ +package ru.bclib.mixin.common; + +import net.minecraft.world.level.biome.Biome; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(Biome.class) +public interface BiomeAccessor { + @Accessor("biomeCategory") + @Mutable + Biome.BiomeCategory bclib_getBiomeCategory(); +} diff --git a/src/main/java/ru/bclib/mixin/common/BiomeSourceMixin.java b/src/main/java/ru/bclib/mixin/common/BiomeSourceMixin.java index d407b585..5372c899 100644 --- a/src/main/java/ru/bclib/mixin/common/BiomeSourceMixin.java +++ b/src/main/java/ru/bclib/mixin/common/BiomeSourceMixin.java @@ -1,5 +1,6 @@ package ru.bclib.mixin.common; +import com.google.common.base.Suppliers; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.BiomeSource; import net.minecraft.world.level.biome.BiomeSource.StepFeatureData; @@ -12,6 +13,7 @@ import ru.bclib.interfaces.BiomeSourceAccessor; import java.util.List; import java.util.Set; +import java.util.function.Supplier; @Mixin(BiomeSource.class) public abstract class BiomeSourceMixin implements BiomeSourceAccessor { @@ -19,10 +21,10 @@ public abstract class BiomeSourceMixin implements BiomeSourceAccessor { @Shadow public abstract Set possibleBiomes(); - @Mutable @Shadow @Final private List featuresPerStep; + @Mutable @Shadow @Final private Supplier> featuresPerStep; public void bclRebuildFeatures(){ BCLib.LOGGER.info("Rebuilding features in BiomeSource " + this); - featuresPerStep = buildFeaturesPerStep(this.possibleBiomes().stream().toList(), true); + featuresPerStep = Suppliers.memoize(() -> buildFeaturesPerStep(this.possibleBiomes().stream().toList(), true)); } } diff --git a/src/main/java/ru/bclib/mixin/common/DimensionTypeMixin.java b/src/main/java/ru/bclib/mixin/common/DimensionTypeMixin.java index 3b73c4bf..656b7367 100644 --- a/src/main/java/ru/bclib/mixin/common/DimensionTypeMixin.java +++ b/src/main/java/ru/bclib/mixin/common/DimensionTypeMixin.java @@ -4,12 +4,17 @@ import com.mojang.serialization.Lifecycle; import net.minecraft.core.MappedRegistry; import net.minecraft.core.Registry; import net.minecraft.core.RegistryAccess; +import net.minecraft.core.WritableRegistry; import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.biome.BiomeSource; +import net.minecraft.world.level.biome.MultiNoiseBiomeSource; import net.minecraft.world.level.dimension.DimensionType; import net.minecraft.world.level.dimension.LevelStem; import net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator; import net.minecraft.world.level.levelgen.NoiseGeneratorSettings; +import net.minecraft.world.level.levelgen.structure.StructureSet; import net.minecraft.world.level.levelgen.synth.NormalNoise; +import org.jetbrains.annotations.NotNull; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -23,41 +28,40 @@ import java.util.OptionalInt; @Mixin(DimensionType.class) public class DimensionTypeMixin { @Inject( - method = "defaultDimensions(Lnet/minecraft/core/RegistryAccess;JZ)Lnet/minecraft/core/MappedRegistry;", + method = "defaultDimensions(Lnet/minecraft/core/RegistryAccess;JZ)Lnet/minecraft/core/Registry;", locals = LocalCapture.CAPTURE_FAILHARD, at = @At("TAIL") ) - private static void bclib_updateDimensions(RegistryAccess registryAccess, long seed, boolean bl, CallbackInfoReturnable> info, MappedRegistry mappedRegistry, Registry registry, Registry biomeRegistry, Registry noiseSettingsRegistry, Registry noiseParamRegistry) { - int id = mappedRegistry.getId(mappedRegistry.get(LevelStem.NETHER)); - mappedRegistry.registerOrOverride( - OptionalInt.of(id), - LevelStem.NETHER, - new LevelStem( - () -> registry.getOrThrow(DimensionType.NETHER_LOCATION), - new NoiseBasedChunkGenerator( - noiseParamRegistry, - new BCLibNetherBiomeSource(biomeRegistry, seed), - seed, - () -> noiseSettingsRegistry.getOrThrow(NoiseGeneratorSettings.NETHER) - ) - ), - Lifecycle.stable() + private static void bclib_updateDimensions(RegistryAccess registryAccess, long seed, boolean bl, CallbackInfoReturnable> info, @NotNull MappedRegistry writableRegistry, Registry registry, Registry biomeRegistry, Registry structureRegistry, Registry noiseSettingsRegistry, Registry noiseParamRegistry) { + int id = writableRegistry.getId(writableRegistry.get(LevelStem.NETHER)); + writableRegistry.register( + LevelStem.NETHER, + new LevelStem( + registry.getOrCreateHolder(DimensionType.NETHER_LOCATION), + new NoiseBasedChunkGenerator( + structureRegistry, + noiseParamRegistry, + new BCLibNetherBiomeSource(biomeRegistry, seed), + seed, + noiseSettingsRegistry.getOrCreateHolder(NoiseGeneratorSettings.NETHER)) + ), + Lifecycle.stable() ); - - id = mappedRegistry.getId(mappedRegistry.get(LevelStem.END)); - mappedRegistry.registerOrOverride( - OptionalInt.of(id), - LevelStem.END, - new LevelStem( - () -> registry.getOrThrow(DimensionType.END_LOCATION), - new NoiseBasedChunkGenerator( - noiseParamRegistry, - new BCLibEndBiomeSource(biomeRegistry, seed), - seed, - () -> noiseSettingsRegistry.getOrThrow(NoiseGeneratorSettings.END) - ) - ), - Lifecycle.stable() + + + id = writableRegistry.getId(writableRegistry.get(LevelStem.END)); + writableRegistry.register( + LevelStem.END, + new LevelStem( + registry.getOrCreateHolder(DimensionType.END_LOCATION), + new NoiseBasedChunkGenerator( + structureRegistry, + noiseParamRegistry, + new BCLibEndBiomeSource(biomeRegistry, seed), + seed, + noiseSettingsRegistry.getOrCreateHolder(NoiseGeneratorSettings.END)) + ), + Lifecycle.stable() ); } } diff --git a/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java b/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java index da5ce859..98872a24 100644 --- a/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java +++ b/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java @@ -3,10 +3,9 @@ package ru.bclib.mixin.common; import com.mojang.authlib.GameProfileRepository; import com.mojang.authlib.minecraft.MinecraftSessionService; import com.mojang.datafixers.DataFixer; -import net.minecraft.core.RegistryAccess.RegistryHolder; import net.minecraft.resources.ResourceKey; import net.minecraft.server.MinecraftServer; -import net.minecraft.server.ServerResources; +import net.minecraft.server.WorldStem; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.progress.ChunkProgressListenerFactory; import net.minecraft.server.packs.repository.PackRepository; @@ -32,7 +31,7 @@ import java.util.concurrent.CompletableFuture; @Mixin(MinecraftServer.class) public class MinecraftServerMixin { @Shadow - private ServerResources resources; + private MinecraftServer.ReloadableResources resources; @Final @Shadow @@ -43,7 +42,7 @@ public class MinecraftServerMixin { protected WorldData worldData; @Inject(method = "*", at = @At("TAIL")) - private void bclib_onServerInit(Thread thread, RegistryHolder registryHolder, LevelStorageAccess levelStorageAccess, WorldData worldData, PackRepository packRepository, Proxy proxy, DataFixer dataFixer, ServerResources serverResources, MinecraftSessionService minecraftSessionService, GameProfileRepository gameProfileRepository, GameProfileCache gameProfileCache, ChunkProgressListenerFactory chunkProgressListenerFactory, CallbackInfo ci) { + private void bclib_onServerInit(Thread thread, LevelStorageAccess levelStorageAccess, PackRepository packRepository, WorldStem worldStem, Proxy proxy, DataFixer dataFixer, MinecraftSessionService minecraftSessionService, GameProfileRepository gameProfileRepository, GameProfileCache gameProfileCache, ChunkProgressListenerFactory chunkProgressListenerFactory, CallbackInfo ci) { DataExchangeAPI.prepareServerside(); } @@ -58,7 +57,7 @@ public class MinecraftServerMixin { } private void bclib_injectRecipes() { - RecipeManagerAccessor accessor = (RecipeManagerAccessor) resources.getRecipeManager(); + RecipeManagerAccessor accessor = (RecipeManagerAccessor) resources.managers().getRecipeManager(); accessor.bclib_setRecipesByName(BCLRecipeManager.getMapByName(accessor.bclib_getRecipesByName())); accessor.bclib_setRecipes(BCLRecipeManager.getMap(accessor.bclib_getRecipes())); } diff --git a/src/main/java/ru/bclib/mixin/common/NoiseBasedChunkGeneratorMixin.java b/src/main/java/ru/bclib/mixin/common/NoiseBasedChunkGeneratorMixin.java index 04a78e74..f2e20e72 100644 --- a/src/main/java/ru/bclib/mixin/common/NoiseBasedChunkGeneratorMixin.java +++ b/src/main/java/ru/bclib/mixin/common/NoiseBasedChunkGeneratorMixin.java @@ -1,18 +1,15 @@ package ru.bclib.mixin.common; import net.minecraft.core.BlockPos; +import net.minecraft.core.Holder; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.StructureFeatureManager; import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.biome.Climate; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkAccess; -import net.minecraft.world.level.levelgen.Aquifer; -import net.minecraft.world.level.levelgen.Beardifier; -import net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator; -import net.minecraft.world.level.levelgen.NoiseChunk; -import net.minecraft.world.level.levelgen.NoiseGeneratorSettings; -import net.minecraft.world.level.levelgen.NoiseSampler; +import net.minecraft.world.level.levelgen.*; import net.minecraft.world.level.levelgen.blending.Blender; import net.minecraft.world.level.levelgen.carver.CarvingContext; import org.spongepowered.asm.mixin.Final; @@ -30,11 +27,13 @@ import java.util.function.Supplier; public abstract class NoiseBasedChunkGeneratorMixin implements SurfaceProvider, NoiseGeneratorSettingsProvider { @Final @Shadow - private NoiseSampler sampler; - + private Climate.Sampler sampler; + + @Shadow @Final private NoiseRouter router; + @Final @Shadow - protected Supplier settings; + protected Holder settings; @Final @Shadow @@ -45,12 +44,12 @@ public abstract class NoiseBasedChunkGeneratorMixin implements SurfaceProvider, @Override public NoiseGeneratorSettings bclib_getNoiseGeneratorSettings(){ - return settings.get(); + return settings.value(); } @Override @SuppressWarnings("deprecation") - public BlockState bclib_getSurface(BlockPos pos, Biome biome, ServerLevel level) { + public BlockState bclib_getSurface(BlockPos pos, Holder biome, ServerLevel level) { ChunkAccess chunkAccess = level.getChunk(pos.getX() >> 4, pos.getZ() >> 4); StructureFeatureManager structureFeatureManager = level.structureFeatureManager(); NoiseBasedChunkGenerator generator = NoiseBasedChunkGenerator.class.cast(this); @@ -72,7 +71,7 @@ public abstract class NoiseBasedChunkGeneratorMixin implements SurfaceProvider, } Beardifier finalBeardifier = beardifier; - NoiseChunk noiseChunk = chunkAccess.getOrCreateNoiseChunk(this.sampler, () -> finalBeardifier, this.settings.get(), this.globalFluidPicker, Blender.empty()); + NoiseChunk noiseChunk = chunkAccess.getOrCreateNoiseChunk(router, () -> finalBeardifier, this.settings.value(), this.globalFluidPicker, Blender.empty()); CarvingContext carvingContext = new CarvingContext(generator, level.registryAccess(), chunkAccess.getHeightAccessorForGeneration(), noiseChunk); Optional optional = carvingContext.topMaterial(bpos -> biome, chunkAccess, pos, false); return optional.isPresent() ? optional.get() : bclib_air; diff --git a/src/main/java/ru/bclib/mixin/common/shears/ItemPredicateBuilderMixin.java b/src/main/java/ru/bclib/mixin/common/shears/ItemPredicateBuilderMixin.java index 566f6ed0..b15d8082 100644 --- a/src/main/java/ru/bclib/mixin/common/shears/ItemPredicateBuilderMixin.java +++ b/src/main/java/ru/bclib/mixin/common/shears/ItemPredicateBuilderMixin.java @@ -1,6 +1,5 @@ package ru.bclib.mixin.common.shears; -import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.minecraft.advancements.critereon.ItemPredicate; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; @@ -24,7 +23,8 @@ public abstract class ItemPredicateBuilderMixin { @Inject(method = "matches", at = @At("HEAD"), cancellable = true) void bclib_of(ItemStack itemStack, CallbackInfoReturnable cir) { if (this.items != null && this.items.size() == 1 && this.items.contains(Items.SHEARS)) { - if (itemStack.is(CommonItemTags.SHEARS) || itemStack.is(FabricToolTags.SHEARS)){ + //TODO: 1.18.2 See if removing minable_shears test is having an efffect... + if (itemStack.is(CommonItemTags.SHEARS) ){ cir.setReturnValue(true); } } diff --git a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java index c689dcb8..61bec9ee 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java @@ -3,7 +3,7 @@ package ru.bclib.world.generator; import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.core.Registry; -import net.minecraft.resources.RegistryLookupCodec; +import net.minecraft.resources.RegistryOps; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome.BiomeCategory; @@ -29,13 +29,8 @@ import java.util.List; import java.util.function.Function; public class BCLibEndBiomeSource extends BCLBiomeSource { - public static final Codec CODEC = RecordCodecBuilder.create((instance) -> { - return instance.group(RegistryLookupCodec.create(Registry.BIOME_REGISTRY).forGetter((theEndBiomeSource) -> { - return theEndBiomeSource.biomeRegistry; - }), Codec.LONG.fieldOf("seed").stable().forGetter((theEndBiomeSource) -> { - return theEndBiomeSource.seed; - })).apply(instance, instance.stable(BCLibEndBiomeSource::new)); - }); + public static final Codec CODEC = RecordCodecBuilder.create((instance) -> instance.group(RegistryOps + .retrieveRegistry(Registry.BIOME_REGISTRY).forGetter((theEndBiomeSource) -> theEndBiomeSource.biomeRegistry), Codec.LONG.fieldOf("seed").stable().forGetter((theEndBiomeSource) -> theEndBiomeSource.seed)).apply(instance, instance.stable(BCLibEndBiomeSource::new))); private static final OpenSimplexNoise SMALL_NOISE = new OpenSimplexNoise(8324); private Function endLandFunction; diff --git a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java index 01365eba..a7509a95 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java @@ -3,7 +3,7 @@ package ru.bclib.world.generator; import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.core.Registry; -import net.minecraft.resources.RegistryLookupCodec; +import net.minecraft.resources.RegistryOps; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome.BiomeCategory; @@ -15,6 +15,7 @@ import ru.bclib.api.biomes.BiomeAPI; import ru.bclib.config.ConfigKeeper.StringArrayEntry; import ru.bclib.config.Configs; import ru.bclib.interfaces.BiomeMap; +import ru.bclib.mixin.common.BiomeAccessor; import ru.bclib.world.biomes.BCLBiome; import ru.bclib.world.generator.map.MapStack; import ru.bclib.world.generator.map.hex.HexBiomeMap; @@ -23,13 +24,22 @@ import ru.bclib.world.generator.map.square.SquareBiomeMap; import java.util.List; public class BCLibNetherBiomeSource extends BCLBiomeSource { - public static final Codec CODEC = RecordCodecBuilder.create((instance) -> { - return instance.group(RegistryLookupCodec.create(Registry.BIOME_REGISTRY).forGetter((theEndBiomeSource) -> { - return theEndBiomeSource.biomeRegistry; - }), Codec.LONG.fieldOf("seed").stable().forGetter((theEndBiomeSource) -> { - return theEndBiomeSource.seed; - })).apply(instance, instance.stable(BCLibNetherBiomeSource::new)); - }); + + public static final Codec CODEC = RecordCodecBuilder + .create(instance -> instance + .group(RegistryOps + .retrieveRegistry(Registry.BIOME_REGISTRY) + .forGetter(source -> source.biomeRegistry) + , + Codec + .LONG + .fieldOf("seed") + .stable() + .forGetter(source -> source.seed) + ) + .apply(instance, instance.stable(BCLibNetherBiomeSource::new)) + ); + private BiomeMap biomeMap; private static boolean forceLegacyGenerator = false; @@ -95,7 +105,7 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource { return true; } - if (GeneratorOptions.addNetherBiomesByCategory() && biome.getBiomeCategory() == BiomeCategory.NETHER) { + if (GeneratorOptions.addNetherBiomesByCategory() && (biome instanceof BiomeAccessor) && ((BiomeAccessor)(Object)biome).bclib_getBiomeCategory()== BiomeCategory.NETHER) { return true; } diff --git a/src/main/resources/bclib.accesswidener b/src/main/resources/bclib.accesswidener index 9fc24c46..5a5692b6 100644 --- a/src/main/resources/bclib.accesswidener +++ b/src/main/resources/bclib.accesswidener @@ -1,6 +1,7 @@ accessWidener v1 named # Classes +accessible class net/minecraft/server/MinecraftServer$ReloadableResources accessible class net/minecraft/client/Minecraft$ExperimentalDialogType accessible class net/minecraft/world/level/levelgen/SurfaceRules$Context accessible class net/minecraft/world/level/levelgen/SurfaceRules$Condition diff --git a/src/main/resources/bclib.mixins.client.json b/src/main/resources/bclib.mixins.client.json index ce5d3e64..0920d0e3 100644 --- a/src/main/resources/bclib.mixins.client.json +++ b/src/main/resources/bclib.mixins.client.json @@ -4,7 +4,6 @@ "package": "ru.bclib.mixin.client", "compatibilityLevel": "JAVA_17", "client": [ - "SimpleReloadableResourceManagerMixin", "EnchantingTableBlockMixin", "ClientRecipeBookMixin", "ModelManagerMixin", diff --git a/src/main/resources/bclib.mixins.common.json b/src/main/resources/bclib.mixins.common.json index 7c96df98..ecb56164 100644 --- a/src/main/resources/bclib.mixins.common.json +++ b/src/main/resources/bclib.mixins.common.json @@ -4,7 +4,6 @@ "package": "ru.bclib.mixin.common", "compatibilityLevel": "JAVA_17", "mixins": [ - "SimpleReloadableResourceManagerMixin", "BiomeGenerationSettingsAccessor", "shears.DiggingEnchantmentMixin", "shears.ItemPredicateBuilderMixin", @@ -42,7 +41,8 @@ "AnvilBlockMixin", "AnvilMenuMixin", "TagLoaderMixin", - "MainMixin" + "MainMixin", + "BiomeAccessor" ], "injectors": { "defaultRequire": 1 From 3c746a8dc4586f5069881af8c234798e686747dd Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 8 Mar 2022 21:27:21 +0100 Subject: [PATCH 05/34] Collected some info about new Feature System --- .../world/structures/BCLStructureFeature.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java b/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java index 9af93ebb..b00608f2 100644 --- a/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java +++ b/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java @@ -5,13 +5,18 @@ import net.fabricmc.fabric.api.structure.v1.FabricStructureBuilder; import net.minecraft.core.BlockPos; import net.minecraft.core.QuartPos; import net.minecraft.data.BuiltinRegistries; +import net.minecraft.data.worldgen.StructureFeatures; +import net.minecraft.data.worldgen.StructureSets; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.levelgen.GenerationStep; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; import net.minecraft.world.level.levelgen.feature.StructureFeature; import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.levelgen.structure.BuiltinStructures; import net.minecraft.world.level.levelgen.structure.pieces.PieceGeneratorSupplier; +import net.minecraft.world.level.levelgen.structure.placement.RandomSpreadStructurePlacement; +import net.minecraft.world.level.levelgen.structure.placement.RandomSpreadType; import java.util.List; import java.util.Random; @@ -27,6 +32,17 @@ public class BCLStructureFeature { public BCLStructureFeature(ResourceLocation id, StructureFeature structure, GenerationStep.Decoration step, int spacing, int separation) { this.id = id; this.featureStep = step; + //parts from vanilla for Structure generation + //public static final ResourceKey> JUNGLE_TEMPLE = + // BuiltinStructures.createKey("jungle_pyramid"); + //public static final Holder> JUNGLE_TEMPLE = + // StructureFeatures.register(BuiltinStructures.JUNGLE_TEMPLE, StructureFeature.JUNGLE_TEMPLE.configured(NoneFeatureConfiguration.INSTANCE, BiomeTags.HAS_JUNGLE_TEMPLE)); + //public static final Holder JUNGLE_TEMPLES = + // StructureSets.register(BuiltinStructureSets.JUNGLE_TEMPLES, StructureFeatures.JUNGLE_TEMPLE, new RandomSpreadStructurePlacement(32, 8, RandomSpreadType.LINEAR, 14357619)); + //public static final StructureFeature JUNGLE_TEMPLE = + // StructureFeature.register("jungle_pyramid", new JunglePyramidFeature(NoneFeatureConfiguration.CODEC), GenerationStep.Decoration.SURFACE_STRUCTURES); + // + final RandomSpreadStructurePlacement spreadConfig = new RandomSpreadStructurePlacement(spacing, separation, RandomSpreadType.LINEAR, RANDOM.nextInt(8192)); this.structure = FabricStructureBuilder .create(id, structure) .step(step) From 86a3480ce036a72ee1f7a4ce6268e2da597cdb64 Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 8 Mar 2022 22:02:24 +0100 Subject: [PATCH 06/34] Added first test code for new StructreFeature building --- .../ru/bclib/api/biomes/BCLBiomeBuilder.java | 3 +- src/main/java/ru/bclib/api/tag/TagAPI.java | 13 +++++++ .../common/StructureFeatureAccessor.java | 14 ++++++++ .../common/StructureFeaturesAccessor.java | 19 ++++++++++ .../ru/bclib/world/features/BCLFeature.java | 1 + .../world/structures/BCLStructureFeature.java | 35 ++++++++++++------- src/main/resources/bclib.mixins.common.json | 4 ++- 7 files changed, 74 insertions(+), 15 deletions(-) create mode 100644 src/main/java/ru/bclib/mixin/common/StructureFeatureAccessor.java create mode 100644 src/main/java/ru/bclib/mixin/common/StructureFeaturesAccessor.java diff --git a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java index a2ac6d70..034d2a65 100644 --- a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java @@ -1,6 +1,7 @@ package ru.bclib.api.biomes; import net.fabricmc.fabric.api.biome.v1.BiomeModifications; +import net.minecraft.core.Holder; import net.minecraft.core.particles.ParticleOptions; import net.minecraft.data.BuiltinRegistries; import net.minecraft.data.worldgen.BiomeDefaultFeatures; @@ -500,7 +501,7 @@ public class BCLBiomeBuilder { * @param feature {@link PlacedFeature}. * @return same {@link BCLBiomeBuilder} instance. */ - public BCLBiomeBuilder feature(Decoration decoration, PlacedFeature feature) { + public BCLBiomeBuilder feature(Decoration decoration, Holder feature) { getGeneration().addFeature(decoration, feature); return this; } diff --git a/src/main/java/ru/bclib/api/tag/TagAPI.java b/src/main/java/ru/bclib/api/tag/TagAPI.java index f5312f20..a3b0da16 100644 --- a/src/main/java/ru/bclib/api/tag/TagAPI.java +++ b/src/main/java/ru/bclib/api/tag/TagAPI.java @@ -11,6 +11,7 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.ItemLike; +import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import ru.bclib.mixin.common.DiggerItemAccessor; @@ -38,6 +39,18 @@ public class TagAPI { .findAny() .orElse(TagKey.create(registry.key(), id)); } + + /** + * Get or create {@link Block} {@link TagKey} with mod namespace. + * + * @param modID - {@link String} mod namespace (mod id); + * @param name - {@link String} tag name. + * @return {@link Block} {@link TagKey}. + */ + public static TagKey makeBiomeTag(String modID, String name) { + return TagKey.create(Registry.BIOME_REGISTRY, new ResourceLocation(modID, name)); + } + /** * Get or create {@link Block} {@link TagKey} with mod namespace. diff --git a/src/main/java/ru/bclib/mixin/common/StructureFeatureAccessor.java b/src/main/java/ru/bclib/mixin/common/StructureFeatureAccessor.java new file mode 100644 index 00000000..03a5a498 --- /dev/null +++ b/src/main/java/ru/bclib/mixin/common/StructureFeatureAccessor.java @@ -0,0 +1,14 @@ +package ru.bclib.mixin.common; + +import net.minecraft.world.level.levelgen.GenerationStep; +import net.minecraft.world.level.levelgen.feature.StructureFeature; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(StructureFeature.class) +public interface StructureFeatureAccessor { + @Invoker + static > F callRegister(String name, F structureFeature, GenerationStep.Decoration step) { + throw new RuntimeException("Unexpected call"); + } +} diff --git a/src/main/java/ru/bclib/mixin/common/StructureFeaturesAccessor.java b/src/main/java/ru/bclib/mixin/common/StructureFeaturesAccessor.java new file mode 100644 index 00000000..5ba97fdd --- /dev/null +++ b/src/main/java/ru/bclib/mixin/common/StructureFeaturesAccessor.java @@ -0,0 +1,19 @@ +package ru.bclib.mixin.common; + +import net.minecraft.core.Holder; +import net.minecraft.data.worldgen.StructureFeatures; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.levelgen.GenerationStep; +import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; +import net.minecraft.world.level.levelgen.feature.StructureFeature; +import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(StructureFeatures.class) +public interface StructureFeaturesAccessor { + @Invoker + static > Holder> callRegister(ResourceKey> resourceKey, ConfiguredStructureFeature configuredStructureFeature) { + throw new RuntimeException("Unexpected call"); + } +} diff --git a/src/main/java/ru/bclib/world/features/BCLFeature.java b/src/main/java/ru/bclib/world/features/BCLFeature.java index fef17cda..8c649c43 100644 --- a/src/main/java/ru/bclib/world/features/BCLFeature.java +++ b/src/main/java/ru/bclib/world/features/BCLFeature.java @@ -1,5 +1,6 @@ package ru.bclib.world.features; +import net.minecraft.core.Holder; import net.minecraft.core.Registry; import net.minecraft.data.BuiltinRegistries; import net.minecraft.resources.ResourceKey; diff --git a/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java b/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java index b00608f2..983bd44c 100644 --- a/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java +++ b/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java @@ -1,22 +1,27 @@ package ru.bclib.world.structures; import com.google.common.collect.Lists; -import net.fabricmc.fabric.api.structure.v1.FabricStructureBuilder; import net.minecraft.core.BlockPos; +import net.minecraft.core.Holder; import net.minecraft.core.QuartPos; -import net.minecraft.data.BuiltinRegistries; -import net.minecraft.data.worldgen.StructureFeatures; +import net.minecraft.core.Registry; import net.minecraft.data.worldgen.StructureSets; +import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.TagKey; +import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.levelgen.GenerationStep; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; import net.minecraft.world.level.levelgen.feature.StructureFeature; import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; -import net.minecraft.world.level.levelgen.structure.BuiltinStructures; +import net.minecraft.world.level.levelgen.structure.StructureSet; import net.minecraft.world.level.levelgen.structure.pieces.PieceGeneratorSupplier; import net.minecraft.world.level.levelgen.structure.placement.RandomSpreadStructurePlacement; import net.minecraft.world.level.levelgen.structure.placement.RandomSpreadType; +import ru.bclib.api.tag.TagAPI; +import ru.bclib.mixin.common.StructureFeatureAccessor; +import ru.bclib.mixin.common.StructureFeaturesAccessor; import java.util.List; import java.util.Random; @@ -24,11 +29,14 @@ import java.util.Random; public class BCLStructureFeature { private static final Random RANDOM = new Random(354); private final StructureFeature structure; - private final ConfiguredStructureFeature featureConfigured; + private final Holder> featureConfigured; private final GenerationStep.Decoration featureStep; private final List biomes = Lists.newArrayList(); private final ResourceLocation id; - + public final TagKey biomeTag; + public final ResourceKey> structureKey; + public final ResourceKey structureSetKey; + public BCLStructureFeature(ResourceLocation id, StructureFeature structure, GenerationStep.Decoration step, int spacing, int separation) { this.id = id; this.featureStep = step; @@ -42,14 +50,15 @@ public class BCLStructureFeature { //public static final StructureFeature JUNGLE_TEMPLE = // StructureFeature.register("jungle_pyramid", new JunglePyramidFeature(NoneFeatureConfiguration.CODEC), GenerationStep.Decoration.SURFACE_STRUCTURES); // + final RandomSpreadStructurePlacement spreadConfig = new RandomSpreadStructurePlacement(spacing, separation, RandomSpreadType.LINEAR, RANDOM.nextInt(8192)); - this.structure = FabricStructureBuilder - .create(id, structure) - .step(step) - .defaultConfig(spacing, separation, RANDOM.nextInt(8192)) - .register(); - this.featureConfigured = this.structure.configured(NoneFeatureConfiguration.NONE); - BuiltinRegistries.register(BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE, id, this.featureConfigured); + this.structureKey = ResourceKey.create(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY, id); + this.structureSetKey = ResourceKey.create(Registry.STRUCTURE_SET_REGISTRY, id); + + this.biomeTag = TagAPI.makeBiomeTag(id.getNamespace(), "has_structure/"+id.getPath()); + this.structure = StructureFeatureAccessor.callRegister(id.toString(), structure, step); + this.featureConfigured = StructureFeaturesAccessor.callRegister(structureKey, this.structure.configured(NoneFeatureConfiguration.NONE, biomeTag)); + StructureSets.register(structureSetKey, featureConfigured, spreadConfig); //TODO: 1.18 check if structures are added correctly //FlatChunkGeneratorConfigAccessor.getStructureToFeatures().put(this.structure, this.featureConfigured); } diff --git a/src/main/resources/bclib.mixins.common.json b/src/main/resources/bclib.mixins.common.json index ecb56164..50f21ce8 100644 --- a/src/main/resources/bclib.mixins.common.json +++ b/src/main/resources/bclib.mixins.common.json @@ -42,7 +42,9 @@ "AnvilMenuMixin", "TagLoaderMixin", "MainMixin", - "BiomeAccessor" + "BiomeAccessor", + "StructureFeatureAccessor", + "StructureFeaturesAccessor" ], "injectors": { "defaultRequire": 1 From ff70a2b1a8488020c1e42b9be9cf11a2ff9afab7 Mon Sep 17 00:00:00 2001 From: Frank Date: Mon, 14 Mar 2022 16:42:54 +0100 Subject: [PATCH 07/34] Changes related to Biome-Holders and Features --- src/main/java/ru/bclib/api/LifeCycleAPI.java | 5 +- .../ru/bclib/api/biomes/BCLBiomeBuilder.java | 14 +- .../java/ru/bclib/api/biomes/BiomeAPI.java | 126 ++++++++++-------- .../bclib/api/surface/SurfaceRuleBuilder.java | 10 +- .../java/ru/bclib/blocks/BaseCropBlock.java | 3 +- .../ru/bclib/blocks/BaseDoublePlantBlock.java | 7 +- .../java/ru/bclib/blocks/BasePlantBlock.java | 7 +- .../bclib/blocks/BasePlantWithAgeBlock.java | 3 +- .../blocks/BaseUnderwaterWallPlantBlock.java | 6 +- .../java/ru/bclib/blocks/BaseVineBlock.java | 4 +- .../ru/bclib/blocks/BaseWallPlantBlock.java | 6 +- .../ru/bclib/blocks/FeatureSaplingBlock.java | 6 +- .../ru/bclib/blocks/UnderwaterPlantBlock.java | 7 +- .../blocks/UnderwaterPlantWithAgeBlock.java | 3 +- .../ru/bclib/blocks/UpDownPlantBlock.java | 4 +- .../ru/bclib/blocks/WallMushroomBlock.java | 3 +- .../client/render/CustomFogRenderer.java | 4 +- .../ru/bclib/integration/ModIntegration.java | 7 +- .../BiomeGenerationSettingsAccessor.java | 9 +- .../bclib/mixin/common/ServerLevelMixin.java | 6 +- .../java/ru/bclib/recipes/AnvilRecipe.java | 7 +- .../java/ru/bclib/recipes/GridRecipe.java | 3 +- .../ru/bclib/recipes/SmithingTableRecipe.java | 5 +- .../java/ru/bclib/world/biomes/BCLBiome.java | 16 ++- .../ru/bclib/world/features/BCLFeature.java | 103 +------------- .../world/features/NBTStructureFeature.java | 7 +- .../bclib/world/generator/BCLBiomeSource.java | 7 +- .../world/generator/BCLibEndBiomeSource.java | 30 +++-- .../generator/BCLibNetherBiomeSource.java | 2 +- .../world/structures/BCLStructureFeature.java | 2 +- 30 files changed, 200 insertions(+), 222 deletions(-) diff --git a/src/main/java/ru/bclib/api/LifeCycleAPI.java b/src/main/java/ru/bclib/api/LifeCycleAPI.java index c6afcb20..cf403cd0 100644 --- a/src/main/java/ru/bclib/api/LifeCycleAPI.java +++ b/src/main/java/ru/bclib/api/LifeCycleAPI.java @@ -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; @@ -49,7 +50,7 @@ public class LifeCycleAPI { LevelStorageSource.LevelStorageAccess levelStorageAccess, ServerLevelData serverLevelData, ResourceKey resourceKey, - DimensionType dimensionType, + Holder dimensionType, ChunkProgressListener chunkProgressListener, ChunkGenerator chunkGenerator, boolean bl, @@ -114,7 +115,7 @@ public class LifeCycleAPI { LevelStorageSource.LevelStorageAccess levelStorageAccess, ServerLevelData serverLevelData, ResourceKey resourceKey, - DimensionType dimensionType, + Holder dimensionType, ChunkProgressListener chunkProgressListener, ChunkGenerator chunkGenerator, boolean bl, diff --git a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java index 034d2a65..cc01ec0c 100644 --- a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java @@ -2,9 +2,12 @@ package ru.bclib.api.biomes; import net.fabricmc.fabric.api.biome.v1.BiomeModifications; import net.minecraft.core.Holder; +import net.minecraft.core.HolderSet; +import net.minecraft.core.Registry; 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; @@ -546,8 +549,8 @@ public class BCLBiomeBuilder { * @param structure {@link ConfiguredStructureFeature} to add. * @return same {@link BCLBiomeBuilder} instance. */ - public BCLBiomeBuilder structure(ConfiguredStructureFeature structure) { - structures.add(structure); + public BCLBiomeBuilder structure(Holder> structure) { + structures.add(structure.value()); return this; } @@ -672,7 +675,7 @@ public class BCLBiomeBuilder { builder.mobSpawnSettings(getSpawns().build()); builder.specialEffects(getEffects().build()); - Map>> defferedFeatures = new HashMap<>(); + Map> defferedFeatures = new HashMap<>(); BiomeGenerationSettingsAccessor acc = BiomeGenerationSettingsAccessor.class.cast(getGeneration().build()); if (acc != null) { builder.generationSettings(new BiomeGenerationSettings.Builder().build()); @@ -700,8 +703,9 @@ public class BCLBiomeBuilder { .setEdge(edge) .setVertical(vertical) .build(); - - final T res = biomeConstructor.apply(biomeID, builder.build(), settings); + + final Biome biome = builder.build(); + final T res = biomeConstructor.apply(biomeID, biome, settings); res.attachStructures(structures); res.setSurface(surfaceRule); res.setFeatures(defferedFeatures); diff --git a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java index 53fa2988..d0a466e3 100644 --- a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java @@ -10,6 +10,7 @@ import net.fabricmc.fabric.impl.biome.TheEndBiomeData; import net.minecraft.client.Minecraft; import net.minecraft.core.BlockPos; import net.minecraft.core.Holder; +import net.minecraft.core.HolderSet; import net.minecraft.core.Registry; import net.minecraft.data.BuiltinRegistries; import net.minecraft.resources.ResourceKey; @@ -74,28 +75,28 @@ public class BiomeAPI { private static final Map ID_MAP = Maps.newHashMap(); private static final Map CLIENT = Maps.newHashMap(); - private static Registry biomeRegistry; + private static Registry> biomeRegistry; private static final Map FEATURE_ORDER = Maps.newHashMap(); private static final MutableInt FEATURE_ORDER_ID = new MutableInt(0); - private static final Map>> MODIFICATIONS = Maps.newHashMap(); + private static final Map>>> MODIFICATIONS = Maps.newHashMap(); private static final Map SURFACE_RULES = Maps.newHashMap(); private static final Set MODIFIED_SURFACE_PROVIDERS = new HashSet<>(8); - public static final BCLBiome NETHER_WASTES_BIOME = registerNetherBiome(getFromRegistry(Biomes.NETHER_WASTES)); - public static final BCLBiome CRIMSON_FOREST_BIOME = registerNetherBiome(getFromRegistry(Biomes.CRIMSON_FOREST)); - public static final BCLBiome WARPED_FOREST_BIOME = registerNetherBiome(getFromRegistry(Biomes.WARPED_FOREST)); - public static final BCLBiome SOUL_SAND_VALLEY_BIOME = registerNetherBiome(getFromRegistry(Biomes.SOUL_SAND_VALLEY)); - public static final BCLBiome BASALT_DELTAS_BIOME = registerNetherBiome(getFromRegistry(Biomes.BASALT_DELTAS)); + public static final BCLBiome NETHER_WASTES_BIOME = registerNetherBiome(getFromRegistry(Biomes.NETHER_WASTES).value()); + public static final BCLBiome CRIMSON_FOREST_BIOME = registerNetherBiome(getFromRegistry(Biomes.CRIMSON_FOREST).value()); + public static final BCLBiome WARPED_FOREST_BIOME = registerNetherBiome(getFromRegistry(Biomes.WARPED_FOREST).value()); + public static final BCLBiome SOUL_SAND_VALLEY_BIOME = registerNetherBiome(getFromRegistry(Biomes.SOUL_SAND_VALLEY).value()); + public static final BCLBiome BASALT_DELTAS_BIOME = registerNetherBiome(getFromRegistry(Biomes.BASALT_DELTAS).value()); - public static final BCLBiome THE_END = registerEndLandBiome(getFromRegistry(Biomes.THE_END)); - public static final BCLBiome END_MIDLANDS = registerSubBiome(THE_END, getFromRegistry(Biomes.END_MIDLANDS), 0.5F); - public static final BCLBiome END_HIGHLANDS = registerSubBiome(THE_END, getFromRegistry(Biomes.END_HIGHLANDS), 0.5F); - - public static final BCLBiome END_BARRENS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("end_barrens"))); - public static final BCLBiome SMALL_END_ISLANDS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("small_end_islands"))); + public static final BCLBiome THE_END = registerEndLandBiome(getFromRegistry(Biomes.THE_END).value()); + public static final BCLBiome END_MIDLANDS = registerSubBiome(THE_END, getFromRegistry(Biomes.END_MIDLANDS).value(), 0.5F); + public static final BCLBiome END_HIGHLANDS = registerSubBiome(THE_END, getFromRegistry(Biomes.END_HIGHLANDS).value(), 0.5F); + public static final BCLBiome END_BARRENS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("end_barrens")).value()); + public static final BCLBiome SMALL_END_ISLANDS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("small_end_islands")).value()); + private static void initFeatureOrder() { if (!FEATURE_ORDER.isEmpty()) { return; @@ -113,7 +114,7 @@ public class BiomeAPI { .map(biome -> (BiomeGenerationSettingsAccessor) biome.getGenerationSettings()) .map(BiomeGenerationSettingsAccessor::bclib_getFeatures) .forEach(stepFeatureSuppliers -> stepFeatureSuppliers.forEach(step -> step.forEach(featureSupplier -> { - PlacedFeature feature = featureSupplier.get(); + PlacedFeature feature = featureSupplier.value(); FEATURE_ORDER.computeIfAbsent(feature, f -> FEATURE_ORDER_ID.getAndIncrement()); }))); } @@ -122,7 +123,7 @@ public class BiomeAPI { * Initialize registry for current server. * @param biomeRegistry - {@link Registry} for {@link Biome}. */ - public static void initRegistry(Registry biomeRegistry) { + public static void initRegistry(Registry> biomeRegistry) { if (biomeRegistry != BiomeAPI.biomeRegistry) { BiomeAPI.biomeRegistry = biomeRegistry; CLIENT.clear(); @@ -185,7 +186,7 @@ public class BiomeAPI { MHelper.randRange(-1.5F, 1.5F, random), random.nextFloat() ); - ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).orElseThrow(); + ResourceKey key = BiomeAPI.getBiomeKeyOrThrow(biome.getBiomeHolder()); NetherBiomeData.addNetherBiome(key, parameters); return biome; } @@ -215,7 +216,7 @@ public class BiomeAPI { END_LAND_BIOME_PICKER.addBiome(biome); float weight = biome.getGenChance(); - ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).orElseThrow(); + ResourceKey key = BiomeAPI.getBiomeKey(biome.getBiome()); TheEndBiomeData.addEndBiomeReplacement(Biomes.END_HIGHLANDS, key, weight); TheEndBiomeData.addEndBiomeReplacement(Biomes.END_MIDLANDS, key, weight); return biome; @@ -261,7 +262,7 @@ public class BiomeAPI { END_VOID_BIOME_PICKER.addBiome(biome); float weight = biome.getGenChance(); - ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).orElseThrow(); + ResourceKey key = BiomeAPI.getBiomeKeyOrThrow(biome.getBiomeHolder()); TheEndBiomeData.addEndBiomeReplacement(Biomes.SMALL_END_ISLANDS, key, weight); return biome; } @@ -300,7 +301,7 @@ public class BiomeAPI { * @param biome - {@link Biome} from world. * @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}. */ - public static BCLBiome getFromBiome(Biome biome) { + public static BCLBiome getFromBiome(Holder biome) { if (biomeRegistry == null) { return EMPTY_BIOME; } @@ -333,7 +334,7 @@ public class BiomeAPI { public static ResourceKey getBiomeKey(Biome biome) { return BuiltinRegistries.BIOME .getResourceKey(biome) - .orElseGet(() -> biomeRegistry != null ? biomeRegistry.getResourceKey(biome).orElse(null) : null); + .orElse(null); } /** @@ -343,9 +344,9 @@ public class BiomeAPI { */ public static ResourceLocation getBiomeID(Biome biome) { ResourceLocation id = BuiltinRegistries.BIOME.getKey(biome); - if (id == null && biomeRegistry != null) { - id = biomeRegistry.getKey(biome); - } + // if (id == null && biomeRegistry != null) { + // id = biomeRegistry.getKey(biome); + //} return id == null ? EMPTY_BIOME.getID() : id; } @@ -361,6 +362,14 @@ public class BiomeAPI { } return null; } + + public static ResourceKey getBiomeKey(Holder biome) { + return biome.unwrapKey().orElse(null); + } + + public static ResourceKey getBiomeKeyOrThrow(Holder biome) { + return biome.unwrapKey().orElseThrow(); + } /** * Get {@link BCLBiome} from given {@link ResourceLocation}. @@ -404,31 +413,31 @@ public class BiomeAPI { public static void loadFabricAPIBiomes() { FabricBiomesData.NETHER_BIOMES.forEach((key) -> { if (!hasBiome(key.location())) { - registerNetherBiome(BuiltinRegistries.BIOME.get(key.location())); + registerNetherBiome(BuiltinRegistries.BIOME.get(key)); } }); FabricBiomesData.END_LAND_BIOMES.forEach((key, weight) -> { if (!hasBiome(key.location())) { - registerEndLandBiome(BuiltinRegistries.BIOME.get(key.location()), weight); + registerEndLandBiome(BuiltinRegistries.BIOME.get(key), weight); } }); FabricBiomesData.END_VOID_BIOMES.forEach((key, weight) -> { if (!hasBiome(key.location())) { - registerEndVoidBiome(BuiltinRegistries.BIOME.get(key.location()), weight); + registerEndVoidBiome(BuiltinRegistries.BIOME.get(key), weight); } }); } @Nullable - public static Biome getFromRegistry(ResourceLocation key) { - return BuiltinRegistries.BIOME.get(key); + public static Holder getFromRegistry(ResourceLocation key) { + return BuiltinRegistries.BIOME.getHolder(ResourceKey.create(Registry.BIOME_REGISTRY, key)).orElseThrow(); } @Nullable - public static Biome getFromRegistry(ResourceKey key) { - return BuiltinRegistries.BIOME.get(key); + public static Holder getFromRegistry(ResourceKey key) { + return BuiltinRegistries.BIOME.getOrCreateHolder(key); } public static boolean isDatapackBiome(ResourceLocation biomeID) { @@ -452,8 +461,8 @@ public class BiomeAPI { * @param dimensionID {@link ResourceLocation} dimension ID, example: Level.OVERWORLD or "minecraft:overworld". * @param modification {@link BiConsumer} with {@link ResourceKey} biome ID and {@link Biome} parameters. */ - public static void registerBiomeModification(ResourceKey dimensionID, BiConsumer modification) { - List> modifications = MODIFICATIONS.computeIfAbsent(dimensionID, k -> Lists.newArrayList()); + public static void registerBiomeModification(ResourceKey dimensionID, BiConsumer> modification) { + List>> modifications = MODIFICATIONS.computeIfAbsent(dimensionID, k -> Lists.newArrayList()); modifications.add(modification); } @@ -461,7 +470,7 @@ public class BiomeAPI { * Registers new biome modification for the Overworld. Will work both for mod and datapack biomes. * @param modification {@link BiConsumer} with {@link ResourceLocation} biome ID and {@link Biome} parameters. */ - public static void registerOverworldBiomeModification(BiConsumer modification) { + public static void registerOverworldBiomeModification(BiConsumer> modification) { registerBiomeModification(Level.OVERWORLD, modification); } @@ -469,7 +478,7 @@ public class BiomeAPI { * Registers new biome modification for the Nether. Will work both for mod and datapack biomes. * @param modification {@link BiConsumer} with {@link ResourceLocation} biome ID and {@link Biome} parameters. */ - public static void registerNetherBiomeModification(BiConsumer modification) { + public static void registerNetherBiomeModification(BiConsumer> modification) { registerBiomeModification(Level.NETHER, modification); } @@ -477,7 +486,7 @@ public class BiomeAPI { * Registers new biome modification for the End. Will work both for mod and datapack biomes. * @param modification {@link BiConsumer} with {@link ResourceLocation} biome ID and {@link Biome} parameters. */ - public static void registerEndBiomeModification(BiConsumer modification) { + public static void registerEndBiomeModification(BiConsumer> modification) { registerBiomeModification(Level.END, modification); } @@ -524,10 +533,10 @@ public class BiomeAPI { } } - List> modifications = MODIFICATIONS.get(level.dimension()); + List>> modifications = MODIFICATIONS.get(level.dimension()); for (Holder biomeHolder : biomes) { if (biomeHolder.isBound()) { - applyModificationsAndUpdateFeatures(modifications, biomeHolder.value()); + applyModificationsAndUpdateFeatures(modifications, biomeHolder); } } @@ -547,7 +556,7 @@ public class BiomeAPI { ((BiomeSourceAccessor) source).bclRebuildFeatures(); } - private static void applyModificationsAndUpdateFeatures(List> modifications, Biome biome) { + private static void applyModificationsAndUpdateFeatures(List>> modifications, Holder biome) { ResourceLocation biomeID = getBiomeID(biome); if (modifications!=null) { modifications.forEach(consumer -> { @@ -567,8 +576,8 @@ public class BiomeAPI { * Create a unique sort order for all Features of the Biome * @param biome The {@link Biome} to sort the features for */ - public static void sortBiomeFeatures(Biome biome) { - BiomeGenerationSettings settings = biome.getGenerationSettings(); + public static void sortBiomeFeatures(Holder biome) { + BiomeGenerationSettings settings = biome.value().getGenerationSettings(); BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) settings; List>> featureList = CollectionsUtil.getMutable(accessor.bclib_getFeatures()); final int size = featureList.size(); @@ -623,7 +632,7 @@ public class BiomeAPI { * @param feature {@link ConfiguredFeature} to add. * */ - public static void addBiomeFeature(Biome biome, BCLFeature feature) { + public static void addBiomeFeature(Holder biome, BCLFeature feature) { addBiomeFeature(biome, feature.getDecoration(), feature.getPlacedFeature()); } @@ -633,7 +642,7 @@ public class BiomeAPI { * @param step a {@link Decoration} step for the feature. * @param featureList {@link ConfiguredFeature} to add. */ - public static void addBiomeFeature(Biome biome, Decoration step, PlacedFeature... featureList) { + public static void addBiomeFeature(Holder biome, Decoration step, Holder... featureList) { addBiomeFeature(biome, step, List.of(featureList)); } @@ -643,12 +652,13 @@ public class BiomeAPI { * @param step a {@link Decoration} step for the feature. * @param featureList List of {@link ConfiguredFeature} to add. */ - private static void addBiomeFeature(Biome biome, Decoration step, List featureList) { - BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings(); - List>> allFeatures = CollectionsUtil.getMutable(accessor.bclib_getFeatures()); + private static void addBiomeFeature(Holder biome, Decoration step, List> featureList) { + BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.value().getGenerationSettings(); + List> allFeatures = CollectionsUtil.getMutable(accessor.bclib_getFeatures()); Set set = CollectionsUtil.getMutable(accessor.bclib_getFeatureSet().get()); - List> features = getFeaturesList(allFeatures, step); + HolderSet features = getFeaturesList(allFeatures, step); for (var feature : featureList) { + features. features.add(() -> feature); set.add(feature); } @@ -659,13 +669,13 @@ public class BiomeAPI { /** * For internal use only! * - * Adds new features to existing biome. Called from {@link #applyModificationsAndUpdateFeatures(List, Biome)} when the Biome is + * Adds new features to existing biome. Called from {@link #applyModificationsAndUpdateFeatures(List, Holder)}} when the Biome is * present in any {@link BiomeSource} * @param biome {@link Biome} to add features in. * @param featureMap Map of {@link ConfiguredFeature} to add. */ - private static void addStepFeaturesToBiome(Biome biome, Map>> featureMap) { - BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings(); + private static void addStepFeaturesToBiome(Holder biome, Map>> featureMap) { + BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.value().getGenerationSettings(); List>> allFeatures = CollectionsUtil.getMutable(accessor.bclib_getFeatures()); Set set = CollectionsUtil.getMutable(accessor.bclib_getFeatureSet().get()); @@ -690,8 +700,8 @@ public class BiomeAPI { */ public static void addBiomeCarver(Biome biome, ConfiguredWorldCarver carver, Carving stage) { BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings(); - Map>>> carvers = CollectionsUtil.getMutable(accessor.bclib_getCarvers()); - List>> carverList = CollectionsUtil.getMutable(carvers.getOrDefault(stage, new ArrayList<>())); + Map>> carvers = CollectionsUtil.getMutable(accessor.bclib_getCarvers()); + HolderSet> carverList = CollectionsUtil.getMutable(carvers.getOrDefault(stage, new ArrayList<>())); carvers.put(stage, carverList); carverList.add(() -> carver); accessor.bclib_setCarvers(carvers); @@ -769,6 +779,10 @@ public class BiomeAPI { return findTopMaterial(getBiome(world.getBiome(pos))); } + public static Optional findTopMaterial(Holder biome){ + return findTopMaterial(getBiome(biome.value())); + } + public static Optional findTopMaterial(Biome biome){ return findTopMaterial(getBiome(biome)); } @@ -784,6 +798,10 @@ public class BiomeAPI { return findUnderMaterial(getBiome(world.getBiome(pos))); } + public static Optional findUnderMaterial(Holder biome){ + return findUnderMaterial(getBiome(biome.value())); + } + public static Optional findUnderMaterial(Biome biome){ return findUnderMaterial(getBiome(biome)); } @@ -887,12 +905,12 @@ public class BiomeAPI { return list; } - private static List> getFeaturesList(List>> features, Decoration step) { + private static HolderSet getFeaturesList(List> features, Decoration step) { int index = step.ordinal(); while (features.size() <= index) { - features.add(Lists.newArrayList()); + features.add(HolderSet.direct(Lists.newArrayList())); } - List> mutable = CollectionsUtil.getMutable(features.get(index)); + HolderSet mutable = features.get(index); features.set(index, mutable); return mutable; } diff --git a/src/main/java/ru/bclib/api/surface/SurfaceRuleBuilder.java b/src/main/java/ru/bclib/api/surface/SurfaceRuleBuilder.java index bd88f2c1..2e6a14c5 100644 --- a/src/main/java/ru/bclib/api/surface/SurfaceRuleBuilder.java +++ b/src/main/java/ru/bclib/api/surface/SurfaceRuleBuilder.java @@ -75,7 +75,7 @@ public class SurfaceRuleBuilder { public SurfaceRuleBuilder subsurface(BlockState state, int depth) { entryInstance = getFromCache("subsurface_" + depth + "_" + state.toString(), () -> { RuleSource rule = SurfaceRules.state(state); - rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(depth, false, false, CaveSurface.FLOOR), rule); + rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(depth, false, CaveSurface.FLOOR), rule); return new SurfaceRuleEntry(3, rule); }); rules.add(entryInstance); @@ -117,7 +117,7 @@ public class SurfaceRuleBuilder { public SurfaceRuleBuilder belowFloor(BlockState state, int height, NoiseCondition noise) { entryInstance = getFromCache("below_floor_" + height + "_" + state.toString() + "_" + noise.getClass().getSimpleName(), () -> { RuleSource rule = SurfaceRules.state(state); - rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(height, false, false, CaveSurface.FLOOR), SurfaceRules.ifTrue(noise, rule)); + rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(height, false, CaveSurface.FLOOR), SurfaceRules.ifTrue(noise, rule)); return new SurfaceRuleEntry(3, rule); }); rules.add(entryInstance); @@ -133,7 +133,7 @@ public class SurfaceRuleBuilder { public SurfaceRuleBuilder belowFloor(BlockState state, int height) { entryInstance = getFromCache("below_floor_" + height + "_" + state.toString(), () -> { RuleSource rule = SurfaceRules.state(state); - rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(height, false, false, CaveSurface.FLOOR), rule); + rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(height, false, CaveSurface.FLOOR), rule); return new SurfaceRuleEntry(3, rule); }); rules.add(entryInstance); @@ -163,7 +163,7 @@ public class SurfaceRuleBuilder { public SurfaceRuleBuilder aboveCeil(BlockState state, int height) { entryInstance = getFromCache("above_ceil_" + height + "_" + state.toString(), () -> { RuleSource rule = SurfaceRules.state(state); - rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(height, false, false, CaveSurface.CEILING), rule); + rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(height, false, CaveSurface.CEILING), rule); return new SurfaceRuleEntry(3, rule); }); rules.add(entryInstance); @@ -179,7 +179,7 @@ public class SurfaceRuleBuilder { public SurfaceRuleBuilder steep(BlockState state, int depth) { entryInstance = getFromCache("steep_" + depth + "_" + state.toString(), () -> { RuleSource rule = SurfaceRules.state(state); - rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(depth, false, false, CaveSurface.FLOOR), rule); + rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(depth, false, CaveSurface.FLOOR), rule); rule = SurfaceRules.ifTrue(SurfaceRules.steep(), rule); int priority = depth < 1 ? 0 : 1; return new SurfaceRuleEntry(priority, rule); diff --git a/src/main/java/ru/bclib/blocks/BaseCropBlock.java b/src/main/java/ru/bclib/blocks/BaseCropBlock.java index 72f7f20a..007db2b3 100644 --- a/src/main/java/ru/bclib/blocks/BaseCropBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseCropBlock.java @@ -39,7 +39,8 @@ public class BaseCropBlock extends BasePlantBlock { public BaseCropBlock(Item drop, Block... terrain) { this( FabricBlockSettings.of(Material.PLANT) - .breakByHand(true) + //TODO: 1.18.2 Check if this is still ok + //.breakByHand(true) .sound(SoundType.GRASS) .randomTicks() .noCollission(), diff --git a/src/main/java/ru/bclib/blocks/BaseDoublePlantBlock.java b/src/main/java/ru/bclib/blocks/BaseDoublePlantBlock.java index 02ae6b35..49b2e34b 100644 --- a/src/main/java/ru/bclib/blocks/BaseDoublePlantBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseDoublePlantBlock.java @@ -31,6 +31,7 @@ import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.interfaces.RenderLayerProvider; +import ru.bclib.items.tool.BaseShearsItem; import ru.bclib.util.BlocksHelper; import java.util.List; @@ -54,7 +55,8 @@ public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements R public BaseDoublePlantBlock(int light) { this( FabricBlockSettings.of(Material.PLANT) - .breakByHand(true) + //TODO: 1.18.2 Check if this is still ok + //.breakByHand(true) .sound(SoundType.GRASS) .lightLevel((state) -> state.getValue(TOP) ? light : 0) .noCollission() @@ -117,7 +119,8 @@ public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements R } ItemStack tool = builder.getParameter(LootContextParams.TOOL); - if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel( + //TODO: 1.18.2 Test if shearing still works + if (tool != null && BaseShearsItem.isShear(tool) || EnchantmentHelper.getItemEnchantmentLevel( Enchantments.SILK_TOUCH, tool ) > 0) { diff --git a/src/main/java/ru/bclib/blocks/BasePlantBlock.java b/src/main/java/ru/bclib/blocks/BasePlantBlock.java index eaffbcdc..a036fdc1 100644 --- a/src/main/java/ru/bclib/blocks/BasePlantBlock.java +++ b/src/main/java/ru/bclib/blocks/BasePlantBlock.java @@ -39,6 +39,7 @@ import ru.bclib.client.models.PatternsHelper; import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.interfaces.RenderLayerProvider; import ru.bclib.interfaces.TagProvider; +import ru.bclib.items.tool.BaseShearsItem; import java.util.List; import java.util.Optional; @@ -70,7 +71,8 @@ public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderL this( FabricBlockSettings .of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT) - .breakByHand(true) + //TODO: 1.18.2 Check if this is still ok + //.breakByHand(true) .luminance(light) .sound(SoundType.GRASS) .noCollission() @@ -116,7 +118,8 @@ public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderL @Override public List getDrops(BlockState state, LootContext.Builder builder) { ItemStack tool = builder.getParameter(LootContextParams.TOOL); - if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel( + //TODO: 1.18.2 Test if shearing still works + if (tool != null && BaseShearsItem.isShear(tool) || EnchantmentHelper.getItemEnchantmentLevel( Enchantments.SILK_TOUCH, tool ) > 0) { diff --git a/src/main/java/ru/bclib/blocks/BasePlantWithAgeBlock.java b/src/main/java/ru/bclib/blocks/BasePlantWithAgeBlock.java index 3beb20d8..56f8b375 100644 --- a/src/main/java/ru/bclib/blocks/BasePlantWithAgeBlock.java +++ b/src/main/java/ru/bclib/blocks/BasePlantWithAgeBlock.java @@ -20,7 +20,8 @@ public abstract class BasePlantWithAgeBlock extends BasePlantBlock { public BasePlantWithAgeBlock() { this( FabricBlockSettings.of(Material.PLANT) - .breakByHand(true) + //TODO: 1.18.2 Check if this is still ok + //.breakByHand(true) .sound(SoundType.GRASS) .randomTicks() .noCollission() diff --git a/src/main/java/ru/bclib/blocks/BaseUnderwaterWallPlantBlock.java b/src/main/java/ru/bclib/blocks/BaseUnderwaterWallPlantBlock.java index e8fc1233..d45fb308 100644 --- a/src/main/java/ru/bclib/blocks/BaseUnderwaterWallPlantBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseUnderwaterWallPlantBlock.java @@ -18,7 +18,8 @@ public abstract class BaseUnderwaterWallPlantBlock extends BaseWallPlantBlock im this( FabricBlockSettings .of(Material.WATER_PLANT) - .breakByHand(true) + //TODO: 1.18.2 Check if this is still ok + //.breakByHand(true) .sound(SoundType.WET_GRASS) .noCollission() ); @@ -28,7 +29,8 @@ public abstract class BaseUnderwaterWallPlantBlock extends BaseWallPlantBlock im this( FabricBlockSettings .of(Material.WATER_PLANT) - .breakByHand(true) + //TODO: 1.18.2 Check if this is still ok + //.breakByHand(true) .luminance(light) .sound(SoundType.WET_GRASS) .noCollission() diff --git a/src/main/java/ru/bclib/blocks/BaseVineBlock.java b/src/main/java/ru/bclib/blocks/BaseVineBlock.java index 2b36688c..0f20c3a7 100644 --- a/src/main/java/ru/bclib/blocks/BaseVineBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseVineBlock.java @@ -30,6 +30,7 @@ import net.minecraft.world.phys.shapes.VoxelShape; import ru.bclib.blocks.BlockProperties.TripleShape; import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.interfaces.RenderLayerProvider; +import ru.bclib.items.tool.BaseShearsItem; import ru.bclib.util.BlocksHelper; import java.util.List; @@ -110,7 +111,8 @@ public class BaseVineBlock extends BaseBlockNotFull implements RenderLayerProvid @Override public List getDrops(BlockState state, LootContext.Builder builder) { ItemStack tool = builder.getParameter(LootContextParams.TOOL); - if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel( + //TODO: Test if shearing still works + if (tool != null && BaseShearsItem.isShear(tool) || EnchantmentHelper.getItemEnchantmentLevel( Enchantments.SILK_TOUCH, tool ) > 0) { diff --git a/src/main/java/ru/bclib/blocks/BaseWallPlantBlock.java b/src/main/java/ru/bclib/blocks/BaseWallPlantBlock.java index 54e8dbd3..7157dd1e 100644 --- a/src/main/java/ru/bclib/blocks/BaseWallPlantBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseWallPlantBlock.java @@ -39,7 +39,8 @@ public abstract class BaseWallPlantBlock extends BasePlantBlock { this( FabricBlockSettings .of(Material.PLANT) - .breakByHand(true) + //TODO: 1.18.2 Check if this is still ok + //.breakByHand(true) .sound(SoundType.GRASS) .noCollission() ); @@ -49,7 +50,8 @@ public abstract class BaseWallPlantBlock extends BasePlantBlock { this( FabricBlockSettings .of(Material.PLANT) - .breakByHand(true) + //TODO: 1.18.2 Check if this is still ok + //.breakByHand(true) .luminance(light) .sound(SoundType.GRASS) .noCollission() diff --git a/src/main/java/ru/bclib/blocks/FeatureSaplingBlock.java b/src/main/java/ru/bclib/blocks/FeatureSaplingBlock.java index dfee5df8..f8b91d65 100644 --- a/src/main/java/ru/bclib/blocks/FeatureSaplingBlock.java +++ b/src/main/java/ru/bclib/blocks/FeatureSaplingBlock.java @@ -44,7 +44,8 @@ public class FeatureSaplingBlock extends SaplingBlock implements RenderLayerProv public FeatureSaplingBlock(Function> featureSupplier) { this(FabricBlockSettings.of(Material.PLANT) - .breakByHand(true) + //TODO: 1.18.2 Check if this is still ok + //.breakByHand(true) .collidable(false) .instabreak() .sound(SoundType.GRASS) @@ -55,7 +56,8 @@ public class FeatureSaplingBlock extends SaplingBlock implements RenderLayerProv public FeatureSaplingBlock(int light, Function> featureSupplier) { this(FabricBlockSettings.of(Material.PLANT) - .breakByHand(true) + //TODO: 1.18.2 Check if this is still ok + //.breakByHand(true) .collidable(false) .luminance(light) .instabreak() diff --git a/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java b/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java index 5f71bf5d..746c6470 100644 --- a/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java +++ b/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java @@ -35,6 +35,7 @@ import ru.bclib.api.tag.TagAPI.TagLocation; import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.interfaces.RenderLayerProvider; import ru.bclib.interfaces.TagProvider; +import ru.bclib.items.tool.BaseShearsItem; import java.util.List; import java.util.Random; @@ -57,7 +58,8 @@ public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements R this( FabricBlockSettings .of(Material.WATER_PLANT) - .breakByHand(true) + //TODO: 1.18.2 Check if this is still ok + //.breakByHand(true) .luminance(light) .sound(SoundType.WET_GRASS) .noCollission() @@ -105,7 +107,8 @@ public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements R @Override public List getDrops(BlockState state, LootContext.Builder builder) { ItemStack tool = builder.getParameter(LootContextParams.TOOL); - if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel( + //TODO: Test is shearing still works + if (tool != null && BaseShearsItem.isShear(tool) || EnchantmentHelper.getItemEnchantmentLevel( Enchantments.SILK_TOUCH, tool ) > 0) { diff --git a/src/main/java/ru/bclib/blocks/UnderwaterPlantWithAgeBlock.java b/src/main/java/ru/bclib/blocks/UnderwaterPlantWithAgeBlock.java index e5ba1b6b..c22473b3 100644 --- a/src/main/java/ru/bclib/blocks/UnderwaterPlantWithAgeBlock.java +++ b/src/main/java/ru/bclib/blocks/UnderwaterPlantWithAgeBlock.java @@ -20,7 +20,8 @@ public abstract class UnderwaterPlantWithAgeBlock extends UnderwaterPlantBlock { super( FabricBlockSettings .of(Material.WATER_PLANT) - .breakByHand(true) + //TODO: 1.18.2 Check if this is still ok + //.breakByHand(true) .sound(SoundType.WET_GRASS) .randomTicks() .noCollission() diff --git a/src/main/java/ru/bclib/blocks/UpDownPlantBlock.java b/src/main/java/ru/bclib/blocks/UpDownPlantBlock.java index 9fdfe7e6..cb60d0a6 100644 --- a/src/main/java/ru/bclib/blocks/UpDownPlantBlock.java +++ b/src/main/java/ru/bclib/blocks/UpDownPlantBlock.java @@ -29,6 +29,7 @@ import ru.bclib.api.tag.TagAPI.TagLocation; import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.interfaces.RenderLayerProvider; import ru.bclib.interfaces.TagProvider; +import ru.bclib.items.tool.BaseShearsItem; import java.util.List; @@ -83,7 +84,8 @@ public abstract class UpDownPlantBlock extends BaseBlockNotFull implements Rende @Override public List getDrops(BlockState state, LootContext.Builder builder) { ItemStack tool = builder.getParameter(LootContextParams.TOOL); - if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel( + //TODO: 1.18.2 Test if shearing still works + if (tool != null && BaseShearsItem.isShear(tool) || EnchantmentHelper.getItemEnchantmentLevel( Enchantments.SILK_TOUCH, tool ) > 0) { diff --git a/src/main/java/ru/bclib/blocks/WallMushroomBlock.java b/src/main/java/ru/bclib/blocks/WallMushroomBlock.java index 6c3379a0..8118b099 100644 --- a/src/main/java/ru/bclib/blocks/WallMushroomBlock.java +++ b/src/main/java/ru/bclib/blocks/WallMushroomBlock.java @@ -19,7 +19,8 @@ public abstract class WallMushroomBlock extends BaseWallPlantBlock { this( FabricBlockSettings .of(Material.PLANT) - .breakByHand(true) + //TODO: 1.18.2 Check if this is still ok + //..breakByHand(true) .luminance(light) .destroyTime(0.2F) .sound(SoundType.GRASS) diff --git a/src/main/java/ru/bclib/client/render/CustomFogRenderer.java b/src/main/java/ru/bclib/client/render/CustomFogRenderer.java index 39291fe9..76a72637 100644 --- a/src/main/java/ru/bclib/client/render/CustomFogRenderer.java +++ b/src/main/java/ru/bclib/client/render/CustomFogRenderer.java @@ -108,12 +108,12 @@ public class CustomFogRenderer { } private static boolean shouldIgnore(Level level, int x, int y, int z) { - Biome biome = level.getBiome(MUT_POS.set(x, y, z)); + Biome biome = level.getBiome(MUT_POS.set(x, y, z)).value(); return BiomeAPI.getRenderBiome(biome) == BiomeAPI.EMPTY_BIOME; } private static float getFogDensityI(Level level, int x, int y, int z) { - Biome biome = level.getBiome(MUT_POS.set(x, y, z)); + Biome biome = level.getBiome(MUT_POS.set(x, y, z)).value(); BCLBiome renderBiome = BiomeAPI.getRenderBiome(biome); return renderBiome.getFogDensity(); } diff --git a/src/main/java/ru/bclib/integration/ModIntegration.java b/src/main/java/ru/bclib/integration/ModIntegration.java index ddfb76a6..8ff8ea63 100644 --- a/src/main/java/ru/bclib/integration/ModIntegration.java +++ b/src/main/java/ru/bclib/integration/ModIntegration.java @@ -1,6 +1,7 @@ package ru.bclib.integration; import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.core.Holder; import net.minecraft.core.Registry; import net.minecraft.data.BuiltinRegistries; import net.minecraft.resources.ResourceKey; @@ -37,6 +38,10 @@ public abstract class ModIntegration { public ResourceLocation getID(String name) { return new ResourceLocation(modID, name); } + + public ResourceKey getFeatureKey(String name) { + return ResourceKey.create(Registry.PLACED_FEATURE_REGISTRY, getID(name)); + } public Block getBlock(String name) { return Registry.BLOCK.get(getID(name)); @@ -61,7 +66,7 @@ public abstract class ModIntegration { public BCLFeature getFeature(String featureID, String placedFeatureID, GenerationStep.Decoration featureStep) { ResourceLocation id = getID(featureID); Feature feature = Registry.FEATURE.get(id); - PlacedFeature featureConfigured = BuiltinRegistries.PLACED_FEATURE.get(getID(placedFeatureID)); + Holder featureConfigured = BuiltinRegistries.PLACED_FEATURE.getHolder(getFeatureKey(placedFeatureID)).orElse(null); return new BCLFeature(id, feature, featureStep, featureConfigured); } diff --git a/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java b/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java index 92e3d099..62e0b156 100644 --- a/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java +++ b/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java @@ -1,5 +1,6 @@ package ru.bclib.mixin.common; +import net.minecraft.core.HolderSet; import net.minecraft.world.level.biome.BiomeGenerationSettings; import net.minecraft.world.level.levelgen.GenerationStep; import net.minecraft.world.level.levelgen.GenerationStep.Carving; @@ -17,11 +18,11 @@ import java.util.function.Supplier; @Mixin(BiomeGenerationSettings.class) public interface BiomeGenerationSettingsAccessor { @Accessor("features") - List>> bclib_getFeatures(); + List> bclib_getFeatures(); @Accessor("features") @Mutable - void bclib_setFeatures(List>> value); + void bclib_setFeatures(List> value); @Accessor("featureSet") Supplier> bclib_getFeatureSet(); @@ -30,8 +31,8 @@ public interface BiomeGenerationSettingsAccessor { void bclib_setFeatureSet(Supplier> features); @Accessor("carvers") - Map>>> bclib_getCarvers(); + Map>> bclib_getCarvers(); @Accessor("carvers") - void bclib_setCarvers(Map>>> features); + void bclib_setCarvers(Map>> features); } diff --git a/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java b/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java index 1bd6050d..15d46beb 100644 --- a/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java +++ b/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java @@ -1,5 +1,6 @@ package ru.bclib.mixin.common; +import net.minecraft.core.Holder; import net.minecraft.resources.ResourceKey; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; @@ -9,6 +10,7 @@ import net.minecraft.world.level.CustomSpawner; import net.minecraft.world.level.Level; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.dimension.DimensionType; +import net.minecraft.world.level.storage.LevelStorageSource; import net.minecraft.world.level.storage.LevelStorageSource.LevelStorageAccess; import net.minecraft.world.level.storage.ServerLevelData; import net.minecraft.world.level.storage.WritableLevelData; @@ -28,12 +30,12 @@ import java.util.function.Supplier; public abstract class ServerLevelMixin extends Level { private static String bclib_lastWorld = null; - protected ServerLevelMixin(WritableLevelData writableLevelData, ResourceKey resourceKey, DimensionType dimensionType, Supplier supplier, boolean bl, boolean bl2, long l) { + protected ServerLevelMixin(WritableLevelData writableLevelData, ResourceKey resourceKey, Holder dimensionType, Supplier supplier, boolean bl, boolean bl2, long l) { super(writableLevelData, resourceKey, dimensionType, supplier, bl, bl2, l); } @Inject(method = "*", at = @At("TAIL")) - private void bclib_onServerWorldInit(MinecraftServer server, Executor executor, LevelStorageAccess levelStorageAccess, ServerLevelData serverLevelData, ResourceKey resourceKey, DimensionType dimensionType, ChunkProgressListener chunkProgressListener, ChunkGenerator chunkGenerator, boolean bl, long l, List list, boolean bl2, CallbackInfo info) { + private void bclib_onServerWorldInit(MinecraftServer server, Executor executor, LevelStorageAccess levelStorageAccess, ServerLevelData serverLevelData, ResourceKey resourceKey, Holder dimensionType, ChunkProgressListener chunkProgressListener, ChunkGenerator chunkGenerator, boolean bl, long l, List list, boolean bl2, CallbackInfo ci) { ServerLevel level = ServerLevel.class.cast(this); LifeCycleAPI._runLevelLoad(level, server, executor, levelStorageAccess, serverLevelData, resourceKey, dimensionType, chunkProgressListener, chunkGenerator, bl, l, list, bl2); diff --git a/src/main/java/ru/bclib/recipes/AnvilRecipe.java b/src/main/java/ru/bclib/recipes/AnvilRecipe.java index 28343417..495b95b2 100644 --- a/src/main/java/ru/bclib/recipes/AnvilRecipe.java +++ b/src/main/java/ru/bclib/recipes/AnvilRecipe.java @@ -5,11 +5,13 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.core.NonNullList; +import net.minecraft.core.Registry; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.TagParser; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.Tag; +import net.minecraft.tags.TagKey; import net.minecraft.util.GsonHelper; import net.minecraft.world.Container; import net.minecraft.world.InteractionHand; @@ -116,7 +118,8 @@ public class AnvilRecipe implements Recipe, UnknownReceipBookCategory public boolean matches(Container craftingInventory) { ItemStack hammer = craftingInventory.getItem(1); - if (hammer.isEmpty() || !CommonItemTags.HAMMERS.contains(hammer.getItem())) { + //TODO: 1.18.2 Test if hammer still works + if (hammer.isEmpty() || !hammer.is(CommonItemTags.HAMMERS)) { return false; } ItemStack material = craftingInventory.getItem(0); @@ -209,7 +212,7 @@ public class AnvilRecipe implements Recipe, UnknownReceipBookCategory return this; } - public Builder setInput(Tag inputTag) { + public Builder setInput(TagKey inputTag) { this.setInput(Ingredient.of(inputTag)); return this; } diff --git a/src/main/java/ru/bclib/recipes/GridRecipe.java b/src/main/java/ru/bclib/recipes/GridRecipe.java index 4a1c6155..3af5b4d1 100644 --- a/src/main/java/ru/bclib/recipes/GridRecipe.java +++ b/src/main/java/ru/bclib/recipes/GridRecipe.java @@ -4,6 +4,7 @@ import com.google.common.collect.Maps; import net.minecraft.core.NonNullList; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.Tag; +import net.minecraft.tags.TagKey; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.CraftingRecipe; @@ -74,7 +75,7 @@ public class GridRecipe { return this; } - public GridRecipe addMaterial(char key, Tag value) { + public GridRecipe addMaterial(char key, TagKey value) { return addMaterial(key, Ingredient.of(value)); } diff --git a/src/main/java/ru/bclib/recipes/SmithingTableRecipe.java b/src/main/java/ru/bclib/recipes/SmithingTableRecipe.java index dc9ad9b7..a981d18a 100644 --- a/src/main/java/ru/bclib/recipes/SmithingTableRecipe.java +++ b/src/main/java/ru/bclib/recipes/SmithingTableRecipe.java @@ -2,6 +2,7 @@ package ru.bclib.recipes; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.Tag; +import net.minecraft.tags.TagKey; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; @@ -59,7 +60,7 @@ public class SmithingTableRecipe { return this; } - public SmithingTableRecipe setBase(Tag tag) { + public SmithingTableRecipe setBase(TagKey tag) { this.base = (Ingredient.of(tag)); return this; } @@ -70,7 +71,7 @@ public class SmithingTableRecipe { return this; } - public SmithingTableRecipe setAddition(Tag tag) { + public SmithingTableRecipe setAddition(TagKey tag) { this.addition = (Ingredient.of(tag)); return this; } diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiome.java b/src/main/java/ru/bclib/world/biomes/BCLBiome.java index bbfdafaa..c2bdca7b 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiome.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiome.java @@ -2,6 +2,7 @@ package ru.bclib.world.biomes; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import net.minecraft.core.Holder; import net.minecraft.core.Registry; import net.minecraft.data.BuiltinRegistries; import net.minecraft.resources.ResourceKey; @@ -31,9 +32,9 @@ public class BCLBiome extends BCLBiomeSettings { private final ResourceLocation biomeID; private final Biome biome; - private Consumer surfaceInit; + private Consumer> surfaceInit; private BCLBiome biomeParent; - private Biome actualBiome; + private Holder actualBiome; /** * Create wrapper for existing biome using its {@link ResourceLocation} identifier. @@ -65,7 +66,7 @@ public class BCLBiome extends BCLBiomeSettings { * @param settings The Settings for this Biome or {@code null} if you want to apply default settings */ public BCLBiome(Biome biome, VanillaBiomeSettings settings) { - this(BuiltinRegistries.BIOME.getKey(biome), biome, settings); + this(BiomeAPI.getBiomeID(biome), biome, settings); } public BCLBiome(ResourceLocation biomeID, Biome biome) { @@ -164,7 +165,10 @@ public class BCLBiome extends BCLBiomeSettings { return biomeID; } - + + public Holder getBiomeHolder() { + return BuiltinRegistries.BIOME.getOrCreateHolder(BiomeAPI.getBiomeKey(biome)); + } /** * Getter for biome from buil-in registry. For datapack biomes will be same as actual biome. * @return {@link Biome}. @@ -177,7 +181,7 @@ public class BCLBiome extends BCLBiomeSettings { * Getter for actual biome (biome from current world registry with same {@link ResourceLocation} id). * @return {@link Biome}. */ - public Biome getActualBiome() { + public Holder getActualBiome() { return this.actualBiome; } @@ -196,7 +200,7 @@ public class BCLBiome extends BCLBiomeSettings { if (edge != null && edge != this) { edge.updateActualBiomes(biomeRegistry); } - this.actualBiome = biomeRegistry.get(biomeID); + this.actualBiome = biomeRegistry.getHolder(ResourceKey.create(Registry.BIOME_REGISTRY, biomeID)).orElse(null); if (actualBiome==null) { BCLib.LOGGER.error("Unable to find actual Biome for " + biomeID); } diff --git a/src/main/java/ru/bclib/world/features/BCLFeature.java b/src/main/java/ru/bclib/world/features/BCLFeature.java index 8c649c43..33e4ef3a 100644 --- a/src/main/java/ru/bclib/world/features/BCLFeature.java +++ b/src/main/java/ru/bclib/world/features/BCLFeature.java @@ -5,32 +5,25 @@ import net.minecraft.core.Registry; import net.minecraft.data.BuiltinRegistries; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.level.block.Block; import net.minecraft.world.level.levelgen.GenerationStep.Decoration; -import net.minecraft.world.level.levelgen.VerticalAnchor; import net.minecraft.world.level.levelgen.feature.Feature; -import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration; -import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; -import net.minecraft.world.level.levelgen.placement.HeightRangePlacement; import net.minecraft.world.level.levelgen.placement.PlacedFeature; -import net.minecraft.world.level.levelgen.placement.PlacementModifier; -import ru.bclib.api.features.BCLCommonFeatures; import java.util.Map.Entry; import java.util.Optional; public class BCLFeature { - private PlacedFeature placedFeature; + private Holder placedFeature; private Decoration featureStep; private Feature feature; - public BCLFeature(ResourceLocation id, Feature feature, Decoration featureStep, PlacedFeature placedFeature) { + public BCLFeature(ResourceLocation id, Feature feature, Decoration featureStep, Holder placedFeature) { this.placedFeature = placedFeature; this.featureStep = featureStep; this.feature = feature; if (!BuiltinRegistries.PLACED_FEATURE.containsKey(id)) { - Registry.register(BuiltinRegistries.PLACED_FEATURE, id, placedFeature); + Registry.register(BuiltinRegistries.PLACED_FEATURE, id, placedFeature.value()); } if (!Registry.FEATURE.containsKey(id) && !containsObj(Registry.FEATURE, feature)) { Registry.register(Registry.FEATURE, id, feature); @@ -58,7 +51,7 @@ public class BCLFeature { * Get configured feature. * @return {@link PlacedFeature}. */ - public PlacedFeature getPlacedFeature() { + public Holder getPlacedFeature() { return placedFeature; } @@ -69,92 +62,4 @@ public class BCLFeature { public Decoration getDecoration() { return featureStep; } - - /** - * Deprecated, use function from {@link BCLCommonFeatures} instead. - */ - @Deprecated(forRemoval = true) - public static BCLFeature makeVegetationFeature(ResourceLocation id, Feature feature, int density) { - return BCLCommonFeatures.makeVegetationFeature(id, feature, density); - } - - /** - * Deprecated, use function from {@link BCLCommonFeatures} instead. - */ - @Deprecated(forRemoval = true) - public static BCLFeature makeVegetationFeature(ResourceLocation id, Feature feature, int density, boolean allHeight) { - return BCLCommonFeatures.makeVegetationFeature(id, feature, density, allHeight); - } - - /** - * Deprecated, moved to {@link BCLCommonFeatures}. Will be completely removed. - */ - @Deprecated(forRemoval = true) - public static BCLFeature makeOreFeature(ResourceLocation id, Block blockOre, Block hostBlock, int veins, int veinSize, float airDiscardChance, VerticalAnchor minY, VerticalAnchor maxY, boolean rare) { - return BCLCommonFeatures.makeOreFeature(id, blockOre, hostBlock, veins, veinSize, airDiscardChance, HeightRangePlacement.uniform(minY, maxY), rare); - } - - /** - * Deprecated, moved to {@link BCLCommonFeatures}. Will be completely removed. - */ - @Deprecated(forRemoval = true) - public static BCLFeature makeOreFeature(ResourceLocation id, Block blockOre, Block hostBlock, int veins, int veinSize, VerticalAnchor minY, VerticalAnchor maxY, boolean rare) { - return BCLCommonFeatures.makeOreFeature(id, blockOre, hostBlock, veins, veinSize, 0.0f, HeightRangePlacement.uniform(minY, maxY), rare); - } - - /** - * Deprecated, use function from {@link BCLCommonFeatures} instead. - */ - @Deprecated(forRemoval = true) - public static BCLFeature makeOreFeature(ResourceLocation id, Block blockOre, Block hostBlock, int veins, int veinSize, float airDiscardChance, PlacementModifier placement, boolean rare) { - return BCLCommonFeatures.makeOreFeature(id, blockOre, hostBlock, veins, veinSize, airDiscardChance, placement, rare); - } - - /** - * Deprecated, use function from {@link BCLCommonFeatures} instead. - */ - @Deprecated(forRemoval = true) - public static BCLFeature makeOreFeature(ResourceLocation id, Block blockOre, Block hostBlock, int veins, int veinSize, PlacementModifier placement, boolean rare) { - return BCLCommonFeatures.makeOreFeature(id, blockOre, hostBlock, veins, veinSize, 0.0f, placement, rare); - } - - /** - * Deprecated, use function from {@link BCLCommonFeatures} instead. - */ - @Deprecated(forRemoval = true) - public static BCLFeature makeChunkFeature(ResourceLocation id, Decoration step, Feature feature) { - return BCLCommonFeatures.makeChunkFeature(id, step, feature); - } - - /** - * Deprecated, use function from {@link BCLCommonFeatures} instead. - */ - @Deprecated(forRemoval = true) - public static BCLFeature makeChancedFeature(ResourceLocation id, Decoration step, Feature feature, int chance) { - return BCLCommonFeatures.makeChancedFeature(id, step, feature, chance); - } - - /** - * Deprecated, use function from {@link BCLCommonFeatures} instead. - */ - @Deprecated(forRemoval = true) - public static BCLFeature makeCountFeature(ResourceLocation id, Decoration step, Feature feature, int count) { - return BCLCommonFeatures.makeCountFeature(id, step, feature, count); - } - - /** - * Deprecated, use {@link ru.bclib.api.features.BCLFeatureBuilder} instead. - * - * Creates and configures new BCLib feature. - * @param id {@link ResourceLocation} feature ID. - * @param step {@link Decoration} feature step. - * @param feature {@link Feature} with {@link NoneFeatureConfiguration} config. - * @param placementModifiers array of {@link PlacementModifier} - * @return new BCLFeature instance. - */ - @Deprecated(forRemoval = true) - public static BCLFeature makeFeature(ResourceLocation id, Decoration step, Feature feature, PlacementModifier... placementModifiers) { - PlacedFeature configured = feature.configured(FeatureConfiguration.NONE).placed(placementModifiers); - return new BCLFeature(id, feature, step, configured); - } } diff --git a/src/main/java/ru/bclib/world/features/NBTStructureFeature.java b/src/main/java/ru/bclib/world/features/NBTStructureFeature.java index 77f51198..77f3eb40 100644 --- a/src/main/java/ru/bclib/world/features/NBTStructureFeature.java +++ b/src/main/java/ru/bclib/world/features/NBTStructureFeature.java @@ -3,6 +3,7 @@ package ru.bclib.world.features; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; +import net.minecraft.core.Holder; import net.minecraft.core.Vec3i; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtIo; @@ -50,7 +51,7 @@ public abstract class NBTStructureFeature extends DefaultFeature { protected abstract void addStructureData(StructurePlaceSettings data); protected BlockPos getGround(WorldGenLevel world, BlockPos center) { - Biome biome = world.getBiome(center); + Holder biome = world.getBiome(center); ResourceLocation id = BiomeAPI.getBiomeID(biome); if (id.getNamespace().contains("moutain") || id.getNamespace().contains("lake")) { int y = getAverageY(world, center); @@ -148,7 +149,7 @@ public abstract class NBTStructureFeature extends DefaultFeature { if (!isTerrain(stateSt)) { if (merge == TerrainMerge.SURFACE) { boolean isTop = mut.getY() == surfMax && state.getMaterial().isSolidBlocking(); - Biome b = world.getBiome(mut); + Holder b = world.getBiome(mut); BlockState top = (isTop ? BiomeAPI.findTopMaterial(b) : BiomeAPI.findUnderMaterial(b)).orElse(defaultBlock); BlocksHelper.setWithoutUpdate(world, mut, top); } @@ -159,7 +160,7 @@ public abstract class NBTStructureFeature extends DefaultFeature { else { if (isTerrain(state) && state.getMaterial().isSolidBlocking()) { if (merge == TerrainMerge.SURFACE) { - Biome b = world.getBiome(mut); + Holder b = world.getBiome(mut); BlockState bottom = BiomeAPI.findUnderMaterial(b).orElse(defaultBlock); BlocksHelper.setWithoutUpdate(world, mut, bottom); } diff --git a/src/main/java/ru/bclib/world/generator/BCLBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLBiomeSource.java index a329a875..cc3c8b74 100644 --- a/src/main/java/ru/bclib/world/generator/BCLBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLBiomeSource.java @@ -1,5 +1,6 @@ package ru.bclib.world.generator; +import net.minecraft.core.Holder; import net.minecraft.core.Registry; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.BiomeSource; @@ -8,15 +9,15 @@ import ru.bclib.api.biomes.BiomeAPI; import java.util.List; public abstract class BCLBiomeSource extends BiomeSource { - protected final Registry biomeRegistry; + protected final Registry> biomeRegistry; protected final long seed; - private static List preInit(Registry biomeRegistry, List biomes){ + private static List> preInit(Registry> biomeRegistry, List> biomes){ biomes.forEach(biome -> BiomeAPI.sortBiomeFeatures(biome)); return biomes; } - protected BCLBiomeSource(Registry biomeRegistry, long seed, List list) { + protected BCLBiomeSource(Registry> biomeRegistry, long seed, List> list) { super(preInit(biomeRegistry, list)); this.seed = seed; diff --git a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java index 61bec9ee..dd2acbae 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java @@ -2,6 +2,7 @@ package ru.bclib.world.generator; import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.core.Holder; import net.minecraft.core.Registry; import net.minecraft.resources.RegistryOps; import net.minecraft.resources.ResourceLocation; @@ -19,6 +20,7 @@ import ru.bclib.api.biomes.BiomeAPI; import ru.bclib.config.ConfigKeeper.StringArrayEntry; import ru.bclib.config.Configs; import ru.bclib.interfaces.BiomeMap; +import ru.bclib.mixin.common.BiomeAccessor; import ru.bclib.noise.OpenSimplexNoise; import ru.bclib.world.biomes.BCLBiome; import ru.bclib.world.generator.map.hex.HexBiomeMap; @@ -29,14 +31,14 @@ import java.util.List; import java.util.function.Function; public class BCLibEndBiomeSource extends BCLBiomeSource { - public static final Codec CODEC = RecordCodecBuilder.create((instance) -> instance.group(RegistryOps + public static Codec CODEC = RecordCodecBuilder.create((instance) -> instance.group(RegistryOps .retrieveRegistry(Registry.BIOME_REGISTRY).forGetter((theEndBiomeSource) -> theEndBiomeSource.biomeRegistry), Codec.LONG.fieldOf("seed").stable().forGetter((theEndBiomeSource) -> theEndBiomeSource.seed)).apply(instance, instance.stable(BCLibEndBiomeSource::new))); private static final OpenSimplexNoise SMALL_NOISE = new OpenSimplexNoise(8324); private Function endLandFunction; private final SimplexNoise noise; - private final Biome centerBiome; - private final Biome barrens; + private final Holder centerBiome; + private final Holder barrens; private BiomeMap mapLand; private BiomeMap mapVoid; private final Point pos; @@ -49,7 +51,7 @@ public class BCLibEndBiomeSource extends BCLBiomeSource { List includeVoid = Configs.BIOMES_CONFIG.getEntry("force_include", "end_void_biomes", StringArrayEntry.class).getValue(); this.possibleBiomes().forEach(biome -> { - ResourceLocation key = biomeRegistry.getKey(biome); + ResourceLocation key = biomeRegistry.getKey(biome.value()); String group = key.getNamespace() + "." + key.getPath(); if (!BiomeAPI.hasBiome(key)) { @@ -94,8 +96,8 @@ public class BCLibEndBiomeSource extends BCLBiomeSource { this.mapVoid = new HexBiomeMap(seed, GeneratorOptions.getBiomeSizeEndVoid(), BiomeAPI.END_VOID_BIOME_PICKER); } - this.centerBiome = biomeRegistry.getOrThrow(Biomes.THE_END); - this.barrens = biomeRegistry.getOrThrow(Biomes.END_BARRENS); + this.centerBiome = biomeRegistry.getHolderOrThrow(Biomes.THE_END); + this.barrens = biomeRegistry.getHolderOrThrow(Biomes.END_BARRENS); WorldgenRandom chunkRandom = new WorldgenRandom(new LegacyRandomSource(seed)); chunkRandom.consumeCount(17292); @@ -115,9 +117,15 @@ public class BCLibEndBiomeSource extends BCLBiomeSource { if (includeLand.contains(key.toString()) || includeVoid.contains(key.toString())) { return true; } - - if (GeneratorOptions.addEndBiomesByCategory() && biome.getBiomeCategory() == BiomeCategory.THEEND) { - return true; + + final boolean isEndBiome; + if ((Object)biome instanceof BiomeAccessor bacc) { + isEndBiome = bacc.bclib_getBiomeCategory() == BiomeCategory.THEEND; + if (GeneratorOptions.addEndBiomesByCategory() && isEndBiome) { + return true; + } + } else { + isEndBiome = false; } BCLBiome bclBiome = BiomeAPI.getBiome(key); @@ -127,12 +135,12 @@ public class BCLibEndBiomeSource extends BCLBiomeSource { } key = bclBiome.getID(); } - return BiomeAPI.END_LAND_BIOME_PICKER.containsImmutable(key) || BiomeAPI.END_VOID_BIOME_PICKER.containsImmutable(key) || (biome.getBiomeCategory() == BiomeCategory.THEEND && BiomeAPI.isDatapackBiome(key)); + return BiomeAPI.END_LAND_BIOME_PICKER.containsImmutable(key) || BiomeAPI.END_VOID_BIOME_PICKER.containsImmutable(key) || (isEndBiome && BiomeAPI.isDatapackBiome(key)); }).toList(); } @Override - public Biome getNoiseBiome(int biomeX, int biomeY, int biomeZ, Climate.Sampler sampler) { + public Holder getNoiseBiome(int biomeX, int biomeY, int biomeZ, Climate.Sampler sampler) { long posX = biomeX << 2; long posZ = biomeZ << 2; long farEndBiomes = GeneratorOptions.getFarEndBiomes(); diff --git a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java index a7509a95..a102e231 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java @@ -71,7 +71,7 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource { BiomeAPI.NETHER_BIOME_PICKER.clearMutables(); this.possibleBiomes().forEach(biome -> { - ResourceLocation key = biomeRegistry.getKey(biome); + ResourceLocation key = biomeRegistry.getKey(biome.value()); if (!BiomeAPI.hasBiome(key)) { BCLBiome bclBiome = new BCLBiome(key, biome); diff --git a/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java b/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java index 983bd44c..7b021944 100644 --- a/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java +++ b/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java @@ -94,7 +94,7 @@ public class BCLStructureFeature { return structure; } - public ConfiguredStructureFeature getFeatureConfigured() { + public Holder> getFeatureConfigured() { return featureConfigured; } From 2eccb1cb9e6347fb04b3df0d4bd39c2286e8aee3 Mon Sep 17 00:00:00 2001 From: Frank Date: Mon, 14 Mar 2022 17:00:44 +0100 Subject: [PATCH 08/34] Fixes to BiomeSources --- .../java/ru/bclib/world/biomes/BCLBiome.java | 7 ++++-- .../world/generator/BCLibEndBiomeSource.java | 18 ++++++++------- .../generator/BCLibNetherBiomeSource.java | 22 +++++++++++++------ 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiome.java b/src/main/java/ru/bclib/world/biomes/BCLBiome.java index c2bdca7b..aa20d39b 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiome.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiome.java @@ -191,7 +191,7 @@ public class BCLBiome extends BCLBiomeSettings { * Recursively update biomes to correct world biome registry instances, for internal usage only. * @param biomeRegistry {@link Registry} for {@link Biome}. */ - public void updateActualBiomes(Registry biomeRegistry) { + public void updateActualBiomes(Registry> biomeRegistry) { subbiomes.forEach((sub) -> { if (sub != this) { sub.updateActualBiomes(biomeRegistry); @@ -200,12 +200,15 @@ public class BCLBiome extends BCLBiomeSettings { if (edge != null && edge != this) { edge.updateActualBiomes(biomeRegistry); } - this.actualBiome = biomeRegistry.getHolder(ResourceKey.create(Registry.BIOME_REGISTRY, biomeID)).orElse(null); + + final ResourceKey> key = ResourceKey.create(biomeRegistry.key(), biomeID); + this.actualBiome = biomeRegistry.get(key); if (actualBiome==null) { BCLib.LOGGER.error("Unable to find actual Biome for " + biomeID); } if (!this.structures.isEmpty()) { + //TODO: 1.18.2 This need to be done by BiomeTags now structures.forEach(s -> BiomeAPI.addBiomeStructure(BiomeAPI.getBiomeKey(actualBiome), s)); } diff --git a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java index dd2acbae..4d1febba 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java @@ -1,10 +1,13 @@ package ru.bclib.world.generator; +import com.mojang.datafixers.kinds.Applicative; import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.core.Holder; import net.minecraft.core.Registry; import net.minecraft.resources.RegistryOps; +import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome.BiomeCategory; @@ -31,8 +34,7 @@ import java.util.List; import java.util.function.Function; public class BCLibEndBiomeSource extends BCLBiomeSource { - public static Codec CODEC = RecordCodecBuilder.create((instance) -> instance.group(RegistryOps - .retrieveRegistry(Registry.BIOME_REGISTRY).forGetter((theEndBiomeSource) -> theEndBiomeSource.biomeRegistry), Codec.LONG.fieldOf("seed").stable().forGetter((theEndBiomeSource) -> theEndBiomeSource.seed)).apply(instance, instance.stable(BCLibEndBiomeSource::new))); + public static Codec CODEC = RecordCodecBuilder.create((instance) -> instance.group(RegistryOps.retrieveRegistry(Registry.BIOME_REGISTRY).forGetter((theEndBiomeSource) -> null), Codec.LONG.fieldOf("seed").stable().forGetter((theEndBiomeSource) -> theEndBiomeSource.seed)).apply(instance, instance.stable(BCLibEndBiomeSource::new))); private static final OpenSimplexNoise SMALL_NOISE = new OpenSimplexNoise(8324); private Function endLandFunction; @@ -43,7 +45,7 @@ public class BCLibEndBiomeSource extends BCLBiomeSource { private BiomeMap mapVoid; private final Point pos; - public BCLibEndBiomeSource(Registry biomeRegistry, long seed) { + public BCLibEndBiomeSource(Registry> biomeRegistry, long seed) { super(biomeRegistry, seed, getBiomes(biomeRegistry)); BiomeAPI.END_LAND_BIOME_PICKER.clearMutables(); @@ -51,11 +53,11 @@ public class BCLibEndBiomeSource extends BCLBiomeSource { List includeVoid = Configs.BIOMES_CONFIG.getEntry("force_include", "end_void_biomes", StringArrayEntry.class).getValue(); this.possibleBiomes().forEach(biome -> { - ResourceLocation key = biomeRegistry.getKey(biome.value()); + ResourceLocation key = biomeRegistry.getKey(biome); String group = key.getNamespace() + "." + key.getPath(); if (!BiomeAPI.hasBiome(key)) { - BCLBiome bclBiome = new BCLBiome(key, biome); + BCLBiome bclBiome = new BCLBiome(key, biome.value()); if (includeVoid.contains(key.toString())) { BiomeAPI.END_VOID_BIOME_PICKER.addBiomeMutable(bclBiome); @@ -96,8 +98,8 @@ public class BCLibEndBiomeSource extends BCLBiomeSource { this.mapVoid = new HexBiomeMap(seed, GeneratorOptions.getBiomeSizeEndVoid(), BiomeAPI.END_VOID_BIOME_PICKER); } - this.centerBiome = biomeRegistry.getHolderOrThrow(Biomes.THE_END); - this.barrens = biomeRegistry.getHolderOrThrow(Biomes.END_BARRENS); + this.centerBiome = biomeRegistry.get(Biomes.THE_END.location()); + this.barrens = biomeRegistry.get(Biomes.END_BARRENS.location()); WorldgenRandom chunkRandom = new WorldgenRandom(new LegacyRandomSource(seed)); chunkRandom.consumeCount(17292); @@ -107,7 +109,7 @@ public class BCLibEndBiomeSource extends BCLBiomeSource { this.pos = new Point(); } - private static List getBiomes(Registry biomeRegistry) { + private static List> getBiomes(Registry> biomeRegistry) { List includeLand = Configs.BIOMES_CONFIG.getEntry("force_include", "end_land_biomes", StringArrayEntry.class).getValue(); List includeVoid = Configs.BIOMES_CONFIG.getEntry("force_include", "end_void_biomes", StringArrayEntry.class).getValue(); diff --git a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java index a102e231..23466e7a 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java @@ -2,8 +2,10 @@ package ru.bclib.world.generator; import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.core.Holder; import net.minecraft.core.Registry; import net.minecraft.resources.RegistryOps; +import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome.BiomeCategory; @@ -29,7 +31,7 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource { .create(instance -> instance .group(RegistryOps .retrieveRegistry(Registry.BIOME_REGISTRY) - .forGetter(source -> source.biomeRegistry) + .forGetter(source -> null) , Codec .LONG @@ -65,16 +67,16 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource { BCLibNetherBiomeSource.worldHeight = worldHeight; } - public BCLibNetherBiomeSource(Registry biomeRegistry, long seed) { + public BCLibNetherBiomeSource(Registry> biomeRegistry, long seed) { super(biomeRegistry, seed, getBiomes(biomeRegistry)); BiomeAPI.NETHER_BIOME_PICKER.clearMutables(); this.possibleBiomes().forEach(biome -> { - ResourceLocation key = biomeRegistry.getKey(biome.value()); + ResourceLocation key = biome.unwrapKey().orElseThrow().location(); if (!BiomeAPI.hasBiome(key)) { - BCLBiome bclBiome = new BCLBiome(key, biome); + BCLBiome bclBiome = new BCLBiome(key, biome.value()); BiomeAPI.NETHER_BIOME_PICKER.addBiomeMutable(bclBiome); } else { @@ -95,7 +97,7 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource { initMap(); } - private static List getBiomes(Registry biomeRegistry) { + private static List> getBiomes(Registry> biomeRegistry) { List include = Configs.BIOMES_CONFIG.getEntry("force_include", "nether_biomes", StringArrayEntry.class).getValue(); return biomeRegistry.stream().filter(biome -> { @@ -116,12 +118,18 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource { } key = bclBiome.getID(); } - return BiomeAPI.NETHER_BIOME_PICKER.containsImmutable(key) || (biome.getBiomeCategory() == BiomeCategory.NETHER && BiomeAPI.isDatapackBiome(key)); + final boolean isNetherBiome; + if ((Object)biome instanceof BiomeAccessor bacc) { + isNetherBiome = bacc.bclib_getBiomeCategory() == BiomeCategory.NETHER; + } else { + isNetherBiome = false; + } + return BiomeAPI.NETHER_BIOME_PICKER.containsImmutable(key) || (isNetherBiome && BiomeAPI.isDatapackBiome(key)); }).toList(); } @Override - public Biome getNoiseBiome(int biomeX, int biomeY, int biomeZ, Climate.Sampler var4) { + public Holder getNoiseBiome(int biomeX, int biomeY, int biomeZ, Climate.Sampler var4) { if (lastWorldHeight != worldHeight) { lastWorldHeight = worldHeight; initMap(); From 6c015a9a5346486220caadcd2187ccf194dacc57 Mon Sep 17 00:00:00 2001 From: Frank Date: Mon, 14 Mar 2022 17:23:57 +0100 Subject: [PATCH 09/34] More BiomeSource related fixes --- .../java/ru/bclib/api/biomes/BiomeAPI.java | 40 ++++++------ .../ru/bclib/interfaces/NumericProvider.java | 2 +- .../java/ru/bclib/world/biomes/BCLBiome.java | 6 +- .../bclib/world/generator/BCLBiomeSource.java | 6 +- .../world/generator/BCLibEndBiomeSource.java | 62 ++++++++++--------- .../generator/BCLibNetherBiomeSource.java | 61 +++++++++--------- 6 files changed, 93 insertions(+), 84 deletions(-) diff --git a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java index d0a466e3..f96b8a6f 100644 --- a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java @@ -75,7 +75,7 @@ public class BiomeAPI { private static final Map ID_MAP = Maps.newHashMap(); private static final Map CLIENT = Maps.newHashMap(); - private static Registry> biomeRegistry; + private static Registry biomeRegistry; private static final Map FEATURE_ORDER = Maps.newHashMap(); private static final MutableInt FEATURE_ORDER_ID = new MutableInt(0); @@ -94,8 +94,8 @@ public class BiomeAPI { public static final BCLBiome END_MIDLANDS = registerSubBiome(THE_END, getFromRegistry(Biomes.END_MIDLANDS).value(), 0.5F); public static final BCLBiome END_HIGHLANDS = registerSubBiome(THE_END, getFromRegistry(Biomes.END_HIGHLANDS).value(), 0.5F); - public static final BCLBiome END_BARRENS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("end_barrens")).value()); - public static final BCLBiome SMALL_END_ISLANDS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("small_end_islands")).value()); + public static final BCLBiome END_BARRENS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("end_barrens"))); + public static final BCLBiome SMALL_END_ISLANDS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("small_end_islands"))); private static void initFeatureOrder() { if (!FEATURE_ORDER.isEmpty()) { @@ -123,7 +123,7 @@ public class BiomeAPI { * Initialize registry for current server. * @param biomeRegistry - {@link Registry} for {@link Biome}. */ - public static void initRegistry(Registry> biomeRegistry) { + public static void initRegistry(Registry biomeRegistry) { if (biomeRegistry != BiomeAPI.biomeRegistry) { BiomeAPI.biomeRegistry = biomeRegistry; CLIENT.clear(); @@ -143,15 +143,17 @@ public class BiomeAPI { /** * Register {@link BCLBiome} instance and its {@link Biome} if necessary. - * @param biome {@link BCLBiome} + * @param bclbiome {@link BCLBiome} * @return {@link BCLBiome} */ - public static BCLBiome registerBiome(BCLBiome biome) { - if (BuiltinRegistries.BIOME.get(biome.getID()) == null) { - Registry.register(BuiltinRegistries.BIOME, biome.getID(), biome.getBiome()); + public static BCLBiome registerBiome(BCLBiome bclbiome) { + if (BuiltinRegistries.BIOME.get(bclbiome.getID()) == null) { + final Biome biome = bclbiome.getBiome(); + ResourceLocation loc = bclbiome.getID(); + Registry.register(BuiltinRegistries.BIOME, loc, biome); } - ID_MAP.put(biome.getID(), biome); - return biome; + ID_MAP.put(bclbiome.getID(), bclbiome); + return bclbiome; } public static BCLBiome registerSubBiome(BCLBiome parent, BCLBiome subBiome) { @@ -273,8 +275,8 @@ public class BiomeAPI { * @param biome {@link BCLBiome} * @return {@link BCLBiome} */ - public static BCLBiome registerEndVoidBiome(Biome biome) { - BCLBiome bclBiome = new BCLBiome(biome, null); + public static BCLBiome registerEndVoidBiome(Holder biome) { + BCLBiome bclBiome = new BCLBiome(biome.value(), null); END_VOID_BIOME_PICKER.addBiome(bclBiome); registerBiome(bclBiome); @@ -288,8 +290,8 @@ public class BiomeAPI { * @param genChance float generation chance. * @return {@link BCLBiome} */ - public static BCLBiome registerEndVoidBiome(Biome biome, float genChance) { - BCLBiome bclBiome = new BCLBiome(biome, VanillaBiomeSettings.createVanilla().setGenChance(genChance).build()); + public static BCLBiome registerEndVoidBiome(Holder biome, float genChance) { + BCLBiome bclBiome = new BCLBiome(biome.value(), VanillaBiomeSettings.createVanilla().setGenChance(genChance).build()); END_VOID_BIOME_PICKER.addBiome(bclBiome); registerBiome(bclBiome); @@ -301,7 +303,7 @@ public class BiomeAPI { * @param biome - {@link Biome} from world. * @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}. */ - public static BCLBiome getFromBiome(Holder biome) { + public static BCLBiome getFromBiome(Biome biome) { if (biomeRegistry == null) { return EMPTY_BIOME; } @@ -334,7 +336,7 @@ public class BiomeAPI { public static ResourceKey getBiomeKey(Biome biome) { return BuiltinRegistries.BIOME .getResourceKey(biome) - .orElse(null); + .orElseGet(() -> biomeRegistry != null ? biomeRegistry.getResourceKey(biome).orElse(null) : null); } /** @@ -344,9 +346,9 @@ public class BiomeAPI { */ public static ResourceLocation getBiomeID(Biome biome) { ResourceLocation id = BuiltinRegistries.BIOME.getKey(biome); - // if (id == null && biomeRegistry != null) { - // id = biomeRegistry.getKey(biome); - //} + if (id == null && biomeRegistry != null) { + id = biomeRegistry.getKey(biome); + } return id == null ? EMPTY_BIOME.getID() : id; } diff --git a/src/main/java/ru/bclib/interfaces/NumericProvider.java b/src/main/java/ru/bclib/interfaces/NumericProvider.java index b24d305e..8bd76b02 100644 --- a/src/main/java/ru/bclib/interfaces/NumericProvider.java +++ b/src/main/java/ru/bclib/interfaces/NumericProvider.java @@ -12,7 +12,7 @@ import java.util.function.Function; public interface NumericProvider { ResourceKey>> NUMERIC_PROVIDER_REGISTRY = ResourceKey.createRegistryKey(BCLib.makeID("worldgen/numeric_provider")); - Registry> NUMERIC_PROVIDER = new MappedRegistry<>(NUMERIC_PROVIDER_REGISTRY, Lifecycle.experimental()); + Registry> NUMERIC_PROVIDER = new MappedRegistry<>(NUMERIC_PROVIDER_REGISTRY, Lifecycle.experimental(), null); Codec CODEC = NUMERIC_PROVIDER.byNameCodec().dispatch(NumericProvider::pcodec, Function.identity()); int getNumber(SurfaceRulesContextAccessor context); diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiome.java b/src/main/java/ru/bclib/world/biomes/BCLBiome.java index aa20d39b..16caea51 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiome.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiome.java @@ -191,7 +191,7 @@ public class BCLBiome extends BCLBiomeSettings { * Recursively update biomes to correct world biome registry instances, for internal usage only. * @param biomeRegistry {@link Registry} for {@link Biome}. */ - public void updateActualBiomes(Registry> biomeRegistry) { + public void updateActualBiomes(Registry biomeRegistry) { subbiomes.forEach((sub) -> { if (sub != this) { sub.updateActualBiomes(biomeRegistry); @@ -201,8 +201,8 @@ public class BCLBiome extends BCLBiomeSettings { edge.updateActualBiomes(biomeRegistry); } - final ResourceKey> key = ResourceKey.create(biomeRegistry.key(), biomeID); - this.actualBiome = biomeRegistry.get(key); + final ResourceKey key = biomeRegistry.getResourceKey(biomeRegistry.get(biomeID)).orElseThrow(); + this.actualBiome = biomeRegistry.getOrCreateHolder(key); if (actualBiome==null) { BCLib.LOGGER.error("Unable to find actual Biome for " + biomeID); } diff --git a/src/main/java/ru/bclib/world/generator/BCLBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLBiomeSource.java index cc3c8b74..d9767866 100644 --- a/src/main/java/ru/bclib/world/generator/BCLBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLBiomeSource.java @@ -9,15 +9,15 @@ import ru.bclib.api.biomes.BiomeAPI; import java.util.List; public abstract class BCLBiomeSource extends BiomeSource { - protected final Registry> biomeRegistry; + protected final Registry biomeRegistry; protected final long seed; - private static List> preInit(Registry> biomeRegistry, List> biomes){ + private static List> preInit(Registry biomeRegistry, List> biomes){ biomes.forEach(biome -> BiomeAPI.sortBiomeFeatures(biome)); return biomes; } - protected BCLBiomeSource(Registry> biomeRegistry, long seed, List> list) { + protected BCLBiomeSource(Registry biomeRegistry, long seed, List> list) { super(preInit(biomeRegistry, list)); this.seed = seed; diff --git a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java index 4d1febba..95c7aac5 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java @@ -45,7 +45,7 @@ public class BCLibEndBiomeSource extends BCLBiomeSource { private BiomeMap mapVoid; private final Point pos; - public BCLibEndBiomeSource(Registry> biomeRegistry, long seed) { + public BCLibEndBiomeSource(Registry biomeRegistry, long seed) { super(biomeRegistry, seed, getBiomes(biomeRegistry)); BiomeAPI.END_LAND_BIOME_PICKER.clearMutables(); @@ -53,7 +53,7 @@ public class BCLibEndBiomeSource extends BCLBiomeSource { List includeVoid = Configs.BIOMES_CONFIG.getEntry("force_include", "end_void_biomes", StringArrayEntry.class).getValue(); this.possibleBiomes().forEach(biome -> { - ResourceLocation key = biomeRegistry.getKey(biome); + ResourceLocation key = biome.unwrapKey().orElseThrow().location(); String group = key.getNamespace() + "." + key.getPath(); if (!BiomeAPI.hasBiome(key)) { @@ -98,8 +98,8 @@ public class BCLibEndBiomeSource extends BCLBiomeSource { this.mapVoid = new HexBiomeMap(seed, GeneratorOptions.getBiomeSizeEndVoid(), BiomeAPI.END_VOID_BIOME_PICKER); } - this.centerBiome = biomeRegistry.get(Biomes.THE_END.location()); - this.barrens = biomeRegistry.get(Biomes.END_BARRENS.location()); + this.centerBiome = biomeRegistry.getOrCreateHolder(Biomes.THE_END); + this.barrens = biomeRegistry.getOrCreateHolder(Biomes.END_BARRENS); WorldgenRandom chunkRandom = new WorldgenRandom(new LegacyRandomSource(seed)); chunkRandom.consumeCount(17292); @@ -109,35 +109,39 @@ public class BCLibEndBiomeSource extends BCLBiomeSource { this.pos = new Point(); } - private static List> getBiomes(Registry> biomeRegistry) { + private static List> getBiomes(Registry biomeRegistry) { List includeLand = Configs.BIOMES_CONFIG.getEntry("force_include", "end_land_biomes", StringArrayEntry.class).getValue(); List includeVoid = Configs.BIOMES_CONFIG.getEntry("force_include", "end_void_biomes", StringArrayEntry.class).getValue(); - return biomeRegistry.stream().filter(biome -> { - ResourceLocation key = biomeRegistry.getKey(biome); - - if (includeLand.contains(key.toString()) || includeVoid.contains(key.toString())) { - return true; - } + return biomeRegistry.stream() + .filter(biome -> biomeRegistry.getResourceKey(biome).isPresent()) + .map(biome -> biomeRegistry.getOrCreateHolder(biomeRegistry.getResourceKey(biome).get())) + .filter(biome -> { + ResourceLocation key = biome.unwrapKey().orElseThrow().location(); - final boolean isEndBiome; - if ((Object)biome instanceof BiomeAccessor bacc) { - isEndBiome = bacc.bclib_getBiomeCategory() == BiomeCategory.THEEND; - if (GeneratorOptions.addEndBiomesByCategory() && isEndBiome) { - return true; - } - } else { - isEndBiome = false; - } - - BCLBiome bclBiome = BiomeAPI.getBiome(key); - if (bclBiome != BiomeAPI.EMPTY_BIOME) { - if (bclBiome.getParentBiome() != null) { - bclBiome = bclBiome.getParentBiome(); - } - key = bclBiome.getID(); - } - return BiomeAPI.END_LAND_BIOME_PICKER.containsImmutable(key) || BiomeAPI.END_VOID_BIOME_PICKER.containsImmutable(key) || (isEndBiome && BiomeAPI.isDatapackBiome(key)); + + if (includeLand.contains(key.toString()) || includeVoid.contains(key.toString())) { + return true; + } + + final boolean isEndBiome; + if ((Object)biome instanceof BiomeAccessor bacc) { + isEndBiome = bacc.bclib_getBiomeCategory() == BiomeCategory.THEEND; + if (GeneratorOptions.addEndBiomesByCategory() && isEndBiome) { + return true; + } + } else { + isEndBiome = false; + } + + BCLBiome bclBiome = BiomeAPI.getBiome(key); + if (bclBiome != BiomeAPI.EMPTY_BIOME) { + if (bclBiome.getParentBiome() != null) { + bclBiome = bclBiome.getParentBiome(); + } + key = bclBiome.getID(); + } + return BiomeAPI.END_LAND_BIOME_PICKER.containsImmutable(key) || BiomeAPI.END_VOID_BIOME_PICKER.containsImmutable(key) || (isEndBiome && BiomeAPI.isDatapackBiome(key)); }).toList(); } diff --git a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java index 23466e7a..4cd6338f 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java @@ -31,7 +31,7 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource { .create(instance -> instance .group(RegistryOps .retrieveRegistry(Registry.BIOME_REGISTRY) - .forGetter(source -> null) + .forGetter(source -> source.biomeRegistry) , Codec .LONG @@ -67,7 +67,7 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource { BCLibNetherBiomeSource.worldHeight = worldHeight; } - public BCLibNetherBiomeSource(Registry> biomeRegistry, long seed) { + public BCLibNetherBiomeSource(Registry biomeRegistry, long seed) { super(biomeRegistry, seed, getBiomes(biomeRegistry)); BiomeAPI.NETHER_BIOME_PICKER.clearMutables(); @@ -97,34 +97,37 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource { initMap(); } - private static List> getBiomes(Registry> biomeRegistry) { + private static List> getBiomes(Registry biomeRegistry) { List include = Configs.BIOMES_CONFIG.getEntry("force_include", "nether_biomes", StringArrayEntry.class).getValue(); - - return biomeRegistry.stream().filter(biome -> { - ResourceLocation key = biomeRegistry.getKey(biome); - - if (include.contains(key.toString())) { - return true; - } - - if (GeneratorOptions.addNetherBiomesByCategory() && (biome instanceof BiomeAccessor) && ((BiomeAccessor)(Object)biome).bclib_getBiomeCategory()== BiomeCategory.NETHER) { - return true; - } - - BCLBiome bclBiome = BiomeAPI.getBiome(key); - if (bclBiome != BiomeAPI.EMPTY_BIOME) { - if (bclBiome.getParentBiome() != null) { - bclBiome = bclBiome.getParentBiome(); - } - key = bclBiome.getID(); - } - final boolean isNetherBiome; - if ((Object)biome instanceof BiomeAccessor bacc) { - isNetherBiome = bacc.bclib_getBiomeCategory() == BiomeCategory.NETHER; - } else { - isNetherBiome = false; - } - return BiomeAPI.NETHER_BIOME_PICKER.containsImmutable(key) || (isNetherBiome && BiomeAPI.isDatapackBiome(key)); + + return biomeRegistry.stream() + .filter(biome -> biomeRegistry.getResourceKey(biome).isPresent()) + .map(biome -> biomeRegistry.getOrCreateHolder(biomeRegistry.getResourceKey(biome).get())) + .filter(biome -> { + ResourceLocation key = biome.unwrapKey().orElseThrow().location(); + + if (include.contains(key.toString())) { + return true; + } + + if (GeneratorOptions.addNetherBiomesByCategory() && (biome instanceof BiomeAccessor) && ((BiomeAccessor)(Object)biome).bclib_getBiomeCategory()== BiomeCategory.NETHER) { + return true; + } + + BCLBiome bclBiome = BiomeAPI.getBiome(key); + if (bclBiome != BiomeAPI.EMPTY_BIOME) { + if (bclBiome.getParentBiome() != null) { + bclBiome = bclBiome.getParentBiome(); + } + key = bclBiome.getID(); + } + final boolean isNetherBiome; + if ((Object)biome instanceof BiomeAccessor bacc) { + isNetherBiome = bacc.bclib_getBiomeCategory() == BiomeCategory.NETHER; + } else { + isNetherBiome = false; + } + return BiomeAPI.NETHER_BIOME_PICKER.containsImmutable(key) || (isNetherBiome && BiomeAPI.isDatapackBiome(key)); }).toList(); } From 824e78abf790cf93afbac9edf76f41c5f059de19 Mon Sep 17 00:00:00 2001 From: Frank Date: Thu, 17 Mar 2022 17:05:59 +0100 Subject: [PATCH 10/34] Fixed compiler errors --- .../ru/bclib/api/biomes/BCLBiomeBuilder.java | 46 ++++----- .../java/ru/bclib/api/biomes/BiomeAPI.java | 99 ++++++++++--------- .../bclib/api/features/BCLFeatureBuilder.java | 12 +-- src/main/java/ru/bclib/api/tag/TagAPI.java | 21 ++++ .../ru/bclib/integration/ModIntegration.java | 14 +-- .../BiomeGenerationSettingsAccessor.java | 9 +- .../mixin/common/RecipeManagerMixin.java | 4 +- .../java/ru/bclib/recipes/AnvilRecipe.java | 13 ++- .../java/ru/bclib/world/biomes/BCLBiome.java | 23 +++-- .../ru/bclib/world/features/BCLFeature.java | 36 ++++++- 10 files changed, 165 insertions(+), 112 deletions(-) diff --git a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java index cc01ec0c..a6c61257 100644 --- a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java @@ -1,16 +1,17 @@ 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.Registry; 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; @@ -44,13 +45,9 @@ 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.*; import java.util.function.BiFunction; import java.util.function.Consumer; -import java.util.function.Supplier; import java.util.stream.Collectors; public class BCLBiomeBuilder { @@ -61,7 +58,7 @@ public class BCLBiomeBuilder { private static final BCLBiomeBuilder INSTANCE = new BCLBiomeBuilder(); private static final SurfaceRules.ConditionSource SURFACE_NOISE = SurfaceRules.noiseCondition(Noises.SOUL_SAND_LAYER, -0.012); - private List structures = new ArrayList<>(16); + private List> structureTags = new ArrayList<>(8); private BiomeGenerationSettings.Builder generationSettings; private BiomeSpecialEffects.Builder effectsBuilder; private MobSpawnSettings.Builder spawnSettings; @@ -91,7 +88,7 @@ public class BCLBiomeBuilder { 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; @@ -546,11 +543,11 @@ public class BCLBiomeBuilder { /** * 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(Holder> structure) { - structures.add(structure.value()); + public BCLBiomeBuilder structure(TagKey structureTag) { + structureTags.add(structureTag); return this; } @@ -561,7 +558,7 @@ public class BCLBiomeBuilder { */ public BCLBiomeBuilder structure(BCLStructureFeature structure) { structure.addInternalBiome(biomeID); - return structure(structure.getFeatureConfigured()); + return structure(structure.biomeTag); } /** @@ -659,7 +656,7 @@ public class BCLBiomeBuilder { public T build(BiFunction biomeConstructor) { return build((id, biome, settings)->biomeConstructor.apply(id, biome)); } - + /** * Finalize biome creation. * @param biomeConstructor {@link BiomeSupplier} biome constructor. @@ -674,24 +671,23 @@ public class BCLBiomeBuilder { builder.mobSpawnSettings(getSpawns().build()); builder.specialEffects(getEffects().build()); - - Map> defferedFeatures = new HashMap<>(); + + Map>> defferedFeatures = Maps.newHashMap(); BiomeGenerationSettingsAccessor acc = BiomeGenerationSettingsAccessor.class.cast(getGeneration().build()); if (acc != null) { builder.generationSettings(new BiomeGenerationSettings.Builder().build()); - var decorations = acc.bclib_getFeatures(); + List> decorations = acc.bclib_getFeatures(); for (Decoration d : Decoration.values()) { int i = d.ordinal(); - if (i >= 0 && i < decorations.size()) { - var features = decorations.get(i); + if (i>=0 && i features = decorations.get(i); defferedFeatures.put(d, features.stream().collect(Collectors.toList())); + } else { + defferedFeatures.put(d, Lists.newArrayList()); } - else { - defferedFeatures.put(d, new ArrayList<>(0)); - } + } - } - else { + } else { builder.generationSettings(getGeneration().build()); } @@ -706,7 +702,7 @@ public class BCLBiomeBuilder { final Biome biome = builder.build(); final T res = biomeConstructor.apply(biomeID, biome, settings); - res.attachStructures(structures); + res.attachStructures(structureTags); res.setSurface(surfaceRule); res.setFeatures(defferedFeatures); return res; diff --git a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java index f96b8a6f..51b00b9f 100644 --- a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java @@ -1,5 +1,7 @@ package ru.bclib.api.biomes; +import com.google.common.base.Suppliers; +import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; @@ -39,6 +41,7 @@ import net.minecraft.world.level.levelgen.SurfaceRules.RuleSource; import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; +import net.minecraft.world.level.levelgen.feature.Feature; import net.minecraft.world.level.levelgen.placement.PlacedFeature; import net.minecraft.world.level.levelgen.structure.StructureSet; import org.apache.commons.lang3.mutable.MutableInt; @@ -77,7 +80,7 @@ public class BiomeAPI { private static final Map CLIENT = Maps.newHashMap(); private static Registry biomeRegistry; - private static final Map FEATURE_ORDER = Maps.newHashMap(); + private static final Map, Integer> FEATURE_ORDER = Maps.newHashMap(); private static final MutableInt FEATURE_ORDER_ID = new MutableInt(0); private static final Map>>> MODIFICATIONS = Maps.newHashMap(); @@ -113,8 +116,7 @@ public class BiomeAPI { .map(Entry::getValue) .map(biome -> (BiomeGenerationSettingsAccessor) biome.getGenerationSettings()) .map(BiomeGenerationSettingsAccessor::bclib_getFeatures) - .forEach(stepFeatureSuppliers -> stepFeatureSuppliers.forEach(step -> step.forEach(featureSupplier -> { - PlacedFeature feature = featureSupplier.value(); + .forEach(stepFeatureSuppliers -> stepFeatureSuppliers.forEach(step -> step.forEach(feature -> { FEATURE_ORDER.computeIfAbsent(feature, f -> FEATURE_ORDER_ID.getAndIncrement()); }))); } @@ -427,7 +429,7 @@ public class BiomeAPI { FabricBiomesData.END_VOID_BIOMES.forEach((key, weight) -> { if (!hasBiome(key.location())) { - registerEndVoidBiome(BuiltinRegistries.BIOME.get(key), weight); + registerEndVoidBiome(BuiltinRegistries.BIOME.getOrCreateHolder(key), weight); } }); } @@ -581,12 +583,12 @@ public class BiomeAPI { public static void sortBiomeFeatures(Holder biome) { BiomeGenerationSettings settings = biome.value().getGenerationSettings(); BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) settings; - List>> featureList = CollectionsUtil.getMutable(accessor.bclib_getFeatures()); + List> featureList = CollectionsUtil.getMutable(accessor.bclib_getFeatures()); final int size = featureList.size(); for (int i = 0; i < size; i++) { - List> features = CollectionsUtil.getMutable(featureList.get(i)); + List> features = getFeaturesListCopy(featureList, i); sortFeatures(features); - featureList.set(i, features); + featureList.set(i, HolderSet.direct(features)); } accessor.bclib_setFeatures(featureList); } @@ -652,20 +654,24 @@ public class BiomeAPI { * Adds new features to existing biome. * @param biome {@link Biome} to add features in. * @param step a {@link Decoration} step for the feature. - * @param featureList List of {@link ConfiguredFeature} to add. + * @param additionalFeatures List of {@link ConfiguredFeature} to add. */ - private static void addBiomeFeature(Holder biome, Decoration step, List> featureList) { + private static void addBiomeFeature(Holder biome, Decoration step, List> additionalFeatures) { BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.value().getGenerationSettings(); List> allFeatures = CollectionsUtil.getMutable(accessor.bclib_getFeatures()); - Set set = CollectionsUtil.getMutable(accessor.bclib_getFeatureSet().get()); - HolderSet features = getFeaturesList(allFeatures, step); - for (var feature : featureList) { - features. - features.add(() -> feature); - set.add(feature); + List> features = getFeaturesListCopy(allFeatures, step); + + for (var feature : additionalFeatures) { + if (!features.contains(feature)) + features.add(feature); } + + allFeatures.set(step.ordinal(), HolderSet.direct(features)); + final Supplier>> flowerFeatures = Suppliers.memoize(() -> allFeatures.stream().flatMap(HolderSet::stream).map(Holder::value).flatMap(PlacedFeature::getFeatures).filter(configuredFeature -> configuredFeature.feature() == Feature.FLOWER).collect(ImmutableList.toImmutableList())); + final Supplier> featureSet = Suppliers.memoize(() -> allFeatures.stream().flatMap(HolderSet::stream).map(Holder::value).collect(Collectors.toSet())); + accessor.bclib_setFeatures(allFeatures); - accessor.bclib_setFeatureSet(()-> set); + accessor.bclib_setFeatureSet(featureSet); } /** @@ -676,22 +682,10 @@ public class BiomeAPI { * @param biome {@link Biome} to add features in. * @param featureMap Map of {@link ConfiguredFeature} to add. */ - private static void addStepFeaturesToBiome(Holder biome, Map>> featureMap) { - BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.value().getGenerationSettings(); - List>> allFeatures = CollectionsUtil.getMutable(accessor.bclib_getFeatures()); - Set set = CollectionsUtil.getMutable(accessor.bclib_getFeatureSet().get()); - + private static void addStepFeaturesToBiome(Holder biome, Map>> featureMap) { for (Decoration step: featureMap.keySet()) { - List> features = getFeaturesList(allFeatures, step); - List> featureList = featureMap.get(step); - - for (Supplier feature : featureList) { - features.add(feature); - set.add(feature.get()); - } + addBiomeFeature(biome, step, featureMap.get(step)); } - accessor.bclib_setFeatures(allFeatures); - accessor.bclib_setFeatureSet(() -> set); } /** @@ -700,13 +694,20 @@ public class BiomeAPI { * @param carver {@link ConfiguredWorldCarver} to add. * @param stage {@link Carving} stage. */ - public static void addBiomeCarver(Biome biome, ConfiguredWorldCarver carver, Carving stage) { + public static void addBiomeCarver(Biome biome, Holder> carver, Carving stage) { BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings(); - Map>> carvers = CollectionsUtil.getMutable(accessor.bclib_getCarvers()); - HolderSet> carverList = CollectionsUtil.getMutable(carvers.getOrDefault(stage, new ArrayList<>())); - carvers.put(stage, carverList); - carverList.add(() -> carver); - accessor.bclib_setCarvers(carvers); + Map>> carverMap = CollectionsUtil.getMutable(accessor.bclib_getCarvers()); + HolderSet> carvers = carverMap.get(stage); + + List>> carverList; + if (carvers==null) { + carverList = Lists.newArrayList(); + } else { + carverList = carvers.stream().toList(); + } + carverList.add(carver); + carverMap.put(stage, HolderSet.direct(carverList)); + accessor.bclib_setCarvers(carverMap); } /** @@ -866,25 +867,24 @@ public class BiomeAPI { } } - private static void sortFeatures(List> features) { + private static void sortFeatures(List> features) { initFeatureOrder(); - Set featuresWithoutDuplicates = Sets.newHashSet(); - features.forEach(provider -> featuresWithoutDuplicates.add(provider.get())); + Set> featuresWithoutDuplicates = Sets.newHashSet(); + features.forEach(holder -> featuresWithoutDuplicates.add(holder)); if (featuresWithoutDuplicates.size() != features.size()) { features.clear(); - featuresWithoutDuplicates.forEach(feature -> features.add(() -> feature)); + featuresWithoutDuplicates.forEach(feature -> features.add(feature)); } - features.forEach(provider -> { - PlacedFeature feature = provider.get(); + features.forEach(feature -> { FEATURE_ORDER.computeIfAbsent(feature, f -> FEATURE_ORDER_ID.getAndIncrement()); }); features.sort((f1, f2) -> { - int v1 = FEATURE_ORDER.getOrDefault(f1.get(), 70000); - int v2 = FEATURE_ORDER.getOrDefault(f2.get(), 70000); + int v1 = FEATURE_ORDER.getOrDefault(f1, 70000); + int v2 = FEATURE_ORDER.getOrDefault(f2, 70000); return Integer.compare(v1, v2); }); } @@ -906,14 +906,15 @@ public class BiomeAPI { lists.set(index, list); return list; } + + private static List> getFeaturesListCopy(List> features, Decoration step) { + return getFeaturesListCopy(features, step.ordinal()); + } - private static HolderSet getFeaturesList(List> features, Decoration step) { - int index = step.ordinal(); + private static List> getFeaturesListCopy(List> features, int index) { while (features.size() <= index) { features.add(HolderSet.direct(Lists.newArrayList())); } - HolderSet mutable = features.get(index); - features.set(index, mutable); - return mutable; + return features.get(index).stream().collect(Collectors.toList()); } } diff --git a/src/main/java/ru/bclib/api/features/BCLFeatureBuilder.java b/src/main/java/ru/bclib/api/features/BCLFeatureBuilder.java index 3aa49a0d..ec98fb1e 100644 --- a/src/main/java/ru/bclib/api/features/BCLFeatureBuilder.java +++ b/src/main/java/ru/bclib/api/features/BCLFeatureBuilder.java @@ -4,6 +4,7 @@ import net.minecraft.data.worldgen.placement.PlacementUtils; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.valueproviders.UniformInt; import net.minecraft.world.level.levelgen.GenerationStep.Decoration; +import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.Feature; import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration; import net.minecraft.world.level.levelgen.placement.BiomeFilter; @@ -18,12 +19,12 @@ import ru.bclib.world.features.BCLFeature; import java.util.ArrayList; import java.util.List; -public class BCLFeatureBuilder { +public class BCLFeatureBuilder >{ private static final BCLFeatureBuilder INSTANCE = new BCLFeatureBuilder(); private List modifications = new ArrayList<>(16); private ResourceLocation featureID; private Decoration decoration; - private Feature feature; + private F feature; private BCLFeatureBuilder() {} @@ -134,10 +135,9 @@ public class BCLFeatureBuilder { * @param configuration any {@link FeatureConfiguration} for provided {@link Feature}. * @return created {@link BCLFeature} instance. */ - public BCLFeature build(FC configuration) { + public BCLFeature build(FC configuration) { PlacementModifier [] modifiers = modifications.toArray(new PlacementModifier [modifications.size()]); - PlacedFeature configured = ((Feature) feature).configured(configuration).placed(modifiers); - return new BCLFeature(featureID, feature, decoration, configured); + return new BCLFeature(featureID, feature, decoration, configuration, modifiers); } /** @@ -146,6 +146,6 @@ public class BCLFeatureBuilder { * @return created {@link BCLFeature} instance. */ public BCLFeature build() { - return build(FeatureConfiguration.NONE); + return build((FC)FeatureConfiguration.NONE); } } diff --git a/src/main/java/ru/bclib/api/tag/TagAPI.java b/src/main/java/ru/bclib/api/tag/TagAPI.java index a3b0da16..8d381b50 100644 --- a/src/main/java/ru/bclib/api/tag/TagAPI.java +++ b/src/main/java/ru/bclib/api/tag/TagAPI.java @@ -62,6 +62,16 @@ public class TagAPI { public static TagKey makeBlockTag(String modID, String name) { return makeTag(Registry.BLOCK, new TagLocation<>(modID, name)); } + + /** + * Get or create {@link Block} {@link TagKey} with mod namespace. + * + * @param id - {@link String} id for the tag; + * @return {@link Block} {@link TagKey}. + */ + public static TagKey makeBlockTag(ResourceLocation id) { + return makeTag(Registry.BLOCK, new TagLocation<>(id)); + } /** * Get or create {@link Item} {@link TagKey} with mod namespace. @@ -73,6 +83,16 @@ public class TagAPI { public static TagKey makeItemTag(String modID, String name) { return makeTag(Registry.ITEM, new TagLocation<>(modID, name)); } + + /** + * Get or create {@link Item} {@link TagKey} with mod namespace. + * + * @param id - {@link String} id for the tag; + * @return {@link Item} {@link TagKey}. + */ + public static TagKey makeItemTag(ResourceLocation id) { + return makeTag(Registry.ITEM, new TagLocation<>(id)); + } /** * Get or create {@link Block} {@link TagKey}. @@ -208,6 +228,7 @@ public class TagAPI { * @return The {@code tagsMap} Parameter. */ public static Map apply(String directory, Map tagsMap) { + System.out.println("TAG DIRECTORY: " + directory); final BiConsumer> consumer; consumer = (id, ids) -> apply(tagsMap.computeIfAbsent(id, key -> Tag.Builder.tag()), ids); if ("tags/blocks".equals(directory)) { diff --git a/src/main/java/ru/bclib/integration/ModIntegration.java b/src/main/java/ru/bclib/integration/ModIntegration.java index 8ff8ea63..bc5961dc 100644 --- a/src/main/java/ru/bclib/integration/ModIntegration.java +++ b/src/main/java/ru/bclib/integration/ModIntegration.java @@ -19,6 +19,7 @@ import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.Feature; import net.minecraft.world.level.levelgen.placement.PlacedFeature; import ru.bclib.BCLib; +import ru.bclib.api.tag.TagAPI; import ru.bclib.world.features.BCLFeature; import java.lang.reflect.Constructor; @@ -66,8 +67,8 @@ public abstract class ModIntegration { public BCLFeature getFeature(String featureID, String placedFeatureID, GenerationStep.Decoration featureStep) { ResourceLocation id = getID(featureID); Feature feature = Registry.FEATURE.get(id); - Holder featureConfigured = BuiltinRegistries.PLACED_FEATURE.getHolder(getFeatureKey(placedFeatureID)).orElse(null); - return new BCLFeature(id, feature, featureStep, featureConfigured); + Holder featurePlaced = BuiltinRegistries.PLACED_FEATURE.getHolder(getFeatureKey(placedFeatureID)).orElse(null); + return new BCLFeature(id, feature, featureStep, featurePlaced); } public BCLFeature getFeature(String name, GenerationStep.Decoration featureStep) { @@ -203,16 +204,11 @@ public abstract class ModIntegration { public TagKey getItemTag(String name) { ResourceLocation id = getID(name); - Tag tag = ItemTags.getAllTags().getTag(id); - - //return tag == null ? (TagKey) TagRegistry.item(id) : (TagKey) tag; - return tag == null ? (TagKey) TagFactory.ITEM.create(id) : (TagKey) tag; + return TagAPI.makeItemTag(id); } public TagKey getBlockTag(String name) { ResourceLocation id = getID(name); - Tag tag = BlockTags.getAllTags().getTag(id); - //return tag == null ? (Named) TagRegistry.block(id) : (Named) tag; - return tag == null ? (TagKey) TagFactory.BLOCK.create(id) : (TagKey) tag; + return TagAPI.makeBlockTag(id); } } diff --git a/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java b/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java index 62e0b156..ff7cda65 100644 --- a/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java +++ b/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java @@ -5,6 +5,7 @@ import net.minecraft.world.level.biome.BiomeGenerationSettings; import net.minecraft.world.level.levelgen.GenerationStep; import net.minecraft.world.level.levelgen.GenerationStep.Carving; import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver; +import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.placement.PlacedFeature; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mutable; @@ -28,7 +29,13 @@ public interface BiomeGenerationSettingsAccessor { Supplier> bclib_getFeatureSet(); @Accessor("featureSet") - void bclib_setFeatureSet(Supplier> features); + void bclib_setFeatureSet(Supplier> featureSet); + + @Accessor("flowerFeatures") + Supplier>> bclib_getFlowerFeatures(); + + @Accessor("flowerFeatures") + void bclib_setFlowerFeatures(Supplier>> flowerFeatures); @Accessor("carvers") Map>> bclib_getCarvers(); diff --git a/src/main/java/ru/bclib/mixin/common/RecipeManagerMixin.java b/src/main/java/ru/bclib/mixin/common/RecipeManagerMixin.java index 70b8878d..10c85644 100644 --- a/src/main/java/ru/bclib/mixin/common/RecipeManagerMixin.java +++ b/src/main/java/ru/bclib/mixin/common/RecipeManagerMixin.java @@ -27,7 +27,7 @@ public abstract class RecipeManagerMixin { } @Inject(method = "getRecipeFor", at = @At(value = "HEAD"), cancellable = true) - private > void bclib_getRecipeFor(RecipeType type, C inventory, Level world, CallbackInfoReturnable> info) { + private > void bclib_getRecipeFor(RecipeType type, C inventory, Level level, CallbackInfoReturnable> info) { Collection> values = byType(type).values(); List> list = new ArrayList<>(values); list.sort((v1, v2) -> { @@ -35,6 +35,6 @@ public abstract class RecipeManagerMixin { boolean b2 = v2.getId().getNamespace().equals("minecraft"); return b1 ^ b2 ? (b1 ? 1 : -1) : 0; }); - info.setReturnValue(list.stream().flatMap((recipe) -> Util.toStream(type.tryMatch(recipe, world, inventory))).findFirst()); + info.setReturnValue(list.stream().flatMap(recipe -> type.tryMatch(recipe, level, inventory).stream()).findFirst()); } } \ No newline at end of file diff --git a/src/main/java/ru/bclib/recipes/AnvilRecipe.java b/src/main/java/ru/bclib/recipes/AnvilRecipe.java index 495b95b2..c2b3b3a0 100644 --- a/src/main/java/ru/bclib/recipes/AnvilRecipe.java +++ b/src/main/java/ru/bclib/recipes/AnvilRecipe.java @@ -4,12 +4,14 @@ import com.google.gson.JsonObject; import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider; import net.minecraft.core.NonNullList; import net.minecraft.core.Registry; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.TagParser; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.ItemTags; import net.minecraft.tags.Tag; import net.minecraft.tags.TagKey; import net.minecraft.util.GsonHelper; @@ -142,12 +144,13 @@ public class AnvilRecipe implements Recipe, UnknownReceipBookCategory @Override public NonNullList getIngredients() { + ; NonNullList defaultedList = NonNullList.create(); - defaultedList.add(Ingredient.of(CommonItemTags.HAMMERS - .getValues() - .stream() - .filter(hammer -> ((TieredItem) hammer).getTier().getLevel() >= toolLevel) - .map(ItemStack::new))); + defaultedList.add(Ingredient.of(Registry.ITEM.stream() + .filter(item->item.builtInRegistryHolder().is(CommonItemTags.HAMMERS)) + .filter(hammer -> ((TieredItem) hammer).getTier().getLevel() >= toolLevel) + .map(ItemStack::new)) + ); defaultedList.add(input); return defaultedList; } diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiome.java b/src/main/java/ru/bclib/world/biomes/BCLBiome.java index 16caea51..48d8d3d6 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiome.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiome.java @@ -2,11 +2,13 @@ package ru.bclib.world.biomes; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import com.google.common.collect.Sets; import net.minecraft.core.Holder; import net.minecraft.core.Registry; import net.minecraft.data.BuiltinRegistries; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.TagKey; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.levelgen.GenerationStep.Decoration; import net.minecraft.world.level.levelgen.SurfaceRules; @@ -18,15 +20,14 @@ import ru.bclib.BCLib; import ru.bclib.api.biomes.BiomeAPI; import ru.bclib.util.WeightedList; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Random; +import java.util.Set; import java.util.function.Consumer; -import java.util.function.Supplier; public class BCLBiome extends BCLBiomeSettings { - private final List structures = Lists.newArrayList(); + private final Set> structureTags = Sets.newHashSet(); private final WeightedList subbiomes = new WeightedList<>(); private final Map customData = Maps.newHashMap(); private final ResourceLocation biomeID; @@ -207,15 +208,17 @@ public class BCLBiome extends BCLBiomeSettings { BCLib.LOGGER.error("Unable to find actual Biome for " + biomeID); } - if (!this.structures.isEmpty()) { + if (!this.structureTags.isEmpty()) { //TODO: 1.18.2 This need to be done by BiomeTags now - structures.forEach(s -> BiomeAPI.addBiomeStructure(BiomeAPI.getBiomeKey(actualBiome), s)); + structureTags.forEach(tagKey -> {System.out.println("Code to add Tags to Biomes should go here. " + tagKey);}); } if (this.surfaceInit != null) { surfaceInit.accept(actualBiome); } } + + /** * Getter for custom data. Will get custom data object or null if object doesn't exists. @@ -283,8 +286,8 @@ public class BCLBiome extends BCLBiomeSettings { * Adds structures to this biome. For internal use only. * Used inside {@link ru.bclib.api.biomes.BCLBiomeBuilder}. */ - public void attachStructures(List structures) { - this.structures.addAll(structures); + public void attachStructures(List> structures) { + this.structureTags.addAll(structures); } /** @@ -303,13 +306,13 @@ public class BCLBiome extends BCLBiomeSettings { }; } - private Map>> features = new HashMap<>(0); + private Map>> features = Maps.newHashMap(); /** * Sets the biome features. * @param features the feature list. */ - public void setFeatures(Map>> features) { + public void setFeatures(Map>> features) { this.features = features; } @@ -317,7 +320,7 @@ public class BCLBiome extends BCLBiomeSettings { * Returns the built-in set of Features for this biome (as they were set with {@link #setFeatures(Map)}) * @return List of all features */ - public Map>> getFeatures(){ + public Map>> getFeatures(){ return features; } diff --git a/src/main/java/ru/bclib/world/features/BCLFeature.java b/src/main/java/ru/bclib/world/features/BCLFeature.java index 33e4ef3a..ef59e1d6 100644 --- a/src/main/java/ru/bclib/world/features/BCLFeature.java +++ b/src/main/java/ru/bclib/world/features/BCLFeature.java @@ -3,25 +3,35 @@ package ru.bclib.world.features; import net.minecraft.core.Holder; import net.minecraft.core.Registry; import net.minecraft.data.BuiltinRegistries; +import net.minecraft.data.worldgen.features.FeatureUtils; +import net.minecraft.data.worldgen.placement.PlacementUtils; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.levelgen.GenerationStep.Decoration; +import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.Feature; +import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration; import net.minecraft.world.level.levelgen.placement.PlacedFeature; +import net.minecraft.world.level.levelgen.placement.PlacementModifier; import java.util.Map.Entry; import java.util.Optional; public class BCLFeature { - private Holder placedFeature; - private Decoration featureStep; - private Feature feature; - + private final Holder placedFeature; + private final Decoration featureStep; + private final Feature feature; + + + public> BCLFeature(ResourceLocation id, F feature, Decoration featureStep, FC configuration, PlacementModifier[] modifiers) { + this(id, feature, featureStep, buildPlacedFeature(id, feature, configuration, modifiers)); + } + public BCLFeature(ResourceLocation id, Feature feature, Decoration featureStep, Holder placedFeature) { this.placedFeature = placedFeature; this.featureStep = featureStep; this.feature = feature; - + if (!BuiltinRegistries.PLACED_FEATURE.containsKey(id)) { Registry.register(BuiltinRegistries.PLACED_FEATURE, id, placedFeature.value()); } @@ -29,6 +39,22 @@ public class BCLFeature { Registry.register(Registry.FEATURE, id, feature); } } + + private static > Holder buildPlacedFeature(ResourceLocation id, F feature, FC configuration, PlacementModifier[] modifiers) { + Holder> configuredFeature; + //TODO: 1.18.2 Check if this cast is working + if (!BuiltinRegistries.CONFIGURED_FEATURE.containsKey(id)) { + configuredFeature = (Holder>)(Object)FeatureUtils.register(id.toString(), feature, configuration); + } else { + configuredFeature = BuiltinRegistries.CONFIGURED_FEATURE.getHolder(ResourceKey.create(BuiltinRegistries.CONFIGURED_FEATURE.key(), id)).orElseThrow(); + } + + if (!BuiltinRegistries.PLACED_FEATURE.containsKey(id)) { + return PlacementUtils.register(id.toString(), configuredFeature, modifiers); + } else { + return BuiltinRegistries.PLACED_FEATURE.getHolder(ResourceKey.create(BuiltinRegistries.PLACED_FEATURE.key(), id)).orElseThrow(); + } + } private static boolean containsObj(Registry registry, E obj) { Optional, E>> optional = registry From e2c4f91f58a43f86000ab1fbb7ed5cd7939264a3 Mon Sep 17 00:00:00 2001 From: Frank Date: Thu, 17 Mar 2022 17:19:26 +0100 Subject: [PATCH 11/34] Fixed mixin errors --- .../client/EnchantingTableBlockMixin.java | 4 +-- .../mixin/common/DimensionTypeMixin.java | 2 +- .../mixin/common/EnchantmentMenuMixin.java | 29 ------------------- src/main/resources/bclib.mixins.common.json | 1 - 4 files changed, 3 insertions(+), 33 deletions(-) delete mode 100644 src/main/java/ru/bclib/mixin/common/EnchantmentMenuMixin.java diff --git a/src/main/java/ru/bclib/mixin/client/EnchantingTableBlockMixin.java b/src/main/java/ru/bclib/mixin/client/EnchantingTableBlockMixin.java index 9ac56d2e..db8ddd23 100644 --- a/src/main/java/ru/bclib/mixin/client/EnchantingTableBlockMixin.java +++ b/src/main/java/ru/bclib/mixin/client/EnchantingTableBlockMixin.java @@ -15,13 +15,13 @@ public abstract class EnchantingTableBlockMixin extends Block { super(settings); } - @Redirect(method = "animateTick", at = @At( + @Redirect(method = "isValidBookShelf", at = @At( value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/BlockState;is(Lnet/minecraft/world/level/block/Block;)Z"), require = -1, expect = -1 ) - private boolean bclib_isBookshelf(BlockState state, Block block) { + private static boolean bclib_isBookshelf(BlockState state, Block block) { return block == Blocks.BOOKSHELF ? state.is(CommonBlockTags.BOOKSHELVES) : state.is(block); } } diff --git a/src/main/java/ru/bclib/mixin/common/DimensionTypeMixin.java b/src/main/java/ru/bclib/mixin/common/DimensionTypeMixin.java index 656b7367..6945bb2e 100644 --- a/src/main/java/ru/bclib/mixin/common/DimensionTypeMixin.java +++ b/src/main/java/ru/bclib/mixin/common/DimensionTypeMixin.java @@ -32,7 +32,7 @@ public class DimensionTypeMixin { locals = LocalCapture.CAPTURE_FAILHARD, at = @At("TAIL") ) - private static void bclib_updateDimensions(RegistryAccess registryAccess, long seed, boolean bl, CallbackInfoReturnable> info, @NotNull MappedRegistry writableRegistry, Registry registry, Registry biomeRegistry, Registry structureRegistry, Registry noiseSettingsRegistry, Registry noiseParamRegistry) { + private static void bclib_updateDimensions(RegistryAccess registryAccess, long seed, boolean bl, CallbackInfoReturnable info, WritableRegistry writableRegistry, Registry registry, Registry biomeRegistry, Registry structureRegistry, Registry noiseSettingsRegistry, Registry noiseParamRegistry) { int id = writableRegistry.getId(writableRegistry.get(LevelStem.NETHER)); writableRegistry.register( LevelStem.NETHER, diff --git a/src/main/java/ru/bclib/mixin/common/EnchantmentMenuMixin.java b/src/main/java/ru/bclib/mixin/common/EnchantmentMenuMixin.java deleted file mode 100644 index 6e33274f..00000000 --- a/src/main/java/ru/bclib/mixin/common/EnchantmentMenuMixin.java +++ /dev/null @@ -1,29 +0,0 @@ -package ru.bclib.mixin.common; - -import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraft.world.inventory.EnchantmentMenu; -import net.minecraft.world.inventory.MenuType; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.state.BlockState; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; -import ru.bclib.api.tag.CommonBlockTags; - -@Mixin(EnchantmentMenu.class) -public abstract class EnchantmentMenuMixin extends AbstractContainerMenu { - protected EnchantmentMenuMixin(MenuType type, int syncId) { - super(type, syncId); - } - - @Redirect(method = "lambda$slotsChanged$0(Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)V", at = @At( - value = "INVOKE", - target = "Lnet/minecraft/world/level/block/state/BlockState;is(Lnet/minecraft/world/level/block/Block;)Z"), - require = -1, - expect = -1 - ) - private boolean bclib_isBookshelf(BlockState state, Block block) { - return block == Blocks.BOOKSHELF ? state.is(CommonBlockTags.BOOKSHELVES) : state.is(block); - } -} diff --git a/src/main/resources/bclib.mixins.common.json b/src/main/resources/bclib.mixins.common.json index 50f21ce8..52029a3f 100644 --- a/src/main/resources/bclib.mixins.common.json +++ b/src/main/resources/bclib.mixins.common.json @@ -21,7 +21,6 @@ "RecipeManagerAccessor", "DiggerItemAccessor", "shears.SnowGolemMixin", - "EnchantmentMenuMixin", "MinecraftServerMixin", "NetherBiomeDataMixin", "PistonBaseBlockMixin", From 7cb0d5de6c11b2169d729b662842c285eef69726 Mon Sep 17 00:00:00 2001 From: Frank Date: Thu, 17 Mar 2022 17:26:26 +0100 Subject: [PATCH 12/34] Fixed BiomeSource registration error --- src/main/java/ru/bclib/mixin/common/DimensionTypeMixin.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/bclib/mixin/common/DimensionTypeMixin.java b/src/main/java/ru/bclib/mixin/common/DimensionTypeMixin.java index 6945bb2e..7618432a 100644 --- a/src/main/java/ru/bclib/mixin/common/DimensionTypeMixin.java +++ b/src/main/java/ru/bclib/mixin/common/DimensionTypeMixin.java @@ -34,7 +34,8 @@ public class DimensionTypeMixin { ) private static void bclib_updateDimensions(RegistryAccess registryAccess, long seed, boolean bl, CallbackInfoReturnable info, WritableRegistry writableRegistry, Registry registry, Registry biomeRegistry, Registry structureRegistry, Registry noiseSettingsRegistry, Registry noiseParamRegistry) { int id = writableRegistry.getId(writableRegistry.get(LevelStem.NETHER)); - writableRegistry.register( + writableRegistry.registerOrOverride( + OptionalInt.of(id), LevelStem.NETHER, new LevelStem( registry.getOrCreateHolder(DimensionType.NETHER_LOCATION), @@ -50,7 +51,8 @@ public class DimensionTypeMixin { id = writableRegistry.getId(writableRegistry.get(LevelStem.END)); - writableRegistry.register( + writableRegistry.registerOrOverride( + OptionalInt.of(id), LevelStem.END, new LevelStem( registry.getOrCreateHolder(DimensionType.END_LOCATION), From 03eda716fe7fa55666d3f7bb57c8a10ee7ba8f14 Mon Sep 17 00:00:00 2001 From: Frank Date: Thu, 17 Mar 2022 17:40:28 +0100 Subject: [PATCH 13/34] Added BiomeTag handling --- src/main/java/ru/bclib/api/tag/TagAPI.java | 54 ++++++++++++++++++- .../ru/bclib/mixin/common/TagLoaderMixin.java | 1 - .../java/ru/bclib/world/biomes/BCLBiome.java | 3 +- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/main/java/ru/bclib/api/tag/TagAPI.java b/src/main/java/ru/bclib/api/tag/TagAPI.java index 8d381b50..557cac7e 100644 --- a/src/main/java/ru/bclib/api/tag/TagAPI.java +++ b/src/main/java/ru/bclib/api/tag/TagAPI.java @@ -3,6 +3,7 @@ package ru.bclib.api.tag; import com.google.common.collect.Maps; import com.google.common.collect.Sets; import net.minecraft.core.Registry; +import net.minecraft.data.BuiltinRegistries; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.resources.ResourceManager; import net.minecraft.tags.Tag; @@ -14,6 +15,7 @@ import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; +import ru.bclib.api.biomes.BiomeAPI; import ru.bclib.mixin.common.DiggerItemAccessor; import java.util.Map; @@ -23,6 +25,7 @@ import java.util.function.BiConsumer; public class TagAPI { private static final Map> TAGS_BLOCK = Maps.newConcurrentMap(); private static final Map> TAGS_ITEM = Maps.newConcurrentMap(); + private static final Map> TAGS_BIOME = Maps.newConcurrentMap(); /** * Get or create {@link TagKey}. @@ -126,7 +129,52 @@ public class TagAPI { addItemTag(CommonItemTags.IRON_INGOTS, Items.IRON_INGOT); addItemTag(CommonItemTags.FURNACES, Blocks.FURNACE); } - + + /** + * Adds multiple Tags to one Biome. + * @param tagIDs array of {@link TagLocation} tag IDs. + * @param biome The {@link Biome} to add tag. + */ + @SafeVarargs + public static void addBiomeTags(Biome biome, TagLocation... tagIDs) { + for (TagLocation tagID : tagIDs) { + addBiomeTagUntyped(tagID, biome); + } + } + + /** + * Adds one Tag to multiple Biomes. + * @param tagID {@link TagLocation} tag ID. + * @param biomes array of {@link Biome} to add into tag. + */ + public static void addBiomeTag(TagLocation tagID, Biome... biomes) { + addBiomeTagUntyped(tagID, biomes); + } + + /** + * Adds one Tag to multiple Biomes. + * @param tagID {@link TagKey} tag ID. + * @param biomes array of {@link Biome} to add into tag. + */ + public static void addBiomeTag(TagKey tagID, Biome... biomes) { + addBiomeTagUntyped(tagID.location(), biomes); + } + /** + * Adds one Tag to multiple Biomes. + * @param tagID {@link ResourceLocation} tag ID. + * @param biomes array of {@link Biome} to add into tag. + */ + protected static void addBiomeTagUntyped(ResourceLocation tagID, Biome... biomes) { + Set set = TAGS_BIOME.computeIfAbsent(tagID, k -> Sets.newHashSet()); + for (Biome biome : biomes) { + ResourceLocation id = BiomeAPI.getBiomeID(biome); + if (id != null) { + set.add(id); + } + } + } + + /** * Adds multiple Tags to one Block. * @param tagIDs array of {@link TagLocation} tag IDs. @@ -228,7 +276,6 @@ public class TagAPI { * @return The {@code tagsMap} Parameter. */ public static Map apply(String directory, Map tagsMap) { - System.out.println("TAG DIRECTORY: " + directory); final BiConsumer> consumer; consumer = (id, ids) -> apply(tagsMap.computeIfAbsent(id, key -> Tag.Builder.tag()), ids); if ("tags/blocks".equals(directory)) { @@ -237,6 +284,9 @@ public class TagAPI { else if ("tags/items".equals(directory)) { TAGS_ITEM.forEach(consumer); } + else if ("tags/worldgen/biome".equals(directory)) { + TAGS_BIOME.forEach(consumer); + } return tagsMap; } diff --git a/src/main/java/ru/bclib/mixin/common/TagLoaderMixin.java b/src/main/java/ru/bclib/mixin/common/TagLoaderMixin.java index cf5722e8..46b83f7a 100644 --- a/src/main/java/ru/bclib/mixin/common/TagLoaderMixin.java +++ b/src/main/java/ru/bclib/mixin/common/TagLoaderMixin.java @@ -20,7 +20,6 @@ public class TagLoaderMixin { @ModifyArg(method = "loadAndBuild", at = @At(value = "INVOKE", target = "Lnet/minecraft/tags/TagLoader;build(Ljava/util/Map;)Ljava/util/Map;")) public Map be_modifyTags(Map tagsMap) { - //TODO: 1.18.2 Check if this still works as expected return TagAPI.apply(directory, tagsMap); } } diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiome.java b/src/main/java/ru/bclib/world/biomes/BCLBiome.java index 48d8d3d6..1100c561 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiome.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiome.java @@ -18,6 +18,7 @@ import net.minecraft.world.level.levelgen.placement.PlacedFeature; import org.jetbrains.annotations.Nullable; import ru.bclib.BCLib; import ru.bclib.api.biomes.BiomeAPI; +import ru.bclib.api.tag.TagAPI; import ru.bclib.util.WeightedList; import java.util.List; @@ -210,7 +211,7 @@ public class BCLBiome extends BCLBiomeSettings { if (!this.structureTags.isEmpty()) { //TODO: 1.18.2 This need to be done by BiomeTags now - structureTags.forEach(tagKey -> {System.out.println("Code to add Tags to Biomes should go here. " + tagKey);}); + structureTags.forEach(tagKey -> TagAPI.addBiomeTag(tagKey, actualBiome.value())); } if (this.surfaceInit != null) { From 6bb218416f4b29d611630d3d48767e50224463d7 Mon Sep 17 00:00:00 2001 From: Frank Date: Thu, 17 Mar 2022 17:47:00 +0100 Subject: [PATCH 14/34] Versions and Dependencies for 1.18.2 --- src/main/resources/fabric.mod.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 420a79b0..b775d1f4 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -37,8 +37,8 @@ "bclib.mixins.client.json" ], "depends": { - "fabricloader": ">=0.12.9", - "fabric": ">=0.44.0", + "fabricloader": ">=0.13.3", + "fabric": ">=0.48.0", "minecraft": "1.18.x" }, "custom":{ From d817a69ae704e68d125188ca16209ba41d0a64c3 Mon Sep 17 00:00:00 2001 From: Frank Date: Thu, 17 Mar 2022 21:20:15 +0100 Subject: [PATCH 15/34] Fixes for Entities, Structures and Features --- .../ru/bclib/api/biomes/BCLBiomeBuilder.java | 21 +++++++------------ .../java/ru/bclib/api/biomes/BiomeAPI.java | 12 +++++------ .../world/structures/BCLStructureFeature.java | 5 ++++- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java index a6c61257..302de18f 100644 --- a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java @@ -6,8 +6,8 @@ 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; @@ -15,16 +15,10 @@ 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; @@ -33,7 +27,6 @@ import net.minecraft.world.level.levelgen.GenerationStep.Decoration; 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; @@ -45,7 +38,9 @@ import ru.bclib.world.biomes.BCLBiomeSettings; import ru.bclib.world.features.BCLFeature; import ru.bclib.world.structures.BCLStructureFeature; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; import java.util.function.BiFunction; import java.util.function.Consumer; import java.util.stream.Collectors; @@ -566,11 +561,9 @@ public class BCLBiomeBuilder { * @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> carver) { final ResourceLocation immutableID = biomeID; - BuiltinRegistries.CONFIGURED_CARVER - .getResourceKey(carver) - .ifPresent(key -> BiomeModifications.addCarver(ctx -> ctx.getBiomeKey().location().equals(immutableID), step, key)); + carver.unwrapKey().ifPresent(key -> BiomeModifications.addCarver( ctx -> ctx.getBiomeKey().location().equals(immutableID), step, (ResourceKey>) key)); return this; } diff --git a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java index 51b00b9f..be55d0b1 100644 --- a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java @@ -302,14 +302,14 @@ public class BiomeAPI { /** * Get {@link BCLBiome} from {@link Biome} instance on server. Used to convert world biomes to BCLBiomes. - * @param biome - {@link Biome} from world. + * @param biome - {@link Holder} from world. * @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}. */ - public static BCLBiome getFromBiome(Biome biome) { + public static BCLBiome getFromBiome(Holder biome) { if (biomeRegistry == null) { return EMPTY_BIOME; } - return ID_MAP.getOrDefault(biomeRegistry.getKey(biome), EMPTY_BIOME); + return ID_MAP.getOrDefault(biome.unwrapKey().orElseThrow().location(), EMPTY_BIOME); } /** @@ -738,7 +738,7 @@ public class BiomeAPI { * @param minGroupCount minimum mobs in group. * @param maxGroupCount maximum mobs in group. */ - public static void addBiomeMobSpawn(Biome biome, BCLEntityWrapper entityType, int weight, int minGroupCount, int maxGroupCount) { + public static void addBiomeMobSpawn(Holder biome, BCLEntityWrapper entityType, int weight, int minGroupCount, int maxGroupCount) { if (entityType.canSpawn()){ addBiomeMobSpawn(biome, entityType.type(), weight, minGroupCount, maxGroupCount); } @@ -752,9 +752,9 @@ public class BiomeAPI { * @param minGroupCount minimum mobs in group. * @param maxGroupCount maximum mobs in group. */ - public static void addBiomeMobSpawn(Biome biome, EntityType entityType, int weight, int minGroupCount, int maxGroupCount) { + public static void addBiomeMobSpawn(Holder biome, EntityType entityType, int weight, int minGroupCount, int maxGroupCount) { final MobCategory category = entityType.getCategory(); - MobSpawnSettingsAccessor accessor = (MobSpawnSettingsAccessor) biome.getMobSettings(); + MobSpawnSettingsAccessor accessor = (MobSpawnSettingsAccessor) biome.value().getMobSettings(); Map> spawners = CollectionsUtil.getMutable(accessor.bcl_getSpawners()); List mobs = spawners.containsKey(category) ? CollectionsUtil.getMutable(spawners.get(category).unwrap()) : Lists.newArrayList(); mobs.add(new SpawnerData(entityType, weight, minGroupCount, maxGroupCount)); diff --git a/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java b/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java index 7b021944..0894ae89 100644 --- a/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java +++ b/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java @@ -38,6 +38,9 @@ public class BCLStructureFeature { public final ResourceKey structureSetKey; public BCLStructureFeature(ResourceLocation id, StructureFeature structure, GenerationStep.Decoration step, int spacing, int separation) { + this(id, structure, step, spacing, separation, false); + } + public BCLStructureFeature(ResourceLocation id, StructureFeature structure, GenerationStep.Decoration step, int spacing, int separation, boolean adaptNoise) { this.id = id; this.featureStep = step; //parts from vanilla for Structure generation @@ -57,7 +60,7 @@ public class BCLStructureFeature { this.biomeTag = TagAPI.makeBiomeTag(id.getNamespace(), "has_structure/"+id.getPath()); this.structure = StructureFeatureAccessor.callRegister(id.toString(), structure, step); - this.featureConfigured = StructureFeaturesAccessor.callRegister(structureKey, this.structure.configured(NoneFeatureConfiguration.NONE, biomeTag)); + this.featureConfigured = StructureFeaturesAccessor.callRegister(structureKey, this.structure.configured(NoneFeatureConfiguration.NONE, biomeTag, adaptNoise)); StructureSets.register(structureSetKey, featureConfigured, spreadConfig); //TODO: 1.18 check if structures are added correctly //FlatChunkGeneratorConfigAccessor.getStructureToFeatures().put(this.structure, this.featureConfigured); From 443042c6ef1e349df673c2dddcbc4e18a2924ff3 Mon Sep 17 00:00:00 2001 From: Frank Date: Thu, 17 Mar 2022 22:05:45 +0100 Subject: [PATCH 16/34] Fixes for Nether Features, Structures and Commands --- .../java/ru/bclib/world/structures/BCLStructureFeature.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java b/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java index 0894ae89..146b4585 100644 --- a/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java +++ b/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java @@ -36,6 +36,7 @@ public class BCLStructureFeature { public final TagKey biomeTag; public final ResourceKey> structureKey; public final ResourceKey structureSetKey; + public final RandomSpreadStructurePlacement spreadConfig; public BCLStructureFeature(ResourceLocation id, StructureFeature structure, GenerationStep.Decoration step, int spacing, int separation) { this(id, structure, step, spacing, separation, false); @@ -54,7 +55,7 @@ public class BCLStructureFeature { // StructureFeature.register("jungle_pyramid", new JunglePyramidFeature(NoneFeatureConfiguration.CODEC), GenerationStep.Decoration.SURFACE_STRUCTURES); // - final RandomSpreadStructurePlacement spreadConfig = new RandomSpreadStructurePlacement(spacing, separation, RandomSpreadType.LINEAR, RANDOM.nextInt(8192)); + this.spreadConfig = new RandomSpreadStructurePlacement(spacing, separation, RandomSpreadType.LINEAR, RANDOM.nextInt(8192)); this.structureKey = ResourceKey.create(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY, id); this.structureSetKey = ResourceKey.create(Registry.STRUCTURE_SET_REGISTRY, id); From 4f7d0939e311a328b8e85d9611045e6dd09d2395 Mon Sep 17 00:00:00 2001 From: Frank Date: Thu, 17 Mar 2022 23:52:46 +0100 Subject: [PATCH 17/34] Fixes BetterNether runtime crashes --- .../ru/bclib/api/biomes/BCLBiomeBuilder.java | 37 ++++++++++++++++--- .../java/ru/bclib/api/biomes/BiomeAPI.java | 5 ++- .../BiomeGenerationSettingsAccessor.java | 6 --- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java index 302de18f..5caab751 100644 --- a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java @@ -31,7 +31,9 @@ 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; @@ -54,6 +56,7 @@ public class BCLBiomeBuilder { private static final SurfaceRules.ConditionSource SURFACE_NOISE = SurfaceRules.noiseCondition(Noises.SOUL_SAND_LAYER, -0.012); private List> structureTags = new ArrayList<>(8); + private List>>> carvers = new ArrayList<>(1); private BiomeGenerationSettings.Builder generationSettings; private BiomeSpecialEffects.Builder effectsBuilder; private MobSpawnSettings.Builder spawnSettings; @@ -92,6 +95,7 @@ public class BCLBiomeBuilder { INSTANCE.height = 0.1F; INSTANCE.vertical = false; INSTANCE.edge = null; + INSTANCE.carvers.clear(); return INSTANCE; } @@ -563,7 +567,11 @@ public class BCLBiomeBuilder { */ public BCLBiomeBuilder carver(GenerationStep.Carving step, Holder> carver) { final ResourceLocation immutableID = biomeID; - carver.unwrapKey().ifPresent(key -> BiomeModifications.addCarver( ctx -> ctx.getBiomeKey().location().equals(immutableID), step, (ResourceKey>) key)); + var oKey = carver.unwrapKey(); + if (oKey.isPresent()) { + BiomeModifications.addCarver(ctx -> ctx.getBiomeKey().location().equals(immutableID), step, (ResourceKey>) oKey.get()); + } + //carvers.add(new Pair<>(step, carver)); return this; } @@ -619,8 +627,8 @@ public class BCLBiomeBuilder { this.height = height; return this; } - - + + /** * Make this a vertical Biome @@ -639,7 +647,7 @@ public class BCLBiomeBuilder { public BCLBiome build() { return build((BiomeSupplier)BCLBiome::new); } - + /** * Finalize biome creation. * @param biomeConstructor {@link BiFunction} biome constructor. @@ -650,6 +658,21 @@ public class BCLBiomeBuilder { 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>> 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. @@ -668,7 +691,7 @@ public class BCLBiomeBuilder { Map>> defferedFeatures = Maps.newHashMap(); BiomeGenerationSettingsAccessor acc = BiomeGenerationSettingsAccessor.class.cast(getGeneration().build()); if (acc != null) { - builder.generationSettings(new BiomeGenerationSettings.Builder().build()); + builder.generationSettings(fixGenerationSettings(new BiomeGenerationSettings.Builder().build())); List> decorations = acc.bclib_getFeatures(); for (Decoration d : Decoration.values()) { int i = d.ordinal(); @@ -681,7 +704,7 @@ public class BCLBiomeBuilder { } } else { - builder.generationSettings(getGeneration().build()); + builder.generationSettings(fixGenerationSettings(getGeneration().build())); } BCLBiomeSettings settings = BCLBiomeSettings.createBCL() @@ -698,6 +721,8 @@ public class BCLBiomeBuilder { res.attachStructures(structureTags); res.setSurface(surfaceRule); res.setFeatures(defferedFeatures); + + //carvers.forEach(cfg -> BiomeAPI.addBiomeCarver(biome, cfg.second, cfg.first)); return res; } diff --git a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java index be55d0b1..878e414a 100644 --- a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java @@ -672,6 +672,7 @@ public class BiomeAPI { accessor.bclib_setFeatures(allFeatures); accessor.bclib_setFeatureSet(featureSet); + accessor.bclib_setFlowerFeatures(flowerFeatures); } /** @@ -694,7 +695,7 @@ public class BiomeAPI { * @param carver {@link ConfiguredWorldCarver} to add. * @param stage {@link Carving} stage. */ - public static void addBiomeCarver(Biome biome, Holder> carver, Carving stage) { + public static void addBiomeCarver(Biome biome, Holder> carver, Carving stage) { BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings(); Map>> carverMap = CollectionsUtil.getMutable(accessor.bclib_getCarvers()); HolderSet> carvers = carverMap.get(stage); @@ -705,7 +706,7 @@ public class BiomeAPI { } else { carverList = carvers.stream().toList(); } - carverList.add(carver); + carverList.add((Holder>)carver); carverMap.put(stage, HolderSet.direct(carverList)); accessor.bclib_setCarvers(carverMap); } diff --git a/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java b/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java index ff7cda65..91f929b1 100644 --- a/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java +++ b/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java @@ -25,15 +25,9 @@ public interface BiomeGenerationSettingsAccessor { @Mutable void bclib_setFeatures(List> value); - @Accessor("featureSet") - Supplier> bclib_getFeatureSet(); - @Accessor("featureSet") void bclib_setFeatureSet(Supplier> featureSet); - @Accessor("flowerFeatures") - Supplier>> bclib_getFlowerFeatures(); - @Accessor("flowerFeatures") void bclib_setFlowerFeatures(Supplier>> flowerFeatures); From 7e981ca1d94cdf2b190244c7c5bfc04c8a2adb9f Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 18 Mar 2022 01:40:17 +0100 Subject: [PATCH 18/34] Fixes for SurfaceRules and Feature code cleanup --- .../ru/bclib/api/biomes/BCLBiomeBuilder.java | 20 +------------- .../java/ru/bclib/api/biomes/BiomeAPI.java | 27 +++---------------- .../common/NoiseGeneratorSettingsMixin.java | 4 +-- .../java/ru/bclib/world/biomes/BCLBiome.java | 20 +------------- 4 files changed, 8 insertions(+), 63 deletions(-) diff --git a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java index 5caab751..87b18ddc 100644 --- a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java @@ -688,24 +688,7 @@ public class BCLBiomeBuilder { builder.mobSpawnSettings(getSpawns().build()); builder.specialEffects(getEffects().build()); - Map>> defferedFeatures = Maps.newHashMap(); - BiomeGenerationSettingsAccessor acc = BiomeGenerationSettingsAccessor.class.cast(getGeneration().build()); - if (acc != null) { - builder.generationSettings(fixGenerationSettings(new BiomeGenerationSettings.Builder().build())); - List> decorations = acc.bclib_getFeatures(); - for (Decoration d : Decoration.values()) { - int i = d.ordinal(); - if (i>=0 && i features = decorations.get(i); - defferedFeatures.put(d, features.stream().collect(Collectors.toList())); - } else { - defferedFeatures.put(d, Lists.newArrayList()); - } - - } - } else { - builder.generationSettings(fixGenerationSettings(getGeneration().build())); - } + builder.generationSettings(fixGenerationSettings(getGeneration().build())); BCLBiomeSettings settings = BCLBiomeSettings.createBCL() .setTerrainHeight(height) @@ -720,7 +703,6 @@ public class BCLBiomeBuilder { 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; diff --git a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java index 878e414a..9303d4a5 100644 --- a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java @@ -504,9 +504,9 @@ public class BiomeAPI { final BiomeSource source = chunkGenerator.getBiomeSource(); final Set> biomes = source.possibleBiomes(); - //TODO: 1.18.2 Is this stilla valid way to determine the correct noiseGeneratorSettings for the level? - - final Registry structureSetRegistry; + if (chunkGenerator instanceof NoiseGeneratorSettingsProvider gen) + noiseGeneratorSettings = gen.bclib_getNoiseGeneratorSettings(); + /*final Registry structureSetRegistry; if (chunkGenerator instanceof ChunkGeneratorAccessor acc) { structureSetRegistry = acc.bclib_getStructureSetsRegistry(); } else { @@ -524,7 +524,7 @@ public class BiomeAPI { .filter(gen-> structureSetRegistry!=null && (gen instanceof NoiseGeneratorSettingsProvider) && (gen instanceof ChunkGeneratorAccessor) && ((ChunkGeneratorAccessor)gen).bclib_getStructureSetsRegistry()==structureSetRegistry) .map(gen->((NoiseGeneratorSettingsProvider)gen).bclib_getNoiseGeneratorSettings()) .findFirst() - .orElse(null); + .orElse(null);*/ // Datapacks (like Amplified Nether)will change the GeneratorSettings upon load, so we will @@ -568,11 +568,6 @@ public class BiomeAPI { }); } - final BCLBiome bclBiome = BiomeAPI.getBiome(biome); - if (bclBiome != null) { - addStepFeaturesToBiome(biome, bclBiome.getFeatures()); - } - sortBiomeFeatures(biome); } @@ -675,20 +670,6 @@ public class BiomeAPI { accessor.bclib_setFlowerFeatures(flowerFeatures); } - /** - * For internal use only! - * - * Adds new features to existing biome. Called from {@link #applyModificationsAndUpdateFeatures(List, Holder)}} when the Biome is - * present in any {@link BiomeSource} - * @param biome {@link Biome} to add features in. - * @param featureMap Map of {@link ConfiguredFeature} to add. - */ - private static void addStepFeaturesToBiome(Holder biome, Map>> featureMap) { - for (Decoration step: featureMap.keySet()) { - addBiomeFeature(biome, step, featureMap.get(step)); - } - } - /** * Adds new carver into existing biome. * @param biome {@link Biome} to add carver in. diff --git a/src/main/java/ru/bclib/mixin/common/NoiseGeneratorSettingsMixin.java b/src/main/java/ru/bclib/mixin/common/NoiseGeneratorSettingsMixin.java index da9a6a4a..ad9d921d 100644 --- a/src/main/java/ru/bclib/mixin/common/NoiseGeneratorSettingsMixin.java +++ b/src/main/java/ru/bclib/mixin/common/NoiseGeneratorSettingsMixin.java @@ -26,14 +26,14 @@ public class NoiseGeneratorSettingsMixin implements SurfaceRuleProvider { private SurfaceRules.RuleSource bclib_originalSurfaceRule; private Set bclib_biomeSources = new HashSet<>(); - private void bclib_updateCutomRules(){ + private void bclib_updateCustomRules(){ bclib_setCustomRules(BiomeAPI.getRuleSources(bclib_biomeSources)); } @Override public void bclib_addBiomeSource(BiomeSource source) { bclib_biomeSources.add(source); - bclib_updateCutomRules(); + bclib_updateCustomRules(); } @Override diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiome.java b/src/main/java/ru/bclib/world/biomes/BCLBiome.java index 1100c561..840c6888 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiome.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiome.java @@ -306,25 +306,7 @@ public class BCLBiome extends BCLBiomeSettings { } }; } - - private Map>> features = Maps.newHashMap(); - - /** - * Sets the biome features. - * @param features the feature list. - */ - public void setFeatures(Map>> features) { - this.features = features; - } - - /** - * Returns the built-in set of Features for this biome (as they were set with {@link #setFeatures(Map)}) - * @return List of all features - */ - public Map>> getFeatures(){ - return features; - } - + /** * Returns the group used in the config Files for this biome * From 5f17127ba519da83245c6867ff065b240f40264e Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 18 Mar 2022 14:44:27 +0100 Subject: [PATCH 19/34] New Interfaces to handle MineableTags for Blocks --- src/main/java/ru/bclib/api/PostInitAPI.java | 20 +++++++++++++++++++ .../java/ru/bclib/blocks/BaseLeavesBlock.java | 6 +++--- .../java/ru/bclib/blocks/BaseOreBlock.java | 5 +++++ .../java/ru/bclib/blocks/BasePlantBlock.java | 10 +++------- .../ru/bclib/blocks/SimpleLeavesBlock.java | 6 +++--- .../ru/bclib/blocks/UnderwaterPlantBlock.java | 11 ++++------ .../ru/bclib/blocks/UpDownPlantBlock.java | 10 +++------- .../interfaces/tools/AddMineableAxe.java | 4 ++++ .../interfaces/tools/AddMineableHoe.java | 4 ++++ .../interfaces/tools/AddMineablePickaxe.java | 4 ++++ .../interfaces/tools/AddMineableShears.java | 4 ++++ .../interfaces/tools/AddMineableShovel.java | 4 ++++ .../interfaces/tools/AddMineableSword.java | 4 ++++ 13 files changed, 65 insertions(+), 27 deletions(-) create mode 100644 src/main/java/ru/bclib/interfaces/tools/AddMineableAxe.java create mode 100644 src/main/java/ru/bclib/interfaces/tools/AddMineableHoe.java create mode 100644 src/main/java/ru/bclib/interfaces/tools/AddMineablePickaxe.java create mode 100644 src/main/java/ru/bclib/interfaces/tools/AddMineableShears.java create mode 100644 src/main/java/ru/bclib/interfaces/tools/AddMineableShovel.java create mode 100644 src/main/java/ru/bclib/interfaces/tools/AddMineableSword.java diff --git a/src/main/java/ru/bclib/api/PostInitAPI.java b/src/main/java/ru/bclib/api/PostInitAPI.java index c0066245..85080844 100644 --- a/src/main/java/ru/bclib/api/PostInitAPI.java +++ b/src/main/java/ru/bclib/api/PostInitAPI.java @@ -10,6 +10,7 @@ import net.minecraft.world.item.Item; 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; @@ -23,6 +24,7 @@ import ru.bclib.config.Configs; 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; @@ -111,6 +113,24 @@ public class PostInitAPI { else if (block instanceof BaseFurnaceBlock) { BaseBlockEntities.FURNACE.registerBlock(block); } + 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 TagProvider) { TagProvider.class.cast(block).addTags(blockTags, itemTags); blockTags.forEach(tag -> TagAPI.addBlockTag(tag, block)); diff --git a/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java b/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java index 9955fbad..8daaee2f 100644 --- a/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java @@ -24,6 +24,8 @@ import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.interfaces.BlockModelProvider; import ru.bclib.interfaces.RenderLayerProvider; import ru.bclib.interfaces.TagProvider; +import ru.bclib.interfaces.tools.AddMineableHoe; +import ru.bclib.interfaces.tools.AddMineableShears; import ru.bclib.items.tool.BaseShearsItem; import ru.bclib.util.MHelper; @@ -31,7 +33,7 @@ import java.util.Collections; import java.util.List; import java.util.function.Consumer; -public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider, RenderLayerProvider, TagProvider { +public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider, RenderLayerProvider, TagProvider, AddMineableShears, AddMineableHoe { protected final Block sapling; private static FabricBlockSettings makeLeaves(MaterialColor color) { @@ -100,8 +102,6 @@ public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider, @Override public void addTags(List> blockTags, List> itemTags) { - blockTags.add(NamedMineableTags.SHEARS); - blockTags.add(NamedMineableTags.HOE); blockTags.add(NamedBlockTags.LEAVES); itemTags.add(NamedItemTags.LEAVES); } diff --git a/src/main/java/ru/bclib/blocks/BaseOreBlock.java b/src/main/java/ru/bclib/blocks/BaseOreBlock.java index 8b0573bf..5b3609d7 100644 --- a/src/main/java/ru/bclib/blocks/BaseOreBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseOreBlock.java @@ -10,6 +10,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.item.enchantment.Enchantments; import net.minecraft.world.level.ItemLike; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.OreBlock; import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.state.BlockState; @@ -17,7 +18,11 @@ import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.parameters.LootContextParams; +import ru.bclib.api.tag.NamedCommonBlockTags; +import ru.bclib.api.tag.NamedMineableTags; +import ru.bclib.api.tag.TagAPI; import ru.bclib.interfaces.BlockModelProvider; +import ru.bclib.interfaces.TagProvider; import ru.bclib.util.LootUtil; import ru.bclib.util.MHelper; diff --git a/src/main/java/ru/bclib/blocks/BasePlantBlock.java b/src/main/java/ru/bclib/blocks/BasePlantBlock.java index a036fdc1..86c8a76d 100644 --- a/src/main/java/ru/bclib/blocks/BasePlantBlock.java +++ b/src/main/java/ru/bclib/blocks/BasePlantBlock.java @@ -39,13 +39,15 @@ import ru.bclib.client.models.PatternsHelper; import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.interfaces.RenderLayerProvider; import ru.bclib.interfaces.TagProvider; +import ru.bclib.interfaces.tools.AddMineableHoe; +import ru.bclib.interfaces.tools.AddMineableShears; import ru.bclib.items.tool.BaseShearsItem; import java.util.List; import java.util.Optional; import java.util.Random; -public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock, TagProvider { +public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock, AddMineableShears, AddMineableHoe { private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12); public BasePlantBlock() { @@ -170,10 +172,4 @@ public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderL Optional pattern = PatternsHelper.createJson(BasePatterns.BLOCK_CROSS, resourceLocation); return ModelsHelper.fromPattern(pattern); } - - @Override - public void addTags(List> blockTags, List> itemTags) { - blockTags.add(NamedMineableTags.SHEARS); - blockTags.add(NamedMineableTags.HOE); - } } diff --git a/src/main/java/ru/bclib/blocks/SimpleLeavesBlock.java b/src/main/java/ru/bclib/blocks/SimpleLeavesBlock.java index 1862427f..7aca9c59 100644 --- a/src/main/java/ru/bclib/blocks/SimpleLeavesBlock.java +++ b/src/main/java/ru/bclib/blocks/SimpleLeavesBlock.java @@ -14,10 +14,12 @@ import ru.bclib.api.tag.TagAPI.TagLocation; import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.interfaces.RenderLayerProvider; import ru.bclib.interfaces.TagProvider; +import ru.bclib.interfaces.tools.AddMineableHoe; +import ru.bclib.interfaces.tools.AddMineableShears; import java.util.List; -public class SimpleLeavesBlock extends BaseBlockNotFull implements RenderLayerProvider, TagProvider { +public class SimpleLeavesBlock extends BaseBlockNotFull implements RenderLayerProvider, TagProvider, AddMineableShears, AddMineableHoe { public SimpleLeavesBlock(MaterialColor color) { this( FabricBlockSettings @@ -58,8 +60,6 @@ public class SimpleLeavesBlock extends BaseBlockNotFull implements RenderLayerPr @Override public void addTags(List> blockTags, List> itemTags) { - blockTags.add(NamedMineableTags.SHEARS); - blockTags.add(NamedMineableTags.HOE); blockTags.add(NamedBlockTags.LEAVES); itemTags.add(NamedItemTags.LEAVES); } diff --git a/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java b/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java index 746c6470..f7a6cedc 100644 --- a/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java +++ b/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java @@ -35,12 +35,14 @@ import ru.bclib.api.tag.TagAPI.TagLocation; import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.interfaces.RenderLayerProvider; import ru.bclib.interfaces.TagProvider; +import ru.bclib.interfaces.tools.AddMineableHoe; +import ru.bclib.interfaces.tools.AddMineableShears; import ru.bclib.items.tool.BaseShearsItem; import java.util.List; import java.util.Random; -public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock, LiquidBlockContainer, TagProvider { +public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock, LiquidBlockContainer, AddMineableShears, AddMineableHoe { private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12); public UnderwaterPlantBlock() { @@ -161,10 +163,5 @@ public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements R public FluidState getFluidState(BlockState state) { return Fluids.WATER.getSource(false); } - - @Override - public void addTags(List> blockTags, List> itemTags) { - blockTags.add(NamedMineableTags.SHEARS); - blockTags.add(NamedMineableTags.HOE); - } + } diff --git a/src/main/java/ru/bclib/blocks/UpDownPlantBlock.java b/src/main/java/ru/bclib/blocks/UpDownPlantBlock.java index cb60d0a6..2b31868e 100644 --- a/src/main/java/ru/bclib/blocks/UpDownPlantBlock.java +++ b/src/main/java/ru/bclib/blocks/UpDownPlantBlock.java @@ -29,11 +29,13 @@ import ru.bclib.api.tag.TagAPI.TagLocation; import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.interfaces.RenderLayerProvider; import ru.bclib.interfaces.TagProvider; +import ru.bclib.interfaces.tools.AddMineableHoe; +import ru.bclib.interfaces.tools.AddMineableShears; import ru.bclib.items.tool.BaseShearsItem; import java.util.List; -public abstract class UpDownPlantBlock extends BaseBlockNotFull implements RenderLayerProvider, TagProvider { +public abstract class UpDownPlantBlock extends BaseBlockNotFull implements RenderLayerProvider, AddMineableShears, AddMineableHoe { private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 16, 12); public UpDownPlantBlock() { @@ -106,10 +108,4 @@ public abstract class UpDownPlantBlock extends BaseBlockNotFull implements Rende super.playerDestroy(world, player, pos, state, blockEntity, stack); world.neighborChanged(pos, Blocks.AIR, pos.below()); } - - @Override - public void addTags(List> blockTags, List> itemTags) { - blockTags.add(NamedMineableTags.SHEARS); - blockTags.add(NamedMineableTags.HOE); - } } diff --git a/src/main/java/ru/bclib/interfaces/tools/AddMineableAxe.java b/src/main/java/ru/bclib/interfaces/tools/AddMineableAxe.java new file mode 100644 index 00000000..e82ee451 --- /dev/null +++ b/src/main/java/ru/bclib/interfaces/tools/AddMineableAxe.java @@ -0,0 +1,4 @@ +package ru.bclib.interfaces.tools; + +public interface AddMineableAxe { +} diff --git a/src/main/java/ru/bclib/interfaces/tools/AddMineableHoe.java b/src/main/java/ru/bclib/interfaces/tools/AddMineableHoe.java new file mode 100644 index 00000000..3bd60291 --- /dev/null +++ b/src/main/java/ru/bclib/interfaces/tools/AddMineableHoe.java @@ -0,0 +1,4 @@ +package ru.bclib.interfaces.tools; + +public interface AddMineableHoe { +} diff --git a/src/main/java/ru/bclib/interfaces/tools/AddMineablePickaxe.java b/src/main/java/ru/bclib/interfaces/tools/AddMineablePickaxe.java new file mode 100644 index 00000000..92fda1ea --- /dev/null +++ b/src/main/java/ru/bclib/interfaces/tools/AddMineablePickaxe.java @@ -0,0 +1,4 @@ +package ru.bclib.interfaces.tools; + +public interface AddMineablePickaxe { +} diff --git a/src/main/java/ru/bclib/interfaces/tools/AddMineableShears.java b/src/main/java/ru/bclib/interfaces/tools/AddMineableShears.java new file mode 100644 index 00000000..5a42b295 --- /dev/null +++ b/src/main/java/ru/bclib/interfaces/tools/AddMineableShears.java @@ -0,0 +1,4 @@ +package ru.bclib.interfaces.tools; + +public interface AddMineableShears { +} diff --git a/src/main/java/ru/bclib/interfaces/tools/AddMineableShovel.java b/src/main/java/ru/bclib/interfaces/tools/AddMineableShovel.java new file mode 100644 index 00000000..cdd601f7 --- /dev/null +++ b/src/main/java/ru/bclib/interfaces/tools/AddMineableShovel.java @@ -0,0 +1,4 @@ +package ru.bclib.interfaces.tools; + +public interface AddMineableShovel { +} diff --git a/src/main/java/ru/bclib/interfaces/tools/AddMineableSword.java b/src/main/java/ru/bclib/interfaces/tools/AddMineableSword.java new file mode 100644 index 00000000..f68e4500 --- /dev/null +++ b/src/main/java/ru/bclib/interfaces/tools/AddMineableSword.java @@ -0,0 +1,4 @@ +package ru.bclib.interfaces.tools; + +public interface AddMineableSword { +} From a2acd5065830787f38606eac86d57483b5b5125d Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 18 Mar 2022 14:44:39 +0100 Subject: [PATCH 20/34] Some cleanup --- .../bclib/api/dataexchange/DataHandler.java | 20 ++----------------- .../handler/autosync/SendFiles.java | 1 - src/main/java/ru/bclib/api/tag/TagAPI.java | 1 - 3 files changed, 2 insertions(+), 20 deletions(-) diff --git a/src/main/java/ru/bclib/api/dataexchange/DataHandler.java b/src/main/java/ru/bclib/api/dataexchange/DataHandler.java index 9f47278c..30492bed 100644 --- a/src/main/java/ru/bclib/api/dataexchange/DataHandler.java +++ b/src/main/java/ru/bclib/api/dataexchange/DataHandler.java @@ -147,24 +147,8 @@ public abstract class DataHandler extends BaseDataHandler { @Environment(EnvType.CLIENT) abstract protected void serializeDataOnClient(FriendlyByteBuf buf); - @Deprecated(forRemoval = true) - protected void deserializeIncomingDataOnServer(FriendlyByteBuf buf, PacketSender responseSender){ } - - //TODO: should be abstract once deserializeIncomingDataOnServer(FriendlyByteBuf buf, PacketSender responseSender) was removed - - protected void deserializeIncomingDataOnServer(FriendlyByteBuf buf, Player player, PacketSender responseSender) { - deserializeIncomingDataOnServer(buf, responseSender); - } - - @Deprecated(forRemoval = true) - protected void runOnServerGameThread(MinecraftServer server){ } - - - //TODO: should be abstract once runOnServerGameThread(MinecraftServer server) was removed - protected void runOnServerGameThread(MinecraftServer server, Player player){ - runOnServerGameThread(server); - } - + protected abstract void deserializeIncomingDataOnServer(FriendlyByteBuf buf, Player player, PacketSender responseSender); + protected abstract void runOnServerGameThread(MinecraftServer server, Player player); @Environment(EnvType.CLIENT) @Override diff --git a/src/main/java/ru/bclib/api/dataexchange/handler/autosync/SendFiles.java b/src/main/java/ru/bclib/api/dataexchange/handler/autosync/SendFiles.java index ef52b214..cd1e21de 100644 --- a/src/main/java/ru/bclib/api/dataexchange/handler/autosync/SendFiles.java +++ b/src/main/java/ru/bclib/api/dataexchange/handler/autosync/SendFiles.java @@ -127,7 +127,6 @@ public class SendFiles extends DataHandler.FromServer { if ( Configs.CLIENT_CONFIG.isAcceptingConfigs() || Configs.CLIENT_CONFIG.isAcceptingFiles() || Configs.CLIENT_CONFIG.isAcceptingMods()) { BCLib.LOGGER.info("Writing Files:"); - //TODO: Reject files that were not in the last RequestFiles. for (Pair entry : receivedFiles) { final AutoFileSyncEntry e = entry.first; final byte[] data = entry.second; diff --git a/src/main/java/ru/bclib/api/tag/TagAPI.java b/src/main/java/ru/bclib/api/tag/TagAPI.java index 557cac7e..98d08a9f 100644 --- a/src/main/java/ru/bclib/api/tag/TagAPI.java +++ b/src/main/java/ru/bclib/api/tag/TagAPI.java @@ -35,7 +35,6 @@ public class TagAPI { * @return {@link TagKey}. */ public static TagKey makeTag(Registry registry, TagLocation id) { - //TODO: 1.18.2 check if registry.key() gets the correct result return registry .getTagNames() .filter(tagKey -> tagKey.location().equals(id)) From 61f9854cd5d2bebff9182cdfcd7211260df9c567 Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 18 Mar 2022 15:34:18 +0100 Subject: [PATCH 21/34] Some mining/drop related fixes --- .../java/ru/bclib/blocks/BaseGlassBlock.java | 63 +++++++++++++++++++ .../java/ru/bclib/blocks/BaseOreBlock.java | 48 +++++++------- .../java/ru/bclib/items/tool/BaseAxeItem.java | 1 - 3 files changed, 88 insertions(+), 24 deletions(-) create mode 100644 src/main/java/ru/bclib/blocks/BaseGlassBlock.java diff --git a/src/main/java/ru/bclib/blocks/BaseGlassBlock.java b/src/main/java/ru/bclib/blocks/BaseGlassBlock.java new file mode 100644 index 00000000..a7766e36 --- /dev/null +++ b/src/main/java/ru/bclib/blocks/BaseGlassBlock.java @@ -0,0 +1,63 @@ +package ru.bclib.blocks; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.item.enchantment.Enchantments; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.storage.loot.parameters.LootContextParams; +import ru.bclib.client.render.BCLRenderLayer; +import ru.bclib.interfaces.RenderLayerProvider; +import ru.bclib.interfaces.tools.AddMineablePickaxe; + +import java.util.Collections; +import java.util.List; + +public class BaseGlassBlock extends BaseBlockNotFull implements AddMineablePickaxe, RenderLayerProvider { + public BaseGlassBlock(Block block) { + this(block, 0.3f); + } + public BaseGlassBlock(Block block, float resistance) { + super(FabricBlockSettings.copyOf(block) + .resistance(resistance) + .nonOpaque() + .isSuffocating((arg1, arg2, arg3) -> false) + .isViewBlocking((arg1, arg2, arg3) -> false)); + } + + @Environment(EnvType.CLIENT) + public float getShadeBrightness(BlockState state, BlockGetter view, BlockPos pos) { + return 1.0F; + } + + @Override + public boolean propagatesSkylightDown(BlockState state, BlockGetter view, BlockPos pos) { + return true; + } + + @Environment(EnvType.CLIENT) + public boolean skipRendering(BlockState state, BlockState neighbor, Direction facing) { + return neighbor.getBlock() == this ? true : super.skipRendering(state, neighbor, facing); + } + + @Override + public List getDrops(BlockState state, LootContext.Builder builder) { + ItemStack tool = builder.getParameter(LootContextParams.TOOL); + if (tool != null && EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) { + return Collections.singletonList(new ItemStack(this)); + } + return Collections.emptyList(); + } + + @Override + public BCLRenderLayer getRenderLayer() { + return BCLRenderLayer.TRANSLUCENT; + } +} diff --git a/src/main/java/ru/bclib/blocks/BaseOreBlock.java b/src/main/java/ru/bclib/blocks/BaseOreBlock.java index 5b3609d7..ceb8fe03 100644 --- a/src/main/java/ru/bclib/blocks/BaseOreBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseOreBlock.java @@ -7,6 +7,7 @@ import net.minecraft.util.Mth; import net.minecraft.util.valueproviders.UniformInt; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.TieredItem; import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.item.enchantment.Enchantments; import net.minecraft.world.level.ItemLike; @@ -34,6 +35,7 @@ public class BaseOreBlock extends OreBlock implements BlockModelProvider { private final Supplier dropItem; private final int minCount; private final int maxCount; + private final int miningLevel; public BaseOreBlock(Supplier drop, int minCount, int maxCount, int experience) { this(drop, minCount, maxCount, experience, 0); @@ -56,16 +58,11 @@ public class BaseOreBlock extends OreBlock implements BlockModelProvider { } public BaseOreBlock(Properties properties, Supplier drop, int minCount, int maxCount, int experience, int miningLevel) { - super(makeProps(properties, miningLevel), UniformInt.of(experience>0?1:0, experience)); + super(properties, UniformInt.of(experience>0?1:0, experience)); this.dropItem = drop; this.minCount = minCount; this.maxCount = maxCount; - } - - private static Properties makeProps(Properties properties, int level){ - //TODO: 1.18.2 make sure this works with the new tag system - //FabricBlockInternals.computeExtraData(properties).addMiningLevel(FabricToolTags.PICKAXES, level); - return properties; + this.miningLevel = miningLevel; } @Override @@ -74,30 +71,35 @@ public class BaseOreBlock extends OreBlock implements BlockModelProvider { return LootUtil .getDrops(this, state, builder) .orElseGet( - ()->BaseOreBlock.getDroppedItems(this, dropItem.get(), maxCount, minCount, state, builder) + ()->BaseOreBlock.getDroppedItems(this, dropItem.get(), maxCount, minCount, miningLevel, state, builder) ); } - public static List getDroppedItems(ItemLike block, Item dropItem, int maxCount, int minCount, BlockState state, LootContext.Builder builder) { + public static List getDroppedItems(ItemLike block, Item dropItem, int maxCount, int minCount, int miningLevel, BlockState state, LootContext.Builder builder) { ItemStack tool = builder.getParameter(LootContextParams.TOOL); if (tool != null && tool.isCorrectToolForDrops(state)) { - if (EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) { - return Collections.singletonList(new ItemStack(block)); + boolean canMine = miningLevel==0; + if (tool.getItem() instanceof TieredItem tired) { + canMine = tired.getTier().getLevel()>=miningLevel; } - int count; - int enchantment = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.BLOCK_FORTUNE, tool); - if (enchantment > 0) { - int min = Mth.clamp(minCount + enchantment, minCount, maxCount); - int max = maxCount + (enchantment / Enchantments.BLOCK_FORTUNE.getMaxLevel()); - if (min == max) { - return Collections.singletonList(new ItemStack(dropItem, max)); + if (canMine) { + if (EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) { + return Collections.singletonList(new ItemStack(block)); } - count = MHelper.randRange(min, max, MHelper.RANDOM); + int count; + int enchantment = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.BLOCK_FORTUNE, tool); + if (enchantment > 0) { + int min = Mth.clamp(minCount + enchantment, minCount, maxCount); + int max = maxCount + (enchantment / Enchantments.BLOCK_FORTUNE.getMaxLevel()); + if (min == max) { + return Collections.singletonList(new ItemStack(dropItem, max)); + } + count = MHelper.randRange(min, max, MHelper.RANDOM); + } else { + count = MHelper.randRange(minCount, maxCount, MHelper.RANDOM); + } + return Collections.singletonList(new ItemStack(dropItem, count)); } - else { - count = MHelper.randRange(minCount, maxCount, MHelper.RANDOM); - } - return Collections.singletonList(new ItemStack(dropItem, count)); } return Collections.emptyList(); } diff --git a/src/main/java/ru/bclib/items/tool/BaseAxeItem.java b/src/main/java/ru/bclib/items/tool/BaseAxeItem.java index 32c6d0b3..bcac32bd 100644 --- a/src/main/java/ru/bclib/items/tool/BaseAxeItem.java +++ b/src/main/java/ru/bclib/items/tool/BaseAxeItem.java @@ -9,7 +9,6 @@ import net.minecraft.world.item.Tier; import ru.bclib.client.models.ModelsHelper; import ru.bclib.interfaces.ItemModelProvider; -//TODO: 1.18.2 See if mining speed is still ok. public class BaseAxeItem extends AxeItem implements ItemModelProvider { public BaseAxeItem(Tier material, float attackDamage, float attackSpeed, Properties settings) { super(material, attackDamage, attackSpeed, settings); From a9c9a7359b33bd83a6a92c0ef814f62c081acb72 Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 18 Mar 2022 16:03:45 +0100 Subject: [PATCH 22/34] Confirmed some fixes related to BN --- src/main/java/ru/bclib/api/PostInitAPI.java | 36 ++++++++++--------- .../java/ru/bclib/blocks/BaseCropBlock.java | 2 -- .../ru/bclib/blocks/BaseDoublePlantBlock.java | 4 --- .../java/ru/bclib/blocks/BasePlantBlock.java | 6 +--- .../bclib/blocks/BasePlantWithAgeBlock.java | 2 -- .../bclib/blocks/BaseStripableLogBlock.java | 2 -- .../blocks/BaseUnderwaterWallPlantBlock.java | 4 --- .../java/ru/bclib/blocks/BaseVineBlock.java | 3 -- .../ru/bclib/blocks/BaseWallPlantBlock.java | 4 --- .../ru/bclib/blocks/FeatureSaplingBlock.java | 4 --- .../ru/bclib/blocks/StripableBarkBlock.java | 2 -- .../ru/bclib/blocks/UnderwaterPlantBlock.java | 7 +--- .../blocks/UnderwaterPlantWithAgeBlock.java | 2 -- .../ru/bclib/blocks/UpDownPlantBlock.java | 3 -- .../ru/bclib/blocks/WallMushroomBlock.java | 2 -- .../interfaces/tools/PreventMineableAdd.java | 4 +++ .../ru/bclib/items/tool/BasePickaxeItem.java | 1 - .../ru/bclib/items/tool/BaseShearsItem.java | 1 - .../ru/bclib/items/tool/BaseShovelItem.java | 1 - .../shears/ItemPredicateBuilderMixin.java | 1 - .../java/ru/bclib/world/biomes/BCLBiome.java | 1 - .../ru/bclib/world/features/BCLFeature.java | 1 - .../world/structures/BCLStructureFeature.java | 2 -- 23 files changed, 25 insertions(+), 70 deletions(-) create mode 100644 src/main/java/ru/bclib/interfaces/tools/PreventMineableAdd.java diff --git a/src/main/java/ru/bclib/api/PostInitAPI.java b/src/main/java/ru/bclib/api/PostInitAPI.java index 85080844..a2db39d4 100644 --- a/src/main/java/ru/bclib/api/PostInitAPI.java +++ b/src/main/java/ru/bclib/api/PostInitAPI.java @@ -113,23 +113,25 @@ public class PostInitAPI { else if (block instanceof BaseFurnaceBlock) { BaseBlockEntities.FURNACE.registerBlock(block); } - 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 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 TagProvider) { TagProvider.class.cast(block).addTags(blockTags, itemTags); diff --git a/src/main/java/ru/bclib/blocks/BaseCropBlock.java b/src/main/java/ru/bclib/blocks/BaseCropBlock.java index 007db2b3..cea2121a 100644 --- a/src/main/java/ru/bclib/blocks/BaseCropBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseCropBlock.java @@ -39,8 +39,6 @@ public class BaseCropBlock extends BasePlantBlock { public BaseCropBlock(Item drop, Block... terrain) { this( FabricBlockSettings.of(Material.PLANT) - //TODO: 1.18.2 Check if this is still ok - //.breakByHand(true) .sound(SoundType.GRASS) .randomTicks() .noCollission(), diff --git a/src/main/java/ru/bclib/blocks/BaseDoublePlantBlock.java b/src/main/java/ru/bclib/blocks/BaseDoublePlantBlock.java index 49b2e34b..0d96dc59 100644 --- a/src/main/java/ru/bclib/blocks/BaseDoublePlantBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseDoublePlantBlock.java @@ -45,8 +45,6 @@ public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements R public BaseDoublePlantBlock() { this( FabricBlockSettings.of(Material.PLANT) - //TODO: 1.18.2 make sure this works with the new tag system - //.breakByHand(true) .sound(SoundType.GRASS) .noCollission() ); @@ -55,8 +53,6 @@ public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements R public BaseDoublePlantBlock(int light) { this( FabricBlockSettings.of(Material.PLANT) - //TODO: 1.18.2 Check if this is still ok - //.breakByHand(true) .sound(SoundType.GRASS) .lightLevel((state) -> state.getValue(TOP) ? light : 0) .noCollission() diff --git a/src/main/java/ru/bclib/blocks/BasePlantBlock.java b/src/main/java/ru/bclib/blocks/BasePlantBlock.java index 86c8a76d..ca88ba50 100644 --- a/src/main/java/ru/bclib/blocks/BasePlantBlock.java +++ b/src/main/java/ru/bclib/blocks/BasePlantBlock.java @@ -47,7 +47,7 @@ import java.util.List; import java.util.Optional; import java.util.Random; -public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock, AddMineableShears, AddMineableHoe { +public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock{ private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12); public BasePlantBlock() { @@ -62,8 +62,6 @@ public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderL this( FabricBlockSettings .of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT) - //TODO: 1.18.2 make sure this works with the new tag system - //.breakByHand(true) .sound(SoundType.GRASS) .noCollission() ); @@ -73,8 +71,6 @@ public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderL this( FabricBlockSettings .of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT) - //TODO: 1.18.2 Check if this is still ok - //.breakByHand(true) .luminance(light) .sound(SoundType.GRASS) .noCollission() diff --git a/src/main/java/ru/bclib/blocks/BasePlantWithAgeBlock.java b/src/main/java/ru/bclib/blocks/BasePlantWithAgeBlock.java index 56f8b375..ae0baf4a 100644 --- a/src/main/java/ru/bclib/blocks/BasePlantWithAgeBlock.java +++ b/src/main/java/ru/bclib/blocks/BasePlantWithAgeBlock.java @@ -20,8 +20,6 @@ public abstract class BasePlantWithAgeBlock extends BasePlantBlock { public BasePlantWithAgeBlock() { this( FabricBlockSettings.of(Material.PLANT) - //TODO: 1.18.2 Check if this is still ok - //.breakByHand(true) .sound(SoundType.GRASS) .randomTicks() .noCollission() diff --git a/src/main/java/ru/bclib/blocks/BaseStripableLogBlock.java b/src/main/java/ru/bclib/blocks/BaseStripableLogBlock.java index 84864803..9d2b9d46 100644 --- a/src/main/java/ru/bclib/blocks/BaseStripableLogBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseStripableLogBlock.java @@ -28,9 +28,7 @@ public class BaseStripableLogBlock extends BaseRotatedPillarBlock { @Override @SuppressWarnings("deprecation") public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { - //TODO: 1.18.2 check if (TagAPI.isToolWithMineableTag(player.getMainHandItem(), NamedMineableTags.AXE)){ - //if (FabricToolTags.AXES.contains(player.getMainHandItem().getItem())) { world.playSound(player, pos, SoundEvents.AXE_STRIP, SoundSource.BLOCKS, 1.0F, 1.0F); if (!world.isClientSide) { world.setBlock(pos, diff --git a/src/main/java/ru/bclib/blocks/BaseUnderwaterWallPlantBlock.java b/src/main/java/ru/bclib/blocks/BaseUnderwaterWallPlantBlock.java index d45fb308..c6351c6a 100644 --- a/src/main/java/ru/bclib/blocks/BaseUnderwaterWallPlantBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseUnderwaterWallPlantBlock.java @@ -18,8 +18,6 @@ public abstract class BaseUnderwaterWallPlantBlock extends BaseWallPlantBlock im this( FabricBlockSettings .of(Material.WATER_PLANT) - //TODO: 1.18.2 Check if this is still ok - //.breakByHand(true) .sound(SoundType.WET_GRASS) .noCollission() ); @@ -29,8 +27,6 @@ public abstract class BaseUnderwaterWallPlantBlock extends BaseWallPlantBlock im this( FabricBlockSettings .of(Material.WATER_PLANT) - //TODO: 1.18.2 Check if this is still ok - //.breakByHand(true) .luminance(light) .sound(SoundType.WET_GRASS) .noCollission() diff --git a/src/main/java/ru/bclib/blocks/BaseVineBlock.java b/src/main/java/ru/bclib/blocks/BaseVineBlock.java index 0f20c3a7..77c515cc 100644 --- a/src/main/java/ru/bclib/blocks/BaseVineBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseVineBlock.java @@ -53,8 +53,6 @@ public class BaseVineBlock extends BaseBlockNotFull implements RenderLayerProvid this( FabricBlockSettings .of(Material.PLANT) - //TODO: 1.18.2 make sure this works with the new tag system - //.breakByHand(true) .sound(SoundType.GRASS) .lightLevel((state) -> bottomOnly ? state.getValue(SHAPE) == TripleShape.BOTTOM ? light : 0 : light) .noCollission() @@ -111,7 +109,6 @@ public class BaseVineBlock extends BaseBlockNotFull implements RenderLayerProvid @Override public List getDrops(BlockState state, LootContext.Builder builder) { ItemStack tool = builder.getParameter(LootContextParams.TOOL); - //TODO: Test if shearing still works if (tool != null && BaseShearsItem.isShear(tool) || EnchantmentHelper.getItemEnchantmentLevel( Enchantments.SILK_TOUCH, tool diff --git a/src/main/java/ru/bclib/blocks/BaseWallPlantBlock.java b/src/main/java/ru/bclib/blocks/BaseWallPlantBlock.java index 7157dd1e..9e100860 100644 --- a/src/main/java/ru/bclib/blocks/BaseWallPlantBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseWallPlantBlock.java @@ -39,8 +39,6 @@ public abstract class BaseWallPlantBlock extends BasePlantBlock { this( FabricBlockSettings .of(Material.PLANT) - //TODO: 1.18.2 Check if this is still ok - //.breakByHand(true) .sound(SoundType.GRASS) .noCollission() ); @@ -50,8 +48,6 @@ public abstract class BaseWallPlantBlock extends BasePlantBlock { this( FabricBlockSettings .of(Material.PLANT) - //TODO: 1.18.2 Check if this is still ok - //.breakByHand(true) .luminance(light) .sound(SoundType.GRASS) .noCollission() diff --git a/src/main/java/ru/bclib/blocks/FeatureSaplingBlock.java b/src/main/java/ru/bclib/blocks/FeatureSaplingBlock.java index f8b91d65..eb646024 100644 --- a/src/main/java/ru/bclib/blocks/FeatureSaplingBlock.java +++ b/src/main/java/ru/bclib/blocks/FeatureSaplingBlock.java @@ -44,8 +44,6 @@ public class FeatureSaplingBlock extends SaplingBlock implements RenderLayerProv public FeatureSaplingBlock(Function> featureSupplier) { this(FabricBlockSettings.of(Material.PLANT) - //TODO: 1.18.2 Check if this is still ok - //.breakByHand(true) .collidable(false) .instabreak() .sound(SoundType.GRASS) @@ -56,8 +54,6 @@ public class FeatureSaplingBlock extends SaplingBlock implements RenderLayerProv public FeatureSaplingBlock(int light, Function> featureSupplier) { this(FabricBlockSettings.of(Material.PLANT) - //TODO: 1.18.2 Check if this is still ok - //.breakByHand(true) .collidable(false) .luminance(light) .instabreak() diff --git a/src/main/java/ru/bclib/blocks/StripableBarkBlock.java b/src/main/java/ru/bclib/blocks/StripableBarkBlock.java index 9118f66b..d04bcf59 100644 --- a/src/main/java/ru/bclib/blocks/StripableBarkBlock.java +++ b/src/main/java/ru/bclib/blocks/StripableBarkBlock.java @@ -28,9 +28,7 @@ public class StripableBarkBlock extends BaseBarkBlock { @Override @SuppressWarnings("deprecation") public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { - //TODO: 1.18.2 check if (TagAPI.isToolWithMineableTag(player.getMainHandItem(), NamedMineableTags.AXE)){ - //if (FabricToolTags.AXES.contains(player.getMainHandItem().getItem())) { world.playSound(player, pos, SoundEvents.AXE_STRIP, SoundSource.BLOCKS, 1.0F, 1.0F); if (!world.isClientSide) { world.setBlock(pos, diff --git a/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java b/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java index f7a6cedc..a85a92be 100644 --- a/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java +++ b/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java @@ -42,15 +42,13 @@ import ru.bclib.items.tool.BaseShearsItem; import java.util.List; import java.util.Random; -public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock, LiquidBlockContainer, AddMineableShears, AddMineableHoe { +public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock, LiquidBlockContainer { private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12); public UnderwaterPlantBlock() { this( FabricBlockSettings .of(Material.WATER_PLANT) - //TODO: 1.18.2 make sure this works with the new tag system - //.breakByHand(true) .sound(SoundType.WET_GRASS) .noCollission() ); @@ -60,8 +58,6 @@ public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements R this( FabricBlockSettings .of(Material.WATER_PLANT) - //TODO: 1.18.2 Check if this is still ok - //.breakByHand(true) .luminance(light) .sound(SoundType.WET_GRASS) .noCollission() @@ -109,7 +105,6 @@ public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements R @Override public List getDrops(BlockState state, LootContext.Builder builder) { ItemStack tool = builder.getParameter(LootContextParams.TOOL); - //TODO: Test is shearing still works if (tool != null && BaseShearsItem.isShear(tool) || EnchantmentHelper.getItemEnchantmentLevel( Enchantments.SILK_TOUCH, tool diff --git a/src/main/java/ru/bclib/blocks/UnderwaterPlantWithAgeBlock.java b/src/main/java/ru/bclib/blocks/UnderwaterPlantWithAgeBlock.java index c22473b3..255f74fb 100644 --- a/src/main/java/ru/bclib/blocks/UnderwaterPlantWithAgeBlock.java +++ b/src/main/java/ru/bclib/blocks/UnderwaterPlantWithAgeBlock.java @@ -20,8 +20,6 @@ public abstract class UnderwaterPlantWithAgeBlock extends UnderwaterPlantBlock { super( FabricBlockSettings .of(Material.WATER_PLANT) - //TODO: 1.18.2 Check if this is still ok - //.breakByHand(true) .sound(SoundType.WET_GRASS) .randomTicks() .noCollission() diff --git a/src/main/java/ru/bclib/blocks/UpDownPlantBlock.java b/src/main/java/ru/bclib/blocks/UpDownPlantBlock.java index 2b31868e..34cf92f3 100644 --- a/src/main/java/ru/bclib/blocks/UpDownPlantBlock.java +++ b/src/main/java/ru/bclib/blocks/UpDownPlantBlock.java @@ -41,8 +41,6 @@ public abstract class UpDownPlantBlock extends BaseBlockNotFull implements Rende public UpDownPlantBlock() { this(FabricBlockSettings .of(Material.PLANT) - //TODO: 1.18.2 make sure this works with the new tag system - //.breakByHand(true) .sound(SoundType.GRASS) .noCollission() ); @@ -86,7 +84,6 @@ public abstract class UpDownPlantBlock extends BaseBlockNotFull implements Rende @Override public List getDrops(BlockState state, LootContext.Builder builder) { ItemStack tool = builder.getParameter(LootContextParams.TOOL); - //TODO: 1.18.2 Test if shearing still works if (tool != null && BaseShearsItem.isShear(tool) || EnchantmentHelper.getItemEnchantmentLevel( Enchantments.SILK_TOUCH, tool diff --git a/src/main/java/ru/bclib/blocks/WallMushroomBlock.java b/src/main/java/ru/bclib/blocks/WallMushroomBlock.java index 8118b099..ff6e6c5a 100644 --- a/src/main/java/ru/bclib/blocks/WallMushroomBlock.java +++ b/src/main/java/ru/bclib/blocks/WallMushroomBlock.java @@ -19,8 +19,6 @@ public abstract class WallMushroomBlock extends BaseWallPlantBlock { this( FabricBlockSettings .of(Material.PLANT) - //TODO: 1.18.2 Check if this is still ok - //..breakByHand(true) .luminance(light) .destroyTime(0.2F) .sound(SoundType.GRASS) diff --git a/src/main/java/ru/bclib/interfaces/tools/PreventMineableAdd.java b/src/main/java/ru/bclib/interfaces/tools/PreventMineableAdd.java new file mode 100644 index 00000000..a6f30fef --- /dev/null +++ b/src/main/java/ru/bclib/interfaces/tools/PreventMineableAdd.java @@ -0,0 +1,4 @@ +package ru.bclib.interfaces.tools; + +public interface PreventMineableAdd { +} diff --git a/src/main/java/ru/bclib/items/tool/BasePickaxeItem.java b/src/main/java/ru/bclib/items/tool/BasePickaxeItem.java index 7fe12455..5c458249 100644 --- a/src/main/java/ru/bclib/items/tool/BasePickaxeItem.java +++ b/src/main/java/ru/bclib/items/tool/BasePickaxeItem.java @@ -9,7 +9,6 @@ import net.minecraft.world.item.Tier; import ru.bclib.client.models.ModelsHelper; import ru.bclib.interfaces.ItemModelProvider; -//TODO: 1.18.2 See if mining speed is still ok. public class BasePickaxeItem extends PickaxeItem implements ItemModelProvider { public BasePickaxeItem(Tier material, int attackDamage, float attackSpeed, Properties settings) { super(material, attackDamage, attackSpeed, settings); diff --git a/src/main/java/ru/bclib/items/tool/BaseShearsItem.java b/src/main/java/ru/bclib/items/tool/BaseShearsItem.java index 4d6bc549..61a29fab 100644 --- a/src/main/java/ru/bclib/items/tool/BaseShearsItem.java +++ b/src/main/java/ru/bclib/items/tool/BaseShearsItem.java @@ -20,7 +20,6 @@ public class BaseShearsItem extends ShearsItem { public static boolean isShear(ItemStack itemStack, Item item){ if (item == Items.SHEARS){ - //TODO: 1.18.2 see if removing SHEARS_MINEABLE causes any problems... It should not, since it is a Block-Tag return itemStack.is(item) | itemStack.is(CommonItemTags.SHEARS); } else { return itemStack.is(item); diff --git a/src/main/java/ru/bclib/items/tool/BaseShovelItem.java b/src/main/java/ru/bclib/items/tool/BaseShovelItem.java index 1795d74b..5c92008b 100644 --- a/src/main/java/ru/bclib/items/tool/BaseShovelItem.java +++ b/src/main/java/ru/bclib/items/tool/BaseShovelItem.java @@ -9,7 +9,6 @@ import net.minecraft.world.item.Tier; import ru.bclib.client.models.ModelsHelper; import ru.bclib.interfaces.ItemModelProvider; -//TODO: 1.18.2 See if mining speed is still ok. public class BaseShovelItem extends ShovelItem implements ItemModelProvider { public BaseShovelItem(Tier material, float attackDamage, float attackSpeed, Properties settings) { super(material, attackDamage, attackSpeed, settings); diff --git a/src/main/java/ru/bclib/mixin/common/shears/ItemPredicateBuilderMixin.java b/src/main/java/ru/bclib/mixin/common/shears/ItemPredicateBuilderMixin.java index b15d8082..eed9de92 100644 --- a/src/main/java/ru/bclib/mixin/common/shears/ItemPredicateBuilderMixin.java +++ b/src/main/java/ru/bclib/mixin/common/shears/ItemPredicateBuilderMixin.java @@ -23,7 +23,6 @@ public abstract class ItemPredicateBuilderMixin { @Inject(method = "matches", at = @At("HEAD"), cancellable = true) void bclib_of(ItemStack itemStack, CallbackInfoReturnable cir) { if (this.items != null && this.items.size() == 1 && this.items.contains(Items.SHEARS)) { - //TODO: 1.18.2 See if removing minable_shears test is having an efffect... if (itemStack.is(CommonItemTags.SHEARS) ){ cir.setReturnValue(true); } diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiome.java b/src/main/java/ru/bclib/world/biomes/BCLBiome.java index 840c6888..c5f5b5fd 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiome.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiome.java @@ -210,7 +210,6 @@ public class BCLBiome extends BCLBiomeSettings { } if (!this.structureTags.isEmpty()) { - //TODO: 1.18.2 This need to be done by BiomeTags now structureTags.forEach(tagKey -> TagAPI.addBiomeTag(tagKey, actualBiome.value())); } diff --git a/src/main/java/ru/bclib/world/features/BCLFeature.java b/src/main/java/ru/bclib/world/features/BCLFeature.java index ef59e1d6..771016bb 100644 --- a/src/main/java/ru/bclib/world/features/BCLFeature.java +++ b/src/main/java/ru/bclib/world/features/BCLFeature.java @@ -42,7 +42,6 @@ public class BCLFeature { private static > Holder buildPlacedFeature(ResourceLocation id, F feature, FC configuration, PlacementModifier[] modifiers) { Holder> configuredFeature; - //TODO: 1.18.2 Check if this cast is working if (!BuiltinRegistries.CONFIGURED_FEATURE.containsKey(id)) { configuredFeature = (Holder>)(Object)FeatureUtils.register(id.toString(), feature, configuration); } else { diff --git a/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java b/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java index 146b4585..93b404ae 100644 --- a/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java +++ b/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java @@ -63,8 +63,6 @@ public class BCLStructureFeature { this.structure = StructureFeatureAccessor.callRegister(id.toString(), structure, step); this.featureConfigured = StructureFeaturesAccessor.callRegister(structureKey, this.structure.configured(NoneFeatureConfiguration.NONE, biomeTag, adaptNoise)); StructureSets.register(structureSetKey, featureConfigured, spreadConfig); - //TODO: 1.18 check if structures are added correctly - //FlatChunkGeneratorConfigAccessor.getStructureToFeatures().put(this.structure, this.featureConfigured); } /** From 5a30e60d31e5287a49999a679d342a4b993123b2 Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 18 Mar 2022 19:18:09 +0100 Subject: [PATCH 23/34] Added Tooltips that tell players what type of ground they can place vegetation on. --- .../ru/bclib/interfaces/SurvivesOnBlocks.java | 27 ++++++++ .../interfaces/SurvivesOnSpecialGround.java | 65 +++++++++++++++++++ .../ru/bclib/interfaces/SurvivesOnTags.java | 33 ++++++++++ .../ru/bclib/mixin/client/BlockMixin.java | 25 +++++++ .../resources/assets/bclib/lang/de_de.json | 4 +- .../resources/assets/bclib/lang/en_us.json | 4 +- src/main/resources/bclib.mixins.client.json | 3 +- 7 files changed, 158 insertions(+), 3 deletions(-) create mode 100644 src/main/java/ru/bclib/interfaces/SurvivesOnBlocks.java create mode 100644 src/main/java/ru/bclib/interfaces/SurvivesOnSpecialGround.java create mode 100644 src/main/java/ru/bclib/interfaces/SurvivesOnTags.java create mode 100644 src/main/java/ru/bclib/mixin/client/BlockMixin.java diff --git a/src/main/java/ru/bclib/interfaces/SurvivesOnBlocks.java b/src/main/java/ru/bclib/interfaces/SurvivesOnBlocks.java new file mode 100644 index 00000000..b792d22f --- /dev/null +++ b/src/main/java/ru/bclib/interfaces/SurvivesOnBlocks.java @@ -0,0 +1,27 @@ +package ru.bclib.interfaces; + +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; + +import java.util.List; +import java.util.stream.Collectors; + +public interface SurvivesOnBlocks extends SurvivesOnSpecialGround{ + List getSurvivableBlocks(); + + @Override + default String getSurvivableBlocksString(){ + return getSurvivableBlocks() + .stream() + .filter(block -> block!= Blocks.AIR) + .map(block ->new ItemStack(block).getHoverName().getString()) + .collect(Collectors.joining(", ")); + } + + @Override + default boolean isSurvivable(BlockState state){ + return getSurvivableBlocks().contains(state.getBlock()); + } +} diff --git a/src/main/java/ru/bclib/interfaces/SurvivesOnSpecialGround.java b/src/main/java/ru/bclib/interfaces/SurvivesOnSpecialGround.java new file mode 100644 index 00000000..e2ad9342 --- /dev/null +++ b/src/main/java/ru/bclib/interfaces/SurvivesOnSpecialGround.java @@ -0,0 +1,65 @@ +package ru.bclib.interfaces; + +import com.google.common.collect.Lists; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.ChatFormatting; +import net.minecraft.core.BlockPos; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.state.BlockState; + +import java.util.List; + +public interface SurvivesOnSpecialGround { + String getSurvivableBlocksString(); + + @Environment(EnvType.CLIENT) + static List splitLines(String input){ + final int MAX_LEN = 30; + final int MAX_LEN_SECOND = 40; + List lines = Lists.newArrayList(); + int maxLen = MAX_LEN; + + while (input.length()>maxLen){ + int idx = input.lastIndexOf(",", maxLen); + if (idx>=0) { + lines.add( input.substring(0, idx+1).trim()); + input = input.substring(idx+1, input.length()).trim(); + } else { + break; + } + + maxLen = MAX_LEN_SECOND; + } + lines.add(input.trim()); + + return lines; + } + + @Environment(EnvType.CLIENT) + static void appendHoverText(List list, String description) { + final int MAX_LINES = 5; + List lines = splitLines(description); + if (lines.size()>0) { + list.add(new TranslatableComponent("tooltip.bclib.place_on", lines.get(0)).withStyle(ChatFormatting.GREEN)); + } + for (int i=1; i> getSurvivableTags(); + + @Override + default String getSurvivableBlocksString(){ + return getSurvivableTags() + .stream() + .map(tag -> Registry.BLOCK.getTag(tag)) + .filter(named->named.isPresent()) + .map(named->named.get()) + .flatMap(named->named.stream()) + .filter(block -> block != Blocks.AIR && block != null) + .map(block ->new ItemStack(block.value()).getHoverName().getString()) + .collect(Collectors.joining(", ")); + } + + @Override + default boolean isSurvivable(BlockState state){ + return getSurvivableTags().stream().anyMatch(tag->state.is(tag)); + } +} diff --git a/src/main/java/ru/bclib/mixin/client/BlockMixin.java b/src/main/java/ru/bclib/mixin/client/BlockMixin.java new file mode 100644 index 00000000..d4f92437 --- /dev/null +++ b/src/main/java/ru/bclib/mixin/client/BlockMixin.java @@ -0,0 +1,25 @@ +package ru.bclib.mixin.client; + +import net.minecraft.network.chat.Component; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.block.Block; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import ru.bclib.interfaces.SurvivesOnSpecialGround; + +import java.util.List; + +@Mixin(Block.class) +public class BlockMixin { + @Inject(method="appendHoverText", at=@At("HEAD")) + void bclib_appendSurvivalBlock(ItemStack itemStack, @Nullable BlockGetter blockGetter, List list, TooltipFlag tooltipFlag, CallbackInfo ci){ + if (this instanceof SurvivesOnSpecialGround surv){ + SurvivesOnSpecialGround.appendHoverText(list, surv.getSurvivableBlocksString()); + } + } +} diff --git a/src/main/resources/assets/bclib/lang/de_de.json b/src/main/resources/assets/bclib/lang/de_de.json index bd83c0c9..5038c9bf 100644 --- a/src/main/resources/assets/bclib/lang/de_de.json +++ b/src/main/resources/assets/bclib/lang/de_de.json @@ -52,5 +52,7 @@ "title.bclib.datafixer.error": "Fehler beim Reparieren der Welt", "message.bclib.datafixer.error": "Es gab Fehler beim Reparieren der Welt. Das bedeutet, dass dieser Level wahrscheinlich in einem inkonsistenten Zustand ist und Sie ihn nicht spielen sollten. Bitte stellen Sie Ihr Backup wieder her und beheben Sie die unten aufgeführten Fehler, bevor Sie es erneut versuchen.", "title.bclib.datafixer.error.continue": "Continue and Mark as Fixed", - "title.config.bclib.main.ui.suppressExperimentalDialogOnLoad": "Disable Experimental Warning Screen on Load" + "title.config.bclib.main.ui.suppressExperimentalDialogOnLoad": "Disable Experimental Warning Screen on Load", + + "tooltip.bclib.place_on": "Lebt auf: %s" } \ No newline at end of file diff --git a/src/main/resources/assets/bclib/lang/en_us.json b/src/main/resources/assets/bclib/lang/en_us.json index 4cd68730..977e7f06 100644 --- a/src/main/resources/assets/bclib/lang/en_us.json +++ b/src/main/resources/assets/bclib/lang/en_us.json @@ -54,5 +54,7 @@ "title.bclib.datafixer.error.continue": "Proceed and mark as fixed", "title.config.bclib.client.rendering.customFogRendering": "Custom Fog Rendering", - "title.config.bclib.client.rendering.netherThickFog": "Nether Thick Fog" + "title.config.bclib.client.rendering.netherThickFog": "Nether Thick Fog", + + "tooltip.bclib.place_on": "Survives on: %s" } \ No newline at end of file diff --git a/src/main/resources/bclib.mixins.client.json b/src/main/resources/bclib.mixins.client.json index 0920d0e3..041d5576 100644 --- a/src/main/resources/bclib.mixins.client.json +++ b/src/main/resources/bclib.mixins.client.json @@ -13,7 +13,8 @@ "ModelBakeryMixin", "WorldPresetMixin", "MinecraftMixin", - "GameMixin" + "GameMixin", + "BlockMixin" ], "injectors": { "defaultRequire": 1 From 12a8b0c23a5a551a756afd15314f6cd98e08b8a9 Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 18 Mar 2022 20:20:44 +0100 Subject: [PATCH 24/34] Fixed TollTip Layout --- .../ru/bclib/interfaces/SurvivesOnBlocks.java | 10 +++++-- .../interfaces/SurvivesOnSpecialGround.java | 30 +++++++++---------- .../ru/bclib/interfaces/SurvivesOnTags.java | 9 +++++- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/main/java/ru/bclib/interfaces/SurvivesOnBlocks.java b/src/main/java/ru/bclib/interfaces/SurvivesOnBlocks.java index b792d22f..148606c6 100644 --- a/src/main/java/ru/bclib/interfaces/SurvivesOnBlocks.java +++ b/src/main/java/ru/bclib/interfaces/SurvivesOnBlocks.java @@ -5,6 +5,7 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; +import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; @@ -15,8 +16,13 @@ public interface SurvivesOnBlocks extends SurvivesOnSpecialGround{ default String getSurvivableBlocksString(){ return getSurvivableBlocks() .stream() - .filter(block -> block!= Blocks.AIR) - .map(block ->new ItemStack(block).getHoverName().getString()) + .filter(block -> block!= Blocks.AIR && block!=null) + .map(block -> { + ItemStack stack = new ItemStack(block); + if (stack.hasCustomHoverName()) return stack.getHoverName().getString(); + else return block.getName().getString(); + }) + .sorted(Comparator.naturalOrder()) .collect(Collectors.joining(", ")); } diff --git a/src/main/java/ru/bclib/interfaces/SurvivesOnSpecialGround.java b/src/main/java/ru/bclib/interfaces/SurvivesOnSpecialGround.java index e2ad9342..de1dae4c 100644 --- a/src/main/java/ru/bclib/interfaces/SurvivesOnSpecialGround.java +++ b/src/main/java/ru/bclib/interfaces/SurvivesOnSpecialGround.java @@ -17,22 +17,18 @@ public interface SurvivesOnSpecialGround { String getSurvivableBlocksString(); @Environment(EnvType.CLIENT) - static List splitLines(String input){ - final int MAX_LEN = 30; - final int MAX_LEN_SECOND = 40; + static List splitLines(String input) { + final int MAX_LEN = 45; List lines = Lists.newArrayList(); - int maxLen = MAX_LEN; - while (input.length()>maxLen){ - int idx = input.lastIndexOf(",", maxLen); + while (input.length()>MAX_LEN){ + int idx = input.lastIndexOf(",", MAX_LEN); if (idx>=0) { lines.add( input.substring(0, idx+1).trim()); - input = input.substring(idx+1, input.length()).trim(); + input = input.substring(idx+1).trim(); } else { break; } - - maxLen = MAX_LEN_SECOND; } lines.add(input.trim()); @@ -41,15 +37,17 @@ public interface SurvivesOnSpecialGround { @Environment(EnvType.CLIENT) static void appendHoverText(List list, String description) { - final int MAX_LINES = 5; + final int MAX_LINES = 7; List lines = splitLines(description); - if (lines.size()>0) { + if (lines.size()==1) { list.add(new TranslatableComponent("tooltip.bclib.place_on", lines.get(0)).withStyle(ChatFormatting.GREEN)); - } - for (int i=1; i1) { + list.add(new TranslatableComponent("tooltip.bclib.place_on", "").withStyle(ChatFormatting.GREEN)); + for (int i = 0; i < Math.min(lines.size(), MAX_LINES); i++) { + String line = lines.get(i); + if (i == MAX_LINES - 1 && i < lines.size() - 1) line += " ..."; + list.add(new TextComponent(" " + line).withStyle(ChatFormatting.GREEN)); + } } } diff --git a/src/main/java/ru/bclib/interfaces/SurvivesOnTags.java b/src/main/java/ru/bclib/interfaces/SurvivesOnTags.java index b39d909c..fbd9d614 100644 --- a/src/main/java/ru/bclib/interfaces/SurvivesOnTags.java +++ b/src/main/java/ru/bclib/interfaces/SurvivesOnTags.java @@ -5,8 +5,10 @@ import net.minecraft.tags.TagKey; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.NetherrackBlock; import net.minecraft.world.level.block.state.BlockState; +import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; @@ -22,7 +24,12 @@ public interface SurvivesOnTags extends SurvivesOnSpecialGround{ .map(named->named.get()) .flatMap(named->named.stream()) .filter(block -> block != Blocks.AIR && block != null) - .map(block ->new ItemStack(block.value()).getHoverName().getString()) + .map(block -> { + ItemStack stack = new ItemStack(block.value()); + if (stack.hasCustomHoverName()) return stack.getHoverName().getString(); + else return block.value().getName().getString(); + }) + .sorted(Comparator.naturalOrder()) .collect(Collectors.joining(", ")); } From c783d007b13dbda510eb28bde397bc3507b8d351 Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 18 Mar 2022 20:44:50 +0100 Subject: [PATCH 25/34] Fixed MultiPackResourceManagerMixin --- .../client/MultiPackResourceManagerMixin.java | 53 +++++++++++++++++++ .../SimpleReloadableResourceManagerMixin.java | 53 ------------------- .../common/MultiPackResourceManagerMixin.java | 30 +++++++++++ .../SimpleReloadableResourceManagerMixin.java | 39 -------------- 4 files changed, 83 insertions(+), 92 deletions(-) create mode 100644 src/main/java/ru/bclib/mixin/client/MultiPackResourceManagerMixin.java delete mode 100644 src/main/java/ru/bclib/mixin/client/SimpleReloadableResourceManagerMixin.java create mode 100644 src/main/java/ru/bclib/mixin/common/MultiPackResourceManagerMixin.java delete mode 100644 src/main/java/ru/bclib/mixin/common/SimpleReloadableResourceManagerMixin.java diff --git a/src/main/java/ru/bclib/mixin/client/MultiPackResourceManagerMixin.java b/src/main/java/ru/bclib/mixin/client/MultiPackResourceManagerMixin.java new file mode 100644 index 00000000..f2bc7b61 --- /dev/null +++ b/src/main/java/ru/bclib/mixin/client/MultiPackResourceManagerMixin.java @@ -0,0 +1,53 @@ +package ru.bclib.mixin.client; + +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.packs.resources.FallbackResourceManager; +import net.minecraft.server.packs.resources.MultiPackResourceManager; +import net.minecraft.server.packs.resources.Resource; +import net.minecraft.server.packs.resources.ResourceManager; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import ru.bclib.BCLib; +import ru.bclib.api.ModIntegrationAPI; +import ru.bclib.client.render.EmissiveTextureInfo; + +import java.io.IOException; +import java.util.Map; + +@Mixin(MultiPackResourceManager.class) +public class MultiPackResourceManagerMixin { + @Final + @Shadow + private Map namespacedManagers; + + private ResourceLocation bclib_alphaEmissionMaterial = BCLib.makeID("materialmaps/block/alpha_emission.json"); + + @Inject(method = "getResource", at = @At("HEAD"), cancellable = true) + private void bclib_getResource(ResourceLocation resourceLocation, CallbackInfoReturnable info) throws IOException { + if (!ModIntegrationAPI.hasCanvas()) { + return; + } + if (!resourceLocation.getPath().startsWith("materialmaps")) { + return; + } + if (!resourceLocation.getPath().contains("/block/")) { + return; + } + + String name = resourceLocation.getPath().replace("materialmaps/block/", "").replace(".json", ""); + ResourceLocation blockID = new ResourceLocation(resourceLocation.getNamespace(), name); + + if (!EmissiveTextureInfo.isEmissiveBlock(blockID)) { + return; + } + + ResourceManager resourceManager = this.namespacedManagers.get(resourceLocation.getNamespace()); + if (resourceManager != null && !resourceManager.hasResource(resourceLocation)) { + info.setReturnValue(resourceManager.getResource(bclib_alphaEmissionMaterial)); + } + } +} diff --git a/src/main/java/ru/bclib/mixin/client/SimpleReloadableResourceManagerMixin.java b/src/main/java/ru/bclib/mixin/client/SimpleReloadableResourceManagerMixin.java deleted file mode 100644 index 594d71f2..00000000 --- a/src/main/java/ru/bclib/mixin/client/SimpleReloadableResourceManagerMixin.java +++ /dev/null @@ -1,53 +0,0 @@ -package ru.bclib.mixin.client; - -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.packs.resources.FallbackResourceManager; -import net.minecraft.server.packs.resources.Resource; -import net.minecraft.server.packs.resources.ResourceManager; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import ru.bclib.BCLib; -import ru.bclib.api.ModIntegrationAPI; -import ru.bclib.client.render.EmissiveTextureInfo; - -import java.io.IOException; -import java.util.Map; - -//TODO: 1.18.2 Disabled to have a compilable Version -//@Mixin(SimpleReloadableResourceManager.class) -//public class SimpleReloadableResourceManagerMixin { -// @Final -// @Shadow -// private Map namespacedPacks; -// -// private ResourceLocation bclib_alphaEmissionMaterial = BCLib.makeID("materialmaps/block/alpha_emission.json"); -// -// @Inject(method = "getResource", at = @At("HEAD"), cancellable = true) -// private void bclib_getResource(ResourceLocation resourceLocation, CallbackInfoReturnable info) throws IOException { -// if (!ModIntegrationAPI.hasCanvas()) { -// return; -// } -// if (!resourceLocation.getPath().startsWith("materialmaps")) { -// return; -// } -// if (!resourceLocation.getPath().contains("/block/")) { -// return; -// } -// -// String name = resourceLocation.getPath().replace("materialmaps/block/", "").replace(".json", ""); -// ResourceLocation blockID = new ResourceLocation(resourceLocation.getNamespace(), name); -// -// if (!EmissiveTextureInfo.isEmissiveBlock(blockID)) { -// return; -// } -// -// ResourceManager resourceManager = this.namespacedPacks.get(resourceLocation.getNamespace()); -// if (resourceManager != null && !resourceManager.hasResource(resourceLocation)) { -// info.setReturnValue(resourceManager.getResource(bclib_alphaEmissionMaterial)); -// } -// } -//} diff --git a/src/main/java/ru/bclib/mixin/common/MultiPackResourceManagerMixin.java b/src/main/java/ru/bclib/mixin/common/MultiPackResourceManagerMixin.java new file mode 100644 index 00000000..09365589 --- /dev/null +++ b/src/main/java/ru/bclib/mixin/common/MultiPackResourceManagerMixin.java @@ -0,0 +1,30 @@ +package ru.bclib.mixin.common; + +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.packs.resources.MultiPackResourceManager; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(MultiPackResourceManager.class) +public class MultiPackResourceManagerMixin { + private static final String[] BCLIB_MISSING_RESOURCES = new String[] { + "dimension/the_end.json", + "dimension/the_nether.json", + "dimension_type/the_end.json", + "dimension_type/the_nether.json" + }; + + @Inject(method = "hasResource", at = @At("HEAD"), cancellable = true) + private void bclib_hasResource(ResourceLocation resourceLocation, CallbackInfoReturnable info) { + if (resourceLocation.getNamespace().equals("minecraft")) { + for (String key: BCLIB_MISSING_RESOURCES) { + if (resourceLocation.getPath().equals(key)) { + info.setReturnValue(false); + return; + } + } + } + } +} diff --git a/src/main/java/ru/bclib/mixin/common/SimpleReloadableResourceManagerMixin.java b/src/main/java/ru/bclib/mixin/common/SimpleReloadableResourceManagerMixin.java deleted file mode 100644 index 3b78fdbc..00000000 --- a/src/main/java/ru/bclib/mixin/common/SimpleReloadableResourceManagerMixin.java +++ /dev/null @@ -1,39 +0,0 @@ -package ru.bclib.mixin.common; - -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.packs.resources.FallbackResourceManager; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.util.Map; - -//TODO: 1.18.2 Disabled to have a compilable Version -//@Mixin(SimpleReloadableResourceManager.class) -//public class SimpleReloadableResourceManagerMixin { -// @Final -// @Shadow -// private Map namespacedPacks; -// -// private static final String[] BCLIB_MISSING_RESOURCES = new String[] { -// "dimension/the_end.json", -// "dimension/the_nether.json", -// "dimension_type/the_end.json", -// "dimension_type/the_nether.json" -// }; -// -// @Inject(method = "hasResource", at = @At("HEAD"), cancellable = true) -// private void bclib_hasResource(ResourceLocation resourceLocation, CallbackInfoReturnable info) { -// if (resourceLocation.getNamespace().equals("minecraft")) { -// for (String key: BCLIB_MISSING_RESOURCES) { -// if (resourceLocation.getPath().equals(key)) { -// info.setReturnValue(false); -// return; -// } -// } -// } -// } -//} From ecc792ed9afb666cc0e165dbda0ea2017ed4bd0d Mon Sep 17 00:00:00 2001 From: Frank Date: Mon, 21 Mar 2022 18:14:28 +0100 Subject: [PATCH 26/34] Version fixes --- gradle.properties | 2 +- src/main/resources/fabric.mod.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index ea6a1b6e..d32c8836 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,4 +17,4 @@ archives_base_name = bclib # Dependencies patchouli_version = 50-FABRIC -modmenu_version=3.0.1 \ No newline at end of file +modmenu_version=3.1.0 \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index b775d1f4..340c2ee7 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,7 +1,7 @@ { "schemaVersion": 1, "id": "bclib", - "version": "${version}", + "version": "1.4.0", "name": "BCLib", "description": "A library for BetterX team mods", "authors": [ @@ -39,7 +39,7 @@ "depends": { "fabricloader": ">=0.13.3", "fabric": ">=0.48.0", - "minecraft": "1.18.x" + "minecraft": "1.18.2" }, "custom":{ "modmenu":{ From 0e1627958a83675bc3417a45f0b4ef1bbd5b3a58 Mon Sep 17 00:00:00 2001 From: Frank Date: Sun, 3 Apr 2022 22:51:05 +0200 Subject: [PATCH 27/34] More Tag Related Changes --- gradle.properties | 2 +- src/main/java/ru/bclib/api/PostInitAPI.java | 3 +++ src/main/java/ru/bclib/api/tag/NamedMineableTags.java | 1 + .../java/ru/bclib/interfaces/tools/AddMineableHammer.java | 4 ++++ 4 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 src/main/java/ru/bclib/interfaces/tools/AddMineableHammer.java diff --git a/gradle.properties b/gradle.properties index d32c8836..a71becfc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,7 +11,7 @@ loader_version= 0.13.3 fabric_version = 0.47.10+1.18.2 # Mod Properties -mod_version = 1.4.0 +mod_version = 1.4.1 maven_group = ru.bclib archives_base_name = bclib diff --git a/src/main/java/ru/bclib/api/PostInitAPI.java b/src/main/java/ru/bclib/api/PostInitAPI.java index a2db39d4..ea2ceb3b 100644 --- a/src/main/java/ru/bclib/api/PostInitAPI.java +++ b/src/main/java/ru/bclib/api/PostInitAPI.java @@ -132,6 +132,9 @@ public class PostInitAPI { 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); diff --git a/src/main/java/ru/bclib/api/tag/NamedMineableTags.java b/src/main/java/ru/bclib/api/tag/NamedMineableTags.java index 78a2c97a..b78e0a16 100644 --- a/src/main/java/ru/bclib/api/tag/NamedMineableTags.java +++ b/src/main/java/ru/bclib/api/tag/NamedMineableTags.java @@ -10,4 +10,5 @@ public class NamedMineableTags { public static final TagLocation SHEARS = new TagLocation<>("fabric", "mineable/shears"); public static final TagLocation SHOVEL = new TagLocation<>("mineable/shovel"); public static final TagLocation SWORD = new TagLocation<>("fabric", "mineable/sword"); + public static final TagLocation HAMMER = new TagLocation<>("c", "mineable/hammer"); } diff --git a/src/main/java/ru/bclib/interfaces/tools/AddMineableHammer.java b/src/main/java/ru/bclib/interfaces/tools/AddMineableHammer.java new file mode 100644 index 00000000..a88997bd --- /dev/null +++ b/src/main/java/ru/bclib/interfaces/tools/AddMineableHammer.java @@ -0,0 +1,4 @@ +package ru.bclib.interfaces.tools; + +public interface AddMineableHammer { +} From 4b550b9e6959322a14b65c233c5c8e7d244fb9a5 Mon Sep 17 00:00:00 2001 From: Frank Date: Sun, 3 Apr 2022 23:45:19 +0200 Subject: [PATCH 28/34] Biome, Structure and Feature fixes --- src/main/java/ru/bclib/api/biomes/BiomeAPI.java | 12 ++++++------ .../ru/bclib/api/features/BCLFeatureBuilder.java | 5 +++++ .../java/ru/bclib/integration/ModIntegration.java | 4 ++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java index 9303d4a5..24787fde 100644 --- a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java @@ -93,7 +93,7 @@ public class BiomeAPI { public static final BCLBiome SOUL_SAND_VALLEY_BIOME = registerNetherBiome(getFromRegistry(Biomes.SOUL_SAND_VALLEY).value()); public static final BCLBiome BASALT_DELTAS_BIOME = registerNetherBiome(getFromRegistry(Biomes.BASALT_DELTAS).value()); - public static final BCLBiome THE_END = registerEndLandBiome(getFromRegistry(Biomes.THE_END).value()); + public static final BCLBiome THE_END = registerEndLandBiome(getFromRegistry(Biomes.THE_END)); public static final BCLBiome END_MIDLANDS = registerSubBiome(THE_END, getFromRegistry(Biomes.END_MIDLANDS).value(), 0.5F); public static final BCLBiome END_HIGHLANDS = registerSubBiome(THE_END, getFromRegistry(Biomes.END_HIGHLANDS).value(), 0.5F); @@ -232,8 +232,8 @@ public class BiomeAPI { * @param biome {@link BCLBiome} * @return {@link BCLBiome} */ - public static BCLBiome registerEndLandBiome(Biome biome) { - BCLBiome bclBiome = new BCLBiome(biome, null); + public static BCLBiome registerEndLandBiome(Holder biome) { + BCLBiome bclBiome = new BCLBiome(biome.value(), null); END_LAND_BIOME_PICKER.addBiome(bclBiome); registerBiome(bclBiome); @@ -247,8 +247,8 @@ public class BiomeAPI { * @param genChance float generation chance. * @return {@link BCLBiome} */ - public static BCLBiome registerEndLandBiome(Biome biome, float genChance) { - BCLBiome bclBiome = new BCLBiome(biome, VanillaBiomeSettings.createVanilla().setGenChance(genChance).build()); + public static BCLBiome registerEndLandBiome(Holder biome, float genChance) { + BCLBiome bclBiome = new BCLBiome(biome.value(), VanillaBiomeSettings.createVanilla().setGenChance(genChance).build()); END_LAND_BIOME_PICKER.addBiome(bclBiome); registerBiome(bclBiome); @@ -423,7 +423,7 @@ public class BiomeAPI { FabricBiomesData.END_LAND_BIOMES.forEach((key, weight) -> { if (!hasBiome(key.location())) { - registerEndLandBiome(BuiltinRegistries.BIOME.get(key), weight); + registerEndLandBiome(BuiltinRegistries.BIOME.getHolder(key).orElseThrow(), weight); } }); diff --git a/src/main/java/ru/bclib/api/features/BCLFeatureBuilder.java b/src/main/java/ru/bclib/api/features/BCLFeatureBuilder.java index ec98fb1e..d0b39889 100644 --- a/src/main/java/ru/bclib/api/features/BCLFeatureBuilder.java +++ b/src/main/java/ru/bclib/api/features/BCLFeatureBuilder.java @@ -61,6 +61,11 @@ public class BCLFeatureBuilder modifiers) { + modifications.addAll(modifiers); + return this; + } /** * Generate feature in certain iterations (per chunk). diff --git a/src/main/java/ru/bclib/integration/ModIntegration.java b/src/main/java/ru/bclib/integration/ModIntegration.java index bc5961dc..77838b24 100644 --- a/src/main/java/ru/bclib/integration/ModIntegration.java +++ b/src/main/java/ru/bclib/integration/ModIntegration.java @@ -79,8 +79,8 @@ public abstract class ModIntegration { return BuiltinRegistries.CONFIGURED_FEATURE.get(getID(name)); } - public Biome getBiome(String name) { - return BuiltinRegistries.BIOME.get(getID(name)); + public Holder getBiome(String name) { + return BuiltinRegistries.BIOME.getHolder(getKey(name)).orElseThrow(); } public Class getClass(String path) { From cdb7b305d94a2baeeeae47dabf72386c8da14529 Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 8 Apr 2022 16:38:13 +0200 Subject: [PATCH 29/34] Possible fix for anvil crash (#116) --- src/main/java/ru/bclib/BCLib.java | 2 ++ src/main/java/ru/bclib/recipes/AnvilRecipe.java | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/main/java/ru/bclib/BCLib.java b/src/main/java/ru/bclib/BCLib.java index f80d8a0d..afc2ace1 100644 --- a/src/main/java/ru/bclib/BCLib.java +++ b/src/main/java/ru/bclib/BCLib.java @@ -13,6 +13,7 @@ import ru.bclib.api.dataexchange.handler.autosync.RequestFiles; 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; @@ -38,6 +39,7 @@ public class BCLib implements ModInitializer { CraftingRecipes.init(); WorldDataAPI.registerModCache(MOD_ID); DataExchangeAPI.registerMod(MOD_ID); + AnvilRecipe.register(); DataExchangeAPI.registerDescriptors(List.of( HelloClient.DESCRIPTOR, diff --git a/src/main/java/ru/bclib/recipes/AnvilRecipe.java b/src/main/java/ru/bclib/recipes/AnvilRecipe.java index c2b3b3a0..c40ca868 100644 --- a/src/main/java/ru/bclib/recipes/AnvilRecipe.java +++ b/src/main/java/ru/bclib/recipes/AnvilRecipe.java @@ -46,6 +46,10 @@ public class AnvilRecipe implements Recipe, UnknownReceipBookCategory ); public final static ResourceLocation ID = BCLib.makeID(GROUP); + public static void register(){ + + } + private final ResourceLocation id; private final Ingredient input; private final ItemStack output; From a52f46a9331e5f8bb7c6971b4c68cf467d5cf28e Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 8 Apr 2022 16:38:28 +0200 Subject: [PATCH 30/34] Generalized Version again... --- src/main/resources/fabric.mod.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 340c2ee7..764249f2 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,7 +1,7 @@ { "schemaVersion": 1, "id": "bclib", - "version": "1.4.0", + "version": "${version}", "name": "BCLib", "description": "A library for BetterX team mods", "authors": [ From a24e03e411bff4df79b6e6fbac7168c53e5a69f7 Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 8 Apr 2022 16:42:28 +0200 Subject: [PATCH 31/34] Updated Fabric-API --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index a71becfc..f71a3970 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ loom_version=0.10-SNAPSHOT # check these on https://fabricmc.net/versions.html minecraft_version= 1.18.2 loader_version= 0.13.3 -fabric_version = 0.47.10+1.18.2 +fabric_version = 0.48.0+1.18.2 # Mod Properties mod_version = 1.4.1 From dee3e89b3b14469bc92a3d3d0507c4c040d95201 Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 8 Apr 2022 17:32:13 +0200 Subject: [PATCH 32/34] Changed Hammer Tool handling --- gradle.properties | 2 +- src/main/java/ru/bclib/api/tag/CommonBlockTags.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index f71a3970..8b1454fd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,7 +11,7 @@ loader_version= 0.13.3 fabric_version = 0.48.0+1.18.2 # Mod Properties -mod_version = 1.4.1 +mod_version = 1.4.2 maven_group = ru.bclib archives_base_name = bclib diff --git a/src/main/java/ru/bclib/api/tag/CommonBlockTags.java b/src/main/java/ru/bclib/api/tag/CommonBlockTags.java index e6b42095..6401a0d8 100644 --- a/src/main/java/ru/bclib/api/tag/CommonBlockTags.java +++ b/src/main/java/ru/bclib/api/tag/CommonBlockTags.java @@ -1,6 +1,7 @@ package ru.bclib.api.tag; import net.minecraft.tags.TagKey; +import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; public class CommonBlockTags { @@ -20,4 +21,6 @@ public class CommonBlockTags { public static final TagKey WOODEN_BARREL = TagAPI.makeCommonBlockTag("wooden_barrels"); public static final TagKey WOODEN_CHEST = TagAPI.makeCommonBlockTag("wooden_chests"); public static final TagKey WORKBENCHES = TagAPI.makeCommonBlockTag("workbench"); + + public static final TagKey MINABLE_WITH_HAMMER = TagAPI.makeCommonBlockTag("mineable/hammer"); } From c057ca3e991b855cf8459d90eeee6b8481a58a70 Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 8 Apr 2022 17:59:06 +0200 Subject: [PATCH 33/34] Fixed Disc Registry --- src/main/java/ru/bclib/registry/ItemRegistry.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/bclib/registry/ItemRegistry.java b/src/main/java/ru/bclib/registry/ItemRegistry.java index 5d46ca92..add85882 100644 --- a/src/main/java/ru/bclib/registry/ItemRegistry.java +++ b/src/main/java/ru/bclib/registry/ItemRegistry.java @@ -44,8 +44,8 @@ public class ItemRegistry extends BaseRegistry { if (!config.getBoolean("musicDiscs", itemId.getPath(), true)) { return item; } - - return register(itemId, new BaseDiscItem(power, sound, makeItemSettings().stacksTo(1))); + register(itemId, item); + return res; } public Item register(ResourceLocation itemId) { From ea999a9ba535b453958fcde16207753a51421a8a Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 8 Apr 2022 18:17:14 +0200 Subject: [PATCH 34/34] Fixed initial runtime crashes in BetterEnd --- src/main/java/ru/bclib/registry/ItemRegistry.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ru/bclib/registry/ItemRegistry.java b/src/main/java/ru/bclib/registry/ItemRegistry.java index add85882..8652b471 100644 --- a/src/main/java/ru/bclib/registry/ItemRegistry.java +++ b/src/main/java/ru/bclib/registry/ItemRegistry.java @@ -45,7 +45,7 @@ public class ItemRegistry extends BaseRegistry { return item; } register(itemId, item); - return res; + return item; } public Item register(ResourceLocation itemId) {