Skip to content

Commit

Permalink
Gave end user more control over tooltips
Browse files Browse the repository at this point in the history
  • Loading branch information
StellarWind22 committed Mar 3, 2022
1 parent da261b1 commit cedc109
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 21 deletions.
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/develop/
minecraft_version=1.18.1
yarn_mappings=1.18.1+build.22
loader_version=0.13.1
minecraft_version=1.18.2
yarn_mappings=1.18.2+build.1
loader_version=0.13.3

# Mod Properties
mod_version=1.5.1-pre2-1.18
maven_group=com.github.crimsondawn45
archives_base_name=FabricShieldLib

# Dependencies
fabric_version=0.46.4+1.18
fabric_version=0.47.8+1.18.2
fabric_asm_version=2.3
cloth_version=6.2.57
mod_menu_version=3.0.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,17 @@ public void onInitializeClient() {
if(stack.getItem() instanceof FabricShield) {

FabricShield shield = (FabricShield) stack.getItem();
getCooldownTooltip(stack, context,tooltip, shield.getCooldownTicks());

//Add any custom tooltips
shield.appendShieldTooltip(stack, tooltip, context);

//Add cooldown tooltip
if(shield.displayTooltip()) {
getCooldownTooltip(stack, context,tooltip, shield.getCooldownTicks());
}
}


//Display tooltip for vanilla shield
if(stack.getItem().equals(Items.SHIELD)) {
getCooldownTooltip(stack, context,tooltip, 100);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import net.minecraft.item.ToolMaterial;
import net.minecraft.recipe.Ingredient;
import net.minecraft.tag.Tag;
import net.minecraft.tag.Tag.Identified;
import net.minecraft.text.Text;
import net.minecraft.util.DyeColor;
import net.minecraft.util.Hand;
Expand All @@ -39,7 +38,7 @@ public class FabricBannerShieldItem extends Item implements FabricShield {
private Item[] repairItems;
private Tag<Item> repairTag;
private Ingredient repairIngredients;
private Collection<Identified<Item>> repairTags;
private Collection<Tag<Item>> repairTags;

private RepairItemType repairType;

Expand Down Expand Up @@ -98,7 +97,7 @@ public FabricBannerShieldItem(Settings settings, int cooldownTicks, ToolMaterial
* @param enchantability enchantability of shield. Vanilla: 9
* @param repairItemTag item tag for repairing shield.
*/
public FabricBannerShieldItem(Settings settings, int cooldownTicks, int enchantability, Tag.Identified<Item> repairItemTag) {
public FabricBannerShieldItem(Settings settings, int cooldownTicks, int enchantability, Tag<Item> repairItemTag) {
super(settings);

//Register dispenser equip behavior
Expand All @@ -123,7 +122,7 @@ public FabricBannerShieldItem(Settings settings, int cooldownTicks, int enchanta
* @param enchantability enchantability of shield. Vanilla: 9
* @param repairItemTag list of item tags for repairing shield.
*/
public FabricBannerShieldItem(Settings settings, int cooldownTicks, int enchantability, Collection<Tag.Identified<Item>> repairItemTags) {
public FabricBannerShieldItem(Settings settings, int cooldownTicks, int enchantability, Collection<Tag<Item>> repairItemTags) {
super(settings);

//Register dispenser equip behavior
Expand All @@ -144,8 +143,8 @@ public FabricBannerShieldItem(Settings settings, int cooldownTicks, int enchanta

public String getTranslationKey(ItemStack stack) {
if (stack.getSubNbt("BlockEntityTag") != null) {
String var10000 = this.getTranslationKey();
return var10000 + "." + getColor(stack).getName();
String key = this.getTranslationKey();
return key + "." + getColor(stack).getName();
} else {
return super.getTranslationKey(stack);
}
Expand All @@ -159,6 +158,9 @@ public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> too
BannerItem.appendBannerTooltip(stack, tooltip);
}

@Override
public void appendShieldTooltip(ItemStack stack, List<Text> tooltip, TooltipContext context) {}

@Override
public int getCooldownTicks() {
return this.cooldownTicks;
Expand Down Expand Up @@ -191,11 +193,11 @@ public boolean canRepair(ItemStack stack, ItemStack ingredient) {
}
}
return false;
case TAG: return this.repairTag.contains(ingredient.getItem());
case TAG: return this.repairTag.values().contains(ingredient.getItem());
case INGREDIENT: return this.repairIngredients.test(ingredient);
case TAG_ARRAY:
for(Tag<Item> tag : this.repairTags) {
if(tag.contains(ingredient.getItem())) {
if(tag.values().contains(ingredient.getItem())) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.github.crimsondawn45.fabricshieldlib.lib.object;

import java.util.List;

import net.minecraft.client.item.TooltipContext;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;

/**
* used to identify which items should be treated as shields.
*/
Expand All @@ -19,9 +25,25 @@ public interface FabricShield {

/**
* If library will allow this shield to have shield enchantments on it.
* @return
*/
default boolean acceptsShieldEnchantments() {
return true;
}

/**
* Whether or not the shield will have a tooltip showing cooldown
* when hit by an axe.
*/
default boolean displayTooltip() {
return true;
}

/**
* Adds a tooltip immediately after the name & before the tooltip saying shield stats.
* @param stack shield's item stack
* @param world world
* @param tooltip current tooltip
* @param context context
*/
void appendShieldTooltip(ItemStack stack, List<Text> tooltip, TooltipContext context);
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package com.github.crimsondawn45.fabricshieldlib.lib.object;

import java.util.Collection;
import java.util.List;

import net.fabricmc.api.EnvType;
import net.fabricmc.fabric.api.object.builder.v1.client.model.FabricModelPredicateProviderRegistry;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.block.DispenserBlock;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ToolMaterial;
import net.minecraft.recipe.Ingredient;
import net.minecraft.tag.Tag;
import net.minecraft.tag.Tag.Identified;
import net.minecraft.text.Text;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.TypedActionResult;
Expand All @@ -32,7 +34,7 @@ public class FabricShieldItem extends Item implements FabricShield {
private Item[] repairItems;
private Tag<Item> repairTag;
private Ingredient repairIngredients;
private Collection<Identified<Item>> repairTags;
private Collection<Tag<Item>> repairTags;

private RepairItemType repairType;

Expand Down Expand Up @@ -91,7 +93,7 @@ public FabricShieldItem(Settings settings, int cooldownTicks, ToolMaterial mater
* @param enchantability enchantability of shield. Vanilla: 14
* @param repairItemTag item tag for repairing shield
*/
public FabricShieldItem(Settings settings, int cooldownTicks, int enchantability, Tag.Identified<Item> repairItemTag) {
public FabricShieldItem(Settings settings, int cooldownTicks, int enchantability, Tag<Item> repairItemTag) {
super(settings); //Make durability match material

//Register dispenser equip behavior
Expand All @@ -116,7 +118,7 @@ public FabricShieldItem(Settings settings, int cooldownTicks, int enchantability
* @param enchantability enchantability of shield. Vanilla: 9
* @param repairItemTag list of item tags for repairing shield.
*/
public FabricShieldItem(Settings settings, int cooldownTicks, int enchantability, Collection<Tag.Identified<Item>> repairItemTags) {
public FabricShieldItem(Settings settings, int cooldownTicks, int enchantability, Collection<Tag<Item>> repairItemTags) {
super(settings);

//Register dispenser equip behavior
Expand All @@ -135,6 +137,9 @@ public FabricShieldItem(Settings settings, int cooldownTicks, int enchantability
this.enchantability = enchantability;
}

@Override
public void appendShieldTooltip(ItemStack stack, List<Text> tooltip, TooltipContext context) {}

@Override
public int getCooldownTicks() {
return this.cooldownTicks;
Expand Down Expand Up @@ -167,11 +172,11 @@ public boolean canRepair(ItemStack stack, ItemStack ingredient) {
}
}
return false;
case TAG: return this.repairTag.contains(ingredient.getItem());
case TAG: return this.repairTag.values().contains(ingredient.getItem());
case INGREDIENT: return this.repairIngredients.test(ingredient);
case TAG_ARRAY:
for(Tag<Item> tag : this.repairTags) {
if(tag.contains(ingredient.getItem())) {
if(tag.values().contains(ingredient.getItem())) {
return true;
}
}
Expand Down

0 comments on commit cedc109

Please sign in to comment.