Skip to content

Commit

Permalink
allow using inventory Preview on Empty Block Entities.
Browse files Browse the repository at this point in the history
  • Loading branch information
sakura-ryoko committed Dec 7, 2024
1 parent 824d762 commit f6004c6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ else if (context.nbt() != null)
}
}

//Tweakeroo.logger.warn("renderInventoryOverlay: type [{}] // Nbt Type [{}]", type.toString(), context.nbt() != null ? InventoryOverlay.getInventoryType(context.nbt()) : "INVALID");
//Tweakeroo.logger.warn("renderInventoryOverlay: type [{}] // Nbt Type [{}] // inv.isEmpty({})", type.toString(), context.nbt() != null ? InventoryOverlay.getInventoryType(context.nbt()) : "INVALID", inv.isEmpty());

if (context.be() != null && context.be().getCachedState().getBlock() instanceof ShulkerBoxBlock sbb)
{
Expand Down
29 changes: 14 additions & 15 deletions src/main/java/fi/dy/masa/tweakeroo/util/RayTraceUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import java.util.List;
import java.util.Optional;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import com.llamalad7.mixinextras.lib.apache.commons.tuple.Pair;
import org.jetbrains.annotations.Nullable;

import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider;
Expand Down Expand Up @@ -35,6 +35,7 @@
import net.minecraft.world.World;

import fi.dy.masa.malilib.render.InventoryOverlay;
import fi.dy.masa.malilib.util.InventoryUtils;
import fi.dy.masa.malilib.util.*;
import fi.dy.masa.tweakeroo.data.ServerDataSyncer;
import fi.dy.masa.tweakeroo.mixin.IMixinAbstractHorseEntity;
Expand Down Expand Up @@ -166,8 +167,7 @@ public static HitResult getRayTraceFromEntity(World worldIn, Entity entityIn, bo
lastBlockEntityContext = null;
}

if (ctx != null &&
(ctx.inv() != null && !ctx.inv().isEmpty()))
if (ctx != null && ctx.inv() != null)
{
lastBlockEntityContext = Pair.of(pos, ctx);
return ctx;
Expand Down Expand Up @@ -275,7 +275,7 @@ else if (lastEntityContext != null && lastEntityContext.getLeft().equals(entity.

if (enderPair != null && enderPair.getRight() != null && enderPair.getRight().contains(NbtKeys.ENDER_ITEMS))
{
enderItems = fi.dy.masa.malilib.util.InventoryUtils.getPlayerEnderItemsFromNbt(enderPair.getRight(), world.getRegistryManager());
enderItems = InventoryUtils.getPlayerEnderItemsFromNbt(enderPair.getRight(), world.getRegistryManager());
}
else
{
Expand Down Expand Up @@ -348,37 +348,36 @@ else if (entity instanceof PiglinEntity)

// Fix for empty horse inv
if (inv != null &&
nbt.contains(NbtKeys.ITEMS) &&
nbt.getList(NbtKeys.ITEMS, Constants.NBT.TAG_COMPOUND).size() > 1)
nbt.contains(NbtKeys.ITEMS) &&
nbt.getList(NbtKeys.ITEMS, Constants.NBT.TAG_COMPOUND).size() > 1)
{
if (entity instanceof AbstractHorseEntity)
{
inv2 = fi.dy.masa.malilib.util.InventoryUtils.getNbtInventoryHorseFix(nbt, -1, entity.getRegistryManager());
inv2 = InventoryUtils.getNbtInventoryHorseFix(nbt, -1, entity.getRegistryManager());
}
else
{
inv2 = fi.dy.masa.malilib.util.InventoryUtils.getNbtInventory(nbt, -1, entity.getRegistryManager());
inv2 = InventoryUtils.getNbtInventory(nbt, -1, entity.getRegistryManager());
}
inv = null;
}
// Fix for saddled horse, no inv
else if (inv != null &&
nbt.contains(NbtKeys.SADDLE))
else if (inv != null && nbt.contains(NbtKeys.SADDLE))
{
inv2 = fi.dy.masa.malilib.util.InventoryUtils.getNbtInventoryHorseFix(nbt, -1, entity.getRegistryManager());
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())
nbt.contains(NbtKeys.INVENTORY) &&
!nbt.getList(NbtKeys.INVENTORY, Constants.NBT.TAG_COMPOUND).isEmpty())
{
inv2 = fi.dy.masa.malilib.util.InventoryUtils.getNbtInventory(nbt, 8, entity.getRegistryManager());
inv2 = InventoryUtils.getNbtInventory(nbt, 8, entity.getRegistryManager());
inv = null;
}
else
{
inv2 = fi.dy.masa.malilib.util.InventoryUtils.getNbtInventory(nbt, inv != null ? inv.size() : -1, entity.getRegistryManager());
inv2 = InventoryUtils.getNbtInventory(nbt, inv != null ? inv.size() : -1, entity.getRegistryManager());

if (inv2 != null)
{
Expand Down

0 comments on commit f6004c6

Please sign in to comment.