-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
Showing
50 changed files
with
877 additions
and
354 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
megane-api/src/main/java/badasintended/megane/api/registry/InventoryTooltipRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.