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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
|
package bwcrossmod.galacticgreg;
import static galacticgreg.registry.GalacticGregRegistry.getModContainers;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;
import net.minecraft.block.Block;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import bartworks.common.configs.Configuration;
import bartworks.system.material.Werkstoff;
import bartworks.system.material.WerkstoffLoader;
import bartworks.system.oregen.BWOreLayer;
import cpw.mods.fml.common.registry.GameRegistry;
import galacticgreg.GalacticGreg;
import galacticgreg.WorldgenOreLayerSpace;
import galacticgreg.WorldgenOreSmallSpace;
import galacticgreg.api.ModContainer;
import galacticgreg.api.ModDimensionDef;
import gregtech.api.GregTechAPI;
import gregtech.api.enums.Materials;
import gregtech.api.interfaces.ISubTagContainer;
import gregtech.api.util.GTUtility;
import gregtech.common.WorldgenGTOreLayer;
import gregtech.common.WorldgenGTOreSmallPieces;
public class VoidMinerUtility {
public static final FluidStack[] NOBLE_GASSES = { WerkstoffLoader.Neon.getFluidOrGas(1),
WerkstoffLoader.Krypton.getFluidOrGas(1), WerkstoffLoader.Xenon.getFluidOrGas(1),
WerkstoffLoader.Oganesson.getFluidOrGas(1) };
public static final int[] NOBEL_GASSES_MULTIPLIER = { 4, 8, 16, 64 };
public static class DropMap {
private float totalWeight;
private final Map<GTUtility.ItemId, Float> internalMap;
private final Set<String> voidMinerBlacklistedDrops;
public DropMap() {
internalMap = new HashMap<>();
totalWeight = 0;
voidMinerBlacklistedDrops = Collections
.unmodifiableSet(new HashSet<>(Arrays.asList(Configuration.multiblocks.voidMinerBlacklist)));
}
/**
* Method used to add an ore to the DropMap
*
* @param weight the non normalised weight
* @param isBWOres true for BW ores, false for GT ores
*/
public void addDrop(int meta, float weight, boolean isBWOres) {
if (isBWOres) {
addDrop(WerkstoffLoader.BWOres, meta, weight);
} else {
addDrop(GregTechAPI.sBlockOres1, meta, weight);
}
}
/**
* Method used to add any item to the DropMap. Will be blocked if blacklisted.
*
* @param weight the non normalised weight
*/
public void addDrop(Block block, int meta, float weight) {
if (this.voidMinerBlacklistedDrops.contains(
String.format(
"%s:%d",
GameRegistry.findUniqueIdentifierFor(block)
.toString(),
meta)))
return;
Item item = Item.getItemFromBlock(block);
addDrop(item, meta, weight);
}
/**
* Method used to add any item to the DropMap. Will be blocked if blacklisted.
*
* @param weight the non normalised weight
*/
public void addDrop(ItemStack itemStack, float weight) {
Item item = itemStack.getItem();
int meta = Items.feather.getDamage(itemStack);
if (this.voidMinerBlacklistedDrops.contains(
String.format(
"%s:%d",
GameRegistry.findUniqueIdentifierFor(Block.getBlockFromItem(item))
.toString(),
meta)))
return;
addDrop(item, meta, weight);
}
private void addDrop(Item item, int meta, float weight) {
GTUtility.ItemId ore = GTUtility.ItemId.createNoCopy(item, meta, null);
internalMap.merge(ore, weight, Float::sum);
totalWeight += weight;
}
public float getTotalWeight() {
return totalWeight;
}
public Map<GTUtility.ItemId, Float> getInternalMap() {
return internalMap;
}
}
public static final Map<Integer, DropMap> dropMapsByDimId = new HashMap<>();
public static final Map<String, DropMap> dropMapsByChunkProviderName = new HashMap<>();
public static final Map<Integer, DropMap> extraDropsDimMap = new HashMap<>();
// Adds tellurium to OW to ensure a way to get it, as it's used in Magneto Resonatic
// Dust and Circuit Compound MK3 Dust
static {
addMaterialToDimensionList(0, Materials.Tellurium, 8.0f);
}
/**
* Computes the ores of the dims
*/
public static void generateDropMaps() {
// vanilla dims
dropMapsByDimId.put(-1, getDropMapVanilla(-1));
dropMapsByDimId.put(0, getDropMapVanilla(0));
dropMapsByDimId.put(1, getDropMapVanilla(1));
// Twilight Forest
dropMapsByDimId.put(7, getDropMapVanilla(7));
// ross dims
dropMapsByDimId.put(
Configuration.crossModInteractions.ross128BID,
getDropMapRoss(Configuration.crossModInteractions.ross128BID));
dropMapsByDimId.put(
Configuration.crossModInteractions.ross128BAID,
getDropMapRoss(Configuration.crossModInteractions.ross128BAID));
// other space dims
for (ModContainer modContainer : getModContainers()) {
for (ModDimensionDef dimDef : modContainer.getDimensionList()) {
dropMapsByChunkProviderName.put(dimDef.getChunkProviderName(), getDropMapSpace(dimDef));
}
}
}
/**
* Method to generate a DropMap that contains ores of a vanilla GT worldgen
*/
private static DropMap getDropMapVanilla(int dimId) {
DropMap dropMap = new DropMap();
// Ore Veins
Predicate<WorldgenGTOreLayer> oreLayerPredicate = makeOreLayerPredicate(dimId);
WorldgenGTOreLayer.sList.stream()
.filter(gt_worldgen -> gt_worldgen.mEnabled && oreLayerPredicate.test(gt_worldgen))
.forEach(element -> {
dropMap.addDrop(element.mPrimaryMeta, element.mWeight, false);
dropMap.addDrop(element.mSecondaryMeta, element.mWeight, false);
dropMap.addDrop(element.mSporadicMeta, element.mWeight / 8f, false);
dropMap.addDrop(element.mBetweenMeta, element.mWeight / 8f, false);
});
// Small Ores
Predicate<WorldgenGTOreSmallPieces> smallOresPredicate = makeSmallOresPredicate(dimId);
WorldgenGTOreSmallPieces.sList.stream()
.filter(gt_worldgen -> gt_worldgen.mEnabled && smallOresPredicate.test(gt_worldgen))
.forEach(element -> dropMap.addDrop(element.mMeta, element.mAmount, false));
return dropMap;
}
/**
* Makes a predicate for the GT normal ore veins worldgen
*
* @return the predicate
*/
private static Predicate<WorldgenGTOreLayer> makeOreLayerPredicate(int dimensionId) {
return switch (dimensionId) {
case -1 -> gt_worldgen -> gt_worldgen.mNether;
case 0 -> gt_worldgen -> gt_worldgen.mOverworld;
case 1 -> gt_worldgen -> gt_worldgen.mEnd || gt_worldgen.mEndAsteroid;
case 7 -> gt_worldgen -> gt_worldgen.twilightForest;
default -> throw new IllegalStateException();
};
}
/**
* Makes a predicate for the GT normal small ore worldgen
*
* @return the predicate
*/
private static Predicate<WorldgenGTOreSmallPieces> makeSmallOresPredicate(int dimensionId) {
return switch (dimensionId) {
case -1 -> gt_worldgen -> gt_worldgen.mNether;
case 0 -> gt_worldgen -> gt_worldgen.mOverworld;
case 1 -> gt_worldgen -> gt_worldgen.mEnd;
case 7 -> gt_worldgen -> gt_worldgen.twilightForest;
default -> throw new IllegalStateException();
};
}
/**
* Create a DropMap that contains ores of Ross dims
*
* @param aID dim id of Ross128b or Ross128ba
*/
private static DropMap getDropMapRoss(int aID) {
DropMap dropMap = new DropMap();
for (BWOreLayer oreLayer : BWOreLayer.sList) {
if (oreLayer.mEnabled && oreLayer.isGenerationAllowed("", aID, 0)) {
List<ItemStack> data = oreLayer.getStacks();
dropMap.addDrop(data.get(0), oreLayer.mWeight);
dropMap.addDrop(data.get(1), oreLayer.mWeight);
dropMap.addDrop(data.get(2), oreLayer.mWeight / 8f);
dropMap.addDrop(data.get(3), oreLayer.mWeight / 8f);
}
}
return dropMap;
}
/**
* Create a DropMap contains the ores from the galacticGreg space worldgen corresponding to the target dim
*
* @param finalDef ModDimensionDef corresponding to the target dim
*/
private static DropMap getDropMapSpace(ModDimensionDef finalDef) {
DropMap dropMap = new DropMap();
// Normal Ore Veins
GalacticGreg.oreVeinWorldgenList.stream()
.filter(
gt_worldgen -> gt_worldgen.mEnabled && gt_worldgen instanceof WorldgenOreLayerSpace oreLayerSpace
&& oreLayerSpace.isEnabledForDim(finalDef))
.map(gt_worldgen -> (WorldgenOreLayerSpace) gt_worldgen)
.forEach(element -> {
dropMap.addDrop(element.mPrimaryMeta, element.mWeight, false);
dropMap.addDrop(element.mSecondaryMeta, element.mWeight, false);
dropMap.addDrop(element.mSporadicMeta, element.mWeight / 8f, false);
dropMap.addDrop(element.mBetweenMeta, element.mWeight / 8f, false);
});
// Normal Small Ores
GalacticGreg.smallOreWorldgenList.stream()
.filter(
gt_worldgen -> gt_worldgen.mEnabled && gt_worldgen instanceof WorldgenOreSmallSpace oreSmallPiecesSpace
&& oreSmallPiecesSpace.isEnabledForDim(finalDef))
.map(gt_worldgen -> (WorldgenOreSmallSpace) gt_worldgen)
.forEach(element -> dropMap.addDrop(element.mMeta, element.mAmount, false));
return dropMap;
}
public static void addBlockToDimensionList(int dimId, Block block, int meta, float weight) {
if (!extraDropsDimMap.containsKey(dimId)) {
extraDropsDimMap.put(dimId, new DropMap());
}
extraDropsDimMap.get(dimId)
.addDrop(block, meta, weight);
}
/**
* Public method giving other mods the ability to add manually a material with an ore version into the external
* dropMap for a specified dim id
*
* @param DimensionID the dim id targeted
* @param Material the material with an ore version
* @param weight the non normalised version of the given weight
*/
public static void addMaterialToDimensionList(int DimensionID, ISubTagContainer Material, float weight) {
if (Material instanceof Materials gtMaterial) {
addBlockToDimensionList(DimensionID, GregTechAPI.sBlockOres1, gtMaterial.mMetaItemSubID, weight);
} else if (Material instanceof Werkstoff werkstoff) {
addBlockToDimensionList(DimensionID, WerkstoffLoader.BWOres, werkstoff.getmID(), weight);
}
}
}
|