Skip to content

Commit

Permalink
Inspecio v1.2.0: add an API for #34, fix #26, #43.
Browse files Browse the repository at this point in the history
  • Loading branch information
LambdAurora committed Jan 1, 2022
1 parent d3d27f3 commit 26bfb69
Show file tree
Hide file tree
Showing 49 changed files with 458 additions and 156 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,12 @@

## 1.2.0

- Added configuration settings to disable lodestone coordinates, and repair cost ([#26](https://github.com/Queerbric/Inspecio/issues/26)).
- Added an interface for custom inventory sizes and deserialization for inventory tooltips ([#34](https://github.com/Queerbric/Inspecio/issues/34)).
- Added Russian translations ([#45](https://github.com/Queerbric/Inspecio/pull/45)).
- Fixed OutOfBoundsException in Potion/TippedArrowMixin ([#38](https://github.com/Queerbric/Inspecio/pull/38)).
- Fixed food effects not displaying when hunger tooltip is disabled ([#42](https://github.com/Queerbric/Inspecio/issues/42)).
- 1.18 specific changes:
- Fixed broken tooltips in 1.18 ([#43](https://github.com/Queerbric/Inspecio/issues/43)).
- Fixed broken loom patterns in 1.18 ([#49](https://github.com/Queerbric/Inspecio/issues/49)).
- Fixed beacon crashing the game in 1.18 ([#50](https://github.com/Queerbric/Inspecio/issues/50)).
2 changes: 1 addition & 1 deletion HEADER
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2020 LambdAurora <[email protected]>, Emi
Copyright (c) 2020 - 2022 LambdAurora <[email protected]>, Emi

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
Expand Down
78 changes: 43 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ Compact:

#### Lodestone Compass

Only shows up if Advanced Tooltip is enabled (`F3 + H`).
Only shows up if Advanced Tooltip is enabled (`F3 + H`) and if the config option is enabled.
![lodestone_compass](images/lodestone_compass.png)

#### Repair Cost

Only shows up if Advanced Tooltip is enabled (`F3 + H`).
Only shows up if Advanced Tooltip is enabled (`F3 + H`) and if the config option is enabled.
![repair_cost](images/repair_cost.png)

## Configuration
Expand All @@ -114,41 +114,20 @@ Here's the default configuration:

```json
{
"food": {
"hunger": true,
"saturation": "merged"
},
"jukebox": "fancy",
"sign": "fancy",
"entities": {
"armor_stand": {
"enabled": true,
"always_show_name": false,
"spin": true
},
"bee": {
"enabled": true,
"always_show_name": false,
"spin": true
},
"fish_bucket": {
"enabled": true,
"always_show_name": false,
"spin": true
},
"spawn_egg": {
"enabled": true,
"always_show_name": false,
"spin": true
},
"pufferfish_puff_state": 2
"advanced_tooltips": {
"repair_cost": true,
"lodestone_coords": false
},
"filled_map": {
"enabled": true,
"show_player_icon": false
},
"armor": true,
"banner_pattern": true,
"food": {
"hunger": true,
"saturation": "merged"
},
"containers": {
"campfire": true,
"storage": {
Expand All @@ -164,21 +143,50 @@ Here's the default configuration:
}
},
"effects": {
"potions": true,
"tipped_arrows": true,
"spectral_arrow": true,
"food": true,
"hidden_motion": true,
"beacon": true
}
"beacon": true,
"potions": true,
"tipped_arrows": true,
"spectral_arrow": true
},
"entities": {
"fish_bucket": {
"enabled": true,
"always_show_name": false,
"spin": true
},
"spawn_egg": {
"enabled": true,
"always_show_name": false,
"spin": true
},
"pufferfish_puff_state": 2,
"armor_stand": {
"enabled": true,
"always_show_name": false,
"spin": true
},
"bee": {
"enabled": true,
"always_show_name": false,
"spin": true
}
},
"armor": true,
"banner_pattern": true
}
```

Here's a list of each configuration entries and what they do:

- `armor` (`bool`) - if `true` then displays the armor bar on armor items, else `false`.
- `banner_pattern` (`bool`) - if `true` then displays the pattern in the tooltip of banner patterns, else `false`.
- `advanced_tooltips`
- `repair_cost` (`bool`) - if `true`, will display the repair cost value if the game has advanced tooltips enabled (F3 + H).
- `lodestone_coords` (`bool`) - if `true`, will display the lodestone coordinates on lodestone compass if the game has advanced tooltips enabled (F3 + H).
- `containers`
- `campfire` (`bool`) - if `true` then displays a special tooltip on campfires which hold custom NBT.
- `storage`
- `enabled` (`bool`) - `true` if the inventory of storage items like chests, barrels, etc. should be shown in the tooltip, else `false`.
- `compact` (`bool`) - `true` if the inventory should be compacted to take as little space as possible, else `false`.
Expand Down
11 changes: 1 addition & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,7 @@ task publishModrinth(type: TaskModrinthUpload) {
publishing {
publications {
mavenJava(MavenPublication) {
// add all the jars that should be included when publishing to maven
artifact(jar) {
builtBy remapJar
}
artifact("${project.buildDir.absolutePath}/libs/${archivesBaseName}-${project.version}.jar") {
builtBy remapJar
}
artifact(sourcesJar) {
builtBy remapSourcesJar
}
from components.java
}
}

Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ org.gradle.jvmargs=-Xmx1G

# Fabric properties
minecraft_version=1.18.1
quilt_mappings=1
loader_version=0.12.11
fabric_api_version=0.44.0+1.18
quilt_mappings=5
loader_version=0.12.12
fabric_api_version=0.45.0+1.18

# Mod properties
mod_version=1.1.0
mod_version=1.2.0
maven_group=io.github.queerbric
archives_base_name=inspecio
modrinth_id=a93H3mKU
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
56 changes: 52 additions & 4 deletions src/main/java/io/github/queerbric/inspecio/Inspecio.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 LambdAurora <[email protected]>, Emi
* Copyright (c) 2020 - 2022 LambdAurora <[email protected]>, Emi
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand All @@ -17,16 +17,22 @@

package io.github.queerbric.inspecio;

import io.github.queerbric.inspecio.api.InspecioEntrypoint;
import io.github.queerbric.inspecio.api.InventoryProvider;
import io.github.queerbric.inspecio.resource.InspecioResourceReloader;
import io.github.queerbric.inspecio.tooltip.ConvertibleTooltipData;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.rendering.v1.TooltipComponentCallback;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.block.Block;
import net.minecraft.block.DispenserBlock;
import net.minecraft.block.HopperBlock;
import net.minecraft.block.ShulkerBoxBlock;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.inventory.Inventories;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
Expand All @@ -37,8 +43,10 @@
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.DyeColor;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.registry.Registry;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -50,7 +58,7 @@
/**
* Represents the Inspecio mod.
*
* @version 1.1.0
* @version 1.2.0
* @since 1.0.0
*/
public class Inspecio implements ClientModInitializer {
Expand All @@ -68,6 +76,26 @@ public void onInitializeClient() {
this.reloadConfig();
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(this.resourceReloader);

InventoryProvider.register((stack, config) -> {
if (config != null && config.isEnabled() && stack.getItem() instanceof BlockItem blockItem) {
DyeColor color = null;
if (blockItem.getBlock() instanceof ShulkerBoxBlock shulkerBoxBlock && ((InspecioConfig.ShulkerBoxConfig) config).hasColor())
color = shulkerBoxBlock.getColor();

var nbt = BlockItem.getBlockEntityNbtFromStack(stack);
if (nbt == null) return null;

DefaultedList<ItemStack> inventory = DefaultedList.ofSize(getInvSizeFor(stack), ItemStack.EMPTY);
Inventories.readNbt(nbt, inventory);
if (inventory.stream().allMatch(ItemStack::isEmpty))
return null;

return new InventoryProvider.Context(inventory, color);
}

return null;
});

TooltipComponentCallback.EVENT.register(data -> {
if (data instanceof ConvertibleTooltipData convertible) {
return convertible.getComponent();
Expand All @@ -76,6 +104,11 @@ public void onInitializeClient() {
});

InspecioCommand.init();

var entrypoints = FabricLoader.getInstance().getEntrypoints("inspecio", InspecioEntrypoint.class);
for (var entrypoint : entrypoints) {
entrypoint.onInspecioInitialized();
}
}

/**
Expand Down Expand Up @@ -129,7 +162,10 @@ public static Inspecio get() {
}

static Consumer<String> onConfigError(String path) {
return error -> get().warn("Configuration error at \"" + path + "\", error: " + error);
return error -> {
InspecioConfig.shouldSaveConfigAfterLoad = true;
get().warn("Configuration error at \"" + path + "\", error: " + error);
};
}

static String getVersion() {
Expand All @@ -142,6 +178,18 @@ static String getVersion() {
}).orElse("unknown");
}

private static int getInvSizeFor(ItemStack stack) {
if (stack.getItem() instanceof BlockItem blockItem) {
var block = blockItem.getBlock();
if (block instanceof DispenserBlock)
return 9;
else if (block instanceof HopperBlock)
return 5;
return 27;
}
return 0;
}

/**
* Appends block item tooltips.
*
Expand Down Expand Up @@ -193,7 +241,7 @@ public static void removeVanillaTooltips(List<Text> tooltips, int fromIndex) {
}

public static @Nullable StatusEffectInstance getRawEffectFromTag(NbtCompound tag, String tagKey) {
if(tag == null) {
if (tag == null) {
return null;
}
if (tag.contains(tagKey, NbtElement.INT_TYPE)) {
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/io/github/queerbric/inspecio/InspecioCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 LambdAurora <[email protected]>, Emi
* Copyright (c) 2020 - 2022 LambdAurora <[email protected]>, Emi
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand Down Expand Up @@ -46,6 +46,7 @@ private InspecioCommand() {

static void init() {
var literalSubCommand = literal("config");

{
literalSubCommand.then(literal("reload")
.executes(ctx -> {
Expand Down Expand Up @@ -133,6 +134,15 @@ static void init() {
.executes(onGetter("sign", getter(InspecioConfig::getSignTooltipMode)))
.then(argument("value", SignTooltipMode.SignArgumentType.signTooltipMode())
.executes(InspecioCommand::onSetSign))
).then(literal("advanced_tooltips")
.then(literal("repair_cost")
.executes(onGetter("advanced_tooltips/repair_cost", getter(cfg -> cfg.getAdvancedTooltipsConfig().hasRepairCost())))
.then(argument("value", BoolArgumentType.bool())
.executes(onBooleanSetter("advanced_tooltips/repair_cost", setter((cfg, val) -> cfg.getAdvancedTooltipsConfig().setRepairCost(val))))))
.then(literal("lodestone_coords")
.executes(onGetter("advanced_tooltips/lodestone_coords", getter(cfg -> cfg.getAdvancedTooltipsConfig().hasLodestoneCoords())))
.then(argument("value", BoolArgumentType.bool())
.executes(onBooleanSetter("advanced_tooltips/lodestone_coords", setter((cfg, val) -> cfg.getAdvancedTooltipsConfig().setLodestoneCoords(val))))))
);
}

Expand All @@ -144,7 +154,7 @@ static void init() {
}

private static LiteralArgumentBuilder<FabricClientCommandSource> initContainer(String name,
Function<InspecioConfig, InspecioConfig.StorageContainerConfig> containerGetter) {
Function<InspecioConfig, InspecioConfig.StorageContainerConfig> containerGetter) {
var prefix = "containers/" + name;
return literal(name)
.executes(onGetter(prefix, () -> containerGetter.apply(Inspecio.get().getConfig()).isEnabled()))
Expand All @@ -161,7 +171,7 @@ private static LiteralArgumentBuilder<FabricClientCommandSource> initContainer(S
}

private static LiteralArgumentBuilder<FabricClientCommandSource> initEntity(String name,
Function<InspecioConfig, InspecioConfig.EntityConfig> containerGetter) {
Function<InspecioConfig, InspecioConfig.EntityConfig> containerGetter) {
var prefix = "entities/" + name;
return literal(name)
.executes(onGetter(prefix, () -> containerGetter.apply(Inspecio.get().getConfig()).isEnabled()))
Expand Down
Loading

0 comments on commit 26bfb69

Please sign in to comment.