Jump to content

[1.13] WorldChunkManager


Auties

Recommended Posts

I'm using spigot for this project, but, as I'm working only with nms, I think that I can ask this question. In the prevoius versions of minecraft we could create a new WorldChunkManager and override the default one of a world with the one just created by using reflection ("c" variable in the WorldProviderClass). As Mojang changes every time the code, in 1.13 the variable c (WorldChunkManager) is found in a class called ChunkGeneratorAbstract that extends ChunkGenerator. From what I know there's only a way to get there: cast ChunkGeneratorAbstract to ChunkGenerator, and this is what I did in my code:


public class Utils {

    private IslandCraftPlugin plugin = JavaPlugin.getPlugin(IslandCraftPlugin.class);

    public void register(World world, final BiomeGenerator biome) throws NoSuchFieldException, IllegalAccessException {

        CraftWorld craftWorld = (CraftWorld) world;

        ChunkGeneratorAbstract generator = (ChunkGeneratorAbstract) craftWorld.getHandle().worldProvider.getChunkGenerator();

        Field field = getField(generator.getClass(), "c");

        field.setAccessible(true);


        field.set(generator, new CustomWorldChunkManager(biome));


    }
    private  Field getField(Class<?> clazz, String fieldName) throws NoSuchFieldException {
        try {
            return clazz.getDeclaredField(fieldName);
        } catch (NoSuchFieldException e) {
            Class<?> superClass = clazz.getSuperclass();
            if (superClass == null) {
                throw e;
            } else {
                return getField(superClass, fieldName);
            }
        }

    }
}

, but when I try :

  craftWorld.getHandle().worldProvider.getChunkGenerator().getWorldChunkManager() instanceof CustomWorldChunkManager

I get a false but when I try to check if the field was correctly set I get true. What am I doing wrong?

 

PS:

If you need it, here's the ChunkGeneratorAbstract class:

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package net.minecraft.server.v1_13_R1;

import com.google.common.collect.Maps;
import java.util.BitSet;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import java.util.function.Function;
import javax.annotation.Nullable;
import net.minecraft.server.v1_13_R1.BlockPosition.MutableBlockPosition;
import net.minecraft.server.v1_13_R1.HeightMap.Type;
import net.minecraft.server.v1_13_R1.WorldGenStage.Decoration;
import net.minecraft.server.v1_13_R1.WorldGenStage.Features;
import org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.longs.Long2ObjectMaps;
import org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.longs.LongSet;

public abstract class ChunkGeneratorAbstract<C extends GeneratorSettings> implements ChunkGenerator<C> {
    protected final GeneratorAccess a;
    protected final long b;
    protected final WorldChunkManager c;
    protected final Map<StructureGenerator<? extends WorldGenFeatureConfiguration>, Long2ObjectMap<StructureStart>> d = Maps.newHashMap();
    protected final Map<StructureGenerator<? extends WorldGenFeatureConfiguration>, Long2ObjectMap<LongSet>> e = Maps.newHashMap();

    public ChunkGeneratorAbstract(GeneratorAccess generatoraccess, WorldChunkManager worldchunkmanager) {
        this.a = generatoraccess;
        this.b = generatoraccess.getSeed();
        this.c = worldchunkmanager;
    }

    public void addFeatures(RegionLimitedWorldAccess regionlimitedworldaccess, Features worldgenstage_features) {
        SeededRandom seededrandom = new SeededRandom(this.b);
        int i = regionlimitedworldaccess.a();
        int j = regionlimitedworldaccess.b();
        BitSet bitset = regionlimitedworldaccess.c(i, j).a(worldgenstage_features);

        for(int k = i - 8; k <= i + 8; ++k) {
            for(int l = j - 8; l <= j + 8; ++l) {
                List list = regionlimitedworldaccess.getChunkProvider().getChunkGenerator().getWorldChunkManager().getBiome(new BlockPosition(k * 16, 0, l * 16), (BiomeBase)null).a(worldgenstage_features);
                ListIterator listiterator = list.listIterator();

                while(listiterator.hasNext()) {
                    int i1 = listiterator.nextIndex();
                    WorldGenCarverWrapper worldgencarverwrapper = (WorldGenCarverWrapper)listiterator.next();
                    seededrandom.c(regionlimitedworldaccess.getMinecraftWorld().getSeed() + (long)i1, k, l);
                    if (worldgencarverwrapper.a(regionlimitedworldaccess, seededrandom, k, l, WorldGenFeatureConfiguration.e)) {
                        worldgencarverwrapper.a(regionlimitedworldaccess, seededrandom, k, l, i, j, bitset, WorldGenFeatureConfiguration.e);
                    }
                }
            }
        }

    }

    @Nullable
    public BlockPosition findNearestMapFeature(World world, String s, BlockPosition blockposition, int i) {
        StructureGenerator structuregenerator = (StructureGenerator)WorldGenerator.aF.get(s.toLowerCase(Locale.ROOT));
        return structuregenerator != null ? structuregenerator.getNearestGeneratedFeature(world, this, blockposition, i) : null;
    }

    protected void a(IChunkAccess ichunkaccess, Random random) {
        MutableBlockPosition blockposition_mutableblockposition = new MutableBlockPosition();
        int i = ichunkaccess.getPos().d();
        int j = ichunkaccess.getPos().e();
        Iterator iterator = BlockPosition.a(i, 0, j, i + 16, 0, j + 16).iterator();

        while(iterator.hasNext()) {
            BlockPosition blockposition = (BlockPosition)iterator.next();

            for(int k = 4; k >= 0; --k) {
                if (k <= random.nextInt(5)) {
                    ichunkaccess.a(blockposition_mutableblockposition.c(blockposition.getX(), k, blockposition.getZ()), Blocks.BEDROCK.getBlockData(), false);
                }
            }
        }

    }

    public void addDecorations(RegionLimitedWorldAccess regionlimitedworldaccess) {
        BlockFalling.instaFall = true;
        int i = regionlimitedworldaccess.a();
        int j = regionlimitedworldaccess.b();
        int k = i * 16;
        int l = j * 16;
        BlockPosition blockposition = new BlockPosition(k, 0, l);
        BiomeBase biomebase = regionlimitedworldaccess.c(i + 1, j + 1).getBiomeIndex()[0];
        SeededRandom seededrandom = new SeededRandom();
        long i1 = seededrandom.a(regionlimitedworldaccess.getSeed(), k, l);
        Decoration[] aworldgenstage_decoration = Decoration.values();
        int j1 = aworldgenstage_decoration.length;

        for(int k1 = 0; k1 < j1; ++k1) {
            Decoration worldgenstage_decoration = aworldgenstage_decoration[k1];
            biomebase.a(worldgenstage_decoration, this, regionlimitedworldaccess, i1, seededrandom, blockposition);
        }

        BlockFalling.instaFall = false;
    }

    public void a(IChunkAccess ichunkaccess, BiomeBase[] abiomebase, SeededRandom seededrandom, int i) {
        ChunkCoordIntPair chunkcoordintpair = ichunkaccess.getPos();
        int j = chunkcoordintpair.d();
        int k = chunkcoordintpair.e();
        double[] adouble = this.a(chunkcoordintpair.x, chunkcoordintpair.z);

        for(int l = 0; l < 16; ++l) {
            for(int i1 = 0; i1 < 16; ++i1) {
                int j1 = j + l;
                int k1 = k + i1;
                int l1 = ichunkaccess.a(Type.WORLD_SURFACE_WG, l, i1) + 1;
                abiomebase[i1 * 16 + l].a(seededrandom, ichunkaccess, j1, k1, l1, adouble[i1 * 16 + l], this.getSettings().r(), this.getSettings().s(), i, this.a.getSeed());
            }
        }

    }

    public abstract C getSettings();

    public abstract double[] a(int var1, int var2);

    public boolean canSpawnStructure(BiomeBase biomebase, StructureGenerator<? extends WorldGenFeatureConfiguration> structuregenerator) {
        return biomebase.a(structuregenerator);
    }

    @Nullable
    public WorldGenFeatureConfiguration getFeatureConfiguration(BiomeBase biomebase, StructureGenerator<? extends WorldGenFeatureConfiguration> structuregenerator) {
        return biomebase.b(structuregenerator);
    }

    public WorldChunkManager getWorldChunkManager() {
        return this.c;
    }

    public long getSeed() {
        return this.b;
    }

    public Long2ObjectMap<StructureStart> getStructureStartCache(StructureGenerator<? extends WorldGenFeatureConfiguration> structuregenerator) {
        return (Long2ObjectMap)this.d.computeIfAbsent(structuregenerator, (s) -> {
            return Long2ObjectMaps.synchronize(new ExpiringMap(8192, 10000));
        });
    }

    public Long2ObjectMap<LongSet> getStructureCache(StructureGenerator<? extends WorldGenFeatureConfiguration> structuregenerator) {
        return (Long2ObjectMap)this.e.computeIfAbsent(structuregenerator, (s) -> {
            return Long2ObjectMaps.synchronize(new ExpiringMap(8192, 10000));
        });
    }

    public int e() {
        return 256;
    }

    public World getWorld() {
        return this.a.getMinecraftWorld();
    }
}

and here's the CHunkGenerator class:

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package net.minecraft.server.v1_13_R1;

import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.server.v1_13_R1.BiomeBase.BiomeMeta;
import net.minecraft.server.v1_13_R1.WorldGenStage.Features;
import org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.longs.LongSet;

public interface ChunkGenerator<C extends GeneratorSettings> {
    void createChunk(IChunkAccess var1);

    void addFeatures(RegionLimitedWorldAccess var1, Features var2);

    void addDecorations(RegionLimitedWorldAccess var1);

    void addMobs(RegionLimitedWorldAccess var1);

    List<BiomeMeta> getMobsFor(EnumCreatureType var1, BlockPosition var2);

    @Nullable
    BlockPosition findNearestMapFeature(World var1, String var2, BlockPosition var3, int var4);

    C getSettings();

    int a(World var1, boolean var2, boolean var3);

    boolean canSpawnStructure(BiomeBase var1, StructureGenerator<? extends WorldGenFeatureConfiguration> var2);

    @Nullable
    WorldGenFeatureConfiguration getFeatureConfiguration(BiomeBase var1, StructureGenerator<? extends WorldGenFeatureConfiguration> var2);

    Long2ObjectMap<StructureStart> getStructureStartCache(StructureGenerator<? extends WorldGenFeatureConfiguration> var1);

    Long2ObjectMap<LongSet> getStructureCache(StructureGenerator<? extends WorldGenFeatureConfiguration> var1);

    WorldChunkManager getWorldChunkManager();

    long getSeed();

    int getSpawnHeight();

    int e();

    World getWorld();
}

 

Link to comment
Share on other sites

40 minutes ago, Auties said:

I'm using spigot for this project

But not Forge, so why are you on the Forge forums?

40 minutes ago, Auties said:

as I'm working only with nms

Whatever that is.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • https://pastebin.com/VwpAW6PX My game crashes upon launch when trying to implement the Oculus mod to this mod compilation, above is the crash report, I do not know where to begin to attempt to fix this issue and require assistance.
    • https://youtube.com/shorts/gqLTSMymgUg?si=5QOeSvA4TTs-bL46
    • CubeHaven is a SMP server with unique features that can't be found on the majority of other servers! Java: MC.CUBEHAVEN.NET Bedrock: MC.CUBEHAVEN.NET:19132 3 different stores: - CubeHaven Store: Our store to purchase using real money. - Bitcoin Store: Store for Bitcoin. Bitcoin can be earned from playing the server. Giving options for players if they want to spend real money or grind to obtain exclusive packages. - Black Market: A hidden store for trading that operates outside our traditional stores, like custom enchantments, exclusive items and more. Some of our features include: Rank Up: Progress through different ranks to unlock new privileges and perks. 📈 Skills: RPG-style skill system that enhances your gaming experience! 🎮 Leaderboards: Compete and shine! Top players are rewarded weekly! 🏆 Random Teleporter: Travel instantly across different worlds with a click! 🌐 Custom World Generation: Beautifully generated world. 🌍 Dungeons: Explore challenging and rewarding dungeons filled with treasures and monsters. 🏰 Kits: Unlock ranks and gain access to various kits. 🛠️ Fishing Tournament: Compete in a friendly fishing tournament! 🎣 Chat Games: Enjoy games right within the chat! 🎲 Minions: Get some help from your loyal minions. 👥 Piñata Party: Enjoy a festive party with Piñatas! 🎉 Quests: Over 1000 quests that you can complete! 📜 Bounty Hunter: Set a bounty on a player's head. 💰 Tags: Displayed on nametags, in the tab list, and in chat. 🏷️ Coinflip: Bet with other players on coin toss outcomes, victory, or defeat! 🟢 Invisible & Glowing Frames: Hide your frames for a cleaner look or apply a glow to it for a beautiful look. 🔲✨[ Player Warp: Set your own warp points for other players to teleport to. 🌟 Display Shop: Create your own shop and sell to other players! 🛒 Item Skins: Customize your items with unique skins. 🎨 Pets: Your cute loyal companion to follow you wherever you go! 🐾 Cosmetics: Enhance the look of your character with beautiful cosmetics! 💄 XP-Bottle: Store your exp safely in a bottle for later use! 🍶 Chest & Inventory Sorting: Keep your items neatly sorted in your inventory or chest! 📦 Glowing: Stand out from other players with a colorful glow! ✨ Player Particles: Over 100 unique particle effects to show off. 🎇 Portable Inventories: Over virtual inventories with ease. 🧳 And a lot more! Become part of our growing community today! Discord: https://cubehaven.net/discord Java: MC.CUBEHAVEN.NET Bedrock: MC.CUBEHAVEN.NET:19132
    • # Problematic frame: # C [libopenal.so+0x9fb4d] It is always the same issue - this refers to the Linux OS - so your system may prevent Java from working   I am not familiar with Linux - check for similar/related issues  
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.