mirror of
https://github.com/GTNewHorizons/bdlib.git
synced 2026-11-24 05:54:39 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
71185838f6 | ||
|
|
f2cdba7800 | ||
|
|
89b54300e3 |
No files matched your search
+1
-1
@@ -1,4 +1,4 @@
|
||||
bdlib.version=1.9.0
|
||||
bdlib.version=1.9.1
|
||||
curseforge.id=70496
|
||||
|
||||
minecraft.version=1.7.10
|
||||
|
||||
@@ -13,6 +13,7 @@ import cpw.mods.fml.common.Mod.EventHandler
|
||||
import cpw.mods.fml.common.event.{FMLPreInitializationEvent, FMLServerStartingEvent, FMLServerStoppingEvent}
|
||||
import cpw.mods.fml.common.{FMLCommonHandler, Mod}
|
||||
import net.bdew.lib.multiblock.network.NetHandler
|
||||
import net.bdew.lib.tooltip.TooltipHandler
|
||||
import net.minecraft.command.CommandHandler
|
||||
import org.apache.logging.log4j.Logger
|
||||
|
||||
@@ -37,6 +38,9 @@ object BdLib {
|
||||
log.debug("List of loaded APIs: " + ApiReporter.APIs)
|
||||
FMLCommonHandler.instance().registerCrashCallable(ApiReporter)
|
||||
NetHandler.init()
|
||||
if (ev.getSide.isClient) {
|
||||
TooltipHandler.init()
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
||||
@@ -14,11 +14,11 @@ import net.bdew.lib.gui.{Color, Point, Rect, Texture}
|
||||
|
||||
import scala.collection.mutable
|
||||
|
||||
class WidgetInfo(val rect: Rect, icon: Texture, text: => String, tooltip: => String) extends Widget {
|
||||
class WidgetInfoMulti(val rect: Rect, icon: Texture, text: => String, tooltip: => List[String]) extends Widget {
|
||||
final val iconRect = Rect(1, 1, 8, 8)
|
||||
|
||||
override def handleTooltip(p: Point, tip: mutable.MutableList[String]) {
|
||||
if (iconRect.contains(p) && tooltip != null) tip += tooltip
|
||||
if (iconRect.contains(p) && tooltip != null) tip ++= tooltip
|
||||
}
|
||||
|
||||
override def draw(mouse: Point) {
|
||||
@@ -26,3 +26,5 @@ class WidgetInfo(val rect: Rect, icon: Texture, text: => String, tooltip: => Str
|
||||
parent.drawText(text, rect.origin +(12, 1), Color.darkGray, false)
|
||||
}
|
||||
}
|
||||
|
||||
class WidgetInfo(rect: Rect, icon: Texture, text: => String, tooltip: => String) extends WidgetInfoMulti(rect, icon, text, List(tooltip))
|
||||
@@ -34,6 +34,7 @@ case class DataSlotPower(name: String, parent: DataSlotContainer) extends DataSl
|
||||
val canExtract = Misc.clamp(v, 0F, stored)
|
||||
if ((canExtract > 0) && !simulate) {
|
||||
stored -= canExtract
|
||||
if (stored < 1) stored = 0
|
||||
parent.dataSlotChanged(this)
|
||||
}
|
||||
return canExtract
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2015
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.tooltip
|
||||
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraftforge.fluids.{FluidContainerRegistry, FluidStack, IFluidContainerItem}
|
||||
|
||||
trait FluidTooltipProvider extends TooltipProvider {
|
||||
def getFluid(is: ItemStack): Option[FluidStack] = {
|
||||
if (is.getItem.isInstanceOf[IFluidContainerItem]) {
|
||||
Option(is.getItem.asInstanceOf[IFluidContainerItem].getFluid(is))
|
||||
} else {
|
||||
Option(FluidContainerRegistry.getFluidForFilledItem(is))
|
||||
}
|
||||
}
|
||||
|
||||
override def shouldHandleTooltip(stack: ItemStack): Boolean = getFluid(stack) exists shouldHandleTooltip
|
||||
override def handleTooltip(stack: ItemStack, advanced: Boolean, shift: Boolean): Iterable[String] =
|
||||
getFluid(stack) map (f => handleTooltip(f, advanced, shift)) getOrElse Iterable.empty
|
||||
|
||||
def shouldHandleTooltip(fluid: FluidStack): Boolean
|
||||
def handleTooltip(fluid: FluidStack, advanced: Boolean, shift: Boolean): Iterable[String]
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2015
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.tooltip
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent
|
||||
import net.bdew.lib.{BdLib, Client}
|
||||
import net.minecraftforge.common.MinecraftForge
|
||||
import net.minecraftforge.event.entity.player.ItemTooltipEvent
|
||||
|
||||
object TooltipHandler {
|
||||
var registry = List.empty[TooltipProvider]
|
||||
|
||||
def init() {
|
||||
MinecraftForge.EVENT_BUS.register(this)
|
||||
}
|
||||
|
||||
def register(p: TooltipProvider) = registry :+= p
|
||||
|
||||
@SubscribeEvent
|
||||
def handleTooltipEvent(ev: ItemTooltipEvent): Unit = {
|
||||
if (ev.itemStack == null || ev.itemStack.getItem == null) return
|
||||
|
||||
val toAdd = for (provider <- registry) yield {
|
||||
try {
|
||||
if (provider.shouldHandleTooltip(ev.itemStack))
|
||||
Some(provider.handleTooltip(ev.itemStack, ev.showAdvancedItemTooltips, Client.shiftDown))
|
||||
else
|
||||
None
|
||||
} catch {
|
||||
case t: Throwable =>
|
||||
BdLib.logErrorException("Error in tooltip provider %s", t, provider)
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
import scala.collection.JavaConversions._
|
||||
|
||||
ev.toolTip ++= toAdd.flatten.flatten
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2015
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.tooltip
|
||||
|
||||
import net.minecraft.item.ItemStack
|
||||
|
||||
trait TooltipProvider {
|
||||
def shouldHandleTooltip(stack: ItemStack): Boolean
|
||||
def handleTooltip(stack: ItemStack, advanced: Boolean, shift: Boolean): Iterable[String]
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user