Skip to content

Commit

Permalink
Whoppa'
Browse files Browse the repository at this point in the history
  • Loading branch information
enjarai committed May 13, 2023
1 parent 6be1a98 commit 7eb00c5
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/main/java/nl/enjarai/omnihopper/blocks/OpenBoxBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@
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;

import java.util.Optional;
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;
Expand Down
23 changes: 21 additions & 2 deletions src/main/java/nl/enjarai/omnihopper/items/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item> ALL = new ArrayList<>();
Expand All @@ -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<Text> 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));
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/nl/enjarai/omnihopper/util/HasTooltip.java
Original file line number Diff line number Diff line change
@@ -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<Text> 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;
}
}
8 changes: 8 additions & 0 deletions src/main/resources/assets/omnihopper/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/data/omnihopper/recipes/fluid_hopper.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
19 changes: 19 additions & 0 deletions src/main/resources/data/omnihopper/recipes/wooden_hopper.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
14 changes: 14 additions & 0 deletions src/main/resources/data/omnihopper/recipes/wooden_omnihopper.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"type": "minecraft:crafting_shapeless",
"ingredients": [
{
"item": "omnihopper:wooden_hopper"
},
{
"item": "minecraft:copper_ingot"
}
],
"result": {
"item": "omnihopper:wooden_omnihopper"
}
}

0 comments on commit 7eb00c5

Please sign in to comment.