Fix rubber trees #betaBuild

This commit is contained in:
modmuss50 2019-11-22 21:05:40 +00:00
parent 8d1c723f4e
commit 6cb919b9a2
6 changed files with 132 additions and 170 deletions

View file

@ -53,7 +53,7 @@ repositories {
}
}
version = "3.0.22"
version = "3.0.23"
configurations {
shade

View file

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

View file

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

View file

@ -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<BranchedTreeFeatureConfig, ?> createTreeFeature(Random random) {
return null; //new RubberTreeFeature(DefaultFeatureConfig::deserialize, true);
return WorldGenerator.RUBBER_TREE.configure(WorldGenerator.RUBBER_TREE_CONFIG);
}
}

View file

@ -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<DefaultFeatureConfig> {
//
// // TODO: Configs
// private int treeBaseHeight = 5;
// private int sapRarity = 10;
// private int spireHeight = 4;
//
//
// public RubberTreeFeature(Function<Dynamic<?>, ? extends DefaultFeatureConfig> featureConfig, boolean notify) {
// super(featureConfig, notify);
// }
//
// @Override
// protected boolean generate(Set<BlockPos> 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<BlockPos> set, Set<BlockPos> set2, BlockBox blockBox, DefaultFeatureConfig treeFeatureConfig) {
// return false;
// }
//
// @Override
// public boolean generate(IWorld world, ChunkGenerator<? extends ChunkGeneratorConfig> 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<Dynamic<?>, ? extends BranchedTreeFeatureConfig> configFactory) {
super(configFactory);
}
@Override
public boolean method_23402(ModifiableTestableWorld world, Random random, BlockPos blockPos, Set<BlockPos> set, Set<BlockPos> 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());
}
}
}

View file

@ -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<IBlockState> IS_ENDSTONE = (state) -> {
// return state != null && (state.getBlock() == Blocks.END_STONE);
// };
public static Feature<BranchedTreeFeatureConfig> RUBBER_TREE;
public static BranchedTreeFeatureConfig RUBBER_TREE_CONFIG;
private static List<Biome> 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))
)
);
}
}
}