From dd79effe802e87337fd8b104339232e3459cff64 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Wed, 17 Nov 2021 21:28:26 +0000 Subject: [PATCH] Finish rubber trees. --- RebornCore/build.gradle | 1 + RebornCore/src/main/resources/fabric.mod.json | 2 +- .../main/resources/reborncore.accesswidener | 2 +- build.gradle | 4 + .../techreborn/world/RubberTreeFeature.java | 108 ------------------ .../world/RubberTreeSpikeDecorator.java | 56 +++++---- .../java/techreborn/world/WorldGenerator.java | 28 ++++- src/main/resources/fabric.mod.json | 3 +- src/main/resources/techreborn.accesswidener | 3 + 9 files changed, 67 insertions(+), 140 deletions(-) delete mode 100644 src/main/java/techreborn/world/RubberTreeFeature.java create mode 100644 src/main/resources/techreborn.accesswidener diff --git a/RebornCore/build.gradle b/RebornCore/build.gradle index 5da5c6476..13fa44099 100644 --- a/RebornCore/build.gradle +++ b/RebornCore/build.gradle @@ -5,6 +5,7 @@ group = 'RebornCore' loom { accessWidenerPath = file("src/main/resources/reborncore.accesswidener") } + def ENV = System.getenv() curseforge { diff --git a/RebornCore/src/main/resources/fabric.mod.json b/RebornCore/src/main/resources/fabric.mod.json index ec9d91017..b5624d1f9 100644 --- a/RebornCore/src/main/resources/fabric.mod.json +++ b/RebornCore/src/main/resources/fabric.mod.json @@ -25,7 +25,7 @@ "reborncore.common.mixins.json" ], "depends": { - "fabricloader": ">=0.6.3", + "fabricloader": ">=0.12.0", "fabric": ">=0.40.0", "team_reborn_energy": ">=2.0.0-beta1", "fabric-biome-api-v1": ">=3.0.0" diff --git a/RebornCore/src/main/resources/reborncore.accesswidener b/RebornCore/src/main/resources/reborncore.accesswidener index ef3efa371..8e837a15a 100644 --- a/RebornCore/src/main/resources/reborncore.accesswidener +++ b/RebornCore/src/main/resources/reborncore.accesswidener @@ -1,4 +1,4 @@ -accessWidener v1 named +accessWidener v2 named accessible method net/minecraft/recipe/ShapedRecipe readSymbols (Lcom/google/gson/JsonObject;)Ljava/util/Map; accessible method net/minecraft/recipe/ShapedRecipe getPattern (Lcom/google/gson/JsonArray;)[Ljava/lang/String; diff --git a/build.gradle b/build.gradle index 3284e65a6..47f25259e 100644 --- a/build.gradle +++ b/build.gradle @@ -137,6 +137,10 @@ allprojects { } } +loom { + accessWidenerPath = file("src/main/resources/techreborn.accesswidener") +} + sourceSets { gametest { compileClasspath += sourceSets.main.compileClasspath diff --git a/src/main/java/techreborn/world/RubberTreeFeature.java b/src/main/java/techreborn/world/RubberTreeFeature.java deleted file mode 100644 index f578d0937..000000000 --- a/src/main/java/techreborn/world/RubberTreeFeature.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * This file is part of TechReborn, licensed under the MIT License (MIT). - * - * Copyright (c) 2020 TechReborn - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package techreborn.world; - -import com.mojang.serialization.Codec; -import com.mojang.serialization.codecs.RecordCodecBuilder; -import net.minecraft.block.BlockState; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.intprovider.IntProvider; -import net.minecraft.world.TestableWorld; -import net.minecraft.world.gen.feature.TreeFeature; -import net.minecraft.world.gen.feature.TreeFeatureConfig; -import net.minecraft.world.gen.foliage.BlobFoliagePlacer; -import net.minecraft.world.gen.foliage.FoliagePlacerType; - -import java.util.Random; -import java.util.function.BiConsumer; - -/** - * @author drcrazy - */ -public class RubberTreeFeature extends TreeFeature { - - public RubberTreeFeature(Codec codec) { - super(codec); - } - - public static class FoliagePlacer extends BlobFoliagePlacer { - public static final Codec CODEC = RecordCodecBuilder.create((instance) -> createCodec(instance) - .and( - Codec.INT.fieldOf("spireHeight").forGetter(FoliagePlacer::getSpireHeight) - ) - .and( - BlockState.CODEC.fieldOf("spireBlockState").forGetter(FoliagePlacer::getSpireBlockState) - ) - .apply(instance, FoliagePlacer::new)); - - private final int spireHeight; - private final BlockState spireBlockState; - - public FoliagePlacer(IntProvider radius, IntProvider offset, int height, int spireHeight, BlockState spireBlockState) { - super(radius, offset, height); - this.spireHeight = spireHeight; - this.spireBlockState = spireBlockState; - } - - @Override - protected void generate(TestableWorld world, BiConsumer replacer, Random random, TreeFeatureConfig config, int trunkHeight, TreeNode treeNode, int foliageHeight, int radius, int offset) { - super.generate(world, replacer, random, config, trunkHeight, treeNode, foliageHeight, radius, offset); - - spawnSpike(world, treeNode.getCenter(), replacer); - } - - private void spawnSpike(TestableWorld world, BlockPos pos, BiConsumer replacer) { - final int startScan = pos.getY(); - BlockPos topPos = null; - - //Limit the scan to 15 blocks - while (topPos == null && pos.getY() - startScan < 15) { - pos = pos.up(); - if (world.testBlockState(pos, BlockState::isAir)) { - topPos = pos; - } - } - - if (topPos == null) return; - - for (int i = 0; i < spireHeight; i++) { - replacer.accept(pos.up(i), spireBlockState); - } - } - - @Override - protected FoliagePlacerType getType() { - return null; - } - - public int getSpireHeight() { - return spireHeight; - } - - public BlockState getSpireBlockState() { - return spireBlockState; - } - } -} diff --git a/src/main/java/techreborn/world/RubberTreeSpikeDecorator.java b/src/main/java/techreborn/world/RubberTreeSpikeDecorator.java index 020d21ceb..5ff558227 100644 --- a/src/main/java/techreborn/world/RubberTreeSpikeDecorator.java +++ b/src/main/java/techreborn/world/RubberTreeSpikeDecorator.java @@ -1,51 +1,61 @@ package techreborn.world; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.block.BlockState; +import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.registry.Registry; import net.minecraft.world.TestableWorld; +import net.minecraft.world.gen.stateprovider.BlockStateProvider; import net.minecraft.world.gen.treedecorator.TreeDecorator; import net.minecraft.world.gen.treedecorator.TreeDecoratorType; +import java.util.Comparator; import java.util.List; import java.util.Random; import java.util.function.BiConsumer; public class RubberTreeSpikeDecorator extends TreeDecorator { - private final int spireHeight; - private final BlockState spireBlockState; + public static final Codec CODEC = RecordCodecBuilder.create(instance -> + instance.group( + Codec.INT.fieldOf("spire_height").forGetter(RubberTreeSpikeDecorator::getSpireHeight), + BlockStateProvider.TYPE_CODEC.fieldOf("provider").forGetter(RubberTreeSpikeDecorator::getProvider) + ).apply(instance, RubberTreeSpikeDecorator::new) + ); - public RubberTreeSpikeDecorator(int spireHeight, BlockState spireBlockState) { + public static final TreeDecoratorType RUBBER_TREE_SPIKE = Registry.register(Registry.TREE_DECORATOR_TYPE, new Identifier("techreborn", "rubber_tree_spike"), new TreeDecoratorType<>(CODEC)); + + private final int spireHeight; + private final BlockStateProvider provider; + + public RubberTreeSpikeDecorator(int spireHeight, BlockStateProvider spireBlockState) { this.spireHeight = spireHeight; - this.spireBlockState = spireBlockState; + this.provider = spireBlockState; } @Override protected TreeDecoratorType getType() { - // TODO 1.18 really needs fabric api help here. - throw new UnsupportedOperationException(); + return RUBBER_TREE_SPIKE; } @Override public void generate(TestableWorld world, BiConsumer replacer, Random random, List logPositions, List leavesPositions) { - System.out.println("hi"); + logPositions.stream() + .max(Comparator.comparingInt(BlockPos::getY)) + .ifPresent(blockPos -> { + for (int i = 0; i < spireHeight; i++) { + BlockPos sPos = blockPos.up(i); + replacer.accept(sPos, provider.getBlockState(random, sPos)); + } + }); } - private void generateSpike(TestableWorld world, BlockPos pos, BiConsumer replacer) { - final int startScan = pos.getY(); - BlockPos topPos = null; + public int getSpireHeight() { + return spireHeight; + } - //Limit the scan to 15 blocks - while (topPos == null && pos.getY() - startScan < 15) { - pos = pos.up(); - if (world.testBlockState(pos, BlockState::isAir)) { - topPos = pos; - } - } - - if (topPos == null) return; - - for (int i = 0; i < spireHeight; i++) { - replacer.accept(pos.up(i), spireBlockState); - } + public BlockStateProvider getProvider() { + return provider; } } diff --git a/src/main/java/techreborn/world/WorldGenerator.java b/src/main/java/techreborn/world/WorldGenerator.java index dab79f325..2c79e8703 100644 --- a/src/main/java/techreborn/world/WorldGenerator.java +++ b/src/main/java/techreborn/world/WorldGenerator.java @@ -25,7 +25,10 @@ package techreborn.world; import net.fabricmc.fabric.api.biome.v1.*; +import net.minecraft.block.BlockState; import net.minecraft.util.Identifier; +import net.minecraft.util.collection.DataPool; +import net.minecraft.util.math.Direction; import net.minecraft.util.math.intprovider.ConstantIntProvider; import net.minecraft.util.registry.BuiltinRegistries; import net.minecraft.util.registry.Registry; @@ -39,7 +42,9 @@ import net.minecraft.world.gen.feature.*; import net.minecraft.world.gen.feature.size.TwoLayersFeatureSize; import net.minecraft.world.gen.foliage.BlobFoliagePlacer; import net.minecraft.world.gen.stateprovider.BlockStateProvider; +import net.minecraft.world.gen.stateprovider.WeightedBlockStateProvider; import net.minecraft.world.gen.trunk.StraightTrunkPlacer; +import techreborn.blocks.misc.BlockRubberLog; import techreborn.init.TRContent; import java.util.Arrays; @@ -92,13 +97,13 @@ public class WorldGenerator { RUBBER_TREE_PATCH_FEATURE = Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, patchId, Feature.RANDOM_PATCH.configure( - ConfiguredFeatures.createRandomPatchFeatureConfig(10, RUBBER_TREE_PLACED_FEATURE) + ConfiguredFeatures.createRandomPatchFeatureConfig(6, RUBBER_TREE_PLACED_FEATURE) ) ); RUBBER_TREE_PATCH_PLACED_FEATURE = Registry.register(BuiltinRegistries.PLACED_FEATURE, patchId, RUBBER_TREE_PATCH_FEATURE.withPlacement( - RarityFilterPlacementModifier.of(5), + RarityFilterPlacementModifier.of(3), SquarePlacementModifier.of(), PlacedFeatures.MOTION_BLOCKING_HEIGHTMAP, BiomePlacementModifier.of() @@ -113,10 +118,20 @@ public class WorldGenerator { biomeModificationContext.getGenerationSettings().addFeature(GenerationStep.Feature.VEGETAL_DECORATION, registryKey); } - private static TreeFeatureConfig.Builder rubber() { + final DataPool.Builder logDataPool = DataPool.builder() + .add(TRContent.RUBBER_LOG.getDefaultState(), 6); + + Arrays.stream(Direction.values()) + .filter(direction -> direction.getAxis().isHorizontal()) + .map(direction -> TRContent.RUBBER_LOG.getDefaultState() + .with(BlockRubberLog.HAS_SAP, true) + .with(BlockRubberLog.SAP_SIDE, direction) + ) + .forEach(state -> logDataPool.add(state, 1)); + return new TreeFeatureConfig.Builder( - BlockStateProvider.of(TRContent.RUBBER_LOG.getDefaultState()), // TODO 1.18 spawn with rubber + new WeightedBlockStateProvider(logDataPool), new StraightTrunkPlacer(6, 3, 0), BlockStateProvider.of(TRContent.RUBBER_LEAVES.getDefaultState()), new BlobFoliagePlacer( @@ -128,8 +143,9 @@ public class WorldGenerator { 1, 0, 1 + )) + .decorators(List.of( + new RubberTreeSpikeDecorator(4, BlockStateProvider.of(TRContent.RUBBER_LEAVES.getDefaultState())) )); - // TODO 1.18 -// .decorators(List.of(new RubberTreeSpikeDecorator(4, TRContent.RUBBER_LEAVES.getDefaultState()))); } } \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 4bef37f19..d4647abd9 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -33,12 +33,13 @@ ] }, "depends": { - "fabricloader": ">=0.11.6", + "fabricloader": ">=0.12.0", "fabric": ">=0.40.0", "reborncore": "*", "team_reborn_energy": ">=2.0.0-beta1", "fabric-biome-api-v1": ">=3.0.0" }, + "accessWidener": "techreborn.accesswidener", "authors": [ "Team Reborn", "modmuss50", diff --git a/src/main/resources/techreborn.accesswidener b/src/main/resources/techreborn.accesswidener new file mode 100644 index 000000000..2e7b9bd8a --- /dev/null +++ b/src/main/resources/techreborn.accesswidener @@ -0,0 +1,3 @@ +accessWidener v2 named + +accessible method net/minecraft/world/gen/treedecorator/TreeDecoratorType (Lcom/mojang/serialization/Codec;)V