Finish rubber trees.

This commit is contained in:
modmuss50 2021-11-17 21:28:26 +00:00
parent b98667e11f
commit dd79effe80
9 changed files with 67 additions and 140 deletions

View file

@ -5,6 +5,7 @@ group = 'RebornCore'
loom {
accessWidenerPath = file("src/main/resources/reborncore.accesswidener")
}
def ENV = System.getenv()
curseforge {

View file

@ -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"

View file

@ -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;

View file

@ -137,6 +137,10 @@ allprojects {
}
}
loom {
accessWidenerPath = file("src/main/resources/techreborn.accesswidener")
}
sourceSets {
gametest {
compileClasspath += sourceSets.main.compileClasspath

View file

@ -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<TreeFeatureConfig> codec) {
super(codec);
}
public static class FoliagePlacer extends BlobFoliagePlacer {
public static final Codec<FoliagePlacer> 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<BlockPos, BlockState> 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<BlockPos, BlockState> 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;
}
}
}

View file

@ -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<RubberTreeSpikeDecorator> 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<RubberTreeSpikeDecorator> 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<BlockPos, BlockState> replacer, Random random, List<BlockPos> logPositions, List<BlockPos> leavesPositions) {
System.out.println("hi");
}
private void generateSpike(TestableWorld world, BlockPos pos, BiConsumer<BlockPos, BlockState> 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;
logPositions.stream()
.max(Comparator.comparingInt(BlockPos::getY))
.ifPresent(blockPos -> {
for (int i = 0; i < spireHeight; i++) {
replacer.accept(pos.up(i), spireBlockState);
}
BlockPos sPos = blockPos.up(i);
replacer.accept(sPos, provider.getBlockState(random, sPos));
}
});
}
public int getSpireHeight() {
return spireHeight;
}
public BlockStateProvider getProvider() {
return provider;
}
}

View file

@ -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<BlockState> logDataPool = DataPool.<BlockState>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())));
}
}

View file

@ -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",

View file

@ -0,0 +1,3 @@
accessWidener v2 named
accessible method net/minecraft/world/gen/treedecorator/TreeDecoratorType <init> (Lcom/mojang/serialization/Codec;)V