Skip to content

Commit

Permalink
many things
Browse files Browse the repository at this point in the history
[api]
Added custom inventory tooltip handler
depends waila on mod json
conditions in provider
strip MeganeUtils from runtime only things

[impl]
AE2 compat
Modern Industrialization compat
Fabric Furnaces compat

[runtime]
Fixes #11 cauldron always shows level 0
depends api on mod json
some more change
  • Loading branch information
deirn committed Oct 4, 2020
1 parent a0c7151 commit fe89344
Show file tree
Hide file tree
Showing 50 changed files with 877 additions and 354 deletions.
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ allprojects {
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
maven { url "https://maven.tehnut.info" }
}

dependencies {
minecraft "com.mojang:minecraft:${rootProject.minecraft}"
mappings "net.fabricmc:yarn:${rootProject.yarn}:v2"
modImplementation "net.fabricmc:fabric-loader:${rootProject.loader}"

modImplementation "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric}"
modImplementation "mcp.mobius.waila:Hwyla:${rootProject.hwyla}"

modApi "org.jetbrains:annotations:19.0.0"
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ yarn = 1.16.3+build.17
loader = 0.10.0+build.208

# Mod Properties
mod = 1.1.0+1.16
mod = 1.2.0+1.16
group = com.github.badasintended
archivesBaseName = megane

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

@SuppressWarnings({"unchecked"})
public final class EnergyTooltipRegistry {

private static final Map<Class<? extends BlockEntity>, Provider<?>> ENTRIES = new HashMap<>();
Expand All @@ -24,6 +23,7 @@ public static <T extends BlockEntity> void register(Class<T> clazz, Provider<T>

@Nullable
@ApiStatus.Internal
@SuppressWarnings({"unchecked"})
public static <T extends BlockEntity> Provider<T> get(T blockEntity) {
Class<?> clazz = blockEntity.getClass();
boolean containsKey = ENTRIES.containsKey(clazz);
Expand All @@ -44,7 +44,16 @@ public static <T extends BlockEntity> Provider<T> get(T blockEntity) {
public interface Provider<T extends BlockEntity> {

static <T extends BlockEntity> Provider<T> of(Function<T, Double> stored, Function<T, Double> max) {
return of(t -> true, stored, max);
}

static <T extends BlockEntity> Provider<T> of(Function<T, Boolean> hasEnergy, Function<T, Double> stored, Function<T, Double> max) {
return new Provider<T>() {
@Override
public boolean hasEnergy(T t) {
return hasEnergy.apply(t);
}

@Override
public double getStored(T t) {
return stored.apply(t);
Expand All @@ -57,6 +66,8 @@ public double getMax(T t) {
};
}

boolean hasEnergy(T t);

double getStored(T t);

double getMax(T t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.function.BiFunction;
import java.util.function.Function;

@SuppressWarnings({"unchecked"})
public final class FluidTooltipRegistry {

private static final Map<Class<? extends BlockEntity>, Provider<?>> ENTRIES = new HashMap<>();
Expand All @@ -26,6 +25,7 @@ public static <T extends BlockEntity> void register(Class<T> clazz, Provider<T>

@Nullable
@ApiStatus.Internal
@SuppressWarnings({"unchecked"})
public static <T extends BlockEntity> Provider<T> get(T blockEntity) {
Class<?> clazz = blockEntity.getClass();
boolean containsKey = ENTRIES.containsKey(clazz);
Expand All @@ -46,7 +46,16 @@ public static <T extends BlockEntity> Provider<T> get(T blockEntity) {
public interface Provider<T extends BlockEntity> {

static <T extends BlockEntity> Provider<T> of(Function<T, Integer> slotCount, BiFunction<T, Integer, Text> name, BiFunction<T, Integer, Double> stored, BiFunction<T, Integer, Double> max) {
return of(t -> true, slotCount, name, stored, max);
}

static <T extends BlockEntity> Provider<T> of(Function<T, Boolean> hasFluid, Function<T, Integer> slotCount, BiFunction<T, Integer, Text> name, BiFunction<T, Integer, Double> stored, BiFunction<T, Integer, Double> max) {
return new Provider<T>() {
@Override
public boolean hasFluid(T t) {
return hasFluid.apply(t);
}

@Override
public int getSlotCount(T t) {
return slotCount.apply(t);
Expand All @@ -69,6 +78,8 @@ public double getMax(T t, int slot) {
};
}

boolean hasFluid(T t);

int getSlotCount(T t);

Text getFluidName(T t, int slot);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package badasintended.megane.api.registry;

import net.minecraft.block.entity.BlockEntity;
import net.minecraft.item.ItemStack;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Function;

public final class InventoryTooltipRegistry {

private static final Map<Class<? extends BlockEntity>, Provider<?>> ENTRIES = new HashMap<>();

public static <T extends BlockEntity> void register(Class<T> clazz, Provider<T> provider) {
ENTRIES.put(clazz, provider);
}

@Nullable
@ApiStatus.Internal
@SuppressWarnings({"unchecked"})
public static <T extends BlockEntity> Provider<T> get(T blockEntity) {
Class<?> clazz = blockEntity.getClass();
boolean containsKey = ENTRIES.containsKey(clazz);

if (!containsKey) do {
clazz = clazz.getSuperclass();
containsKey = ENTRIES.containsKey(clazz);
} while (!containsKey && clazz != BlockEntity.class);

if (containsKey) {
Provider<T> provider = (Provider<T>) ENTRIES.get(clazz);
ENTRIES.putIfAbsent(blockEntity.getClass(), provider);
return provider;
}
return null;
}

public interface Provider<T extends BlockEntity> {

static <T extends BlockEntity> Provider<T> of(Function<T, Integer> size, BiFunction<T, Integer, ItemStack> stack) {
return of(t -> true, size, stack);
}

static <T extends BlockEntity> Provider<T> of(Function<T, Boolean> hasInventory, Function<T, Integer> size, BiFunction<T, Integer, ItemStack> stack) {
return new Provider<T>() {
@Override
public boolean hasInventory(T t) {
return hasInventory.apply(t);
}

@Override
public int size(T t) {
return size.apply(t);
}

@Override
public ItemStack getStack(T t, int slot) {
return stack.apply(t, slot);
}
};
}

boolean hasInventory(T t);

int size(T t);

ItemStack getStack(T t, int slot);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

import net.minecraft.block.entity.BlockEntity;
import net.minecraft.item.ItemStack;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.*;

import java.util.HashMap;
import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Function;

@SuppressWarnings({"unchecked"})
public final class ProgressTooltipRegistry {

private static final Map<Class<? extends BlockEntity>, Provider<?>> ENTRIES = new HashMap<>();
Expand All @@ -27,6 +24,7 @@ public static <T extends BlockEntity> void register(Class<T> clazz, Provider<T>

@Nullable
@ApiStatus.Internal
@SuppressWarnings({"unchecked"})
public static <T extends BlockEntity> Provider<T> get(T blockEntity) {
Class<?> clazz = blockEntity.getClass();
boolean containsKey = ENTRIES.containsKey(clazz);
Expand All @@ -47,7 +45,16 @@ public static <T extends BlockEntity> Provider<T> get(T blockEntity) {
public interface Provider<T extends BlockEntity> {

static <T extends BlockEntity> Provider<T> of(Function<T, int[]> inputSlots, Function<T, int[]> outputSlots, BiFunction<T, Integer, ItemStack> stack, Function<T, Integer> percentage) {
return of(t -> true, inputSlots, outputSlots, stack, percentage);
}

static <T extends BlockEntity> Provider<T> of(Function<T, Boolean> hasProgress, Function<T, int[]> inputSlots, Function<T, int[]> outputSlots, BiFunction<T, Integer, ItemStack> stack, Function<T, Integer> percentage) {
return new Provider<T>() {
@Override
public boolean hasProgress(T t) {
return hasProgress.apply(t);
}

@Override
public int[] getInputSlots(T t) {
return inputSlots.apply(t);
Expand All @@ -70,6 +77,8 @@ public int getPercentage(T t) {
};
}

boolean hasProgress(T t);

int[] getInputSlots(T t);

int[] getOutputSlots(T t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.*;

public class MeganeConfig {

Expand All @@ -16,7 +13,16 @@ public class MeganeConfig {
public final Fluid fluid = new Fluid();
public final Progress progress = new Progress();

public static class Inventory {
public interface Base {

boolean isEnabled();

Set<Identifier> getBlacklist();

}

public static class Inventory implements Base {

private boolean enabled = true;
private int maxWidth = 9;
private int maxHeight = 3;
Expand All @@ -38,6 +44,7 @@ public void setBlacklist(Set<Identifier> blacklist) {
this.blacklist = blacklist;
}

@Override
public boolean isEnabled() {
return enabled;
}
Expand All @@ -50,26 +57,35 @@ public int getMaxHeight() {
return maxHeight;
}

@Override
public Set<Identifier> getBlacklist() {
return blacklist;
}

}

public static class Energy {
public static class Energy implements Base {

private boolean enabled = true;
private boolean expandWhenSneak = true;
private Map<String, Integer> colors = new HashMap<>();
private Map<String, String> units = new HashMap<>();
private Set<Identifier> blacklist = new HashSet<>();

public Energy() {
units.put("assets/megane", "E");
units.put("megane", "E");
units.put("indrev", "LF");
units.put("appliedenergistics2", "AE");
units.put("modern_industrialization", "EU");

colors.put("assets/megane", 0xFF710C00);
colors.put("megane", 0xFF710C00);
colors.put("astromine", 0xFF356D95);
colors.put("techreborn", 0xFF800800);
colors.put("indrev", 0xFF3B4ADE);
colors.put("appliedenergistics2", 0xFF64099F);
colors.put("modern_industrialization", 0xFFB70000);

blacklist.add(new Identifier("appliedenergistics2", "energy_acceptor"));
}

public void setEnabled(boolean enabled) {
Expand All @@ -92,6 +108,7 @@ public void setBlacklist(Set<Identifier> blacklist) {
this.blacklist = blacklist;
}

@Override
public boolean isEnabled() {
return enabled;
}
Expand All @@ -108,12 +125,15 @@ public Map<String, Integer> getColors() {
return colors;
}

@Override
public Set<Identifier> getBlacklist() {
return blacklist;
}

}

public static class Fluid {
public static class Fluid implements Base {

private boolean enabled = true;
private boolean expandWhenSneak = true;
private int barColor = 0xFF0D0D59;
Expand All @@ -135,6 +155,7 @@ public void setBlacklist(Set<Identifier> blacklist) {
this.blacklist = blacklist;
}

@Override
public boolean isEnabled() {
return enabled;
}
Expand All @@ -147,13 +168,17 @@ public int getBarColor() {
return barColor;
}

@Override
public Set<Identifier> getBlacklist() {
return blacklist;
}

}

public static class Progress {
public static class Progress implements Base {

private boolean enabled = true;
private boolean showWhenZero = false;
private Set<Identifier> blacklist = new HashSet<>();

public Progress() {
Expand All @@ -165,17 +190,28 @@ public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

public void setShowWhenZero(boolean showWhenZero) {
this.showWhenZero = showWhenZero;
}

public void setBlacklist(Set<Identifier> blacklist) {
this.blacklist = blacklist;
}

@Override
public boolean isEnabled() {
return enabled;
}

public boolean isShowWhenZero() {
return showWhenZero;
}

@Override
public Set<Identifier> getBlacklist() {
return blacklist;
}

}

}
Loading

0 comments on commit fe89344

Please sign in to comment.