From 05f0bb733bc378ff2e2db51ee0c3c78aee7e6b8c Mon Sep 17 00:00:00 2001 From: Tobias Gremeyer Date: Fri, 1 Feb 2019 02:16:02 +0100 Subject: [PATCH] Removed some redundant stuff for Bindable items, improved inheritance (#1455) * Added explicit Tooltip for unbound items and restructured Bindable inheritance - Added a "Item is not bound" tooltip to ItemBindableBase - Streamlined inheritance. All Sigils now extend ItemBindableBase at some point. - removed redundant hasTextCompound check * Removed TextHelper usages in the affected files. * Nobody likes tooltips. * Forgot the translation entry. * Reverted change --- .../WayofTime/bloodmagic/item/ItemBindableBase.java | 4 ++-- .../WayofTime/bloodmagic/item/sigil/ItemSigil.java | 7 +++---- .../bloodmagic/item/sigil/ItemSigilBase.java | 13 +++---------- .../item/sigil/ItemSigilToggleableBase.java | 9 ++------- 4 files changed, 10 insertions(+), 23 deletions(-) diff --git a/src/main/java/WayofTime/bloodmagic/item/ItemBindableBase.java b/src/main/java/WayofTime/bloodmagic/item/ItemBindableBase.java index 71bafcd7..fa5d84e8 100644 --- a/src/main/java/WayofTime/bloodmagic/item/ItemBindableBase.java +++ b/src/main/java/WayofTime/bloodmagic/item/ItemBindableBase.java @@ -3,10 +3,10 @@ package WayofTime.bloodmagic.item; import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.core.data.Binding; import WayofTime.bloodmagic.iface.IBindable; -import WayofTime.bloodmagic.util.helper.TextHelper; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -29,6 +29,6 @@ public class ItemBindableBase extends Item implements IBindable { Binding binding = getBinding(stack); if (binding != null) - tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.currentOwner", binding.getOwnerName())); + tooltip.add(new TextComponentTranslation("tooltip.bloodmagic.currentOwner", binding.getOwnerName()).getFormattedText()); } } diff --git a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigil.java b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigil.java index 70be6e84..496958e1 100644 --- a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigil.java +++ b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigil.java @@ -1,16 +1,15 @@ package WayofTime.bloodmagic.item.sigil; -import WayofTime.bloodmagic.util.Constants; -import WayofTime.bloodmagic.iface.IBindable; import WayofTime.bloodmagic.iface.ISigil; +import WayofTime.bloodmagic.item.ItemBindableBase; +import WayofTime.bloodmagic.util.Constants; import WayofTime.bloodmagic.util.helper.NBTHelper; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; /** * Base class for all (static) sigils. */ -public class ItemSigil extends Item implements IBindable, ISigil { +public class ItemSigil extends ItemBindableBase implements ISigil { private int lpUsed; public ItemSigil(int lpUsed) { diff --git a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilBase.java b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilBase.java index c62a8ca8..dd4471dc 100644 --- a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilBase.java +++ b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilBase.java @@ -2,14 +2,15 @@ package WayofTime.bloodmagic.item.sigil; import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.client.IVariantProvider; -import WayofTime.bloodmagic.core.data.Binding; import WayofTime.bloodmagic.util.helper.TextHelper; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.item.ItemStack; +import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import org.apache.commons.lang3.text.WordUtils; import javax.annotation.Nonnull; import java.util.Arrays; @@ -24,7 +25,6 @@ public class ItemSigilBase extends ItemSigil implements IVariantProvider { super(lpUsed); setUnlocalizedName(BloodMagic.MODID + ".sigil." + name); - setCreativeTab(BloodMagic.TAB_BM); this.name = name; this.tooltipBase = "tooltip.bloodmagic.sigil." + name + "."; @@ -38,14 +38,7 @@ public class ItemSigilBase extends ItemSigil implements IVariantProvider { @SideOnly(Side.CLIENT) public void addInformation(ItemStack stack, World world, List tooltip, ITooltipFlag flag) { if (TextHelper.canTranslate(tooltipBase + "desc")) - tooltip.addAll(Arrays.asList(TextHelper.cutLongString(TextHelper.localizeEffect(tooltipBase + "desc")))); - - if (!stack.hasTagCompound()) - return; - - Binding binding = getBinding(stack); - if (binding != null) - tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.currentOwner", binding.getOwnerName())); + tooltip.addAll(Arrays.asList(WordUtils.wrap(new TextComponentTranslation(tooltipBase + "desc").getFormattedText(), 30, "/cut", false).split("/cut"))); super.addInformation(stack, world, tooltip, flag); } diff --git a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilToggleableBase.java b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilToggleableBase.java index 08fb9dff..2586e266 100644 --- a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilToggleableBase.java +++ b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilToggleableBase.java @@ -3,11 +3,10 @@ package WayofTime.bloodmagic.item.sigil; import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.client.IMeshProvider; import WayofTime.bloodmagic.client.mesh.CustomMeshDefinitionActivatable; -import WayofTime.bloodmagic.core.data.Binding; -import WayofTime.bloodmagic.util.helper.TextHelper; import net.minecraft.client.renderer.ItemMeshDefinition; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.item.ItemStack; +import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -38,11 +37,7 @@ public class ItemSigilToggleableBase extends ItemSigilToggleable implements IMes if (!stack.hasTagCompound()) return; - tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic." + (getActivated(stack) ? "activated" : "deactivated"))); - - Binding binding = getBinding(stack); - if (binding != null) - tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.currentOwner", binding.getOwnerName())); + tooltip.add(new TextComponentTranslation("tooltip.bloodmagic." + (getActivated(stack) ? "activated" : "deactivated")).getFormattedText()); } @Override