mirror of
https://github.com/GTNewHorizons/bdlib.git
synced 2026-10-27 06:44:05 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6a78467232 | ||
|
|
561833db33 | ||
|
|
0e345e6675 | ||
|
|
e78e565ec8 | ||
|
|
573330efd3 | ||
|
|
5e7c8bda2f | ||
|
|
9346d95052 | ||
|
|
f0169a15e5 | ||
|
|
1da90af3f1 | ||
|
|
b015636514 | ||
|
|
610be18c74 | ||
|
|
9c977904ab | ||
|
|
cc107d7466 | ||
|
|
4284f11ec4 | ||
|
|
300726e660 | ||
|
|
02850b9f85 | ||
|
|
1618931c6d | ||
|
|
5854625700 | ||
|
|
8bbab862ab | ||
|
|
9e83d04487 | ||
|
|
9202b27340 | ||
|
|
70ee9fabd6 | ||
|
|
78d9bed924 | ||
|
|
92517cdcec | ||
|
|
bcb8edc8a5 | ||
|
|
9a837361e7 | ||
|
|
5ae0461f10 | ||
|
|
b3f8fb3c56 | ||
|
|
023ae4d77f | ||
|
|
b1e0e70fc4 | ||
|
|
5f01716310 | ||
|
|
0976fb4acc | ||
|
|
4effeafbb7 | ||
|
|
e0d3609e66 | ||
|
|
5a1c150a03 | ||
|
|
c5a7fc3d51 | ||
|
|
9787c4836e | ||
|
|
cd833163af | ||
|
|
5a9aedb4d5 | ||
|
|
2a7bbaeb97 | ||
|
|
58125ee291 | ||
|
|
d9cc8ace82 | ||
|
|
32617ff592 | ||
|
|
64683a0208 | ||
|
|
f593458511 | ||
|
|
e6b38472ce | ||
|
|
e6c0ef2c68 | ||
|
|
56110d8ec5 | ||
|
|
f000d11c54 | ||
|
|
913d4f48a6 | ||
|
|
a25553edaf | ||
|
|
82328d10ec | ||
|
|
12f19fc410 | ||
|
|
7c275f434a | ||
|
|
f960050f9c | ||
|
|
87dd7c34c5 | ||
|
|
9fdc6bd880 | ||
|
|
490433a7f4 | ||
|
|
71bef762a6 | ||
|
|
5eef56811b | ||
|
|
5a3fa7ef75 | ||
|
|
2d799bb797 | ||
|
|
03d9b0fef0 |
No files matched your search
+4
-2
@@ -21,7 +21,7 @@ buildscript {
|
||||
apply plugin: 'scala'
|
||||
apply plugin: 'forge'
|
||||
|
||||
version = "1.4.0"
|
||||
version = "1.6.2"
|
||||
|
||||
if (project.hasProperty('buildnum')) {
|
||||
project.version = project.version + '.' + project.buildnum
|
||||
@@ -34,7 +34,7 @@ archivesBaseName = "bdlib"
|
||||
ext.versuffix = "mc1710"
|
||||
|
||||
minecraft {
|
||||
version = "1.7.10-10.13.0.1180"
|
||||
version = "1.7.10-10.13.2.1231"
|
||||
replace("BDLIB_VER", project.version)
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ sourceSets {
|
||||
resources {
|
||||
srcDir 'resources'
|
||||
}
|
||||
output.resourcesDir = output.classesDir // Hack for IDEA
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +71,7 @@ task sourceJar(type: Jar) {
|
||||
|
||||
task deobfJar(type: Jar) {
|
||||
from sourceSets.main.output
|
||||
duplicatesStrategy "exclude"
|
||||
}
|
||||
|
||||
jar {
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
bdlib.multiblock.face.north=Sever
|
||||
bdlib.multiblock.face.south=Jih
|
||||
bdlib.multiblock.face.east=Západ
|
||||
bdlib.multiblock.face.west=Východ
|
||||
bdlib.multiblock.face.up=Vršek
|
||||
bdlib.multiblock.face.down=Spodek
|
||||
|
||||
bdlib.multiblock.disabled=Zakázáno
|
||||
bdlib.multiblock.incomplete=Tento stroj není kompletní, ještě potřebuje alespoň:
|
||||
bdlib.multiblock.notconnected=Nepřipojeno ke správnému stroji
|
||||
bdlib.multiblock.toomanyoutputs=Připojeno příliš mnoho výstupů, nemohu získat nové připojení
|
||||
|
||||
bdlib.rsmode.always=Vždy ZAPNUTO
|
||||
bdlib.rsmode.never=Zakázáno
|
||||
bdlib.rsmode.rs_on=Povoleno při ruditovém signálu
|
||||
bdlib.rsmode.rs_off=Zakázáno při ruditovém signálu
|
||||
|
||||
bdlib.label.empty=Prázdný
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
bdlib.multiblock.face.north=North
|
||||
bdlib.multiblock.face.south=South
|
||||
bdlib.multiblock.face.east=East
|
||||
bdlib.multiblock.face.west=West
|
||||
bdlib.multiblock.face.up=Top
|
||||
bdlib.multiblock.face.down=Bottom
|
||||
|
||||
bdlib.multiblock.disabled=Disabled
|
||||
bdlib.multiblock.incomplete=This machine is incomplete, it requires at least:
|
||||
bdlib.multiblock.notconnected=Not connected to a valid machine
|
||||
bdlib.multiblock.toomanyoutputs=Too many outputs connected, unable to attach new connection
|
||||
|
||||
bdlib.rsmode.always=Always ON
|
||||
bdlib.rsmode.never=Disabled
|
||||
bdlib.rsmode.rs_on=Enable on redstone
|
||||
bdlib.rsmode.rs_off=Disable on redstone
|
||||
|
||||
bdlib.label.empty=Empty
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
bdlib.multiblock.face.north=Север
|
||||
bdlib.multiblock.face.south=Юг
|
||||
bdlib.multiblock.face.east=Восток
|
||||
bdlib.multiblock.face.west=Запад
|
||||
bdlib.multiblock.face.up=Верх
|
||||
bdlib.multiblock.face.down=Низ
|
||||
|
||||
bdlib.multiblock.disabled=Отключено
|
||||
bdlib.multiblock.incomplete=Этот механизм не завершён, ему требуется как минимум:
|
||||
bdlib.multiblock.notconnected=Не подключено к верному механизму
|
||||
bdlib.multiblock.toomanyoutputs=Слишком много выходов подсоединено, нельзя установить новое соединение
|
||||
|
||||
bdlib.rsmode.always=Всегда ВКЛ.
|
||||
bdlib.rsmode.never=Отключен
|
||||
bdlib.rsmode.rs_on=Включение по сигналу красного камня
|
||||
bdlib.rsmode.rs_off=Отключение по сигналу красного камня
|
||||
|
||||
bdlib.label.empty=Пусто
|
||||
@@ -0,0 +1,18 @@
|
||||
bdlib.multiblock.face.north=北方
|
||||
bdlib.multiblock.face.south=南方
|
||||
bdlib.multiblock.face.east=东方
|
||||
bdlib.multiblock.face.west=西方
|
||||
bdlib.multiblock.face.up=顶部
|
||||
bdlib.multiblock.face.down=底部
|
||||
|
||||
bdlib.multiblock.disabled=停用
|
||||
bdlib.multiblock.incomplete=这台多方块结构机器未搭建完成, 它至少需要安装一个:
|
||||
bdlib.multiblock.notconnected=未连接有效机器
|
||||
bdlib.multiblock.toomanyoutputs=连接的输出接口过多, 无法连接新的接口
|
||||
|
||||
bdlib.rsmode.always=一直启用
|
||||
bdlib.rsmode.never=一直停用
|
||||
bdlib.rsmode.rs_on=接收到红石信号时启用
|
||||
bdlib.rsmode.rs_off=接收到红石信号时停用
|
||||
|
||||
bdlib.label.empty=空
|
||||
+1
-1
@@ -1 +1 @@
|
||||
rootProject.name='bdlib'
|
||||
rootProject.name = 'bdlib'
|
||||
@@ -4,16 +4,17 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib
|
||||
|
||||
import cpw.mods.fml.common.Mod
|
||||
import cpw.mods.fml.common.event.{FMLServerStartingEvent, FMLPreInitializationEvent}
|
||||
import org.apache.logging.log4j.Logger
|
||||
import cpw.mods.fml.common.Mod.EventHandler
|
||||
import cpw.mods.fml.common.event.{FMLPreInitializationEvent, FMLServerStartingEvent, FMLServerStoppingEvent}
|
||||
import net.bdew.lib.multiblock.network.NetHandler
|
||||
import net.minecraft.command.CommandHandler
|
||||
import org.apache.logging.log4j.Logger
|
||||
|
||||
@Mod(modid = "bdlib", name = "BD lib", version = "BDLIB_VER", modLanguage = "scala")
|
||||
object BdLib {
|
||||
@@ -25,15 +26,25 @@ object BdLib {
|
||||
def logWarnException(msg: String, t: Throwable, args: Any*) = log.warn(msg.format(args: _*), t)
|
||||
def logErrorException(msg: String, t: Throwable, args: Any*) = log.error(msg.format(args: _*), t)
|
||||
|
||||
val onServerStarting = Event[FMLServerStartingEvent]
|
||||
val onServerStopping = Event[FMLServerStoppingEvent]
|
||||
|
||||
@EventHandler
|
||||
def preInit(ev: FMLPreInitializationEvent) {
|
||||
log = ev.getModLog
|
||||
log.info("bdlib BDLIB_VER loaded")
|
||||
NetHandler.init()
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
def serverStarting(event: FMLServerStartingEvent) {
|
||||
val commandHandler = event.getServer.getCommandManager.asInstanceOf[CommandHandler]
|
||||
commandHandler.registerCommand(new CommandDumpRegistry)
|
||||
onServerStarting.trigger(event)
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
def serverStopping(event: FMLServerStoppingEvent) {
|
||||
onServerStopping.trigger(event)
|
||||
}
|
||||
}
|
||||
@@ -4,23 +4,28 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib
|
||||
|
||||
import org.lwjgl.input.Keyboard
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.renderer.texture.TextureMap
|
||||
import org.lwjgl.input.Keyboard
|
||||
|
||||
/**
|
||||
* Misc functions and shortcuts for clientside code
|
||||
* Misc functions and shortcuts for client-side code
|
||||
*/
|
||||
object Client {
|
||||
def minecraft = Minecraft.getMinecraft
|
||||
def fontRenederer = Minecraft.getMinecraft.fontRenderer
|
||||
def fontRenderer = Minecraft.getMinecraft.fontRenderer
|
||||
def renderEngine = Minecraft.getMinecraft.renderEngine
|
||||
def world = Minecraft.getMinecraft.theWorld
|
||||
def player = Minecraft.getMinecraft.thePlayer
|
||||
def textureManager = Minecraft.getMinecraft.getTextureManager
|
||||
|
||||
def blockMissingIcon = textureManager.getTexture(TextureMap.locationBlocksTexture).asInstanceOf[TextureMap].getAtlasSprite("missingno")
|
||||
def itemMissingIcon = textureManager.getTexture(TextureMap.locationItemsTexture).asInstanceOf[TextureMap].getAtlasSprite("missingno")
|
||||
|
||||
def shiftDown: Boolean = {
|
||||
return Keyboard.isKeyDown(42) || Keyboard.isKeyDown(54)
|
||||
|
||||
@@ -4,24 +4,25 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib
|
||||
|
||||
import net.minecraft.command.{CommandBase, ICommandSender}
|
||||
import cpw.mods.fml.relauncher.FMLInjectionData
|
||||
import java.io.{FileWriter, BufferedWriter, File}
|
||||
import cpw.mods.fml.common.registry.GameData
|
||||
import java.io.{BufferedWriter, File, FileWriter}
|
||||
|
||||
import com.google.common.collect.Table
|
||||
import cpw.mods.fml.common.registry.GameData
|
||||
import cpw.mods.fml.relauncher.FMLInjectionData
|
||||
import net.minecraft.command.{CommandBase, ICommandSender}
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraftforge.oredict.OreDictionary
|
||||
import net.minecraftforge.fluids.FluidRegistry
|
||||
import net.minecraftforge.oredict.OreDictionary
|
||||
|
||||
class CommandDumpRegistry extends CommandBase {
|
||||
def getCommandName = "dumpregistry"
|
||||
override def getRequiredPermissionLevel = 2
|
||||
def getCommandUsage(icommandsender: ICommandSender) = "dumpregistry"
|
||||
def getCommandUsage(c: ICommandSender) = "dumpregistry"
|
||||
|
||||
def processCommand(sender: ICommandSender, params: Array[String]) {
|
||||
val mcHome = FMLInjectionData.data()(6).asInstanceOf[File] //is there a better way to get this?
|
||||
@@ -45,7 +46,12 @@ class CommandDumpRegistry extends CommandBase {
|
||||
dumpWriter.write("\n\n")
|
||||
|
||||
dumpWriter.write("==== ORE DICT ====\n")
|
||||
dumpWriter.write(OreDictionary.getOreNames.sorted.mkString("\n"))
|
||||
dumpWriter.write((OreDictionary.getOreNames.sorted flatMap { name =>
|
||||
List(name) ++
|
||||
(OreDictionary.getOres(name) map { ore =>
|
||||
" - " + ore.toString
|
||||
})
|
||||
}).mkString("\n"))
|
||||
dumpWriter.write("\n\n")
|
||||
|
||||
dumpWriter.write("==== FLUIDS ====\n")
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* 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
|
||||
|
||||
import net.minecraft.creativetab.CreativeTabs
|
||||
import net.minecraft.item.Item
|
||||
|
||||
class CreativeTabContainer {
|
||||
|
||||
class Tab(name: String, item: => Item) extends CreativeTabs(name) {
|
||||
override def getTabIconItem = item
|
||||
}
|
||||
|
||||
BdLib.logInfo("Loaded creative tabs for %s", Misc.getActiveModId)
|
||||
|
||||
def init() {}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* 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
|
||||
|
||||
import java.text.DecimalFormat
|
||||
|
||||
object DecFormat {
|
||||
val thousandsFmt = new DecimalFormat("#,##0")
|
||||
val dec2Fmt = new DecimalFormat("#,##0.00")
|
||||
val dec1Fmt = new DecimalFormat("#,##0.0")
|
||||
|
||||
def round(x: Double) = thousandsFmt.format(x)
|
||||
def round(x: Float) = thousandsFmt.format(x)
|
||||
def round(x: Int) = thousandsFmt.format(x)
|
||||
|
||||
def dec2(x: Double) = dec2Fmt.format(x)
|
||||
def dec2(x: Float) = dec2Fmt.format(x)
|
||||
def dec2(x: Int) = dec2Fmt.format(x)
|
||||
|
||||
def short(x: Double) = if (x > 10) thousandsFmt.format(x) else if (x > 1) dec1Fmt.format(x) else dec2Fmt.format(x)
|
||||
def short(x: Float) = if (x > 10) thousandsFmt.format(x) else if (x > 1) dec1Fmt.format(x) else dec2Fmt.format(x)
|
||||
def short(x: Int) = if (x > 10) thousandsFmt.format(x) else if (x > 1) dec1Fmt.format(x) else dec2Fmt.format(x)
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib
|
||||
|
||||
+49
-14
@@ -4,21 +4,22 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraft.util.StatCollector
|
||||
import net.minecraft.item.ItemStack
|
||||
import cpw.mods.fml.common.versioning.{ArtifactVersion, VersionParser}
|
||||
import cpw.mods.fml.common.Loader
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe
|
||||
import net.minecraft.world.biome.BiomeGenBase
|
||||
import cpw.mods.fml.common.registry.GameRegistry
|
||||
import cpw.mods.fml.common.versioning.{ArtifactVersion, VersionParser}
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import net.minecraft.util.{IIcon, StatCollector}
|
||||
import net.minecraft.world.biome.BiomeGenBase
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
import net.minecraftforge.fluids.{Fluid, FluidStack}
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe
|
||||
|
||||
object Misc {
|
||||
def iterNbtCompoundList(parent: NBTTagCompound, name: String): Iterable[NBTTagCompound] = {
|
||||
@@ -26,6 +27,11 @@ object Misc {
|
||||
for (i <- 0 until list.tagCount()) yield list.getCompoundTagAt(i)
|
||||
}
|
||||
|
||||
def iterNbtIntArray(parent: NBTTagCompound, name: String): Iterable[Array[Int]] = {
|
||||
val list = parent.getTagList(name, 11)
|
||||
for (i <- 0 until list.tagCount()) yield list.func_150306_c(i)
|
||||
}
|
||||
|
||||
def getActiveModId = Loader.instance().activeModContainer().getModId
|
||||
|
||||
def toLocal(s: String) = StatCollector.translateToLocal(s)
|
||||
@@ -49,8 +55,8 @@ object Misc {
|
||||
def addRecipeOD(result: ItemStack, pattern: Seq[String], items: Map[Char, AnyRef]) =
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(result, flattenRecipe(pattern, items): _*))
|
||||
|
||||
def min[T](vals: T*)(implicit o: Ordering[T]): T = vals.min(o)
|
||||
def max[T](vals: T*)(implicit o: Ordering[T]): T = vals.max(o)
|
||||
def min[T: Ordering](values: T*) = values.min
|
||||
def max[T: Ordering](values: T*) = values.max
|
||||
|
||||
def clamp[T](value: T, min: T, max: T)(implicit o: Ordering[T]): T = if (o.gt(value, max)) max else if (o.lt(value, min)) min else value
|
||||
|
||||
@@ -59,15 +65,15 @@ object Misc {
|
||||
|
||||
def filterType[T](from: Iterable[_], cls: Class[T]) = from.filter(cls.isInstance).asInstanceOf[Iterable[T]]
|
||||
|
||||
def getBiomeByName(name: String) = BiomeGenBase.getBiomeGenArray.find(x => x != null && x.biomeName == name).getOrElse(null)
|
||||
def getBiomeByName(name: String) = BiomeGenBase.getBiomeGenArray.find(x => x != null && x.biomeName == name).orNull
|
||||
|
||||
def haveModVersion(spec: String): Boolean = {
|
||||
val req = VersionParser.parseVersionReference(spec)
|
||||
val modid = req.getLabel
|
||||
val modId = req.getLabel
|
||||
|
||||
if (!Loader.instance.getIndexedModList.containsKey(modid)) return false
|
||||
if (!Loader.instance.getIndexedModList.containsKey(modId)) return false
|
||||
|
||||
val found: ArtifactVersion = Loader.instance.getIndexedModList.get(modid).getProcessedVersion
|
||||
val found: ArtifactVersion = Loader.instance.getIndexedModList.get(modId).getProcessedVersion
|
||||
|
||||
if (found == null || !req.containsVersion(found)) return false
|
||||
|
||||
@@ -81,8 +87,37 @@ object Misc {
|
||||
def asInstanceOpt[T](v: Any, cls: Class[T]) =
|
||||
if (cls.isInstance(v)) Some(v.asInstanceOf[T]) else None
|
||||
|
||||
// Same thing but in a way that's easier to use with map, etc.
|
||||
def asInstanceOpt[T](cls: Class[T])(v: Any) =
|
||||
if (cls.isInstance(v)) Some(v.asInstanceOf[T]) else None
|
||||
|
||||
def getNeighbourTile[T](origin: TileEntity, dir: ForgeDirection, cls: Class[T]) =
|
||||
Option(origin.getWorldObj.getTileEntity(origin.xCoord + dir.offsetX,
|
||||
origin.yCoord + dir.offsetY, origin.zCoord + dir.offsetZ)) flatMap (asInstanceOpt(_, cls))
|
||||
|
||||
@inline def applyMutator[T](f: (T) => Unit, init: T): T = {
|
||||
f(init)
|
||||
init
|
||||
}
|
||||
|
||||
@inline def applyMutator[T](init: T)(f: (T) => Unit) = {
|
||||
f(init)
|
||||
init
|
||||
}
|
||||
|
||||
def getFluidIcon(fs: FluidStack): IIcon =
|
||||
if (fs != null && fs.getFluid != null && fs.getFluid.getIcon != null)
|
||||
fs.getFluid.getIcon(fs)
|
||||
else
|
||||
Client.blockMissingIcon
|
||||
|
||||
def getFluidIcon(f: Fluid): IIcon =
|
||||
if (f != null) getFluidIcon(new FluidStack(f, 1)) else Client.blockMissingIcon
|
||||
|
||||
def getFluidColor(fs: FluidStack): Int =
|
||||
if (fs != null && fs.getFluid != null) fs.getFluid.getColor(fs) else 0xFFFFFF
|
||||
|
||||
def getFluidColor(f: Fluid): Int =
|
||||
if (f != null) getFluidColor(new FluidStack(f, 1)) else 0xFFFFFF
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* 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.block
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
case class BlockFace(x: Int, y: Int, z: Int, face: ForgeDirection) {
|
||||
def origin = BlockRef(x, y, z)
|
||||
def target = origin.neighbour(face)
|
||||
def opposite = face.getOpposite
|
||||
}
|
||||
|
||||
object BlockFace {
|
||||
def apply(bp: BlockRef, face: ForgeDirection) = new BlockFace(bp.x, bp.y, bp.z, face)
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* 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.block
|
||||
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import net.minecraft.world.IBlockAccess
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
import scala.reflect.ClassTag
|
||||
|
||||
case class BlockRef(x: Int, y: Int, z: Int) {
|
||||
def block(w: IBlockAccess) = Option(w.getBlock(x, y, z))
|
||||
def tile(w: IBlockAccess) = Option(w.getTileEntity(x, y, z))
|
||||
def meta(w: IBlockAccess) = w.getBlockMetadata(x, y, z)
|
||||
|
||||
def blockIs(w: IBlockAccess, other: Block) = block(w).contains(other)
|
||||
|
||||
def neighbour(side: ForgeDirection) = BlockRef(x + side.offsetX, y + side.offsetY, z + side.offsetZ)
|
||||
def neighbours = ForgeDirection.VALID_DIRECTIONS.map(x => x -> neighbour(x)).toMap
|
||||
|
||||
override def toString = "(x=%d y=%d z=%d)".format(x, y, z)
|
||||
|
||||
def getTile[T: ClassTag](w: IBlockAccess) = tile(w) flatMap { tile =>
|
||||
val cls = implicitly[ClassTag[T]].runtimeClass
|
||||
if (cls.isInstance(tile))
|
||||
Some(tile.asInstanceOf[T])
|
||||
else None
|
||||
}
|
||||
|
||||
def ==(tx: Int, ty: Int, tz: Int) = x == tx && y == ty && z == tz
|
||||
|
||||
def getBlock[T: ClassTag](w: IBlockAccess) = block(w) flatMap { block =>
|
||||
val cls = implicitly[ClassTag[T]].runtimeClass
|
||||
if (cls.isInstance(block))
|
||||
Some(block.asInstanceOf[T])
|
||||
else None
|
||||
}
|
||||
|
||||
def writeToNBT(tag: NBTTagCompound) {
|
||||
tag.setInteger("x", x)
|
||||
tag.setInteger("y", y)
|
||||
tag.setInteger("z", z)
|
||||
}
|
||||
}
|
||||
|
||||
object BlockRef {
|
||||
def fromTile(te: TileEntity) = BlockRef(te.xCoord, te.yCoord, te.zCoord)
|
||||
def fromNBT(tag: NBTTagCompound) =
|
||||
BlockRef(tag.getInteger("x"), tag.getInteger("y"), tag.getInteger("z"))
|
||||
}
|
||||
@@ -4,20 +4,23 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.block
|
||||
|
||||
import net.minecraft.block.{ITileEntityProvider, Block}
|
||||
import net.minecraft.world.{IBlockAccess, World}
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import net.bdew.lib.BdLib
|
||||
import net.minecraft.block.{Block, ITileEntityProvider}
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import net.minecraft.world.{IBlockAccess, World}
|
||||
|
||||
trait HasTE[T] extends Block with ITileEntityProvider {
|
||||
val TEClass: Class[_ <: TileEntity]
|
||||
|
||||
def createNewTileEntity(world: World, meta: Int): TileEntity = TEClass.newInstance()
|
||||
|
||||
def getTE(w: IBlockAccess, ref: BlockRef): T = getTE(w, ref.x, ref.y, ref.z)
|
||||
|
||||
def getTE(w: IBlockAccess, x: Int, y: Int, z: Int): T = {
|
||||
var t = w.getTileEntity(x, y, z)
|
||||
if ((t == null) || !TEClass.isInstance(t)) {
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* 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.block
|
||||
|
||||
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||
import net.bdew.lib.Misc
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.block.material.Material
|
||||
import net.minecraft.client.renderer.texture.IIconRegister
|
||||
|
||||
trait NamedBlock extends Block {
|
||||
def name: String
|
||||
}
|
||||
|
||||
class SimpleBlock(val name: String, material: Material) extends Block(material) with NamedBlock {
|
||||
val modId = Misc.getActiveModId
|
||||
setBlockName(modId + "." + name)
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
override def registerBlockIcons(reg: IIconRegister) {
|
||||
blockIcon = reg.registerIcon(modId + ":" + name.toLowerCase)
|
||||
}
|
||||
}
|
||||
@@ -4,27 +4,26 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.config
|
||||
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.block.Block
|
||||
import cpw.mods.fml.common.registry.GameRegistry
|
||||
import net.bdew.lib.block.HasTE
|
||||
import net.bdew.lib.Misc
|
||||
import net.bdew.lib.block.{HasTE, NamedBlock}
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.creativetab.CreativeTabs
|
||||
import net.minecraft.item.ItemStack
|
||||
|
||||
class BlockManager() {
|
||||
|
||||
def regBlockCls[T <: Block](blockCls: Class[T], name: String, addStack: Boolean = false): T = {
|
||||
val block = blockCls.newInstance()
|
||||
regBlock[T](block, name, addStack)
|
||||
}
|
||||
class BlockManager(creativeTab: CreativeTabs) {
|
||||
def regBlock[T <: NamedBlock](block: T): T = regBlock(block, block.name)
|
||||
|
||||
def regBlock[T <: Block](block: T, name: String, addStack: Boolean = false): T = {
|
||||
GameRegistry.registerBlock(block, name)
|
||||
|
||||
block.setCreativeTab(creativeTab)
|
||||
|
||||
if (addStack)
|
||||
GameRegistry.registerCustomItemStack(name, new ItemStack(block))
|
||||
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.config
|
||||
|
||||
import net.minecraftforge.fluids.{FluidRegistry, Fluid}
|
||||
import net.minecraftforge.fluids.{Fluid, FluidRegistry}
|
||||
|
||||
class FluidManager() {
|
||||
def regFluid[T <: Fluid](fluid: T): T = {
|
||||
|
||||
@@ -4,30 +4,28 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.config
|
||||
|
||||
import net.minecraft.item.{ItemStack, Item}
|
||||
import cpw.mods.fml.common.registry.GameRegistry
|
||||
import net.bdew.lib.items.{NamedItem, SimpleItem}
|
||||
import net.minecraft.creativetab.CreativeTabs
|
||||
import net.minecraft.item.{Item, ItemStack}
|
||||
|
||||
class ItemManager() {
|
||||
class ItemManager(creativeTab: CreativeTabs) {
|
||||
def regSimpleItem(name: String): SimpleItem = regItem(new SimpleItem(name), name)
|
||||
|
||||
def regItem[T <: NamedItem](item: T): T = regItem[T](item, item.name)
|
||||
|
||||
def regItemCls[T <: Item](itemCls: Class[T], name: String, addStack: Boolean = false): T = {
|
||||
val item = itemCls.newInstance()
|
||||
regItem[T](item, name, addStack)
|
||||
}
|
||||
|
||||
def regItem[T <: Item](item: T, name: String, addStack: Boolean = false): T = {
|
||||
GameRegistry.registerItem(item, name)
|
||||
item.setCreativeTab(creativeTab)
|
||||
if (addStack)
|
||||
GameRegistry.registerCustomItemStack(name, new ItemStack(item))
|
||||
return item
|
||||
}
|
||||
|
||||
def load() {}
|
||||
}
|
||||
@@ -4,21 +4,22 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.config
|
||||
|
||||
import net.bdew.lib.recipes.gencfg.ConfigSection
|
||||
import net.bdew.lib.gui.{GuiHandler, GuiProvider}
|
||||
import net.bdew.lib.machine.Machine
|
||||
import net.bdew.lib.gui.{GuiProvider, GuiHandler}
|
||||
import net.bdew.lib.recipes.gencfg.ConfigSection
|
||||
import net.minecraft.creativetab.CreativeTabs
|
||||
|
||||
class MachineManager(val tuning: ConfigSection, guiHandler: GuiHandler) {
|
||||
class MachineManager(val tuning: ConfigSection, guiHandler: GuiHandler, creativeTab: CreativeTabs) {
|
||||
def registerMachine[R <: Machine[_]](machine: R): R = {
|
||||
machine.tuning = tuning.getSection(machine.name)
|
||||
if (machine.tuning.getBoolean("Enabled")) {
|
||||
machine.enabled = true
|
||||
machine.regBlock()
|
||||
machine.regBlock(creativeTab)
|
||||
if (machine.isInstanceOf[GuiProvider])
|
||||
guiHandler.register(machine.asInstanceOf[GuiProvider])
|
||||
}
|
||||
|
||||
@@ -4,25 +4,31 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.covers
|
||||
|
||||
import net.bdew.lib.block.HasTE
|
||||
import net.minecraft.world.{IBlockAccess, World}
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||
import net.bdew.lib.Misc
|
||||
import net.bdew.lib.block.HasTE
|
||||
import net.bdew.lib.items.ItemUtils
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.util.IIcon
|
||||
import net.minecraft.world.{IBlockAccess, World}
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
trait BlockCoverable[T <: TileCoverable] extends HasTE[T] {
|
||||
override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer, face: Int, xoffs: Float, yoffs: Float, zoffs: Float): Boolean = {
|
||||
@SideOnly(Side.CLIENT)
|
||||
override def getRenderType = CoverRenderer.id
|
||||
|
||||
override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer, face: Int, xOffs: Float, yOffs: Float, zOffs: Float): Boolean = {
|
||||
val te = getTE(world, x, y, z)
|
||||
val side = Misc.forgeDirection(face)
|
||||
|
||||
if (player.getCurrentEquippedItem == null && player.isSneaking) {
|
||||
for (cover <- Option(te.covers(side).cval)) {
|
||||
for (cover <- Option(te.covers(side).value)) {
|
||||
if (!world.isRemote) {
|
||||
te.covers(side) := null
|
||||
te.onCoversChanged()
|
||||
@@ -39,7 +45,7 @@ trait BlockCoverable[T <: TileCoverable] extends HasTE[T] {
|
||||
if te.isValidCover(side, activeStack) && coverItem.isValidTile(te, activeStack)
|
||||
} {
|
||||
if (!world.isRemote) {
|
||||
for (cover <- Option(te.covers(side).cval))
|
||||
for (cover <- Option(te.covers(side).value))
|
||||
ItemUtils.throwItemAt(world, te.xCoord + side.offsetX, te.yCoord + side.offsetY, te.zCoord + side.offsetZ, cover.copy())
|
||||
|
||||
te.covers(side) := activeStack.splitStack(1)
|
||||
@@ -50,19 +56,19 @@ trait BlockCoverable[T <: TileCoverable] extends HasTE[T] {
|
||||
return true
|
||||
}
|
||||
|
||||
super.onBlockActivated(world, x, y, z, player, face, xoffs, yoffs, zoffs)
|
||||
super.onBlockActivated(world, x, y, z, player, face, xOffs, yOffs, zOffs)
|
||||
}
|
||||
|
||||
override def getIcon(w: IBlockAccess, x: Int, y: Int, z: Int, side: Int) =
|
||||
(for {
|
||||
coverStack <- Option(getTE(w, x, y, z).covers(Misc.forgeDirection(side)).cval)
|
||||
coverItem <- Option(coverStack.getItem) flatMap (Misc.asInstanceOpt(_, classOf[ItemCover]))
|
||||
def getCoverIcon(w: IBlockAccess, x: Int, y: Int, z: Int, side: ForgeDirection): Option[IIcon] =
|
||||
for {
|
||||
coverStack <- Option(getTE(w, x, y, z).covers(side).value)
|
||||
coverItemMaybe <- Option(coverStack.getItem)
|
||||
coverItem <- Misc.asInstanceOpt(coverItemMaybe, classOf[ItemCover])
|
||||
} yield coverItem.getCoverIcon(coverStack)
|
||||
) getOrElse super.getIcon(w, x, y, z, side)
|
||||
|
||||
override def breakBlock(world: World, x: Int, y: Int, z: Int, block: Block, meta: Int) {
|
||||
if (!world.isRemote)
|
||||
for ((dir, covOpt) <- getTE(world, x, y, z).covers; cover <- Option(covOpt.cval))
|
||||
for ((dir, covOpt) <- getTE(world, x, y, z).covers; cover <- Option(covOpt.value))
|
||||
ItemUtils.throwItemAt(world, x, y, z, cover)
|
||||
super.breakBlock(world, x, y, z, block, meta)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* 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.covers
|
||||
|
||||
import net.bdew.lib.Misc
|
||||
import net.bdew.lib.render.connected.ConnectedHelper
|
||||
import net.bdew.lib.render.{BaseBlockRenderHandler, RenderUtils}
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.client.renderer.RenderBlocks
|
||||
import net.minecraft.world.IBlockAccess
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
object CoverRenderer extends BaseBlockRenderHandler {
|
||||
override def renderInventoryBlock(block: Block, metadata: Int, modelId: Int, renderer: RenderBlocks) =
|
||||
RenderUtils.renderSimpleBlockItem(block, metadata, renderer)
|
||||
|
||||
override def renderWorldBlock(world: IBlockAccess, x: Int, y: Int, z: Int, block: Block, modelId: Int, renderer: RenderBlocks) = {
|
||||
renderer.renderStandardBlock(block, x, y, z)
|
||||
for {
|
||||
blockCov <- Misc.asInstanceOpt(block, classOf[BlockCoverable[_]])
|
||||
face <- ForgeDirection.VALID_DIRECTIONS
|
||||
icon <- blockCov.getCoverIcon(world, x, y, z, face)
|
||||
if block.shouldSideBeRendered(world, x + face.offsetX, y + face.offsetY, z + face.offsetZ, face.ordinal())
|
||||
} ConnectedHelper.draw(face, 8).doDraw(ConnectedHelper.Vec3F(x, y, z), icon)
|
||||
true
|
||||
}
|
||||
}
|
||||
@@ -4,18 +4,18 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.covers
|
||||
|
||||
import net.minecraft.item.{ItemStack, Item}
|
||||
import net.minecraft.item.{Item, ItemStack}
|
||||
import net.minecraft.util.IIcon
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
trait ItemCover extends Item {
|
||||
/**
|
||||
* @return Icon to render, MUST be on terrain spritesheet (0), not item!
|
||||
* @return Icon to render, MUST be on terrain sprite sheet (0), not item!
|
||||
*/
|
||||
def getCoverIcon(stack: ItemStack): IIcon
|
||||
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.covers
|
||||
|
||||
import net.bdew.lib.data.base.{UpdateKind, TileDataSlots}
|
||||
import net.bdew.lib.data.DataSlotItemStack
|
||||
import net.bdew.lib.Misc
|
||||
import net.bdew.lib.data.DataSlotItemStack
|
||||
import net.bdew.lib.data.base.{TileDataSlots, UpdateKind}
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
@@ -33,7 +33,7 @@ trait TileCoverable extends TileDataSlots {
|
||||
def tickCovers() =
|
||||
for {
|
||||
(dir, coverSlot) <- covers
|
||||
coverStack <- Option(coverSlot.cval)
|
||||
coverStack <- Option(coverSlot.value)
|
||||
coverItem <- Option(coverStack.getItem) flatMap (Misc.asInstanceOpt(_, classOf[ItemCover]))
|
||||
} {
|
||||
coverItem.tickCover(this, dir, coverStack)
|
||||
|
||||
@@ -4,16 +4,16 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.data
|
||||
|
||||
import net.bdew.lib.data.base.{DataSlotVal, TileDataSlots, UpdateKind}
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.bdew.lib.data.base.{UpdateKind, TileDataSlots, DataSlotVal}
|
||||
|
||||
case class DataSlotBoolean(name: String, parent: TileDataSlots, default: Boolean = false) extends DataSlotVal[Boolean] {
|
||||
var cval = default
|
||||
def save(t: NBTTagCompound, kind: UpdateKind.Value) = t.setBoolean(name, cval)
|
||||
def load(t: NBTTagCompound, kind: UpdateKind.Value) = cval = t.getBoolean(name)
|
||||
var value = default
|
||||
def save(t: NBTTagCompound, kind: UpdateKind.Value) = t.setBoolean(name, value)
|
||||
def load(t: NBTTagCompound, kind: UpdateKind.Value) = value = t.getBoolean(name)
|
||||
}
|
||||
@@ -4,17 +4,17 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.data
|
||||
|
||||
import net.bdew.lib.data.base.{TileDataSlots, UpdateKind, DataSlotVal}
|
||||
import net.bdew.lib.data.base.{DataSlotVal, TileDataSlots, UpdateKind}
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
case class DataSlotDirection(name: String, parent: TileDataSlots) extends DataSlotVal[ForgeDirection] {
|
||||
var cval = ForgeDirection.UP
|
||||
def save(t: NBTTagCompound, kind: UpdateKind.Value) = t.setByte(name, cval.ordinal().toByte)
|
||||
def load(t: NBTTagCompound, kind: UpdateKind.Value) = cval = ForgeDirection.getOrientation(t.getByte(name))
|
||||
var value = ForgeDirection.UP
|
||||
def save(t: NBTTagCompound, kind: UpdateKind.Value) = t.setByte(name, value.ordinal().toByte)
|
||||
def load(t: NBTTagCompound, kind: UpdateKind.Value) = value = ForgeDirection.getOrientation(t.getByte(name))
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* 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.data
|
||||
|
||||
import net.bdew.lib.data.base.{DataSlotNumeric, TileDataSlots, UpdateKind}
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
case class DataSlotDouble(name: String, parent: TileDataSlots, default: Double = 0) extends DataSlotNumeric[Double](default) {
|
||||
def save(t: NBTTagCompound, kind: UpdateKind.Value) = t.setDouble(name, value)
|
||||
def load(t: NBTTagCompound, kind: UpdateKind.Value) = value = t.getDouble(name)
|
||||
}
|
||||
@@ -4,15 +4,15 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.data
|
||||
|
||||
import net.bdew.lib.data.base.{DataSlotNumeric, TileDataSlots, UpdateKind}
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.bdew.lib.data.base.{UpdateKind, TileDataSlots, DataSlotNumeric}
|
||||
|
||||
case class DataSlotFloat(name: String, parent: TileDataSlots, default: Float = 0) extends DataSlotNumeric[Float](default) {
|
||||
def save(t: NBTTagCompound, kind: UpdateKind.Value) = t.setFloat(name, cval)
|
||||
def load(t: NBTTagCompound, kind: UpdateKind.Value) = cval = t.getFloat(name)
|
||||
def save(t: NBTTagCompound, kind: UpdateKind.Value) = t.setFloat(name, value)
|
||||
def load(t: NBTTagCompound, kind: UpdateKind.Value) = value = t.getFloat(name)
|
||||
}
|
||||
@@ -1,3 +1,12 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* 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.data
|
||||
|
||||
import java.util.UUID
|
||||
@@ -8,20 +17,20 @@ import net.minecraft.nbt.NBTTagCompound
|
||||
import org.apache.commons.lang3.StringUtils
|
||||
|
||||
case class DataSlotGameProfile(name: String, parent: TileDataSlots) extends DataSlotVal[GameProfile] {
|
||||
override var cval: GameProfile = null
|
||||
override var value: GameProfile = null
|
||||
|
||||
override def load(t: NBTTagCompound, kind: UpdateKind.Value) = {
|
||||
cval = if (t.hasKey(name + "_uid") || t.hasKey(name + "_name")) {
|
||||
val uid = if (t.hasKey(name + "_uid")) UUID.fromString(t.getString(name + "_uid")) else null
|
||||
val uname = if (t.hasKey(name + "_name")) t.getString(name + "_name") else null
|
||||
new GameProfile(uid, uname)
|
||||
value = if (t.hasKey(name + "_uid") || t.hasKey(name + "_name")) {
|
||||
val uId = if (t.hasKey(name + "_uid")) UUID.fromString(t.getString(name + "_uid")) else null
|
||||
val uName = if (t.hasKey(name + "_name")) t.getString(name + "_name") else null
|
||||
new GameProfile(uId, uName)
|
||||
} else null
|
||||
}
|
||||
|
||||
override def save(t: NBTTagCompound, kind: UpdateKind.Value) = {
|
||||
if (cval != null) {
|
||||
Option(cval.getId) map (id => t.setString(name + "_uid", id.toString))
|
||||
Option(cval.getName) filterNot (name => StringUtils.isBlank(name)) map (name => t.setString(name + "_name", name))
|
||||
if (value != null) {
|
||||
Option(value.getId) map (id => t.setString(name + "_uid", id.toString))
|
||||
Option(value.getName) filterNot (name => StringUtils.isBlank(name)) map (name => t.setString(name + "_name", name))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,15 +4,15 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.data
|
||||
|
||||
import net.bdew.lib.data.base.{DataSlotNumeric, TileDataSlots, UpdateKind}
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.bdew.lib.data.base.{UpdateKind, TileDataSlots, DataSlotNumeric}
|
||||
|
||||
case class DataSlotInt(name: String, parent: TileDataSlots, default: Int = 0) extends DataSlotNumeric[Int](default) {
|
||||
def save(t: NBTTagCompound, kind: UpdateKind.Value) = t.setInteger(name, cval)
|
||||
def load(t: NBTTagCompound, kind: UpdateKind.Value) = cval = t.getInteger(name)
|
||||
def save(t: NBTTagCompound, kind: UpdateKind.Value) = t.setInteger(name, value)
|
||||
def load(t: NBTTagCompound, kind: UpdateKind.Value) = value = t.getInteger(name)
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* 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.data
|
||||
|
||||
import net.bdew.lib.Misc
|
||||
import net.bdew.lib.data.base.{DataSlot, TileDataSlots, UpdateKind}
|
||||
import net.bdew.lib.tile.inventory.BaseInventory
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.{NBTTagCompound, NBTTagList}
|
||||
|
||||
case class DataSlotInventory(name: String, parent: TileDataSlots, size: Int) extends DataSlot with BaseInventory {
|
||||
setUpdate(UpdateKind.SAVE)
|
||||
|
||||
override def getSizeInventory = size
|
||||
override def markDirty() = parent.dataSlotChanged(this)
|
||||
|
||||
override def load(t: NBTTagCompound, kind: UpdateKind.Value) {
|
||||
inv = new Array[ItemStack](getSizeInventory)
|
||||
for (nbtItem <- Misc.iterNbtCompoundList(t, name)) {
|
||||
val slot = nbtItem.getByte("Slot")
|
||||
if (slot >= 0 && slot < inv.size) {
|
||||
inv(slot) = ItemStack.loadItemStackFromNBT(nbtItem)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override def save(t: NBTTagCompound, kind: UpdateKind.Value) {
|
||||
val itemList = new NBTTagList
|
||||
for ((item, i) <- inv.view.zipWithIndex if item != null) {
|
||||
val itemNbt: NBTTagCompound = new NBTTagCompound
|
||||
itemNbt.setByte("Slot", i.asInstanceOf[Byte])
|
||||
item.writeToNBT(itemNbt)
|
||||
itemList.appendTag(itemNbt)
|
||||
}
|
||||
t.setTag(name, itemList)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,29 +4,29 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.data
|
||||
|
||||
import net.bdew.lib.data.base.{TileDataSlots, UpdateKind, DataSlotVal}
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.bdew.lib.data.base.{DataSlotVal, TileDataSlots, UpdateKind}
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
case class DataSlotItemStack(name: String, parent: TileDataSlots) extends DataSlotVal[ItemStack] {
|
||||
var cval: ItemStack = null
|
||||
var value: ItemStack = null
|
||||
|
||||
override def update(v: ItemStack) = {
|
||||
if (!ItemStack.areItemStacksEqual(v, cval)) {
|
||||
cval = if (v == null) null else v.copy()
|
||||
if (!ItemStack.areItemStacksEqual(v, value)) {
|
||||
value = if (v == null) null else v.copy()
|
||||
parent.dataSlotChanged(this)
|
||||
}
|
||||
}
|
||||
|
||||
def save(t: NBTTagCompound, kind: UpdateKind.Value) = {
|
||||
val tag = new NBTTagCompound()
|
||||
if (cval != null) cval.writeToNBT(tag)
|
||||
if (value != null) value.writeToNBT(tag)
|
||||
t.setTag(name, tag)
|
||||
}
|
||||
def load(t: NBTTagCompound, kind: UpdateKind.Value) = cval = ItemStack.loadItemStackFromNBT(t.getCompoundTag(name))
|
||||
def load(t: NBTTagCompound, kind: UpdateKind.Value) = value = ItemStack.loadItemStackFromNBT(t.getCompoundTag(name))
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* 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.data
|
||||
|
||||
import net.bdew.lib.data.base.DataSlotVal
|
||||
|
||||
abstract class DataSlotOption[T] extends DataSlotVal[Option[T]] {
|
||||
override var value: Option[T] = None
|
||||
|
||||
def set(v: T) {
|
||||
if (v == null) sys.error("Null should never be used with DataSlotOption")
|
||||
value = Some(v)
|
||||
}
|
||||
|
||||
def unset() {
|
||||
value = None
|
||||
}
|
||||
|
||||
override def isSame(v: Option[T]) = {
|
||||
if (v == null) sys.error("Null should never be used with DataSlotOption")
|
||||
super.isSame(v)
|
||||
}
|
||||
override def :=(that: Option[T]) = {
|
||||
if (that == null) sys.error("Null should never be used with DataSlotOption")
|
||||
super.:=(that)
|
||||
}
|
||||
override def :!=(that: Option[T]) = {
|
||||
if (that == null) sys.error("Null should never be used with DataSlotOption")
|
||||
super.:!=(that)
|
||||
}
|
||||
override def :==(that: Option[T]) = {
|
||||
if (that == null) sys.error("Null should never be used with DataSlotOption")
|
||||
super.:==(that)
|
||||
}
|
||||
override def update(v: Option[T]) = {
|
||||
if (v == null) sys.error("Null should never be used with DataSlotOption")
|
||||
super.update(v)
|
||||
}
|
||||
}
|
||||
@@ -4,16 +4,16 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.data
|
||||
|
||||
import net.bdew.lib.data.base.{DataSlotVal, TileDataSlots, UpdateKind}
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.bdew.lib.data.base.{UpdateKind, TileDataSlots, DataSlotVal}
|
||||
|
||||
case class DataSlotString(name: String, parent: TileDataSlots, default: String = null) extends DataSlotVal[String] {
|
||||
var cval: String = default
|
||||
def save(t: NBTTagCompound, kind: UpdateKind.Value) = if (cval != null) t.setString(name, cval)
|
||||
def load(t: NBTTagCompound, kind: UpdateKind.Value) = cval = if (t.hasKey(name)) t.getString(name) else null
|
||||
var value: String = default
|
||||
def save(t: NBTTagCompound, kind: UpdateKind.Value) = if (value != null) t.setString(name, value)
|
||||
def load(t: NBTTagCompound, kind: UpdateKind.Value) = value = if (t.hasKey(name)) t.getString(name) else null
|
||||
}
|
||||
@@ -4,14 +4,14 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.data
|
||||
|
||||
import net.minecraftforge.fluids.{IFluidTank, FluidTank, FluidStack}
|
||||
import net.bdew.lib.data.base.{DataSlot, TileDataSlots, UpdateKind}
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.bdew.lib.data.base.{UpdateKind, TileDataSlots, DataSlot}
|
||||
import net.minecraftforge.fluids.{FluidStack, FluidTank, IFluidTank}
|
||||
|
||||
abstract class DataSlotTankBase(sz: Int) extends FluidTank(sz) with IFluidTank with DataSlot {
|
||||
var oldStack: FluidStack = null
|
||||
@@ -20,6 +20,8 @@ abstract class DataSlotTankBase(sz: Int) extends FluidTank(sz) with IFluidTank w
|
||||
|
||||
updateKind = Set(UpdateKind.GUI, UpdateKind.SAVE)
|
||||
|
||||
val sendCapacityOnUpdateKind = Set(UpdateKind.GUI)
|
||||
|
||||
def checkUpdate() {
|
||||
if (!isSame(oldStack, fluid)) {
|
||||
oldStack = if (fluid == null) null else fluid.copy()
|
||||
@@ -36,7 +38,7 @@ abstract class DataSlotTankBase(sz: Int) extends FluidTank(sz) with IFluidTank w
|
||||
def save(t: NBTTagCompound, k: UpdateKind.Value) {
|
||||
val tag = new NBTTagCompound()
|
||||
writeToNBT(tag)
|
||||
if (k == UpdateKind.GUI)
|
||||
if (sendCapacityOnUpdateKind.contains(k))
|
||||
tag.setInteger("size", getCapacity)
|
||||
t.setTag(name, tag)
|
||||
}
|
||||
@@ -45,9 +47,22 @@ abstract class DataSlotTankBase(sz: Int) extends FluidTank(sz) with IFluidTank w
|
||||
setFluid(null)
|
||||
val tag = t.getCompoundTag(name)
|
||||
readFromNBT(tag)
|
||||
if (k == UpdateKind.GUI)
|
||||
if (sendCapacityOnUpdateKind.contains(k))
|
||||
setCapacity(tag.getInteger("size"))
|
||||
}
|
||||
override def setFluid(fluid: FluidStack) = execWithChangeNotify(super.setFluid(fluid))
|
||||
override def setCapacity(capacity: Int) = execWithChangeNotify(super.setCapacity(capacity))
|
||||
override def drain(maxDrain: Int, doDrain: Boolean) =
|
||||
if (doDrain)
|
||||
execWithChangeNotify(super.drain(maxDrain, true))
|
||||
else
|
||||
super.drain(maxDrain, false)
|
||||
|
||||
override def fill(resource: FluidStack, doFill: Boolean) =
|
||||
if (doFill)
|
||||
execWithChangeNotify(super.fill(resource, true))
|
||||
else
|
||||
super.fill(resource, false)
|
||||
}
|
||||
|
||||
case class DataSlotTank(name: String, parent: TileDataSlots, size: Int) extends DataSlotTankBase(size)
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.data.base
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP
|
||||
import net.bdew.lib.gui.NoInvContainer
|
||||
import net.minecraft.entity.player.EntityPlayerMP
|
||||
import net.minecraft.inventory.ICrafting
|
||||
|
||||
trait ContainerDataSlots extends NoInvContainer {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.data.base
|
||||
@@ -35,6 +35,12 @@ trait DataSlot {
|
||||
def save(t: NBTTagCompound, kind: UpdateKind.Value)
|
||||
def load(t: NBTTagCompound, kind: UpdateKind.Value)
|
||||
|
||||
def execWithChangeNotify[T](f: => T): T = {
|
||||
val v = f
|
||||
parent.dataSlotChanged(this)
|
||||
v
|
||||
}
|
||||
|
||||
def setUpdate(vals: UpdateKind.Value*): this.type = {
|
||||
updateKind = vals.toSet
|
||||
return this
|
||||
|
||||
@@ -4,19 +4,19 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.data.base
|
||||
|
||||
/**
|
||||
* Base class for data slots that hold numeric values
|
||||
* adds convinience operators to modify the value
|
||||
* adds convenience operators to modify the value
|
||||
*/
|
||||
|
||||
abstract class DataSlotNumeric[T](default: T)(implicit n: Numeric[T]) extends DataSlotVal[T] {
|
||||
var cval = default
|
||||
def +=(that: T) = update(n.plus(cval, that))
|
||||
def -=(that: T) = update(n.minus(cval, that))
|
||||
def *=(that: T) = update(n.times(cval, that))
|
||||
var value = default
|
||||
def +=(that: T) = update(n.plus(value, that))
|
||||
def -=(that: T) = update(n.minus(value, that))
|
||||
def *=(that: T) = update(n.times(value, that))
|
||||
}
|
||||
@@ -4,18 +4,18 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.data.base
|
||||
|
||||
/**
|
||||
* Base class for data slots that hold values with ordering operators, adds more convinience operators
|
||||
* Base class for data slots that hold values with ordering operators, adds more convenience operators
|
||||
* TODO: Do i need this? normal operators can be used with the implicit conversion
|
||||
*/
|
||||
abstract class DataSlotOrdered[T](implicit n: Ordering[T]) extends DataSlotVal[T] {
|
||||
def :>(that: T) = n.compare(cval, that) > 0
|
||||
def :<(that: T) = n.compare(cval, that) < 0
|
||||
def :>=(that: T) = n.compare(cval, that) >= 0
|
||||
def :<=(that: T) = n.compare(cval, that) <= 0
|
||||
def :>(that: T) = n.compare(value, that) > 0
|
||||
def :<(that: T) = n.compare(value, that) < 0
|
||||
def :>=(that: T) = n.compare(value, that) >= 0
|
||||
def :<=(that: T) = n.compare(value, that) <= 0
|
||||
}
|
||||
@@ -4,36 +4,36 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.data.base
|
||||
|
||||
import language.implicitConversions
|
||||
import scala.language.implicitConversions
|
||||
|
||||
/**
|
||||
* Base trait for data slots that hold primitive values
|
||||
* Defines some convinience operators to access the value and an implicit conversion to the value
|
||||
* Defines some convenience operators to access the value and an implicit conversion to the value
|
||||
*/
|
||||
|
||||
trait DataSlotVal[T] extends DataSlot {
|
||||
var cval: T
|
||||
var value: T
|
||||
|
||||
def isSame(v: T) = v == cval
|
||||
def isSame(v: T) = v == value
|
||||
|
||||
def :=(that: T) = update(that)
|
||||
|
||||
def :!=(that: T) = cval != that
|
||||
def :==(that: T) = cval == that
|
||||
def :!=(that: T) = value != that
|
||||
def :==(that: T) = value == that
|
||||
|
||||
def update(v: T) {
|
||||
if (!isSame(v)) {
|
||||
cval = v
|
||||
value = v
|
||||
parent.dataSlotChanged(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object DataSlotVal {
|
||||
implicit def slot2val[T](slot: DataSlotVal[T]): T = slot.cval
|
||||
implicit def slot2val[T](slot: DataSlotVal[T]): T = slot.value
|
||||
}
|
||||
@@ -4,16 +4,17 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.data.base
|
||||
|
||||
import scala.collection.mutable
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.bdew.lib.tile.TileExtended
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraft.network.Packet
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity
|
||||
|
||||
import scala.collection.mutable
|
||||
|
||||
trait TileDataSlots extends TileExtended {
|
||||
val dataSlots = mutable.HashMap.empty[String, DataSlot]
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.data.base
|
||||
|
||||
@@ -4,15 +4,15 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.gui
|
||||
|
||||
import net.minecraft.inventory.IInventory
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.bdew.lib.items.ItemUtils
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.inventory.IInventory
|
||||
import net.minecraft.item.ItemStack
|
||||
|
||||
abstract class BaseContainer(te: IInventory) extends NoInvContainer {
|
||||
override def transferStackInSlot(player: EntityPlayer, slot: Int): ItemStack = {
|
||||
@@ -28,5 +28,7 @@ abstract class BaseContainer(te: IInventory) extends NoInvContainer {
|
||||
getSlot(slot).putStack(stack)
|
||||
return null
|
||||
}
|
||||
|
||||
override def canInteractWith(player: EntityPlayer) = te.isUseableByPlayer(player)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.gui
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.gui
|
||||
|
||||
@@ -4,17 +4,18 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.gui
|
||||
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.gui.inventory.GuiContainer
|
||||
import net.minecraft.inventory.Container
|
||||
import scala.collection.mutable
|
||||
import net.minecraft.client.Minecraft
|
||||
import org.lwjgl.opengl.GL11
|
||||
|
||||
import scala.collection.mutable
|
||||
|
||||
abstract class BaseScreen(cont: Container, xSz: Int, ySz: Int) extends GuiContainer(cont) {
|
||||
xSize = xSz
|
||||
ySize = ySz
|
||||
@@ -53,7 +54,7 @@ abstract class BaseScreen(cont: Container, xSz: Int, ySz: Int) extends GuiContai
|
||||
|
||||
widgets.handleTooltip(Point(x, y) - rect.origin, tip)
|
||||
|
||||
import collection.JavaConversions._
|
||||
import scala.collection.JavaConversions._
|
||||
|
||||
if (tip.size > 0)
|
||||
drawHoveringText(tip, x, y, getFontRenderer)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.gui
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.gui
|
||||
|
||||
import org.lwjgl.opengl.GL11
|
||||
import net.bdew.lib.Misc
|
||||
import org.lwjgl.opengl.GL11
|
||||
|
||||
case class Color(r: Float, g: Float, b: Float, a: Float = 1) {
|
||||
def this(c: (Float, Float, Float)) = this(c._1, c._2, c._3)
|
||||
@@ -44,6 +44,6 @@ object Color {
|
||||
final val magenta = Color(1, 0, 1)
|
||||
|
||||
final val gray = Color(0.5F, 0.5F, 0.5F)
|
||||
final val lightgray = Color(0.75F, 0.75F, 0.75F)
|
||||
final val darkgray = Color(0.25F, 0.25F, 0.25F)
|
||||
final val lightGray = Color(0.75F, 0.75F, 0.75F)
|
||||
final val darkGray = Color(0.25F, 0.25F, 0.25F)
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.gui
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.gui
|
||||
|
||||
import net.minecraft.client.renderer.Tessellator
|
||||
import net.minecraft.client.gui.FontRenderer
|
||||
import net.minecraft.client.renderer.Tessellator
|
||||
|
||||
trait DrawTarget {
|
||||
def getZLevel: Float
|
||||
@@ -20,7 +20,7 @@ trait DrawTarget {
|
||||
def drawTextMultiline(text: String, r: Rect, color: Color)
|
||||
|
||||
def drawTextureInterpolate(r: Rect, t: Texture, x1: Float, y1: Float, x2: Float, y2: Float, color: Color = Color.white) =
|
||||
drawTexture(r.interpolate(x1, y1, x2, y2), Texture.interpolate(t, x1, y1, x2, y2))
|
||||
drawTexture(r.interpolate(x1, y1, x2, y2), Texture.interpolate(t, x1, y1, x2, y2), color)
|
||||
}
|
||||
|
||||
trait SimpleDrawTarget extends DrawTarget {
|
||||
|
||||
@@ -4,28 +4,29 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.gui
|
||||
|
||||
import cpw.mods.fml.common.network.IGuiHandler
|
||||
import scala.collection.mutable
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.world.World
|
||||
|
||||
import scala.collection.mutable
|
||||
|
||||
class GuiHandler extends IGuiHandler {
|
||||
val guis = mutable.Map.empty[Int, GuiProvider]
|
||||
val GUIs = mutable.Map.empty[Int, GuiProvider]
|
||||
|
||||
def register(p: GuiProvider) = {
|
||||
if (guis.isDefinedAt(p.guiId))
|
||||
sys.error("GUI ID Collision - %d was registered for %s and attemted to register by %s".format(p.guiId, guis(p.guiId), p))
|
||||
guis += (p.guiId -> p)
|
||||
if (GUIs.isDefinedAt(p.guiId))
|
||||
sys.error("GUI ID Collision - %d was registered for %s and attempted to register by %s".format(p.guiId, GUIs(p.guiId), p))
|
||||
GUIs += (p.guiId -> p)
|
||||
}
|
||||
|
||||
def getServerGuiElement(ID: Int, player: EntityPlayer, world: World, x: Int, y: Int, z: Int): AnyRef =
|
||||
guis(ID).getContainer(world.getTileEntity(x, y, z), player)
|
||||
GUIs(ID).getContainer(world.getTileEntity(x, y, z), player)
|
||||
|
||||
def getClientGuiElement(ID: Int, player: EntityPlayer, world: World, x: Int, y: Int, z: Int): AnyRef =
|
||||
guis(ID).getGui(world.getTileEntity(x, y, z), player)
|
||||
GUIs(ID).getGui(world.getTileEntity(x, y, z), player)
|
||||
}
|
||||
@@ -4,14 +4,14 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.gui
|
||||
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
|
||||
trait GuiProvider {
|
||||
def guiId: Int
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.gui
|
||||
|
||||
import net.minecraft.inventory.{Slot, Container}
|
||||
import net.bdew.lib.Misc
|
||||
import net.minecraft.entity.player.{EntityPlayer, InventoryPlayer, EntityPlayerMP}
|
||||
import net.minecraft.entity.player.{EntityPlayer, EntityPlayerMP, InventoryPlayer}
|
||||
import net.minecraft.inventory.{Container, Slot}
|
||||
import net.minecraft.item.ItemStack
|
||||
|
||||
abstract class NoInvContainer extends Container {
|
||||
@@ -28,13 +28,13 @@ abstract class NoInvContainer extends Container {
|
||||
addSlotToContainer(new Slot(inv, i, xOffs + i * 18, yOffsHotbar))
|
||||
}
|
||||
|
||||
override def slotClick(slotnum: Int, button: Int, modifiers: Int, player: EntityPlayer): ItemStack = {
|
||||
if (inventorySlots.isDefinedAt(slotnum)) {
|
||||
val slot = getSlot(slotnum)
|
||||
override def slotClick(slotNum: Int, button: Int, modifiers: Int, player: EntityPlayer): ItemStack = {
|
||||
if (inventorySlots.isDefinedAt(slotNum)) {
|
||||
val slot = getSlot(slotNum)
|
||||
if (slot != null && slot.isInstanceOf[SlotClickable])
|
||||
return slot.asInstanceOf[SlotClickable].onClick(button, modifiers, player)
|
||||
}
|
||||
return super.slotClick(slotnum, button, modifiers, player)
|
||||
return super.slotClick(slotNum, button, modifiers, player)
|
||||
}
|
||||
|
||||
override def transferStackInSlot(player: EntityPlayer, slot: Int): ItemStack = null
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.gui
|
||||
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.inventory.Slot
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.inventory.Slot
|
||||
import net.minecraft.item.ItemStack
|
||||
|
||||
trait SlotClickable extends Slot {
|
||||
def onClick(button: Int, mods: Int, player: EntityPlayer): ItemStack
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.gui
|
||||
|
||||
@@ -4,14 +4,15 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.gui
|
||||
|
||||
import net.minecraft.util.{IIcon, ResourceLocation}
|
||||
import net.bdew.lib.Client
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.renderer.texture.TextureMap
|
||||
import net.minecraft.util.{IIcon, ResourceLocation}
|
||||
|
||||
trait Texture {
|
||||
def u1: Float
|
||||
@@ -29,7 +30,13 @@ class InterpolatedTexture(val texture: Texture, rect: Rect) extends Texture {
|
||||
def v2 = rect.y2 * (texture.v2 - texture.v1) + texture.v1
|
||||
}
|
||||
|
||||
class IconWrapper(val resource: ResourceLocation, val icon: IIcon) extends Texture {
|
||||
class IconWrapper(val resource: ResourceLocation, aIcon: IIcon) extends Texture {
|
||||
val icon = if (aIcon == null) {
|
||||
if (resource == Texture.ITEMS) Client.itemMissingIcon
|
||||
else if (resource == Texture.BLOCKS) Client.blockMissingIcon
|
||||
else sys.error("Attempt to create IconWrapper for null IIcon")
|
||||
} else aIcon
|
||||
|
||||
def u1 = icon.getMinU
|
||||
def u2 = icon.getMaxU
|
||||
def v1 = icon.getMinV
|
||||
|
||||
@@ -4,16 +4,17 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.gui
|
||||
|
||||
import scala.collection.mutable
|
||||
import net.bdew.lib.gui.widgets.BaseWidget
|
||||
import net.minecraft.client.gui.FontRenderer
|
||||
import org.lwjgl.opengl.GL11
|
||||
|
||||
import scala.collection.mutable
|
||||
|
||||
trait WidgetContainer extends DrawTarget {
|
||||
val rect: Rect
|
||||
val widgets = mutable.MutableList.empty[BaseWidget]
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib
|
||||
@@ -13,15 +13,19 @@ package object gui {
|
||||
type Rect = BaseRect[Float]
|
||||
type Point = BasePoint[Float]
|
||||
|
||||
import language.implicitConversions
|
||||
import scala.language.implicitConversions
|
||||
|
||||
implicit def awt2point(p: java.awt.Point) = BasePoint(p.x, p.y)
|
||||
implicit def awt2point(p: java.awt.Point): BasePoint[Int] = BasePoint(p.x, p.y)
|
||||
implicit def point2awt(p: BasePoint[Int]): java.awt.Point = new java.awt.Point(p.x, p.y)
|
||||
implicit def tuple2point[T: Numeric](p: (T, T)) = BasePoint(p._1, p._2)
|
||||
implicit def tuple2point[T: Numeric](p: (T, T)): BasePoint[T] = BasePoint(p._1, p._2)
|
||||
|
||||
// Converts different kinds of Point/Rect as long as there's an implicit for the underlying type
|
||||
implicit def pointconvert[T, R](a: BasePoint[R])(implicit f: R => T, n: Numeric[T]) = BasePoint[T](f(a.x), f(a.y))
|
||||
implicit def rectconvert[T, R](a: BaseRect[R])(implicit f: R => T, n: Numeric[T]) = BaseRect[T](f(a.x), f(a.y), f(a.w), f(a.h))
|
||||
|
||||
implicit def pointConvert[T, R](a: BasePoint[R])(implicit f: R => T, n: Numeric[T]): BasePoint[T] =
|
||||
BasePoint[T](f(a.x), f(a.y))
|
||||
|
||||
implicit def rectConvert[T, R](a: BaseRect[R])(implicit f: R => T, n: Numeric[T]): BaseRect[T] =
|
||||
BaseRect[T](f(a.x), f(a.y), f(a.w), f(a.h))
|
||||
|
||||
def Rect(x: Float, y: Float, w: Float, h: Float) = BaseRect(x, y, w, h)
|
||||
def Point(x: Float, y: Float) = BasePoint(x, y)
|
||||
|
||||
@@ -4,13 +4,14 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.gui.widgets
|
||||
|
||||
import net.bdew.lib.gui.{Point, Rect, WidgetContainer}
|
||||
|
||||
import scala.collection.mutable
|
||||
import net.bdew.lib.gui.{WidgetContainer, Point, Rect}
|
||||
|
||||
trait BaseWidget {
|
||||
val rect: Rect
|
||||
|
||||
@@ -4,15 +4,15 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.gui.widgets
|
||||
|
||||
import net.minecraft.client.gui.GuiButton
|
||||
import net.bdew.lib.gui.{Point, Rect}
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.audio.PositionedSoundRecord
|
||||
import net.minecraft.client.gui.GuiButton
|
||||
import net.minecraft.util.ResourceLocation
|
||||
|
||||
class WidgetButton(val rect: Rect, text: String, clicked: WidgetButton => Unit)
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* 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.gui.widgets
|
||||
|
||||
import net.bdew.lib.gui.{Point, Rect, Texture}
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.audio.PositionedSoundRecord
|
||||
import net.minecraft.util.ResourceLocation
|
||||
|
||||
import scala.collection.mutable
|
||||
|
||||
class WidgetButtonIcon(p: Point, clicked: WidgetButtonIcon => Unit, baseTex: Texture, hoverTex: Texture) extends Widget {
|
||||
val rect = new Rect(p, 16, 16)
|
||||
val iconRect = new Rect(p +(1, 1), 14, 14)
|
||||
|
||||
var icon: Texture = null
|
||||
var hover: String = null
|
||||
|
||||
override def draw(mouse: Point) {
|
||||
if (rect.contains(mouse))
|
||||
parent.drawTexture(rect, hoverTex)
|
||||
else
|
||||
parent.drawTexture(rect, baseTex)
|
||||
|
||||
if (icon != null)
|
||||
parent.drawTexture(iconRect, icon)
|
||||
}
|
||||
|
||||
override def handleTooltip(p: Point, tip: mutable.MutableList[String]) {
|
||||
if (hover != null && hover > "")
|
||||
tip += hover
|
||||
}
|
||||
|
||||
override def mouseClicked(p: Point, button: Int) {
|
||||
Minecraft.getMinecraft.getSoundHandler.playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F))
|
||||
clicked(this)
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.gui.widgets
|
||||
|
||||
@@ -4,20 +4,20 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.gui.widgets
|
||||
|
||||
import net.bdew.lib.gui._
|
||||
import net.bdew.lib.data.base.DataSlotNumeric
|
||||
import net.bdew.lib.gui._
|
||||
|
||||
class WidgetFillDataslot[T](val rect: Rect, val texture: Texture, dir: Direction.Direction, dslot: DataSlotNumeric[T], maxval: T)(implicit num: Numeric[T]) extends Widget {
|
||||
class WidgetFillDataSlot[T](val rect: Rect, val texture: Texture, dir: Direction.Direction, dSlot: DataSlotNumeric[T], maxVal: T)(implicit num: Numeric[T]) extends Widget {
|
||||
|
||||
import num.mkNumericOps
|
||||
|
||||
override def draw(mouse: Point) {
|
||||
val fill = dslot.cval.toFloat() / maxval.toFloat()
|
||||
val fill = dSlot.value.toFloat() / maxVal.toFloat()
|
||||
dir match {
|
||||
case Direction.UP =>
|
||||
parent.drawTextureInterpolate(rect, texture, 0, 1 - fill, 1, 1)
|
||||
|
||||
@@ -4,25 +4,23 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.gui.widgets
|
||||
|
||||
import net.bdew.lib.gui.{Texture, Point, Rect}
|
||||
import net.bdew.lib.data.DataSlotTankBase
|
||||
import scala.collection.mutable
|
||||
import java.text.DecimalFormat
|
||||
import net.bdew.lib.Misc
|
||||
import net.bdew.lib.gui.{Color, Point, Rect, Texture}
|
||||
import net.bdew.lib.{DecFormat, Misc}
|
||||
import org.lwjgl.opengl.GL11
|
||||
|
||||
class WidgetFluidGauge(val rect: Rect, overlay: Texture, dslot: DataSlotTankBase) extends Widget {
|
||||
val formater = new DecimalFormat("#,###")
|
||||
import scala.collection.mutable
|
||||
|
||||
class WidgetFluidGauge(val rect: Rect, overlay: Texture, dSlot: DataSlotTankBase) extends Widget {
|
||||
override def handleTooltip(p: Point, tip: mutable.MutableList[String]) {
|
||||
if (dslot.getFluid != null) {
|
||||
tip += dslot.getFluid.getFluid.getLocalizedName(dslot.getFluid)
|
||||
tip += "%s/%s mB".format(formater.format(dslot.getFluidAmount), formater.format(dslot.getCapacity))
|
||||
if (dSlot.getFluid != null) {
|
||||
tip += dSlot.getFluid.getFluid.getLocalizedName(dSlot.getFluid)
|
||||
tip += "%s/%s mB".format(DecFormat.round(dSlot.getFluidAmount), DecFormat.round(dSlot.getCapacity))
|
||||
} else {
|
||||
tip += Misc.toLocal("bdlib.label.empty")
|
||||
}
|
||||
@@ -32,26 +30,29 @@ class WidgetFluidGauge(val rect: Rect, overlay: Texture, dslot: DataSlotTankBase
|
||||
GL11.glEnable(GL11.GL_BLEND)
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA)
|
||||
|
||||
val fstack = dslot.getFluid
|
||||
if (fstack != null && fstack.getFluid.getStillIcon != null) {
|
||||
val icon = Texture(Texture.BLOCKS, fstack.getFluid.getStillIcon)
|
||||
var fillHeight = if (dslot.getCapacity > 0) rect.h * fstack.amount / dslot.getCapacity else 0
|
||||
val fStack = dSlot.getFluid
|
||||
if (fStack != null) {
|
||||
val color = Color.fromInt(Misc.getFluidColor(fStack))
|
||||
val icon = Texture(Texture.BLOCKS, Misc.getFluidIcon(fStack))
|
||||
var fillHeight = if (dSlot.getCapacity > 0) rect.h * fStack.amount / dSlot.getCapacity else 0
|
||||
var yStart: Int = 0
|
||||
|
||||
while (fillHeight > 0) {
|
||||
if (fillHeight > 16) {
|
||||
parent.drawTexture(new Rect(rect.x, rect.y2 - 16 - yStart, rect.w, 16), icon)
|
||||
parent.drawTexture(new Rect(rect.x, rect.y2 - 16 - yStart, rect.w, 16), icon, color)
|
||||
fillHeight -= 16
|
||||
} else {
|
||||
parent.drawTextureInterpolate(new Rect(rect.x, rect.y2 - 16 - yStart, rect.w, 16), icon, 0, 1 - fillHeight / 16, 1, 1)
|
||||
parent.drawTextureInterpolate(new Rect(rect.x, rect.y2 - 16 - yStart, rect.w, 16), icon, 0, 1 - fillHeight / 16, 1, 1, color)
|
||||
fillHeight = 0
|
||||
}
|
||||
yStart = yStart + 16
|
||||
}
|
||||
}
|
||||
|
||||
GL11.glColor3d(1, 1, 1)
|
||||
GL11.glDisable(GL11.GL_BLEND)
|
||||
|
||||
parent.drawTexture(rect, overlay)
|
||||
if (overlay != null)
|
||||
parent.drawTexture(rect, overlay)
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.gui.widgets
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.gui.widgets
|
||||
|
||||
import net.bdew.lib.gui.Rect
|
||||
|
||||
abstract class WidgetMultipane(rect: Rect) extends WidgetSubcontainer(rect) {
|
||||
abstract class WidgetMultiPane(rect: Rect) extends WidgetSubContainer(rect) {
|
||||
def getActivePane: BaseWidget
|
||||
|
||||
def addPane[T <: BaseWidget](w: T): T = {
|
||||
|
||||
@@ -4,15 +4,16 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.gui.widgets
|
||||
|
||||
import net.bdew.lib.gui._
|
||||
import scala.collection.mutable
|
||||
import net.bdew.lib.data.DataSlotFloat
|
||||
import net.bdew.lib.gui._
|
||||
|
||||
class WidgetProgressBar(rect: Rect, texture: Texture, dslot: DataSlotFloat) extends WidgetFillDataslot[Float](rect, texture, Direction.RIGHT, dslot, 1) {
|
||||
override def handleTooltip(p: Point, tip: mutable.MutableList[String]) = tip += "%.0f".format(dslot.cval * 100) + "%"
|
||||
import scala.collection.mutable
|
||||
|
||||
class WidgetProgressBar(rect: Rect, texture: Texture, dSlot: DataSlotFloat) extends WidgetFillDataSlot[Float](rect, texture, Direction.RIGHT, dSlot, 1) {
|
||||
override def handleTooltip(p: Point, tip: mutable.MutableList[String]) = tip += "%.0f".format(dSlot.value * 100) + "%"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* 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.gui.widgets
|
||||
|
||||
import net.bdew.lib.gui._
|
||||
|
||||
case class WidgetSimpleIcon(rect: Rect, icon: Texture) extends Widget {
|
||||
override def draw(mouse: Point) = parent.drawTexture(rect, icon)
|
||||
}
|
||||
@@ -4,15 +4,14 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.gui.widgets
|
||||
|
||||
import net.bdew.lib.gui._
|
||||
import net.bdew.lib.gui.Rect
|
||||
|
||||
class WidgetSubcontainer(val rect: Rect) extends BaseWidget with WidgetContainer with SimpleDrawTarget {
|
||||
class WidgetSubContainer(val rect: Rect) extends BaseWidget with WidgetContainer with SimpleDrawTarget {
|
||||
def getZLevel = parent.getZLevel
|
||||
def getFontRenderer = parent.getFontRenderer
|
||||
def getOffsetFromWindow = parent.getOffsetFromWindow + rect.origin
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.gui.widgets
|
||||
|
||||
import net.minecraft.client.gui.{FontRenderer, GuiTextField}
|
||||
import net.bdew.lib.gui.{Point, Rect}
|
||||
import net.minecraft.client.gui.{FontRenderer, GuiTextField}
|
||||
|
||||
class WidgetTextEdit(val rect: Rect, fr: FontRenderer) extends GuiTextField(fr, rect.x.round, rect.y.round, rect.w.round, rect.h.round) with Widget {
|
||||
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.items
|
||||
|
||||
import net.minecraft.item.{ItemBlock, Item, ItemStack}
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.item.{Item, ItemBlock, ItemStack}
|
||||
|
||||
/**
|
||||
* Allows matching Items in ItemStacks in scala pattern matches
|
||||
|
||||
@@ -4,18 +4,19 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.items
|
||||
|
||||
import java.util.Random
|
||||
|
||||
import net.bdew.lib.Misc
|
||||
import net.minecraft.entity.item.EntityItem
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.inventory.{IInventory, ISidedInventory}
|
||||
import net.minecraft.item.{Item, ItemStack}
|
||||
import net.minecraft.world.World
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.inventory.{ISidedInventory, IInventory}
|
||||
import net.bdew.lib.Misc
|
||||
import java.util.Random
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
object ItemUtils {
|
||||
@@ -24,11 +25,11 @@ object ItemUtils {
|
||||
val dx = world.rand.nextFloat * 0.8
|
||||
val dy = world.rand.nextFloat * 0.8
|
||||
val dz = world.rand.nextFloat * 0.8
|
||||
val entityitem: EntityItem = new EntityItem(world, x + dx, y + dy, z + dz, stack)
|
||||
entityitem.motionX = world.rand.nextGaussian * 0.05
|
||||
entityitem.motionY = world.rand.nextGaussian * 0.05 + 0.2
|
||||
entityitem.motionZ = world.rand.nextGaussian * 0.05
|
||||
world.spawnEntityInWorld(entityitem)
|
||||
val entity = new EntityItem(world, x + dx, y + dy, z + dz, stack)
|
||||
entity.motionX = world.rand.nextGaussian * 0.05
|
||||
entity.motionY = world.rand.nextGaussian * 0.05 + 0.2
|
||||
entity.motionZ = world.rand.nextGaussian * 0.05
|
||||
world.spawnEntityInWorld(entity)
|
||||
}
|
||||
|
||||
def dropItemToPlayer(world: World, player: EntityPlayer, stack: ItemStack) {
|
||||
@@ -46,11 +47,11 @@ object ItemUtils {
|
||||
return ItemStack.areItemStackTagsEqual(stack2, stack1)
|
||||
}
|
||||
|
||||
def addStackToSlots(stack: ItemStack, inv: IInventory, slots: Iterable[Int], checkvalid: Boolean): ItemStack = {
|
||||
def addStackToSlots(stack: ItemStack, inv: IInventory, slots: Iterable[Int], checkValid: Boolean): ItemStack = {
|
||||
if (stack == null) return null
|
||||
|
||||
// Try merging into existing slots
|
||||
for (slot <- slots if (!checkvalid || inv.isItemValidForSlot(slot, stack)) && isSameItem(stack, inv.getStackInSlot(slot))) {
|
||||
for (slot <- slots if (!checkValid || inv.isItemValidForSlot(slot, stack)) && isSameItem(stack, inv.getStackInSlot(slot))) {
|
||||
val target = inv.getStackInSlot(slot)
|
||||
val toAdd = Misc.min(target.getMaxStackSize - target.stackSize, inv.getInventoryStackLimit - target.stackSize, stack.stackSize)
|
||||
if (toAdd >= stack.stackSize) {
|
||||
@@ -66,7 +67,7 @@ object ItemUtils {
|
||||
}
|
||||
|
||||
// Now find empty slots and stick any leftovers there
|
||||
for (slot <- slots if (!checkvalid || inv.isItemValidForSlot(slot, stack)) && inv.getStackInSlot(slot) == null) {
|
||||
for (slot <- slots if (!checkValid || inv.isItemValidForSlot(slot, stack)) && inv.getStackInSlot(slot) == null) {
|
||||
if (inv.getInventoryStackLimit < stack.stackSize) {
|
||||
inv.setInventorySlotContents(slot, stack.splitStack(inv.getInventoryStackLimit))
|
||||
} else {
|
||||
|
||||
@@ -4,15 +4,15 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.items
|
||||
|
||||
import net.minecraft.item.Item
|
||||
import net.minecraft.client.renderer.texture.IIconRegister
|
||||
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||
import net.bdew.lib.Misc
|
||||
import net.minecraft.client.renderer.texture.IIconRegister
|
||||
import net.minecraft.item.Item
|
||||
|
||||
trait NamedItem extends Item {
|
||||
def name: String
|
||||
|
||||
@@ -4,26 +4,24 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.items.inventory
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.bdew.lib.gui.BaseContainer
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.inventory.Slot
|
||||
import net.minecraft.item.ItemStack
|
||||
|
||||
class ContainerItemInventory(inv: InventoryItemAdapter, player: EntityPlayer) extends BaseContainer(inv) {
|
||||
def canInteractWith(entityplayer: EntityPlayer) = entityplayer == player
|
||||
|
||||
override def slotClick(slotnum: Int, button: Int, modifiers: Int, player: EntityPlayer): ItemStack = {
|
||||
if (slotnum > 0 && slotnum < inventorySlots.size()) {
|
||||
val slot = inventorySlots.asInstanceOf[java.util.List[Slot]].get(slotnum)
|
||||
override def slotClick(slotNum: Int, button: Int, modifiers: Int, player: EntityPlayer): ItemStack = {
|
||||
if (slotNum > 0 && slotNum < inventorySlots.size()) {
|
||||
val slot = inventorySlots.asInstanceOf[java.util.List[Slot]].get(slotNum)
|
||||
if (slot.isSlotInInventory(inv.player.inventory, inv.slot))
|
||||
return null
|
||||
}
|
||||
if (modifiers == 2 && button == inv.slot) return null
|
||||
return super.slotClick(slotnum, button, modifiers, player)
|
||||
return super.slotClick(slotNum, button, modifiers, player)
|
||||
}
|
||||
}
|
||||
@@ -4,16 +4,16 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.items.inventory
|
||||
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.bdew.lib.tile.inventory.BaseInventory
|
||||
import net.bdew.lib.Misc
|
||||
import net.minecraft.nbt.{NBTTagList, NBTTagCompound}
|
||||
import net.bdew.lib.tile.inventory.BaseInventory
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.{NBTTagCompound, NBTTagList}
|
||||
|
||||
class InventoryItemAdapter(val player: EntityPlayer, val slot: Int, val size: Int, val tagName: String) extends BaseInventory {
|
||||
def getSizeInventory = size
|
||||
@@ -24,7 +24,7 @@ class InventoryItemAdapter(val player: EntityPlayer, val slot: Int, val size: In
|
||||
|
||||
def load() {
|
||||
val tag = getStack.getTagCompound
|
||||
for (nbtItem <- Misc.iterNbtCompoundList(tag, "tagName")) {
|
||||
for (nbtItem <- Misc.iterNbtCompoundList(tag, tagName)) {
|
||||
val slot = nbtItem.getByte("Slot")
|
||||
if (slot >= 0 && slot < inv.size) {
|
||||
inv(slot) = ItemStack.loadItemStackFromNBT(nbtItem)
|
||||
|
||||
@@ -4,22 +4,22 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.items.inventory
|
||||
|
||||
import net.minecraft.item.Item
|
||||
import net.bdew.lib.gui.GuiProvider
|
||||
import cpw.mods.fml.common.Loader
|
||||
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.bdew.lib.BdLib
|
||||
import net.bdew.lib.gui.GuiProvider
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.item.Item
|
||||
import net.minecraft.world.World
|
||||
|
||||
/**
|
||||
* Mixin for items that have an internal inventory
|
||||
* Subclasses are responsible for registering themself with the GuiHandler of their mod
|
||||
* Subclasses are responsible for registering themselves with the GuiHandler of their mod
|
||||
*/
|
||||
trait ItemInventory extends Item with GuiProvider {
|
||||
type TEClass = Any
|
||||
|
||||
@@ -4,16 +4,17 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.machine
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry
|
||||
import net.bdew.lib.Misc
|
||||
import net.bdew.lib.block.HasTE
|
||||
import net.bdew.lib.recipes.gencfg.ConfigSection
|
||||
import net.minecraft.block.Block
|
||||
import cpw.mods.fml.common.registry.GameRegistry
|
||||
import net.bdew.lib.block.HasTE
|
||||
import net.bdew.lib.Misc
|
||||
import net.minecraft.creativetab.CreativeTabs
|
||||
|
||||
abstract class Machine[T <: Block](val name: String, blockConstruct: => T) {
|
||||
var block: T = null.asInstanceOf[T]
|
||||
@@ -21,9 +22,10 @@ abstract class Machine[T <: Block](val name: String, blockConstruct: => T) {
|
||||
var enabled = false
|
||||
val modId = Misc.getActiveModId
|
||||
|
||||
def regBlock() {
|
||||
def regBlock(creativeTab: CreativeTabs) {
|
||||
block = blockConstruct
|
||||
GameRegistry.registerBlock(block, name)
|
||||
block.setCreativeTab(creativeTab)
|
||||
if (block.isInstanceOf[HasTE[_]]) {
|
||||
GameRegistry.registerTileEntity(block.asInstanceOf[HasTE[_]].TEClass, "%s.%s".format(modId, name))
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.machine
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.machine
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* 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.multiblock
|
||||
|
||||
import net.bdew.lib.recipes.gencfg.{ConfigSection, EntryDouble}
|
||||
|
||||
trait MachineCore {
|
||||
var tuning: ConfigSection
|
||||
|
||||
def cfgSectionToMap(name: String) = tuning.getSection(name).map({
|
||||
case (n, EntryDouble(v)) => n -> v.toInt
|
||||
case (n, x) => sys.error("Invalid config value in section %s%s.%s = %s".format(tuning.pfx, name, n, x))
|
||||
}).toMap
|
||||
|
||||
lazy val modules = cfgSectionToMap("Modules")
|
||||
lazy val required = cfgSectionToMap("Required")
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* 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.multiblock
|
||||
|
||||
import net.bdew.lib.gui.{Color, Texture}
|
||||
import net.minecraft.util.IIcon
|
||||
|
||||
trait ResourceProvider {
|
||||
// Icons for rendering, *must* be on block sprite sheet
|
||||
def edge: IIcon
|
||||
def disabled: IIcon
|
||||
def output: IIcon
|
||||
def arrowTop: IIcon
|
||||
def arrowRight: IIcon
|
||||
def arrowBottom: IIcon
|
||||
def arrowLeft: IIcon
|
||||
|
||||
// Textures for GUI stuff
|
||||
def btBase: Texture
|
||||
def btHover: Texture
|
||||
def btRsOn: Texture
|
||||
def btRsOff: Texture
|
||||
def btEnabled: Texture
|
||||
def btDisabled: Texture
|
||||
|
||||
val outputColors: Map[Int, Color]
|
||||
val unlocalizedOutputName: Map[Int, String]
|
||||
def getModuleName(s: String): String
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* 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.multiblock
|
||||
|
||||
import net.bdew.lib.block.BlockRef
|
||||
import net.bdew.lib.multiblock.tile.{TileController, TileModule}
|
||||
import net.minecraft.world.World
|
||||
|
||||
import scala.collection.mutable
|
||||
|
||||
object Tools {
|
||||
def canConnect(world: World, core: BlockRef, kind: String): Boolean = {
|
||||
val t = core.getTile[TileController](world).getOrElse(return false)
|
||||
t.getNumOfModules(kind) < t.cfg.modules.getOrElse(kind, return false)
|
||||
}
|
||||
|
||||
def findConnections(world: World, start: BlockRef, kind: String) =
|
||||
(start.neighbours.values flatMap { case pos =>
|
||||
(pos.tile(world) flatMap {
|
||||
case t: TileModule => t.connected.value
|
||||
case t: TileController => Some(pos)
|
||||
case _ => None
|
||||
}) filter (x => canConnect(world, x, kind))
|
||||
}).toList.distinct
|
||||
|
||||
def getConnectedNeighbours(w: World, core: BlockRef, pos: BlockRef, seen: mutable.Set[BlockRef]) =
|
||||
pos.neighbours.values
|
||||
.filterNot(seen.contains)
|
||||
.flatMap(_.getTile[TileModule](w))
|
||||
.filter(x => x.connected.contains(core))
|
||||
.map(_.myPos)
|
||||
|
||||
def findReachableModules(world: World, core: BlockRef): Set[BlockRef] = {
|
||||
val seen = mutable.Set.empty[BlockRef]
|
||||
val queue = mutable.Queue.empty[BlockRef]
|
||||
queue ++= getConnectedNeighbours(world, core, core, seen)
|
||||
while (queue.size > 0) {
|
||||
val current = queue.dequeue()
|
||||
seen.add(current)
|
||||
queue ++= getConnectedNeighbours(world, core, current, seen)
|
||||
}
|
||||
return seen.toSet
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* 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.multiblock.block
|
||||
|
||||
import net.bdew.lib.block.{BlockRef, HasTE}
|
||||
import net.bdew.lib.multiblock.ResourceProvider
|
||||
import net.bdew.lib.multiblock.tile.TileController
|
||||
import net.bdew.lib.render.connected.ConnectedTextureBlock
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.block.material.Material
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.world.{IBlockAccess, World}
|
||||
|
||||
abstract class BlockController[T <: TileController](val name: String, material: Material, val TEClass: Class[T])
|
||||
extends Block(material) with HasTE[T] with ConnectedTextureBlock {
|
||||
|
||||
def resources: ResourceProvider
|
||||
|
||||
override def edgeIcon = resources.edge
|
||||
|
||||
override def breakBlock(world: World, x: Int, y: Int, z: Int, block: Block, meta: Int) {
|
||||
getTE(world, x, y, z).onBreak()
|
||||
super.breakBlock(world, x, y, z, block, meta)
|
||||
}
|
||||
|
||||
override def canConnect(world: IBlockAccess, origin: BlockRef, target: BlockRef) =
|
||||
getTE(world, origin).modules.contains(target)
|
||||
|
||||
override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer, meta: Int, xOffs: Float, yOffs: Float, zOffs: Float): Boolean = {
|
||||
if (player.isSneaking) return false
|
||||
if (world.isRemote) return true
|
||||
getTE(world, x, y, z).onClick(player)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* 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.multiblock.block
|
||||
|
||||
import net.bdew.lib.block.{BlockRef, HasTE}
|
||||
import net.bdew.lib.multiblock.tile.TileModule
|
||||
import net.bdew.lib.multiblock.{ResourceProvider, Tools}
|
||||
import net.bdew.lib.render.connected.ConnectedTextureBlock
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.block.material.Material
|
||||
import net.minecraft.entity.EntityLivingBase
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.util.ChatComponentTranslation
|
||||
import net.minecraft.world.{IBlockAccess, World}
|
||||
|
||||
abstract class BlockModule[T <: TileModule](val name: String, val kind: String, material: Material, val TEClass: Class[T])
|
||||
extends Block(material) with HasTE[T] with ConnectedTextureBlock {
|
||||
|
||||
def resources: ResourceProvider
|
||||
|
||||
override def edgeIcon = resources.edge
|
||||
|
||||
override def canPlaceBlockAt(world: World, x: Int, y: Int, z: Int): Boolean =
|
||||
Tools.findConnections(world, BlockRef(x, y, z), kind).size <= 1
|
||||
|
||||
override def onBlockPlacedBy(world: World, x: Int, y: Int, z: Int, player: EntityLivingBase, stack: ItemStack) {
|
||||
getTE(world, x, y, z).tryConnect()
|
||||
}
|
||||
|
||||
override def onNeighborBlockChange(world: World, x: Int, y: Int, z: Int, block: Block) {
|
||||
getTE(world, x, y, z).tryConnect()
|
||||
}
|
||||
|
||||
override def breakBlock(world: World, x: Int, y: Int, z: Int, block: Block, meta: Int) {
|
||||
getTE(world, x, y, z).onBreak()
|
||||
super.breakBlock(world, x, y, z, block, meta)
|
||||
}
|
||||
|
||||
override def canConnect(world: IBlockAccess, origin: BlockRef, target: BlockRef) = {
|
||||
val me = getTE(world, origin)
|
||||
me.connected.contains(target) ||
|
||||
(target.getTile[TileModule](world) exists { other =>
|
||||
me.getCore.isDefined && other.getCore == me.getCore
|
||||
})
|
||||
}
|
||||
|
||||
override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer, meta: Int, xOffs: Float, yOffs: Float, zOffs: Float): Boolean = {
|
||||
if (player.isSneaking) return false
|
||||
if (world.isRemote) return true
|
||||
val te = getTE(world, x, y, z)
|
||||
(for {
|
||||
p <- te.connected.value
|
||||
bl <- p.block(world)
|
||||
} yield {
|
||||
bl.onBlockActivated(world, p.x, p.y, p.z, player, meta, 0, 0, 0)
|
||||
}) getOrElse {
|
||||
player.addChatMessage(new ChatComponentTranslation("bdlib.multiblock.notconnected"))
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* 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.multiblock.block
|
||||
|
||||
import net.bdew.lib.block.{BlockFace, BlockRef}
|
||||
import net.bdew.lib.multiblock.tile.TileOutput
|
||||
import net.bdew.lib.render.connected.{BlockAdditionalRender, ConnectedHelper, FaceOverlay}
|
||||
import net.minecraft.world.IBlockAccess
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
trait BlockOutput[T <: TileOutput[_]] extends BlockModule[T] with BlockAdditionalRender {
|
||||
def getNeighbourFaces(face: ForgeDirection, bp: BlockRef) = {
|
||||
val sides = ConnectedHelper.neighbourFaces(face)
|
||||
Seq(
|
||||
(BlockFace(bp, sides.top), resources.arrowTop),
|
||||
(BlockFace(bp, sides.right), resources.arrowRight),
|
||||
(BlockFace(bp, sides.bottom), resources.arrowBottom),
|
||||
(BlockFace(bp, sides.left), resources.arrowLeft)
|
||||
)
|
||||
}
|
||||
|
||||
def getFaceOverlays(world: IBlockAccess, x: Int, y: Int, z: Int, face: ForgeDirection): List[FaceOverlay] = {
|
||||
var result = List.empty[FaceOverlay]
|
||||
Option(getTE(world, x, y, z)) flatMap (_.getCore) map { core =>
|
||||
val bf = BlockFace(x, y, z, face)
|
||||
if (core.outputFaces.contains(bf))
|
||||
result :+= FaceOverlay(resources.output, resources.outputColors(core.outputFaces(bf)))
|
||||
for ((bf, icon) <- getNeighbourFaces(face, bf.origin)) {
|
||||
if (core.outputFaces.contains(bf))
|
||||
result :+= FaceOverlay(icon, resources.outputColors(core.outputFaces(bf)))
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* 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.multiblock.data
|
||||
|
||||
import net.bdew.lib.Misc
|
||||
import net.bdew.lib.block.BlockFace
|
||||
import net.bdew.lib.data.base.{DataSlot, TileDataSlots, UpdateKind}
|
||||
import net.minecraft.nbt.{NBTTagCompound, NBTTagIntArray, NBTTagList}
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
import scala.collection.mutable
|
||||
|
||||
case class DataSlotBlockFaceMap(name: String, parent: TileDataSlots) extends DataSlot {
|
||||
val map = collection.mutable.Map.empty[BlockFace, Int]
|
||||
|
||||
setUpdate(UpdateKind.SAVE, UpdateKind.WORLD)
|
||||
|
||||
def inverted = map.map(_.swap)
|
||||
|
||||
def ent2arr(x: (BlockFace, Int)) = Array(x._2, x._1.x, x._1.y, x._1.z, x._1.face.ordinal())
|
||||
def arr2ent(x: Array[Int]) = BlockFace(x(1), x(2), x(3), ForgeDirection.values()(x(4))) -> x(0)
|
||||
|
||||
def save(t: NBTTagCompound, kind: UpdateKind.Value) {
|
||||
val lst = new NBTTagList()
|
||||
for (x <- map) lst.appendTag(new NBTTagIntArray(ent2arr(x)))
|
||||
t.setTag(name, lst)
|
||||
}
|
||||
|
||||
def load(t: NBTTagCompound, kind: UpdateKind.Value) {
|
||||
map.clear()
|
||||
map ++= Misc.iterNbtIntArray(t, name) map arr2ent
|
||||
}
|
||||
|
||||
def updated() = parent.dataSlotChanged(this)
|
||||
}
|
||||
|
||||
object DataSlotBlockFaceMap {
|
||||
|
||||
import scala.language.implicitConversions
|
||||
|
||||
implicit def dataSlotBlockFaceMap2map(v: DataSlotBlockFaceMap): mutable.Map[BlockFace, Int] = v.map
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* 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.multiblock.data
|
||||
|
||||
import net.bdew.lib.data.base.{DataSlot, TileDataSlots, UpdateKind}
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
import scala.collection.mutable
|
||||
|
||||
case class DataSlotOutputConfig(name: String, parent: TileDataSlots, slots: Int) extends DataSlot {
|
||||
val map = collection.mutable.Map.empty[Int, OutputConfig]
|
||||
|
||||
setUpdate(UpdateKind.SAVE, UpdateKind.GUI)
|
||||
|
||||
def inverted = map.map(_.swap)
|
||||
|
||||
def save(t: NBTTagCompound, kind: UpdateKind.Value) {
|
||||
for ((n, x) <- map) {
|
||||
val tmp = new NBTTagCompound()
|
||||
x.write(tmp)
|
||||
tmp.setString("kind", x.id)
|
||||
t.setTag(name + "_" + n, tmp)
|
||||
}
|
||||
}
|
||||
|
||||
def load(t: NBTTagCompound, kind: UpdateKind.Value) {
|
||||
map.clear()
|
||||
for (i <- 0 until slots) {
|
||||
if (t.hasKey(name + "_" + i)) {
|
||||
val cfg = t.getCompoundTag(name + "_" + i)
|
||||
val cfgObj = OutputConfigManager.create(cfg.getString("kind"))
|
||||
cfgObj.read(cfg)
|
||||
map += i -> cfgObj
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def updated() = parent.dataSlotChanged(this)
|
||||
}
|
||||
|
||||
object DataSlotOutputConfig {
|
||||
|
||||
import scala.language.implicitConversions
|
||||
|
||||
implicit def dataSlotOutputConfig2map(v: DataSlotOutputConfig): mutable.Map[Int, OutputConfig] = v.map
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* 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.multiblock.data
|
||||
|
||||
import net.bdew.lib.Misc
|
||||
import net.bdew.lib.block.BlockRef
|
||||
import net.bdew.lib.data.DataSlotOption
|
||||
import net.bdew.lib.data.base.{TileDataSlots, UpdateKind}
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
case class DataSlotPos(name: String, parent: TileDataSlots) extends DataSlotOption[BlockRef] {
|
||||
setUpdate(UpdateKind.SAVE, UpdateKind.WORLD)
|
||||
|
||||
def save(t: NBTTagCompound, kind: UpdateKind.Value) {
|
||||
value map (x => t.setTag(name, Misc.applyMutator(x.writeToNBT, new NBTTagCompound)))
|
||||
}
|
||||
|
||||
def load(t: NBTTagCompound, kind: UpdateKind.Value) {
|
||||
value = if (t.hasKey(name))
|
||||
Some(BlockRef.fromNBT(t.getCompoundTag(name)))
|
||||
else
|
||||
None
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* 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.multiblock.data
|
||||
|
||||
import net.bdew.lib.Misc
|
||||
import net.bdew.lib.block.BlockRef
|
||||
import net.bdew.lib.data.base.{DataSlot, TileDataSlots, UpdateKind}
|
||||
import net.minecraft.nbt.{NBTTagCompound, NBTTagList}
|
||||
|
||||
import scala.collection.mutable
|
||||
|
||||
case class DataSlotPosSet(name: String, parent: TileDataSlots) extends DataSlot {
|
||||
val set = collection.mutable.Set.empty[BlockRef]
|
||||
|
||||
setUpdate(UpdateKind.SAVE, UpdateKind.WORLD)
|
||||
|
||||
def save(t: NBTTagCompound, kind: UpdateKind.Value) {
|
||||
val lst = new NBTTagList()
|
||||
for (x <- set) lst.appendTag(Misc.applyMutator(x.writeToNBT, new NBTTagCompound))
|
||||
t.setTag(name, lst)
|
||||
}
|
||||
|
||||
def load(t: NBTTagCompound, kind: UpdateKind.Value) {
|
||||
set.clear()
|
||||
set ++= Misc.iterNbtCompoundList(t, name) map BlockRef.fromNBT
|
||||
}
|
||||
|
||||
def updated() = parent.dataSlotChanged(this)
|
||||
|
||||
}
|
||||
|
||||
object DataSlotPosSet {
|
||||
|
||||
import scala.language.implicitConversions
|
||||
|
||||
implicit def dataSlotPosSet2set(v: DataSlotPosSet): mutable.Set[BlockRef] = v.set
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* 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.multiblock.data
|
||||
|
||||
import net.bdew.lib.multiblock.network.MsgOutputCfg
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException
|
||||
|
||||
abstract class OutputConfig {
|
||||
def id: String
|
||||
def read(t: NBTTagCompound)
|
||||
def write(t: NBTTagCompound)
|
||||
def handleConfigPacket(m: MsgOutputCfg)
|
||||
}
|
||||
|
||||
class OutputConfigInvalid extends OutputConfig {
|
||||
override val id: String = "invalid"
|
||||
def read(t: NBTTagCompound) {}
|
||||
def write(t: NBTTagCompound) = throw new NotImplementedException
|
||||
def handleConfigPacket(m: MsgOutputCfg) = throw new NotImplementedException
|
||||
}
|
||||
|
||||
object OutputConfigManager {
|
||||
var loaders = Map.empty[String, () => OutputConfig]
|
||||
def register(id: String, loader: () => OutputConfig) = loaders += id -> loader
|
||||
def create(id: String) = loaders.get(id).map(_.apply()).getOrElse(new OutputConfigInvalid)
|
||||
|
||||
register("fluid", () => new OutputConfigFluid)
|
||||
register("power", () => new OutputConfigPower)
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* 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.multiblock.data
|
||||
|
||||
import net.bdew.lib.multiblock.network.MsgOutputCfg
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
class OutputConfigFluid extends OutputConfig with OutputConfigRSControllable {
|
||||
override def id = "fluid"
|
||||
var avg = 0.0
|
||||
var rsMode = RSMode.ALWAYS
|
||||
|
||||
final val decay = 0.5
|
||||
|
||||
def updateAvg(v: Double) {
|
||||
avg = avg * decay + (1 - decay) * v
|
||||
}
|
||||
|
||||
def read(t: NBTTagCompound) {
|
||||
avg = t.getDouble("avg")
|
||||
rsMode = RSMode(t.getInteger("rsMode"))
|
||||
}
|
||||
|
||||
def write(t: NBTTagCompound) {
|
||||
t.setDouble("avg", avg)
|
||||
t.setInteger("rsMode", rsMode.id)
|
||||
}
|
||||
|
||||
def handleConfigPacket(m: MsgOutputCfg) = m match {
|
||||
case MsgOutputCfgRSMode(_, r) => rsMode = r
|
||||
case _ => sys.error("Invalid output config packet %s to config %s".format(m, this))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* 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.multiblock.data
|
||||
|
||||
import net.bdew.lib.multiblock.network.{MsgOutputCfg, MsgOutputCfgSlot}
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
trait OutputConfigSlots {
|
||||
val slotsDef: SlotSet
|
||||
var slot = slotsDef.default
|
||||
}
|
||||
|
||||
class OutputConfigFluidSlots(val slotsDef: SlotSet) extends OutputConfigFluid with OutputConfigSlots {
|
||||
override def id = slotsDef.outputConfigId
|
||||
override def read(t: NBTTagCompound) {
|
||||
super.read(t)
|
||||
slot = slotsDef.get(t.getString("slot"))
|
||||
}
|
||||
override def write(t: NBTTagCompound) {
|
||||
super.write(t)
|
||||
t.setString("slot", slot.id)
|
||||
}
|
||||
override def handleConfigPacket(m: MsgOutputCfg) = m match {
|
||||
case MsgOutputCfgSlot(n, id) => slot = slotsDef.get(id)
|
||||
case _ => super.handleConfigPacket(m)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* 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.multiblock.data
|
||||
|
||||
import net.bdew.lib.multiblock.network.MsgOutputCfg
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
class OutputConfigItems extends OutputConfig with OutputConfigRSControllable {
|
||||
override def id = "items"
|
||||
var rsMode = RSMode.ALWAYS
|
||||
|
||||
def read(t: NBTTagCompound) {
|
||||
rsMode = RSMode(t.getInteger("rsMode"))
|
||||
}
|
||||
|
||||
def write(t: NBTTagCompound) {
|
||||
t.setInteger("rsMode", rsMode.id)
|
||||
}
|
||||
|
||||
def handleConfigPacket(m: MsgOutputCfg) = m match {
|
||||
case MsgOutputCfgRSMode(_, r) => rsMode = r
|
||||
case _ => sys.error("Invalid output config packet %s to config %s".format(m, this))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* 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.multiblock.data
|
||||
|
||||
import net.bdew.lib.multiblock.network.MsgOutputCfg
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
class OutputConfigPower(var unit: String = "MJ") extends OutputConfig with OutputConfigRSControllable {
|
||||
override val id = "power"
|
||||
var avg = 0.0
|
||||
var rsMode = RSMode.ALWAYS
|
||||
|
||||
final val decay = 0.5
|
||||
|
||||
def updateAvg(v: Double) {
|
||||
avg = avg * decay + (1 - decay) * v
|
||||
}
|
||||
|
||||
def read(t: NBTTagCompound) {
|
||||
avg = t.getDouble("avg")
|
||||
rsMode = RSMode(t.getInteger("rsMode"))
|
||||
unit = t.getString("unit")
|
||||
}
|
||||
|
||||
def write(t: NBTTagCompound) {
|
||||
t.setDouble("avg", avg)
|
||||
t.setInteger("rsMode", rsMode.id)
|
||||
t.setString("unit", unit)
|
||||
}
|
||||
|
||||
def handleConfigPacket(m: MsgOutputCfg) = m match {
|
||||
case MsgOutputCfgRSMode(_, r) => rsMode = r
|
||||
case _ => sys.error("Invalid output config packet %s to config %s".format(m, this))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* 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.multiblock.data
|
||||
|
||||
import net.bdew.lib.multiblock.network.MsgOutputCfg
|
||||
|
||||
case class MsgOutputCfgRSMode(output: Int, rsMode: RSMode.Value) extends MsgOutputCfg
|
||||
|
||||
trait OutputConfigRSControllable extends OutputConfig {
|
||||
var rsMode: RSMode.Value
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* 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.multiblock.data
|
||||
|
||||
object RSMode extends Enumeration {
|
||||
val ALWAYS = Value(0, "ALWAYS")
|
||||
val RS_ON = Value(1, "RS_ON")
|
||||
val RS_OFF = Value(2, "RS_OFF")
|
||||
val NEVER = Value(3, "NEVER")
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* 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.multiblock.data
|
||||
|
||||
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||
import net.bdew.lib.gui.Texture
|
||||
|
||||
abstract class SlotSet(val outputConfigId: String) {
|
||||
// outputConfigId should be registered in OutputConfigManager
|
||||
|
||||
var slotMap = Map.empty[String, Slot]
|
||||
|
||||
case class Slot(id: String, name: String) {
|
||||
slotMap += id -> this
|
||||
def next = order(this)
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
def texture = textures(this)
|
||||
}
|
||||
|
||||
def default: Slot
|
||||
val order: Map[Slot, Slot]
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
def textures: Map[Slot, Texture]
|
||||
|
||||
def get(id: String) = slotMap(id)
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* 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.multiblock.gui
|
||||
|
||||
import net.bdew.lib.gui.widgets.Widget
|
||||
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 {
|
||||
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
|
||||
}
|
||||
|
||||
override def draw(mouse: Point) {
|
||||
parent.drawTexture(iconRect + rect.origin, icon)
|
||||
parent.drawText(text, rect.origin +(12, 1), Color.darkGray, false)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* 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.multiblock.gui
|
||||
|
||||
import net.bdew.lib.Misc
|
||||
import net.bdew.lib.gui.widgets.Widget
|
||||
import net.bdew.lib.gui.{Point, Rect, Texture}
|
||||
import net.bdew.lib.multiblock.interact.CIOutputFaces
|
||||
import net.bdew.lib.render.connected.BlockAdditionalRender
|
||||
|
||||
import scala.collection.mutable
|
||||
|
||||
class WidgetOutputIcon(p: Point, te: CIOutputFaces, output: Int) extends Widget {
|
||||
val rect = new Rect(p, 16, 16)
|
||||
|
||||
override def draw(mouse: Point) {
|
||||
val faces = te.outputFaces.inverted
|
||||
if (faces.isDefinedAt(output)) {
|
||||
val bf = faces(output)
|
||||
bf.origin.block(te.getWorldObj) map { block =>
|
||||
parent.drawTexture(rect, Texture(Texture.BLOCKS, block.getIcon(te.getWorldObj, bf.origin.x, bf.origin.y, bf.origin.z, bf.face.ordinal())))
|
||||
if (block.isInstanceOf[BlockAdditionalRender]) {
|
||||
for (over <- block.asInstanceOf[BlockAdditionalRender].getFaceOverlays(te.getWorldObj, bf.origin.x, bf.origin.y, bf.origin.z, bf.face))
|
||||
parent.drawTexture(rect, Texture(Texture.BLOCKS, over.icon), over.color)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
parent.drawTexture(rect, Texture(Texture.BLOCKS, te.resources.disabled), te.resources.outputColors(output))
|
||||
}
|
||||
}
|
||||
|
||||
override def handleTooltip(p: Point, tip: mutable.MutableList[String]) {
|
||||
val faces = te.outputFaces.inverted
|
||||
tip += Misc.toLocal(te.resources.unlocalizedOutputName(output))
|
||||
if (faces.isDefinedAt(output)) {
|
||||
val bf = faces(output)
|
||||
bf.origin.block(te.getWorldObj) map { block =>
|
||||
tip += block.getLocalizedName
|
||||
tip += "%d, %d, %d - %s".format(bf.x, bf.y, bf.z, Misc.toLocal("bdlib.multiblock.face." + bf.face.toString.toLowerCase))
|
||||
}
|
||||
} else {
|
||||
tip += Misc.toLocal("bdlib.multiblock.disabled")
|
||||
}
|
||||
}
|
||||
}
|
||||
Loaded 100 of 176 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user