fix custom trees growing naturally despite being disabled in the generator options

This commit is contained in:
dags- 2020-03-13 16:10:29 +00:00
parent 696ed8a422
commit ed80aa3773

View File

@ -26,6 +26,8 @@
package com.terraforged.mod.feature.tree; package com.terraforged.mod.feature.tree;
import com.terraforged.mod.TerraWorld; 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.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.SaplingBlock; import net.minecraft.block.SaplingBlock;
@ -34,8 +36,10 @@ import net.minecraft.util.math.Vec3i;
import net.minecraft.world.IWorld; import net.minecraft.world.IWorld;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.WorldType; import net.minecraft.world.WorldType;
import net.minecraft.world.gen.ChunkGenerator;
import net.minecraft.world.gen.feature.Feature; import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.NoFeatureConfig; import net.minecraft.world.gen.feature.NoFeatureConfig;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.event.world.SaplingGrowTreeEvent; import net.minecraftforge.event.world.SaplingGrowTreeEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
@ -54,9 +58,18 @@ public class SaplingListener {
@SubscribeEvent @SubscribeEvent
public static void onTreeGrow(SaplingGrowTreeEvent event) { public static void onTreeGrow(SaplingGrowTreeEvent event) {
// ignore if client
if (event.getWorld().isRemote()) {
return;
}
// ignore other world types
if (!TerraWorld.isTerraWorld(event.getWorld())) { if (!TerraWorld.isTerraWorld(event.getWorld())) {
return; return;
} }
// has user disabled custom trees?
if (!areCustomTreesEnabled(event.getWorld())) {
return;
}
IWorld world = event.getWorld(); IWorld world = event.getWorld();
BlockPos pos = event.getPos(); BlockPos pos = event.getPos();
@ -128,14 +141,15 @@ public class SaplingListener {
return NONE; return NONE;
} }
private static boolean isTerraWorld(IWorld world) { private static boolean areCustomTreesEnabled(IWorld world) {
if (world instanceof World) { if (world instanceof ServerWorld) {
return isTerraWorld(((World) world).getWorldType()); 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; return false;
} }
private static boolean isTerraWorld(WorldType type) {
return type.getName().equals("terraforged");
}
} }