mirror of
https://github.com/GTNewHorizons/bdlib.git
synced 2026-11-24 05:54:39 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7c275f434a | ||
|
|
f960050f9c | ||
|
|
87dd7c34c5 | ||
|
|
9fdc6bd880 | ||
|
|
490433a7f4 | ||
|
|
71bef762a6 | ||
|
|
5eef56811b | ||
|
|
5a3fa7ef75 | ||
|
|
2d799bb797 | ||
|
|
03d9b0fef0 |
No files matched your search
+1
-1
@@ -21,7 +21,7 @@ buildscript {
|
||||
apply plugin: 'scala'
|
||||
apply plugin: 'forge'
|
||||
|
||||
version = "1.4.0"
|
||||
version = "1.4.2"
|
||||
|
||||
if (project.hasProperty('buildnum')) {
|
||||
project.version = project.version + '.' + project.buildnum
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
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}
|
||||
import net.minecraft.command.CommandHandler
|
||||
import org.apache.logging.log4j.Logger
|
||||
|
||||
@Mod(modid = "bdlib", name = "BD lib", version = "BDLIB_VER", modLanguage = "scala")
|
||||
object BdLib {
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
package net.bdew.lib
|
||||
|
||||
import org.lwjgl.input.Keyboard
|
||||
import net.minecraft.client.Minecraft
|
||||
import org.lwjgl.input.Keyboard
|
||||
|
||||
/**
|
||||
* Misc functions and shortcuts for clientside code
|
||||
|
||||
@@ -9,14 +9,15 @@
|
||||
|
||||
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"
|
||||
|
||||
@@ -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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
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() {}
|
||||
}
|
||||
@@ -9,16 +9,16 @@
|
||||
|
||||
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.StatCollector
|
||||
import net.minecraft.world.biome.BiomeGenBase
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe
|
||||
|
||||
object Misc {
|
||||
def iterNbtCompoundList(parent: NBTTagCompound, name: String): Iterable[NBTTagCompound] = {
|
||||
@@ -26,6 +26,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)
|
||||
@@ -59,7 +64,7 @@ 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)
|
||||
@@ -84,5 +89,10 @@ object Misc {
|
||||
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))
|
||||
|
||||
def applyMutator[T](f: (T) => Unit, init: T): T = {
|
||||
f(init)
|
||||
init
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
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"))
|
||||
}
|
||||
@@ -9,15 +9,18 @@
|
||||
|
||||
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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -9,22 +9,21 @@
|
||||
|
||||
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, SimpleBlock}
|
||||
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 <: SimpleBlock](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))
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
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 = {
|
||||
|
||||
@@ -9,25 +9,23 @@
|
||||
|
||||
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() {}
|
||||
}
|
||||
@@ -9,16 +9,17 @@
|
||||
|
||||
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])
|
||||
}
|
||||
|
||||
@@ -9,12 +9,12 @@
|
||||
|
||||
package net.bdew.lib.covers
|
||||
|
||||
import net.bdew.lib.block.HasTE
|
||||
import net.minecraft.world.{IBlockAccess, World}
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
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.world.{IBlockAccess, World}
|
||||
|
||||
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 = {
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
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
|
||||
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
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
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
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
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
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
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
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)
|
||||
|
||||
@@ -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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
package net.bdew.lib.data
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
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)
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
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
|
||||
|
||||
@@ -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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
package net.bdew.lib.data
|
||||
|
||||
import net.bdew.lib.data.base.DataSlotVal
|
||||
|
||||
abstract class DataSlotOption[T] extends DataSlotVal[Option[T]] {
|
||||
override var cval: Option[T] = None
|
||||
|
||||
def set(v: T) {
|
||||
if (v == null) sys.error("Null should never be used with DataSlotOption")
|
||||
cval = Some(v)
|
||||
}
|
||||
|
||||
def unset() {
|
||||
cval = 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)
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
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
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
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
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
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 {
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
package net.bdew.lib.data.base
|
||||
|
||||
import language.implicitConversions
|
||||
import scala.language.implicitConversions
|
||||
|
||||
/**
|
||||
* Base trait for data slots that hold primitive values
|
||||
|
||||
@@ -9,11 +9,12 @@
|
||||
|
||||
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]
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
|
||||
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 = {
|
||||
|
||||
@@ -9,12 +9,13 @@
|
||||
|
||||
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)
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
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)
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
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
|
||||
|
||||
@@ -10,10 +10,11 @@
|
||||
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]
|
||||
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
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
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
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 {
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
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
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
package net.bdew.lib.gui
|
||||
|
||||
import net.minecraft.util.{IIcon, ResourceLocation}
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.renderer.texture.TextureMap
|
||||
import net.minecraft.util.{IIcon, ResourceLocation}
|
||||
|
||||
trait Texture {
|
||||
def u1: Float
|
||||
|
||||
@@ -9,11 +9,12 @@
|
||||
|
||||
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]
|
||||
|
||||
@@ -13,7 +13,7 @@ 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 point2awt(p: BasePoint[Int]): java.awt.Point = new java.awt.Point(p.x, p.y)
|
||||
|
||||
@@ -9,8 +9,9 @@
|
||||
|
||||
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
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
|
||||
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)
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
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 {
|
||||
|
||||
|
||||
@@ -9,13 +9,15 @@
|
||||
|
||||
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.data.DataSlotTankBase
|
||||
import net.bdew.lib.gui.{Point, Rect, Texture}
|
||||
import org.lwjgl.opengl.GL11
|
||||
|
||||
import scala.collection.mutable
|
||||
|
||||
class WidgetFluidGauge(val rect: Rect, overlay: Texture, dslot: DataSlotTankBase) extends Widget {
|
||||
val formater = new DecimalFormat("#,###")
|
||||
|
||||
|
||||
@@ -9,9 +9,10 @@
|
||||
|
||||
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._
|
||||
|
||||
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.cval * 100) + "%"
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
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 {
|
||||
def getZLevel = parent.getZLevel
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
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 {
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
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
|
||||
|
||||
@@ -9,13 +9,14 @@
|
||||
|
||||
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 {
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
|
||||
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
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
|
||||
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
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
|
||||
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)
|
||||
|
||||
@@ -9,12 +9,12 @@
|
||||
|
||||
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
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,11 +9,12 @@
|
||||
|
||||
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))
|
||||
}
|
||||
|
||||
@@ -0,0 +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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
package net.bdew.lib.network
|
||||
|
||||
abstract class Message extends Serializable
|
||||
@@ -9,63 +9,63 @@
|
||||
|
||||
package net.bdew.lib.network
|
||||
|
||||
import cpw.mods.fml.common.network.{FMLOutboundHandler, NetworkRegistry}
|
||||
import java.util
|
||||
|
||||
import cpw.mods.fml.common.network.{FMLEmbeddedChannel, FMLOutboundHandler, NetworkRegistry}
|
||||
import cpw.mods.fml.relauncher.Side
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import io.netty.channel.{ChannelFutureListener, ChannelHandler}
|
||||
import net.bdew.lib.{BdLib, Misc}
|
||||
import net.minecraft.entity.player.EntityPlayerMP
|
||||
import io.netty.channel.{ChannelHandler, ChannelFutureListener}
|
||||
|
||||
class NetChannel(val name: String) {
|
||||
val channels = NetworkRegistry.INSTANCE.newChannel(name, new NBTMessageToMessageCodec)
|
||||
var channels: util.EnumMap[Side, FMLEmbeddedChannel] = null
|
||||
|
||||
var serverHandlers = Map.empty[String, (NBTTagCompound, EntityPlayerMP) => Unit]
|
||||
var clientHandlers = Map.empty[String, (NBTTagCompound) => Unit]
|
||||
def init() {
|
||||
channels = NetworkRegistry.INSTANCE.newChannel(name, new SerializedMessageCodec)
|
||||
BdLib.logInfo("Initialized network channel '%s' for mod '%s'", name, Misc.getActiveModId)
|
||||
addHandler(Side.SERVER, new NetChannelServerHandler(this))
|
||||
addHandler(Side.CLIENT, new NetChannelClientHandler(this))
|
||||
}
|
||||
|
||||
def regServerHandler(id: String, callable: (NBTTagCompound, EntityPlayerMP) => Unit) =
|
||||
if (serverHandlers.contains(id))
|
||||
sys.error("Command name already in use: %s".format(name))
|
||||
else
|
||||
serverHandlers += (id -> callable)
|
||||
var clientChain = PartialFunction.empty[Message, Unit]
|
||||
var serverChain = PartialFunction.empty[(Message, EntityPlayerMP), Unit]
|
||||
|
||||
def regClientHandler(id: String, callable: (NBTTagCompound) => Unit) =
|
||||
if (clientHandlers.contains(id))
|
||||
sys.error("Command name already in use: %s".format(name))
|
||||
else
|
||||
clientHandlers += (id -> callable)
|
||||
def regServerHandler(f: PartialFunction[(Message, EntityPlayerMP), Unit]) =
|
||||
serverChain = serverChain.orElse(f)
|
||||
|
||||
addHandler(Side.SERVER, new NetChannelServerHandler(this))
|
||||
addHandler(Side.CLIENT, new NetChannelClientHandler(this))
|
||||
def regClientHandler(f: PartialFunction[Message, Unit]) =
|
||||
clientChain = clientChain.orElse(f)
|
||||
|
||||
def addHandler(side: Side, handler: ChannelHandler) {
|
||||
private def addHandler(side: Side, handler: ChannelHandler) {
|
||||
val ch = channels.get(side)
|
||||
val name = ch.findChannelHandlerNameForType(classOf[NBTMessageToMessageCodec])
|
||||
val name = ch.findChannelHandlerNameForType(classOf[SerializedMessageCodec])
|
||||
ch.pipeline().addAfter(name, side + "Handler", handler)
|
||||
}
|
||||
|
||||
def sendToAll(message: NBTTagCompound) {
|
||||
def sendToAll(message: Message) {
|
||||
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALL)
|
||||
channels.get(Side.SERVER).writeAndFlush(message).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE)
|
||||
}
|
||||
|
||||
def sendTo(message: NBTTagCompound, player: EntityPlayerMP) {
|
||||
def sendTo(message: Message, player: EntityPlayerMP) {
|
||||
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER)
|
||||
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(player)
|
||||
channels.get(Side.SERVER).writeAndFlush(message).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE)
|
||||
}
|
||||
|
||||
def sendToAllAround(message: NBTTagCompound, point: NetworkRegistry.TargetPoint) {
|
||||
def sendToAllAround(message: Message, point: NetworkRegistry.TargetPoint) {
|
||||
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALLAROUNDPOINT)
|
||||
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(point)
|
||||
channels.get(Side.SERVER).writeAndFlush(message).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE)
|
||||
}
|
||||
|
||||
def sendToDimension(message: NBTTagCompound, dimensionId: Int) {
|
||||
def sendToDimension(message: Message, dimensionId: Int) {
|
||||
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.DIMENSION)
|
||||
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(new Integer(dimensionId))
|
||||
channels.get(Side.SERVER).writeAndFlush(message).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE)
|
||||
}
|
||||
|
||||
def sendToServer(message: NBTTagCompound) {
|
||||
def sendToServer(message: Message) {
|
||||
channels.get(Side.CLIENT).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.TOSERVER)
|
||||
channels.get(Side.CLIENT).writeAndFlush(message).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE)
|
||||
}
|
||||
|
||||
@@ -10,15 +10,17 @@
|
||||
package net.bdew.lib.network
|
||||
|
||||
import io.netty.channel.{ChannelHandlerContext, SimpleChannelInboundHandler}
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.bdew.lib.BdLib
|
||||
|
||||
class NetChannelClientHandler(ch: NetChannel) extends SimpleChannelInboundHandler[NBTTagCompound] {
|
||||
def channelRead0(ctx: ChannelHandlerContext, msg: NBTTagCompound) {
|
||||
val cmd = msg.getString("_cmd")
|
||||
ch.clientHandlers.getOrElse(cmd, {
|
||||
BdLib.log.error("Unknown command: '%s' from server".format(cmd))
|
||||
return
|
||||
})(msg)
|
||||
class NetChannelClientHandler(ch: NetChannel) extends SimpleChannelInboundHandler[Message] {
|
||||
def channelRead0(ctx: ChannelHandlerContext, msg: Message) {
|
||||
try {
|
||||
if (ch.clientChain.isDefinedAt(msg))
|
||||
ch.clientChain(msg)
|
||||
else
|
||||
BdLib.logWarn("Unable to handle message from server: %s", msg)
|
||||
} catch {
|
||||
case e: Throwable => BdLib.logErrorException("Error handling packet", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,19 +9,21 @@
|
||||
|
||||
package net.bdew.lib.network
|
||||
|
||||
import io.netty.channel.{ChannelHandlerContext, SimpleChannelInboundHandler}
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import cpw.mods.fml.common.network.NetworkRegistry
|
||||
import net.minecraft.network.NetHandlerPlayServer
|
||||
import io.netty.channel.{ChannelHandlerContext, SimpleChannelInboundHandler}
|
||||
import net.bdew.lib.BdLib
|
||||
import net.minecraft.network.NetHandlerPlayServer
|
||||
|
||||
class NetChannelServerHandler(ch: NetChannel) extends SimpleChannelInboundHandler[NBTTagCompound] {
|
||||
def channelRead0(ctx: ChannelHandlerContext, msg: NBTTagCompound) {
|
||||
val cmd = msg.getString("_cmd")
|
||||
val nh = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get.asInstanceOf[NetHandlerPlayServer].playerEntity
|
||||
ch.serverHandlers.getOrElse(cmd, {
|
||||
BdLib.log.error("Unknown command: '%s' from '%s'".format(cmd, nh.getCommandSenderName))
|
||||
return
|
||||
})(msg, nh)
|
||||
class NetChannelServerHandler(ch: NetChannel) extends SimpleChannelInboundHandler[Message] {
|
||||
def channelRead0(ctx: ChannelHandlerContext, msg: Message) {
|
||||
try {
|
||||
val player = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get.asInstanceOf[NetHandlerPlayServer].playerEntity
|
||||
if (ch.serverChain.isDefinedAt(msg, player))
|
||||
ch.serverChain(msg, player)
|
||||
else
|
||||
BdLib.logWarn("Unable to handle message from user %s: %s", player.getDisplayName, msg)
|
||||
} catch {
|
||||
case e: Throwable => BdLib.logErrorException("Error handling packet", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
-12
@@ -9,30 +9,31 @@
|
||||
|
||||
package net.bdew.lib.network
|
||||
|
||||
import io.netty.handler.codec.MessageToMessageCodec
|
||||
import cpw.mods.fml.common.network.internal.FMLProxyPacket
|
||||
import net.minecraft.nbt.{CompressedStreamTools, NBTTagCompound}
|
||||
import io.netty.channel.ChannelHandlerContext
|
||||
import java.io.{ObjectInputStream, ObjectOutputStream}
|
||||
import java.util
|
||||
import java.io.{DataInputStream, DataOutputStream}
|
||||
import io.netty.buffer.{ByteBufInputStream, ByteBufOutputStream, Unpooled}
|
||||
|
||||
import cpw.mods.fml.common.network.NetworkRegistry
|
||||
import cpw.mods.fml.common.network.internal.FMLProxyPacket
|
||||
import io.netty.buffer.{ByteBufInputStream, ByteBufOutputStream, Unpooled}
|
||||
import io.netty.channel.ChannelHandler.Sharable
|
||||
import io.netty.channel.ChannelHandlerContext
|
||||
import io.netty.handler.codec.MessageToMessageCodec
|
||||
import net.bdew.lib.BdLib
|
||||
|
||||
@Sharable
|
||||
class NBTMessageToMessageCodec extends MessageToMessageCodec[FMLProxyPacket, NBTTagCompound] {
|
||||
def encode(ctx: ChannelHandlerContext, msg: NBTTagCompound, out: util.List[AnyRef]) {
|
||||
class SerializedMessageCodec extends MessageToMessageCodec[FMLProxyPacket, Message] {
|
||||
def encode(ctx: ChannelHandlerContext, msg: Message, out: util.List[AnyRef]) {
|
||||
val buff = Unpooled.buffer()
|
||||
val writer = new DataOutputStream(new ByteBufOutputStream(buff))
|
||||
CompressedStreamTools.write(msg, writer)
|
||||
val writer = new ObjectOutputStream(new ByteBufOutputStream(buff))
|
||||
writer.writeObject(msg)
|
||||
val pkt = new FMLProxyPacket(buff, ctx.channel.attr(NetworkRegistry.FML_CHANNEL).get)
|
||||
out.add(pkt)
|
||||
}
|
||||
|
||||
def decode(ctx: ChannelHandlerContext, msg: FMLProxyPacket, out: util.List[AnyRef]) {
|
||||
try {
|
||||
val stream = new DataInputStream(new ByteBufInputStream(msg.payload()))
|
||||
out.add(CompressedStreamTools.read(stream))
|
||||
val reader = new ObjectInputStream(new ByteBufInputStream(msg.payload()))
|
||||
out.add(reader.readObject())
|
||||
} catch {
|
||||
case e: Throwable => BdLib.log.error("Error decoding packet", e)
|
||||
}
|
||||
@@ -9,10 +9,10 @@
|
||||
|
||||
package net.bdew.lib.power
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.bdew.lib.data.base.{TileDataSlots, UpdateKind, DataSlot}
|
||||
import net.bdew.lib.Misc
|
||||
import net.bdew.lib.data.base.{DataSlot, TileDataSlots, UpdateKind}
|
||||
import net.bdew.lib.machine.PoweredMachine
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
case class DataSlotPower(name: String, parent: TileDataSlots) extends DataSlot {
|
||||
updateKind = Set(UpdateKind.GUI, UpdateKind.SAVE)
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
package net.bdew.lib.power
|
||||
|
||||
import net.minecraft.item.{ItemStack, Item}
|
||||
import net.bdew.lib.Misc
|
||||
import net.minecraft.entity.EntityLivingBase
|
||||
import net.minecraft.item.{Item, ItemStack}
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
trait ItemPoweredBase extends Item {
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
|
||||
package net.bdew.lib.power
|
||||
|
||||
import net.bdew.lib.tile.TileExtended
|
||||
import net.bdew.lib.data.base.{UpdateKind, TileDataSlots}
|
||||
import net.bdew.lib.tile.inventory.{BreakableInventoryTile, SidedInventory, PersistentInventoryTile}
|
||||
import net.bdew.lib.data.DataSlotFloat
|
||||
import net.bdew.lib.data.base.{TileDataSlots, UpdateKind}
|
||||
import net.bdew.lib.machine.ProcessorMachine
|
||||
import net.bdew.lib.tile.TileExtended
|
||||
import net.bdew.lib.tile.inventory.{BreakableInventoryTile, PersistentInventoryTile, SidedInventory}
|
||||
|
||||
abstract class TileBaseProcessor extends TileExtended
|
||||
with TileDataSlots
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
package net.bdew.lib.power
|
||||
|
||||
import net.bdew.lib.tile.TileExtended
|
||||
import net.bdew.lib.machine.PoweredMachine
|
||||
import net.bdew.lib.tile.TileExtended
|
||||
|
||||
trait TilePoweredBase extends TileExtended {
|
||||
def power: DataSlotPower
|
||||
|
||||
@@ -9,10 +9,12 @@
|
||||
|
||||
package net.bdew.lib.power
|
||||
|
||||
import net.bdew.lib.gui.{Texture, Point, Rect}
|
||||
import scala.collection.mutable
|
||||
import java.text.DecimalFormat
|
||||
|
||||
import net.bdew.lib.gui.widgets.Widget
|
||||
import net.bdew.lib.gui.{Point, Rect, Texture}
|
||||
|
||||
import scala.collection.mutable
|
||||
|
||||
class WidgetPowerGauge(val rect: Rect, texture: Texture, dslot: DataSlotPower) extends Widget {
|
||||
val formater = new DecimalFormat("#,###")
|
||||
|
||||
@@ -125,6 +125,16 @@ case class StClassMacro(id: String, cls: String) extends DelayedStatement
|
||||
*/
|
||||
case class StIfHaveMod(mod: String, thn: List[Statement], els: List[Statement]) extends Statement
|
||||
|
||||
/**
|
||||
* Conditional block - checks if api is loaded
|
||||
* Syntax: ifAPI {string} { {statements} } [else { {statements} }]
|
||||
* Parser: [[net.bdew.lib.recipes.RecipeParser.ifApi]]
|
||||
* @param mod API modid
|
||||
* @param thn Statements to run if present
|
||||
* @param els Statements to run otherwise
|
||||
*/
|
||||
case class StIfHaveAPI(mod: String, thn: List[Statement], els: List[Statement]) extends Statement
|
||||
|
||||
/**
|
||||
* Conditional block - checks if mod is loaded
|
||||
* Can contain only delayed statements
|
||||
|
||||
@@ -10,11 +10,13 @@
|
||||
package net.bdew.lib.recipes
|
||||
|
||||
import java.io.Reader
|
||||
import net.minecraft.item.{Item, ItemStack}
|
||||
|
||||
import cpw.mods.fml.common.ModAPIManager
|
||||
import cpw.mods.fml.common.registry.GameRegistry
|
||||
import net.bdew.lib.{BdLib, Misc}
|
||||
import net.minecraft.block.Block
|
||||
import cpw.mods.fml.common.registry.GameRegistry
|
||||
import net.minecraftforge.oredict.{ShapelessOreRecipe, OreDictionary}
|
||||
import net.minecraft.item.{Item, ItemStack}
|
||||
import net.minecraftforge.oredict.{OreDictionary, ShapelessOreRecipe}
|
||||
|
||||
/**
|
||||
* Main recipe loader class
|
||||
@@ -219,6 +221,15 @@ class RecipeLoader {
|
||||
processStatementsSafe(els)
|
||||
}
|
||||
|
||||
case StIfHaveAPI(mod, thn, els) =>
|
||||
if (ModAPIManager.INSTANCE.hasAPI(mod)) {
|
||||
BdLib.logInfo("ifAPI: %s found", mod)
|
||||
processStatementsSafe(thn)
|
||||
} else {
|
||||
BdLib.logInfo("ifAPI: %s not found", mod)
|
||||
processStatementsSafe(els)
|
||||
}
|
||||
|
||||
case StClearRecipes(res) =>
|
||||
BdLib.logInfo("Clearing recipes that produce %s", res)
|
||||
delayedStatements = delayedStatements.filter({
|
||||
|
||||
@@ -11,9 +11,10 @@ package net.bdew.lib.recipes
|
||||
|
||||
import java.io.Reader
|
||||
|
||||
import scala.util.parsing.combinator._
|
||||
import org.apache.commons.lang3.StringEscapeUtils
|
||||
import net.minecraftforge.oredict.OreDictionary
|
||||
import org.apache.commons.lang3.StringEscapeUtils
|
||||
|
||||
import scala.util.parsing.combinator._
|
||||
|
||||
class RecipeParser extends JavaTokenParsers {
|
||||
// Allows C-style comments
|
||||
@@ -81,6 +82,10 @@ class RecipeParser extends JavaTokenParsers {
|
||||
case mod ~ thn ~ els => new StIfHaveMod(mod, thn, els.getOrElse(List.empty[Statement]))
|
||||
}
|
||||
|
||||
def ifAPI = ("ifAPI" ~> str) ~ ("{" ~> statements <~ "}") ~ ("else" ~> "{" ~> statements <~ "}").? ^^ {
|
||||
case mod ~ thn ~ els => new StIfHaveAPI(mod, thn, els.getOrElse(List.empty[Statement]))
|
||||
}
|
||||
|
||||
def ifOreDict = ("ifOreDict" ~> str) ~ ("{" ~> delayedStatements <~ "}") ~ ("else" ~> "{" ~> delayedStatements <~ "}").? ^^ {
|
||||
case id ~ thn ~ els => new StIfHaveOD(id, thn, els.getOrElse(List.empty[DelayedStatement]))
|
||||
}
|
||||
@@ -118,7 +123,7 @@ class RecipeParser extends JavaTokenParsers {
|
||||
| recipeSmelting
|
||||
)
|
||||
|
||||
def statement: Parser[Statement] = delayedStatement | ifMod | clearRecipes
|
||||
def statement: Parser[Statement] = delayedStatement | ifMod | ifAPI | clearRecipes
|
||||
|
||||
def statements = statement.*
|
||||
def delayedStatements = delayedStatement.*
|
||||
|
||||
@@ -9,10 +9,12 @@
|
||||
|
||||
package net.bdew.lib.recipes
|
||||
|
||||
import java.lang.reflect.Modifier
|
||||
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.item.Item
|
||||
|
||||
import scala.reflect.ClassTag
|
||||
import java.lang.reflect.Modifier
|
||||
|
||||
object Vanilla {
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
package net.bdew.lib.recipes.gencfg
|
||||
|
||||
import net.bdew.lib.recipes.{Statement, RecipeLoader}
|
||||
import net.bdew.lib.BdLib
|
||||
import net.bdew.lib.recipes.{RecipeLoader, Statement}
|
||||
|
||||
trait GenericConfigLoader extends RecipeLoader {
|
||||
val cfgStore: ConfigSection
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
|
||||
package net.bdew.lib.recipes.lootlist
|
||||
|
||||
import net.bdew.lib.recipes.gencfg.GenericConfigLoader
|
||||
import net.minecraftforge.oredict.OreDictionary
|
||||
import net.bdew.lib.recipes.StackRef
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.bdew.lib.BdLib
|
||||
import net.bdew.lib.recipes.StackRef
|
||||
import net.bdew.lib.recipes.gencfg.GenericConfigLoader
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraftforge.oredict.OreDictionary
|
||||
|
||||
/**
|
||||
* Loader mixin for loot lists
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
|
||||
package net.bdew.lib.render
|
||||
|
||||
import net.minecraft.client.renderer.texture.IIconRegister
|
||||
import net.minecraftforge.common.MinecraftForge
|
||||
import net.minecraftforge.client.event.TextureStitchEvent
|
||||
import net.bdew.lib.gui.{Texture, IconWrapper}
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent
|
||||
import net.bdew.lib.gui.{IconWrapper, Texture}
|
||||
import net.minecraft.client.renderer.texture.IIconRegister
|
||||
import net.minecraftforge.client.event.TextureStitchEvent
|
||||
import net.minecraftforge.common.MinecraftForge
|
||||
|
||||
/**
|
||||
* Allows loading of texture that don't belong to specific block or item into vanilla block/item atlas
|
||||
@@ -33,7 +33,7 @@ class IconPreloader(kind: Int) {
|
||||
icons += this
|
||||
}
|
||||
|
||||
import language.implicitConversions
|
||||
import scala.language.implicitConversions
|
||||
|
||||
implicit def entry2icon(v: TextureLoc) = v.texture.icon
|
||||
implicit def entry2texture(v: TextureLoc) = v.texture
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
package net.bdew.lib.render.connected
|
||||
|
||||
import net.bdew.lib.gui.Color
|
||||
import net.minecraft.util.IIcon
|
||||
import net.minecraft.world.IBlockAccess
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
case class FaceOverlay(icon: IIcon, color: Color) {
|
||||
def this(icon: IIcon, color: (Float, Float, Float)) = this(icon, new Color(color._1, color._2, color._3))
|
||||
}
|
||||
|
||||
trait BlockAdditionalRender {
|
||||
def getFaceOverlays(world: IBlockAccess, x: Int, y: Int, z: Int, face: ForgeDirection): List[FaceOverlay]
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
package net.bdew.lib.render.connected
|
||||
|
||||
import net.bdew.lib.block.BlockRef
|
||||
import net.minecraft.client.renderer.Tessellator
|
||||
import net.minecraft.util.IIcon
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
object ConnectedHelper {
|
||||
val edgeWidth = 1 / 16F
|
||||
|
||||
// Represents the rectangles of all edges/corners on a 2d pane
|
||||
// 701
|
||||
// 6 2
|
||||
// 543
|
||||
// 8 is a special case for the full face
|
||||
val faceEdges = Array(
|
||||
RectF(0, 1 - edgeWidth, 1, 1),
|
||||
RectF(1 - edgeWidth, 1 - edgeWidth, 1, 1),
|
||||
RectF(1 - edgeWidth, 0, 1, 1),
|
||||
RectF(1 - edgeWidth, 0, 1, edgeWidth),
|
||||
RectF(0, 0, 1, edgeWidth),
|
||||
RectF(0, 0, edgeWidth, edgeWidth),
|
||||
RectF(0, 0, edgeWidth, 1),
|
||||
RectF(0, 1 - edgeWidth, edgeWidth, 1),
|
||||
RectF(0, 0, 1, 1)
|
||||
)
|
||||
|
||||
val faceAdjanced = (for (x <- ForgeDirection.VALID_DIRECTIONS) yield x -> new FaceAdjanced(x)).toMap
|
||||
|
||||
// Maps edge number + face to 3d vertices
|
||||
val draw =
|
||||
(for ((rect, n) <- faceEdges.zipWithIndex; face <- ForgeDirection.VALID_DIRECTIONS)
|
||||
yield (face, n) -> new EdgeDraw(rect, face)).toMap
|
||||
|
||||
val brightnessMultiplier = Map(
|
||||
ForgeDirection.UP -> 1F,
|
||||
ForgeDirection.DOWN -> 0.5F,
|
||||
ForgeDirection.NORTH -> 0.8F,
|
||||
ForgeDirection.SOUTH -> 0.8F,
|
||||
ForgeDirection.WEST -> 0.6F,
|
||||
ForgeDirection.EAST -> 0.6F
|
||||
)
|
||||
|
||||
case class Vec3F(x: Float, y: Float, z: Float) {
|
||||
def *(m: Float) = Vec3F(x * m, y * m, z * m)
|
||||
def +(m: Vec3F) = Vec3F(x + m.x, y + m.y, z + m.z)
|
||||
def -(m: Vec3F) = Vec3F(x - m.x, y - m.y, z - m.z)
|
||||
def +(d: ForgeDirection) = Vec3F(x + d.offsetX, y + d.offsetY, z + d.offsetZ)
|
||||
def toInts = (x.toInt, y.toInt, z.toInt)
|
||||
def asBlockRef = BlockRef(x.toInt, y.toInt, z.toInt)
|
||||
}
|
||||
|
||||
case class RectF(x1: Float, y1: Float, x2: Float, y2: Float) {
|
||||
def corners = Seq(Vec2F(x1, y1), Vec2F(x2, y1), Vec2F(x2, y2), Vec2F(x1, y2))
|
||||
}
|
||||
|
||||
case class Vec2F(u: Float, v: Float)
|
||||
|
||||
case class VecPair(pos: Vec3F, tex: Vec2F)
|
||||
|
||||
class EdgeDraw(rect: RectF, face: ForgeDirection) {
|
||||
val vertices = rect.corners map { d =>
|
||||
val v = face match {
|
||||
case ForgeDirection.UP => Vec3F(d.u, 1, 1 - d.v)
|
||||
case ForgeDirection.DOWN => Vec3F(d.u, 0, d.v)
|
||||
case ForgeDirection.NORTH => Vec3F(1 - d.u, d.v, 0)
|
||||
case ForgeDirection.SOUTH => Vec3F(d.u, d.v, 1)
|
||||
case ForgeDirection.EAST => Vec3F(1, d.v, 1 - d.u)
|
||||
case ForgeDirection.WEST => Vec3F(0, d.v, d.u)
|
||||
case _ => sys.error("Invalid face")
|
||||
}
|
||||
VecPair(extend(v, 0.001F), d)
|
||||
}
|
||||
|
||||
def doDraw(pos: Vec3F, icon: IIcon) {
|
||||
for (v <- vertices)
|
||||
addVertextWithUV(v.pos + pos, mapToIcon(v.tex, icon))
|
||||
}
|
||||
}
|
||||
|
||||
def extend(v: Vec3F, o: Float) = Vec3F(
|
||||
if (v.x == 0F) -o else if (v.x == 1F) 1 + o else v.x,
|
||||
if (v.y == 0F) -o else if (v.y == 1F) 1 + o else v.y,
|
||||
if (v.z == 0F) -o else if (v.z == 1F) 1 + o else v.z
|
||||
)
|
||||
|
||||
def mapToIcon(v: Vec2F, i: IIcon) = Vec2F(i.getInterpolatedU(v.u * 16), i.getInterpolatedV((1 - v.v) * 16))
|
||||
|
||||
def addVertextWithUV(p: Vec3F, t: Vec2F) =
|
||||
Tessellator.instance.addVertexWithUV(p.x, p.y, p.z, t.u, t.v)
|
||||
|
||||
class FaceAdjanced(d: ForgeDirection) {
|
||||
val top = d match {
|
||||
case ForgeDirection.UP => ForgeDirection.NORTH
|
||||
case ForgeDirection.DOWN => ForgeDirection.SOUTH
|
||||
case _ => ForgeDirection.UP
|
||||
}
|
||||
|
||||
val right = d match {
|
||||
case ForgeDirection.UP => ForgeDirection.EAST
|
||||
case ForgeDirection.DOWN => ForgeDirection.EAST
|
||||
case ForgeDirection.NORTH => ForgeDirection.WEST
|
||||
case ForgeDirection.WEST => ForgeDirection.SOUTH
|
||||
case ForgeDirection.SOUTH => ForgeDirection.EAST
|
||||
case ForgeDirection.EAST => ForgeDirection.NORTH
|
||||
case _ => ForgeDirection.UNKNOWN
|
||||
}
|
||||
val bottom = top.getOpposite
|
||||
val left = right.getOpposite
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* 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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
package net.bdew.lib.render.connected
|
||||
|
||||
import cpw.mods.fml.client.registry.{ISimpleBlockRenderingHandler, RenderingRegistry}
|
||||
import net.bdew.lib.block.BlockRef
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.client.renderer.{RenderBlocks, Tessellator}
|
||||
import net.minecraft.world.IBlockAccess
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
import org.lwjgl.opengl.GL11
|
||||
|
||||
object ConnectedRenderer extends ISimpleBlockRenderingHandler {
|
||||
val id = RenderingRegistry.getNextAvailableRenderId
|
||||
RenderingRegistry.registerBlockHandler(this)
|
||||
|
||||
def doRenderItemSide(d: ForgeDirection, r: RenderBlocks, block: Block, meta: Int) = {
|
||||
val icon = r.getBlockIconFromSideAndMetadata(block, d.ordinal(), meta)
|
||||
Tessellator.instance.setNormal(d.offsetX, d.offsetY, d.offsetZ)
|
||||
d match {
|
||||
case ForgeDirection.DOWN => r.renderFaceYNeg(block, 0.0D, 0.0D, 0.0D, icon)
|
||||
case ForgeDirection.UP => r.renderFaceYPos(block, 0.0D, 0.0D, 0.0D, icon)
|
||||
case ForgeDirection.NORTH => r.renderFaceZNeg(block, 0.0D, 0.0D, 0.0D, icon)
|
||||
case ForgeDirection.SOUTH => r.renderFaceZPos(block, 0.0D, 0.0D, 0.0D, icon)
|
||||
case ForgeDirection.WEST => r.renderFaceXNeg(block, 0.0D, 0.0D, 0.0D, icon)
|
||||
case ForgeDirection.EAST => r.renderFaceXPos(block, 0.0D, 0.0D, 0.0D, icon)
|
||||
case _ => sys.error("Invalid side")
|
||||
}
|
||||
}
|
||||
|
||||
override def renderInventoryBlock(block: Block, metadata: Int, modelID: Int, renderer: RenderBlocks) {
|
||||
val tessellator = Tessellator.instance
|
||||
GL11.glTranslatef(-0.5F, -0.5F, -0.5F)
|
||||
|
||||
val edge = block.asInstanceOf[ConnectedTextureBlock].edgeIcon
|
||||
|
||||
for (side <- ForgeDirection.VALID_DIRECTIONS) {
|
||||
tessellator.startDrawingQuads()
|
||||
doRenderItemSide(side, renderer, block, metadata)
|
||||
val m = ConnectedHelper.brightnessMultiplier(side)
|
||||
ConnectedHelper.draw(side, 8).doDraw(ConnectedHelper.Vec3F(0, 0, 0), edge)
|
||||
tessellator.draw()
|
||||
}
|
||||
|
||||
GL11.glTranslatef(0.5F, 0.5F, 0.5F)
|
||||
}
|
||||
|
||||
override def renderWorldBlock(world: IBlockAccess, x: Int, y: Int, z: Int, block: Block, modelId: Int, renderer: RenderBlocks): Boolean = {
|
||||
renderer.renderStandardBlock(block, x, y, z)
|
||||
|
||||
val pos = ConnectedHelper.Vec3F(x, y, z)
|
||||
for (face <- ForgeDirection.VALID_DIRECTIONS)
|
||||
if (block.shouldSideBeRendered(world, x + face.offsetX, y + face.offsetY, z + face.offsetZ, face.ordinal()))
|
||||
drawFaceEdges(world, pos, face, block.asInstanceOf[ConnectedTextureBlock])
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
def drawFaceEdges(world: IBlockAccess, pos: ConnectedHelper.Vec3F, face: ForgeDirection, block: ConnectedTextureBlock) {
|
||||
val edge = block.edgeIcon
|
||||
val canConnect = block.canConnect(world, pos.asBlockRef, _: BlockRef)
|
||||
val sides = ConnectedHelper.faceAdjanced(face)
|
||||
|
||||
val m = ConnectedHelper.brightnessMultiplier(face)
|
||||
Tessellator.instance.setColorOpaque_F(m, m, m)
|
||||
|
||||
val fo = pos + face
|
||||
val b = block.getMixedBrightnessForBlock(world, fo.x.toInt, fo.y.toInt, fo.z.toInt)
|
||||
Tessellator.instance.setBrightness(b)
|
||||
|
||||
val U = !canConnect((pos + sides.top).asBlockRef)
|
||||
val D = !canConnect((pos + sides.bottom).asBlockRef)
|
||||
val L = !canConnect((pos + sides.left).asBlockRef)
|
||||
val R = !canConnect((pos + sides.right).asBlockRef)
|
||||
|
||||
if (!U && !R && !canConnect((pos + sides.top + sides.right).asBlockRef))
|
||||
ConnectedHelper.draw(face, 1).doDraw(pos, edge)
|
||||
|
||||
if (!U && !L && !canConnect((pos + sides.top + sides.left).asBlockRef))
|
||||
ConnectedHelper.draw(face, 7).doDraw(pos, edge)
|
||||
|
||||
if (!D && !R && !canConnect((pos + sides.bottom + sides.right).asBlockRef))
|
||||
ConnectedHelper.draw(face, 3).doDraw(pos, edge)
|
||||
|
||||
if (!D && !L && !canConnect((pos + sides.bottom + sides.left).asBlockRef))
|
||||
ConnectedHelper.draw(face, 5).doDraw(pos, edge)
|
||||
|
||||
if (U) ConnectedHelper.draw(face, 0).doDraw(pos, edge)
|
||||
if (D) ConnectedHelper.draw(face, 4).doDraw(pos, edge)
|
||||
if (R) ConnectedHelper.draw(face, 2).doDraw(pos, edge)
|
||||
if (L) ConnectedHelper.draw(face, 6).doDraw(pos, edge)
|
||||
|
||||
if (block.isInstanceOf[BlockAdditionalRender]) {
|
||||
val overlays = block.asInstanceOf[BlockAdditionalRender].getFaceOverlays(world, pos.x.toInt, pos.y.toInt, pos.z.toInt, face)
|
||||
for (overlay <- overlays) {
|
||||
Tessellator.instance.setColorOpaque_F(overlay.color.r, overlay.color.g, overlay.color.b)
|
||||
ConnectedHelper.draw(face, 8).doDraw(pos, overlay.icon)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override def shouldRender3DInInventory(modelId: Int) = true
|
||||
override def getRenderId = id
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
package net.bdew.lib.render.connected
|
||||
|
||||
import net.bdew.lib.block.BlockRef
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.util.IIcon
|
||||
import net.minecraft.world.IBlockAccess
|
||||
|
||||
trait ConnectedTextureBlock extends Block {
|
||||
def edgeIcon: IIcon
|
||||
def canConnect(world: IBlockAccess, origin: BlockRef, target: BlockRef): Boolean
|
||||
|
||||
override def getRenderType = ConnectedRenderer.id
|
||||
}
|
||||
@@ -9,15 +9,14 @@
|
||||
|
||||
package net.bdew.lib.rotate
|
||||
|
||||
import cpw.mods.fml.relauncher.Side
|
||||
import cpw.mods.fml.relauncher.SideOnly
|
||||
import java.util.EnumSet
|
||||
|
||||
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.entity.EntityLivingBase
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.util.{IIcon, MathHelper}
|
||||
import net.minecraft.world.IBlockAccess
|
||||
import net.minecraft.world.World
|
||||
import java.util.EnumSet
|
||||
import net.minecraft.world.{IBlockAccess, World}
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
package net.bdew.lib.rotate
|
||||
|
||||
import net.bdew.lib.data.base.{UpdateKind, TileDataSlots}
|
||||
import net.bdew.lib.data.DataSlotDirection
|
||||
import net.bdew.lib.data.base.{TileDataSlots, UpdateKind}
|
||||
|
||||
trait RotateableTile extends TileDataSlots {
|
||||
var rotation = DataSlotDirection("rotation", this).setUpdate(UpdateKind.SAVE, UpdateKind.WORLD)
|
||||
|
||||
@@ -9,10 +9,9 @@
|
||||
|
||||
package net.bdew.lib.rotate
|
||||
|
||||
import net.minecraft.block.ITileEntityProvider
|
||||
import net.minecraft.world.IBlockAccess
|
||||
import net.minecraft.world.World
|
||||
import cpw.mods.fml.common.FMLCommonHandler
|
||||
import net.minecraft.block.ITileEntityProvider
|
||||
import net.minecraft.world.{IBlockAccess, World}
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
package net.bdew.lib.tile
|
||||
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import net.minecraftforge.fluids._
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
import net.minecraftforge.fluids._
|
||||
|
||||
trait ExposeTank extends TileEntity with IFluidHandler {
|
||||
def getTankFromDirection(dir: ForgeDirection): IFluidTank
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
|
||||
package net.bdew.lib.tile
|
||||
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraft.network.{NetworkManager, Packet}
|
||||
import net.bdew.lib.Event
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity
|
||||
import net.minecraft.network.{NetworkManager, Packet}
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
|
||||
class TileExtended extends TileEntity {
|
||||
final val ACT_CLIENT = 1
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
package net.bdew.lib.tile.inventory
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.inventory.IInventory
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
|
||||
trait BaseInventory extends IInventory {
|
||||
var inv: Array[ItemStack] = new Array(getSizeInventory)
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
package net.bdew.lib.tile.inventory
|
||||
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.bdew.lib.items.ItemUtils
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
|
||||
trait BreakableInventoryTile extends TileEntity with BaseInventory {
|
||||
def dropItems() {
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
|
||||
package net.bdew.lib.tile.inventory
|
||||
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.{NBTTagList, NBTTagCompound}
|
||||
import net.bdew.lib.Misc
|
||||
import net.bdew.lib.tile.TileExtended
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.{NBTTagCompound, NBTTagList}
|
||||
|
||||
trait PersistentInventoryTile extends TileExtended with BaseInventory {
|
||||
persistLoad.listen((tag: NBTTagCompound) => {
|
||||
|
||||
Reference in new issue
Block a user