-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
d3d27f3
commit 26bfb69
Showing
49 changed files
with
458 additions
and
156 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
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 | ||
|
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
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 |
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 |
---|---|---|
@@ -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 | ||
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -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 { | ||
|
@@ -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(); | ||
|
@@ -76,6 +104,11 @@ public void onInitializeClient() { | |
}); | ||
|
||
InspecioCommand.init(); | ||
|
||
var entrypoints = FabricLoader.getInstance().getEntrypoints("inspecio", InspecioEntrypoint.class); | ||
for (var entrypoint : entrypoints) { | ||
entrypoint.onInspecioInitialized(); | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -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() { | ||
|
@@ -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. | ||
* | ||
|
@@ -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)) { | ||
|
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 |
---|---|---|
@@ -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 | ||
|
@@ -46,6 +46,7 @@ private InspecioCommand() { | |
|
||
static void init() { | ||
var literalSubCommand = literal("config"); | ||
|
||
{ | ||
literalSubCommand.then(literal("reload") | ||
.executes(ctx -> { | ||
|
@@ -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)))))) | ||
); | ||
} | ||
|
||
|
@@ -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())) | ||
|
@@ -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())) | ||
|
Oops, something went wrong.