Skip to content

Commit

Permalink
uhh, things
Browse files Browse the repository at this point in the history
#6 rename the mod icon

[api]
rewrite registries, hence the 2.0
entity inventory registry

[impl]
jukebox record tooltip
campfire item inventory
donkey & llama inventory tooltip
player inventory tooltip

[runtime]
show player's ender chest when hovering it
pet owner tooltip
status effect tooltip
align ":"
config side info
spawn egg icon
player head icon
  • Loading branch information
deirn committed Oct 8, 2020
1 parent fe89344 commit 19091c0
Show file tree
Hide file tree
Showing 75 changed files with 1,652 additions and 737 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# megane [![1][1]][6] [![2][2]][4] [![3][3]][5] [![14][14]][15] <img src="src/main/resources/pack.png" align="right"/>
# megane [![1][1]][6] [![2][2]][4] [![3][3]][5] [![14][14]][15] <img src="megane-runtime/src/main/resources/assets/megane/icon.png" align="right"/>

megane is a [HWYLA][11] plugin that adds useful tooltips such as energy, fluid volumes, and inventory contents.
megane also add an API for other mod creator to add that tooltip.
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.2.0+1.16
mod = 2.0.0+1.16
group = com.github.badasintended
archivesBaseName = megane

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package badasintended.megane.api.provider;

import badasintended.megane.api.registry.BaseTooltipRegistry;

import java.util.function.Function;

public interface EnergyProvider<T> extends BaseTooltipRegistry.Provider<T> {

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

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

@Override
public double getStored(T t) {
return stored.apply(t);
}

@Override
public double getMax(T t) {
return max.apply(t);
}
};
}

boolean hasEnergy(T t);

double getStored(T t);

double getMax(T t);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package badasintended.megane.api.provider;

import badasintended.megane.api.registry.BaseTooltipRegistry;
import net.minecraft.text.Text;

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

public interface FluidProvider<T> extends BaseTooltipRegistry.Provider<T> {

static <T> FluidProvider<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> FluidProvider<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 FluidProvider<T>() {
@Override
public boolean hasFluid(T t) {
return hasFluid.apply(t);
}

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

@Override
public Text getFluidName(T t, int slot) {
return name.apply(t, slot);
}

@Override
public double getStored(T t, int slot) {
return stored.apply(t, slot);
}

@Override
public double getMax(T t, int slot) {
return max.apply(t, slot);
}
};
}

boolean hasFluid(T t);

int getSlotCount(T t);

Text getFluidName(T t, int slot);

double getStored(T t, int slot);

double getMax(T t, int slot);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package badasintended.megane.api.provider;

import badasintended.megane.api.registry.BaseTooltipRegistry;
import net.minecraft.item.ItemStack;

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

public interface InventoryProvider<T> extends BaseTooltipRegistry.Provider<T> {

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

static <T> InventoryProvider<T> of(Function<T, Boolean> hasInventory, Function<T, Integer> size, BiFunction<T, Integer, ItemStack> stack) {
return new InventoryProvider<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
@@ -0,0 +1,56 @@
package badasintended.megane.api.provider;

import badasintended.megane.api.registry.BaseTooltipRegistry;
import net.minecraft.item.ItemStack;
import org.jetbrains.annotations.NotNull;

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

public interface ProgressProvider<T> extends BaseTooltipRegistry.Provider<T> {

static <T> ProgressProvider<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> ProgressProvider<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 ProgressProvider<T>() {
@Override
public boolean hasProgress(T t) {
return hasProgress.apply(t);
}

@Override
public int[] getInputSlots(T t) {
return inputSlots.apply(t);
}

@Override
public int[] getOutputSlots(T t) {
return outputSlots.apply(t);
}

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

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

boolean hasProgress(T t);

int[] getInputSlots(T t);

int[] getOutputSlots(T t);

@NotNull
ItemStack getStack(T t, int slot);

int getPercentage(T t);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package badasintended.megane.api.registry;

import java.util.*;

@SuppressWarnings("unchecked")
public abstract class BaseTooltipRegistry<T, P extends BaseTooltipRegistry.Provider<? extends T>> {

protected final Map<Class<? extends T>, P> entries = new HashMap<>();
protected final Set<Class<?>> nulls = new HashSet<>();

private final Class<T> tClass;

public BaseTooltipRegistry(Class<T> tClass) {
this.tClass = tClass;
}

public Map<Class<? extends T>, P> getEntries() {
return entries;
}

public <K extends T> void register(Class<K> clazz, Provider<K> provider) {
getEntries().put(clazz, (P) provider);
}

public P get(T v) {
if (nulls.contains(v.getClass())) return null;

Class<?> clazz = v.getClass();
boolean containsKey = getEntries().containsKey(clazz);

if (!containsKey) do {
clazz = clazz.getSuperclass();
containsKey = getEntries().containsKey(clazz);
} while (!containsKey && clazz != tClass);

if (containsKey) {
P provider = getEntries().get(clazz);
getEntries().putIfAbsent((Class<? extends T>) v.getClass(), provider);
return provider;
}

nulls.add(v.getClass());
return null;
}

public interface Provider<T> {

}

}

This file was deleted.

Loading

1 comment on commit 19091c0

@deirn
Copy link
Member Author

@deirn deirn commented on 19091c0 Oct 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@qsefthuopq you may want to update your translation

Please sign in to comment.