Search in sources :

Example 1 with Structure

use of net.minecraft.world.gen.feature.structure.Structure in project bioplethora by AquexTheSeal.

the class BPStructureGeneration method addDimensionalSpacing.

@SubscribeEvent
public static void addDimensionalSpacing(final WorldEvent.Load event) {
    if (event.getWorld() instanceof ServerWorld) {
        ServerWorld serverWorld = (ServerWorld) event.getWorld();
        try {
            Method GETCODEC_METHOD = ObfuscationReflectionHelper.findMethod(ChunkGenerator.class, "func_230347_a_");
            ResourceLocation cgRL = Registry.CHUNK_GENERATOR.getKey((Codec<? extends ChunkGenerator>) GETCODEC_METHOD.invoke(serverWorld.getChunkSource().generator));
            if (cgRL != null && cgRL.getNamespace().equals("terraforged")) {
                return;
            }
        } catch (Exception e) {
            LogManager.getLogger().error("Was unable to check if " + serverWorld.dimension().location() + " is using Terraforged's ChunkGenerator.");
        }
        // Prevent spawning our structure in Vanilla's superflat world
        if (serverWorld.getChunkSource().generator instanceof FlatChunkGenerator && serverWorld.dimension().equals(World.OVERWORLD)) {
            return;
        }
        // Adding our Structure to the Map
        Map<Structure<?>, StructureSeparationSettings> tempMap = new HashMap<Structure<?>, StructureSeparationSettings>(serverWorld.getChunkSource().generator.getSettings().structureConfig());
        tempMap.putIfAbsent(BioplethoraStructures.ALPHANUM_MAUSOLEUM.get(), DimensionStructuresSettings.DEFAULTS.get(BioplethoraStructures.ALPHANUM_MAUSOLEUM.get()));
        serverWorld.getChunkSource().generator.getSettings().structureConfig = tempMap;
    }
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) HashMap(java.util.HashMap) FlatChunkGenerator(net.minecraft.world.gen.FlatChunkGenerator) ResourceLocation(net.minecraft.util.ResourceLocation) StructureSeparationSettings(net.minecraft.world.gen.settings.StructureSeparationSettings) Method(java.lang.reflect.Method) Structure(net.minecraft.world.gen.feature.structure.Structure) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 2 with Structure

use of net.minecraft.world.gen.feature.structure.Structure in project ChocolateQuestRepoured by TeamChocoQuest.

the class StructureHelper method isStructureInRange.

public static boolean isStructureInRange(World world, BlockPos pos, int radius, String name) {
    if (!world.getWorldInfo().isMapFeaturesEnabled()) {
        return false;
    }
    if (name.equals("AW2")) {
        // check for aw2 structures
        if (!CQRMain.isAW2Installed) {
            return false;
        }
        return AW2Integration.isAW2StructureInRange(world, pos, radius);
    }
    ChunkGenerator chunkGenerator = ((ServerWorld) world).getChunkProvider().chunkGenerator;
    if (chunkGenerator instanceof OverworldChunkGenerator || chunkGenerator instanceof NetherChunkGenerator || chunkGenerator instanceof EndChunkGenerator || chunkGenerator instanceof FlatChunkGenerator || chunkGenerator instanceof DebugChunkGenerator) {
        // vanilla chunk generator
        Structure structureGenerator = getStructureGenerator(world, name);
        if (structureGenerator != null) {
            return isStructureInRange(world, structureGenerator, pos, radius);
        }
        return false;
    }
    // modded chunk generator
    BlockPos structurePos;
    try {
        structurePos = chunkGenerator.getNearestStructurePos(world, name, pos, false);
        if (structurePos != null && (Math.abs(structurePos.getX() - pos.getX()) <= radius || Math.abs(structurePos.getZ() - pos.getZ()) <= radius)) {
            return true;
        }
    } catch (NullPointerException e) {
    // ignore
    }
    try {
        structurePos = chunkGenerator.getNearestStructurePos(world, name, pos, true);
        if (structurePos != null && (Math.abs(structurePos.getX() - pos.getX()) <= radius || Math.abs(structurePos.getZ() - pos.getZ()) <= radius)) {
            return true;
        }
    } catch (NullPointerException e) {
    // ignore
    }
    return false;
}
Also used : FlatChunkGenerator(net.minecraft.world.gen.FlatChunkGenerator) EndChunkGenerator(net.minecraft.world.gen.EndChunkGenerator) BlockPos(net.minecraft.util.math.BlockPos) OverworldChunkGenerator(net.minecraft.world.gen.OverworldChunkGenerator) ChunkGenerator(net.minecraft.world.gen.ChunkGenerator) EndChunkGenerator(net.minecraft.world.gen.EndChunkGenerator) FlatChunkGenerator(net.minecraft.world.gen.FlatChunkGenerator) NetherChunkGenerator(net.minecraft.world.gen.NetherChunkGenerator) OverworldChunkGenerator(net.minecraft.world.gen.OverworldChunkGenerator) Structure(net.minecraft.world.gen.feature.structure.Structure) NetherChunkGenerator(net.minecraft.world.gen.NetherChunkGenerator)

Example 3 with Structure

use of net.minecraft.world.gen.feature.structure.Structure in project ChaosAwakens by ChaosAwakens.

the class CommonSetupEvent method addDimensionalSpacing.

// public static void registerReachModifiers(final PlayerEvent event) {
// double reachDistance = 0.0D;
// ImmutableMultimap.Builder<Attribute, AttributeModifier> builder = ImmutableMultimap.builder();
// builder.put(ForgeMod.REACH_DISTANCE.get(), new AttributeModifier(ExtendedHitWeaponItem.REACH_MODIFIER, "Weapon modifier", reachDistance, AttributeModifier.Operation.ADDITION));
// ItemStack bigBertha = new ItemStack(CAItems.BIG_BERTHA.get());
// ItemStack attitudeAdjuster = new ItemStack(CAItems.ATTITUDE_ADJUSTER.get());
// ItemStack prismaticReaper = new ItemStack(CAItems.PRISMATIC_REAPER.get());
// PlayerEntity player =  event.getPlayer();
// 
// if(player.getItemInHand(Hand.MAIN_HAND).equals(bigBertha)) {
// reachDistance = 25.0D;
// }
// 
// if(player.getItemInHand(Hand.MAIN_HAND).equals(attitudeAdjuster)) {
// reachDistance = 15.0D;
// }
// 
// if(player.getItemInHand(Hand.MAIN_HAND).equals(prismaticReaper)) {
// reachDistance = 13.0D;
// }
// }
public static void addDimensionalSpacing(final WorldEvent.Load event) {
    if (!(event.getWorld() instanceof ServerWorld))
        return;
    ServerWorld serverWorld = (ServerWorld) event.getWorld();
    ServerChunkProvider chunkProvider = serverWorld.getChunkSource();
    try {
        if (codecMethod == null)
            codecMethod = ObfuscationReflectionHelper.findMethod(ChunkGenerator.class, "codec");
        // TODO Fix this
        ResourceLocation chunkGeneratorKey = Registry.CHUNK_GENERATOR.getKey((Codec<? extends ChunkGenerator>) codecMethod.invoke(chunkProvider.generator));
        if (chunkGeneratorKey != null && chunkGeneratorKey.getNamespace().equals("terraforged"))
            return;
    } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
        ChaosAwakens.warn("WORLDGEN", e);
        e.printStackTrace();
    } catch (UnableToFindMethodException e) {
        if (CAConfig.COMMON.terraforgedCheckMsg.get())
            ChaosAwakens.info("WORLDGEN", "Unable to check if " + serverWorld.dimension().location() + " is using Terraforged's ChunkGenerator due to Terraforged not being present or not accessible," + " if you aren't using Terraforged please ignore this message");
    }
    if (serverWorld.getChunkSource().getGenerator() instanceof FlatChunkGenerator && serverWorld.dimension().equals(World.OVERWORLD))
        return;
    Map<Structure<?>, StructureSeparationSettings> tempMap = new HashMap<>(chunkProvider.generator.getSettings().structureConfig());
    tempMap.putIfAbsent(CAStructures.ACACIA_ENT_TREE.get(), DimensionStructuresSettings.DEFAULTS.get(CAStructures.ACACIA_ENT_TREE.get()));
    tempMap.putIfAbsent(CAStructures.BIRCH_ENT_TREE.get(), DimensionStructuresSettings.DEFAULTS.get(CAStructures.BIRCH_ENT_TREE.get()));
    tempMap.putIfAbsent(CAStructures.CRIMSON_ENT_TREE.get(), DimensionStructuresSettings.DEFAULTS.get(CAStructures.CRIMSON_ENT_TREE.get()));
    tempMap.putIfAbsent(CAStructures.DARK_OAK_ENT_TREE.get(), DimensionStructuresSettings.DEFAULTS.get(CAStructures.DARK_OAK_ENT_TREE.get()));
    tempMap.putIfAbsent(CAStructures.JUNGLE_ENT_TREE.get(), DimensionStructuresSettings.DEFAULTS.get(CAStructures.JUNGLE_ENT_TREE.get()));
    tempMap.putIfAbsent(CAStructures.OAK_ENT_TREE.get(), DimensionStructuresSettings.DEFAULTS.get(CAStructures.OAK_ENT_TREE.get()));
    tempMap.putIfAbsent(CAStructures.SPRUCE_ENT_TREE.get(), DimensionStructuresSettings.DEFAULTS.get(CAStructures.SPRUCE_ENT_TREE.get()));
    tempMap.putIfAbsent(CAStructures.WARPED_ENT_TREE.get(), DimensionStructuresSettings.DEFAULTS.get(CAStructures.WARPED_ENT_TREE.get()));
    tempMap.putIfAbsent(CAStructures.WASP_DUNGEON.get(), DimensionStructuresSettings.DEFAULTS.get(CAStructures.WASP_DUNGEON.get()));
    chunkProvider.generator.getSettings().structureConfig = tempMap;
}
Also used : UnableToFindMethodException(net.minecraftforge.fml.common.ObfuscationReflectionHelper.UnableToFindMethodException) HashMap(java.util.HashMap) FlatChunkGenerator(net.minecraft.world.gen.FlatChunkGenerator) InvocationTargetException(java.lang.reflect.InvocationTargetException) ServerWorld(net.minecraft.world.server.ServerWorld) ResourceLocation(net.minecraft.util.ResourceLocation) StructureSeparationSettings(net.minecraft.world.gen.settings.StructureSeparationSettings) Structure(net.minecraft.world.gen.feature.structure.Structure) ServerChunkProvider(net.minecraft.world.server.ServerChunkProvider)

Aggregations

FlatChunkGenerator (net.minecraft.world.gen.FlatChunkGenerator)3 Structure (net.minecraft.world.gen.feature.structure.Structure)3 HashMap (java.util.HashMap)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 StructureSeparationSettings (net.minecraft.world.gen.settings.StructureSeparationSettings)2 ServerWorld (net.minecraft.world.server.ServerWorld)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 BlockPos (net.minecraft.util.math.BlockPos)1 ChunkGenerator (net.minecraft.world.gen.ChunkGenerator)1 EndChunkGenerator (net.minecraft.world.gen.EndChunkGenerator)1 NetherChunkGenerator (net.minecraft.world.gen.NetherChunkGenerator)1 OverworldChunkGenerator (net.minecraft.world.gen.OverworldChunkGenerator)1 ServerChunkProvider (net.minecraft.world.server.ServerChunkProvider)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1 UnableToFindMethodException (net.minecraftforge.fml.common.ObfuscationReflectionHelper.UnableToFindMethodException)1