Added tooltip for the drawers to show its contents

This commit is contained in:
Buuz135 2022-01-06 13:55:12 +01:00
parent 7f3f3361bb
commit 171c2f4a80
13 changed files with 357 additions and 70 deletions

View File

@ -26,7 +26,7 @@ a50aeb3877dd4003bb3ed359fccde1f3674bc028 assets/functionalstorage/blockstates/sp
fbf8ebd85350f3b4ad0bf6faf51f9ecf0677bf5b assets/functionalstorage/blockstates/warped_1.json
bcd4b5e128d5175bea44ecae340aeec86cd5a123 assets/functionalstorage/blockstates/warped_2.json
ebc4aebffb44baa4dd507078b9fd3c74e881f4c1 assets/functionalstorage/blockstates/warped_4.json
904f5686edc535271e730aaaa27811f689efbfb4 assets/functionalstorage/lang/en_us.json
74b41817ead04f33efc61a7716871e43427de99a assets/functionalstorage/lang/en_us.json
68c3f6a8fe55202f83c0fcdd6c8ca10ef88019ef assets/functionalstorage/models/block/acacia_1_locked.json
c7d0376ba2a080ba12c344369ad11538899db176 assets/functionalstorage/models/block/acacia_2_locked.json
79b86baeec4aa6784aa52028d2f3bc98ddab8c14 assets/functionalstorage/models/block/acacia_4_locked.json
@ -130,7 +130,7 @@ d6b02c345edd356b8e4b7421bdd453f454c6ed7f data/functionalstorage/recipes/storage_
bcb281904eac23183c45786e3d703d24bba92be6 data/functionalstorage/recipes/warped_1.json
8fc3f76a2c57eb4d80ce86947fabebe48fa6f692 data/functionalstorage/recipes/warped_2.json
7510a8ca1f1e3bb63f4c4f4add0bb6b713feaa0b data/functionalstorage/recipes/warped_4.json
c90035bcbbce8f048618fbdd442779eb16c37cc0 data/functionalstorage/tags/items/drawer.json
f37e620a26ceb158507c607cee6ba3b51f14c6d6 data/functionalstorage/tags/items/drawer.json
12ec935226bf5a6a1493d353ef6dc6c224c256dd data/functionalstorage/tags/items/ignore_crafting_check.json
c90035bcbbce8f048618fbdd442779eb16c37cc0 data/minecraft/tags/blocks/mineable/axe.json
f37e620a26ceb158507c607cee6ba3b51f14c6d6 data/minecraft/tags/blocks/mineable/axe.json
2c1ca62408eae8963178024550b0771101e01d53 data/minecraft/tags/blocks/mineable/pickaxe.json

View File

@ -33,6 +33,7 @@
"configurationtool.configmode.toggle_render": "Hide/Show Item Renders",
"configurationtool.configmode.toggle_upgrades": "Hide/Show Upgrade Renders",
"configurationtool.use": "Sneak + Right Click in the air to change modes. Right click a drawer to toggle the option.",
"drawer.block.contents": "Contents: ",
"item.functionalstorage.collector_upgrade": "Collector Upgrade",
"item.functionalstorage.configuration_tool": "Configuration Tool",
"item.functionalstorage.copper_upgrade": "Copper Upgrade",

View File

@ -9,14 +9,6 @@
"functionalstorage:dark_oak_2",
"functionalstorage:crimson_2",
"functionalstorage:warped_2",
"functionalstorage:oak_1",
"functionalstorage:spruce_1",
"functionalstorage:birch_1",
"functionalstorage:jungle_1",
"functionalstorage:acacia_1",
"functionalstorage:dark_oak_1",
"functionalstorage:crimson_1",
"functionalstorage:warped_1",
"functionalstorage:oak_4",
"functionalstorage:spruce_4",
"functionalstorage:birch_4",
@ -24,6 +16,14 @@
"functionalstorage:acacia_4",
"functionalstorage:dark_oak_4",
"functionalstorage:crimson_4",
"functionalstorage:warped_4"
"functionalstorage:warped_4",
"functionalstorage:oak_1",
"functionalstorage:spruce_1",
"functionalstorage:birch_1",
"functionalstorage:jungle_1",
"functionalstorage:acacia_1",
"functionalstorage:dark_oak_1",
"functionalstorage:crimson_1",
"functionalstorage:warped_1"
]
}

View File

@ -9,14 +9,6 @@
"functionalstorage:dark_oak_2",
"functionalstorage:crimson_2",
"functionalstorage:warped_2",
"functionalstorage:oak_1",
"functionalstorage:spruce_1",
"functionalstorage:birch_1",
"functionalstorage:jungle_1",
"functionalstorage:acacia_1",
"functionalstorage:dark_oak_1",
"functionalstorage:crimson_1",
"functionalstorage:warped_1",
"functionalstorage:oak_4",
"functionalstorage:spruce_4",
"functionalstorage:birch_4",
@ -24,6 +16,14 @@
"functionalstorage:acacia_4",
"functionalstorage:dark_oak_4",
"functionalstorage:crimson_4",
"functionalstorage:warped_4"
"functionalstorage:warped_4",
"functionalstorage:oak_1",
"functionalstorage:spruce_1",
"functionalstorage:birch_1",
"functionalstorage:jungle_1",
"functionalstorage:acacia_1",
"functionalstorage:dark_oak_1",
"functionalstorage:crimson_1",
"functionalstorage:warped_1"
]
}

View File

@ -9,14 +9,14 @@ import com.buuz135.functionalstorage.data.FunctionalStorageBlockTagsProvider;
import com.buuz135.functionalstorage.data.FunctionalStorageBlockstateProvider;
import com.buuz135.functionalstorage.data.FunctionalStorageItemTagsProvider;
import com.buuz135.functionalstorage.data.FunctionalStorageLangProvider;
import com.buuz135.functionalstorage.inventory.BigInventoryHandler;
import com.buuz135.functionalstorage.inventory.item.DrawerStackItemHandler;
import com.buuz135.functionalstorage.item.ConfigurationToolItem;
import com.buuz135.functionalstorage.item.LinkingToolItem;
import com.buuz135.functionalstorage.item.StorageUpgradeItem;
import com.buuz135.functionalstorage.item.UpgradeItem;
import com.buuz135.functionalstorage.network.EnderDrawerSyncMessage;
import com.buuz135.functionalstorage.util.DrawerWoodType;
import com.buuz135.functionalstorage.util.IWoodType;
import com.buuz135.functionalstorage.util.StorageTags;
import com.buuz135.functionalstorage.util.*;
import com.hrznstudio.titanium.block.BasicBlock;
import com.hrznstudio.titanium.block.BasicTileBlock;
import com.hrznstudio.titanium.datagenerator.loot.TitaniumLootTableProvider;
@ -44,6 +44,7 @@ import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.event.ColorHandlerEvent;
import net.minecraftforge.client.event.EntityRenderersEvent;
import net.minecraftforge.client.event.RenderTooltipEvent;
import net.minecraftforge.client.model.generators.BlockModelProvider;
import net.minecraftforge.client.model.generators.ItemModelProvider;
import net.minecraftforge.common.Tags;
@ -52,6 +53,7 @@ import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.forge.event.lifecycle.GatherDataEvent;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import org.apache.logging.log4j.LogManager;
@ -97,6 +99,23 @@ public class FunctionalStorage extends ModuleController {
public FunctionalStorage() {
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> this::onClient);
EventManager.forge(RenderTooltipEvent.Pre.class).process(itemTooltipEvent -> {
if (itemTooltipEvent.getItemStack().getItem().equals(FunctionalStorage.ENDER_DRAWER.get().asItem()) && itemTooltipEvent.getItemStack().hasTag()) {
TooltipUtil.renderItems(itemTooltipEvent.getPoseStack(), EnderDrawerBlock.getFrequencyDisplay(itemTooltipEvent.getItemStack().getTag().getCompound("BlockEntityTag").getString("frequency")), itemTooltipEvent.getX() + 14, itemTooltipEvent.getY() + 11);
}
if (itemTooltipEvent.getItemStack().is(FunctionalStorage.LINKING_TOOL.get()) && itemTooltipEvent.getItemStack().getOrCreateTag().contains(LinkingToolItem.NBT_ENDER)) {
TooltipUtil.renderItems(itemTooltipEvent.getPoseStack(), EnderDrawerBlock.getFrequencyDisplay(itemTooltipEvent.getItemStack().getOrCreateTag().getString(LinkingToolItem.NBT_ENDER)), itemTooltipEvent.getX() + 14, itemTooltipEvent.getY() + 11);
}
itemTooltipEvent.getItemStack().getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).ifPresent(iItemHandler -> {
if (iItemHandler instanceof DrawerStackItemHandler) {
int i = 0;
for (BigInventoryHandler.BigStack storedStack : ((DrawerStackItemHandler) iItemHandler).getStoredStacks()) {
TooltipUtil.renderItemAdvanced(itemTooltipEvent.getPoseStack(), storedStack.getStack(), itemTooltipEvent.getX() + 20 + 26 * i, itemTooltipEvent.getY() + 11, 512, NumberUtils.getFormatedBigNumber(storedStack.getAmount()) + "/" + NumberUtils.getFormatedBigNumber(iItemHandler.getSlotLimit(i)));
++i;
}
}
});
}).subscribe();
}

View File

@ -3,6 +3,7 @@ package com.buuz135.functionalstorage.block;
import com.buuz135.functionalstorage.FunctionalStorage;
import com.buuz135.functionalstorage.block.tile.DrawerControllerTile;
import com.buuz135.functionalstorage.block.tile.DrawerTile;
import com.buuz135.functionalstorage.inventory.item.DrawerCapabilityProvider;
import com.buuz135.functionalstorage.item.LinkingToolItem;
import com.buuz135.functionalstorage.util.IWoodType;
import com.google.common.collect.Multimap;
@ -13,19 +14,24 @@ import com.hrznstudio.titanium.module.DeferredRegistryHelper;
import com.hrznstudio.titanium.recipe.generator.TitaniumShapedRecipeBuilder;
import com.hrznstudio.titanium.util.RayTraceUtils;
import com.hrznstudio.titanium.util.TileUtil;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.NonNullList;
import net.minecraft.data.recipes.FinishedRecipe;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
@ -41,15 +47,16 @@ import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.common.Tags;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.annotation.Nonnull;
import java.awt.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.Supplier;
public class DrawerBlock extends RotatableBlock<DrawerTile> {
@ -114,6 +121,17 @@ public class DrawerBlock extends RotatableBlock<DrawerTile> {
registerDefaultState(defaultBlockState().setValue(RotatableBlock.FACING_HORIZONTAL, Direction.NORTH).setValue(LOCKED, false));
}
@Override
public Supplier<Item> getItemBlockFactory() {
return () -> new BlockItem(this, new Item.Properties().tab(this.getItemGroup())) {
@Nullable
@Override
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundTag nbt) {
return new DrawerCapabilityProvider(stack, type);
}
};
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> p_206840_1_) {
super.createBlockStateDefinition(p_206840_1_);
@ -253,4 +271,17 @@ public class DrawerBlock extends RotatableBlock<DrawerTile> {
}
super.onRemove(state, worldIn, pos, newState, isMoving);
}
@Override
public void appendHoverText(ItemStack p_49816_, @Nullable BlockGetter p_49817_, List<net.minecraft.network.chat.Component> tooltip, TooltipFlag p_49819_) {
super.appendHoverText(p_49816_, p_49817_, tooltip, p_49819_);
if (p_49816_.hasTag()) {
TranslatableComponent text = new TranslatableComponent("drawer.block.contents");
tooltip.add(text.withStyle(ChatFormatting.GRAY));
tooltip.add(new TextComponent(""));
tooltip.add(new TextComponent(""));
}
}
}

View File

@ -5,15 +5,9 @@ import com.buuz135.functionalstorage.block.tile.DrawerControllerTile;
import com.buuz135.functionalstorage.block.tile.DrawerTile;
import com.buuz135.functionalstorage.block.tile.EnderDrawerTile;
import com.buuz135.functionalstorage.item.LinkingToolItem;
import com.buuz135.functionalstorage.util.IWoodType;
import com.buuz135.functionalstorage.util.TooltipUtil;
import com.google.common.collect.Multimap;
import com.google.common.collect.MultimapBuilder;
import com.hrznstudio.titanium.block.RotatableBlock;
import com.hrznstudio.titanium.datagenerator.loot.block.BasicBlockLootTables;
import com.hrznstudio.titanium.event.handler.EventManager;
import com.hrznstudio.titanium.module.DeferredRegistryHelper;
import com.hrznstudio.titanium.recipe.generator.TitaniumShapedRecipeBuilder;
import com.hrznstudio.titanium.util.RayTraceUtils;
import com.hrznstudio.titanium.util.TileUtil;
import net.minecraft.ChatFormatting;
@ -22,7 +16,6 @@ import net.minecraft.core.Direction;
import net.minecraft.core.NonNullList;
import net.minecraft.data.recipes.FinishedRecipe;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.InteractionHand;
@ -33,25 +26,18 @@ import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.storage.loot.LootTable;
import net.minecraft.world.level.storage.loot.functions.CopyNbtFunction;
import net.minecraft.world.level.storage.loot.providers.nbt.ContextNbtProvider;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.shapes.BooleanOp;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.client.event.RenderTooltipEvent;
import net.minecraftforge.common.Tags;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.fml.LogicalSide;
import net.minecraftforge.registries.ForgeRegistries;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -68,12 +54,6 @@ import static com.buuz135.functionalstorage.block.DrawerBlock.LOCKED;
public class EnderDrawerBlock extends RotatableBlock<EnderDrawerTile> {
static {
EventManager.forge(RenderTooltipEvent.Pre.class).filter(itemTooltipEvent -> itemTooltipEvent.getItemStack().getItem().equals(FunctionalStorage.ENDER_DRAWER.get().asItem()) && itemTooltipEvent.getItemStack().hasTag()).process(itemTooltipEvent -> {
TooltipUtil.renderItems(itemTooltipEvent.getPoseStack(), EnderDrawerBlock.getFrequencyDisplay(itemTooltipEvent.getItemStack().getTag().getCompound("BlockEntityTag").getString("frequency")) , itemTooltipEvent.getX() + 14, itemTooltipEvent.getY() + 11);
}).subscribe();
}
public EnderDrawerBlock() {
super("ender_drawer", Properties.copy(Blocks.ENDER_CHEST), EnderDrawerTile.class);
setItemGroup(FunctionalStorage.TAB);

View File

@ -64,5 +64,6 @@ public class FunctionalStorageLangProvider extends LanguageProvider {
this.add("upgrade.type.utility", "Utility");
this.add("linkingtool.ender.frequency", "Frequency: ");
this.add("linkingtool.ender.clear", "Sneak + Right Click in the air to clear frequency.");
this.add("drawer.block.contents", "Contents: ");
}
}

View File

@ -13,7 +13,6 @@ import java.util.List;
public abstract class BigInventoryHandler implements IItemHandler, INBTSerializable<CompoundTag> {
public static String VOID = "Void";
public static String BIG_ITEMS = "BigItems";
public static String STACK = "Stack";
public static String AMOUNT = "Amount";
@ -144,7 +143,7 @@ public abstract class BigInventoryHandler implements IItemHandler, INBTSerializa
return storedStacks;
}
public class BigStack{
public static class BigStack {
private ItemStack stack;
private int amount;

View File

@ -0,0 +1,39 @@
package com.buuz135.functionalstorage.inventory.item;
import com.buuz135.functionalstorage.FunctionalStorage;
import net.minecraft.core.Direction;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class DrawerCapabilityProvider implements ICapabilityProvider {
private final ItemStack stack;
private final DrawerStackItemHandler drawerStackItemHandler;
private final LazyOptional<IItemHandler> itemHandler;
public DrawerCapabilityProvider(ItemStack stack, FunctionalStorage.DrawerType type) {
this.stack = stack;
this.drawerStackItemHandler = new DrawerStackItemHandler(stack, type);
this.itemHandler = LazyOptional.of(() -> this.drawerStackItemHandler);
}
@NotNull
@Override
public <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) {
if (cap.equals(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)) return this.itemHandler.cast();
return LazyOptional.empty();
}
@NotNull
@Override
public <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap) {
if (cap.equals(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)) return this.itemHandler.cast();
return LazyOptional.empty();
}
}

View File

@ -0,0 +1,185 @@
package com.buuz135.functionalstorage.inventory.item;
import com.buuz135.functionalstorage.FunctionalStorage;
import com.buuz135.functionalstorage.inventory.BigInventoryHandler;
import com.buuz135.functionalstorage.item.StorageUpgradeItem;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.common.util.INBTSerializable;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemHandlerHelper;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import static com.buuz135.functionalstorage.inventory.BigInventoryHandler.*;
public class DrawerStackItemHandler implements IItemHandler, INBTSerializable<CompoundTag> {
private List<BigInventoryHandler.BigStack> storedStacks;
private ItemStack stack;
private FunctionalStorage.DrawerType type;
private int multiplier;
private boolean downgrade;
private boolean isVoid;
public DrawerStackItemHandler(ItemStack stack, FunctionalStorage.DrawerType drawerType) {
this.stack = stack;
this.storedStacks = new ArrayList<>();
this.type = drawerType;
this.multiplier = 1;
this.downgrade = false;
this.isVoid = false;
for (int i = 0; i < drawerType.getSlots(); i++) {
this.storedStacks.add(i, new BigInventoryHandler.BigStack(ItemStack.EMPTY, 0));
}
if (stack.hasTag()) {
deserializeNBT(stack.getTag().getCompound("BlockEntityTag").getCompound("handler"));
for (Tag tag : stack.getOrCreateTag().getCompound("BlockEntityTag").getCompound("storageUpgrades").getList("Items", Tag.TAG_COMPOUND)) {
ItemStack itemStack = ItemStack.of((CompoundTag) tag);
if (itemStack.getItem() instanceof StorageUpgradeItem) {
if (multiplier == 1) multiplier = ((StorageUpgradeItem) itemStack.getItem()).getStorageMultiplier();
else multiplier *= ((StorageUpgradeItem) itemStack.getItem()).getStorageMultiplier();
}
if (itemStack.getItem().equals(FunctionalStorage.STORAGE_UPGRADES.get(StorageUpgradeItem.StorageTier.IRON).get())) {
this.downgrade = true;
}
}
for (Tag tag : stack.getOrCreateTag().getCompound("BlockEntityTag").getCompound("utilityUpgrades").getList("Items", Tag.TAG_COMPOUND)) {
ItemStack itemStack = ItemStack.of((CompoundTag) tag);
if (itemStack.getItem().equals(FunctionalStorage.VOID_UPGRADE.get())) {
this.isVoid = true;
}
}
}
}
@Override
public CompoundTag serializeNBT() {
CompoundTag compoundTag = new CompoundTag();
CompoundTag items = new CompoundTag();
for (int i = 0; i < this.storedStacks.size(); i++) {
CompoundTag bigStack = new CompoundTag();
bigStack.put(STACK, this.storedStacks.get(i).getStack().serializeNBT());
bigStack.putInt(AMOUNT, this.storedStacks.get(i).getAmount());
items.put(i + "", bigStack);
}
compoundTag.put(BIG_ITEMS, items);
return compoundTag;
}
@Override
public void deserializeNBT(CompoundTag nbt) {
for (String allKey : nbt.getCompound(BIG_ITEMS).getAllKeys()) {
this.storedStacks.get(Integer.parseInt(allKey)).setStack(ItemStack.of(nbt.getCompound(BIG_ITEMS).getCompound(allKey).getCompound(STACK)));
this.storedStacks.get(Integer.parseInt(allKey)).setAmount(nbt.getCompound(BIG_ITEMS).getCompound(allKey).getInt(AMOUNT));
}
}
@Override
public int getSlots() {
return type.getSlots();
}
@Nonnull
@Override
public ItemStack getStackInSlot(int slot) {
BigStack bigStack = this.storedStacks.get(slot);
ItemStack copied = bigStack.getStack().copy();
copied.setCount(bigStack.getAmount());
return copied;
}
@Nonnull
@Override
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
if (isValid(slot, stack)) {
BigStack bigStack = this.storedStacks.get(slot);
int inserted = Math.min(getSlotLimit(slot) - bigStack.getAmount(), stack.getCount());
if (!simulate) {
bigStack.setStack(stack);
bigStack.setAmount(Math.min(bigStack.getAmount() + inserted, getSlotLimit(slot)));
onChange();
}
if (inserted == stack.getCount() || isVoid()) return ItemStack.EMPTY;
return ItemHandlerHelper.copyStackWithSize(stack, stack.getCount() - inserted);
}
return stack;
}
private boolean isVoid() {
return true;
}
private void onChange() {
if (stack.getOrCreateTag().contains("BlockEntityTag"))
stack.getOrCreateTag().put("BlockEntityTag", new CompoundTag());
stack.getOrCreateTag().getCompound("BlockEntityTag").put("handler", serializeNBT());
}
private boolean isValid(int slot, @Nonnull ItemStack stack) {
if (slot < type.getSlots()) {
BigStack bigStack = this.storedStacks.get(slot);
ItemStack fl = bigStack.getStack();
return fl.isEmpty() || (fl.sameItem(stack) && ItemStack.tagMatches(fl, stack));
}
return false;
}
@Nonnull
@Override
public ItemStack extractItem(int slot, int amount, boolean simulate) {
if (amount == 0) return ItemStack.EMPTY;
if (slot < type.getSlots()) {
BigStack bigStack = this.storedStacks.get(slot);
if (bigStack.getStack().isEmpty()) return ItemStack.EMPTY;
if (bigStack.getAmount() <= amount) {
ItemStack out = bigStack.getStack().copy();
int newAmount = bigStack.getAmount();
if (!simulate) {
if (!isLocked()) bigStack.setStack(ItemStack.EMPTY);
bigStack.setAmount(0);
onChange();
}
out.setCount(newAmount);
return out;
} else {
if (!simulate) {
bigStack.setAmount(bigStack.getAmount() - amount);
onChange();
}
return ItemHandlerHelper.copyStackWithSize(bigStack.getStack(), amount);
}
}
return ItemStack.EMPTY;
}
public boolean isLocked() {
return true;
}
@Override
public int getSlotLimit(int slot) {
if (hasDowngrade()) return 64;
return (int) Math.min(Integer.MAX_VALUE, type.getSlotAmount() * (long) getMultiplier());
}
private long getMultiplier() {
return multiplier;
}
private boolean hasDowngrade() {
return downgrade;
}
@Override
public boolean isItemValid(int slot, @Nonnull ItemStack stack) {
return !stack.isEmpty();
}
public List<BigStack> getStoredStacks() {
return storedStacks;
}
}

View File

@ -1,16 +1,13 @@
package com.buuz135.functionalstorage.item;
import com.buuz135.functionalstorage.FunctionalStorage;
import com.buuz135.functionalstorage.block.EnderDrawerBlock;
import com.buuz135.functionalstorage.block.tile.ControllableDrawerTile;
import com.buuz135.functionalstorage.block.tile.DrawerControllerTile;
import com.buuz135.functionalstorage.block.tile.EnderDrawerTile;
import com.buuz135.functionalstorage.inventory.EnderInventoryHandler;
import com.buuz135.functionalstorage.util.TooltipUtil;
import com.buuz135.functionalstorage.world.EnderSavedData;
import com.hrznstudio.titanium.event.handler.EventManager;
import com.hrznstudio.titanium.item.BasicItem;
import com.hrznstudio.titanium.util.InventoryUtil;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.core.NonNullList;
@ -22,25 +19,22 @@ import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.*;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraftforge.client.event.RenderTooltipEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.fml.LogicalSide;
import net.minecraftforge.registries.ForgeRegistries;
import org.jetbrains.annotations.Nullable;
import java.awt.*;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.Locale;
public class LinkingToolItem extends BasicItem {
@ -66,9 +60,6 @@ public class LinkingToolItem extends BasicItem {
}
static {
EventManager.forge(RenderTooltipEvent.Pre.class).filter(itemTooltipEvent -> itemTooltipEvent.getItemStack().is(FunctionalStorage.LINKING_TOOL.get()) && itemTooltipEvent.getItemStack().getOrCreateTag().contains(NBT_ENDER)).process(itemTooltipEvent -> {
TooltipUtil.renderItems(itemTooltipEvent.getPoseStack(), EnderDrawerBlock.getFrequencyDisplay(itemTooltipEvent.getItemStack().getOrCreateTag().getString(NBT_ENDER)) , itemTooltipEvent.getX() + 14, itemTooltipEvent.getY() + 11);
}).subscribe();
EventManager.forge(PlayerInteractEvent.LeftClickBlock.class).filter(leftClickBlock -> leftClickBlock.getSide() == LogicalSide.SERVER && leftClickBlock.getItemStack().is(FunctionalStorage.LINKING_TOOL.get())).process(leftClickBlock -> {
ItemStack stack = leftClickBlock.getItemStack();
BlockEntity blockEntity = leftClickBlock.getWorld().getBlockEntity(leftClickBlock.getPos());

View File

@ -4,7 +4,9 @@ import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.platform.Lighting;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.client.renderer.texture.OverlayTexture;
@ -12,12 +14,11 @@ import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.ItemUtils;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import javax.annotation.Nullable;
import java.util.List;
public class TooltipUtil {
@ -33,6 +34,46 @@ public class TooltipUtil {
renderItemModelIntoGUI(matrixStack, stack, x, y, z, Minecraft.getInstance().getItemRenderer().getModel(stack, (Level) null, (LivingEntity) null, 0));
}
public static void renderItemAdvanced(PoseStack matrixStack, ItemStack stack, int x, int y, int z, String amount) {
renderItemModelIntoGUI(matrixStack, stack, x, y, z, Minecraft.getInstance().getItemRenderer().getModel(stack, (Level) null, (LivingEntity) null, 0));
renderItemStackOverlay(matrixStack, Minecraft.getInstance().font, stack, x, y, amount, amount.length() - 2);
}
public static void renderItemStackOverlay(PoseStack matrixStack, Font fr, ItemStack stack, int xPosition, int yPosition, @Nullable String text, int scaled) {
matrixStack.pushPose();
matrixStack.translate(0, 0, 512 + 32);
if (!stack.isEmpty()) {
if (stack.getCount() != 1 || text != null) {
String s = text == null ? String.valueOf(stack.getCount()) : text;
if (text == null && stack.getCount() < 1) {
ChatFormatting var10000 = ChatFormatting.RED;
s = var10000 + String.valueOf(stack.getCount());
}
matrixStack.translate(0.0D, 0.0D, (double) (Minecraft.getInstance().getItemRenderer().blitOffset + 200.0F));
RenderSystem.disableDepthTest();
RenderSystem.disableBlend();
if (scaled >= 2) {
matrixStack.pushPose();
matrixStack.scale(0.5F, 0.5F, 0.5F);
fr.drawShadow(matrixStack, s, (float) ((xPosition + 19 - 2) * 2 - 1 - fr.width(s)), (float) (yPosition * 2 + 24), 16777215);
matrixStack.popPose();
} else if (scaled == 1) {
matrixStack.pushPose();
matrixStack.scale(0.75F, 0.75F, 0.75F);
fr.drawShadow(matrixStack, s, (float) (xPosition - 2) * 1.34F + 24.0F - (float) fr.width(s), (float) yPosition * 1.34F + 14.0F, 16777215);
matrixStack.popPose();
} else {
fr.drawShadow(matrixStack, s, (float) (xPosition + 19 - 2 - fr.width(s)), (float) (yPosition + 6 + 3), 16777215);
}
RenderSystem.enableDepthTest();
RenderSystem.enableBlend();
}
}
matrixStack.popPose();
}
@OnlyIn(Dist.CLIENT)
public static void renderItemModelIntoGUI(PoseStack posestack, ItemStack stack, int x, int y, int z, BakedModel bakedmodel) {
Minecraft.getInstance().getTextureManager().getTexture(TextureAtlas.LOCATION_BLOCKS).setFilter(false, false);