Skip to content

Commit

Permalink
fix Inventory Overlay NBT logic
Browse files Browse the repository at this point in the history
  • Loading branch information
sakura-ryoko committed Nov 2, 2024
1 parent b54d949 commit b740995
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ author = masa
mod_file_name = minihud-fabric

# Current mod version
mod_version = 0.33.0-sakura.3
mod_version = 0.33.0-sakura.4

# Required malilib version
malilib_version = 0.22.0-sakura.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import fi.dy.masa.malilib.util.BlockUtils;
import fi.dy.masa.malilib.util.GuiUtils;
import fi.dy.masa.malilib.util.WorldUtils;
import fi.dy.masa.minihud.MiniHUD;
import fi.dy.masa.minihud.config.Configs;
import fi.dy.masa.minihud.data.EntitiesDataManager;
import fi.dy.masa.minihud.event.RenderHandler;
Expand Down Expand Up @@ -64,14 +65,20 @@ public void render(DrawContext drawContext, int mouseX, int mouseY, float delta)
List<ItemStack> armourItems = new ArrayList<>();
if (previewData.entity() instanceof AbstractHorseEntity)
{
armourItems.add(previewData.inv().getStack(0));
if (previewData.inv() == null)
{
MiniHUD.logger.error("InventoryOverlayScreen(): Horse inv() = null");
return;
}
armourItems.add(previewData.entity().getEquippedStack(EquipmentSlot.BODY));
armourItems.add(previewData.inv().getStack(0));
startSlot = 1;
totalSlots = previewData.inv().size() - 1;
}
else if (previewData.entity() instanceof WolfEntity)
{
armourItems.add(previewData.entity().getEquippedStack(EquipmentSlot.BODY));
//armourItems.add(ItemStack.EMPTY);
}

final InventoryOverlay.InventoryRenderType type = (previewData.entity() instanceof VillagerEntity) ? InventoryOverlay.InventoryRenderType.VILLAGER : InventoryOverlay.getBestInventoryType(previewData.inv(), previewData.nbt() != null ? previewData.nbt() : new NbtCompound(), previewData);
Expand Down
31 changes: 15 additions & 16 deletions src/main/java/fi/dy/masa/minihud/util/RayTraceUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,11 @@ else if (entity instanceof PiglinEntity)
//MiniHUD.logger.warn("getTargetInventoryFromEntity(): rawNbt: [{}]", nbt.toString());

// Fix for empty horse inv
if (inv != null && inv.size() == 1 &&
if (inv != null &&
//inv.size() == 1 &&
nbt.contains(NbtKeys.ITEMS) &&
nbt.getList(NbtKeys.ITEMS, Constants.NBT.TAG_COMPOUND).size() > 1 &&
!DataStorage.getInstance().hasIntegratedServer())
nbt.getList(NbtKeys.ITEMS, Constants.NBT.TAG_COMPOUND).size() > 1)
//!DataStorage.getInstance().hasIntegratedServer())
{
if (entity instanceof AbstractHorseEntity)
{
Expand All @@ -315,26 +316,31 @@ else if (entity instanceof PiglinEntity)
inv = null;
}
// Fix for saddled horse, no inv
else if (inv != null && inv.size() == 1 &&
nbt.contains(NbtKeys.SADDLE) &&
!DataStorage.getInstance().hasIntegratedServer())
else if (inv != null &&
inv.size() == 1 &&
nbt.contains(NbtKeys.SADDLE))
//!DataStorage.getInstance().hasIntegratedServer())
{
inv2 = InventoryUtils.getNbtInventoryHorseFix(nbt, -1, entity.getRegistryManager());
inv = null;
}
// Fix for empty Villager/Piglin inv
else if (inv != null && inv.size() == 8 &&
nbt.contains(NbtKeys.INVENTORY) &&
!nbt.getList(NbtKeys.INVENTORY, Constants.NBT.TAG_COMPOUND).isEmpty() &&
!DataStorage.getInstance().hasIntegratedServer())
!nbt.getList(NbtKeys.INVENTORY, Constants.NBT.TAG_COMPOUND).isEmpty())
//!DataStorage.getInstance().hasIntegratedServer())
{
inv2 = InventoryUtils.getNbtInventory(nbt, 8, entity.getRegistryManager());
inv = null;
}
else
{
inv2 = InventoryUtils.getNbtInventory(nbt, inv != null ? inv.size() : -1, entity.getRegistryManager());
inv = null;

if (inv2 != null)
{
inv = null;
}
}

//MiniHUD.logger.error("getTargetInventoryFromEntity(): inv.size [{}], inv2.size [{}]", inv != null ? inv.size() : "null", inv2 != null ? inv2.size() : "null");
Expand All @@ -350,14 +356,7 @@ else if (inv != null && inv.size() == 8 &&
return null;
}

//return new InventoryPreviewData(inv, null, entityLivingBase);
return new InventoryOverlay.Context(inv != null ? InventoryOverlay.getBestInventoryType(inv, nbt) : InventoryOverlay.getInventoryType(nbt),
inv, null, entityLivingBase, nbt);
}

/*
public record InventoryPreviewData(Inventory inv, @Nullable BlockEntity te, @Nullable LivingEntity entity)
{
}
*/
}

0 comments on commit b740995

Please sign in to comment.