Skip to content

Commit

Permalink
Implement #44
Browse files Browse the repository at this point in the history
  • Loading branch information
JackFred2 committed Jan 4, 2022
1 parent e91a5d5 commit b5864fd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx2G

mod_version = 1.1.6
mod_version = 1.1.7
maven_group = red.jackf
archives_base_name = chesttracker

Expand All @@ -19,6 +19,6 @@ cloth_client_version=2.0.54
modmenu_version=3.0.0
libgui_version=5.0.0-beta.2+1.18-rc1

whereisit_version=1.14.4
whereisit_version=1.14.6
expanded_storage_file_id=3539944
ninjaphenix_container_lib_file_id=3539922
16 changes: 13 additions & 3 deletions src/main/java/red/jackf/chesttracker/ChestTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@
import red.jackf.chesttracker.memory.MemoryDatabase;
import red.jackf.chesttracker.memory.MemoryUtils;
import red.jackf.chesttracker.resource.ButtonPositionManager;
import red.jackf.whereisit.WhereIsIt;
import red.jackf.whereisit.WhereIsItClient;
import red.jackf.whereisit.client.PositionData;
import red.jackf.whereisit.client.RenderUtils;
import red.jackf.whereisit.compat.OptifineHooks;

import java.util.Collection;

Expand Down Expand Up @@ -116,6 +118,7 @@ public static int sliderValueToRange(int sliderValue) {
}

public static void drawLabels(WorldRenderContext context) {
if (ChestTracker.CONFIG.visualOptions.nameRenderRange == 0) return;
MemoryDatabase database = MemoryDatabase.getCurrent();
if (database == null) return;
MinecraftClient mc = MinecraftClient.getInstance();
Expand All @@ -124,10 +127,12 @@ public static void drawLabels(WorldRenderContext context) {
Collection<Memory> toRender = database.getNamedMemories(mc.world.getRegistryKey().getValue());
for (Memory memory : toRender) {
BlockPos blockPos = memory.getPosition();
if (blockPos != null && memory.getTitle() != null && !RenderUtils.FOUND_ITEM_POSITIONS.containsKey(blockPos)) {
boolean alreadyHandled = WhereIsIt.CONFIG.shouldShowResultLabels() && RenderUtils.FOUND_ITEM_POSITIONS.containsKey(blockPos);
if (blockPos != null && memory.getTitle() != null && !alreadyHandled) {
Vec3d pos = Vec3d.of(blockPos);
if (memory.getNameOffset() != null) pos = pos.add(memory.getNameOffset());
RenderUtils.drawTextWithBackground(context, pos, memory.getTitle(), CONFIG.visualOptions.nameRenderRange);
if (!context.world().getBlockState(blockPos.up()).isOpaque()) pos = pos.add(0, 1d, 0);
RenderUtils.drawTextWithBackground(context, pos, memory.getTitle(), CONFIG.visualOptions.nameRenderRange, true);
}
}
}
Expand All @@ -143,7 +148,12 @@ public void onInitializeClient() {
if (database != null) database.save();
});

WorldRenderEvents.AFTER_ENTITIES.register(ChestTracker::drawLabels);
WorldRenderEvents.BEFORE_BLOCK_OUTLINE.register((context, hitResult) -> {
OptifineHooks.doOptifineAwareRender(context, (context1, simple) -> {
ChestTracker.drawLabels(context1);
});
return true;
});

WhereIsItClient.SEARCH_FOR_ITEM.register((item, matchNbt, compoundTag) -> {
ItemStack stack = new ItemStack(item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class ChestTrackerConfig implements ConfigData {
@Override
public void validatePostLoad() {
visualOptions.borderColour = MathHelper.clamp(visualOptions.borderColour, 0, 0xffffff);
visualOptions.nameRenderRange = MathHelper.clamp(visualOptions.nameRenderRange, 1, 16);
visualOptions.nameRenderRange = MathHelper.clamp(visualOptions.nameRenderRange, 0, 16);
visualOptions.rowCount = MathHelper.clamp(visualOptions.rowCount, 6, 12);
visualOptions.columnCount = MathHelper.clamp(visualOptions.columnCount, 9, 18);
databaseOptions.destroyedMemoryCheckInterval = MathHelper.clamp(databaseOptions.destroyedMemoryCheckInterval, 0, 60);
Expand All @@ -40,7 +40,7 @@ public void validatePostLoad() {
public static class VisualOptions {
@ConfigEntry.ColorPicker
public int borderColour = 0x00baff;
@ConfigEntry.BoundedDiscrete(min = 1, max = 16)
@ConfigEntry.BoundedDiscrete(min = 0, max = 16)
public int nameRenderRange = 12;
@ConfigEntry.BoundedDiscrete(min = 6, max = 12)
public int rowCount = 6;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"fabricloader": ">=0.7.4",
"fabric": "*",
"minecraft": "1.18.x",
"whereisit": ">=1.12.0",
"whereisit": ">=1.14.6",
"cloth-config2": ">=6.0.0"
},
"suggests": {
Expand Down

0 comments on commit b5864fd

Please sign in to comment.