diff --git a/src/main/java/nl/enjarai/omnihopper/blocks/OpenBoxBlock.java b/src/main/java/nl/enjarai/omnihopper/blocks/OpenBoxBlock.java index 6b862f5..0b66751 100644 --- a/src/main/java/nl/enjarai/omnihopper/blocks/OpenBoxBlock.java +++ b/src/main/java/nl/enjarai/omnihopper/blocks/OpenBoxBlock.java @@ -17,10 +17,11 @@ import nl.enjarai.omnihopper.blocks.entity.OpenBoxBlockEntity; import nl.enjarai.omnihopper.util.DatagenBlock; +import nl.enjarai.omnihopper.util.HasTooltip; import org.jetbrains.annotations.Nullable; @SuppressWarnings("deprecation") -public class OpenBoxBlock extends BlockWithEntity implements DatagenBlock { +public class OpenBoxBlock extends BlockWithEntity implements DatagenBlock, HasTooltip { public static final DirectionProperty FACING = Properties.FACING; public static final VoxelShape[] SHAPES = new VoxelShape[6]; diff --git a/src/main/java/nl/enjarai/omnihopper/blocks/hopper/FluidHopperBlock.java b/src/main/java/nl/enjarai/omnihopper/blocks/hopper/FluidHopperBlock.java index 52e92aa..373e5b9 100644 --- a/src/main/java/nl/enjarai/omnihopper/blocks/hopper/FluidHopperBlock.java +++ b/src/main/java/nl/enjarai/omnihopper/blocks/hopper/FluidHopperBlock.java @@ -1,5 +1,7 @@ package nl.enjarai.omnihopper.blocks.hopper; +import net.minecraft.util.Identifier; +import nl.enjarai.omnihopper.OmniHopper; import org.jetbrains.annotations.Nullable; import net.minecraft.block.BlockState; @@ -39,4 +41,9 @@ public TextureMap getTextureMap() { public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { return ActionResult.PASS; } + + @Override + public Identifier modifyTooltipId(Identifier id) { + return OmniHopper.id("fluid_hopper"); + } } diff --git a/src/main/java/nl/enjarai/omnihopper/blocks/hopper/FluidOmniHopperBlock.java b/src/main/java/nl/enjarai/omnihopper/blocks/hopper/FluidOmniHopperBlock.java index 16eda32..af939d1 100644 --- a/src/main/java/nl/enjarai/omnihopper/blocks/hopper/FluidOmniHopperBlock.java +++ b/src/main/java/nl/enjarai/omnihopper/blocks/hopper/FluidOmniHopperBlock.java @@ -1,5 +1,7 @@ package nl.enjarai.omnihopper.blocks.hopper; +import net.minecraft.util.Identifier; +import nl.enjarai.omnihopper.OmniHopper; import org.jetbrains.annotations.Nullable; import net.minecraft.block.BlockState; @@ -39,4 +41,9 @@ public TextureMap getTextureMap() { public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { return ActionResult.PASS; } + + @Override + public Identifier modifyTooltipId(Identifier id) { + return OmniHopper.id("fluid_omnihopper"); + } } diff --git a/src/main/java/nl/enjarai/omnihopper/blocks/hopper/HopperBlock.java b/src/main/java/nl/enjarai/omnihopper/blocks/hopper/HopperBlock.java index ced3ebb..edda4fc 100644 --- a/src/main/java/nl/enjarai/omnihopper/blocks/hopper/HopperBlock.java +++ b/src/main/java/nl/enjarai/omnihopper/blocks/hopper/HopperBlock.java @@ -36,6 +36,7 @@ import nl.enjarai.omnihopper.blocks.entity.hopper.HopperBlockEntity; import nl.enjarai.omnihopper.blocks.entity.hopper.behaviour.ItemHopperBehaviour; import nl.enjarai.omnihopper.util.DatagenBlock; +import nl.enjarai.omnihopper.util.HasTooltip; import nl.enjarai.omnihopper.util.TextureMapProvider; import org.jetbrains.annotations.Nullable; @@ -43,7 +44,7 @@ import java.util.Set; @SuppressWarnings({"UnstableApiUsage", "deprecation"}) -public abstract class HopperBlock extends BlockWithEntity implements DatagenBlock, TextureMapProvider { +public abstract class HopperBlock extends BlockWithEntity implements DatagenBlock, TextureMapProvider, HasTooltip { public static final BooleanProperty ENABLED; public static final VoxelShape[] SUCKY_AREA; private static final VoxelShape MIDDLE_SHAPE; diff --git a/src/main/java/nl/enjarai/omnihopper/items/ModItems.java b/src/main/java/nl/enjarai/omnihopper/items/ModItems.java index 2a99544..edb1dea 100644 --- a/src/main/java/nl/enjarai/omnihopper/items/ModItems.java +++ b/src/main/java/nl/enjarai/omnihopper/items/ModItems.java @@ -6,12 +6,22 @@ import net.fabricmc.fabric.api.item.v1.FabricItemSettings; import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents; import net.minecraft.block.Block; +import net.minecraft.client.item.TooltipContext; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.ItemGroups; +import net.minecraft.item.ItemStack; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; +import net.minecraft.text.Style; +import net.minecraft.text.Text; +import net.minecraft.text.TextColor; +import net.minecraft.util.Formatting; +import net.minecraft.util.Identifier; +import net.minecraft.world.World; import nl.enjarai.omnihopper.blocks.ModBlocks; +import nl.enjarai.omnihopper.util.HasTooltip; +import org.jetbrains.annotations.Nullable; public class ModItems { public static final List ALL = new ArrayList<>(); @@ -20,8 +30,17 @@ public class ModItems { public static void register() {} private static BlockItem registerBlockItem(Block block) { - var item = Registry.register(Registries.ITEM, Registries.BLOCK.getId(block), - new BlockItem(block, new FabricItemSettings())); + Identifier id = Registries.BLOCK.getId(block); + var item = Registry.register(Registries.ITEM, id, new BlockItem(block, new FabricItemSettings()) { + @Override + public void appendTooltip(ItemStack stack, @Nullable World world, List tooltip, TooltipContext context) { + if (block instanceof HasTooltip hasTooltip) { + hasTooltip.appendTooltip(stack, world, tooltip, context, id); + } + + super.appendTooltip(stack, world, tooltip, context); + } + }); ALL.add(item); ItemGroupEvents.modifyEntriesEvent(ItemGroups.REDSTONE).register((entries) -> entries.add(item)); diff --git a/src/main/java/nl/enjarai/omnihopper/util/HasTooltip.java b/src/main/java/nl/enjarai/omnihopper/util/HasTooltip.java new file mode 100644 index 0000000..292e70d --- /dev/null +++ b/src/main/java/nl/enjarai/omnihopper/util/HasTooltip.java @@ -0,0 +1,24 @@ +package nl.enjarai.omnihopper.util; + +import net.minecraft.client.item.TooltipContext; +import net.minecraft.item.ItemStack; +import net.minecraft.text.Style; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; +import net.minecraft.util.Identifier; +import net.minecraft.util.Util; +import net.minecraft.world.World; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public interface HasTooltip { + default void appendTooltip(ItemStack stack, @Nullable World world, List tooltip, TooltipContext context, Identifier id) { + tooltip.add(Text.translatable(Util.createTranslationKey("item", modifyTooltipId(id)) + ".tooltip") + .setStyle(Style.EMPTY.withColor(Formatting.DARK_GRAY))); + } + + default Identifier modifyTooltipId(Identifier id) { + return id; + } +} diff --git a/src/main/resources/assets/omnihopper/lang/en_us.json b/src/main/resources/assets/omnihopper/lang/en_us.json index 0cdc41d..50e3215 100644 --- a/src/main/resources/assets/omnihopper/lang/en_us.json +++ b/src/main/resources/assets/omnihopper/lang/en_us.json @@ -21,6 +21,14 @@ "block.omnihopper.open_box": "Lidless Chest", + "item.omnihopper.omnihopper.tooltip": "Can be placed in any orientation", + "item.omnihopper.fluid_omnihopper.tooltip": "Transfers fluids instead of items, omnidirectional", + "item.omnihopper.fluid_hopper.tooltip": "Transfers fluids instead of items", + "item.omnihopper.wooden_omnihopper.tooltip": "A cheaper and slower hopper variant, omnidirectional", + "item.omnihopper.wooden_hopper.tooltip": "A cheaper and slower hopper variant", + + "item.omnihopper.open_box.tooltip": "Drops any inserted items on the ground", + "container.omnihopper": "Omni-Hopper", "container.fluid_omnihopper": "Omni-Flopper", "container.fluid_hopper": "Flopper", diff --git a/src/main/resources/data/omnihopper/recipes/fluid_hopper.json b/src/main/resources/data/omnihopper/recipes/fluid_hopper.json index 2894dfd..bdd90b6 100644 --- a/src/main/resources/data/omnihopper/recipes/fluid_hopper.json +++ b/src/main/resources/data/omnihopper/recipes/fluid_hopper.json @@ -2,12 +2,12 @@ "type": "minecraft:crafting_shaped", "pattern": [ "c c", - "cCc", + "cBc", " c " ], "key": { - "C": { - "item": "minecraft:cauldron" + "B": { + "item": "minecraft:bucket" }, "c": { "item": "minecraft:copper_ingot" diff --git a/src/main/resources/data/omnihopper/recipes/wooden_hopper.json b/src/main/resources/data/omnihopper/recipes/wooden_hopper.json new file mode 100644 index 0000000..3023abf --- /dev/null +++ b/src/main/resources/data/omnihopper/recipes/wooden_hopper.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "w w", + "wCw", + " w " + ], + "key": { + "C": { + "item": "minecraft:chest" + }, + "w": { + "tag": "minecraft:planks" + } + }, + "result": { + "item": "omnihopper:wooden_hopper" + } +} \ No newline at end of file diff --git a/src/main/resources/data/omnihopper/recipes/wooden_omnihopper.json b/src/main/resources/data/omnihopper/recipes/wooden_omnihopper.json new file mode 100644 index 0000000..aeb38fe --- /dev/null +++ b/src/main/resources/data/omnihopper/recipes/wooden_omnihopper.json @@ -0,0 +1,14 @@ +{ + "type": "minecraft:crafting_shapeless", + "ingredients": [ + { + "item": "omnihopper:wooden_hopper" + }, + { + "item": "minecraft:copper_ingot" + } + ], + "result": { + "item": "omnihopper:wooden_omnihopper" + } +}