Skip to content

Commit

Permalink
Recipe Outputs in TOP + Separate RF Producer
Browse files Browse the repository at this point in the history
  • Loading branch information
IntegerLimit committed Jan 4, 2025
1 parent 1d68717 commit d41d49e
Show file tree
Hide file tree
Showing 12 changed files with 456 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ This mod requires [GregTech CEu](https://github.com/GregTechCEu/GregTech). Other

## Credits:
- [GTCEu Buildscripts](https://github.com/GregTechCEu/Buildscripts) for the amazing buildscripts
- [GregicProbeCEu](https://github.com/Supernoobv/GregicProbeCEu) for base FluidStack element and base recipe outputs implementation (integrated in Labs for localization and display improvements and easier future GT porting)
- [Actually Additions](https://github.com/Ellpeck/ActuallyAdditions) for part of the custom fluid code
- [Content Tweaker](https://github.com/CraftTweaker/ContentTweaker) for base textures of custom fluids
- [Nomifactory](https://github.com/Nomifactory/Nomifactory) for textures of items, blocks, base code, and the original pack
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/nomiceu/nomilabs/LabsValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ public class LabsValues {
public static final String THERMAL_FOUNDATION_MODID = "thermalfoundation";
public static final String BETTER_P2P_MODID = "betterp2p";
public static final String FIND_ME_MODID = "findme";
public static final String REDSTONE_FLUX_MODID = "redstoneflux";
}
24 changes: 24 additions & 0 deletions src/main/java/com/nomiceu/nomilabs/config/LabsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public class LabsConfig {
@Config.Name("mod integration")
public static ModIntegration modIntegration = new ModIntegration();

@Config.Comment("The One Probe Settings")
@Config.LangKey("config.nomilabs.top")
@Config.Name("top settings")
public static TheOneProbeSettings topSettings = new TheOneProbeSettings();

@Config.Comment("Advanced Settings")
@Config.LangKey("config.nomilabs.advanced")
@Config.Name("advanced")
Expand Down Expand Up @@ -182,6 +187,25 @@ public enum GTRecipeSearchMode {
}
}

public static class TheOneProbeSettings {

@Config.Comment({
"Mode to enable Labs' RF Provider. Behaviour is the same as TOP's, but allows for rearranging the RF bar.",
"You will have to set TOP's 'RF Mode' to 0.",
"0: Disable, 1: Show as Bar, 2: Show as Text",
"[default: 0]" })
@Config.LangKey("config.nomilabs.top.rf_provider")
@Config.RangeInt(min = 0, max = 2)
public int rfProviderMode = 0;

@Config.Comment({
"Enable Display of GT Recipe Outputs in TOP.",
"[default: true]"
})
@Config.LangKey("config.nomilabs.top.gt_recipe_output")
public boolean enableGTRecipeOutput = true;
}

public static class ModIntegration {

@Config.Comment({ "Whether to enable NuclearCraft Integration, which fixes its crash with GTCEu.",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.nomiceu.nomilabs.gregtech.mixinhelper;

import java.util.List;

import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;

public interface AccessibleAbstractRecipeLogic {

List<ItemStack> labs$getOutputs();

List<FluidStack> labs$getFluidOutputs();

int labs$getEUt();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package com.nomiceu.nomilabs.integration.top;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraftforge.fluids.FluidStack;

import org.jetbrains.annotations.NotNull;

import gregtech.api.util.TextFormattingUtil;
import gregtech.client.utils.RenderUtil;
import io.netty.buffer.ByteBuf;
import mcjty.theoneprobe.api.IElement;
import mcjty.theoneprobe.network.NetworkTools;

/**
* From <a href=
* "https://github.com/Supernoobv/GregicProbeCEu/blob/master/src/main/java/vfyjxf/gregicprobe/element/FluidStackElement.java">GregicProbe</a>.
*/
public class LabsFluidStackElement implements IElement {

private final String location;
private final int color;
private final int amount;

private TextureAtlasSprite sprite = null;

public LabsFluidStackElement(@NotNull FluidStack stack) {
this.location = stack.getFluid().getStill(stack).toString();
this.color = stack.getFluid().getColor(stack);
this.amount = stack.amount;
}

public LabsFluidStackElement(@NotNull ByteBuf buf) {
this.location = NetworkTools.readStringUTF8(buf);
this.color = buf.readInt();
this.amount = buf.readInt();
}

@Override
public void render(int x, int y) {
String actualLocation = location;

// Gregtech fluids added by GRS do this for some reason
// As a consequence the fluid texture from /dull will not show up on anything from GRS.
if (location.contains("material_sets/fluid/") && (location.contains("/gas") || location.contains("/plasma"))) {
actualLocation = location.replace("material_sets/fluid/", "material_sets/dull/");
}

if (sprite == null) {
sprite = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(actualLocation);
}

GlStateManager.enableBlend();
Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);

RenderUtil.setGlColorFromInt(color, 0xFF);
RenderUtil.drawFluidTexture(x + 1, y - 1, sprite, 2, 2, 0);

if (amount > 0) {
GlStateManager.pushMatrix();
GlStateManager.scale(0.5, 0.5, 1);
Minecraft minecraft = Minecraft.getMinecraft();
String format = TextFormattingUtil.formatLongToCompactString(amount) + "L";
minecraft.fontRenderer.drawStringWithShadow(
format,
(x + 16) * 2 - minecraft.fontRenderer.getStringWidth(format),
(y + 16) * 2 - minecraft.fontRenderer.FONT_HEIGHT,
0xFFFFFF);
GlStateManager.popMatrix();
}

GlStateManager.disableBlend();
}

@Override
public int getWidth() {
return 16;
}

@Override
public int getHeight() {
return 16;
}

@Override
public void toBytes(@NotNull ByteBuf buf) {
NetworkTools.writeStringUTF8(buf, location);
buf.writeInt(color);
buf.writeInt(amount);
}

@Override
public int getID() {
return LabsTOPManager.FLUID_STACK_ELEMENT;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.nomiceu.nomilabs.integration.top;

import static mcjty.theoneprobe.api.TextStyleClass.PROGRESS;

import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
import net.minecraftforge.fml.common.Loader;

import com.nomiceu.nomilabs.LabsValues;
import com.nomiceu.nomilabs.config.LabsConfig;

import mcjty.lib.api.power.IBigPower;
import mcjty.theoneprobe.api.IProbeHitData;
import mcjty.theoneprobe.api.IProbeInfo;
import mcjty.theoneprobe.api.IProbeInfoProvider;
import mcjty.theoneprobe.api.ProbeMode;
import mcjty.theoneprobe.apiimpl.elements.ElementProgress;
import mcjty.theoneprobe.compat.RedstoneFluxTools;
import mcjty.theoneprobe.config.Config;

/**
* A duplicate of TOP RF Info Provider Logic, but separate
* Allows for rearranging the RF bar.
*/
public class LabsRFInfoProvider implements IProbeInfoProvider {

@Override
public String getID() {
return LabsValues.LABS_MODID + ":rf_provider";
}

@Override
public void addProbeInfo(ProbeMode mode, IProbeInfo info, EntityPlayer player, World world, IBlockState state,
IProbeHitData data) {
if (LabsConfig.topSettings.rfProviderMode == 0) return;

TileEntity te = world.getTileEntity(data.getPos());
if (te == null) return;

if (te instanceof IBigPower) {
long energy = ((IBigPower) te).getStoredPower();
long maxEnergy = ((IBigPower) te).getCapacity();
addRFInfo(info, LabsConfig.topSettings.rfProviderMode, energy, maxEnergy);
return;
}

if (Loader.isModLoaded(LabsValues.REDSTONE_FLUX_MODID) && RedstoneFluxTools.isEnergyHandler(te)) {
int energy = RedstoneFluxTools.getEnergy(te);
int maxEnergy = RedstoneFluxTools.getMaxEnergy(te);
addRFInfo(info, LabsConfig.topSettings.rfProviderMode, energy, maxEnergy);
return;
}

if (te.hasCapability(CapabilityEnergy.ENERGY, null)) {
IEnergyStorage handler = te.getCapability(CapabilityEnergy.ENERGY, null);
if (handler != null) {
addRFInfo(info, LabsConfig.topSettings.rfProviderMode, handler.getEnergyStored(),
handler.getMaxEnergyStored());
}
}
}

/**
* Adds information about Redstone Flux energy based on the given configuration.
* If the RF mode in the configuration is set to 1, a progress bar is displayed with specific styling.
* Otherwise, a text representation of the RF energy is shown.
*
* @author McJty
*
* @param probeInfo The {@link IProbeInfo} object to which the RF information will be added.
* @param rfMode Mode to display RF in.
* @param energy The current amount of RF energy.
* @param maxEnergy The maximum capacity of RF energy.
*/
private void addRFInfo(IProbeInfo probeInfo, int rfMode, long energy, long maxEnergy) {
if (rfMode == 1) {
probeInfo.progress(energy, maxEnergy,
probeInfo.defaultProgressStyle()
.suffix("RF")
.filledColor(Config.rfbarFilledColor)
.alternateFilledColor(Config.rfbarAlternateFilledColor)
.borderColor(Config.rfbarBorderColor)
.numberFormat(Config.rfFormat));
} else {
probeInfo.text(PROGRESS + "RF: " + ElementProgress.format(energy, Config.rfFormat, "RF"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class LabsTOPManager {

public static int FLUID_NAME_ELEMENT;
public static int CUSTOM_NAME_ELEMENT;
public static int FLUID_STACK_ELEMENT;

public static void register() {
ITheOneProbe TOP = TheOneProbe.theOneProbeImp;
Expand All @@ -25,12 +26,17 @@ public static void register() {

// GT TOP Integration
TOP.registerProvider(new SteamMachineInfoProvider());
TOP.registerProvider(new RecipeOutputsProvider());

// Labs TOP Integration
TOP.registerProvider(new TOPTooltipMessage());

// General TOP Integration
TOP.registerProvider(new LabsRFInfoProvider());

FLUID_NAME_ELEMENT = TOP.registerElementFactory(LabsFluidNameElement::new);
CUSTOM_NAME_ELEMENT = TOP.registerElementFactory(CustomNameElement::new);
FLUID_STACK_ELEMENT = TOP.registerElementFactory(LabsFluidStackElement::new);
}

public static class TOPTooltipMessage implements IProbeInfoProvider {
Expand Down
Loading

0 comments on commit d41d49e

Please sign in to comment.