Skip to content

Commit

Permalink
backport
Browse files Browse the repository at this point in the history
- tooltip generation via item class instead of event
- ender helmet added #15
  • Loading branch information
cech12 committed Nov 10, 2020
1 parent bd7d5fa commit 503709d
Show file tree
Hide file tree
Showing 30 changed files with 433 additions and 37 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false

mod_version=1.8.5
mod_version=1.9.0
minecraft_version=1.14.4

forge_version=1.14.4-28.1.0
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/cech12/usefulhats/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public class Config {
public static final ConfigType.Double CHOPPING_HAT_SPEED_WITH_EFFICIENCY_4 = new ConfigType.Double(1.0);
public static final ConfigType.Double CHOPPING_HAT_SPEED_WITH_EFFICIENCY_5 = new ConfigType.Double(1.5);

public static final ConfigType.Boolean ENDER_HELMET_ENABLED = new ConfigType.Boolean(true);
public static final ConfigType.Boolean ENDER_HELMET_DAMAGE_ENABLED = new ConfigType.Boolean(true);
public static final ConfigType.Integer ENDER_HELMET_DURABILITY = new ConfigType.Integer(80);
public static final ConfigType.Boolean ENDER_HELMET_INTERDIMENSIONAL_ENABLED = new ConfigType.Boolean(true);

public static final ConfigType.Boolean HALO_ENABLED = new ConfigType.Boolean(true);
public static final ConfigType.Boolean HALO_DAMAGE_ENABLED = new ConfigType.Boolean(true);
public static final ConfigType.Integer HALO_DURABILITY = new ConfigType.Integer(600);
Expand Down Expand Up @@ -118,6 +123,9 @@ public class Config {
CHOPPING_HAT_ENABLED.configObj = common
.comment("Whether or not Chopping Hat should be enabled.")
.define("choppingHatEnabled", CHOPPING_HAT_ENABLED.getDefaultValue());
ENDER_HELMET_ENABLED.configObj = common
.comment("Whether or not Ender Helmet should be enabled.")
.define("enderHelmetEnabled", ENDER_HELMET_ENABLED.getDefaultValue());
HALO_ENABLED.configObj = common
.comment("Whether or not Halo should be enabled.")
.define("haloEnabled", HALO_ENABLED.getDefaultValue());
Expand Down Expand Up @@ -206,6 +214,18 @@ public class Config {
.defineInRange("choppingHatSpeedWithEfficiency5", CHOPPING_HAT_SPEED_WITH_EFFICIENCY_5.getDefaultValue(), 0.0, 5.0);
common.pop();

common.push("Ender Helmet");
ENDER_HELMET_DAMAGE_ENABLED.configObj = common
.comment("Whether or not damaging of Ender Helmet should be enabled.")
.define("enderHelmetDamageEnabled", ENDER_HELMET_DAMAGE_ENABLED.getDefaultValue());
ENDER_HELMET_DURABILITY.configObj = common
.comment("Ender Helmet durability.")
.defineInRange("enderHelmetDurability", ENDER_HELMET_DURABILITY.getDefaultValue(), 1, 10000);
ENDER_HELMET_INTERDIMENSIONAL_ENABLED.configObj = common
.comment("Whether or not interdimensional teleporting with the Ender Helmet should be enabled.")
.define("enderHelmetInterdimensionalEnabled", ENDER_HELMET_INTERDIMENSIONAL_ENABLED.getDefaultValue());
common.pop();

common.push("Halo");
HALO_DAMAGE_ENABLED.configObj = common
.comment("Whether or not damaging of Halo should be enabled.")
Expand Down
25 changes: 14 additions & 11 deletions src/main/java/cech12/usefulhats/init/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import net.minecraftforge.event.entity.living.LivingEquipmentChangeEvent;
import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent;
import net.minecraftforge.event.entity.player.ItemFishedEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
Expand All @@ -39,6 +39,7 @@ public class ModItems {
new AquanautHelmetItem(),
new BunnyEarsItem(),
new ChoppingHatItem(),
new EnderHelmetItem(),
new HaloItem(),
new LuckyHatItem(),
new MiningHatItem(),
Expand Down Expand Up @@ -83,6 +84,7 @@ public static void addEventListeners() {
MinecraftForge.EVENT_BUS.addListener(ModItems::onLivingEquipmentChangeEvent);
MinecraftForge.EVENT_BUS.addListener(ModItems::onLivingSetAttackTargetEvent);
MinecraftForge.EVENT_BUS.addListener(ModItems::onLivingUseItemEvent);
MinecraftForge.EVENT_BUS.addListener(ModItems::onRightClickItemEvent);
//curios events
if (CuriosMod.isLoaded()) {
MinecraftForge.EVENT_BUS.addListener(ModItems::onCuriosEquipmentChangeEvent);
Expand All @@ -94,7 +96,6 @@ public static void addEventListeners() {
*/
@OnlyIn(Dist.CLIENT)
public static void addClientEventListeners() {
MinecraftForge.EVENT_BUS.addListener(ModItems::onItemToolTipEvent);
MinecraftForge.EVENT_BUS.addListener(ModItems::onRenderGameOverlayEvent);
}

Expand Down Expand Up @@ -139,15 +140,6 @@ private static void onItemFishedEvent(ItemFishedEvent event) {
}
}

private static void onItemToolTipEvent(ItemTooltipEvent event) {
ItemStack stack = event.getItemStack();
for (Item item : ModItems.items) {
if (/*item instanceof AbstractHatItem &&*/ stack.getItem() == item) {
((AbstractHatItem) item).onItemToolTipEvent(stack, event.getToolTip());
}
}
}

private static void onLivingDropsEvent(LivingDropsEvent event) {
if (event.getSource().getImmediateSource() instanceof PlayerEntity) {
PlayerEntity player = (PlayerEntity) event.getSource().getImmediateSource();
Expand Down Expand Up @@ -229,6 +221,17 @@ private static void onLivingSetAttackTargetEvent(LivingSetAttackTargetEvent even
}
}

private static void onRightClickItemEvent(PlayerInteractEvent.RightClickItem event) {
PlayerEntity player = event.getPlayer();
for (ItemStack headSlotItemStack : UsefulHatsUtils.getEquippedHatItemStacks(player)) {
for (Item item : ModItems.items) {
if (item instanceof IRightClickListener && item == headSlotItemStack.getItem()) {
((IRightClickListener) item).onRightClickItemEvent(event, headSlotItemStack);
}
}
}
}

@OnlyIn(Dist.CLIENT)
private static void onRenderGameOverlayEvent(RenderGameOverlayEvent.Pre event) {
if (!event.isCanceled() && event.getType() == RenderGameOverlayEvent.ElementType.HELMET) {
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/cech12/usefulhats/item/AbstractHatItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.google.common.collect.Multimap;
import com.lazy.baubles.api.IBauble;
import com.lazy.baubles.api.cap.BaublesCapabilities;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.enchantment.Enchantments;
Expand All @@ -31,6 +32,9 @@
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
Expand Down Expand Up @@ -204,7 +208,10 @@ public <T extends LivingEntity> int damageItem(ItemStack stack, int amount, T en
* Adds "When on head" line to end of tooltip.
* When hat item has no effect, override this method with an empty method.
*/
public void onItemToolTipEvent(ItemStack stack, List<ITextComponent> tooltip) {
@Override
@OnlyIn(Dist.CLIENT)
public void addInformation(@Nonnull ItemStack stack, @Nullable World worldIn, @Nonnull List<ITextComponent> tooltip, @Nonnull ITooltipFlag flagIn) {
super.addInformation(stack, worldIn, tooltip, flagIn);
//tooltip.add(new StringTextComponent("Durability: " + (stack.getMaxDamage() - stack.getDamage()) + "/" + stack.getMaxDamage()).applyTextStyle(TextFormatting.RED));
tooltip.add(new StringTextComponent(""));
tooltip.add((new TranslationTextComponent("item.modifiers." + EquipmentSlotType.HEAD.getName())).applyTextStyle(TextFormatting.GRAY));
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/cech12/usefulhats/item/AquanautHelmetItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.entity.LivingEntity;
Expand All @@ -23,6 +24,8 @@
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;

public class AquanautHelmetItem extends AbstractHatItem implements IEquipmentChangeListener, IUsefulHatModelOwner, IGameOverlayRenderer {
Expand All @@ -49,8 +52,9 @@ private int getConduitPowerDuration(ItemStack stack) {
}

@Override
public void onItemToolTipEvent(ItemStack stack, List<ITextComponent> tooltip) {
super.onItemToolTipEvent(stack, tooltip);
@OnlyIn(Dist.CLIENT)
public void addInformation(@Nonnull ItemStack stack, @Nullable World worldIn, @Nonnull List<ITextComponent> tooltip, @Nonnull ITooltipFlag flagIn) {
super.addInformation(stack, worldIn, tooltip, flagIn);
int effectTime = this.getEffectTimeConfig(EnchantmentHelper.getEnchantmentLevel(Enchantments.RESPIRATION, stack));
tooltip.add(new TranslationTextComponent("item.usefulhats.aquanaut_helmet.desc.conduit_power", effectTime).applyTextStyle(TextFormatting.BLUE));
}
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/cech12/usefulhats/item/BunnyEarsItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cech12.usefulhats.UsefulHatsUtils;
import cech12.usefulhats.config.Config;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.entity.LivingEntity;
Expand All @@ -12,8 +13,12 @@
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.event.entity.living.LivingEntityUseItemEvent;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;

public class BunnyEarsItem extends AbstractHatItem implements IEquipmentChangeListener, IItemUseListener, IUsefulHatModelOwner {
Expand All @@ -26,8 +31,9 @@ public BunnyEarsItem() {
}

@Override
public void onItemToolTipEvent(ItemStack stack, List<ITextComponent> tooltip) {
super.onItemToolTipEvent(stack, tooltip);
@OnlyIn(Dist.CLIENT)
public void addInformation(@Nonnull ItemStack stack, @Nullable World worldIn, @Nonnull List<ITextComponent> tooltip, @Nonnull ITooltipFlag flagIn) {
super.addInformation(stack, worldIn, tooltip, flagIn);
int enchantmentLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.EFFICIENCY, stack) + 1;
tooltip.add(new TranslationTextComponent("item.usefulhats.bunny_ears.desc.jump_boost", UsefulHatsUtils.getRomanNumber(enchantmentLevel, false)).applyTextStyle(TextFormatting.BLUE));
tooltip.add(new TranslationTextComponent("item.usefulhats.bunny_ears.desc.eating", enchantmentLevel + 1).applyTextStyle(TextFormatting.BLUE));
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/cech12/usefulhats/item/ChoppingHatItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

import cech12.usefulhats.config.Config;
import net.minecraft.block.BlockState;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.ToolType;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
import java.util.Set;

Expand All @@ -30,8 +36,9 @@ protected double[] getSpeedConfig() {
}

@Override
public void onItemToolTipEvent(ItemStack stack, List<ITextComponent> tooltip) {
super.onItemToolTipEvent(stack, tooltip);
@OnlyIn(Dist.CLIENT)
public void addInformation(@Nonnull ItemStack stack, @Nullable World worldIn, @Nonnull List<ITextComponent> tooltip, @Nonnull ITooltipFlag flagIn) {
super.addInformation(stack, worldIn, tooltip, flagIn);
int value = (int) (this.getEnchantmentValue(stack, this.getSpeedConfig()) * 100);
tooltip.add(new TranslationTextComponent("item.usefulhats.chopping_hat.desc.chopping_speed", value).applyTextStyle(TextFormatting.BLUE));
}
Expand Down
Loading

0 comments on commit 503709d

Please sign in to comment.