mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-14 01:04:12 +00:00
Auto-apply stats tooltips to all IHiveFrame items (#51)
* Auto-apply stats tooltips to all IHiveFrame items * allow generated tooltip to be overridden * link event in api, update production tooltip
This commit is contained in:
1 parent
39c822df8a
commit
29df6ceb1b
4 files changed
+128
No files matched your search
@@ -5,7 +5,12 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.apiculture;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
||||
|
||||
public interface IHiveFrame {
|
||||
|
||||
@@ -22,4 +27,15 @@ public interface IHiveFrame {
|
||||
ItemStack frameUsed(IBeeHousing housing, ItemStack frame, IBee queen, int wear);
|
||||
|
||||
IBeeModifier getBeeModifier();
|
||||
|
||||
/**
|
||||
* Provides an override for the "Hold Shift" tooltip info for a frame.<br>
|
||||
* Called by {@link forestry.apiculture.EventHandlerApiculture#addFrameTooltip(ItemTooltipEvent)}.
|
||||
*
|
||||
* @return The info to display for this frame, or null if default generated info.
|
||||
*/
|
||||
@Nullable
|
||||
default List<String> getFrameTooltip() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package forestry.apiculture;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import forestry.api.apiculture.IBeeModifier;
|
||||
import forestry.api.apiculture.IHiveFrame;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.StringUtil;
|
||||
|
||||
public class EventHandlerApiculture {
|
||||
|
||||
@SubscribeEvent
|
||||
public void addFrameTooltip(ItemTooltipEvent event) {
|
||||
ItemStack itemStack = event.itemStack;
|
||||
if (itemStack != null && itemStack.getItem() instanceof IHiveFrame) {
|
||||
IHiveFrame frame = (IHiveFrame) itemStack.getItem();
|
||||
IBeeModifier modifier = frame.getBeeModifier();
|
||||
List<String> tooltip = event.toolTip;
|
||||
|
||||
if (!Proxies.common.isShiftDown()) {
|
||||
tooltip.add(EnumChatFormatting.ITALIC + "<" + StringUtil.localize("gui.tooltip.tmi") + ">");
|
||||
} else {
|
||||
if (frame.getFrameTooltip() != null) {
|
||||
// use the override if it exists
|
||||
tooltip.addAll(frame.getFrameTooltip());
|
||||
} else {
|
||||
// otherwise use the auto-generated info
|
||||
int durability = itemStack.getMaxDamage();
|
||||
tooltip.add(StringUtil.localize("frame.tooltip.durability") + getDurabilityFormatted(durability));
|
||||
|
||||
float territory = modifier.getTerritoryModifier(null, 1.0F);
|
||||
tooltip.add(StringUtil.localize("frame.tooltip.territory") + getColorFormatted(territory));
|
||||
|
||||
float mutation = modifier.getMutationModifier(null, null, 1.0F);
|
||||
tooltip.add(StringUtil.localize("frame.tooltip.mutationRate") + getColorFormatted(mutation));
|
||||
|
||||
float lifespan = modifier.getLifespanModifier(null, null, 1.0F);
|
||||
tooltip.add(StringUtil.localize("frame.tooltip.lifespan") + getColorFormatted(lifespan));
|
||||
|
||||
float production = modifier.getProductionModifier(null, 1.0F);
|
||||
tooltip.add(StringUtil.localize("frame.tooltip.production") + getColorFormatted(production, true));
|
||||
|
||||
float decay = modifier.getGeneticDecay(null, 1.0F);
|
||||
tooltip.add(StringUtil.localize("frame.tooltip.geneticDecay") + getColorFormatted(decay));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String getDurabilityFormatted(int durability) {
|
||||
EnumChatFormatting color;
|
||||
if (durability < 100) {
|
||||
color = EnumChatFormatting.DARK_RED;
|
||||
} else if (durability < 200) {
|
||||
color = EnumChatFormatting.RED;
|
||||
} else if (durability < 250) {
|
||||
color = EnumChatFormatting.GOLD;
|
||||
} else if (durability < 750) {
|
||||
color = EnumChatFormatting.GREEN;
|
||||
} else {
|
||||
color = EnumChatFormatting.AQUA;
|
||||
}
|
||||
return color + " " + durability;
|
||||
}
|
||||
|
||||
private static String getColorFormatted(float value, boolean additive) {
|
||||
EnumChatFormatting color;
|
||||
if (value <= 0.5F) {
|
||||
color = EnumChatFormatting.DARK_RED; // "bad" stat
|
||||
} else if (value < 1.0F) {
|
||||
color = EnumChatFormatting.RED; // "below average" stat
|
||||
} else if (value == 1.0F) {
|
||||
color = EnumChatFormatting.GOLD; // "average" stat
|
||||
} else if (value <= 2.0F) {
|
||||
color = EnumChatFormatting.GREEN; // "above average" stat
|
||||
} else {
|
||||
color = EnumChatFormatting.AQUA; // "great" stat
|
||||
}
|
||||
String formatted = color.toString();
|
||||
|
||||
// Set symbol for if this value is additive or multiplicative
|
||||
if (additive) {
|
||||
formatted += " +";
|
||||
} else {
|
||||
formatted += " x";
|
||||
}
|
||||
|
||||
// trim trailing zeroes if no decimal-precision is needed
|
||||
if (value == (long) value) {
|
||||
return formatted + (long) value;
|
||||
}
|
||||
return formatted + value;
|
||||
}
|
||||
|
||||
private static String getColorFormatted(float value) {
|
||||
return getColorFormatted(value, false);
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,7 @@ import forestry.api.recipes.RecipeManagers;
|
||||
import forestry.api.storage.ICrateRegistry;
|
||||
import forestry.api.storage.StorageManager;
|
||||
import forestry.apiculture.ArmorApiaristHelper;
|
||||
import forestry.apiculture.EventHandlerApiculture;
|
||||
import forestry.apiculture.SaveEventHandlerApiculture;
|
||||
import forestry.apiculture.VillageHandlerApiculture;
|
||||
import forestry.apiculture.blocks.BlockAlveary;
|
||||
@@ -185,6 +186,7 @@ public class PluginApiculture extends ForestryPlugin {
|
||||
super.preInit();
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
MinecraftForge.EVENT_BUS.register(new EventHandlerApiculture());
|
||||
|
||||
blocks.apiculture.addDefinitions(
|
||||
new MachineDefinition(BlockApicultureType.APIARY).setFaces(0, 1, 2, 2, 4, 4, 0, 7),
|
||||
|
||||
@@ -568,6 +568,13 @@ item.for.frameImpregnated.name=Impregnated Frame
|
||||
item.for.frameProven.name=Proven Frame
|
||||
item.for.frameUntreated.name=Untreated Frame
|
||||
|
||||
for.frame.tooltip.durability=Durability:
|
||||
for.frame.tooltip.territory=Territory:
|
||||
for.frame.tooltip.mutationRate=Mutation Rate:
|
||||
for.frame.tooltip.lifespan=Lifespan:
|
||||
for.frame.tooltip.production=Production:
|
||||
for.frame.tooltip.geneticDecay=Genetic Decay:
|
||||
|
||||
item.for.fruits.cherry.name=Cherry
|
||||
item.for.fruits.chestnut.name=Chestnut
|
||||
item.for.fruits.dates.name=Date
|
||||
|
||||
Reference in new issue
Block a user