Skip to content

Commit

Permalink
fix: Use the correct Pair() system.
Browse files Browse the repository at this point in the history
add: update to the InventoryOverlayHandler System, and remove the previous Screen.
  • Loading branch information
sakura-ryoko committed Dec 30, 2024
1 parent 9842bff commit 1312183
Show file tree
Hide file tree
Showing 10 changed files with 571 additions and 653 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mod_file_name = minihud-fabric
mod_version = 0.32.55

# Required malilib version
malilib_version = 3f02eb2ef6
malilib_version = 1.21-0.21.6

# Minecraft, Fabric Loader and API and mappings versions
minecraft_version_out = 1.21
Expand Down
31 changes: 25 additions & 6 deletions src/main/java/fi/dy/masa/minihud/data/EntitiesDataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.Nullable;
import com.google.gson.JsonObject;
import com.llamalad7.mixinextras.lib.apache.commons.tuple.Pair;
import org.apache.commons.lang3.tuple.Pair;

import com.mojang.datafixers.util.Either;
import net.minecraft.block.BlockEntityProvider;
Expand Down Expand Up @@ -36,6 +36,7 @@
import net.minecraft.world.World;

import fi.dy.masa.malilib.interfaces.IClientTickHandler;
import fi.dy.masa.malilib.interfaces.IDataSyncer;
import fi.dy.masa.malilib.network.ClientPlayHandler;
import fi.dy.masa.malilib.network.IPluginClientPlayHandler;
import fi.dy.masa.malilib.util.Constants;
Expand All @@ -54,7 +55,7 @@
import fi.dy.masa.minihud.util.EntityUtils;

@SuppressWarnings("deprecation")
public class EntitiesDataManager implements IClientTickHandler
public class EntitiesDataManager implements IClientTickHandler, IDataSyncer
{
private static final EntitiesDataManager INSTANCE = new EntitiesDataManager();

Expand Down Expand Up @@ -83,12 +84,14 @@ public static EntitiesDataManager getInstance()
private ClientWorld clientWorld;

@Nullable
@Override
public World getWorld()
{
return WorldUtils.getBestWorld(mc);
}

private ClientWorld getClientWorld()
@Override
public ClientWorld getClientWorld()
{
if (this.clientWorld == null)
{
Expand Down Expand Up @@ -186,6 +189,7 @@ public IPluginClientPlayHandler<ServuxEntitiesPacket.Payload> getNetworkHandler(
return HANDLER;
}

@Override
public void reset(boolean isLogout)
{
if (isLogout)
Expand Down Expand Up @@ -257,6 +261,7 @@ private void tickCache()
}
}

@Override
public @Nullable NbtCompound getFromBlockEntityCacheNbt(BlockPos pos)
{
if (this.blockEntityCache.containsKey(pos))
Expand All @@ -267,6 +272,7 @@ private void tickCache()
return null;
}

@Override
public @Nullable BlockEntity getFromBlockEntityCache(BlockPos pos)
{
if (this.blockEntityCache.containsKey(pos))
Expand All @@ -277,6 +283,7 @@ private void tickCache()
return null;
}

@Override
public @Nullable NbtCompound getFromEntityCacheNbt(int entityId)
{
if (this.entityCache.containsKey(entityId))
Expand All @@ -287,6 +294,7 @@ private void tickCache()
return null;
}

@Override
public @Nullable Entity getFromEntityCache(int entityId)
{
if (this.entityCache.containsKey(entityId))
Expand Down Expand Up @@ -346,12 +354,14 @@ public int getEntityCacheCount()
return this.entityCache.size();
}

@Override
public void onGameInit()
{
ClientPlayHandler.getInstance().registerClientPlayHandler(HANDLER);
HANDLER.registerPlayPayload(ServuxEntitiesPacket.Payload.ID, ServuxEntitiesPacket.Payload.CODEC, IPluginClientPlayHandler.BOTH_CLIENT);
}

@Override
public void onWorldPre()
{
if (DataStorage.getInstance().hasIntegratedServer() == false)
Expand All @@ -360,6 +370,7 @@ public void onWorldPre()
}
}

@Override
public void onWorldJoin()
{
// NO-OP
Expand Down Expand Up @@ -406,6 +417,7 @@ public void onPacketFailure()
this.hasInValidServux = true;
}

@Override
public @Nullable Pair<BlockEntity, NbtCompound> requestBlockEntity(World world, BlockPos pos)
{
if (this.blockEntityCache.containsKey(pos))
Expand Down Expand Up @@ -438,7 +450,8 @@ else if (world.getBlockState(pos).getBlock() instanceof BlockEntityProvider)
return null;
}

public @Nullable Pair<Entity, NbtCompound> requestEntity(int entityId)
@Override
public @Nullable Pair<Entity, NbtCompound> requestEntity(World world, int entityId)
{
if (this.entityCache.containsKey(entityId))
{
Expand Down Expand Up @@ -473,6 +486,7 @@ else if (world.getBlockState(pos).getBlock() instanceof BlockEntityProvider)
}

@Nullable
@Override
public Inventory getBlockInventory(World world, BlockPos pos, boolean useNbt)
{
if (this.blockEntityCache.containsKey(pos))
Expand Down Expand Up @@ -545,7 +559,8 @@ public Inventory getBlockInventory(World world, BlockPos pos, boolean useNbt)
}

@Nullable
public Inventory getEntityInventory(int entityId, boolean useNbt)
@Override
public Inventory getEntityInventory(World world, int entityId, boolean useNbt)
{
if (this.entityCache.containsKey(entityId) && this.getWorld() != null)
{
Expand Down Expand Up @@ -589,7 +604,7 @@ else if (entity instanceof PiglinEntity)

if (Configs.Generic.ENTITY_DATA_SYNC.getBooleanValue())
{
this.requestEntity(entityId);
this.requestEntity(this.getWorld(), entityId);
}

return null;
Expand Down Expand Up @@ -650,6 +665,7 @@ private void requestServuxEntityData(int entityId)
}

@Nullable
@Override
public BlockEntity handleBlockEntityData(BlockPos pos, NbtCompound nbt, @Nullable Identifier type)
{
this.pendingBlockEntitiesQueue.remove(pos);
Expand Down Expand Up @@ -732,6 +748,7 @@ public BlockEntity handleBlockEntityData(BlockPos pos, NbtCompound nbt, @Nullabl
}

@Nullable
@Override
public Entity handleEntityData(int entityId, NbtCompound nbt)
{
this.pendingEntitiesQueue.remove(entityId);
Expand Down Expand Up @@ -770,11 +787,13 @@ public Entity handleEntityData(int entityId, NbtCompound nbt)
return entity;
}

@Override
public void handleBulkEntityData(int transactionId, NbtCompound nbt)
{
// todo
}

@Override
public void handleVanillaQueryNbt(int transactionId, NbtCompound nbt)
{
Either<BlockPos, Integer> either = this.transactionToBlockPosOrEntityId.remove(transactionId);
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/fi/dy/masa/minihud/event/RenderHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.concurrent.CompletableFuture;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import com.llamalad7.mixinextras.lib.apache.commons.tuple.Pair;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
import org.joml.Matrix4f;

Expand Down Expand Up @@ -82,6 +82,7 @@
import fi.dy.masa.minihud.data.HudDataManager;
import fi.dy.masa.minihud.data.MobCapDataHandler;
import fi.dy.masa.minihud.mixin.*;
import fi.dy.masa.minihud.renderer.InventoryOverlayHandler;
import fi.dy.masa.minihud.renderer.OverlayRenderer;
import fi.dy.masa.minihud.util.DataStorage;
import fi.dy.masa.minihud.util.IServerEntityManager;
Expand Down Expand Up @@ -179,12 +180,16 @@ public void onRenderGameOverlayPost(DrawContext drawContext)
if (Configs.Generic.INVENTORY_PREVIEW_ENABLED.getBooleanValue() &&
Configs.Generic.INVENTORY_PREVIEW.getKeybind().isKeybindHeld())
{
/*
var inventory = RayTraceUtils.getTargetInventory(mc, true);
if (inventory != null)
{
fi.dy.masa.minihud.renderer.RenderUtils.renderInventoryOverlay(inventory, drawContext);
}
*/

InventoryOverlayHandler.getInstance().getRenderContext(drawContext, mc.getProfiler(), mc);

// OG method (Works with Crafters also)
//fi.dy.masa.minihud.renderer.RenderUtils.renderInventoryOverlay(mc, drawContext);
Expand Down Expand Up @@ -221,7 +226,7 @@ else if (stack.isOf(Items.ENDER_CHEST) && Configs.Generic.SHULKER_DISPLAY_ENDER_

if (player != null)
{
Pair<Entity, NbtCompound> pair = EntitiesDataManager.getInstance().requestEntity(player.getId());
Pair<Entity, NbtCompound> pair = EntitiesDataManager.getInstance().requestEntity(world, player.getId());
NbtCompound nbt = new NbtCompound();
EnderChestInventory inv;

Expand Down Expand Up @@ -1713,7 +1718,7 @@ public Pair<Entity, NbtCompound> getTargetEntity(World world, MinecraftClient mc
}
else
{
pair = EntitiesDataManager.getInstance().requestEntity(lookedEntity.getId());
pair = EntitiesDataManager.getInstance().requestEntity(world, lookedEntity.getId());
}

// Remember the last entity so the "refresh time" is smoothed over.
Expand Down
Loading

0 comments on commit 1312183

Please sign in to comment.