Compare commits

...
13 Commits
26 changed files with 367 additions and 80 deletions

No files matched your search

+2 -2
View File
@@ -1,5 +1,5 @@
bdlib.version=1.9.1
bdlib.version=1.9.4
curseforge.id=70496
minecraft.version=1.7.10
forge.version=10.13.4.1448-1.7.10
forge.version=10.13.4.1558-1.7.10
+1 -1
View File
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-bin.zip
+4
View File
@@ -9,6 +9,10 @@ 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.multiblock.tip.module=Can be installed in:
bdlib.multiblock.tip.controller=Possible modules:
bdlib.multiblock.tip.module.range= * %s (%s - %s)
bdlib.multiblock.tip.module.max= * %s (up to %s)
bdlib.rsmode.always=Always ON
bdlib.rsmode.never=Disabled
+5 -1
View File
@@ -8,7 +8,11 @@ bdlib.multiblock.face.down=Dessous
bdlib.multiblock.disabled=Désactivé
bdlib.multiblock.incomplete=Cette machine est incomplète, elle exige au moins :
bdlib.multiblock.notconnected=Pas connecté à une machine valide
bdlib.multiblock.toomanyoutputs=Trop de soties connectées, Incapable d'ajouter une nouvelle connexion
bdlib.multiblock.toomanyoutputs=Trop de sorties connectées, impossible d'ajouter une nouvelle connexion
bdlib.multiblock.tip.module=Peut être installé dans :
bdlib.multiblock.tip.controller=Modules possibles:
bdlib.multiblock.tip.module.range= * %s (%s - %s)
bdlib.multiblock.tip.module.max= * %s (plus de %s)
bdlib.rsmode.always=Toujours actif
bdlib.rsmode.never=Désactivé
+2 -1
View File
@@ -10,6 +10,7 @@
package net.bdew.lib
import java.util
import java.util.Locale
import cpw.mods.fml.common.{ICrashCallable, ModAPIManager, ModContainer}
@@ -20,7 +21,7 @@ object ApiReporter extends ICrashCallable {
val mods = new util.ArrayList[ModContainer]
val nameLookup = new util.HashMap[String, ModContainer]
ModAPIManager.INSTANCE.injectAPIModContainers(mods, nameLookup)
(for (mod <- mods.sortBy(_.getModId.toLowerCase)) yield
(for (mod <- mods.sortBy(_.getModId.toLowerCase(Locale.US))) yield
"\t\t* %s (%s) from %s".format(mod.getModId, mod.getVersion,
if (mod.getSource.isDirectory)
mod.getSource
+9 -9
View File
@@ -16,15 +16,15 @@ object DecFormat {
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 round(x: Double) = thousandsFmt.format(x).replace('\u00A0', ' ')
def round(x: Float) = thousandsFmt.format(x).replace('\u00A0', ' ')
def round(x: Int) = thousandsFmt.format(x).replace('\u00A0', ' ')
def dec2(x: Double) = dec2Fmt.format(x)
def dec2(x: Float) = dec2Fmt.format(x)
def dec2(x: Int) = dec2Fmt.format(x)
def dec2(x: Double) = dec2Fmt.format(x).replace('\u00A0', ' ')
def dec2(x: Float) = dec2Fmt.format(x).replace('\u00A0', ' ')
def dec2(x: Int) = dec2Fmt.format(x).replace('\u00A0', ' ')
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)
def short(x: Double) = (if (x > 10) thousandsFmt.format(x) else if (x > 1) dec1Fmt.format(x) else dec2Fmt.format(x)).replace('\u00A0', ' ')
def short(x: Float) = (if (x > 10) thousandsFmt.format(x) else if (x > 1) dec1Fmt.format(x) else dec2Fmt.format(x)).replace('\u00A0', ' ')
def short(x: Int) = (if (x > 10) thousandsFmt.format(x) else if (x > 1) dec1Fmt.format(x) else dec2Fmt.format(x)).replace('\u00A0', ' ')
}
+31
View File
@@ -10,6 +10,7 @@
package net.bdew.lib
import java.util
import java.util.Locale
import cpw.mods.fml.common.registry.GameRegistry
import cpw.mods.fml.common.versioning.VersionParser
@@ -140,5 +141,35 @@ object Misc {
if (f != null) getFluidColor(new FluidStack(f, 1)) else 0xFFFFFF
lazy val lineSeparator = System.getProperty("line.separator")
/**
* Provides something like java try-with-resources in scala
*/
def withAutoClose[T <: AutoCloseable, R](o: T)(f: T => R): R = {
val res = try {
f(o)
} catch {
case t1: Throwable =>
if (o != null) {
try {
o.close()
} catch {
case t2: Throwable =>
t1.addSuppressed(t2)
}
}
throw t1
}
if (o != null)
o.close()
res
}
def iconName(domain: String, name: String, path: String*) =
if (path.isEmpty)
"%s:%s".format(domain, name).toLowerCase(Locale.US)
else
"%s:%s/%s".format(domain, name, path.mkString("/")).toLowerCase(Locale.US)
}
+3 -1
View File
@@ -15,6 +15,8 @@ import net.minecraft.block.Block
import net.minecraft.block.material.Material
import net.minecraft.client.renderer.texture.IIconRegister
import scala.language.implicitConversions
trait NamedBlock extends Block {
def name: String
}
@@ -25,6 +27,6 @@ class SimpleBlock(val name: String, material: Material) extends Block(material)
@SideOnly(Side.CLIENT)
override def registerBlockIcons(reg: IIconRegister) {
blockIcon = reg.registerIcon(modId + ":" + name.toLowerCase)
blockIcon = reg.registerIcon(Misc.iconName(modId, name))
}
}
@@ -9,8 +9,11 @@
package net.bdew.lib.config
import net.bdew.lib.Misc
import net.bdew.lib.gui.{GuiHandler, GuiProvider}
import net.bdew.lib.machine.Machine
import net.bdew.lib.multiblock.MachineCore
import net.bdew.lib.multiblock.block.BlockModule
import net.bdew.lib.recipes.gencfg.ConfigSection
import net.minecraft.creativetab.CreativeTabs
@@ -25,5 +28,27 @@ class MachineManager(val tuning: ConfigSection, guiHandler: GuiHandler, creative
}
return machine
}
def load() {}
}
trait MachineManagerMultiblock extends MachineManager {
var controllers = Set.empty[MachineCore]
override def registerMachine[R <: Machine[_]](machine: R): R = {
super.registerMachine(machine)
if (machine.enabled) {
Misc.asInstanceOpt(machine, classOf[MachineCore]) foreach { controllerMachine =>
controllers += controllerMachine
controllerMachine.getController.machine = controllerMachine
}
}
machine
}
def getMachinesForBlock(b: BlockModule[_]): Map[MachineCore, (Int, Int)] = {
(for (machine <- controllers; max <- machine.modules.get(b.kind)) yield {
machine ->(machine.required.getOrElse(b.kind, 0), max)
}).toMap
}
}
+66 -17
View File
@@ -11,10 +11,11 @@ package net.bdew.lib.covers
import cpw.mods.fml.relauncher.{Side, SideOnly}
import net.bdew.lib.Misc
import net.bdew.lib.block.HasTE
import net.bdew.lib.block.{BlockRef, HasTE}
import net.bdew.lib.items.ItemUtils
import net.minecraft.block.Block
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.entity.player.{EntityPlayer, EntityPlayerMP}
import net.minecraft.item.ItemStack
import net.minecraft.util.IIcon
import net.minecraft.world.{IBlockAccess, World}
import net.minecraftforge.common.util.ForgeDirection
@@ -23,53 +24,101 @@ trait BlockCoverable[T <: TileCoverable] extends HasTE[T] {
@SideOnly(Side.CLIENT)
override def getRenderType = CoverRenderer.id
private def getCoverItem(w: IBlockAccess, x: Int, y: Int, z: Int, side: ForgeDirection): Option[(ItemCover, ItemStack, TileCoverable)] = {
val te = getTE(w, x, y, z)
for {
coverStack <- Option(te.covers(side).value)
coverItemMaybe <- Option(coverStack.getItem)
coverItem <- Misc.asInstanceOpt(coverItemMaybe, classOf[ItemCover])
} yield (coverItem, coverStack, te)
}
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)
// Shift+RightClick with empty hand should remove cover
if (player.getCurrentEquippedItem == null && player.isSneaking) {
for (cover <- Option(te.covers(side).value)) {
for {
cover <- Option(te.covers(side).value)
coverItem <- Misc.asInstanceOpt(cover.getItem, classOf[ItemCover])
} {
if (!world.isRemote) {
te.covers(side) := null
te.onCoversChanged()
ItemUtils.dropItemToPlayer(world, player, cover)
coverChanged(world, x, y, z, side)
ItemUtils.dropItemToPlayer(world, player, coverItem.onRemove(cover))
}
return true
}
}
// If held item is cover - try to install it
for {
activeStack <- Option(player.getCurrentEquippedItem)
activeItem <- Option(activeStack.getItem)
coverItem <- Misc.asInstanceOpt(activeItem, classOf[ItemCover])
if te.isValidCover(side, activeStack) && coverItem.isValidTile(te, activeStack)
} {
if (!world.isRemote) {
for (cover <- Option(te.covers(side).value))
ItemUtils.throwItemAt(world, te.xCoord + side.offsetX, te.yCoord + side.offsetY, te.zCoord + side.offsetZ, cover.copy())
if (!world.isRemote && player.isInstanceOf[EntityPlayerMP]) {
for {
oldCover <- Option(te.covers(side).value)
oldItem <- Misc.asInstanceOpt(oldCover.getItem, classOf[ItemCover])
} {
ItemUtils.throwItemAt(world, te.xCoord + side.offsetX, te.yCoord + side.offsetY, te.zCoord + side.offsetZ, oldItem.onRemove(oldCover))
}
te.covers(side) := activeStack.splitStack(1)
te.covers(side) := coverItem.onInstall(te, side, activeStack.splitStack(1), player.asInstanceOf[EntityPlayerMP])
if (activeStack.stackSize <= 0)
player.inventory.setInventorySlotContents(player.inventory.currentItem, null)
if (activeStack.stackSize <= 0) player.inventory.setInventorySlotContents(player.inventory.currentItem, null)
te.onCoversChanged()
coverChanged(world, x, y, z, side)
}
return true
}
// If has cover - let it handle the click
for ((item, stack, te) <- getCoverItem(world, x, y, z, side)) {
if (item.clickCover(te, side, stack, player)) return true
}
super.onBlockActivated(world, x, y, z, player, face, xOffs, yOffs, zOffs)
}
override def canProvidePower = true
override def isProvidingWeakPower(w: IBlockAccess, x: Int, y: Int, z: Int, side: Int): Int = {
val direction = Misc.forgeDirection(side).getOpposite
for ((item, stack, te) <- getCoverItem(w, x, y, z, direction)) {
if (item.isEmittingSignal(te, direction, stack)) return 15
}
0
}
def coverChanged(w: World, x: Int, y: Int, z: Int, side: ForgeDirection): Unit = {
val pos = BlockRef(x, y, z).neighbour(side)
w.notifyBlockOfNeighborChange(pos.x, pos.y, pos.z, pos.block(w).orNull)
}
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)
for ((item, stack, te) <- getCoverItem(w, x, y, z, side))
yield item.getCoverIcon(te, side, stack)
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.value))
ItemUtils.throwItemAt(world, x, y, z, cover)
if (!world.isRemote) {
val te = getTE(world, x, y, z)
for {
(dir, covOpt) <- te.covers
cover <- Option(covOpt.value)
item <- Misc.asInstanceOpt(cover.getItem, classOf[ItemCover])
} {
te.covers(dir) := null
ItemUtils.throwItemAt(world, x, y, z, item.onRemove(cover))
coverChanged(world, x, y, z, dir)
}
}
super.breakBlock(world, x, y, z, block, meta)
}
}
+7 -6
View File
@@ -23,12 +23,13 @@ object CoverRenderer extends BaseBlockRenderHandler {
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)
if (!renderer.hasOverrideBlockTexture)
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
}
}
+54 -3
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) bdew, 2013 - 2014
* Copyright (c) bdew, 2013 - 2015
* https://github.com/bdew/bdlib
*
* This mod is distributed under the terms of the Minecraft Mod Public
@@ -9,23 +9,74 @@
package net.bdew.lib.covers
import net.minecraft.entity.player.{EntityPlayer, EntityPlayerMP}
import net.minecraft.item.{Item, ItemStack}
import net.minecraft.util.IIcon
import net.minecraftforge.common.util.ForgeDirection
trait ItemCover extends Item {
/**
* @return true if tickCover should be called
*/
def isCoverTicking: Boolean
/**
* @param te Host TileEntity
* @param side Side the cover is installed on
* @param cover Cover ItemStack
* @return Icon to render, MUST be on terrain sprite sheet (0), not item!
*/
def getCoverIcon(stack: ItemStack): IIcon
def getCoverIcon(te: TileCoverable, side: ForgeDirection, cover: ItemStack): IIcon
/**
* Perform tick, called on server only
* @param te Host TileEntity
* @param side Side the cover is installed on
* @param cover Cover ItemStack
*/
def tickCover(te: TileCoverable, side: ForgeDirection, cover: ItemStack)
def tickCover(te: TileCoverable, side: ForgeDirection, cover: ItemStack): Unit = {}
/**
* Checks if this cover can be installed on a specific TE
* @param te Potential host TileEntity
* @param cover Cover ItemStack
* @return true if can be installed
*/
def isValidTile(te: TileCoverable, cover: ItemStack): Boolean
/**
* Handle click on covered side - called on both client and server
* @param te Host TileEntity
* @param side Side the cover is installed on
* @param cover Cover ItemStack
* @param player Player clicking the cover
* @return true if click was handled by cover
*/
def clickCover(te: TileCoverable, side: ForgeDirection, cover: ItemStack, player: EntityPlayer): Boolean = false
/**
* Check if cover is emitting RS signal
* @param te Host TileEntity
* @param side Side the cover is installed on
* @param cover Cover ItemStack
* @return true if cover is emitting RS signal
*/
def isEmittingSignal(te: TileCoverable, side: ForgeDirection, cover: ItemStack): Boolean = false
/**
* Called when cover is installed on a block - called only on server
* @param te Host TileEntity
* @param side Side the cover is installed on
* @param cover Cover ItemStack - do not modify!
* @param player Player entity doing the installation
* @return cover ItemStack - copy if modified
*/
def onInstall(te:TileCoverable, side: ForgeDirection, cover: ItemStack, player: EntityPlayerMP): ItemStack = cover
/**
* Called when cover is removed from block or block is destroyed - called only on server
* @param cover Cover ItemStack - do not modify!
* @return cover ItemStack - copy if modified
*/
def onRemove(cover: ItemStack): ItemStack = cover
}
+3 -1
View File
@@ -9,6 +9,8 @@
package net.bdew.lib.covers
import java.util.Locale
import net.bdew.lib.Misc
import net.bdew.lib.data.DataSlotItemStack
import net.bdew.lib.data.base.{TileDataSlots, UpdateKind}
@@ -17,7 +19,7 @@ import net.minecraftforge.common.util.ForgeDirection
trait TileCoverable extends TileDataSlots {
val covers = (ForgeDirection.VALID_DIRECTIONS map { x =>
x -> DataSlotItemStack("cover_" + x.toString.toLowerCase, this).setUpdate(UpdateKind.SAVE, UpdateKind.WORLD, UpdateKind.RENDER)
x -> DataSlotItemStack("cover_" + x.toString.toLowerCase(Locale.US), this).setUpdate(UpdateKind.SAVE, UpdateKind.WORLD, UpdateKind.RENDER)
}).toMap
/**
+9 -2
View File
@@ -23,6 +23,13 @@ trait GuiProvider {
def getContainer(te: TEClass, player: EntityPlayer): AnyRef
@SideOnly(Side.CLIENT)
def getGui(te: TileEntity, player: EntityPlayer): AnyRef = getGui(te.asInstanceOf[TEClass], player)
def getContainer(te: TileEntity, player: EntityPlayer): AnyRef = getContainer(te.asInstanceOf[TEClass], player)
def getGui(te: TileEntity, player: EntityPlayer): AnyRef =
if (te != null)
getGui(te.asInstanceOf[TEClass], player)
else null
def getContainer(te: TileEntity, player: EntityPlayer): AnyRef =
if (te != null)
getContainer(te.asInstanceOf[TEClass], player)
else null
}
+60
View File
@@ -0,0 +1,60 @@
/*
* Copyright (c) bdew, 2013 - 2015
* https://github.com/bdew/bdlib
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.helpers
import net.minecraft.util._
import scala.language.implicitConversions
class RichChatComponent(v: IChatComponent) {
def &(that: IChatComponent) = v.appendSibling(that)
private def applyStyle(f: ChatStyle => Unit) = {
f(v.getChatStyle)
v
}
def setColor(c: EnumChatFormatting) = applyStyle(_.setColor(c))
def setBold(b: Boolean) = applyStyle(_.setBold(b))
def setItalic(b: Boolean) = applyStyle(_.setItalic(b))
def setObfuscated(b: Boolean) = applyStyle(_.setObfuscated(b))
def setStrikethrough(b: Boolean) = applyStyle(_.setStrikethrough(b))
def setUnderlined(b: Boolean) = applyStyle(_.setUnderlined(b))
}
object ChatHelper {
object Color {
val BLACK = EnumChatFormatting.BLACK
val DARK_BLUE = EnumChatFormatting.DARK_BLUE
val DARK_GREEN = EnumChatFormatting.DARK_GREEN
val DARK_AQUA = EnumChatFormatting.DARK_AQUA
val DARK_RED = EnumChatFormatting.DARK_RED
val DARK_PURPLE = EnumChatFormatting.DARK_PURPLE
val GOLD = EnumChatFormatting.GOLD
val GRAY = EnumChatFormatting.GRAY
val DARK_GRAY = EnumChatFormatting.DARK_GRAY
val BLUE = EnumChatFormatting.BLUE
val GREEN = EnumChatFormatting.GREEN
val AQUA = EnumChatFormatting.AQUA
val RED = EnumChatFormatting.RED
val LIGHT_PURPLE = EnumChatFormatting.LIGHT_PURPLE
val YELLOW = EnumChatFormatting.YELLOW
val WHITE = EnumChatFormatting.WHITE
}
implicit def str2chat(s: String): ChatComponentText = new ChatComponentText(s)
implicit def str2rich(s: String): RichChatComponent = new RichChatComponent(new ChatComponentText(s))
implicit def pimpIChatComponent(v: IChatComponent): RichChatComponent = new RichChatComponent(v)
def C(s: String) = new ChatComponentText(s)
def L(s: String, params: IChatComponent*) = new ChatComponentTranslation(s, params: _*)
}
+1 -1
View File
@@ -24,6 +24,6 @@ class SimpleItem(val name: String) extends Item with NamedItem {
@SideOnly(Side.CLIENT)
override def registerIcons(reg: IIconRegister) {
itemIcon = reg.registerIcon(modId + ":" + name.toLowerCase)
itemIcon = reg.registerIcon(Misc.iconName(modId, name))
}
}
@@ -9,11 +9,16 @@
package net.bdew.lib.multiblock
import net.bdew.lib.machine.Machine
import net.bdew.lib.multiblock.block.BlockController
import net.bdew.lib.recipes.gencfg.{ConfigSection, EntryDouble}
trait MachineCore {
trait MachineCore extends {
this: Machine[_ <: BlockController[_]] =>
var tuning: ConfigSection
def getController: BlockController[_] = block
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))
@@ -9,17 +9,22 @@
package net.bdew.lib.multiblock.block
import net.bdew.lib.block.{BlockRef, HasTE}
import net.bdew.lib.multiblock.ResourceProvider
import net.bdew.lib.Misc
import net.bdew.lib.block.{BlockRef, BlockTooltip, HasTE}
import net.bdew.lib.multiblock.tile.TileController
import net.bdew.lib.multiblock.{MachineCore, ResourceProvider}
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.item.ItemStack
import net.minecraft.util.EnumChatFormatting
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 {
extends Block(material) with HasTE[T] with ConnectedTextureBlock with BlockTooltip {
var machine: MachineCore = null
def resources: ResourceProvider
@@ -39,6 +44,23 @@ abstract class BlockController[T <: TileController](val name: String, material:
getTE(world, x, y, z).onClick(player)
return true
}
override def getTooltip(stack: ItemStack, player: EntityPlayer, advanced: Boolean): List[String] = {
List(Misc.toLocal("bdlib.multiblock.tip.controller")) ++ (
for ((kind, max) <- machine.modules) yield {
val name = Misc.toLocalF(resources.getModuleName(kind))
if (machine.required.getOrElse(kind, 0) > 0) {
Misc.toLocalF("bdlib.multiblock.tip.module.range",
EnumChatFormatting.YELLOW + name + EnumChatFormatting.RESET,
EnumChatFormatting.YELLOW + machine.required(kind).toString + EnumChatFormatting.RESET,
EnumChatFormatting.YELLOW + max.toString + EnumChatFormatting.RESET)
} else {
Misc.toLocalF("bdlib.multiblock.tip.module.max",
EnumChatFormatting.YELLOW + name + EnumChatFormatting.RESET,
EnumChatFormatting.YELLOW + max.toString + EnumChatFormatting.RESET)
}
})
}
}
@@ -9,7 +9,9 @@
package net.bdew.lib.multiblock.block
import net.bdew.lib.block.{BlockRef, HasTE}
import net.bdew.lib.Misc
import net.bdew.lib.block.{BlockRef, BlockTooltip, HasTE}
import net.bdew.lib.config.MachineManagerMultiblock
import net.bdew.lib.multiblock.tile.TileModule
import net.bdew.lib.multiblock.{ResourceProvider, Tools}
import net.bdew.lib.render.connected.ConnectedTextureBlock
@@ -18,11 +20,11 @@ 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.util.{ChatComponentTranslation, EnumChatFormatting}
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 {
abstract class BlockModule[T <: TileModule](val name: String, val kind: String, material: Material, val TEClass: Class[T], val machines: MachineManagerMultiblock)
extends Block(material) with HasTE[T] with ConnectedTextureBlock with BlockTooltip {
def resources: ResourceProvider
@@ -60,10 +62,27 @@ abstract class BlockModule[T <: TileModule](val name: String, val kind: String,
p <- te.connected.value
bl <- p.block(world)
} yield {
bl.onBlockActivated(world, p.x, p.y, p.z, player, meta, 0, 0, 0)
}) getOrElse {
bl.onBlockActivated(world, p.x, p.y, p.z, player, meta, 0, 0, 0)
}) getOrElse {
player.addChatMessage(new ChatComponentTranslation("bdlib.multiblock.notconnected"))
}
true
}
override def getTooltip(stack: ItemStack, player: EntityPlayer, advanced: Boolean): List[String] = {
List(Misc.toLocal("bdlib.multiblock.tip.module")) ++ (
for ((machine, (min, max)) <- machines.getMachinesForBlock(this)) yield {
val name = machine.getController.getLocalizedName
if (min > 0) {
Misc.toLocalF("bdlib.multiblock.tip.module.range",
EnumChatFormatting.YELLOW + name + EnumChatFormatting.RESET,
EnumChatFormatting.YELLOW + min.toString + EnumChatFormatting.RESET,
EnumChatFormatting.YELLOW + max.toString + EnumChatFormatting.RESET)
} else {
Misc.toLocalF("bdlib.multiblock.tip.module.max",
EnumChatFormatting.YELLOW + name + EnumChatFormatting.RESET,
EnumChatFormatting.YELLOW + max.toString + EnumChatFormatting.RESET)
}
})
}
}
@@ -9,6 +9,8 @@
package net.bdew.lib.multiblock.gui
import java.util.Locale
import net.bdew.lib.Misc
import net.bdew.lib.gui.widgets.Widget
import net.bdew.lib.gui.{Point, Rect, Texture}
@@ -43,7 +45,7 @@ class WidgetOutputIcon(p: Point, te: CIOutputFaces, output: Int) extends Widget
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))
tip += "%d, %d, %d - %s".format(bf.x, bf.y, bf.z, Misc.toLocal("bdlib.multiblock.face." + bf.face.toString.toLowerCase(Locale.US)))
}
} else {
tip += Misc.toLocal("bdlib.multiblock.disabled")
@@ -9,6 +9,8 @@
package net.bdew.lib.multiblock.gui
import java.util.Locale
import net.bdew.lib.Misc
import net.bdew.lib.gui.widgets.{WidgetButtonIcon, WidgetSubContainer}
import net.bdew.lib.gui.{Point, Rect}
@@ -37,7 +39,7 @@ class WidgetRSConfig(te: CIOutputFaces, output: Int, p: Point) extends WidgetSub
override def draw(mouse: Point) {
bt.icon = icons(cfg.rsMode)
bt.hover = Misc.toLocal("bdlib.rsmode." + cfg.rsMode.toString.toLowerCase)
bt.hover = Misc.toLocal("bdlib.rsmode." + cfg.rsMode.toString.toLowerCase(Locale.US))
super.draw(mouse)
}
@@ -10,21 +10,17 @@
package net.bdew.lib.multiblock.tile
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.util.{ChatComponentTranslation, ChatStyle, EnumChatFormatting}
abstract class TileControllerGui extends TileController {
def openGui(player: EntityPlayer)
def onClick(player: EntityPlayer) = {
import net.bdew.lib.helpers.ChatHelper._
val missing = cfg.required.filter({ case (mod, cnt) => getNumOfModules(mod) < cnt })
if (missing.nonEmpty) {
player.addChatMessage(new ChatComponentTranslation("bdlib.multiblock.incomplete")
.setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED)))
player.addChatMessage(L("bdlib.multiblock.incomplete").setColor(Color.RED))
for ((mod, cnt) <- missing)
player.addChatMessage(
new ChatComponentTranslation("- %s %s", Integer.valueOf(cnt),
new ChatComponentTranslation(resources.getModuleName(mod)))
.setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED)))
player.addChatMessage(L("- %s %s", cnt.toString, L(resources.getModuleName(mod))).setColor(Color.RED))
} else openGui(player)
}
+13 -13
View File
@@ -12,7 +12,7 @@ package net.bdew.lib.recipes
import java.io._
import cpw.mods.fml.common.FMLCommonHandler
import net.bdew.lib.BdLib
import net.bdew.lib.{BdLib, Misc}
object RecipesHelper {
/**
@@ -26,15 +26,14 @@ object RecipesHelper {
def loadConfigs(modName: String, listResource: String, configDir: File, resBaseName: String, loader: RecipeLoader) {
BdLib.logInfo("Loading internal config files for mod %s", modName)
val listReader = new BufferedReader(new InputStreamReader(getClass.getResourceAsStream(listResource)))
val internals = Iterator.continually(listReader.readLine)
.takeWhile(_ != null)
.map(_.trim)
.filterNot(_.startsWith("#"))
.filterNot(_.isEmpty)
.toList
listReader.close()
val internals = Misc.withAutoClose(new BufferedReader(new InputStreamReader(getClass.getResourceAsStream(listResource)))) { listReader =>
Iterator.continually(listReader.readLine)
.takeWhile(_ != null)
.map(_.trim)
.filterNot(_.startsWith("#"))
.filterNot(_.isEmpty)
.toList
}
val overrideDir = new File(configDir, "overrides")
if (!overrideDir.exists()) overrideDir.mkdir()
@@ -44,9 +43,10 @@ object RecipesHelper {
if (overrideFile.exists()) {
tryLoadConfig(new FileReader(overrideFile), overrideFile.getCanonicalPath, modName, loader)
} else {
val resource = resBaseName + fileName
tryLoadConfig(new InputStreamReader(getClass.getResourceAsStream(resource)),
getClass.getResource(resource).toString, modName, loader)
val url = getClass.getResource(resBaseName + fileName)
Misc.withAutoClose(url.openStream()) { stream =>
tryLoadConfig(new InputStreamReader(stream), url.toString, modName, loader)
}
}
}
@@ -9,6 +9,8 @@
package net.bdew.lib.recipes.gencfg
import java.util.Locale
import net.bdew.lib.gui.Color
abstract class ConfigEntry
@@ -43,7 +45,7 @@ case class ConfigSection(pfx: String = "") extends ConfigEntry with Iterable[(St
def getSection(id: String) = getRaw(id, classOf[ConfigSection])
final val trueVals = Set("y", "true", "yes", "on")
def getBoolean(id: String) = trueVals.contains(getString(id).toLowerCase)
def getBoolean(id: String) = trueVals.contains(getString(id).toLowerCase(Locale.US))
def hasValue(id: String) = raw.isDefinedAt(id)
+1 -1
View File
@@ -13,5 +13,5 @@ import net.bdew.lib.data.DataSlotDirection
import net.bdew.lib.data.base.{TileDataSlots, UpdateKind}
trait RotatableTile extends TileDataSlots {
var rotation = DataSlotDirection("rotation", this).setUpdate(UpdateKind.SAVE, UpdateKind.WORLD)
var rotation = DataSlotDirection("rotation", this).setUpdate(UpdateKind.SAVE, UpdateKind.WORLD, UpdateKind.RENDER)
}
@@ -9,6 +9,8 @@
package net.bdew.lib.sensors.multiblock
import java.util.Locale
import cpw.mods.fml.relauncher.{Side, SideOnly}
import net.bdew.lib.Misc
import net.bdew.lib.gui._
@@ -102,7 +104,7 @@ trait SensorOutput extends GenericSensorType[TileEntity, Boolean] {
val bf = faces(output)
bf.origin.block(te.getWorldObj) foreach { block =>
list :+= block.getLocalizedName
list :+= "%d, %d, %d - %s".format(bf.x, bf.y, bf.z, Misc.toLocal("bdlib.multiblock.face." + bf.face.toString.toLowerCase))
list :+= "%d, %d, %d - %s".format(bf.x, bf.y, bf.z, Misc.toLocal("bdlib.multiblock.face." + bf.face.toString.toLowerCase(Locale.US)))
}
}
list