Skip to content

Commit 6ba4e77

Browse files
Fix Ore generation Page glitches (#1668)
1 parent 93d24ac commit 6ba4e77

File tree

4 files changed

+87
-44
lines changed

4 files changed

+87
-44
lines changed

src/main/java/gregtech/api/GTValues.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ public class GTValues {
7575
MODID_CT = "crafttweaker",
7676
MODID_TOP = "theoneprobe",
7777
MODID_CTM = "ctm",
78-
MODID_CC = "cubicchunks";
78+
MODID_CC = "cubicchunks",
79+
MODID_AR = "advancedrocketry";
7980

8081
//because forge is too fucking retarded to cache results or at least do not create fucking
8182
//immutable collections every time you retrieve indexed mod list

src/main/java/gregtech/api/worldgen/config/WorldGenRegistry.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private WorldGenRegistry() {
4949
private final Map<String, Supplier<ShapeGenerator>> shapeGeneratorRegistry = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
5050
private final Map<String, Supplier<BlockFiller>> blockFillerRegistry = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
5151
private final Map<String, Supplier<IVeinPopulator>> veinPopulatorRegistry = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
52-
private final Map<String, Integer> namedDimensions = new HashMap<>();
52+
private final Map<Integer, String> namedDimensions = new HashMap<>();
5353

5454
private final List<OreDepositDefinition> registeredDefinitions = new ArrayList<>();
5555
private final Map<WorldProvider, WorldOreVeinCache> oreVeinCache = new WeakHashMap<>();
@@ -221,7 +221,7 @@ private void gatherNamedDimensions(Path dimensionsFile) {
221221
try {
222222
JsonArray dims = element.getAsJsonArray("dims");
223223
for(JsonElement dim : dims) {
224-
namedDimensions.put(dim.getAsJsonObject().get("dimName").getAsString(), dim.getAsJsonObject().get("dimID").getAsInt());
224+
namedDimensions.put(dim.getAsJsonObject().get("dimID").getAsInt(), dim.getAsJsonObject().get("dimName").getAsString());
225225
}
226226
} catch (RuntimeException exception){
227227
GTLog.logger.error("Failed to parse named dimensions", exception);
@@ -279,7 +279,7 @@ public static List<OreDepositDefinition> getOreDeposits() {
279279
return Collections.unmodifiableList(INSTANCE.registeredDefinitions);
280280
}
281281

282-
public static Map<String, Integer> getNamedDimensions() {
282+
public static Map<Integer, String> getNamedDimensions() {
283283
return INSTANCE.namedDimensions;
284284
}
285285

src/main/java/gregtech/integration/jei/GTOreCategory.java

Lines changed: 77 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package gregtech.integration.jei;
22

33
import gregtech.api.gui.GuiTextures;
4+
import gregtech.api.util.GTLog;
5+
import gregtech.api.worldgen.config.OreDepositDefinition;
46
import gregtech.api.worldgen.config.WorldGenRegistry;
57
import gregtech.integration.jei.recipe.primitive.PrimitiveRecipeCategory;
8+
import it.unimi.dsi.fastutil.ints.IntSortedSet;
69
import mezz.jei.api.IGuiHelper;
710
import mezz.jei.api.gui.IDrawable;
811
import mezz.jei.api.gui.IGuiItemStackGroup;
@@ -11,20 +14,29 @@
1114
import mezz.jei.api.recipe.IRecipeWrapper;
1215
import net.minecraft.client.Minecraft;
1316
import net.minecraft.client.gui.FontRenderer;
17+
import net.minecraft.world.DimensionType;
18+
import net.minecraftforge.common.DimensionManager;
1419

15-
import java.util.Map;
20+
import java.util.*;
21+
import java.util.function.Supplier;
22+
23+
import static gregtech.api.GTValues.MODID_AR;
24+
import static gregtech.api.GTValues.isModLoaded;
1625

1726
public class GTOreCategory extends PrimitiveRecipeCategory<GTOreInfo, GTOreInfo> {
1827

1928
protected final IDrawable slot;
29+
protected OreDepositDefinition definition;
2030
protected String veinName;
2131
protected int minHeight;
2232
protected int maxHeight;
2333
protected int outputCount;
2434
protected int weight;
25-
protected int[] dimensionIDs;
35+
protected List<Integer> dimensionIDs;
2636
protected final int FONT_HEIGHT = Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT;
27-
protected final Map<String, Integer> namedDimensions = WorldGenRegistry.getNamedDimensions();
37+
protected final Map<Integer, String> namedDimensions = WorldGenRegistry.getNamedDimensions();
38+
private Map<DimensionType, IntSortedSet> dimMap = DimensionManager.getRegisteredDimensions();
39+
private Supplier<List<Integer>> dimension = this::getAllRegisteredDimensions;
2840
private final int NUM_OF_SLOTS = 5;
2941
private final int SLOT_WIDTH = 18;
3042
private final int SLOT_HEIGHT = 18;
@@ -65,7 +77,7 @@ public void setRecipe(IRecipeLayout recipeLayout, GTOreInfo recipeWrapper, IIngr
6577
maxHeight = recipeWrapper.getMaxHeight();
6678
outputCount = recipeWrapper.getOutputCount();
6779
weight = recipeWrapper.getWeight();
68-
dimensionIDs = recipeWrapper.getDimensionIDs();
80+
definition = recipeWrapper.getDefinition();
6981
}
7082

7183
@Override
@@ -86,7 +98,7 @@ public void drawExtras(Minecraft minecraft) {
8698
//Selected Ore
8799
this.slot.draw(minecraft, 22, baseYPos);
88100
//Surface Identifier
89-
this.slot.draw(minecraft, 22, 73);
101+
this.slot.draw(minecraft, 22, SLOT_HEIGHT * (NUM_OF_SLOTS - 1) + 1);
90102

91103
int yPos = 0;
92104
for(int i = 0; i < outputCount; i++) {
@@ -96,17 +108,20 @@ public void drawExtras(Minecraft minecraft) {
96108
this.slot.draw(minecraft, xPos, yPos);
97109
}
98110

99-
baseYPos = yPos; //has to be set to position of last rendered slot for later use
111+
//base positions set to position of last rendered slot for later use.
112+
//Must account for the fact that yPos is the top corner of the slot, so add in another slot height
113+
baseYPos = yPos + SLOT_HEIGHT;
100114

101115
drawVeinName(minecraft.fontRenderer);
102116

103117
//Begin Drawing information, depending on how many rows of ore outputs were created
104118
//Give room for 5 lines of 5 ores each, so 25 unique ores in the vein
105-
if(baseYPos > 73) {
119+
//73 is SLOT_HEIGHT * (NUM_OF_SLOTS - 1) + 1
120+
if(baseYPos >= SLOT_HEIGHT * NUM_OF_SLOTS) {
106121
minecraft.fontRenderer.drawString("Spawn Range: " + minHeight + "-" + maxHeight, 70, baseYPos + 1, 0x111111);
107122
}
108123
else {
109-
minecraft.fontRenderer.drawString("Spawn Range: " + minHeight + "-" + maxHeight, 70, 73, 0x111111);
124+
minecraft.fontRenderer.drawString("Spawn Range: " + minHeight + "-" + maxHeight, 70, SLOT_HEIGHT * (NUM_OF_SLOTS - 1) + 1, 0x111111);
110125
//Update the position at which the spawn information ends
111126
baseYPos = 73;
112127
}
@@ -117,27 +132,25 @@ public void drawExtras(Minecraft minecraft) {
117132
//Create the Dimensions
118133
minecraft.fontRenderer.drawString("Dimensions: ", 70, baseYPos + (2 * FONT_HEIGHT), 0x111111);
119134

135+
dimensionIDs = dimension.get();
136+
120137
//Will attempt to write dimension IDs in a single line, separated by commas. If the list is so long such that it
121138
//would run off the end of the page, the list is continued on a new line.
122-
for(int i = 0; i < dimensionIDs.length; i++) {
139+
for(int i = 0; i < dimensionIDs.size(); i++) {
123140

124141
//If the dimension name is included, append it to the dimension number
125-
if(namedDimensions.containsValue(dimensionIDs[i])) {
126-
int finalI = i;
127-
dimName = namedDimensions.entrySet().stream()
128-
.filter(entry -> dimensionIDs[finalI] == entry.getValue())
129-
.map(Map.Entry::getKey)
130-
.findFirst().get();
131-
fullDimName = i == dimensionIDs.length - 1 ?
132-
dimensionIDs[i] + " (" + dimName + ")" :
133-
dimensionIDs[i] + " (" + dimName + "),";
142+
if(namedDimensions.containsKey(dimensionIDs.get(i))) {
143+
dimName = namedDimensions.get(dimensionIDs.get(i));
144+
fullDimName = i == dimensionIDs.size() - 1 ?
145+
dimensionIDs.get(i) + " (" + dimName + ")" :
146+
dimensionIDs.get(i) + " (" + dimName + "), ";
134147
}
135148
//If the dimension name is not included, just add the dimension number
136149
else {
137150

138-
fullDimName = i == dimensionIDs.length - 1 ?
139-
Integer.toString(dimensionIDs[i]) :
140-
dimensionIDs[i] + ",";
151+
fullDimName = i == dimensionIDs.size() - 1 ?
152+
Integer.toString(dimensionIDs.get(i)) :
153+
dimensionIDs.get(i) + ", ";
141154
}
142155

143156
//Find the length of the dimension name string
@@ -157,7 +170,7 @@ public void drawExtras(Minecraft minecraft) {
157170

158171

159172
//Label the Surface Identifier
160-
minecraft.fontRenderer.drawSplitString("SurfaceMaterial", 15, 92, 42, 0x111111);
173+
minecraft.fontRenderer.drawSplitString("SurfaceMaterial", 15, 92, minecraft.fontRenderer.getStringWidth("Surface"), 0x111111);
161174

162175
}
163176

@@ -176,4 +189,46 @@ private void drawVeinName(final FontRenderer fontRenderer) {
176189

177190
fontRenderer.drawString(veinNameToDraw, startPosition, 1, 0x111111);
178191
}
192+
193+
public List<Integer> getAllRegisteredDimensions() {
194+
List<Integer> dims = new ArrayList<>();
195+
dimMap.values().stream()
196+
.flatMap(Collection::stream)
197+
.mapToInt(Integer::intValue)
198+
.filter(num -> definition.getDimensionFilter().test(DimensionManager.createProviderFor(num)))
199+
.forEach(dims::add);
200+
201+
if(isModLoaded(MODID_AR)) {
202+
try {
203+
int[] plantDims = DimensionManager.getDimensions(DimensionType.byName("planet"));
204+
int[] asteroidDims = DimensionManager.getDimensions(DimensionType.byName("asteroid"));
205+
int[] spaceDims = DimensionManager.getDimensions(DimensionType.byName("space"));
206+
207+
//Add the Planets to the dimension list
208+
Arrays.stream(plantDims)
209+
.filter(num -> !dims.contains(num))
210+
.filter(num -> definition.getDimensionFilter().test(DimensionManager.createProviderFor(num)))
211+
.forEach(dims::add);
212+
213+
//Add the Asteroids to the dimension list
214+
Arrays.stream(asteroidDims)
215+
.filter(num -> !dims.contains(num))
216+
.filter(num -> definition.getDimensionFilter().test(DimensionManager.createProviderFor(num)))
217+
.forEach(dims::add);
218+
219+
//Remove Space from the dimension list
220+
for (int spaceDim : spaceDims) {
221+
if (dims.contains(spaceDim)) {
222+
dims.remove((Integer) spaceDim);
223+
}
224+
}
225+
}
226+
catch (IllegalArgumentException e) {
227+
GTLog.logger.error("Something went wrong with AR JEI integration, No DimensionType found");
228+
GTLog.logger.error(e);
229+
}
230+
}
231+
232+
return dims;
233+
}
179234
}

src/main/java/gregtech/integration/jei/GTOreInfo.java

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,14 @@
99
import gregtech.api.worldgen.populator.IVeinPopulator;
1010
import gregtech.api.worldgen.populator.SurfaceBlockPopulator;
1111
import gregtech.api.worldgen.populator.SurfaceRockPopulator;
12-
import it.unimi.dsi.fastutil.ints.IntSortedSet;
1312
import mezz.jei.api.ingredients.IIngredients;
1413
import mezz.jei.api.recipe.IRecipeWrapper;
1514
import net.minecraft.block.Block;
1615
import net.minecraft.block.state.IBlockState;
1716
import net.minecraft.client.resources.I18n;
1817
import net.minecraft.init.Items;
1918
import net.minecraft.item.ItemStack;
20-
import net.minecraft.world.DimensionType;
2119
import net.minecraft.world.biome.Biome;
22-
import net.minecraftforge.common.DimensionManager;
2320
import net.minecraftforge.fluids.*;
2421
import org.apache.commons.lang3.tuple.Pair;
2522

@@ -39,13 +36,11 @@ public class GTOreInfo implements IRecipeWrapper {
3936
private final String name;
4037
private final String description;
4138
private final int weight;
42-
private final int[] dimensionIDs;
4339
private final IVeinPopulator veinPopulator;
4440
private final BlockFiller blockFiller;
4541
private List<List<ItemStack>> groupedInputsAsItemStacks = new ArrayList<>();
4642
private List<List<ItemStack>> groupedOutputsAsItemStacks = new ArrayList<>();
4743
private final Function<Biome, Integer> biomeFunction;
48-
private Map<DimensionType, IntSortedSet> dimMap = DimensionManager.getRegisteredDimensions();
4944

5045
public GTOreInfo(OreDepositDefinition definition) {
5146
this.definition = definition;
@@ -83,13 +78,6 @@ public GTOreInfo(OreDepositDefinition definition) {
8378

8479
this.biomeFunction = definition.getBiomeWeightModifier();
8580

86-
//Gather the dimension IDs that the vein can spawn in
87-
dimensionIDs = dimMap.values().stream()
88-
.flatMap(Collection::stream)
89-
.mapToInt(Integer::intValue)
90-
.filter(num -> definition.getDimensionFilter().test(DimensionManager.createProviderFor(num)))
91-
.toArray();
92-
9381
//Group the input ores and the Surface Identifier
9482
List<ItemStack> generatedBlocksAsItemStacks = findComponentBlocksAsItemStacks();
9583
groupedInputsAsItemStacks.add(generatedBlocksAsItemStacks);
@@ -211,7 +199,7 @@ else if(veinPopulator instanceof FluidSpringPopulator) {
211199
}
212200
}
213201

214-
//Should never reach here?
202+
//No defined surface rock
215203
return stack;
216204
}
217205

@@ -326,7 +314,6 @@ public List<String> createOreWeightingTooltip(int slotIndex) {
326314
return tooltip;
327315
}
328316

329-
330317
public int getOutputCount() {
331318
return groupedOutputsAsItemStacks.size();
332319
}
@@ -343,11 +330,11 @@ public int getMinHeight() {
343330
return minHeight;
344331
}
345332

346-
public int[] getDimensionIDs() {
347-
return dimensionIDs;
348-
}
349-
350333
public int getWeight() {
351334
return weight;
352335
}
336+
337+
public OreDepositDefinition getDefinition() {
338+
return definition;
339+
}
353340
}

0 commit comments

Comments
 (0)