Skip to content

Commit

Permalink
recipeviewer page fixes and additions (#1857)
Browse files Browse the repository at this point in the history
  • Loading branch information
screret authored Sep 1, 2024
1 parent d7fe0f1 commit d881009
Show file tree
Hide file tree
Showing 29 changed files with 376 additions and 78 deletions.
6 changes: 3 additions & 3 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ dependencies {
modImplementation forge.flywheel

// JEI
modImplementation(forge.jei.common.api) { transitive = false }
modImplementation(forge.jei.forge.api) { transitive = false }
modImplementation(forge.jei.forge.impl) { transitive = false }
modCompileOnly(forge.jei.common.api) { transitive = false }
modCompileOnly(forge.jei.forge.api) { transitive = false }
modCompileOnly(forge.jei.forge.impl) { transitive = false }

// REI
modCompileOnly forge.rei.plugin
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dependencyResolutionManagement {
def vineFlowerVersion = "1.+"
def macheteVersion = "1.+"
def configurationVersion = "2.2.0"
def ldLibVersion = "1.0.27.a"
def ldLibVersion = "1.0.27.b"
def mixinextrasVersion = "0.2.0"
def shimmerVersion = "0.2.4"
def lombokPluginVersion = "8.7.1"
Expand Down
1 change: 1 addition & 0 deletions src/generated/resources/assets/gtceu/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -2847,6 +2847,7 @@
"gtceu.jei.bedrock_fluid.raw_oil_deposit": "ʇısodǝᗡ ןıO ʍɐᴚ",
"gtceu.jei.bedrock_fluid.salt_water_deposit": "ʇısodǝᗡ ɹǝʇɐM ʇןɐS",
"gtceu.jei.bedrock_fluid_diagram": "ɯɐɹbɐıᗡ pınןℲ ʞɔoɹpǝᗺ",
"gtceu.jei.bedrock_ore_diagram": "ɯɐɹbɐıᗡ ǝɹO ʞɔoɹpǝᗺ",
"gtceu.jei.fluid.dep_amount_hover": "ʎq pǝʇǝןdǝp ǝq ןןıʍ uıǝʌ ǝɥʇ ʇunoɯɐ ǝɥ⟘",
"gtceu.jei.fluid.dep_chance_hover": "ʇsǝʌɹɐɥ uodn pǝʇǝןdǝp ǝq oʇ uıǝʌ ǝɥʇ ɹoɟ ǝɔuɐɥɔ ǝbɐʇuǝɔɹǝd ǝɥ⟘",
"gtceu.jei.fluid.dep_yield_hover": "pǝʇǝןdǝp ʎןןnɟ sı ʇı uǝɥʍ uıǝʌ ǝɥʇ ɟo pןǝıʎ ɯnɯıxɐɯ ǝɥ⟘",
Expand Down
1 change: 1 addition & 0 deletions src/generated/resources/assets/gtceu/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -2847,6 +2847,7 @@
"gtceu.jei.bedrock_fluid.raw_oil_deposit": "Raw Oil Deposit",
"gtceu.jei.bedrock_fluid.salt_water_deposit": "Salt Water Deposit",
"gtceu.jei.bedrock_fluid_diagram": "Bedrock Fluid Diagram",
"gtceu.jei.bedrock_ore_diagram": "Bedrock Ore Diagram",
"gtceu.jei.fluid.dep_amount_hover": "The amount the vein will be depleted by",
"gtceu.jei.fluid.dep_chance_hover": "The percentage chance for the vein to be depleted upon harvest",
"gtceu.jei.fluid.dep_yield_hover": "The maximum yield of the vein when it is fully depleted",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ public Integer apply(Holder<Biome> biome) {
};
}

public List<Integer> getAllChances() {
return materials().stream().map(Pair::getSecond).toList();
}

public List<Material> getAllMaterials() {
return materials().stream().map(Pair::getFirst).toList();
}

public static Builder builder(ResourceLocation name) {
return new Builder(name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ private static void initRecipeViewerLang(RegistrateLangProvider provider) {
provider.add("gtceu.jei.ore_processing_diagram", "Ore Processing Diagram");
provider.add("gtceu.jei.ore_vein_diagram", "Ore Vein Diagram");
provider.add("gtceu.jei.bedrock_fluid_diagram", "Bedrock Fluid Diagram");
provider.add("gtceu.jei.bedrock_ore_diagram", "Bedrock Ore Diagram");
provider.add("gtceu.jei.ore_vein_diagram.chance", "§eChance: %s§r");
provider.add("gtceu.jei.ore_vein_diagram.spawn_range", "Spawn Range:");
provider.add("gtceu.jei.ore_vein_diagram.weight", "Weight: %s");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@
import com.gregtechceu.gtceu.api.data.worldgen.bedrockfluid.BedrockFluidDefinition;
import com.gregtechceu.gtceu.api.registry.GTRegistries;
import com.gregtechceu.gtceu.common.data.GTBedrockFluids;
import com.gregtechceu.gtceu.common.network.GTNetwork;
import com.gregtechceu.gtceu.common.network.packets.SPacketSyncBedrockOreVeins;
import com.gregtechceu.gtceu.integration.kjs.GTCEuServerEvents;
import com.gregtechceu.gtceu.integration.kjs.events.GTFluidVeinEventJS;

import com.lowdragmc.lowdraglib.Platform;

import net.minecraft.resources.RegistryOps;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
Expand Down Expand Up @@ -78,11 +74,6 @@ protected void apply(Map<ResourceLocation, JsonElement> resourceList, ResourceMa
if (!GTRegistries.BEDROCK_FLUID_DEFINITIONS.isFrozen()) {
GTRegistries.BEDROCK_FLUID_DEFINITIONS.freeze();
}

if (Platform.getMinecraftServer() != null) {
GTNetwork.NETWORK
.sendToAll(new SPacketSyncBedrockOreVeins(GTRegistries.BEDROCK_ORE_DEFINITIONS.registry()));
}
}

public static BedrockFluidDefinition fromJson(ResourceLocation id, JsonObject json, RegistryOps<JsonElement> ops) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import com.gregtechceu.gtceu.api.addon.IGTAddon;
import com.gregtechceu.gtceu.api.data.worldgen.bedrockore.BedrockOreDefinition;
import com.gregtechceu.gtceu.api.registry.GTRegistries;
import com.gregtechceu.gtceu.common.network.GTNetwork;
import com.gregtechceu.gtceu.common.network.packets.SPacketSyncFluidVeins;
import com.gregtechceu.gtceu.integration.kjs.GTCEuServerEvents;
import com.gregtechceu.gtceu.integration.kjs.events.GTBedrockOreVeinEventJS;

Expand Down Expand Up @@ -81,9 +79,7 @@ protected void apply(Map<ResourceLocation, JsonElement> resourceList, ResourceMa
GTRegistries.BEDROCK_ORE_DEFINITIONS.freeze();
}

if (Platform.getMinecraftServer() != null) {
GTNetwork.NETWORK.sendToAll(new SPacketSyncFluidVeins(GTRegistries.BEDROCK_FLUID_DEFINITIONS.registry()));
}
if (Platform.getMinecraftServer() != null) {}
}

public static BedrockOreDefinition fromJson(ResourceLocation id, JsonObject json, RegistryOps<JsonElement> ops) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@
import com.gregtechceu.gtceu.api.data.worldgen.generator.veins.NoopVeinGenerator;
import com.gregtechceu.gtceu.api.registry.GTRegistries;
import com.gregtechceu.gtceu.common.data.GTOres;
import com.gregtechceu.gtceu.common.network.GTNetwork;
import com.gregtechceu.gtceu.common.network.packets.SPacketSyncOreVeins;
import com.gregtechceu.gtceu.integration.kjs.GTCEuServerEvents;
import com.gregtechceu.gtceu.integration.kjs.events.GTOreVeinEventJS;

import com.lowdragmc.lowdraglib.Platform;

import net.minecraft.resources.RegistryOps;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
Expand Down Expand Up @@ -89,10 +85,6 @@ protected void apply(Map<ResourceLocation, JsonElement> resourceList, ResourceMa
if (!GTRegistries.ORE_VEINS.isFrozen()) {
GTRegistries.ORE_VEINS.freeze();
}

if (Platform.getMinecraftServer() != null) {
GTNetwork.NETWORK.sendToAll(new SPacketSyncOreVeins(GTRegistries.ORE_VEINS.registry()));
}
}

public static void buildVeinGenerator() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.event.AddReloadListenerEvent;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.*;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.living.LivingFallEvent;
import net.minecraftforge.event.entity.living.MobSpawnEvent;
Expand Down Expand Up @@ -239,19 +236,31 @@ public static void worldUnload(LevelEvent.Unload event) {
@SubscribeEvent
public static void onPlayerJoinServer(PlayerEvent.PlayerLoggedInEvent event) {
if (event.getEntity() instanceof ServerPlayer serverPlayer) {
GTNetwork.NETWORK.sendToPlayer(new SPacketSyncOreVeins(GTRegistries.ORE_VEINS.registry()), serverPlayer);
GTNetwork.NETWORK.sendToPlayer(new SPacketSyncFluidVeins(GTRegistries.BEDROCK_FLUID_DEFINITIONS.registry()),
serverPlayer);
GTNetwork.NETWORK.sendToPlayer(
new SPacketSyncBedrockOreVeins(GTRegistries.BEDROCK_ORE_DEFINITIONS.registry()), serverPlayer);

if (!ConfigHolder.INSTANCE.gameplay.environmentalHazards)
return;

ServerLevel level = (ServerLevel) event.getEntity().level();
ServerLevel level = serverPlayer.serverLevel();
var data = EnvironmentalHazardSavedData.getOrCreate(level);
GTNetwork.NETWORK.sendToPlayer(new SPacketSyncLevelHazards(data.getHazardZones()),
serverPlayer);
GTNetwork.NETWORK.sendToPlayer(new SPacketSyncLevelHazards(data.getHazardZones()), serverPlayer);
}
}

@SubscribeEvent
public static void onDatapackSync(OnDatapackSyncEvent event) {
ServerPlayer player = event.getPlayer();
if (player == null) {
// if player == null, the /reload command was ran. sync to all players.
GTNetwork.NETWORK.sendToAll(new SPacketSyncOreVeins(GTRegistries.ORE_VEINS.registry()));
GTNetwork.NETWORK.sendToAll(new SPacketSyncFluidVeins(GTRegistries.BEDROCK_FLUID_DEFINITIONS.registry()));
GTNetwork.NETWORK
.sendToAll(new SPacketSyncBedrockOreVeins(GTRegistries.BEDROCK_ORE_DEFINITIONS.registry()));
} else {
// else it's a player logging in. sync to only that player.
GTNetwork.NETWORK.sendToPlayer(new SPacketSyncOreVeins(GTRegistries.ORE_VEINS.registry()), player);
GTNetwork.NETWORK.sendToPlayer(new SPacketSyncFluidVeins(GTRegistries.BEDROCK_FLUID_DEFINITIONS.registry()),
player);
GTNetwork.NETWORK.sendToPlayer(
new SPacketSyncBedrockOreVeins(GTRegistries.BEDROCK_ORE_DEFINITIONS.registry()), player);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.gregtechceu.gtceu.api.data.tag.TagPrefix;
import com.gregtechceu.gtceu.api.data.worldgen.GTOreDefinition;
import com.gregtechceu.gtceu.api.data.worldgen.bedrockfluid.BedrockFluidDefinition;
import com.gregtechceu.gtceu.api.data.worldgen.bedrockore.BedrockOreDefinition;
import com.gregtechceu.gtceu.api.registry.GTRegistries;
import com.gregtechceu.gtceu.client.ClientProxy;
import com.gregtechceu.gtceu.config.ConfigHolder;
Expand Down Expand Up @@ -72,6 +73,17 @@ public GTOreVeinWidget(BedrockFluidDefinition fluid) {
setupText(fluid);
}

public GTOreVeinWidget(BedrockOreDefinition bedrockOre) {
super(0, 0, width, 140);
this.name = getBedrockOreName(bedrockOre);
this.weight = bedrockOre.weight();
this.dimensionFilter = bedrockOre.dimensionFilter();
this.range = "NULL";
setClientSideWidget();
setupBaseGui(bedrockOre);
setupText(bedrockOre);
}

@SuppressWarnings("all")
private String range(GTOreDefinition oreDefinition) {
HeightProvider height = oreDefinition.range().height;
Expand All @@ -92,9 +104,10 @@ private void setupBaseGui(GTOreDefinition oreDefinition) {
for (int i = 0; i < n; i++) {
SlotWidget oreSlot = new SlotWidget(new ItemStackTransfer(containedOresAsItemStacks), i, x, 18, false,
false);
int finalI = i;
int finalIndex = i;
oreSlot.setOnAddedTooltips((stack, tooltips) -> tooltips.add(Component
.nullToEmpty(LocalizationUtils.format("gtceu.jei.ore_vein_diagram.chance", chances.get(finalI)))));
.nullToEmpty(
LocalizationUtils.format("gtceu.jei.ore_vein_diagram.chance", chances.get(finalIndex)))));
oreSlot.setIngredientIO(IngredientIO.OUTPUT);
addWidget(oreSlot);
x += 18;
Expand All @@ -109,6 +122,25 @@ private void setupBaseGui(BedrockFluidDefinition fluid) {
addWidget(fluidSlot);
}

private void setupBaseGui(BedrockOreDefinition bedrockOreDefinition) {
NonNullList<ItemStack> containedOresAsItemStacks = NonNullList.create();
List<Integer> chances = bedrockOreDefinition.getAllChances();
containedOresAsItemStacks.addAll(getRawMaterialList(bedrockOreDefinition));
int n = containedOresAsItemStacks.size();
int x = (width - 18 * n) / 2;
for (int i = 0; i < n; i++) {
SlotWidget oreSlot = new SlotWidget(new ItemStackTransfer(containedOresAsItemStacks), i, x, 18, false,
false);
int finalIndex = i;
oreSlot.setOnAddedTooltips((stack, tooltips) -> tooltips.add(Component
.nullToEmpty(
LocalizationUtils.format("gtceu.jei.ore_vein_diagram.chance", chances.get(finalIndex)))));
oreSlot.setIngredientIO(IngredientIO.OUTPUT);
addWidget(oreSlot);
x += 18;
}
}

private void setupText(GTOreDefinition ignored) {
addWidget(new ImageWidget(5, 0, width - 10, 16,
new TextTexture("gtceu.jei.ore_vein." + name).setType(TextTexture.TextType.LEFT_ROLL)
Expand All @@ -135,6 +167,17 @@ private void setupText(BedrockFluidDefinition ignored) {
setupDimensionMarker(60);
}

private void setupText(BedrockOreDefinition ignored) {
addWidget(new ImageWidget(5, 0, width - 10, 16,
new TextTexture("gtceu.jei.bedrock_ore." + name).setType(TextTexture.TextType.LEFT_ROLL)
.setWidth(width - 10)));
addWidget(new LabelWidget(5, 40,
LocalizationUtils.format("gtceu.jei.ore_vein_diagram.weight", weight)));
addWidget(new LabelWidget(5, 50,
LocalizationUtils.format("gtceu.jei.ore_vein_diagram.dimensions")));
setupDimensionMarker(60);
}

private void setupDimensionMarker(int yPosition) {
if (this.dimensionFilter != null) {
int interval = 2;
Expand Down Expand Up @@ -190,6 +233,12 @@ public static List<ItemStack> getRawMaterialList(GTOreDefinition oreDefinition)
.toList();
}

public static List<ItemStack> getRawMaterialList(BedrockOreDefinition bedrockOreDefinition) {
return bedrockOreDefinition.materials().stream()
.map(entry -> ChemicalHelper.get(TagPrefix.rawOre, entry.getFirst()))
.toList();
}

public String getOreName(GTOreDefinition oreDefinition) {
ResourceLocation id = ClientProxy.CLIENT_ORE_VEINS.inverse().get(oreDefinition);
return id.getPath();
Expand All @@ -199,4 +248,9 @@ public String getFluidName(BedrockFluidDefinition fluid) {
ResourceLocation id = ClientProxy.CLIENT_FLUID_VEINS.inverse().get(fluid);
return id.getPath();
}

public String getBedrockOreName(BedrockOreDefinition oreDefinition) {
ResourceLocation id = ClientProxy.CLIENT_BEDROCK_ORE_VEINS.inverse().get(oreDefinition);
return id.getPath();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.gregtechceu.gtceu.integration.emi.multipage.MultiblockInfoEmiCategory;
import com.gregtechceu.gtceu.integration.emi.oreprocessing.GTOreProcessingEmiCategory;
import com.gregtechceu.gtceu.integration.emi.orevein.GTBedrockFluidEmiCategory;
import com.gregtechceu.gtceu.integration.emi.orevein.GTBedrockOreEmiCategory;
import com.gregtechceu.gtceu.integration.emi.orevein.GTOreVeinEmiCategory;
import com.gregtechceu.gtceu.integration.emi.recipe.Ae2PatternTerminalHandler;
import com.gregtechceu.gtceu.integration.emi.recipe.GTEmiRecipeHandler;
Expand Down Expand Up @@ -44,6 +45,8 @@ public void register(EmiRegistry registry) {
registry.addCategory(GTOreProcessingEmiCategory.CATEGORY);
registry.addCategory(GTOreVeinEmiCategory.CATEGORY);
registry.addCategory(GTBedrockFluidEmiCategory.CATEGORY);
if (ConfigHolder.INSTANCE.machines.doBedrockOres)
registry.addCategory(GTBedrockOreEmiCategory.CATEGORY);
for (RecipeType<?> recipeType : BuiltInRegistries.RECIPE_TYPE) {
if (recipeType instanceof GTRecipeType gtRecipeType) {
if (Platform.isDevEnv() || gtRecipeType.getRecipeUI().isXEIVisible()) {
Expand All @@ -67,13 +70,16 @@ public void register(EmiRegistry registry) {
GTOreProcessingEmiCategory.registerDisplays(registry);
GTOreVeinEmiCategory.registerDisplays(registry);
GTBedrockFluidEmiCategory.registerDisplays(registry);
if (ConfigHolder.INSTANCE.machines.doBedrockOres)
GTBedrockOreEmiCategory.registerDisplays(registry);
// workstations
MultiblockInfoEmiCategory.registerWorkStations(registry);
GTRecipeTypeEmiCategory.registerWorkStations(registry);
if (!ConfigHolder.INSTANCE.compat.hideOreProcessingDiagrams)
GTOreProcessingEmiCategory.registerWorkStations(registry);
GTOreVeinEmiCategory.registerWorkStations(registry);
GTBedrockFluidEmiCategory.registerWorkStations(registry);
if (ConfigHolder.INSTANCE.machines.doBedrockOres)
GTBedrockOreEmiCategory.registerWorkStations(registry);
for (MachineDefinition definition : GTMachines.ELECTRIC_FURNACE) {
if (definition != null) {
registry.addWorkstation(VanillaEmiRecipeCategories.SMELTING, EmiStack.of(definition.asStack()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@ public static void registerDisplays(EmiRegistry registry) {
.forEach(registry::addRecipe);
}

public static void registerWorkStations(EmiRegistry registry) {
for (var definition : GTRegistries.MACHINES.values()) {
if (definition instanceof MultiblockMachineDefinition multiblockDefinition) {
registry.addWorkstation(CATEGORY, EmiStack.of(multiblockDefinition.asStack()));
}
}
}

@Override
public Component getName() {
return Component.translatable("gtceu.jei.multiblock_info");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public EmiRecipeCategory getCategory() {

@Override
public @Nullable ResourceLocation getId() {
return ClientProxy.CLIENT_FLUID_VEINS.inverse().get(fluid);
return ClientProxy.CLIENT_FLUID_VEINS.inverse().get(fluid).withPrefix("/bedrock_fluid_diagram/");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public static void registerDisplays(EmiRegistry registry) {
}

public static void registerWorkStations(EmiRegistry registry) {
registry.addWorkstation(CATEGORY, EmiStack.of(GTItems.PROSPECTOR_LV.asStack()));
registry.addWorkstation(CATEGORY, EmiStack.of(GTItems.PROSPECTOR_HV.asStack()));
registry.addWorkstation(CATEGORY, EmiStack.of(GTItems.PROSPECTOR_LUV.asStack()));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.gregtechceu.gtceu.integration.emi.orevein;

import com.gregtechceu.gtceu.api.data.worldgen.bedrockore.BedrockOreDefinition;
import com.gregtechceu.gtceu.client.ClientProxy;
import com.gregtechceu.gtceu.integration.GTOreVeinWidget;

import com.lowdragmc.lowdraglib.emi.ModularEmiRecipe;
import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup;

import net.minecraft.resources.ResourceLocation;

import dev.emi.emi.api.recipe.EmiRecipeCategory;
import org.jetbrains.annotations.Nullable;

public class GTBedrockOre extends ModularEmiRecipe<WidgetGroup> {

private final BedrockOreDefinition bedrockOre;

public GTBedrockOre(BedrockOreDefinition bedrockOre) {
super(() -> new GTOreVeinWidget(bedrockOre));
this.bedrockOre = bedrockOre;
}

@Override
public EmiRecipeCategory getCategory() {
return GTBedrockOreEmiCategory.CATEGORY;
}

@Override
public @Nullable ResourceLocation getId() {
return ClientProxy.CLIENT_BEDROCK_ORE_VEINS.inverse().get(bedrockOre).withPrefix("/bedrock_ore_diagram/");
}
}
Loading

0 comments on commit d881009

Please sign in to comment.