From 5512e668dac76761b0a1b348ff18b2b97c219054 Mon Sep 17 00:00:00 2001 From: Motschen Date: Wed, 12 Aug 2020 20:37:34 +0200 Subject: [PATCH] Update to 1.16.2 Refactor ore generation for 1.16.2 --- build.gradle | 2 +- gradle.properties | 12 +++--- .../motschen/decorative/DecorativeMain.java | 25 +---------- .../motschen/decorative/OreFeatures.java | 17 ++++++++ .../decorative/item/BathTireItem.java | 3 +- .../mixin/DefaultBiomeFeaturesMixin.java | 18 ++++++++ .../decorative/world/RockyAsphalt.java | 41 ------------------- src/main/resources/decorative.mixins.json | 11 +++++ src/main/resources/fabric.mod.json | 6 ++- 9 files changed, 62 insertions(+), 73 deletions(-) create mode 100644 src/main/java/eu/midnightdust/motschen/decorative/OreFeatures.java create mode 100644 src/main/java/eu/midnightdust/motschen/decorative/mixin/DefaultBiomeFeaturesMixin.java delete mode 100644 src/main/java/eu/midnightdust/motschen/decorative/world/RockyAsphalt.java create mode 100644 src/main/resources/decorative.mixins.json diff --git a/build.gradle b/build.gradle index a4a15f4..9d8a652 100644 --- a/build.gradle +++ b/build.gradle @@ -27,7 +27,7 @@ dependencies { // Fabric API. This is technically optional, but you probably want it anyway. modCompile "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - modCompile("vazkii.patchouli:Patchouli_1.16-fabric:${project.patchouli_version}") + modCompile("vazkii.patchouli:Patchouli:${project.patchouli_version}") // PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs. // You may need to force-disable transitiveness on them. } diff --git a/gradle.properties b/gradle.properties index bcefbf5..0d096c5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,16 +3,16 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use - minecraft_version=1.16.1 - yarn_mappings=1.16.1+build.7 - loader_version=0.8.8+build.202 + minecraft_version=1.16.2 + yarn_mappings=1.16.2+build.6 + loader_version=0.9.1+build.205 # Mod Properties - mod_version = 2.0.0 + mod_version = 2.0.1 maven_group = eu.midnightdust.motschen archives_base_name = decorative # Dependencies # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api - fabric_version=0.14.0+build.371-1.16 - patchouli_version=1.16-37.21-FABRIC + fabric_version=0.17.2+build.396-1.16 + patchouli_version=1.16-40-FABRIC diff --git a/src/main/java/eu/midnightdust/motschen/decorative/DecorativeMain.java b/src/main/java/eu/midnightdust/motschen/decorative/DecorativeMain.java index 2ceaa6f..188b164 100644 --- a/src/main/java/eu/midnightdust/motschen/decorative/DecorativeMain.java +++ b/src/main/java/eu/midnightdust/motschen/decorative/DecorativeMain.java @@ -90,30 +90,9 @@ public class DecorativeMain implements ModInitializer { Registry.register(Registry.ITEM, new Identifier("decorative","christmas_tree"), new BlockItem(ChristmasTree, new Item.Settings().group(DecorativeMain.IndoorGroup))); Registry.register(Registry.BLOCK, new Identifier("decorative","christmas_lights"), ChristmasLights); Registry.register(Registry.ITEM, new Identifier("decorative","christmas_lights"), new BlockItem(ChristmasLights, new Item.Settings().group(DecorativeMain.IndoorGroup))); + Lamps.init(); DoubleLamps.init(); - eu.midnightdust.motschen.decorative.world.RockyAsphalt.initBiomeFeatures(); - } - public enum Ores implements ItemConvertible { - RockyAsphalt(7, 20, 14, 200); - - public final String name; - public final int veinSize; - public final int veinsPerChunk; - public final int minY; - public final int maxY; - - Ores(int veinSize, int veinsPerChunk, int minY, int maxY) { - name = this.toString().toLowerCase(Locale.ROOT); - this.veinSize = veinSize; - this.veinsPerChunk = veinsPerChunk; - this.minY = minY; - this.maxY = maxY; - } - - @Override - public Item asItem() { - return RockyAsphalt.asItem(); - } + OreFeatures.init(); } } diff --git a/src/main/java/eu/midnightdust/motschen/decorative/OreFeatures.java b/src/main/java/eu/midnightdust/motschen/decorative/OreFeatures.java new file mode 100644 index 0000000..304e049 --- /dev/null +++ b/src/main/java/eu/midnightdust/motschen/decorative/OreFeatures.java @@ -0,0 +1,17 @@ +package eu.midnightdust.motschen.decorative; + +import net.minecraft.util.Identifier; +import net.minecraft.util.registry.BuiltinRegistries; +import net.minecraft.util.registry.Registry; +import net.minecraft.world.gen.feature.ConfiguredFeature; +import net.minecraft.world.gen.feature.Feature; +import net.minecraft.world.gen.feature.OreFeatureConfig; + +public class OreFeatures { + public static final ConfiguredFeature ROCKY_ASPHALT_FEATURE = Feature.ORE.configure(new OreFeatureConfig(OreFeatureConfig.Rules.BASE_STONE_OVERWORLD, DecorativeMain.RockyAsphalt.getDefaultState(), 7)).method_30377(200).spreadHorizontally().repeat(20); + + public static void init() { + Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new Identifier(DecorativeMain.MOD_ID, "rocky_asphalt"), ROCKY_ASPHALT_FEATURE); + + } +} diff --git a/src/main/java/eu/midnightdust/motschen/decorative/item/BathTireItem.java b/src/main/java/eu/midnightdust/motschen/decorative/item/BathTireItem.java index 4d24291..16e8498 100644 --- a/src/main/java/eu/midnightdust/motschen/decorative/item/BathTireItem.java +++ b/src/main/java/eu/midnightdust/motschen/decorative/item/BathTireItem.java @@ -9,6 +9,7 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.world.ServerWorld; import net.minecraft.stat.Stats; import net.minecraft.util.Hand; import net.minecraft.util.TypedActionResult; @@ -42,7 +43,7 @@ public class BathTireItem extends Item { return TypedActionResult.pass(itemStack); } else if (world.canPlayerModifyAt(user, blockPos) && user.canPlaceOn(blockPos, blockHitResult.getSide(), itemStack)) { EntityType entityType = this.getEntityType(itemStack.getTag()); - if (entityType.spawnFromItemStack(world, itemStack, user, blockPos.up(1), SpawnReason.SPAWN_EGG, false, false) == null) { + if (entityType.spawnFromItemStack((ServerWorld) world, itemStack, user, blockPos.up(1), SpawnReason.SPAWN_EGG, false, false) == null) { return TypedActionResult.pass(itemStack); } else { if (!user.abilities.creativeMode) { diff --git a/src/main/java/eu/midnightdust/motschen/decorative/mixin/DefaultBiomeFeaturesMixin.java b/src/main/java/eu/midnightdust/motschen/decorative/mixin/DefaultBiomeFeaturesMixin.java new file mode 100644 index 0000000..6c20262 --- /dev/null +++ b/src/main/java/eu/midnightdust/motschen/decorative/mixin/DefaultBiomeFeaturesMixin.java @@ -0,0 +1,18 @@ +package eu.midnightdust.motschen.decorative.mixin; + +import eu.midnightdust.motschen.decorative.OreFeatures; +import net.minecraft.world.biome.GenerationSettings.Builder; +import net.minecraft.world.gen.GenerationStep; +import net.minecraft.world.gen.feature.DefaultBiomeFeatures; +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; + +@Mixin(DefaultBiomeFeatures.class) +public class DefaultBiomeFeaturesMixin { + @Inject(at = @At("RETURN"), method = "addDefaultOres") + private static void addDefaultOres(Builder builder, CallbackInfo info) { + builder.feature(GenerationStep.Feature.UNDERGROUND_ORES, OreFeatures.ROCKY_ASPHALT_FEATURE); + } +} diff --git a/src/main/java/eu/midnightdust/motschen/decorative/world/RockyAsphalt.java b/src/main/java/eu/midnightdust/motschen/decorative/world/RockyAsphalt.java deleted file mode 100644 index 1f3026b..0000000 --- a/src/main/java/eu/midnightdust/motschen/decorative/world/RockyAsphalt.java +++ /dev/null @@ -1,41 +0,0 @@ -package eu.midnightdust.motschen.decorative.world; - -import eu.midnightdust.motschen.decorative.DecorativeMain; -import net.fabricmc.fabric.api.event.registry.RegistryEntryAddedCallback; -import net.minecraft.util.registry.Registry; -import net.minecraft.world.biome.Biome; -import net.minecraft.world.gen.GenerationStep; -import net.minecraft.world.gen.decorator.Decorator; -import net.minecraft.world.gen.decorator.RangeDecoratorConfig; -import net.minecraft.world.gen.feature.Feature; -import net.minecraft.world.gen.feature.OreFeatureConfig; - -import java.util.ArrayList; -import java.util.List; - -public class RockyAsphalt { - private static List checkedBiomes = new ArrayList<>(); - - public static void initBiomeFeatures() { - for (Biome biome : Registry.BIOME) { - addToBiome(biome); - } - - //Handles modded biomes - RegistryEntryAddedCallback.event(Registry.BIOME).register((i, identifier, biome) -> addToBiome(biome)); - } - private static void addToBiome(Biome biome){ - if(checkedBiomes.contains(biome)){ - //Just to be sure we dont add the stuff twice to the same biome - return; - } - checkedBiomes.add(biome); - addOre(biome, OreFeatureConfig.Target.NATURAL_STONE, DecorativeMain.Ores.RockyAsphalt); - } - - private static void addOre(Biome biome, OreFeatureConfig.Target canReplaceIn, DecorativeMain.Ores ore) { - biome.addFeature(GenerationStep.Feature.UNDERGROUND_ORES, Feature.ORE.configure( - new OreFeatureConfig(canReplaceIn, DecorativeMain.RockyAsphalt.getDefaultState(), ore.veinSize)).createDecoratedFeature(Decorator.COUNT_RANGE.configure( - new RangeDecoratorConfig(ore.veinsPerChunk, ore.minY, ore.minY, ore.maxY)))); - } -} diff --git a/src/main/resources/decorative.mixins.json b/src/main/resources/decorative.mixins.json new file mode 100644 index 0000000..420c293 --- /dev/null +++ b/src/main/resources/decorative.mixins.json @@ -0,0 +1,11 @@ +{ + "required": true, + "package": "eu.midnightdust.motschen.decorative.mixin", + "compatibilityLevel": "JAVA_8", + "mixins": [ + "DefaultBiomeFeaturesMixin" + ], + "injectors": { + "defaultRequire": 1 + } +} \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 5279b1c..19f2971 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,7 +1,7 @@ { "schemaVersion": 1, "id": "decorative", - "version": "2.0.0 - Summer 2020 Update", + "version": "${version}", "name": "Decorative", "description": "Adds many cool new decorative items with 3d models!", @@ -27,6 +27,10 @@ ] }, + "mixins": [ + "decorative.mixins.json" + ], + "depends": { "fabricloader": ">=0.7.2", "fabric": "*"