Skip to content

Commit

Permalink
Correctly show tooltips for nerfed items. Faster lookups for correct …
Browse files Browse the repository at this point in the history
…tool and tooltips. Fixes #6
  • Loading branch information
wendall911 committed Jun 14, 2018
1 parent 7f3085d commit 711ed8a
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 149 deletions.
4 changes: 2 additions & 2 deletions build.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod_name=TinkerSurvival
modid=tinkersurvival
mod_version=1.0.1.17
last_mod_version=1.0.1.16
mod_version=1.0.1.18
last_mod_version=1.0.1.17
cf_release_type=release
minecraft_version=1.12.2
minecraft_short_version=1.12
Expand Down
5 changes: 3 additions & 2 deletions files/updates.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"homepage": "https://minecraft.curseforge.com/projects/tinkersurvival",
"1.12.2": {
"1.0.1.18": "https://github.com/wendall911/TinkerSurvival/releases/tag/1.0.1.18",
"1.0.1.17": "https://github.com/wendall911/TinkerSurvival/releases/tag/1.0.1.17",
"1.0.1.16": "https://github.com/wendall911/TinkerSurvival/releases/tag/1.0.1.16",
"1.0.1.15": "https://github.com/wendall911/TinkerSurvival/releases/tag/1.0.1.15",
Expand All @@ -12,7 +13,7 @@
"1.0.0.23": "https://github.com/wendall911/TinkerSurvival/releases/tag/1.0.0.23"
},
"promos": {
"1.12.2-latest": "1.0.1.17",
"1.12.2-recommended": "1.0.1.17"
"1.12.2-latest": "1.0.1.18",
"1.12.2-recommended": "1.0.1.18"
}
}
2 changes: 1 addition & 1 deletion resources/assets/tinkersurvival/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jei.description.flint_shard=Flint shards can be obtained from striking flint on

# Tooltips
tooltip.uselessTool1=This tool cannot mine anything!
tooltip.uselessTool2=It can only be used for crafting.
tooltip.uselessTool2=Can only be used for crafting.
tooltip.uselessHoe1=This hoe cannot hoe anything!
tooltip.uselessWeapon1=This weapon hits like a wet noodle!
tooltip.uselessBow1=This bows bowstring snapped!
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/tinkersurvival/event/AttackEventHandler.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package tinkersurvival.event;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;

import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import tinkersurvival.client.sound.Sounds;
import tinkersurvival.util.Event;
import tinkersurvival.util.ItemUse;

public class AttackEventHandler {

Expand All @@ -22,9 +22,7 @@ public void onHurt(LivingHurtEvent event) {
return;
}

ItemStack heldItemStack = player.getHeldItemMainhand();

if (Event.isUselessTool(heldItemStack)) {
if (!ItemUse.isWhitelistItem(player.getHeldItemMainhand())) {
Sounds.play(player, Sounds.SWORD_FAIL, 0.4F, 1.0F);
event.setAmount(0.0f);
event.setCanceled(true);
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/tinkersurvival/event/BowEventHandler.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package tinkersurvival.event;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;

import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.event.entity.player.ArrowLooseEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import tinkersurvival.client.sound.Sounds;
import tinkersurvival.util.Event;
import tinkersurvival.util.ItemUse;

public class BowEventHandler {

@SubscribeEvent
public void onArrowLoose(ArrowLooseEvent event) {
EntityPlayer player = event.getEntityPlayer();
Expand All @@ -20,11 +22,10 @@ public void onArrowLoose(ArrowLooseEvent event) {
return;
}

ItemStack heldItemStack = player.getHeldItemMainhand();

if (Event.isUselessBow(heldItemStack)) {
if (!ItemUse.isWhitelistItem(player.getHeldItemMainhand())) {
Sounds.play(player, Sounds.BOW_FAIL, 0.6F, 1.0F);
event.setCanceled(true);
}
}

}
60 changes: 27 additions & 33 deletions src/main/java/tinkersurvival/event/HarvestEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import tinkersurvival.tools.tool.CrudeKnife;
import tinkersurvival.tools.tool.Knife;
import tinkersurvival.util.Chat;
import tinkersurvival.util.Event;
import tinkersurvival.util.ItemUse;
import tinkersurvival.world.block.BlockRock;
import tinkersurvival.world.TinkerSurvivalWorld;

Expand Down Expand Up @@ -77,22 +77,22 @@ public void slowMining(PlayerEvent.BreakSpeed event) {
}

if (neededToolClass != null) {
if (Event.isValidTool(heldItemStack, neededToolClass)) {
for (String toolClass : heldItemStack.getItem().getToolClasses(heldItemStack)) {
if (neededToolClass.equals(toolClass)) {
if (heldItemStack.getItem().getHarvestLevel(heldItemStack, toolClass, null, null) >= neededHarvestLevel) {
return;
}
}
else if (neededToolClass.equals("axe") && toolClass.equals("mattock")) {
return;
}
else if (neededToolClass.equals("shovel") && toolClass.equals("mattock")) {
return;
} else if(neededToolClass.equals("shovel") && toolClass.equals("pickaxe") && heldItemStack.getItem().getHarvestLevel(heldItemStack, toolClass, null, null) >= 1) {
if (ItemUse.isWhitelistItem(heldItemStack)) {
String toolClass = ItemUse.getToolClass(heldItemStack);

if (neededToolClass.equals(toolClass)) {
if (heldItemStack.getItem().getHarvestLevel(heldItemStack, toolClass, null, null) >= neededHarvestLevel) {
return;
}
}
else if (neededToolClass.equals("axe") && toolClass.equals("mattock")) {
return;
}
else if (neededToolClass.equals("shovel") && toolClass.equals("mattock")) {
return;
} else if(neededToolClass.equals("shovel") && toolClass.equals("pickaxe") && heldItemStack.getItem().getHarvestLevel(heldItemStack, toolClass, null, null) >= 1) {
return;
}

switch (neededToolClass) {
case "axe":
Expand Down Expand Up @@ -150,28 +150,22 @@ public void breakBlock(BlockEvent.BreakEvent event) {
String neededToolClass = block.getHarvestTool(event.getState());

if (neededToolClass != null) {
if (Event.isValidTool(heldItemStack, neededToolClass)) {
Item heldItem = heldItemStack.getItem();
for (String toolClass : heldItem.getToolClasses(heldItemStack)) {
if (neededToolClass.equals(toolClass)) {
if (heldItemStack.getItem().getHarvestLevel(heldItemStack, toolClass, null, null) >= neededHarvestLevel) {
return;
}
}
else if (neededToolClass.equals("axe") && toolClass.equals("mattock")) {
return;
}
else if (neededToolClass.equals("shovel") && toolClass.equals("mattock")) {
return;
}
// Metal Pickaxes and above are allowed to function as shovels with no mining speed penalty + block drops.
else if (neededToolClass.equals("shovel") && toolClass.equals("pickaxe") && heldItemStack.getItem().getHarvestLevel(heldItemStack, toolClass, null, null) >= 1) {
if (ItemUse.isWhitelistItem(heldItemStack)) {
String toolClass = ItemUse.getToolClass(heldItemStack);

if (neededToolClass.equals(toolClass)) {
if (heldItemStack.getItem().getHarvestLevel(heldItemStack, toolClass, null, null) >= neededHarvestLevel) {
return;
}
}

// Sometimes mods register tools as tools, though they aren't really tools. Fun.
if (Event.isWhitelistTool(heldItem.getRegistryName().toString(), neededToolClass)) {
else if (neededToolClass.equals("axe") && toolClass.equals("mattock")) {
return;
}
else if (neededToolClass.equals("shovel") && toolClass.equals("mattock")) {
return;
}
// Metal Pickaxes and above are allowed to function as shovels with no mining speed penalty + block drops.
else if (neededToolClass.equals("shovel") && toolClass.equals("pickaxe") && heldItemStack.getItem().getHarvestLevel(heldItemStack, toolClass, null, null) >= 1) {
return;
}

Expand Down
11 changes: 6 additions & 5 deletions src/main/java/tinkersurvival/event/HoeEventHandler.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package tinkersurvival.event;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;

import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.event.entity.player.UseHoeEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import tinkersurvival.client.sound.Sounds;
import tinkersurvival.util.Event;
import tinkersurvival.util.ItemUse;

public class HoeEventHandler {

@SubscribeEvent
public void onHoeBlock(UseHoeEvent event) {
EntityPlayer player = event.getEntityPlayer();
Expand All @@ -20,11 +22,10 @@ public void onHoeBlock(UseHoeEvent event) {
return;
}

ItemStack heldItemStack = player.getHeldItemMainhand();

if (Event.isUselessHoe(heldItemStack)) {
if (!ItemUse.isWhitelistItem(player.getHeldItemMainhand())) {
Sounds.play(player, Sounds.HOE_FAIL, 0.2F, 1.0F);
event.setCanceled(true);
}
}

}
49 changes: 32 additions & 17 deletions src/main/java/tinkersurvival/event/TooltipEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import slimeknights.tconstruct.library.utils.TinkerUtil;

import tinkersurvival.TinkerSurvival;
import tinkersurvival.util.Event;
import tinkersurvival.util.ItemUse;
import tinkersurvival.util.ToolLevelNBT;

public class TooltipEventHandler {
Expand All @@ -32,28 +32,43 @@ public void onItemToolTip(ItemTooltipEvent event) {
return;
}

NBTTagCompound tag = TinkerUtil.getModifierTag(event.getItemStack(), TinkerSurvival.modToolLeveling.getModifierIdentifier());
if (!tag.hasNoTags()) {
ToolLevelNBT data = new ToolLevelNBT(tag);
if (data.cxp >= 0) {
event.getToolTip().add(1, TextFormatting.GOLD + I18n.translateToLocalFormatted("tooltip.cxp"));
ItemStack stack = event.getItemStack();

if (ItemUse.isWhitelistItem(stack)) {
NBTTagCompound tag = TinkerUtil.getModifierTag(stack, TinkerSurvival.modToolLeveling.getModifierIdentifier());
if (!tag.hasNoTags()) {
ToolLevelNBT data = new ToolLevelNBT(tag);
if (data.cxp >= 0) {
event.getToolTip().add(1, TextFormatting.GOLD + I18n.translateToLocalFormatted("tooltip.cxp"));
}
}
}
else {
String type = ItemUse.getToolClass(stack);
String tooltip = "tooltip.uselessTool2";

if (Event.isUselessBow(event.getItemStack())) {
event.getToolTip().add(TextFormatting.DARK_RED + I18n.translateToLocalFormatted("tooltip.uselessBow1"));
}
if (type != null) {
switch (type) {
case "bow":
tooltip = "tooltip.uselessBow1";
break;
case "hoe":
tooltip = "tooltip.uselessHoe1";
break;
case "pickaxe":
tooltip = "tooltip.uselessTool1";
break;
case "sword":
tooltip = "tooltip.uselessWeapon1";
break;
default:
break;

if (Event.isUselessHoe(event.getItemStack())) {
event.getToolTip().add(TextFormatting.DARK_RED + I18n.translateToLocalFormatted("tooltip.uselessHoe1"));
}
event.getToolTip().add(TextFormatting.DARK_RED + I18n.translateToLocalFormatted(tooltip));
}
}

if (Event.isUselessSword(event.getItemStack())) {
event.getToolTip().add(TextFormatting.DARK_RED + I18n.translateToLocalFormatted("tooltip.uselessWeapon1"));
}
if (Event.isUselessTool(event.getItemStack())) {
event.getToolTip().add(TextFormatting.DARK_RED + I18n.translateToLocalFormatted("tooltip.uselessTool2"));
}
}

}
3 changes: 3 additions & 0 deletions src/main/java/tinkersurvival/proxy/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import tinkersurvival.recipe.TinkerSurvivalRecipes;
import tinkersurvival.TinkerSurvival;
import tinkersurvival.tools.TinkerSurvivalTools;
import tinkersurvival.util.ItemUse;
import tinkersurvival.world.TinkerSurvivalWorld;
import tinkersurvival.world.worldgen.RockGenerator;

Expand Down Expand Up @@ -115,6 +116,8 @@ public void postInit(FMLPostInitializationEvent event) {
}
}
}

ItemUse.init();
}

@SubscribeEvent
Expand Down
79 changes: 0 additions & 79 deletions src/main/java/tinkersurvival/util/Event.java

This file was deleted.

Loading

0 comments on commit 711ed8a

Please sign in to comment.