Skip to content

Commit

Permalink
Cherrypick #481, #482, #489, #490 (#492)
Browse files Browse the repository at this point in the history
* Added KJS Binder for GCyM stuff (#481)

* GCyM Kjs Binders

* removed gcym mats

* "fix" #480 (#482)

* "fix" #480

* memoize this cuz why not, should? speed it up.

* fixed molten watertight steel missing (#489)

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

* fixes (#490)

* fix: SoundEntryProvider uses the wrong modid if you don't call it from GT.

* fix: material tooltips on non-GT items.

* fix: add ChemicalHelper to KJS bindings

* fix: stone can be crafted to dust in crafting table, other issues like that

* fix: tools only have "digger" enchantments

* fix #488

* try to fix #458

* chore: changelog, version bump

* revert fix. didn't fix.

* feat: fluid tooltips (untested this laptop is too slow)

* feat: fluid tooltips (untested this laptop is too slow)

* final fixes to stuff
stop adding tooltips to other mods' items as a temp fix to it being _really_ slow to compute

* todo comment

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

* Update common/src/main/java/com/gregtechceu/gtceu/api/data/chemical/ChemicalHelper.java

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

---------

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

---------

Co-authored-by: Drackion <[email protected]>
Co-authored-by: screret <[email protected]>
Co-authored-by: Arbor <[email protected]>
Co-authored-by: Arborsm <[email protected]>
  • Loading branch information
5 people authored Oct 25, 2023
1 parent 8677e4a commit 9815cdf
Show file tree
Hide file tree
Showing 26 changed files with 331 additions and 35 deletions.
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# ChangeLog

* fix feature order cycle on fabric
* make some API methods more addon dev friendly
* add tags for all purified/refined ores
* fix tools only accepting digger enchantments
* fix stone, netherrack, hay being craftable to 9 dust in a crafting table
* fix machines sometimes crashing when auto-output is toggled rapidly, resulting in it being enabled but no output side being set
* fix SoundEntryProvider always placing the JSON in /assets/gtceu/sounds.json
* add material tooltips for non-GT items
* add KJS binding for ChemicalHelper
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.gregtechceu.gtceu.api.block;

import com.gregtechceu.gtceu.client.renderer.block.MaterialBlockRenderer;
import com.gregtechceu.gtceu.api.data.chemical.material.Material;
import com.gregtechceu.gtceu.api.data.tag.TagPrefix;
import com.gregtechceu.gtceu.client.renderer.block.MaterialBlockRenderer;
import com.gregtechceu.gtceu.config.ConfigHolder;
import com.lowdragmc.lowdraglib.Platform;
import com.lowdragmc.lowdraglib.client.renderer.IBlockRendererProvider;
Expand Down Expand Up @@ -102,9 +102,7 @@ public void tick(BlockState state, ServerLevel level, BlockPos pos, RandomSource
@Override
public void animateTick(BlockState state, Level level, BlockPos pos, RandomSource random) {
if (!TagPrefix.ORES.containsKey(this.tagPrefix) || super.material != net.minecraft.world.level.material.Material.SAND || !ConfigHolder.INSTANCE.worldgen.sandOresFall) return;

BlockPos blockPos;
if (random.nextInt(16) == 0 && FallingBlock.isFree(level.getBlockState(blockPos = pos.below()))) {
if (random.nextInt(16) == 0 && FallingBlock.isFree(level.getBlockState(pos.below()))) {
double d = (double)pos.getX() + random.nextDouble();
double e = (double)pos.getY() - 0.05;
double f = (double)pos.getZ() + random.nextDouble();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
package com.gregtechceu.gtceu.api.data.chemical;

import com.gregtechceu.gtceu.api.data.chemical.material.Material;
import com.gregtechceu.gtceu.api.data.chemical.material.properties.FluidProperty;
import com.gregtechceu.gtceu.api.data.chemical.material.properties.PropertyKey;
import com.gregtechceu.gtceu.api.data.chemical.material.stack.ItemMaterialInfo;
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.api.data.tag.TagUtil;
import com.gregtechceu.gtceu.api.fluids.store.FluidStorageKey;
import com.gregtechceu.gtceu.api.registry.GTRegistries;
import com.gregtechceu.gtceu.common.data.GTBlocks;
import com.gregtechceu.gtceu.common.data.GTItems;
import com.gregtechceu.gtceu.data.tags.TagsHandler;
import com.lowdragmc.lowdraglib.Platform;
import com.tterrag.registrate.util.entry.BlockEntry;
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.Fluids;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -38,12 +46,16 @@ public class ChemicalHelper {
/** Used for custom material data for items that do not fall into the normal "prefix, material" pair */
public static final Map<ItemLike, ItemMaterialInfo> ITEM_MATERIAL_INFO = new Object2ObjectLinkedOpenHashMap<>();
/** Mapping of an item to a "prefix, material" pair */
public static final Map<ItemLike, UnificationEntry> ITEM_UNIFICATION_ENTRY = new HashMap<>();
public static final Map<ItemLike, UnificationEntry> ITEM_UNIFICATION_ENTRY = new Object2ObjectLinkedOpenHashMap<>();
/** Mapping of a tag to a "prefix, material" pair */
public static final Map<TagKey<Item>, UnificationEntry> TAG_UNIFICATION_ENTRY = new Object2ObjectLinkedOpenHashMap<>();
/** Mapping of a fluid to a material */
public static final Map<Fluid, Material> FLUID_MATERIAL = new Object2ObjectLinkedOpenHashMap<>();
/** Mapping of all items that represent a "prefix, material" pair */
public static final Map<UnificationEntry, ArrayList<ItemLike>> UNIFICATION_ENTRY_ITEM = new Object2ObjectLinkedOpenHashMap<>();
public static final Map<UnificationEntry, ArrayList<Block>> UNIFICATION_ENTRY_BLOCK = new Object2ObjectLinkedOpenHashMap<>();
/** Mapping of stone type blockState to "prefix, material" */
public static final Map<Supplier<BlockState>, TagPrefix> ORES_INVERSE = new HashMap<>();
public static final Map<Supplier<BlockState>, TagPrefix> ORES_INVERSE = new Object2ObjectLinkedOpenHashMap<>();

public static void registerMaterialInfo(ItemLike item, ItemMaterialInfo materialInfo) {
ITEM_MATERIAL_INFO.put(item, materialInfo);
Expand Down Expand Up @@ -105,6 +117,27 @@ public static MaterialStack getMaterial(ItemLike itemLike) {
return info == null ? null : info.getMaterial().copy();
}

@Nullable
public static Material getMaterial(Fluid fluid) {
return FLUID_MATERIAL.computeIfAbsent(fluid, f -> {
for (Material material : GTRegistries.MATERIALS) {
if (material.hasProperty(PropertyKey.FLUID)) {
FluidProperty property = material.getProperty(PropertyKey.FLUID);
for (FluidStorageKey key : FluidStorageKey.allKeys()) {
Fluid stored = property.getStorage().get(key);
TagKey<Fluid> tag = TagUtil.createFluidTag(Registry.FLUID.getKey(stored).getPath());
if (!Platform.isForge() && tag.location().equals(new ResourceLocation("water")) && !stored.isSame(Fluids.WATER)) continue;
if (!Platform.isForge() && tag.location().equals(new ResourceLocation("lava")) && !stored.isSame(Fluids.LAVA)) continue;
if (f == stored || f.is(tag)) {
return material;
}
}
}
}
return null;
});
}

@Nullable
public static TagPrefix getPrefix(ItemLike itemLike) {
if (itemLike == null) return null;
Expand Down Expand Up @@ -169,6 +202,29 @@ public static UnificationEntry getUnificationEntry(ItemLike item) {
return ITEM_UNIFICATION_ENTRY.get(item);
}

// TODO optimize this so it can be used in tooltips/etc.
public static UnificationEntry getUnificationEntry(TagKey<Item> tag) {
return TAG_UNIFICATION_ENTRY.computeIfAbsent(tag, tagKey -> {
for (TagPrefix prefix : TagPrefix.values()) {
for (Material material : GTRegistries.MATERIALS) {
if (Arrays.stream(prefix.getItemTags(material)).anyMatch(tagKey1 -> tagKey1.location().equals(tagKey.location()))) {
return new UnificationEntry(prefix, material);
}
}
}
return new UnificationEntry.EmptyMapMarkerEntry();
});
}

@Nullable
public static UnificationEntry getOrComputeUnificationEntry(ItemLike item) {
return ITEM_UNIFICATION_ENTRY.computeIfAbsent(item, itemLike -> {
Holder<Item> holder = Registry.ITEM.getOrCreateHolderOrThrow(Registry.ITEM.getResourceKey(itemLike.asItem()).orElseThrow());
return holder.tags().map(ChemicalHelper::getUnificationEntry).filter(Objects::nonNull)
.filter(entry -> !(entry instanceof UnificationEntry.EmptyMapMarkerEntry)).findFirst().orElse(null);
});
}

public static List<ItemLike> getItems(UnificationEntry unificationEntry) {
return UNIFICATION_ENTRY_ITEM.computeIfAbsent(unificationEntry, entry -> {
var items = new ArrayList<ItemLike>();
Expand Down Expand Up @@ -260,6 +316,7 @@ public static void reinitializeUnification() {
ChemicalHelper.UNIFICATION_ENTRY_ITEM.clear();
ChemicalHelper.UNIFICATION_ENTRY_BLOCK.clear();
ChemicalHelper.ITEM_UNIFICATION_ENTRY.clear();
ChemicalHelper.FLUID_MATERIAL.clear();

// Load new data
TagsHandler.initExtraUnificationEntries();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,25 @@ public String toString() {
return tagPrefix.name + (material != null ? material.toCamelCaseString() : "");
}

public static class EmptyMapMarkerEntry extends UnificationEntry {

public EmptyMapMarkerEntry() {
super(null);
}

@Override
public boolean equals(Object o) {
return this == o;
}

@Override
public int hashCode() {
return 0;
}

@Override
public String toString() {
return "EMPTY UNIFICATION ENTRY";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,14 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.*;
import java.util.function.*;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.function.Supplier;

import static com.gregtechceu.gtceu.api.data.tag.TagPrefix.Conditions.*;
import static com.gregtechceu.gtceu.api.data.tag.TagPrefix.LoaderType.*;
import static com.gregtechceu.gtceu.api.data.tag.TagPrefix.LoaderType.FABRIC;
import static com.gregtechceu.gtceu.api.data.tag.TagPrefix.LoaderType.FORGE;

@Accessors(chain = true, fluent = true)
public class TagPrefix {
Expand All @@ -71,7 +75,7 @@ public static TagPrefix get(String name) {
return PREFIXES.get(name);
}

public static final TagPrefix ore = oreTagPrefix("stone")
public static final TagPrefix ore = oreTagPrefix("ore")
.langValue("%s Ore")
.materialIconType(MaterialIconType.ore)
.miningToolTag(BlockTags.MINEABLE_WITH_PICKAXE)
Expand Down Expand Up @@ -686,6 +690,14 @@ public static TagPrefix get(String name) {
.miningToolTag(BlockTags.MINEABLE_WITH_PICKAXE)
.unificationEnabled(true);

// Prefix to determine which kind of Rock this is.
public static final TagPrefix stone = new TagPrefix("stone")
.defaultTagPath(FORGE, "%s")
.defaultTagPath(FABRIC, "%s")
.langValue("%s")
.miningToolTag(BlockTags.MINEABLE_WITH_PICKAXE)
.unificationEnabled(true);

public static final TagPrefix frameGt = new TagPrefix("frameGt")
.defaultTagPath(FORGE, "frames/%s")
.defaultTagPath(FABRIC, "%s_frames")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void scan(String[][][] storage, LevelChunk chunk) {
if (state.is(oreTag)) {
var itemName = BLOCK_CACHE.computeIfAbsent(state, blockState -> {
var name = Registry.BLOCK.getKey(blockState.getBlock()).toString();
var entry = ChemicalHelper.getUnificationEntry(blockState.getBlock());
var entry = ChemicalHelper.getOrComputeUnificationEntry(blockState.getBlock());
if (entry != null && entry.material != null) {
name = "material_" + entry.material.getName();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public void exportToNearby(Direction... facings) {
var level = getMachine().getLevel();
var pos = getMachine().getPos();
for (Direction facing : facings) {
if (facing == null) continue; // TODO find actual fix
ItemTransferHelper.exportToTarget(this, Integer.MAX_VALUE, f -> true, level, pos.relative(facing), facing.getOpposite());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import com.google.gson.JsonObject;
import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.sound.CustomSoundEntry;
import com.gregtechceu.gtceu.api.sound.SoundEntry;
import com.gregtechceu.gtceu.api.registry.GTRegistries;
import com.gregtechceu.gtceu.api.sound.ConfiguredSoundEvent;
import com.gregtechceu.gtceu.api.sound.CustomSoundEntry;
import com.gregtechceu.gtceu.api.sound.SoundEntry;
import com.gregtechceu.gtceu.api.sound.WrappedSoundEntry;
import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.data.CachedOutput;
Expand All @@ -18,7 +18,8 @@
import javax.annotation.ParametersAreNonnullByDefault;
import java.io.IOException;
import java.nio.file.Path;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;

/**
Expand All @@ -41,7 +42,7 @@ public SoundEntryProvider(DataGenerator generator, String modId) {

@Override
public void run(CachedOutput cache) {
generate(generator.getOutputFolder(), cache);
generate(generator.getOutputFolder().resolve(modId), cache);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.material.Fluid;

import java.util.List;

Expand All @@ -37,7 +38,7 @@ public static void appendTooltips(ItemStack stack, TooltipFlag flag, List<Compon
}

// Formula
var unificationEntry = ChemicalHelper.getUnificationEntry(stack.getItem());
var unificationEntry = ChemicalHelper.getUnificationEntry(stack.getItem()); // TODO optimize getOrComputeUnificationEntry so we can use that
if (unificationEntry != null && unificationEntry.material != null) {
if (unificationEntry.material.getChemicalFormula() != null && !unificationEntry.material.getChemicalFormula().isEmpty())
tooltips.add(1, Component.literal(unificationEntry.material.getChemicalFormula()).withStyle(ChatFormatting.YELLOW));
Expand All @@ -57,4 +58,12 @@ public static void appendTooltips(ItemStack stack, TooltipFlag flag, List<Compon
}
}
}

public static void appendFluidTooltips(Fluid fluid, List<Component> tooltips, TooltipFlag flag) {
var material = ChemicalHelper.getMaterial(fluid);
if (material != null) {
if (material.getChemicalFormula() != null && !material.getChemicalFormula().isEmpty())
tooltips.add(1, Component.literal(material.getChemicalFormula()).withStyle(ChatFormatting.YELLOW));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gregtechceu.gtceu.client.renderer.block;

import com.google.common.base.Suppliers;
import com.gregtechceu.gtceu.client.model.ItemBakedModel;
import com.lowdragmc.lowdraglib.LDLib;
import com.lowdragmc.lowdraglib.client.bakedpipeline.FaceQuad;
Expand Down Expand Up @@ -44,7 +45,7 @@ public class OreBlockRenderer extends BlockStateRenderer {
private final boolean emissive;

public OreBlockRenderer(Supplier<BlockState> stone, Supplier<ResourceLocation> overlaySupplier, boolean emissive) {
this.stone = stone;
this.stone = Suppliers.memoize(stone::get);
this.overlaySupplier = overlaySupplier;
this.emissive = emissive;
if (LDLib.isClient()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,7 @@ public static void init() {
block.setIgnored(Coal, Blocks.COAL_BLOCK);
block.setIgnored(Amethyst, Blocks.AMETHYST_BLOCK);
block.setIgnored(Glass, Blocks.GLASS);
block.setIgnored(Marble);
block.setIgnored(Granite, Blocks.GRANITE);
block.setIgnored(GraniteRed);
block.setIgnored(Andesite, Blocks.ANDESITE);
block.setIgnored(Diorite, Blocks.DIORITE);
block.setIgnored(Stone, Blocks.STONE);
block.setIgnored(Glowstone, Blocks.GLOWSTONE);
block.setIgnored(Endstone, Blocks.END_STONE);
block.setIgnored(Wheat, Blocks.HAY_BLOCK);
block.setIgnored(Oilsands);
block.setIgnored(Wood);
block.setIgnored(TreatedWood);
Expand All @@ -207,13 +199,24 @@ public static void init() {
block.setIgnored(Bone, Blocks.BONE_BLOCK);
block.setIgnored(NetherQuartz, Blocks.QUARTZ_BLOCK);
block.setIgnored(Ice, Blocks.ICE);
block.setIgnored(Netherrack, Blocks.NETHERRACK);
block.setIgnored(Concrete, Blocks.WHITE_CONCRETE, Blocks.ORANGE_CONCRETE, Blocks.MAGENTA_CONCRETE, Blocks.LIGHT_BLUE_CONCRETE, Blocks.YELLOW_CONCRETE, Blocks.LIME_CONCRETE,
Blocks.PINK_CONCRETE, Blocks.GRAY_CONCRETE, Blocks.LIGHT_GRAY_CONCRETE, Blocks.CYAN_CONCRETE, Blocks.PURPLE_CONCRETE, Blocks.BLUE_CONCRETE,
Blocks.BROWN_CONCRETE, Blocks.GREEN_CONCRETE, Blocks.RED_CONCRETE, Blocks.BLACK_CONCRETE);
block.setIgnored(Blaze);
block.setIgnored(Lapotron);
block.setIgnored(Obsidian, Blocks.OBSIDIAN);

stone.setIgnored(Marble);
stone.setIgnored(Granite, Blocks.GRANITE);
stone.setIgnored(Granite, Blocks.POLISHED_GRANITE);
stone.setIgnored(GraniteRed);
stone.setIgnored(Andesite, Blocks.ANDESITE);
stone.setIgnored(Andesite, Blocks.POLISHED_ANDESITE);
stone.setIgnored(Diorite, Blocks.DIORITE);
stone.setIgnored(Diorite, Blocks.POLISHED_DIORITE);
stone.setIgnored(Stone, Blocks.STONE);
stone.setIgnored(Netherrack, Blocks.NETHERRACK);
stone.setIgnored(Obsidian, Blocks.OBSIDIAN);
stone.setIgnored(Endstone, Blocks.END_STONE);

crushed.addSecondaryMaterial(new MaterialStack(Stone, dust.materialAmount()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void register() {
.buildAndRegister();

WatertightSteel = new Material.Builder("watertight_steel")
.ingot(4)
.ingot(4).fluid()
.color(0x2B4B56).iconSet(METALLIC)
.appendFlags(STD_METAL, GENERATE_PLATE, GENERATE_ROD, GENERATE_FRAME)
.components(Iron, 7, Aluminium, 4, Nickel, 2, Chromium, 1, Sulfur, 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,22 @@ public String getRefMapperConfig() {

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
if (mixinClassName.contains("com.gregtechceu.gtceu.core.mixins.kjs")) {
if (mixinClassName.contains("com.gregtechceu.gtceu.core.mixins.kjs") || mixinClassName.contains("com.gregtechceu.gtceu.core.mixins.rhino")) {
return MixinPluginShared.isClassFound("dev.latvian.mods.kubejs.KubeJSPlugin");
} else if (mixinClassName.contains("com.gregtechceu.gtceu.core.mixins.create")) {
return MixinPluginShared.isClassFound("com.simibubi.create.compat.Mods");
} else if (mixinClassName.contains("com.gregtechceu.gtceu.core.mixins.rei")) {
return MixinPluginShared.isClassFound("me.shedaniel.rei.api.common.plugins.REIPlugin");
} else if (mixinClassName.contains("com.gregtechceu.gtceu.fabric.core.mixins.kjs")) {
return MixinPluginShared.isClassFound("dev.latvian.mods.kubejs.fabric.KubeJSFabric");
} else if (mixinClassName.contains("com.gregtechceu.gtceu.forge.core.mixins.kjs")) {
return MixinPluginShared.isClassFound("dev.latvian.mods.kubejs.forge.KubeJSForge");
} else if (mixinClassName.contains("com.gregtechceu.gtceu.core.mixins.top")) {
return MixinPluginShared.isClassFound("mcjty.theoneprobe.api.ITheOneProbe");
} else if (mixinClassName.contains("com.gregtechceu.gtceu.forge.core.mixins.jei")) {
return MixinPluginShared.isClassFound("mezz.jei.api.IModPlugin");
}else if (mixinClassName.contains("com.gregtechceu.gtceu.forge.core.mixins.emi")) {
return MixinPluginShared.isClassFound("dev.emi.emi.api.EmiPlugin");
}
return true;
}
Expand Down
Loading

0 comments on commit 9815cdf

Please sign in to comment.