Skip to content

Commit

Permalink
fixes (#394)
Browse files Browse the repository at this point in the history
* fixes
fix unification being broken as shit
fix oregen crashing in dimensions with 0 ore veins
make unification data reset on reload

* Update common/src/main/java/com/gregtechceu/gtceu/common/data/GTOres.java

Co-authored-by: Mikerooni <[email protected]>

* Update common/src/main/java/com/gregtechceu/gtceu/api/data/worldgen/ores/OreGenerator.java

Co-authored-by: Mikerooni <[email protected]>

---------

Co-authored-by: Mikerooni <[email protected]>
  • Loading branch information
screret and mikerooni authored Sep 21, 2023
1 parent c03fcc8 commit 361f0e9
Show file tree
Hide file tree
Showing 25 changed files with 150 additions and 102 deletions.
9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# ChangeLog

* fix recipes not loading if a KJS recipe event exists
* set blocks' loot tables to block paramset to improve compatibility
* fix PA recipe issue
* make impure dusts/crushed ores/etc washable in cauldron
* fix issue in tag loading causing some recipes to behave unexpectedly
* fix unification info being kept between reloads
* fix worldgen, veins now generate as they should have been
* fix tool tiers being broken
*
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import com.gregtechceu.gtceu.api.data.chemical.material.stack.MaterialStack;
import com.gregtechceu.gtceu.api.data.chemical.material.stack.UnificationEntry;
import com.gregtechceu.gtceu.api.data.tag.TagPrefix;
import com.gregtechceu.gtceu.common.data.GTBlocks;
import com.gregtechceu.gtceu.common.data.GTItems;
import com.gregtechceu.gtceu.data.tags.TagsHandler;
import com.tterrag.registrate.util.entry.BlockEntry;
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.BuiltInRegistries;
Expand Down Expand Up @@ -57,6 +61,9 @@ public static void registerUnificationItems(UnificationEntry unificationEntry, I
if (item instanceof Block block) {
UNIFICATION_ENTRY_BLOCK.computeIfAbsent(unificationEntry, entry -> new ArrayList<>())
.add(block);
} else if (item instanceof BlockEntry<?> blockEntry) {
UNIFICATION_ENTRY_BLOCK.computeIfAbsent(unificationEntry, entry -> new ArrayList<>())
.add(blockEntry.get());
}
}
}
Expand Down Expand Up @@ -243,4 +250,26 @@ public static List<Map.Entry<ItemStack, ItemMaterialInfo>> getAllItemInfos() {
.map(entry -> new AbstractMap.SimpleEntry<>(new ItemStack(entry.getKey().asItem()), entry.getValue()))
.collect(Collectors.toList());
}

public static void reinitializeUnification() {
// Clear old data
ChemicalHelper.UNIFICATION_ENTRY_ITEM.clear();
ChemicalHelper.UNIFICATION_ENTRY_BLOCK.clear();
ChemicalHelper.ITEM_UNIFICATION_ENTRY.clear();

// Load new data
TagsHandler.initExtraUnificationEntries();
for (TagPrefix prefix : TagPrefix.values()) {
prefix.getIgnored().forEach((mat, items) -> {
if (items.length > 0) {
ChemicalHelper.registerUnificationItems(prefix, mat, items);
}
});
}
GTItems.MATERIAL_ITEMS.rowMap().forEach((prefix, map) -> map.forEach((material, item) -> ChemicalHelper.registerUnificationItems(prefix, material, item.get())));
GTBlocks.MATERIAL_BLOCKS.rowMap().forEach((prefix, map) -> map.forEach((material, block) -> ChemicalHelper.registerUnificationItems(prefix, material, block.get())));
GTBlocks.CABLE_BLOCKS.rowMap().forEach((prefix, map) -> map.forEach((material, block) -> ChemicalHelper.registerUnificationItems(prefix, material, block.get())));
GTBlocks.FLUID_PIPE_BLOCKS.rowMap().forEach((prefix, map) -> map.forEach((material, block) -> ChemicalHelper.registerUnificationItems(prefix, material, block.get())));
// add new stuff here as more maps are added, IDK a better way
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ public record OreType(Supplier<BlockState> stoneType, boolean isNether, boolean
@Setter
private BiConsumer<Material, List<Component>> tooltip;

private final Set<Material> ignoredMaterials = new HashSet<>();
private final Map<Material, ItemLike[]> ignoredMaterials = new HashMap<>();

@Getter
@Setter
Expand Down Expand Up @@ -924,11 +924,21 @@ public static TagPrefix getPrefix(String prefixName, @Nullable TagPrefix replace

@SuppressWarnings("unchecked")
public TagKey<Item>[] getItemTags(@Nonnull Material mat) {
return (Platform.isForge() ? forgeTags : fabricTags).stream().filter(type -> !type.isParentTag()).map(type -> type.getTag(this, mat)).toArray(TagKey[]::new);
}

@SuppressWarnings("unchecked")
public TagKey<Item>[] getAllItemTags(@Nonnull Material mat) {
return (Platform.isForge() ? forgeTags : fabricTags).stream().map(type -> type.getTag(this, mat)).toArray(TagKey[]::new);
}

@SuppressWarnings("unchecked")
public TagKey<Block>[] getBlockTags(@Nonnull Material mat) {
return (Platform.isForge() ? forgeTags : fabricTags).stream().filter(type -> !type.isParentTag()).map(type -> type.getTag(this, mat)).map(itemTagKey -> TagKey.create(Registries.BLOCK, itemTagKey.location())).toArray(TagKey[]::new);
}

@SuppressWarnings("unchecked")
public TagKey<Block>[] getAllBlockTags(@Nonnull Material mat) {
return (Platform.isForge() ? forgeTags : fabricTags).stream().map(type -> type.getTag(this, mat)).map(itemTagKey -> TagKey.create(Registries.BLOCK, itemTagKey.location())).toArray(TagKey[]::new);
}

Expand Down Expand Up @@ -983,11 +993,11 @@ public String getUnlocalizedName(Material material) {
}

public boolean isIgnored(Material material) {
return ignoredMaterials.contains(material);
return ignoredMaterials.containsKey(material);
}

public void setIgnored(Material material, ItemLike... items) {
ignoredMaterials.add(material);
ignoredMaterials.put(material, items);
if (items.length > 0) {
ChemicalHelper.registerUnificationItems(this, material, items);
}
Expand All @@ -997,6 +1007,10 @@ public void removeIgnored(Material material) {
ignoredMaterials.remove(material);
}

public Map<Material, ItemLike[]> getIgnored() {
return new HashMap<>(ignoredMaterials);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.gregtechceu.gtceu.api.data.chemical.material.Material;
import com.gregtechceu.gtceu.utils.FormattingUtil;
import lombok.Getter;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;

Expand All @@ -10,6 +11,8 @@
public class TagType {

private final String tagPath;
@Getter
private boolean isParentTag = false;
private BiFunction<TagPrefix, Material, TagKey<Item>> formatter;

private TagType(String tagPath) {
Expand Down Expand Up @@ -44,12 +47,14 @@ public static TagType withPrefixFormatter(String tagPath) {
public static TagType withPrefixOnlyFormatter(String tagPath) {
TagType type = new TagType(tagPath);
type.formatter = (prefix, mat) -> TagUtil.createItemTag(type.tagPath.formatted(FormattingUtil.toLowerCaseUnderscore(prefix.name)));
type.isParentTag = true;
return type;
}

public static TagType withNoFormatter(String tagPath) {
TagType type = new TagType(tagPath);
type.formatter = (prefix, material) -> TagUtil.createItemTag(type.tagPath);
type.isParentTag = true;
return type;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.gregtechceu.gtceu.api.data.worldgen.BiomeWeightModifier;
import com.gregtechceu.gtceu.api.registry.GTRegistries;
import com.gregtechceu.gtceu.common.data.GTBedrockFluids;
import com.mojang.datafixers.util.Pair;
import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
Expand All @@ -11,7 +12,6 @@
import lombok.experimental.Accessors;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderSet;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.RegistryCodecs;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
Expand Down Expand Up @@ -168,7 +168,7 @@ public Builder biomes(int weight, HolderSet<Biome> biomes) {

public BedrockFluidDefinition register() {
var definition = new BedrockFluidDefinition(weight, minimumYield, maximumYield, depletionAmount, depletionChance, depletedYield, fluid, biomes, dimensions);
GTRegistries.BEDROCK_FLUID_DEFINITIONS.register(name, definition);
GTBedrockFluids.toReRegister.put(name, definition);
return definition;
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@
import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.data.worldgen.GTOreDefinition;
import com.gregtechceu.gtceu.api.data.worldgen.GTOreFeatureConfiguration;
import com.gregtechceu.gtceu.api.data.worldgen.WorldGeneratorUtils;
import com.gregtechceu.gtceu.api.data.worldgen.bedrockore.BedrockOreVeinSavedData;
import com.gregtechceu.gtceu.api.registry.GTRegistries;
import com.gregtechceu.gtceu.config.ConfigHolder;
import com.gregtechceu.gtceu.utils.GTUtil;
import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.XoroshiroRandomSource;
import net.minecraft.world.level.levelgen.placement.PlacementContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.annotation.ParametersAreNonnullByDefault;
import java.util.Map;
Expand Down Expand Up @@ -63,11 +68,12 @@ private Optional<VeinConfiguration> createConfig(WorldGenLevel level, ChunkGener
var entry = config.getEntry(level, level.getBiome(veinCenter), random);
var id = GTRegistries.ORE_VEINS.getKey(entry);

if (entry == null) return null;
BlockPos origin = computeVeinOrigin(level, generator, random, veinCenter, entry).orElseThrow(() ->
new IllegalStateException("Cannot determine y coordinate for the vein at " + veinCenter)
);

return new VeinConfiguration(id, entry, random, origin);
return new VeinConfiguration(id, entry, random, origin);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ public V replace(K key, V value) {
return registry.put(key, value);
}

public V registerOrOverride(K key, V value) {
if (isFrozen) {
throw new IllegalStateException("[register] registry %s has been frozen");
}
return registry.put(key, value);
}

@NotNull
@Override
public Iterator<V> iterator() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ public static void init() {
// fabric exclusive, squeeze this in here to register before stuff is used
GTRegistries.REGISTRATE.registerRegistrate();
WorldGenLayers.registerAll();
GTOres.init();
GTBedrockFluids.init();
GTFeatures.init();
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
package com.gregtechceu.gtceu.common.data;

import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.data.worldgen.GTOreDefinition;
import com.gregtechceu.gtceu.api.data.worldgen.bedrockfluid.BedrockFluidDefinition;
import com.gregtechceu.gtceu.api.registry.GTRegistries;
import com.gregtechceu.gtceu.data.recipe.CustomTags;
import net.minecraft.core.HolderSet;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BiomeTags;
import net.minecraft.world.level.biome.Biomes;
import net.minecraft.world.level.dimension.BuiltinDimensionTypes;
import net.minecraft.world.level.dimension.DimensionType;

import java.util.HashMap;
import java.util.Map;

/**
* @author KilaBash
* @date 2023/7/11
* @implNote GTBedrockFluids
*/
public class GTBedrockFluids {
public static final Map<ResourceLocation, BedrockFluidDefinition> toReRegister = new HashMap<>();


//////////////////////////////////////
//******** OVERWORLD ********//
//////////////////////////////////////
Expand Down Expand Up @@ -116,6 +124,6 @@ public static HolderSet<DimensionType> end() {
}

public static void init() {

toReRegister.forEach(GTRegistries.BEDROCK_FLUID_DEFINITIONS::registerOrOverride);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.data.worldgen.modifier.BiomeFilter;
import com.gregtechceu.gtceu.api.data.worldgen.modifier.BiomePlacement;
import com.gregtechceu.gtceu.api.data.worldgen.modifier.DimensionFilter;
import com.gregtechceu.gtceu.api.data.worldgen.modifier.FrequencyModifier;
Expand All @@ -20,7 +19,6 @@ public class GTFeatures {

public static void init() {
Object inst = FrequencyModifier.FREQUENCY_MODIFIER; // seemingly useless access to init the class in time
inst = BiomeFilter.BIOME_FILTER;
inst = DimensionFilter.DIMENSION_FILTER;
inst = BiomePlacement.BIOME_PLACEMENT;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ public static void init() {
dye.setIgnored(DyeWhite, Items.WHITE_DYE);

// register vanilla materials
registerUnificationItems(ingot, Clay, Items.CLAY_BALL);
/* Adding back the GT ores. It'd be too much pain to replace the loot tables.
ore.setIgnored(Redstone, Blocks.REDSTONE_ORE);
oreDeepslate.setIgnored(Redstone, Blocks.DEEPSLATE_REDSTONE_ORE);
Expand Down
Loading

0 comments on commit 361f0e9

Please sign in to comment.