From 6cb919b9a292f4ad13ee3f7b481029f5790d125a Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Fri, 22 Nov 2019 21:05:40 +0000 Subject: [PATCH] Fix rubber trees #betaBuild --- build.gradle | 2 +- .../java/techreborn/TechRebornClient.java | 2 + .../blocks/misc/BlockRubberLeaves.java | 2 +- .../world/RubberSaplingGenerator.java | 4 +- .../techreborn/world/RubberTreeFeature.java | 236 ++++++------------ .../java/techreborn/world/WorldGenerator.java | 56 ++++- 6 files changed, 132 insertions(+), 170 deletions(-) diff --git a/build.gradle b/build.gradle index 9e31b6bd5..0a94ea22b 100644 --- a/build.gradle +++ b/build.gradle @@ -53,7 +53,7 @@ repositories { } } -version = "3.0.22" +version = "3.0.23" configurations { shade diff --git a/src/main/java/techreborn/TechRebornClient.java b/src/main/java/techreborn/TechRebornClient.java index 51cebab16..a1e000fd3 100644 --- a/src/main/java/techreborn/TechRebornClient.java +++ b/src/main/java/techreborn/TechRebornClient.java @@ -139,6 +139,8 @@ public class TechRebornClient implements ClientModInitializer { BlockRenderLayerMap.INSTANCE.putBlock(TRContent.RUBBER_SAPLING, RenderLayer.getCutout()); BlockRenderLayerMap.INSTANCE.putBlock(TRContent.REINFORCED_GLASS, RenderLayer.getCutout()); + BlockRenderLayerMap.INSTANCE.putBlock(TRContent.RUBBER_LEAVES, RenderLayer.getCutoutMipped()); + for (ModFluids fluid : ModFluids.values()) { BlockRenderLayerMap.INSTANCE.putFluid(fluid.getFluid(), RenderLayer.getTranslucent()); BlockRenderLayerMap.INSTANCE.putFluid(fluid.getFlowingFluid(), RenderLayer.getTranslucent()); diff --git a/src/main/java/techreborn/blocks/misc/BlockRubberLeaves.java b/src/main/java/techreborn/blocks/misc/BlockRubberLeaves.java index d7c552ab3..f3cde08cb 100644 --- a/src/main/java/techreborn/blocks/misc/BlockRubberLeaves.java +++ b/src/main/java/techreborn/blocks/misc/BlockRubberLeaves.java @@ -34,7 +34,7 @@ import net.minecraft.sound.BlockSoundGroup; public class BlockRubberLeaves extends LeavesBlock { public BlockRubberLeaves() { - super(FabricBlockSettings.of(Material.LEAVES).hardness(0.2F).ticksRandomly().sounds(BlockSoundGroup.GRASS).build()); + super(FabricBlockSettings.of(Material.LEAVES).hardness(0.2F).ticksRandomly().sounds(BlockSoundGroup.GRASS).build().nonOpaque()); ((FireBlock) Blocks.FIRE).registerFlammableBlock(this, 30, 60); } diff --git a/src/main/java/techreborn/world/RubberSaplingGenerator.java b/src/main/java/techreborn/world/RubberSaplingGenerator.java index 43fef65b6..19f57bf71 100644 --- a/src/main/java/techreborn/world/RubberSaplingGenerator.java +++ b/src/main/java/techreborn/world/RubberSaplingGenerator.java @@ -25,8 +25,10 @@ package techreborn.world; import net.minecraft.block.sapling.SaplingGenerator; +import net.minecraft.world.biome.DefaultBiomeFeatures; import net.minecraft.world.gen.feature.BranchedTreeFeatureConfig; import net.minecraft.world.gen.feature.ConfiguredFeature; +import net.minecraft.world.gen.feature.DefaultFeatureConfig; import javax.annotation.Nullable; import java.util.Random; @@ -36,7 +38,7 @@ public class RubberSaplingGenerator extends SaplingGenerator { @Nullable @Override protected ConfiguredFeature createTreeFeature(Random random) { - return null; //new RubberTreeFeature(DefaultFeatureConfig::deserialize, true); + return WorldGenerator.RUBBER_TREE.configure(WorldGenerator.RUBBER_TREE_CONFIG); } } diff --git a/src/main/java/techreborn/world/RubberTreeFeature.java b/src/main/java/techreborn/world/RubberTreeFeature.java index a982fb4bb..527bd128d 100644 --- a/src/main/java/techreborn/world/RubberTreeFeature.java +++ b/src/main/java/techreborn/world/RubberTreeFeature.java @@ -1,157 +1,79 @@ -///* -// * This file is part of TechReborn, licensed under the MIT License (MIT). -// * -// * Copyright (c) 2018 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 java.util.Random; -//import java.util.Set; -//import java.util.function.Function; -// -//import com.mojang.datafixers.Dynamic; -// -//import net.minecraft.block.BlockState; -//import net.minecraft.util.math.BlockBox; -//import net.minecraft.util.math.BlockPos; -//import net.minecraft.util.math.Direction; -//import net.minecraft.world.IWorld; -//import net.minecraft.world.ModifiableTestableWorld; -//import net.minecraft.world.gen.chunk.ChunkGenerator; -//import net.minecraft.world.gen.chunk.ChunkGeneratorConfig; -//import net.minecraft.world.gen.feature.AbstractTreeFeature; -//import net.minecraft.world.gen.feature.DefaultFeatureConfig; -//import techreborn.blocks.misc.BlockRubberLog; -//import techreborn.init.TRContent; -// -///** -// * @author drcrazy -// * -// */ -//public class RubberTreeFeature extends AbstractTreeFeature { -// -// // TODO: Configs -// private int treeBaseHeight = 5; -// private int sapRarity = 10; -// private int spireHeight = 4; -// -// -// public RubberTreeFeature(Function, ? extends DefaultFeatureConfig> featureConfig, boolean notify) { -// super(featureConfig, notify); -// } -// -// @Override -// protected boolean generate(Set changedBlocks, ModifiableTestableWorld worldIn, Random rand, -// BlockPos saplingPos, BlockBox mutableBoundingBox) { -// int treeHeight = rand.nextInt(5) + treeBaseHeight; -// int baseY = saplingPos.getY(); -// int baseX = saplingPos.getX(); -// int baseZ = saplingPos.getZ(); -// if (baseY <= 1 && baseY + treeHeight + spireHeight + 1 >= 256) { -// return false; -// } -// -// if (!isDirtOrGrass(worldIn, saplingPos.down())) { -// return false; -// } -// -// int yOffset; -// int xOffset; -// int zOffset; -// for (yOffset = baseY; yOffset <= baseY + 1 + treeHeight; ++yOffset) { -// byte radius = 1; -// if (yOffset == baseY) { -// radius = 0; -// } -// if (yOffset >= baseY + 1 + treeHeight - 2) { -// radius = 2; -// } -// -// BlockPos.Mutable blockpos$mutable = new BlockPos.Mutable(); -// for (xOffset = baseX - radius; xOffset <= baseX + radius; ++xOffset) { -// for (zOffset = baseZ - radius; zOffset <= baseZ + radius; ++zOffset) { -// if (!isAirOrLeaves(worldIn, blockpos$mutable.set(xOffset, yOffset, zOffset))) { -// return false; -// } -// } -// } -// } -// -// // Ok, we are cleared for take off! -// this.setToDirt(worldIn, saplingPos.down()); -// -// // Leaves -// BlockState leafState = TRContent.RUBBER_LEAVES.getDefaultState(); -// for (yOffset = baseY - 3 + treeHeight; yOffset <= baseY + treeHeight; ++yOffset) { -// int var12 = yOffset - (baseY + treeHeight), center = 1 - var12 / 2; -// for (xOffset = baseX - center; xOffset <= baseX + center; ++xOffset) { -// int xPos = xOffset - baseX, t = xPos >> 15; -// xPos = (xPos + t) ^ t; -// for (zOffset = baseZ - center; zOffset <= baseZ + center; ++zOffset) { -// int zPos = zOffset - baseZ; -// zPos = (zPos + (t = zPos >> 31)) ^ t; -// if ((xPos != center | zPos != center) || rand.nextInt(2) != 0 && var12 != 0) { -// BlockPos leafPos = new BlockPos(xOffset, yOffset, zOffset); -// if (isAirOrLeaves(worldIn, leafPos) || isReplaceablePlant(worldIn, leafPos)) { -// this.setBlockState(changedBlocks, worldIn, leafPos, leafState, mutableBoundingBox); -// } -// } -// } -// } -// } -// -// // Trunk -// BlockPos currentLogPos = null; -// BlockState logState = TRContent.RUBBER_LOG.getDefaultState(); -// for (yOffset = 0; yOffset < treeHeight; ++yOffset) { -// currentLogPos = saplingPos.up(yOffset); -// if (!isAirOrLeaves(worldIn, currentLogPos)) { -// continue; -// } -// if (rand.nextInt(sapRarity) == 0) { -// logState = logState.with(BlockRubberLog.HAS_SAP, true).with(BlockRubberLog.SAP_SIDE, -// Direction.fromHorizontal(rand.nextInt(4))); -// } -// this.setBlockState(changedBlocks, worldIn, currentLogPos, logState, mutableBoundingBox); -// } -// -// // Spire -// if (currentLogPos != null) { -// for (int i = 0; i < spireHeight; i++) { -// BlockPos blockpos = currentLogPos.up(i); -// this.setBlockState(changedBlocks, worldIn, blockpos, leafState, mutableBoundingBox); -// } -// } -// -// return true; -// } -// -// @Override -// protected boolean generate(ModifiableTestableWorld modifiableTestableWorld, Random random, BlockPos blockPos, Set set, Set set2, BlockBox blockBox, DefaultFeatureConfig treeFeatureConfig) { -// return false; -// } -// -// @Override -// public boolean generate(IWorld world, ChunkGenerator generator, Random random, BlockPos pos, DefaultFeatureConfig config) { -// return false; -// } -//} +/* + * This file is part of TechReborn, licensed under the MIT License (MIT). + * + * Copyright (c) 2018 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.datafixers.Dynamic; +import net.minecraft.block.BlockState; +import net.minecraft.util.math.BlockBox; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.ModifiableTestableWorld; +import net.minecraft.world.World; +import net.minecraft.world.gen.feature.BranchedTreeFeatureConfig; +import net.minecraft.world.gen.feature.OakTreeFeature; +import techreborn.init.TRContent; + +import java.util.Random; +import java.util.Set; +import java.util.function.Function; +import java.util.function.Predicate; + +/** + * @author drcrazy + * + */ +public class RubberTreeFeature extends OakTreeFeature { + + public RubberTreeFeature(Function, ? extends BranchedTreeFeatureConfig> configFactory) { + super(configFactory); + } + + @Override + public boolean method_23402(ModifiableTestableWorld world, Random random, BlockPos blockPos, Set set, Set set2, BlockBox blockBox, BranchedTreeFeatureConfig branchedTreeFeatureConfig) { + if(super.method_23402(world, random, blockPos, set, set2, blockBox, branchedTreeFeatureConfig)) { + spawnSpike(world, blockPos); + return true; + } + return false; + } + + private void spawnSpike(ModifiableTestableWorld world, BlockPos pos) { + 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 < 3; i++) { + setBlockState(world, pos.up(i), TRContent.RUBBER_LEAVES.getDefaultState()); + } + } +} diff --git a/src/main/java/techreborn/world/WorldGenerator.java b/src/main/java/techreborn/world/WorldGenerator.java index 9fc880117..0499b8b52 100644 --- a/src/main/java/techreborn/world/WorldGenerator.java +++ b/src/main/java/techreborn/world/WorldGenerator.java @@ -26,6 +26,8 @@ package techreborn.world; import net.fabricmc.fabric.api.event.registry.RegistryEntryAddedCallback; import net.minecraft.block.Blocks; +import net.minecraft.util.Identifier; +import net.minecraft.util.math.Direction; import net.minecraft.util.registry.Registry; import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome.Category; @@ -33,16 +35,20 @@ import net.minecraft.world.gen.GenerationStep; import net.minecraft.world.gen.decorator.CountExtraChanceDecoratorConfig; import net.minecraft.world.gen.decorator.Decorator; import net.minecraft.world.gen.decorator.RangeDecoratorConfig; -import net.minecraft.world.gen.feature.DefaultFeatureConfig; +import net.minecraft.world.gen.feature.BranchedTreeFeatureConfig; import net.minecraft.world.gen.feature.Feature; -import net.minecraft.world.gen.feature.FeatureConfig; import net.minecraft.world.gen.feature.OreFeatureConfig; import net.minecraft.world.gen.feature.OreFeatureConfig.Target; +import net.minecraft.world.gen.foliage.BlobFoliagePlacer; +import net.minecraft.world.gen.stateprovider.SimpleStateProvider; +import net.minecraft.world.gen.stateprovider.WeightedStateProvider; import reborncore.common.world.CustomOreFeature; import reborncore.common.world.CustomOreFeatureConfig; +import techreborn.blocks.misc.BlockRubberLog; import techreborn.init.TRContent; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** @@ -51,13 +57,15 @@ import java.util.List; */ public class WorldGenerator { -// public static final Predicate IS_ENDSTONE = (state) -> { -// return state != null && (state.getBlock() == Blocks.END_STONE); -// }; + public static Feature RUBBER_TREE; + + public static BranchedTreeFeatureConfig RUBBER_TREE_CONFIG; private static List checkedBiomes = new ArrayList<>(); public static void initBiomeFeatures() { + setupTrees(); + for (Biome biome : Registry.BIOME) { addToBiome(biome); } @@ -66,6 +74,32 @@ public class WorldGenerator { RegistryEntryAddedCallback.event(Registry.BIOME).register((i, identifier, biome) -> addToBiome(biome)); } + private static void setupTrees() { + RUBBER_TREE = Registry.register(Registry.FEATURE, new Identifier("techreborn:rubber_tree"), new RubberTreeFeature(BranchedTreeFeatureConfig::method_23426)); + + WeightedStateProvider logProvider = new WeightedStateProvider(); + logProvider.addState(TRContent.RUBBER_LOG.getDefaultState(), 10); + + 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 -> logProvider.addState(state, 1)); + + RUBBER_TREE_CONFIG = new BranchedTreeFeatureConfig.Builder( + logProvider, + new SimpleStateProvider(TRContent.RUBBER_LEAVES.getDefaultState()), + new BlobFoliagePlacer(2, 0)) + .method_23428(6) //Base height + .method_23430(2) + .method_23437(3) + .method_23427() + .method_23431(); + + } + private static void addToBiome(Biome biome){ if(checkedBiomes.contains(biome)){ //Just to be sure we dont add the stuff twice to the same biome @@ -94,11 +128,13 @@ public class WorldGenerator { addOre(biome, OreFeatureConfig.Target.NATURAL_STONE, TRContent.Ores.SILVER); addOre(biome, OreFeatureConfig.Target.NATURAL_STONE, TRContent.Ores.TIN); - if (biome.getCategory() == Category.FOREST || biome.getCategory() == Category.TAIGA) { -// biome.addFeature(GenerationStep.Feature.VEGETAL_DECORATION, -// Biome.configureFeature(new RubberTreeFeature(DefaultFeatureConfig::deserialize, false), -// FeatureConfig.DEFAULT, Decorator.COUNT_EXTRA_HEIGHTMAP, -// new CountExtraChanceDecoratorConfig(1, 0.1F, 1))); + if (biome.getCategory() == Category.FOREST || biome.getCategory() == Category.TAIGA || biome.getCategory() == Category.SWAMP) { + biome.addFeature(GenerationStep.Feature.VEGETAL_DECORATION, + RUBBER_TREE.configure(RUBBER_TREE_CONFIG) + .createDecoratedFeature(Decorator.COUNT_EXTRA_HEIGHTMAP + .configure(new CountExtraChanceDecoratorConfig(biome.getCategory() == Category.SWAMP ? 2 : 1, 0.1F, 1)) + ) + ); } } }