From 1cae6d8bce74337fdf329bf56c556d4475f21e96 Mon Sep 17 00:00:00 2001 From: Buuz135 Date: Mon, 6 Jun 2022 21:18:41 +0200 Subject: [PATCH] Fixed drawers not showing items on their tooltip --- build.gradle | 2 +- .../functionalstorage/FunctionalStorage.java | 3 +- .../functionalstorage/block/DrawerBlock.java | 33 ++++++++++++------- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/build.gradle b/build.gradle index 2ea9e8a..89305b8 100644 --- a/build.gradle +++ b/build.gradle @@ -100,7 +100,7 @@ dependencies { //implementation fg.deobf("curse.maven:allthecompressed-514045:3723881") //runtimeOnly fg.deobf("curse.maven:create-328085:3600402") //runtimeOnly fg.deobf("curse.maven:flywheel-486392:3600401") - runtimeOnly fg.deobf("curse.maven:mekanism-268560:3810540") + implementation fg.deobf("curse.maven:mekanism-268560:3810540") runtimeOnly fg.deobf("curse.maven:refined-pipes-370696:3816785") annotationProcessor "org.spongepowered:mixin:0.8.5:processor" } diff --git a/src/main/java/com/buuz135/functionalstorage/FunctionalStorage.java b/src/main/java/com/buuz135/functionalstorage/FunctionalStorage.java index ed5c8d4..a283f1c 100644 --- a/src/main/java/com/buuz135/functionalstorage/FunctionalStorage.java +++ b/src/main/java/com/buuz135/functionalstorage/FunctionalStorage.java @@ -147,7 +147,8 @@ public class FunctionalStorage extends ModuleController { for (DrawerType value : DrawerType.values()) { for (IWoodType woodType : WOOD_TYPES) { String name = woodType.getName() + "_" + value.getSlots(); - DRAWER_TYPES.computeIfAbsent(value, drawerType -> new ArrayList<>()).add(getRegistries().registerBlockWithTile(name, () -> new DrawerBlock(woodType, value))); + DRAWER_TYPES.computeIfAbsent(value, drawerType -> new ArrayList<>()).add(getRegistries().registerBlockWithTileItem(name, () -> new DrawerBlock(woodType, value), blockRegistryObject -> () -> + new DrawerBlock.DrawerItem((DrawerBlock) blockRegistryObject.get(), new Item.Properties().tab(TAB)))); } DRAWER_TYPES.get(value).forEach(blockRegistryObject -> TAB.addIconStacks(() -> new ItemStack(blockRegistryObject.getLeft().get()))); } diff --git a/src/main/java/com/buuz135/functionalstorage/block/DrawerBlock.java b/src/main/java/com/buuz135/functionalstorage/block/DrawerBlock.java index 5ecd81e..0c15874 100644 --- a/src/main/java/com/buuz135/functionalstorage/block/DrawerBlock.java +++ b/src/main/java/com/buuz135/functionalstorage/block/DrawerBlock.java @@ -28,6 +28,7 @@ import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.tooltip.TooltipComponent; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; @@ -60,6 +61,7 @@ import javax.annotation.Nonnull; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Optional; import java.util.function.Consumer; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -127,17 +129,6 @@ public class DrawerBlock extends RotatableBlock { registerDefaultState(defaultBlockState().setValue(RotatableBlock.FACING_HORIZONTAL, Direction.NORTH).setValue(LOCKED, false)); } - @Override - public Supplier 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 p_206840_1_) { super.createBlockStateDefinition(p_206840_1_); @@ -336,5 +327,25 @@ public class DrawerBlock extends RotatableBlock { } } + public static class DrawerItem extends BlockItem{ + + private DrawerBlock drawerBlock; + public DrawerItem(DrawerBlock p_40565_, Properties p_40566_) { + super(p_40565_, p_40566_); + this.drawerBlock = p_40565_; + } + + @Override + public Optional getTooltipImage(ItemStack stack) { + return super.getTooltipImage(stack); + } + + @Nullable + @Override + public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundTag nbt) { + return new DrawerCapabilityProvider(stack, this.drawerBlock.getType()); + } + } + }