diff --git a/src/main/java/fi/dy/masa/malilib/MaLiLibReference.java b/src/main/java/fi/dy/masa/malilib/MaLiLibReference.java index 0c30f8e009..9a319b83e9 100644 --- a/src/main/java/fi/dy/masa/malilib/MaLiLibReference.java +++ b/src/main/java/fi/dy/masa/malilib/MaLiLibReference.java @@ -7,6 +7,6 @@ public class MaLiLibReference public static final String MOD_ID = "malilib"; public static final String MOD_NAME = "MaLiLib"; public static final String MOD_VERSION = StringUtils.getModVersionString(MOD_ID); - public static final boolean DEBUG_MODE = false; + public static final boolean DEBUG_MODE = true; public static final boolean EXPERIMENTAL_MODE = false; } diff --git a/src/main/java/fi/dy/masa/malilib/interfaces/IDataSyncer.java b/src/main/java/fi/dy/masa/malilib/interfaces/IDataSyncer.java index 1c93c7b56a..c8269e3d40 100644 --- a/src/main/java/fi/dy/masa/malilib/interfaces/IDataSyncer.java +++ b/src/main/java/fi/dy/masa/malilib/interfaces/IDataSyncer.java @@ -3,49 +3,360 @@ import javax.annotation.Nullable; import org.apache.commons.lang3.tuple.Pair; +import net.minecraft.block.BlockEntityProvider; +import net.minecraft.block.BlockState; +import net.minecraft.block.ChestBlock; import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.ChestBlockEntity; +import net.minecraft.block.enums.ChestType; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.Entity; +import net.minecraft.entity.mob.PiglinEntity; +import net.minecraft.entity.passive.AbstractHorseEntity; +import net.minecraft.entity.passive.VillagerEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.inventory.DoubleInventory; import net.minecraft.inventory.Inventory; +import net.minecraft.inventory.SimpleInventory; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import fi.dy.masa.malilib.mixin.IMixinAbstractHorseEntity; +import fi.dy.masa.malilib.mixin.IMixinPiglinEntity; +import fi.dy.masa.malilib.util.InventoryUtils; +import fi.dy.masa.malilib.util.WorldUtils; + +/** + * Used as a common Server Data Syncer interface used by the IInventoryOverlayHandler Interface. + * A lot of this is optional, but the main required items for a Successful Data Syncer are + * the Requesters, Getters, and the Vanilla Packet Handler; at the Minimum. + * - + * The included default code is only enough to get the Data from the ServerWorld in Single Player. + */ public interface IDataSyncer { - void reset(boolean isLogout); + /** + * Get the 'Best World' object + * @return () + */ + @Nullable + default World getWorld() + { + if (MinecraftClient.getInstance() == null) + { + return null; + } + + return WorldUtils.getBestWorld(MinecraftClient.getInstance()); + } + + /** + * Get the Client World Object + * @return () + */ + @Nullable + default ClientWorld getClientWorld() + { + if (MinecraftClient.getInstance().world == null) + { + return null; + } - void onGameInit(); + return MinecraftClient.getInstance().world; + } - void onWorldPre(); + /** + * Called when Joining / Leaving worlds; used to "reset" any Data Syncer Cache. + * @param isLogout () + */ + default void reset(boolean isLogout) { } + + /** + * If you need to initialize a Packet Handler's Payload Registration. + * Needs to be called during your Mod Init Function. + */ + default void onGameInit() {} + + /** + * If you need to initialize a Packet Receiver, aka. register your Global Receiver. + * Needs to be called during the onWorldJoinPre() phase. + */ + default void onWorldPre() {} + + /** + * What to do when joining a world? Such a register your + * Data Syncer with any Server Back end; requesting Metadata, etc. + * Needs to be called during the onWorldJoinPost() phase. + */ + default void onWorldJoin() {} + + /** + * Used to return an NBT Object from the Entity Data Syncer Cache at the specific BlockPos. + * Note, that these functions are intended to be simple Getters. + * For Requesting Server Data, use `requestBlockEntity()` + * @param pos () + * @return () + */ + @Nullable + default NbtCompound getFromBlockEntityCacheNbt(BlockPos pos) { return null; } - void onWorldJoin(); + /** + * Used to return an BlockEntity Object from the Entity Data Syncer Cache at the specific BlockPos. + * Note, that these functions are intended to be simple Getters. + * For Requesting Server Data, use `requestBlockEntity()` + * @param pos () + * @return () + */ + @Nullable + default BlockEntity getFromBlockEntityCache(BlockPos pos) { return null; } + /** + * Used to return an NBT Object from the Entity Data Syncer Cache at the specific BlockPos. + * Note, that these functions are intended to be simple Getters. + * For Requesting Server Data, use `requestEntity()` + * @param entityId () + * @return () + */ @Nullable - NbtCompound getFromBlockEntityCacheNbt(BlockPos pos); + default NbtCompound getFromEntityCacheNbt(int entityId) { return null; } + /** + * Used to return an Entity Object from the Entity Data Syncer Cache at the specific BlockPos. + * Note, that these functions are intended to be simple Getters. + * For Requesting Server Data, use `requestEntity()` + * @param entityId () + * @return () + */ @Nullable - BlockEntity getFromBlockEntityCache(BlockPos pos); + default Entity getFromEntityCache(int entityId) { return null; } + /** + * Request the Block Entity Pair from the server; + * if the Cache contains the Data, return the data Pair. + * @param world () + * @param pos () + * @return (The Data Pair|Null) + */ @Nullable - NbtCompound getFromEntityCacheNbt(int entityId); + default Pair requestBlockEntity(World world, BlockPos pos) + { + if (world == null) + { + world = this.getWorld(); + } + + if (world == null) return null; + + if (world.getBlockState(pos).getBlock() instanceof BlockEntityProvider) + { + BlockEntity be = world.getWorldChunk(pos).getBlockEntity(pos); + + if (be != null) + { + NbtCompound nbt = be.createNbtWithIdentifyingData(world.getRegistryManager()); + + return Pair.of(be, nbt); + } + } + return null; + } + + /** + * Request the Entity Pair from the server; + * if the Cache contains the Data, return the data Pair. + * @param entityId () + * @return (The Data Pair|Null) + */ @Nullable - Entity getFromEntityCache(int entityId); + default Pair requestEntity(World world, int entityId) + { + if (world == null) + { + world = this.getWorld(); + } + + if (world == null) return null; + + Entity entity = world.getEntityById(entityId); + NbtCompound nbt = new NbtCompound(); + + if (entity != null && entity.saveSelfNbt(nbt)) + { + return Pair.of(entity, nbt); + } + + return null; + } + + /** + * Used to Obtain the Inventory Object from the Specified BlockPos, + * and handle if it is a Double Chest. If the Data doesn't exist in the Cache, request it. + * @param world (Provided for compatibility with other worlds) + * @param pos () + * @param useNbt () + * @return (Inventory|EmptyInventory|Null) + */ + @Nullable + @SuppressWarnings("deprecation") + default Inventory getBlockInventory(World world, BlockPos pos, boolean useNbt) + { + if (world == null) + { + world = this.getWorld(); + } + + if (world == null) return null; + + Pair pair = this.requestBlockEntity(world, pos); + Inventory inv = null; + + if (pair == null) return null; + + if (useNbt) + { + inv = InventoryUtils.getNbtInventory(pair.getRight(), -1, world.getRegistryManager()); + } + else + { + BlockEntity be = pair.getLeft(); + + if (be instanceof Inventory inv1) + { + if (be instanceof ChestBlockEntity) + { + BlockState state = world.getBlockState(pos); + ChestType type = state.get(ChestBlock.CHEST_TYPE); + + if (type != ChestType.SINGLE) + { + BlockPos posAdj = pos.offset(ChestBlock.getFacing(state)); + + if (!world.isChunkLoaded(posAdj)) return null; + BlockState stateAdj = world.getBlockState(posAdj); + + Pair pairAdj = this.requestBlockEntity(world, posAdj); + + if (pairAdj == null) + { + return inv1; + } + + if (stateAdj.getBlock() == state.getBlock() && + pairAdj.getLeft() instanceof ChestBlockEntity inv2 && + stateAdj.get(ChestBlock.CHEST_TYPE) != ChestType.SINGLE && + stateAdj.get(ChestBlock.FACING) == state.get(ChestBlock.FACING)) + { + Inventory invRight = type == ChestType.RIGHT ? inv1 : inv2; + Inventory invLeft = type == ChestType.RIGHT ? inv2 : inv1; + + inv = new DoubleInventory(invRight, invLeft); + } + } + else + { + inv = inv1; + } + } + else + { + inv = inv1; + } + } + } + + return inv; + } + + /** + * Used to Obtain the Inventory Object from the Specified Entity, if available; + * and handle if it needs special handling. If the Data doesn't exist in the Cache, request it. + * @param entityId () + * @param useNbt () + * @return (Inventory|Null) + */ + @Nullable + default Inventory getEntityInventory(World world, int entityId, boolean useNbt) + { + if (world == null) + { + world = this.getWorld(); + } + + if (world == null) return null; + + Pair pair = this.requestEntity(world, entityId); + Inventory inv = null; + + if (pair == null) return null; - Pair requestBlockEntity(World world, BlockPos pos); + if (useNbt) + { + inv = InventoryUtils.getNbtInventory(pair.getRight(), -1, world.getRegistryManager()); + } + else + { + Entity entity = pair.getLeft(); - Pair requestEntity(int entityId); + if (entity instanceof Inventory) + { + inv = (Inventory) entity; + } + else if (entity instanceof PlayerEntity player) + { + inv = new SimpleInventory(player.getInventory().main.toArray(new ItemStack[36])); + } + else if (entity instanceof VillagerEntity) + { + inv = ((VillagerEntity) entity).getInventory(); + } + else if (entity instanceof AbstractHorseEntity) + { + inv = ((IMixinAbstractHorseEntity) entity).malilib_getHorseInventory(); + } + else if (entity instanceof PiglinEntity) + { + inv = ((IMixinPiglinEntity) entity).malilib_getInventory(); + } - Inventory getBlockInventory(World world, BlockPos pos, boolean useNbt); + return inv; + } - Inventory getEntityInventory(World world, BlockPos pos, boolean useNbt); + return inv; + } - BlockEntity handleBlockEntityData(BlockPos pos, NbtCompound nbt, @Nullable Identifier type); + /** + * Used by your Packet Receiver to hande incoming data from BlockPos and the Server Side NBT tags. + * @param pos () + * @param nbt () + * @param type (Optional) + * @return (BlockEntity|Null) + */ + default BlockEntity handleBlockEntityData(BlockPos pos, NbtCompound nbt, @Nullable Identifier type) { return null; } - Entity handleEntityData(int entityId, NbtCompound nbt); + /** + * Used by your Packet Receiver to hande incoming data from the entityId and the Server Side NBT tags. + * @param nbt () + * @return (Entity|Null) + */ + default Entity handleEntityData(int entityId, NbtCompound nbt) { return null; } - void handleBulkEntityData(int transactionId, NbtCompound nbt); + /** + * Used by your Packet Receiver if any Bulk handling of NBT Tags for multiple Entities is required. + * This is usually used for something like downloading an entire ChunkPos worth of Entity Data; such as with Litematica. + * @param transactionId + * @param nbt + */ + default void handleBulkEntityData(int transactionId, NbtCompound nbt) {} - void handleVanillaQueryNbt(int transactionId, NbtCompound nbt); + /** + * Vanilla QueryNbt Packet Receiver & Handling + * @param transactionId (QueryNbt Transaction Id) + * @param nbt (The NBT Data returned by the server) + */ + default void handleVanillaQueryNbt(int transactionId, NbtCompound nbt) {} } diff --git a/src/main/java/fi/dy/masa/malilib/interfaces/IInventoryOverlayHandler.java b/src/main/java/fi/dy/masa/malilib/interfaces/IInventoryOverlayHandler.java index 7c2a837afb..e04fe40680 100644 --- a/src/main/java/fi/dy/masa/malilib/interfaces/IInventoryOverlayHandler.java +++ b/src/main/java/fi/dy/masa/malilib/interfaces/IInventoryOverlayHandler.java @@ -10,6 +10,7 @@ import net.minecraft.block.enums.ChestType; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.screen.Screen; import net.minecraft.entity.Entity; import net.minecraft.nbt.NbtCompound; import net.minecraft.server.world.ServerWorld; @@ -22,30 +23,76 @@ public interface IInventoryOverlayHandler { + /** + * Return your Mod's ID for the Screen Title + * @return () + */ String getModId(); + /** + * Return your ServerDataSyncer Instance. + * @return () + */ IDataSyncer getDataSyncer(); + /** + * Manually change a Built-In Data Syncer. + * @param syncer () + */ + void setDataSyncer(IDataSyncer syncer); + + /** + * Return your Inventory.Overlay Refresh Handler. + * @return () + */ InventoryOverlay.Refresher getRefreshHandler(); + /** + * Return if the saved InventoryOverlay.Context is Empty or not. + * @return () + */ boolean isEmpty(); + /** + * Get the Existing saved InventoryOverlay.Context, whether it's null or not. + * @return () + */ @Nullable InventoryOverlay.Context getRenderContextNullable(); + /** + * Start your Rendering Context & Request the Context Data from your Server Data Syncer. + * It optionally returns the Current Context. + * @param drawContext () + * @param profiler () + * @param mc () + * @return () + */ @Nullable InventoryOverlay.Context getRenderContext(DrawContext drawContext, Profiler profiler, MinecraftClient mc); + /** + * Render the InventoryOverlay.Context on Screen for the First time. + * @param context () + * @param drawContext () + * @param mc () + * @param shulkerBGColors () + */ default void renderInventoryOverlay(InventoryOverlay.Context context, DrawContext drawContext, MinecraftClient mc, boolean shulkerBGColors) { - var screen = new InventoryOverlayScreen(this.getModId(), context, shulkerBGColors); + Screen screen = new InventoryOverlayScreen(this.getModId(), context, shulkerBGColors); screen.init(mc, 0, 0); screen.render(drawContext, 0, 0, 0); } + /** + * Refresh your InventoryOverlay.Context and redraw the Screen. + * Used for using the Assigned Hotkey to "open" the Screen; and keep the data updated. + * @param mc () + * @param shulkerBGColors () + */ default void refreshInventoryOverlay(MinecraftClient mc, boolean shulkerBGColors) { - //this.getTargetInventory(mc, newScreen); this.getTargetInventory(mc); if (!this.isEmpty()) @@ -54,6 +101,13 @@ default void refreshInventoryOverlay(MinecraftClient mc, boolean shulkerBGColors } } + /** + * This is used to 'pre-Request' your DataSyncer to Sync a Block Entity, + * particularly for a Double Chest situation. + * @param world () + * @param pos () + * @return () + */ @Nullable default Pair requestBlockEntityAt(World world, BlockPos pos) { @@ -79,12 +133,31 @@ default Pair requestBlockEntityAt(World world, BlockPo return null; } + /** + * The Main Function used to Build the InventoryOverlay.Context, and Build the Inventory Objects, etc. + * @param mc () + * @return () + */ @Nullable InventoryOverlay.Context getTargetInventory(MinecraftClient mc); + /** + * The code used to build the Block Entity Context. + * @param world () + * @param pos () + * @param be () + * @param nbt () + * @return () + */ @Nullable InventoryOverlay.Context getTargetInventoryFromBlock(World world, BlockPos pos, @Nullable BlockEntity be, NbtCompound nbt); + /** + * The code used to build the Entity Context. + * @param entity () + * @param nbt () + * @return () + */ @Nullable InventoryOverlay.Context getTargetInventoryFromEntity(Entity entity, NbtCompound nbt); } diff --git a/src/main/java/fi/dy/masa/malilib/test/TestDataSyncer.java b/src/main/java/fi/dy/masa/malilib/test/TestDataSyncer.java index 01e92497b5..b3dbc9768e 100644 --- a/src/main/java/fi/dy/masa/malilib/test/TestDataSyncer.java +++ b/src/main/java/fi/dy/masa/malilib/test/TestDataSyncer.java @@ -1,26 +1,11 @@ package fi.dy.masa.malilib.test; -import org.apache.commons.lang3.tuple.Pair; import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.Nullable; -import net.minecraft.block.BlockEntityProvider; -import net.minecraft.block.BlockState; -import net.minecraft.block.ChestBlock; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.block.entity.ChestBlockEntity; -import net.minecraft.block.enums.ChestType; import net.minecraft.client.MinecraftClient; -import net.minecraft.entity.Entity; -import net.minecraft.inventory.DoubleInventory; -import net.minecraft.inventory.Inventory; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.util.Identifier; -import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import fi.dy.masa.malilib.interfaces.IDataSyncer; -import fi.dy.masa.malilib.util.InventoryUtils; import fi.dy.masa.malilib.util.WorldUtils; @ApiStatus.Experimental @@ -28,189 +13,13 @@ public class TestDataSyncer implements IDataSyncer { private static final TestDataSyncer INSTANCE = new TestDataSyncer(); - public TestDataSyncer() - { - } + public TestDataSyncer() { } public static TestDataSyncer getInstance() { return INSTANCE; } - private World getWorld() - { - return WorldUtils.getBestWorld(MinecraftClient.getInstance()); - } - @Override - public Pair requestEntity(int entityId) + public World getWorld() { - if (this.getWorld() != null) - { - Entity entity = this.getWorld().getEntityById(entityId); - NbtCompound nbt = new NbtCompound(); - - if (entity != null && entity.saveSelfNbt(nbt)) - { - return Pair.of(entity, nbt); - } - } - - return null; - } - - @Override - public void reset(boolean isLogout) - { - // NO-OP - } - - @Override - public void onGameInit() - { - // NO-OP - } - - @Override - public void onWorldPre() - { - // NO-OP - } - - @Override - public void onWorldJoin() - { - // NO-OP - } - - @Override - public @Nullable NbtCompound getFromBlockEntityCacheNbt(BlockPos pos) - { - return null; - } - - @Override - public @Nullable BlockEntity getFromBlockEntityCache(BlockPos pos) - { - return null; - } - - @Override - public @Nullable NbtCompound getFromEntityCacheNbt(int entityId) - { - return null; - } - - @Override - public @Nullable Entity getFromEntityCache(int entityId) - { - return null; - } - - @Override - public Pair requestBlockEntity(World world, BlockPos pos) - { - if (world.getBlockState(pos).getBlock() instanceof BlockEntityProvider) - { - BlockEntity be = world.getWorldChunk(pos).getBlockEntity(pos); - - if (be != null) - { - NbtCompound nbt = be.createNbtWithIdentifyingData(world.getRegistryManager()); - - return Pair.of(be, nbt); - } - } - - return null; - } - - @Override - @SuppressWarnings("deprecation") - public Inventory getBlockInventory(World world, BlockPos pos, boolean useNbt) - { - Inventory inv = null; - - Pair pair = requestBlockEntity(world, pos); - - if (pair == null) - { - return null; - } - - if (useNbt) - { - inv = InventoryUtils.getNbtInventory(pair.getRight(), -1, world.getRegistryManager()); - } - else - { - BlockEntity be = pair.getLeft(); - - if (be instanceof Inventory inv1) - { - if (be instanceof ChestBlockEntity) - { - BlockState state = world.getBlockState(pos); - ChestType type = state.get(ChestBlock.CHEST_TYPE); - - if (type != ChestType.SINGLE) - { - BlockPos posAdj = pos.offset(ChestBlock.getFacing(state)); - if (!world.isChunkLoaded(posAdj)) return null; - BlockState stateAdj = world.getBlockState(posAdj); - - Pair pairAdj = this.requestBlockEntity(world, posAdj); - - if (stateAdj.getBlock() == state.getBlock() && - pairAdj.getLeft() instanceof ChestBlockEntity inv2 && - stateAdj.get(ChestBlock.CHEST_TYPE) != ChestType.SINGLE && - stateAdj.get(ChestBlock.FACING) == state.get(ChestBlock.FACING)) - { - Inventory invRight = type == ChestType.RIGHT ? inv1 : inv2; - Inventory invLeft = type == ChestType.RIGHT ? inv2 : inv1; - - inv = new DoubleInventory(invRight, invLeft); - } - } - else - { - inv = inv1; - } - } - else - { - inv = inv1; - } - } - } - - return inv; - } - - @Override - public Inventory getEntityInventory(World world, BlockPos pos, boolean useNbt) - { - return null; - } - - @Override - public BlockEntity handleBlockEntityData(BlockPos pos, NbtCompound nbt, @Nullable Identifier type) - { - return null; - } - - @Override - public Entity handleEntityData(int entityId, NbtCompound nbt) - { - return null; - } - - @Override - public void handleBulkEntityData(int transactionId, NbtCompound nbt) - { - // NO-OP - } - - @Override - public void handleVanillaQueryNbt(int transactionId, NbtCompound nbt) - { - // NO-OP + return WorldUtils.getBestWorld(MinecraftClient.getInstance()); } } diff --git a/src/main/java/fi/dy/masa/malilib/test/TestInventoryOverlayHandler.java b/src/main/java/fi/dy/masa/malilib/test/TestInventoryOverlayHandler.java index 071a12b9b3..5eaed7c6b8 100644 --- a/src/main/java/fi/dy/masa/malilib/test/TestInventoryOverlayHandler.java +++ b/src/main/java/fi/dy/masa/malilib/test/TestInventoryOverlayHandler.java @@ -46,7 +46,7 @@ public class TestInventoryOverlayHandler implements IInventoryOverlayHandler public static TestInventoryOverlayHandler getInstance() {return INSTANCE;} - TestDataSyncer syncer; + IDataSyncer syncer; InventoryOverlay.Context context; InventoryOverlay.Refresher refresher; @@ -72,6 +72,12 @@ public IDataSyncer getDataSyncer() return this.syncer; } + @Override + public void setDataSyncer(IDataSyncer syncer) + { + this.syncer = syncer; + } + @Override public InventoryOverlay.Refresher getRefreshHandler() { @@ -218,7 +224,7 @@ else if (trace.getType() == HitResult.Type.ENTITY) } else { - Pair pair = this.getDataSyncer().requestEntity(entity.getId()); + Pair pair = this.getDataSyncer().requestEntity(world, entity.getId()); if (pair != null) { @@ -320,8 +326,8 @@ 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) { @@ -387,12 +393,12 @@ public InventoryOverlay.Context onContextRefresh(InventoryOverlay.Context data, // Refresh data if (data.be() != null) { - TestRenderHandler.getInstance().requestBlockEntityAt(world, data.be().getPos()); + TestInventoryOverlayHandler.getInstance().requestBlockEntityAt(world, data.be().getPos()); data = TestInventoryOverlayHandler.getInstance().getTargetInventoryFromBlock(data.be().getWorld(), data.be().getPos(), data.be(), data.nbt()); } else if (data.entity() != null) { - TestDataSyncer.getInstance().requestEntity(data.entity().getId()); + TestInventoryOverlayHandler.getInstance().getDataSyncer().requestEntity(world, data.entity().getId()); data = TestInventoryOverlayHandler.getInstance().getTargetInventoryFromEntity(data.entity(), data.nbt()); } diff --git a/src/main/java/fi/dy/masa/malilib/test/TestRenderHandler.java b/src/main/java/fi/dy/masa/malilib/test/TestRenderHandler.java index 5cb94075c6..681c33d26b 100644 --- a/src/main/java/fi/dy/masa/malilib/test/TestRenderHandler.java +++ b/src/main/java/fi/dy/masa/malilib/test/TestRenderHandler.java @@ -4,18 +4,13 @@ import java.util.List; import java.util.Set; import java.util.function.Supplier; -import javax.annotation.Nullable; -import org.apache.commons.lang3.tuple.Pair; import org.jetbrains.annotations.ApiStatus; import org.joml.Matrix4f; import com.mojang.blaze3d.systems.RenderSystem; -import net.minecraft.block.BlockState; -import net.minecraft.block.ChestBlock; import net.minecraft.block.ShulkerBoxBlock; import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.CrafterBlockEntity; -import net.minecraft.block.enums.ChestType; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.render.Camera; @@ -33,14 +28,11 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; -import net.minecraft.server.world.ServerWorld; import net.minecraft.text.Text; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.HitResult; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.profiler.Profiler; import net.minecraft.util.profiler.Profilers; -import net.minecraft.world.World; import fi.dy.masa.malilib.MaLiLib; import fi.dy.masa.malilib.MaLiLibConfigs; @@ -579,29 +571,4 @@ else if (context.nbt() != null) InventoryOverlay.renderEquipmentStacks(entityLivingBase, x, y, mc, drawContext); } } - - @Nullable - public Pair requestBlockEntityAt(World world, BlockPos pos) - { - if (!(world instanceof ServerWorld)) - { - Pair pair = TestDataSyncer.getInstance().requestBlockEntity(world, pos); - - BlockState state = world.getBlockState(pos); - - if (state.getBlock() instanceof ChestBlock) - { - ChestType type = state.get(ChestBlock.CHEST_TYPE); - - if (type != ChestType.SINGLE) - { - return TestDataSyncer.getInstance().requestBlockEntity(world, pos.offset(ChestBlock.getFacing(state))); - } - } - - return pair; - } - - return null; - } }