forked from maruohon/malilib
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Convert all Pair objects to Apache Commons.
fix: Tooltip rendering for InventoryOverlayScreen handling for calling the `IRender.onRenderTooltipLast` handling feat: Item Tooltip handlers for inserting text into Item Tooltips at 3 places; First, Middle, and Last. feat: Migrate InventoryOverlayScreen to MaLiLib and add a common Interface for downstream mods called `IInventoryOverlayHandler` with an accompanying `IDataSyncer` interface as just a common way to call the mods' assigned Data Syncer.
- Loading branch information
1 parent
c0cdc23
commit 9d6530c
Showing
28 changed files
with
1,132 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/fi/dy/masa/malilib/interfaces/IDataSyncer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package fi.dy.masa.malilib.interfaces; | ||
|
||
import javax.annotation.Nullable; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
|
||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.entity.Entity; | ||
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; | ||
|
||
public interface IDataSyncer | ||
{ | ||
void reset(boolean isLogout); | ||
|
||
void onGameInit(); | ||
|
||
void onWorldPre(); | ||
|
||
void onWorldJoin(); | ||
|
||
@Nullable | ||
NbtCompound getFromBlockEntityCacheNbt(BlockPos pos); | ||
|
||
@Nullable | ||
BlockEntity getFromBlockEntityCache(BlockPos pos); | ||
|
||
@Nullable | ||
NbtCompound getFromEntityCacheNbt(int entityId); | ||
|
||
@Nullable | ||
Entity getFromEntityCache(int entityId); | ||
|
||
Pair<BlockEntity, NbtCompound> requestBlockEntity(World world, BlockPos pos); | ||
|
||
Pair<Entity, NbtCompound> requestEntity(int entityId); | ||
|
||
Inventory getBlockInventory(World world, BlockPos pos, boolean useNbt); | ||
|
||
Inventory getEntityInventory(World world, BlockPos pos, boolean useNbt); | ||
|
||
BlockEntity handleBlockEntityData(BlockPos pos, NbtCompound nbt, @Nullable Identifier type); | ||
|
||
Entity handleEntityData(int entityId, NbtCompound nbt); | ||
|
||
void handleBulkEntityData(int transactionId, NbtCompound nbt); | ||
|
||
void handleVanillaQueryNbt(int transactionId, NbtCompound nbt); | ||
} |
90 changes: 90 additions & 0 deletions
90
src/main/java/fi/dy/masa/malilib/interfaces/IInventoryOverlayHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package fi.dy.masa.malilib.interfaces; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import org.apache.commons.lang3.tuple.Pair; | ||
|
||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.ChestBlock; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.block.enums.ChestType; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.DrawContext; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.server.world.ServerWorld; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.profiler.Profiler; | ||
import net.minecraft.world.World; | ||
|
||
import fi.dy.masa.malilib.render.InventoryOverlay; | ||
import fi.dy.masa.malilib.render.InventoryOverlayScreen; | ||
|
||
public interface IInventoryOverlayHandler | ||
{ | ||
String getModId(); | ||
|
||
IDataSyncer getDataSyncer(); | ||
|
||
InventoryOverlay.Refresher getRefreshHandler(); | ||
|
||
boolean isEmpty(); | ||
|
||
@Nullable | ||
InventoryOverlay.Context getRenderContextNullable(); | ||
|
||
@Nullable | ||
InventoryOverlay.Context getRenderContext(DrawContext drawContext, Profiler profiler, MinecraftClient mc); | ||
|
||
default void renderInventoryOverlay(InventoryOverlay.Context context, DrawContext drawContext, MinecraftClient mc, boolean shulkerBGColors) | ||
{ | ||
var screen = new InventoryOverlayScreen(this.getModId(), context, shulkerBGColors); | ||
screen.init(mc, 0, 0); | ||
screen.render(drawContext, 0, 0, 0); | ||
} | ||
|
||
default void refreshInventoryOverlay(MinecraftClient mc, boolean shulkerBGColors) | ||
{ | ||
//this.getTargetInventory(mc, newScreen); | ||
this.getTargetInventory(mc); | ||
|
||
if (!this.isEmpty()) | ||
{ | ||
mc.setScreen(new InventoryOverlayScreen(this.getModId(), this.getRenderContextNullable(), shulkerBGColors)); | ||
} | ||
} | ||
|
||
@Nullable | ||
default Pair<BlockEntity, NbtCompound> requestBlockEntityAt(World world, BlockPos pos) | ||
{ | ||
if (!(world instanceof ServerWorld)) | ||
{ | ||
Pair<BlockEntity, NbtCompound> pair = this.getDataSyncer().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 this.getDataSyncer().requestBlockEntity(world, pos.offset(ChestBlock.getFacing(state))); | ||
} | ||
} | ||
|
||
return pair; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Nullable | ||
InventoryOverlay.Context getTargetInventory(MinecraftClient mc); | ||
|
||
@Nullable | ||
InventoryOverlay.Context getTargetInventoryFromBlock(World world, BlockPos pos, @Nullable BlockEntity be, NbtCompound nbt); | ||
|
||
@Nullable | ||
InventoryOverlay.Context getTargetInventoryFromEntity(Entity entity, NbtCompound nbt); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/java/fi/dy/masa/malilib/mixin/MixinItemStack.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package fi.dy.masa.malilib.mixin; | ||
|
||
import java.util.List; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import com.llamalad7.mixinextras.sugar.Local; | ||
|
||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.tooltip.TooltipType; | ||
import net.minecraft.text.Text; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import fi.dy.masa.malilib.event.RenderEventHandler; | ||
|
||
@Mixin(ItemStack.class) | ||
public abstract class MixinItemStack | ||
{ | ||
// This Goes before the Item Additional Tooltips. | ||
@Inject(method = "getTooltip", | ||
at = @At(value = "INVOKE", | ||
target = "Lnet/minecraft/item/Item;appendTooltip(Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/Item$TooltipContext;Ljava/util/List;Lnet/minecraft/item/tooltip/TooltipType;)V", | ||
shift = At.Shift.BEFORE)) | ||
private void onGetTooltipComponentsFirst(Item.TooltipContext context, @Nullable PlayerEntity player, TooltipType type, CallbackInfoReturnable<List<Text>> cir, | ||
@Local List<Text> list) | ||
{ | ||
((RenderEventHandler) RenderEventHandler.getInstance()).onRenderTooltipComponentInsertFirst(context, (ItemStack) (Object) this, list); | ||
} | ||
|
||
// This Goes after the Item Additional Tooltips. | ||
@Inject(method = "getTooltip", | ||
at = @At(value = "INVOKE", | ||
target = "Lnet/minecraft/item/ItemStack;appendTooltip(Lnet/minecraft/component/ComponentType;Lnet/minecraft/item/Item$TooltipContext;Ljava/util/function/Consumer;Lnet/minecraft/item/tooltip/TooltipType;)V", | ||
ordinal = 0, | ||
shift = At.Shift.BEFORE)) | ||
private void onGetTooltipComponentsMiddle(Item.TooltipContext context, @Nullable PlayerEntity player, TooltipType type, CallbackInfoReturnable<List<Text>> cir, | ||
@Local List<Text> list) | ||
{ | ||
((RenderEventHandler) RenderEventHandler.getInstance()).onRenderTooltipComponentInsertMiddle(context, (ItemStack) (Object) this, list); | ||
} | ||
|
||
// This Goes before the Item durability, item id, and component count. | ||
@Inject(method = "getTooltip", | ||
at = @At(value = "INVOKE", | ||
target = "Lnet/minecraft/item/ItemStack;appendTooltip(Lnet/minecraft/component/ComponentType;Lnet/minecraft/item/Item$TooltipContext;Ljava/util/function/Consumer;Lnet/minecraft/item/tooltip/TooltipType;)V", | ||
ordinal = 6, | ||
shift = At.Shift.AFTER)) | ||
private void onGetTooltipComponentsLast(Item.TooltipContext context, @Nullable PlayerEntity player, TooltipType type, CallbackInfoReturnable<List<Text>> cir, | ||
@Local List<Text> list) | ||
{ | ||
((RenderEventHandler) RenderEventHandler.getInstance()).onRenderTooltipComponentInsertLast(context, (ItemStack) (Object) this, list); | ||
} | ||
} |
Oops, something went wrong.