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

    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
    • OLXTOTO adalah situs bandar togel online resmi terbesar dan terpercaya di Indonesia. Bergabunglah dengan OLXTOTO dan nikmati pengalaman bermain togel yang aman dan terjamin. Koleksi toto 4D dan togel toto terlengkap di OLXTOTO membuat para member memiliki pilihan taruhan yang lebih banyak. Sebagai situs togel terpercaya, OLXTOTO menjaga keamanan dan kenyamanan para membernya dengan sistem keamanan terbaik dan enkripsi data. Transaksi yang cepat, aman, dan terpercaya merupakan jaminan dari OLXTOTO. Nikmati layanan situs toto terbaik dari OLXTOTO dengan tampilan yang user-friendly dan mudah digunakan. Layanan pelanggan tersedia 24/7 untuk membantu para member. Bergabunglah dengan OLXTOTO sekarang untuk merasakan pengalaman bermain togel yang menyenangkan dan menguntungkan.
    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
  • Topics

×
×
  • Create New...

Important Information

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