diff --git a/src/main/java/com/projecturanus/foodcraft/FoodCraftReloaded.kt b/src/main/java/com/projecturanus/foodcraft/FoodCraftReloaded.kt index d4067e0..611b8e9 100644 --- a/src/main/java/com/projecturanus/foodcraft/FoodCraftReloaded.kt +++ b/src/main/java/com/projecturanus/foodcraft/FoodCraftReloaded.kt @@ -8,7 +8,7 @@ import com.projecturanus.foodcraft.common.network.registerMessages import com.projecturanus.foodcraft.common.recipe.RecipeRegistryHandler import com.projecturanus.foodcraft.fluid.FluidCookingOil import com.projecturanus.foodcraft.fluid.FluidMilk -import com.projecturanus.foodcraft.worldgen.FruitTreeWorldGen +import com.projecturanus.foodcraft.worldgen.FruitTreeWorldGenHandler import net.minecraft.util.ResourceLocation import net.minecraftforge.common.MinecraftForge import net.minecraftforge.fluids.FluidRegistry @@ -43,7 +43,7 @@ object FoodCraftReloaded { FluidRegistry.addBucketForFluid(FluidCookingOil) registerMessages() - MinecraftForge.TERRAIN_GEN_BUS.register(FruitTreeWorldGen) + MinecraftForge.TERRAIN_GEN_BUS.register(FruitTreeWorldGenHandler) } fun registerTileEntities() { diff --git a/src/main/java/com/projecturanus/foodcraft/common/block/BlockFruitSapling.kt b/src/main/java/com/projecturanus/foodcraft/common/block/BlockFruitSapling.kt index 8835a31..dc613ad 100644 --- a/src/main/java/com/projecturanus/foodcraft/common/block/BlockFruitSapling.kt +++ b/src/main/java/com/projecturanus/foodcraft/common/block/BlockFruitSapling.kt @@ -1,5 +1,7 @@ package com.projecturanus.foodcraft.common.block +import com.projecturanus.foodcraft.common.config.FcConfig +import com.projecturanus.foodcraft.worldgen.WorldGenFruitTree import net.minecraft.block.* import net.minecraft.block.BlockSapling.STAGE import net.minecraft.block.state.BlockStateContainer @@ -11,7 +13,6 @@ import net.minecraft.item.ItemStack import net.minecraft.util.NonNullList import net.minecraft.util.math.BlockPos import net.minecraft.world.World -import net.minecraft.world.gen.feature.WorldGenTrees import net.minecraftforge.event.terraingen.TerrainGen import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly @@ -90,13 +91,14 @@ class BlockFruitSapling(val leavesState: IBlockState) : BlockBush(), IGrowable { override fun getLocalizedName(): String = I18n.format(baseTranslationKey, I18n.format(realTranslationKey)) } -fun generateTree(worldIn: World, pos: BlockPos, state: IBlockState, rand: Random, leavesState: IBlockState, isSapling: Boolean = true) { +fun generateTree(worldIn: World, pos: BlockPos, state: IBlockState, rand: Random, fruitLeafState: IBlockState, isSapling: Boolean = true) { if (!TerrainGen.saplingGrowTree(worldIn, rand, pos)) return val logState = Blocks.LOG.defaultState.withProperty(BlockOldLog.VARIANT, BlockPlanks.EnumType.JUNGLE) + val leafState = Blocks.LEAVES.defaultState.withProperty(BlockOldLeaf.VARIANT, BlockPlanks.EnumType.JUNGLE) val air = Blocks.AIR.defaultState worldIn.setBlockState(pos, air, 4) - val genTrees = WorldGenTrees(true, 4 + rand.nextInt(7), logState, leavesState, false) + val genTrees = WorldGenFruitTree(4 + rand.nextInt(7), logState, leafState, fruitLeafState, FcConfig.fruitLeavesChance) if (!genTrees.generate(worldIn, rand, pos) && isSapling) { worldIn.setBlockState(pos, state, 4) } diff --git a/src/main/java/com/projecturanus/foodcraft/common/config/FcConfig.java b/src/main/java/com/projecturanus/foodcraft/common/config/FcConfig.java index 9950c65..02f2478 100644 --- a/src/main/java/com/projecturanus/foodcraft/common/config/FcConfig.java +++ b/src/main/java/com/projecturanus/foodcraft/common/config/FcConfig.java @@ -1,7 +1,7 @@ package com.projecturanus.foodcraft.common.config; import com.projecturanus.foodcraft.FoodCraftReloadedKt; -import com.projecturanus.foodcraft.worldgen.FruitTreeWorldGen; +import com.projecturanus.foodcraft.worldgen.FruitTreeWorldGenHandler; import net.minecraftforge.common.config.Config; import net.minecraftforge.common.config.ConfigManager; import net.minecraftforge.fml.client.event.ConfigChangedEvent; @@ -19,6 +19,12 @@ public class FcConfig { @Config.SlidingOption public static double fruitTreeChance = 0.08; + @Config.Name("Fruit Leaves Generate Chance") + @Config.Comment({"Generate chance for fruit leaves on a fruit tree, default to 0.3 (lower to be more rare)"}) + @Config.RangeDouble(min = 0.0, max = 1.0) + @Config.SlidingOption + public static double fruitLeavesChance = 0.3; + @Config.Name("Fruit Tree Biomes Whitelist") @Config.Comment("Use ; to split, requires full ResourceLocation name") public static String fruitTreeBiomes = "minecraft:jungle;minecraft:mutated_jungle;minecraft:mutated_jungle_edge"; @@ -129,7 +135,7 @@ public static class ClientConfig { public static void onReloadConfig(ConfigChangedEvent event) { if (event.getModID().equals(FoodCraftReloadedKt.MODID)) { ConfigManager.sync(FoodCraftReloadedKt.MODID, Config.Type.INSTANCE); - FruitTreeWorldGen.INSTANCE.setBiomeIds(fruitTreeBiomes); + FruitTreeWorldGenHandler.INSTANCE.setBiomeIds(fruitTreeBiomes); } } } diff --git a/src/main/java/com/projecturanus/foodcraft/common/init/FCRItems.java b/src/main/java/com/projecturanus/foodcraft/common/init/FCRItems.java index 65e5c3c..b94f816 100644 --- a/src/main/java/com/projecturanus/foodcraft/common/init/FCRItems.java +++ b/src/main/java/com/projecturanus/foodcraft/common/init/FCRItems.java @@ -7,6 +7,7 @@ import net.minecraft.item.Item; import net.minecraftforge.fml.common.registry.GameRegistry; +@SuppressWarnings("unused") @GameRegistry.ObjectHolder(FoodCraftReloadedKt.MODID) public class FCRItems { public static final Item CHOPPING_BOARD = null; diff --git a/src/main/java/com/projecturanus/foodcraft/common/init/RegisterHandler.kt b/src/main/java/com/projecturanus/foodcraft/common/init/RegisterHandler.kt index 18ec215..1eb9170 100644 --- a/src/main/java/com/projecturanus/foodcraft/common/init/RegisterHandler.kt +++ b/src/main/java/com/projecturanus/foodcraft/common/init/RegisterHandler.kt @@ -140,19 +140,19 @@ object RegisterHandler { } to arrayOf("crop$capitalized", "food$capitalized", "seed$capitalized", "listAllveggie") } plantFruits.forEach { - val capitalized = it.toString().replace("_", "").capitalize() - val blockCrop = BlockCrop().apply { - setRegistryName(MODID, it.toString()) - } - PLANTS += blockCrop - blockQueue += blockCrop - itemQueue += crop(null, blockCrop) { - setRegistryName(MODID, it.toString()) - creativeTab = FcTabPlant - translationKey = "$MODID.$it" - CROPS += this@crop - blockCrop.cropItem = this - } to arrayOf("crop$capitalized", "food$capitalized", "seed$capitalized", "listAllfruit") + val capitalized = it.toString().replace("_", "").capitalize() + val blockCrop = BlockCrop().apply { + setRegistryName(MODID, it.toString()) + } + PLANTS += blockCrop + blockQueue += blockCrop + itemQueue += crop(null, blockCrop) { + setRegistryName(MODID, it.toString()) + creativeTab = FcTabPlant + translationKey = "$MODID.$it" + CROPS += this@crop + blockCrop.cropItem = this + } to arrayOf("crop$capitalized", "food$capitalized", "seed$capitalized", "listAllfruit") } saplingFruits.forEach { val fruit = food(name = it.toString(), healAmount = 1, saturation = 0.6f) {} @@ -172,10 +172,10 @@ object RegisterHandler { LEAVES += blockLeaves blockQueue += blockSapling SAPLINGS += blockSapling - itemQueue += ItemBlock(blockLeaves).apply { + itemQueue += ItemBlockTranslation(blockLeaves).apply { setRegistryName(MODID, "${it}_leaves") } to arrayOf("treeLeaves") - itemQueue += ItemBlock(blockSapling).apply { + itemQueue += ItemBlockTranslation(blockSapling).apply { setRegistryName(MODID, "${it}_sapling") } to arrayOf("treeSapling") } diff --git a/src/main/java/com/projecturanus/foodcraft/common/item/ItemBlockTranslation.kt b/src/main/java/com/projecturanus/foodcraft/common/item/ItemBlockTranslation.kt new file mode 100644 index 0000000..8ce0660 --- /dev/null +++ b/src/main/java/com/projecturanus/foodcraft/common/item/ItemBlockTranslation.kt @@ -0,0 +1,16 @@ +package com.projecturanus.foodcraft.common.item + +import net.minecraft.block.Block +import net.minecraft.item.ItemBlock +import net.minecraft.item.ItemStack +import net.minecraftforge.fml.relauncher.Side +import net.minecraftforge.fml.relauncher.SideOnly + +/** + * Delegate translation to block + */ +class ItemBlockTranslation(block: Block) : ItemBlock(block) { + @SideOnly(Side.CLIENT) + override fun getItemStackDisplayName(stack: ItemStack): String = + block.localizedName +} diff --git a/src/main/java/com/projecturanus/foodcraft/worldgen/FruitTreeWorldGen.kt b/src/main/java/com/projecturanus/foodcraft/worldgen/FruitTreeWorldGenHandler.kt similarity index 97% rename from src/main/java/com/projecturanus/foodcraft/worldgen/FruitTreeWorldGen.kt rename to src/main/java/com/projecturanus/foodcraft/worldgen/FruitTreeWorldGenHandler.kt index 2c417eb..dbc43e0 100644 --- a/src/main/java/com/projecturanus/foodcraft/worldgen/FruitTreeWorldGen.kt +++ b/src/main/java/com/projecturanus/foodcraft/worldgen/FruitTreeWorldGenHandler.kt @@ -10,7 +10,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.registry.ForgeRegistries import net.minecraftforge.registries.ForgeRegistry -object FruitTreeWorldGen { +object FruitTreeWorldGenHandler { private var biomeIdsInternal = emptyList() var biomeIds diff --git a/src/main/java/com/projecturanus/foodcraft/worldgen/WorldGenFruitTree.kt b/src/main/java/com/projecturanus/foodcraft/worldgen/WorldGenFruitTree.kt new file mode 100644 index 0000000..258ff77 --- /dev/null +++ b/src/main/java/com/projecturanus/foodcraft/worldgen/WorldGenFruitTree.kt @@ -0,0 +1,107 @@ +package com.projecturanus.foodcraft.worldgen + +import net.minecraft.block.BlockSapling +import net.minecraft.block.material.Material +import net.minecraft.block.state.IBlockState +import net.minecraft.init.Blocks +import net.minecraft.util.EnumFacing +import net.minecraft.util.math.BlockPos +import net.minecraft.util.math.BlockPos.MutableBlockPos +import net.minecraft.world.World +import net.minecraft.world.gen.feature.WorldGenAbstractTree +import java.util.* +import kotlin.math.abs + +class WorldGenFruitTree(val minTreeHeight: Int, val wood: IBlockState, val leaves: IBlockState, val fruitLeaves: IBlockState, val fruitChance: Double) : WorldGenAbstractTree(true) { + + override fun generate(worldIn: World, rand: Random, position: BlockPos): Boolean { + val i = rand.nextInt(3) + minTreeHeight + var flag = true + return if (position.y >= 1 && position.y + i + 1 <= worldIn.height) { + for (j in position.y..position.y + 1 + i) { + var k = 1 + if (j == position.y) { + k = 0 + } + if (j >= position.y + 1 + i - 2) { + k = 2 + } + val mutablePos = MutableBlockPos() + var l = position.x - k + while (l <= position.x + k && flag) { + var i1 = position.z - k + while (i1 <= position.z + k && flag) { + if (j >= 0 && j < worldIn.height) { + if (!isReplaceable(worldIn, mutablePos.setPos(l, j, i1))) { + flag = false + } + } else { + flag = false + } + ++i1 + } + ++l + } + } + if (!flag) { + false + } else { + var state = worldIn.getBlockState(position.down()) + if (state.block.canSustainPlant( + state, + worldIn, + position.down(), + EnumFacing.UP, + Blocks.SAPLING as BlockSapling + ) && position.y < worldIn.height - i - 1 + ) { + state.block.onPlantGrow(state, worldIn, position.down(), position) + for (i3 in position.y - 3 + i..position.y + i) { + val i4 = i3 - (position.y + i) + val j1 = 1 - i4 / 2 + for (k1 in position.x - j1..position.x + j1) { + val l1 = k1 - position.x + for (i2 in position.z - j1..position.z + j1) { + val j2 = i2 - position.z + if (abs(l1) != j1 || abs(j2) != j1 || rand.nextInt(2) != 0 && i4 != 0) { + val blockpos = BlockPos(k1, i3, i2) + state = worldIn.getBlockState(blockpos) + if (state.block.isAir(state, worldIn, blockpos) || state.block.isLeaves( + state, + worldIn, + blockpos + ) || state.material === Material.VINE + ) { + val leaves = if (worldIn.rand.nextDouble() <= fruitChance) { + this.leaves + } else { + this.fruitLeaves + } + setBlockAndNotifyAdequately(worldIn, blockpos, leaves) + } + } + } + } + } + for (j3 in 0 until i) { + val upN = position.up(j3) + state = worldIn.getBlockState(upN) + if (state.block.isAir(state, worldIn, upN) || state.block.isLeaves( + state, + worldIn, + upN + ) || state.material === Material.VINE + ) { + setBlockAndNotifyAdequately(worldIn, position.up(j3), this.wood) + } + } + true + } else { + false + } + } + } else { + false + } + } +} diff --git a/src/main/resources/assets/foodcraftreloaded/lang/en_us.lang b/src/main/resources/assets/foodcraftreloaded/lang/en_us.lang index 4d0906c..5c0fdd8 100644 --- a/src/main/resources/assets/foodcraftreloaded/lang/en_us.lang +++ b/src/main/resources/assets/foodcraftreloaded/lang/en_us.lang @@ -200,7 +200,8 @@ item.foodcraftreloaded.diamond_kitchen_knife.name=Diamond Knife item.foodcraftreloaded.emerald_kitchen_knife.name=Emerald Knife # Sapling -item.foodcraftreloaded.sapling=%s Sapling +item.foodcraftreloaded.sapling.name=%s Sapling +item.foodcraftreloaded.leaves.name=%s Leaves # Jam item.foodcraftreloaded.jam.name=%s Jam diff --git a/src/main/resources/assets/foodcraftreloaded/lang/zh_cn.lang b/src/main/resources/assets/foodcraftreloaded/lang/zh_cn.lang index c9531fb..69a0b61 100644 --- a/src/main/resources/assets/foodcraftreloaded/lang/zh_cn.lang +++ b/src/main/resources/assets/foodcraftreloaded/lang/zh_cn.lang @@ -216,7 +216,8 @@ item.foodcraftreloaded.diamond_kitchen_knife.name=钻石刀 item.foodcraftreloaded.emerald_kitchen_knife.name=绿宝石刀 # Sapling -item.foodcraftreloaded.sapling=%s树苗 +item.foodcraftreloaded.sapling.name=%s树苗 +item.foodcraftreloaded.leaves.name=%s树叶 # Jam item.foodcraftreloaded.jam.name=%s果酱