aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/world/GTWorldgen.java
blob: 07c76e0e3a5bb8df56e4b7501875c18e661b9131 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package gregtech.api.world;

import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;

import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraftforge.common.DimensionManager;

public abstract class GTWorldgen {

    public final String mWorldGenName;
    public final boolean mEnabled;
    private final Map<String, Boolean> mDimensionMap = new ConcurrentHashMap<>();

    @SuppressWarnings({ "unchecked", "rawtypes" }) // The adding of "this" needs a List<this> which does not exist
    public GTWorldgen(String aName, List aList, boolean aDefault) {
        mWorldGenName = aName;
        mEnabled = aDefault;
        if (mEnabled) aList.add(this);
    }

    /**
     * @param aWorld         The World Object
     * @param aRandom        The Random Generator to use
     * @param aBiome         The Name of the Biome (always != null)
     * @param aDimensionType The Type of Worldgeneration to add. -1 = Nether, 0 = Overworld, +1 = End
     * @param aChunkX        xCoord of the Chunk
     * @param aChunkZ        zCoord of the Chunk
     * @return if the Worldgeneration has been successfully completed
     */
    public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int aDimensionType, int aChunkX,
        int aChunkZ, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) {
        return false;
    }

    public int executeWorldgenChunkified(World aWorld, Random aRandom, String aBiome, int aDimensionType, int aChunkX,
        int aChunkZ, int seedX, int seedZ, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) {
        return 4; // This is for the empty Orevein
    }

    /**
     *
     * @param aDimName              The Dimension Name
     * @param aDimensionType        The Type of Worldgeneration to add. -1 = Nether, 0 = Overworld, +1 = End
     * @param aAllowedDimensionType The Type of allowed Worldgeneration
     * @return if generation for this world is allowed for MoronTech (tm) OreGen (ATM (2.0.3.1Dev) only End, Nether,
     *         Overworld, Twilight Forest and Deep Dark)
     */
    public boolean isGenerationAllowed(String aDimName, int aDimensionType, int aAllowedDimensionType) {
        if (aDimName.equalsIgnoreCase("Underdark")) {
            return false;
        }
        if (!(aDimName.equalsIgnoreCase("Overworld") || aDimName.equalsIgnoreCase("Nether")
            || aDimName.equalsIgnoreCase("The End")
            || aDimName.equalsIgnoreCase("Twilight Forest"))) return false;

        Boolean tAllowed = mDimensionMap.get(aDimName);
        if (tAllowed == null) {
            mDimensionMap.put(aDimName, aDimensionType == aAllowedDimensionType);
            return aDimensionType == aAllowedDimensionType;
        }
        return tAllowed;
    }

    public boolean isGenerationAllowed(World aWorld, int aAllowedDimensionType) {
        World allowedWorld = DimensionManager.getWorld(aAllowedDimensionType);
        if (allowedWorld != null && allowedWorld.provider != null) {
            return isGenerationAllowed(aWorld, allowedWorld.provider.getClass());
        } else {
            return aWorld.provider.dimensionId == aAllowedDimensionType;
        }
    }

    /**
     *
     * @param aWorld                 The World Object
     * @param aAllowedDimensionTypes The Types of allowed Worldgeneration
     * @return if generation for this world is allowed for MoronTech (tm) OreGen (ATM (2.0.3.1Dev) only End, Nether,
     *         Overworld, Twilight Forest and Deep Dark)
     */
    public boolean isGenerationAllowed(World aWorld, Class... aAllowedDimensionTypes) {
        return isGenerationAllowed(aWorld, null, aAllowedDimensionTypes);
    }

    /**
     *
     * @param aWorld                 The World Object
     * @param blackListedProviders   List of blacklisted Worldgeneration classes
     * @param aAllowedDimensionTypes The Types of allowed Worldgeneration
     * @return if generation for this world is allowed for MoronTech (tm) OreGen (ATM (2.0.3.1Dev) only End, Nether,
     *         Overworld, Twilight Forest and Deep Dark)
     */
    public boolean isGenerationAllowed(World aWorld, String[] blackListedProviders, Class... aAllowedDimensionTypes) {
        String aDimName = aWorld.provider.getDimensionName();
        if (aDimName.equalsIgnoreCase("Underdark")) {
            return false;
        }
        if (!(aDimName.equalsIgnoreCase("Overworld") || aDimName.equalsIgnoreCase("Nether")
            || aDimName.equalsIgnoreCase("The End")
            || aDimName.equalsIgnoreCase("Twilight Forest"))) return false;

        Boolean tAllowed = mDimensionMap.get(aDimName);
        if (tAllowed == null) {
            if (blackListedProviders != null) {
                for (String dimClass : blackListedProviders) {
                    if (dimClass.equals(
                        aWorld.provider.getClass()
                            .getName())) {
                        return false;
                    }
                }
            }
            boolean value = false;
            for (Class aAllowedDimensionType : aAllowedDimensionTypes) {
                if (aAllowedDimensionType.isInstance(aWorld.provider)) {
                    value = true;
                    break;
                }
            }

            mDimensionMap.put(aDimName, value);
            return value;
        }
        return tAllowed;
    }
}