Skip to content

Commit

Permalink
add create contraptions tooltip
Browse files Browse the repository at this point in the history
closes #50
  • Loading branch information
deirn committed Sep 1, 2022
1 parent c99d087 commit 462afc2
Show file tree
Hide file tree
Showing 40 changed files with 870 additions and 53 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/head.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:
with:
java-version: 17
- uses: gradle/gradle-build-action@v2
with:
cache-read-only: ${{ github.repository != 'badasintended/megane' }}
- run: |
chmod +x setup.sh
./setup.sh
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
with:
java-version: 17
- uses: gradle/gradle-build-action@v2
with:
cache-read-only: true
- run: |
chmod +x setup.sh
./setup.sh
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repositories {
}

dependencies {
implementation("fabric-loom:fabric-loom.gradle.plugin:0.12.+")
implementation("fabric-loom:fabric-loom.gradle.plugin:1.0.+")
implementation("com.modrinth.minotaur:Minotaur:2.2.1")
implementation("com.github.deirn:CurseForgeGradle:c693018f92")
implementation("com.google.code.gson:gson:2.9.1")
Expand Down
10 changes: 5 additions & 5 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ object versions {
object deps {
val minecraft = "com.mojang:minecraft:${versions.minecraft}"
val yarn = "net.fabricmc:yarn:1.18.2+build.3:v2"
val fabricLoader = "net.fabricmc:fabric-loader:0.14.7"
val fabricLoader = "net.fabricmc:fabric-loader:0.14.9"

val wthit = "mcp.mobius.waila:wthit:fabric-4.12.0"
val wthit = "mcp.mobius.waila:wthit:fabric-4.13.3"

val ae2 = "appeng:appliedenergistics2-fabric:11.1.5"
val ae2 = "appeng:appliedenergistics2-fabric:11.1.6"
val alloyForge = "maven.modrinth:jhl28YkY:2.0.13+1.18"
val create = "com.simibubi:Create:0.5.0c-708"
val clothConfig = "me.shedaniel.cloth:cloth-config-fabric:6.2.62"
val extraGen = "maven.modrinth:VXtwLg17:1.2.1-BETA+1.18"
val fabricApi = "net.fabricmc.fabric-api:fabric-api:0.58.0+1.18.2"
val flk = "net.fabricmc:fabric-language-kotlin:1.8.2+kotlin.1.7.10"
val flk = "net.fabricmc:fabric-language-kotlin:1.8.3+kotlin.1.7.10"
val kibe = "maven.modrinth:OvlwmUdC:1.9.9-BETA+1.18"
val modernDynamics = "maven.modrinth:fMpvLrnF:0.2.4-beta"
val modernDynamics = "maven.modrinth:fMpvLrnF:0.2.5-beta"
val modmenu = "com.terraformersmc:modmenu:3.2.3"
val noIndium = "me.luligabi:NoIndium:1.0.2+1.18.2"
val owo = "io.wispforest:owo-lib:0.7.2-no-cme+1.18"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@

public interface MeganeModule {

/**
* Register common-sided providers here.
*/
default void registerCommon(CommonRegistrar registrar) {
}

/**
* Register client-sided providers here.
*/
default void registerClient(ClientRegistrar registrar) {
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package lol.bai.megane.api.provider;

import javax.annotation.Nullable;

import lol.bai.megane.api.registry.ClientRegistrar;
import lol.bai.megane.api.util.BarFormat;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
Expand Down Expand Up @@ -35,15 +34,23 @@ public Text getName() {
return DEFAULT_NAME;
}

/**
* Returns the format of the number on the bar.
*/
public BarFormat getFormat() {
return BarFormat.FRACTION;
}

/**
* Returns the color of the energy bar.
*/
public abstract int getColor();

/**
* Returns the unit of the energy, or {@code null} if it doesn't have one.
* Returns the unit of the energy.
*/
@Nullable
public abstract String getUnit();
public String getUnit() {
return "E";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public boolean hasEnergy() {
/**
* Returns how much the capacity of the storage.
* <p>
* Return {@code -1} to mark this as unlimited capacity.
* Return {@code -1} to mark this doesn't have a capacity.
*/
public abstract long getMax();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package lol.bai.megane.api.provider.base;

import lol.bai.megane.api.provider.ProgressProvider;
import net.minecraft.item.ItemStack;
import org.jetbrains.annotations.NotNull;

public abstract class IoLessProgressProvider<T> extends ProgressProvider<T> {

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

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

@Override
public @NotNull ItemStack getInputStack(int slot) {
return ItemStack.EMPTY;
}

@Override
public @NotNull ItemStack getOutputStack(int slot) {
return ItemStack.EMPTY;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package lol.bai.megane.api.util;

public enum BarFormat {
FRACTION,
PERCENT
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ public void register(IRegistrar r) {
LOGGER.info("[megane] Loading {} from {}", className, modId);
MeganeModule entry = (MeganeModule) Class.forName(className).getDeclaredConstructor().newInstance();
entry.registerCommon(Registrar.INSTANCE);
if (loader.getEnvironmentType() == EnvType.CLIENT)
if (loader.getEnvironmentType() == EnvType.CLIENT) {
entry.registerClient(Registrar.INSTANCE);
}
} catch (Throwable t) {
LOGGER.error("[megane] error when loading {} from {}", className, modId);
t.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
import java.math.RoundingMode;
import java.text.DecimalFormat;

import lol.bai.megane.api.util.BarFormat;
import lol.bai.megane.runtime.util.MeganeUtils;
import mcp.mobius.waila.api.ITooltipComponent;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;

import static net.minecraft.client.gui.DrawableHelper.fill;

public class BarComponent implements ITooltipComponent {
public class StorageAmountComponent implements ITooltipComponent {

private static final DecimalFormat FORMAT = new DecimalFormat("#.##");
private static final Identifier TEXTURE = MeganeUtils.id("textures/bar.png");
private static final String INFINITE = "\u221E";

static {
FORMAT.setRoundingMode(RoundingMode.DOWN);
Expand All @@ -22,42 +24,69 @@ public class BarComponent implements ITooltipComponent {
private final int color;
private final double stored, max;

private final boolean drawBar;
private final String valString;

public BarComponent(int color, double stored, double max, String unit, boolean verbose) {
public StorageAmountComponent(BarFormat format, int color, double stored, double max, String unit, boolean verbose) {
this.color = color;
this.stored = stored;
this.max = max;

String storedString;
if (stored < 0 || stored == Double.MAX_VALUE) {
storedString = "∞";
} else {
storedString = verbose ? String.valueOf(stored) : MeganeUtils.suffix((long) stored);
if (isInfinite(max)) {
drawBar = false;
valString = createValStr(createNumberStr(stored, verbose), unit);
return;
}

String maxString;
if (max <= 0 || max == Double.MAX_VALUE) {
maxString = "∞";
} else {
maxString = verbose ? String.valueOf(max) : MeganeUtils.suffix((long) max);
}
String number = switch (format) {
case FRACTION -> {
String storedString = createNumberStr(stored, verbose);
String maxString = max == 0 ? INFINITE : createNumberStr(max, verbose);
yield storedString + '/' + maxString;
}
case PERCENT -> {
if (isInfinite(stored) || max == 0 || isInfinite(max)) {
yield INFINITE + '%';
}

yield String.valueOf(stored / max * 100) + '%';
}
};

drawBar = true;
valString = number + (unit.isEmpty() ? "" : " " + unit);
}

private static String createNumberStr(double number, boolean verbose) {
return isInfinite(number) ? INFINITE
: verbose ? String.valueOf(number) : MeganeUtils.suffix((long) number);
}

valString = storedString + "/" + maxString + (unit.isEmpty() ? "" : " " + unit);
private static String createValStr(String number, String unit) {
return number + (unit.isEmpty() ? "" : " " + unit);
}

private static boolean isInfinite(double number) {
return number < 0 || number == Double.MAX_VALUE || number == Double.POSITIVE_INFINITY;
}

@Override
public int getWidth() {
return Math.max(MeganeUtils.textRenderer().getWidth(valString), 100);
return Math.max(MeganeUtils.textRenderer().getWidth(valString), drawBar ? 100 : -1);
}

@Override
public int getHeight() {
return 13;
return drawBar ? 13 : MeganeUtils.textRenderer().fontHeight;
}

@Override
public void render(MatrixStack matrices, int x, int y, float delta) {
if (!drawBar) {
MeganeUtils.textRenderer().draw(matrices, valString, x, y, 0xFF000000 | color);
return;
}

float ratio = max == 0 ? 1F : ((float) Math.floor((Math.min((float) (stored / max), 1F)) * 100)) / 100F;

MeganeUtils.drawTexture(matrices, TEXTURE, x, y, 100, 11, 0, 0, 1F, 0.5F, color);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import java.util.Objects;

import lol.bai.megane.api.provider.EnergyInfoProvider;
import lol.bai.megane.runtime.component.BarComponent;
import lol.bai.megane.api.util.BarFormat;
import lol.bai.megane.runtime.component.StorageAmountComponent;
import lol.bai.megane.runtime.config.MeganeConfig;
import lol.bai.megane.runtime.registry.Registrar;
import mcp.mobius.waila.api.IBlockAccessor;
Expand Down Expand Up @@ -69,7 +70,7 @@ protected void append(ITooltip tooltip, IBlockAccessor accessor) {
} else {
color = provider == null
? colors.computeIfAbsent(MODID, c -> 0x710C00)
: provider.getColor();
: provider.getColor() & 0xFFFFFF;
colors.put(key, color);
CONFIG.save();
}
Expand All @@ -87,7 +88,7 @@ protected void append(ITooltip tooltip, IBlockAccessor accessor) {

tooltip.addLine(new PairComponent(
new WrappedComponent(provider != null ? provider.getName() : ENERGY_NAME),
new BarComponent(color, stored, max, unit, expand)));
new StorageAmountComponent(provider != null ? provider.getFormat() : BarFormat.FRACTION, color, stored, max, unit, expand)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import java.util.Map;

import lol.bai.megane.api.provider.FluidInfoProvider;
import lol.bai.megane.runtime.component.BarComponent;
import lol.bai.megane.api.util.BarFormat;
import lol.bai.megane.runtime.component.StorageAmountComponent;
import lol.bai.megane.runtime.registry.Registrar;
import mcp.mobius.waila.api.IBlockAccessor;
import mcp.mobius.waila.api.ITooltip;
Expand Down Expand Up @@ -60,7 +61,7 @@ protected void addFluid(ITooltip tooltip, IBlockAccessor accessor, Fluid fluid,

int color;
if (nbt != null && provider != null) {
color = provider.getColor();
color = provider.getColor() & 0xFFFFFF;
} else if (colors.containsKey(id)) {
color = colors.get(id);
} else {
Expand All @@ -73,7 +74,7 @@ protected void addFluid(ITooltip tooltip, IBlockAccessor accessor, Fluid fluid,

tooltip.addLine(new PairComponent(
new WrappedComponent(provider == null ? fluidName(fluid) : provider.getName()),
new BarComponent(color, stored, max, "mB", expand)));
new StorageAmountComponent(BarFormat.FRACTION, color, stored, max, "mB", expand)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,68 @@
package lol.bai.megane.module.create;

import com.simibubi.create.content.contraptions.components.actors.BlockBreakingKineticTileEntity;
import com.simibubi.create.content.contraptions.components.crusher.CrushingWheelControllerTileEntity;
import com.simibubi.create.content.contraptions.components.deployer.DeployerTileEntity;
import com.simibubi.create.content.contraptions.components.millstone.MillstoneTileEntity;
import com.simibubi.create.content.contraptions.components.mixer.MechanicalMixerTileEntity;
import com.simibubi.create.content.contraptions.fluids.tank.CreativeFluidTankTileEntity;
import com.simibubi.create.content.contraptions.fluids.tank.FluidTankTileEntity;
import com.simibubi.create.content.contraptions.processing.BasinTileEntity;
import com.simibubi.create.content.logistics.block.vault.ItemVaultTileEntity;
import com.simibubi.create.content.schematics.block.SchematicTableTileEntity;
import com.simibubi.create.content.schematics.block.SchematicannonTileEntity;
import com.tterrag.registrate.fabric.SimpleFlowableFluid;
import lol.bai.megane.api.MeganeModule;
import lol.bai.megane.api.registry.ClientRegistrar;
import lol.bai.megane.api.registry.CommonRegistrar;
import lol.bai.megane.module.create.provider.BasinFluidProvider;
import lol.bai.megane.module.create.provider.BasinItemProvider;
import lol.bai.megane.module.create.provider.BasinProgressProvider;
import lol.bai.megane.module.create.provider.BlockBreakingProgressProvider;
import lol.bai.megane.module.create.provider.CreativeFluidTankFluidProvider;
import lol.bai.megane.module.create.provider.CrushingWheelControllerProgressProvider;
import lol.bai.megane.module.create.provider.DeployerItemProvider;
import lol.bai.megane.module.create.provider.FluidTankFluidProvider;
import lol.bai.megane.module.create.provider.ItemStackHandlerItemProvider;
import lol.bai.megane.module.create.provider.MechanicalMixerProgressProvider;
import lol.bai.megane.module.create.provider.MillstoneItemProvider;
import lol.bai.megane.module.create.provider.MillstoneProgressProvider;
import lol.bai.megane.module.create.provider.SchematicannonEnergyInfoProvider;
import lol.bai.megane.module.create.provider.SchematicannonEnergyProvider;
import lol.bai.megane.module.create.provider.SchematicannonProgressProvider;
import lol.bai.megane.module.create.provider.SimpleFlowableFluidInfoProvider;

@SuppressWarnings("unused")
public class MeganeCreate implements MeganeModule {

@Override
public void registerCommon(CommonRegistrar registrar) {
registrar.addFluid(CreativeFluidTankTileEntity.class, new CreativeFluidTankFluidProvider());
registrar.addFluid(999, CreativeFluidTankTileEntity.class, new CreativeFluidTankFluidProvider());
registrar.addFluid(BasinTileEntity.class, new BasinFluidProvider());
registrar.addFluid(FluidTankTileEntity.class, new FluidTankFluidProvider<>());

registrar.addEnergy(SchematicannonTileEntity.class, new SchematicannonEnergyProvider());

registrar.addProgress(BasinTileEntity.class, new BasinProgressProvider());
registrar.addProgress(BlockBreakingKineticTileEntity.class, new BlockBreakingProgressProvider());
registrar.addProgress(CrushingWheelControllerTileEntity.class, new CrushingWheelControllerProgressProvider());
registrar.addProgress(MechanicalMixerTileEntity.class, new MechanicalMixerProgressProvider());
registrar.addProgress(MillstoneTileEntity.class, new MillstoneProgressProvider());
registrar.addProgress(SchematicannonTileEntity.class, new SchematicannonProgressProvider());

registrar.addItem(BasinTileEntity.class, new BasinItemProvider());
registrar.addItem(DeployerTileEntity.class, new DeployerItemProvider());
registrar.addItem(ItemVaultTileEntity.class, new ItemStackHandlerItemProvider.Single<>(ItemVaultTileEntity::getInventoryOfBlock));
registrar.addItem(MillstoneTileEntity.class, new MillstoneItemProvider());
registrar.addItem(SchematicannonTileEntity.class, new ItemStackHandlerItemProvider.Single<>(t -> t.inventory));
registrar.addItem(SchematicTableTileEntity.class, new ItemStackHandlerItemProvider.Single<>(t -> t.inventory));
}

@Override
public void registerClient(ClientRegistrar registrar) {
registrar.addFluidInfo(SimpleFlowableFluid.class, new SimpleFlowableFluidInfoProvider());

registrar.addEnergyInfo(SchematicannonTileEntity.class, new SchematicannonEnergyInfoProvider());
}

}
Loading

0 comments on commit 462afc2

Please sign in to comment.