From ed80aa377328b44926fbe7aa6ab9f9f8b66464c3 Mon Sep 17 00:00:00 2001 From: dags- Date: Fri, 13 Mar 2020 16:10:29 +0000 Subject: [PATCH] fix custom trees growing naturally despite being disabled in the generator options --- .../mod/feature/tree/SaplingListener.java | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/tree/SaplingListener.java b/TerraForgedMod/src/main/java/com/terraforged/mod/feature/tree/SaplingListener.java index 18e2e24..7e36191 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/tree/SaplingListener.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/feature/tree/SaplingListener.java @@ -26,6 +26,8 @@ package com.terraforged.mod.feature.tree; import com.terraforged.mod.TerraWorld; +import com.terraforged.mod.chunk.TerraChunkGenerator; +import com.terraforged.mod.chunk.TerraContext; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.SaplingBlock; @@ -34,8 +36,10 @@ import net.minecraft.util.math.Vec3i; import net.minecraft.world.IWorld; import net.minecraft.world.World; import net.minecraft.world.WorldType; +import net.minecraft.world.gen.ChunkGenerator; import net.minecraft.world.gen.feature.Feature; import net.minecraft.world.gen.feature.NoFeatureConfig; +import net.minecraft.world.server.ServerWorld; import net.minecraftforge.event.world.SaplingGrowTreeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @@ -54,9 +58,18 @@ public class SaplingListener { @SubscribeEvent public static void onTreeGrow(SaplingGrowTreeEvent event) { + // ignore if client + if (event.getWorld().isRemote()) { + return; + } + // ignore other world types if (!TerraWorld.isTerraWorld(event.getWorld())) { return; } + // has user disabled custom trees? + if (!areCustomTreesEnabled(event.getWorld())) { + return; + } IWorld world = event.getWorld(); BlockPos pos = event.getPos(); @@ -128,14 +141,15 @@ public class SaplingListener { return NONE; } - private static boolean isTerraWorld(IWorld world) { - if (world instanceof World) { - return isTerraWorld(((World) world).getWorldType()); + private static boolean areCustomTreesEnabled(IWorld world) { + if (world instanceof ServerWorld) { + ServerWorld serverWorld = (ServerWorld) world; + ChunkGenerator generator = serverWorld.getChunkProvider().generator; + if (generator instanceof TerraChunkGenerator) { + TerraContext context = ((TerraChunkGenerator) generator).getContext(); + return context.terraSettings.features.customBiomeFeatures; + } } return false; } - - private static boolean isTerraWorld(WorldType type) { - return type.getName().equals("terraforged"); - } }