Compare commits

...
106 Commits
Author SHA1 Message Date
bdew 9ee12091e6 Modules dataslot in multiblock controlers should not trigger render updates 2015-06-27 19:00:12 +03:00
bdew 08ccf07dfb Don't trigger chunk updates if somethings changes UpdateKind.WORLD dataslot on client. 2015-06-27 18:59:35 +03:00
bdew 382c21f732 Added KeepData mixins for blocks that keep their stuff when broken. 2015-06-24 15:50:23 +03:00
bdew 17e4bf3a2f BlockTooltip will now use the new HasItemBlock trait 2015-06-24 15:50:09 +03:00
bdew ebe2c1f34a Added HasItemBlock - trait that tells BlockManager and Machine to register custom ItemBlocks. Replaces old itemClass parameter. Version bumped to 1.9.0 2015-06-24 15:49:00 +03:00
bdew fae2825e7b Added RichNBTTagCompound.toItemStack 2015-06-24 12:05:48 +03:00
bdew b2e138f3cd TileBaseProcessor shouldn't include BreakableInventoryTile 2015-06-24 12:05:02 +03:00
bdew 9d897d0663 getActiveModId will return <unknown> instead of null 2015-06-24 12:03:58 +03:00
bdew 497917185c BreakableInventoryBlock now checks that the TileEntity extends BreakableInventoryTile at compile time 2015-06-23 11:19:03 +03:00
bdew 9ff7a75604 Build against forge 10.13.4.1448, updated to gradle 2.4 2015-06-10 11:24:27 +03:00
bdew f8bb1e8fbb Added a way to manually run ServerTickExecutionContext 2015-06-08 15:44:16 +03:00
bdew a530c66680 Added ItemBlock with tooltip 2015-06-02 16:45:22 +03:00
bdew 26af828491 Added BlockManager.registerLegacyTileEntity 2015-06-02 14:37:27 +03:00
bdew 1c0913d674 Code cleanup 2015-06-02 13:52:51 +03:00
bdew 895cfd9cb6 Improved NBT constructor 2015-05-31 15:40:08 +03:00
bdew f43dd28e03 Added easy NBT constructor - see https://gist.github.com/bdew/0a44363dcac4be85415c 2015-05-25 15:29:31 +03:00
bdew 289f8f7120 derp 2015-05-24 04:03:23 +03:00
bdew e7787fb9ca bumped version to 1.8.0, removed deprecated methods 2015-05-24 04:01:36 +03:00
bdew 58e336f8a9 Misc.haveModVersion should check APIs too, added getModVersion 2015-05-24 04:00:23 +03:00
bdew bea6a13896 Added async helpers and ServerTickExecutionContext (executes futures in server thread using tick event) 2015-05-21 18:05:33 +03:00
bdew 793ceb0024 Merge pull request #16 from Mazdallier/patch-1
Create fr_FR.lang
2015-05-13 12:07:16 +03:00
Yves 66d9be58c8 Update fr_FR.lang
--file return back
2015-05-12 17:13:57 +02:00
Yves 87d64208c8 Create fr_FR.lang 2015-05-12 15:59:10 +02:00
bdew 6f6496c1e3 /oredistribution - added dense ore support 2015-05-12 16:04:44 +03:00
bdew 934e984abf /oredistribution - Added option to dump to file 2015-05-12 16:02:03 +03:00
bdew 4900537a82 /oredistribution - Fixed meta detection with some ores (e.g. lapis) 2015-05-12 10:19:37 +03:00
bdew 31b5ab9d52 Added /oredistribution command 2015-05-10 22:37:04 +03:00
bdew 8a4ccf7d81 Prevent build failure when CF api key is not available 2015-05-10 15:49:37 +03:00
bdew 429107215f Allow fractional chances in config lootlists 2015-05-10 15:36:31 +03:00
bdew 0c60d596b6 Jenkins will now upload builds to curseforge 2015-05-10 15:35:45 +03:00
bdew da35094895 Merge pull request #14 from theelixzammuto/mc1710
Added Italian Localization
2015-04-27 23:30:19 +03:00
theelixzammuto 83d30f12c2 Added Italian Localization 2015-04-26 21:42:29 +02:00
bdew 8d4484ca18 DataSlotTankRestricted now takes fluid object instead of fluid ID 2015-04-20 14:53:25 +03:00
bdew 624df87299 Updated to grade 2.3, reworked build script to use properties file, changed version format to include MC version 2015-04-20 14:37:23 +03:00
bdew 18b4f19dab Compatibility fix for forge 10.13.3.x 2015-04-14 19:29:13 +03:00
bdew 00b32712a0 Added TankEmulator 2015-04-02 11:22:47 +03:00
bdew 2a008aa093 Refactored nbt helper 2015-04-02 10:29:28 +03:00
bdew 745170415e changed SimpleGenericSensor.parameters back to GenericSensorParameter for greater flexibility 2015-03-30 14:50:48 +03:00
bdew 69b8e80c5f Removed unused field from DataSlotResource and fixed warning 2015-03-30 14:49:54 +03:00
bdew 93ccc42429 Refactored some common code into bdlib, added ability for modules to decide if they can connect to a controller 2015-03-25 17:34:13 +02:00
bdew dc567bd1be More work on sensors 2015-03-25 16:34:46 +02:00
bdew 516133ee0a Fixed multiple derps in 61ba86d451 2015-03-25 16:18:54 +02:00
bdew 28de3620a2 Added human readable errors to NBTTypes 2015-03-25 13:28:18 +02:00
bdew 61ba86d451 Added NBTHelper, changed OutputConfigFluid to use moving average 2015-03-25 13:11:52 +02:00
bdew 8e65772cae More work on sensor system 2015-03-25 10:46:18 +02:00
bdew 284cdfc970 Fixed crash on dedicated servers (bdew/generators#29) 2015-03-24 13:47:58 +02:00
bdew bae688c366 More sensor changes 2015-03-23 17:42:36 +02:00
bdew d3952b69d0 More work on sensor system 2015-03-22 16:14:29 +02:00
bdew 399abf1054 Attempt to Fix getWorldObj reobfuscation shenanigans 2015-03-18 10:40:16 +02:00
bdew f66b97d0cc Refactored TileDataSlots into a base trait DataSlotContainer that can be implemented by other things 2015-03-15 10:20:19 +02:00
bdew 13778072c0 derp 2015-03-12 17:03:39 +02:00
bdew 7dc95fcce1 Give a sensible error if trying to use a Block with no matching ItemBlock in recipes 2015-03-12 17:01:11 +02:00
bdew b71db73b11 Allowed custom ItemBlock registration in BlockManager 2015-03-11 18:00:58 +02:00
bdew 530d5add82 Moved block rotation from player camera logic into a separate object 2015-03-11 18:00:32 +02:00
bdew 3dd917b2a0 Added BlockAccessProxy 2015-03-11 17:06:53 +02:00
bdew 8f44111b4c Fixed item rendering for rotated blocks 2015-03-06 20:56:23 +02:00
bdew 8415ee7a00 Added slot types for sensors 2015-03-04 11:03:06 +02:00
bdew 6439ef8f08 Added Misc.prevInSeq, Added SimpleInventory 2015-03-04 11:02:37 +02:00
bdew dc59ee3d31 Added RotatedBlockRenderer and support for rotated blocks to ConnectedRenderer 2015-03-03 17:47:32 +02:00
bdew 9ae4935fd9 Added sensor system
Bump version
2015-03-03 17:46:45 +02:00
bdew 0929ba9278 Java 6 doesn't have System.lineSeparator *facepalm* 2015-02-26 14:55:18 +02:00
bdew 1003aa1d6a Prevent update spam in tank and resource dataslots when they don't actually change (bdew/pressure#34) 2015-02-26 14:29:04 +02:00
bdew 64c0484c2d Added ApiReporter 2015-02-24 17:23:45 +02:00
bdew 8e90643ea1 GUI update packets are now timestamped, packets from the past will be ignored 2015-02-22 11:12:16 +02:00
bdew a232ce52f3 Build against forge 10.13.2.1291 2015-02-20 13:23:11 +02:00
bdew 35b3a77582 Fixed BlockRef crash on dedicated servers (bdew/generators#26) 2015-02-20 13:23:11 +02:00
bdew be3a1cf2aa Merge pull request #10 from DragonsLover/mc1710
Adding French Canadian language
2015-02-20 06:15:21 +02:00
DragonsLover e0f5d0ceda Adding French Canadian language 2015-02-19 23:14:00 -05:00
bdew e4169f7a5d Fixed Rect.contains being off by 1 2015-02-19 17:56:50 +02:00
bdew eb75a26c40 Moving dataslot classes to bdlib 2015-02-19 12:04:13 +02:00
bdew 3431a6910e Prevent access to invalid coordinates from BlockRef 2015-02-19 01:44:07 +02:00
bdew 02598183b8 Added CIItemInput 2015-02-18 17:52:40 +02:00
bdew 70c19bff5b Lowered log level of some spammy messages in config system to Debug (bdew/gendustry#81) 2015-02-18 12:01:31 +02:00
bdew 6a78467232 Fixed DataSlotResource.drainFluid draining 2x (bdew/generators#21) 2015-02-09 00:21:38 +02:00
bdew 561833db33 Refactored SlotSet to prevent textures being initialized on dedicated servers (bdew/generators#23) 2015-02-08 23:39:37 +02:00
bdew 0e345e6675 Added DecFormat.short 2015-02-05 00:52:42 +02:00
bdew e78e565ec8 Less retarded way to prevent duplicate class files in deobf 2015-02-04 21:57:52 +02:00
bdew 573330efd3 Prevent leftover fractional resources due to FP rounding errors 2015-02-04 20:27:51 +02:00
bdew 5e7c8bda2f attempt to de-derpify unobfuscated jars 2015-01-05 16:03:05 +02:00
bdew 9346d95052 Huge typos and code style cleanup 2014-12-23 17:54:59 +02:00
bdew f0169a15e5 updated copyright header and minor cleanup 2014-12-23 14:41:32 +02:00
bdew 1da90af3f1 Added multiblock stuff for item output and slot selection 2014-12-23 14:34:54 +02:00
bdew b015636514 Added InventoryProxy and MultipleInventoryAdapter 2014-12-23 14:29:13 +02:00
bdew 610be18c74 Added resource system 2014-12-23 14:27:21 +02:00
bdew 9c977904ab Added hack to the gradle script to prevent IDEA14 from derping 2014-12-18 16:43:11 +02:00
bdew cc107d7466 Version bump 2014-12-18 11:26:55 +02:00
bdew 4284f11ec4 Added DataSlotDouble 2014-12-18 11:26:25 +02:00
bdew 300726e660 reworked OutputConfig &co to be easier to extend 2014-12-18 11:26:12 +02:00
bdew 02850b9f85 added DecFormat, some cleanup 2014-12-18 11:20:18 +02:00
bdew 1618931c6d Allow fluid gauge to have no overlay, fixed typo 2014-11-05 16:29:59 +02:00
bdew 5854625700 Added serialization helpers for ItemStack and NBTTagCompound 2014-10-28 10:04:57 +02:00
bdew 8bbab862ab Added RecipesHelper with some shared code for config system loading 2014-10-19 17:16:59 +03:00
bdew 9e83d04487 Build with newer forge 2014-10-19 17:16:15 +03:00
bdew 9202b27340 Added renderer for covers (to allow partially showing the underlying texture) - bdew/gendustry#57 2014-10-15 12:09:08 +03:00
bdew 70ee9fabd6 Added BaseBlockRenderHandler and RenderUtils (some common code moved there) 2014-10-15 12:09:08 +03:00
bdew 78d9bed924 Merge pull request #7 from nalimleinad/mc1710
Create cs_CZ.lang
2014-10-14 13:44:19 +03:00
nalimleinad 92517cdcec Create cs_CZ.lang 2014-10-13 15:30:59 +02:00
bdew bcb8edc8a5 Improved handling of missing icons of fluids and in Texture class 2014-10-08 12:11:53 +03:00
bdew 9a837361e7 /dumpregistry will now show actual items registered in OD 2014-10-06 13:51:40 +03:00
bdew 5ae0461f10 Recipe parser/loader rework, see http://bdew.net/bacon/ for description of new format 2014-10-06 13:51:38 +03:00
bdew b3f8fb3c56 Added PlayerCache - a generic player->whatever map that auto-clears on server restart, logoff, respawn, etc. 2014-09-23 14:12:13 +03:00
bdew 023ae4d77f Added another version of Misc.asInstanceOpt that's easier to use with map, etc. 2014-09-23 14:12:13 +03:00
bdew b1e0e70fc4 Added WidgetSimpleIcon 2014-09-23 14:12:13 +03:00
bdew 5f01716310 Made network message type bound to a specific channel, this should give compile-time errors for sending messages on the wrong channel. Messages should now inherit from YourChannelObject.Message 2014-09-23 14:12:13 +03:00
bdew 0976fb4acc Merge pull request #5 from ViKaleidoscope/patch-1
Create zh_CN.lang
2014-09-19 09:25:35 +03:00
∑( ° △ °|||) 4effeafbb7 Create zh_CN.lang 2014-09-19 12:54:59 +08:00
217 changed files with 4192 additions and 1054 deletions

No files matched your search

+37 -13
View File
@@ -21,21 +21,30 @@ buildscript {
apply plugin: 'scala'
apply plugin: 'forge'
version = "1.4.4"
file "build.properties" withReader {
def prop = new Properties()
prop.load(it)
ext.config = new ConfigSlurper().parse prop
}
if (project.hasProperty('forgeOverride')) {
config.forge.version = forgeOverride
}
if (project.hasProperty('buildnum')) {
project.version = project.version + '.' + project.buildnum
ext.simpleVersion = "${config.bdlib.version}.${project.buildnum}"
} else {
project.version = "0-SNAPSHOT"
ext.simpleVersion = "${config.bdlib.version}-DEV"
}
version = simpleVersion + '-mc' + config.minecraft.version
group = "net.bdew"
archivesBaseName = "bdlib"
ext.versuffix = "mc1710"
minecraft {
version = "1.7.10-10.13.0.1180"
replace("BDLIB_VER", project.version)
version = "${config.minecraft.version}-${config.forge.version}"
replace("BDLIB_VER", simpleVersion.toString())
}
import org.apache.tools.ant.filters.ReplaceTokens
@@ -49,6 +58,7 @@ sourceSets {
resources {
srcDir 'resources'
}
output.resourcesDir = output.classesDir // Hack for IDEA
}
}
@@ -65,15 +75,18 @@ processResources {
}
task sourceJar(type: Jar) {
from sourceSets.main.allSource
classifier "sources"
}
task deobfJar(type: Jar) {
from sourceSets.main.output
classifier "dev"
duplicatesStrategy "exclude"
}
jar {
appendix = project.versuffix
afterEvaluate { project ->
// Fudge the inputs of source jars so we get the version after replacements
tasks.getByPath(":sourceJar").from(tasks.getByPath(":sourceMainScala").outputs.files)
}
artifacts {
@@ -87,10 +100,7 @@ publishing {
publications {
maven(MavenPublication) {
artifact deobfJar
artifact sourceJar {
classifier "sources"
}
artifact sourceJar
}
}
repositories {
@@ -98,4 +108,18 @@ publishing {
url "file://var/www/maven"
}
}
}
apply plugin: 'curseforge'
curse {
projectId = config.curseforge.id
apiKey = project.hasProperty("curseForgeApiKey") ? project.curseForgeApiKey : ""
releaseType = 'alpha'
artifact = jar
changelog = project.hasProperty("changelog") ? project.changelog : "No changelog available"
additionalArtifact deobfJar
additionalArtifact sourceJar
}
+5
View File
@@ -0,0 +1,5 @@
bdlib.version=1.9.0
curseforge.id=70496
minecraft.version=1.7.10
forge.version=10.13.4.1448-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.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-bin.zip
Vendored Regular → Executable
View File
File mode changed.
+19
View File
@@ -0,0 +1,19 @@
bdlib.multiblock.face.north=Sever
bdlib.multiblock.face.south=Jih
bdlib.multiblock.face.east=Západ
bdlib.multiblock.face.west=Východ
bdlib.multiblock.face.up=Vršek
bdlib.multiblock.face.down=Spodek
bdlib.multiblock.disabled=Zakázáno
bdlib.multiblock.incomplete=Tento stroj není kompletní, ještě potřebuje alespoň:
bdlib.multiblock.notconnected=Nepřipojeno ke správnému stroji
bdlib.multiblock.toomanyoutputs=Připojeno příliš mnoho výstupů, nemohu získat nové připojení
bdlib.rsmode.always=Vždy ZAPNUTO
bdlib.rsmode.never=Zakázáno
bdlib.rsmode.rs_on=Povoleno při ruditovém signálu
bdlib.rsmode.rs_off=Zakázáno při ruditovém signálu
bdlib.label.empty=Prázdný
+7
View File
@@ -17,3 +17,10 @@ bdlib.rsmode.rs_off=Disable on redstone
bdlib.label.empty=Empty
bdlib.oredistribution.usage=/oredistribution <radius> [<min height>] [<max height>] [--file]
bdlib.oredistribution.start1=Checking ore distribution in (%s,%s,%s) to (%s,%s,%s) dim %s
bdlib.oredistribution.start2=Server may lag for a while
bdlib.oredistribution.entry=%s %s - %s (%s%%)
bdlib.oredistribution.warn=%s Warning: %s has multiple variants generated:
bdlib.oredistribution.saved=Ore distribution dumped to %s
bdlib.oredistribution.error=Failed to save ore distribution dump: %s
+18
View File
@@ -0,0 +1,18 @@
bdlib.multiblock.face.north=Nord
bdlib.multiblock.face.south=Sud
bdlib.multiblock.face.east=Est
bdlib.multiblock.face.west=Ouest
bdlib.multiblock.face.up=Haut
bdlib.multiblock.face.down=Bas
bdlib.multiblock.disabled=Désactivé(e)
bdlib.multiblock.incomplete=Cette machine est incomplète, elle requiert au moins :
bdlib.multiblock.notconnected=Pas connecté(e) à une machine valide
bdlib.multiblock.toomanyoutputs=Trop de sorties connectées, incapable d'attacher de nouvelles connexions
bdlib.rsmode.always=Toujours en marche
bdlib.rsmode.never=Désactivé(e)
bdlib.rsmode.rs_on=Activer par la redstone
bdlib.rsmode.rs_off=Désactiver par la redstone
bdlib.label.empty=Vide
+26
View File
@@ -0,0 +1,26 @@
bdlib.multiblock.face.north=Nord
bdlib.multiblock.face.south=Sud
bdlib.multiblock.face.east=Est
bdlib.multiblock.face.west=Ouest
bdlib.multiblock.face.up=Dessus
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.rsmode.always=Toujours actif
bdlib.rsmode.never=Désactivé
bdlib.rsmode.rs_on=Activé par redstone
bdlib.rsmode.rs_off=Désactivé par redstone
bdlib.label.empty=Vide
bdlib.oredistribution.usage=/oredistribution <rayon> [<hauteur mini>] [<hauteur maxi>] [--file]
bdlib.oredistribution.start1=Valide la distribution de minerai entre (%s,%s,%s) et (%s,%s,%s) dim %s
bdlib.oredistribution.start2=Le server peut ralentir pendantun certain temps
bdlib.oredistribution.entry=%s %s - %s (%s%%)
bdlib.oredistribution.warn=%s Attention: %s fait produire des variantes multiples :
bdlib.oredistribution.saved=Distribution de minerai déposée dans %s
bdlib.oredistribution.error=Impossible d'enregistrer la distribution de minerai : %s
+18
View File
@@ -0,0 +1,18 @@
bdlib.multiblock.face.north=Nord
bdlib.multiblock.face.south=Sud
bdlib.multiblock.face.east=Est
bdlib.multiblock.face.west=Ovest
bdlib.multiblock.face.up=Sopra
bdlib.multiblock.face.down=Sotto
bdlib.multiblock.disabled=Disattivo
bdlib.multiblock.incomplete=Questa macchina è incompleta, richiede almeno:
bdlib.multiblock.notconnected=Non connesso ad una macchina valida
bdlib.multiblock.toomanyoutputs=Troppi Output collegati,impossibile inserire una nuova connessione
bdlib.rsmode.always=Sempre Attivo
bdlib.rsmode.never=Disattivo
bdlib.rsmode.rs_on=Attivo su Impulso di Pietrarossa
bdlib.rsmode.rs_off=Disattivo su Impulso di Pietrarossa
bdlib.label.empty=Vuoto
+18
View File
@@ -0,0 +1,18 @@
bdlib.multiblock.face.north=北方
bdlib.multiblock.face.south=南方
bdlib.multiblock.face.east=东方
bdlib.multiblock.face.west=西方
bdlib.multiblock.face.up=顶部
bdlib.multiblock.face.down=底部
bdlib.multiblock.disabled=停用
bdlib.multiblock.incomplete=这台多方块结构机器未搭建完成, 它至少需要安装一个:
bdlib.multiblock.notconnected=未连接有效机器
bdlib.multiblock.toomanyoutputs=连接的输出接口过多, 无法连接新的接口
bdlib.rsmode.always=一直启用
bdlib.rsmode.never=一直停用
bdlib.rsmode.rs_on=接收到红石信号时启用
bdlib.rsmode.rs_off=接收到红石信号时停用
bdlib.label.empty=空
+33
View File
@@ -0,0 +1,33 @@
/*
* 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
import java.util
import cpw.mods.fml.common.{ICrashCallable, ModAPIManager, ModContainer}
import scala.collection.JavaConversions._
object ApiReporter extends ICrashCallable {
lazy val APIs = {
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
"\t\t* %s (%s) from %s".format(mod.getModId, mod.getVersion,
if (mod.getSource.isDirectory)
mod.getSource
else
mod.getSource.getName
)).mkString(Misc.lineSeparator)
}
override def getLabel = "List of loaded APIs"
override def call() = Misc.lineSeparator + APIs
}
+17 -4
View File
@@ -4,14 +4,14 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib
import cpw.mods.fml.common.Mod
import cpw.mods.fml.common.Mod.EventHandler
import cpw.mods.fml.common.event.{FMLPreInitializationEvent, FMLServerStartingEvent}
import cpw.mods.fml.common.event.{FMLPreInitializationEvent, FMLServerStartingEvent, FMLServerStoppingEvent}
import cpw.mods.fml.common.{FMLCommonHandler, Mod}
import net.bdew.lib.multiblock.network.NetHandler
import net.minecraft.command.CommandHandler
import org.apache.logging.log4j.Logger
@@ -20,22 +20,35 @@ import org.apache.logging.log4j.Logger
object BdLib {
var log: Logger = null
def logDebug(msg: String, args: Any*) = log.debug(msg.format(args: _*))
def logInfo(msg: String, args: Any*) = log.info(msg.format(args: _*))
def logWarn(msg: String, args: Any*) = log.warn(msg.format(args: _*))
def logError(msg: String, args: Any*) = log.error(msg.format(args: _*))
def logWarnException(msg: String, t: Throwable, args: Any*) = log.warn(msg.format(args: _*), t)
def logErrorException(msg: String, t: Throwable, args: Any*) = log.error(msg.format(args: _*), t)
val onServerStarting = Event[FMLServerStartingEvent]
val onServerStopping = Event[FMLServerStoppingEvent]
@EventHandler
def preInit(ev: FMLPreInitializationEvent) {
log = ev.getModLog
log.info("bdlib BDLIB_VER loaded")
log.debug("List of loaded APIs: " + ApiReporter.APIs)
FMLCommonHandler.instance().registerCrashCallable(ApiReporter)
NetHandler.init()
}
@EventHandler
def serverStarting(event: FMLServerStartingEvent) {
val commandHandler = event.getServer.getCommandManager.asInstanceOf[CommandHandler]
commandHandler.registerCommand(new CommandDumpRegistry)
commandHandler.registerCommand(CommandDumpRegistry)
commandHandler.registerCommand(CommandOreDistribution)
onServerStarting.trigger(event)
}
@EventHandler
def serverStopping(event: FMLServerStoppingEvent) {
onServerStopping.trigger(event)
}
}
+8 -3
View File
@@ -4,23 +4,28 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib
import net.minecraft.client.Minecraft
import net.minecraft.client.renderer.texture.TextureMap
import org.lwjgl.input.Keyboard
/**
* Misc functions and shortcuts for clientside code
* Misc functions and shortcuts for client-side code
*/
object Client {
def minecraft = Minecraft.getMinecraft
def fontRenederer = Minecraft.getMinecraft.fontRenderer
def fontRenderer = Minecraft.getMinecraft.fontRenderer
def renderEngine = Minecraft.getMinecraft.renderEngine
def world = Minecraft.getMinecraft.theWorld
def player = Minecraft.getMinecraft.thePlayer
def textureManager = Minecraft.getMinecraft.getTextureManager
def blockMissingIcon = textureManager.getTexture(TextureMap.locationBlocksTexture).asInstanceOf[TextureMap].getAtlasSprite("missingno")
def itemMissingIcon = textureManager.getTexture(TextureMap.locationItemsTexture).asInstanceOf[TextureMap].getAtlasSprite("missingno")
def shiftDown: Boolean = {
return Keyboard.isKeyDown(42) || Keyboard.isKeyDown(54)
+9 -4
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib
@@ -19,10 +19,10 @@ import net.minecraft.item.ItemStack
import net.minecraftforge.fluids.FluidRegistry
import net.minecraftforge.oredict.OreDictionary
class CommandDumpRegistry extends CommandBase {
object CommandDumpRegistry extends CommandBase {
def getCommandName = "dumpregistry"
override def getRequiredPermissionLevel = 2
def getCommandUsage(icommandsender: ICommandSender) = "dumpregistry"
def getCommandUsage(c: ICommandSender) = "dumpregistry"
def processCommand(sender: ICommandSender, params: Array[String]) {
val mcHome = FMLInjectionData.data()(6).asInstanceOf[File] //is there a better way to get this?
@@ -46,7 +46,12 @@ class CommandDumpRegistry extends CommandBase {
dumpWriter.write("\n\n")
dumpWriter.write("==== ORE DICT ====\n")
dumpWriter.write(OreDictionary.getOreNames.sorted.mkString("\n"))
dumpWriter.write((OreDictionary.getOreNames.sorted flatMap { name =>
List(name) ++
(OreDictionary.getOres(name) map { ore =>
" - " + ore.toString
})
}).mkString("\n"))
dumpWriter.write("\n\n")
dumpWriter.write("==== FLUIDS ====\n")
@@ -0,0 +1,148 @@
/*
* Copyright (c) bdew, 2013 - 2014
* https://github.com/bdew/bdlib
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib
import java.io.{BufferedWriter, File, FileWriter}
import cpw.mods.fml.common.registry.GameData
import cpw.mods.fml.relauncher.FMLInjectionData
import net.minecraft.command.{CommandBase, ICommandSender, WrongUsageException}
import net.minecraft.entity.player.EntityPlayerMP
import net.minecraft.item.Item
import net.minecraft.util.EnumChatFormatting
import net.minecraftforge.oredict.OreDictionary
import scala.collection.mutable
object CommandOreDistribution extends CommandBase {
def getCommandName = "oredistribution"
override def getRequiredPermissionLevel = 2
def getCommandUsage(c: ICommandSender) = "bdlib.oredistribution.usage"
def safeInt(s: String) =
try {
s.toInt
} catch {
case e: NumberFormatException => throw new WrongUsageException("bdlib.oredistribution.usage")
}
def wrapColor(s: String, c: EnumChatFormatting) = c + s + EnumChatFormatting.RESET
def processCommand(sender: ICommandSender, baseParams: Array[String]) {
val (flags, params) = baseParams.partition(_.startsWith("--"))
if (params.length < 1 || params.length > 3)
throw new WrongUsageException(getCommandUsage(sender))
val (startX, startZ, world) =
sender match {
case p: EntityPlayerMP => (p.posX.toInt, p.posZ.toInt, p.worldObj)
case _ => (0, 0, sender.getEntityWorld)
}
val radius = safeInt(params.head)
val minY = if (params.length >= 2) safeInt(params(1)) else 0
val maxY = if (params.length >= 3) safeInt(params(2)) else world.getHeight - 1
if (minY < 0 || radius <= 0 || minY > maxY || maxY > world.getHeight - 1)
throw new WrongUsageException(getCommandUsage(sender))
val toFile = flags.contains("--file")
// why java, WHY?
CommandBase.func_152373_a(sender, this, "bdlib.oredistribution.start1",
Array[Integer](startX - radius, minY, startZ - radius, startX + radius, maxY, startZ + radius, world.provider.dimensionId): _*)
CommandBase.func_152373_a(sender, this, "bdlib.oredistribution.start2")
import scala.collection.JavaConversions._
val ores = (OreDictionary.getOreNames.filter(x => x.startsWith("ore") || x.startsWith("denseore")) flatMap { name =>
val fixedName =
if (name.startsWith("ore"))
name.substring(3)
else if (name.startsWith("denseore"))
"Dense " + name.substring(8)
else name
for (s <- OreDictionary.getOres(name)) yield (s.getItem, s.getItemDamage) -> fixedName
}).toMap
val distribution = mutable.Map.empty[String, Int].withDefaultValue(0)
val kinds = mutable.Map.empty[String, Set[(Item, Int)]].withDefaultValue(Set.empty)
for {
x <- startX - radius to startX + radius
y <- minY to maxY
z <- startZ - radius to startZ + radius
if !world.isAirBlock(x, y, z)
} {
val key = (Item.getItemFromBlock(world.getBlock(x, y, z)), world.getBlockMetadata(x, y, z))
for (ore <- ores.get(key)) {
distribution(ore) += 1
kinds(ore) += key
}
}
val total = distribution.values.sum
val warnings = kinds.filter(_._2.size > 1)
if (toFile) {
// === OUTPUT TO FILE ===
val mcHome = FMLInjectionData.data()(6).asInstanceOf[File] //is there a better way to get this?
val dumpFile = new File(mcHome, "ore_distribution.txt")
val dumpWriter = new BufferedWriter(new FileWriter(dumpFile))
try {
dumpWriter.write("Ore distribution report - (%d,%d,%d) to (%d,%d,%d) dim %d".format(
startX - radius, minY, startZ - radius, startX + radius, maxY, startZ + radius, world.provider.dimensionId
))
dumpWriter.newLine()
dumpWriter.newLine()
if (warnings.nonEmpty) {
for ((id, types) <- warnings.toList.sortBy(_._1)) {
dumpWriter.write("Warning: %s has multiple variants generated:".format(id))
dumpWriter.newLine()
for ((item, dmg) <- types) {
dumpWriter.write(" - %s@%s".format(GameData.getItemRegistry.getNameForObject(item), dmg))
dumpWriter.newLine()
}
dumpWriter.newLine()
}
dumpWriter.write("=================")
dumpWriter.newLine()
dumpWriter.newLine()
}
for ((id, num) <- distribution.filter(_._2 > 0).toList.sortBy(-_._2)) {
dumpWriter.write("%s - %s (%s%%)".format(id, DecFormat.round(num), DecFormat.short(100F * num / total)))
dumpWriter.newLine()
}
CommandBase.func_152373_a(sender, this, "bdlib.oredistribution.saved", dumpFile.getCanonicalPath)
} catch {
case e: Throwable =>
CommandBase.func_152373_a(sender, this, "bdlib.oredistribution.error", e.toString)
BdLib.logErrorException("Failed to save ore distribution dump", e)
} finally {
dumpWriter.close()
}
} else {
// === OUTPUT TO CHAT ===
for ((id, types) <- warnings.toList.sortBy(_._1)) {
CommandBase.func_152373_a(sender, this, "bdlib.oredistribution.warn",
wrapColor(" !", EnumChatFormatting.RED), wrapColor(id, EnumChatFormatting.RED))
for ((item, dmg) <- types)
CommandBase.func_152373_a(sender, this, wrapColor(" - ", EnumChatFormatting.RED) + GameData.getItemRegistry.getNameForObject(item) + "@" + dmg)
}
for ((id, num) <- distribution.filter(_._2 > 0).toList.sortBy(-_._2)) {
CommandBase.func_152373_a(sender, this, "bdlib.oredistribution.entry",
" *", wrapColor(id, EnumChatFormatting.YELLOW),
DecFormat.round(num), DecFormat.short(100F * num / total))
}
}
}
}
+1 -1
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib
+30
View File
@@ -0,0 +1,30 @@
/*
* Copyright (c) bdew, 2013 - 2014
* https://github.com/bdew/bdlib
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib
import java.text.DecimalFormat
object DecFormat {
val thousandsFmt = new DecimalFormat("#,##0")
val dec2Fmt = new DecimalFormat("#,##0.00")
val dec1Fmt = new DecimalFormat("#,##0.0")
def round(x: Double) = thousandsFmt.format(x)
def round(x: Float) = thousandsFmt.format(x)
def round(x: Int) = thousandsFmt.format(x)
def dec2(x: Double) = dec2Fmt.format(x)
def dec2(x: Float) = dec2Fmt.format(x)
def dec2(x: Int) = dec2Fmt.format(x)
def short(x: Double) = if (x > 10) thousandsFmt.format(x) else if (x > 1) dec1Fmt.format(x) else dec2Fmt.format(x)
def short(x: Float) = if (x > 10) thousandsFmt.format(x) else if (x > 1) dec1Fmt.format(x) else dec2Fmt.format(x)
def short(x: Int) = if (x > 10) thousandsFmt.format(x) else if (x > 1) dec1Fmt.format(x) else dec2Fmt.format(x)
}
+2 -2
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib
@@ -12,7 +12,7 @@ package net.bdew.lib
class EventBase[T] extends {
var listeners = Seq.empty[T]
def listen(x: T) = listeners :+= x
def hasListeners = listeners.size > 0
def hasListeners = listeners.nonEmpty
}
class Event0 extends EventBase[() => Unit] {
+73 -27
View File
@@ -4,43 +4,36 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib
import cpw.mods.fml.common.Loader
import java.util
import cpw.mods.fml.common.registry.GameRegistry
import cpw.mods.fml.common.versioning.{ArtifactVersion, VersionParser}
import cpw.mods.fml.common.versioning.VersionParser
import cpw.mods.fml.common.{Loader, ModAPIManager, ModContainer}
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.tileentity.TileEntity
import net.minecraft.util.StatCollector
import net.minecraft.util.{IIcon, StatCollector}
import net.minecraft.world.biome.BiomeGenBase
import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.fluids.{Fluid, FluidStack}
import net.minecraftforge.oredict.ShapedOreRecipe
object Misc {
def iterNbtCompoundList(parent: NBTTagCompound, name: String): Iterable[NBTTagCompound] = {
val list = parent.getTagList(name, 10)
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 getActiveModId = Option(Loader.instance().activeModContainer().getModId) getOrElse "<UNKNOWN>"
def toLocal(s: String) = StatCollector.translateToLocal(s)
def toLocalF(s: String, params: Any*) = StatCollector.translateToLocal(s).format(params: _*)
def hasLocal(s: String) = StatCollector.canTranslate(s)
def flattenRecipe(pattern: Seq[String], items: Map[Char, AnyRef]) =
pattern ++ items.map {
pattern ++ items.flatMap {
case (k, v) => Seq(new Character(k), v)
}.flatten
}
def wrapTag(n: String, f: (NBTTagCompound) => Any)(t: NBTTagCompound) {
val p = t.getCompoundTag(n)
@@ -54,8 +47,8 @@ object Misc {
def addRecipeOD(result: ItemStack, pattern: Seq[String], items: Map[Char, AnyRef]) =
GameRegistry.addRecipe(new ShapedOreRecipe(result, flattenRecipe(pattern, items): _*))
def min[T](vals: T*)(implicit o: Ordering[T]): T = vals.min(o)
def max[T](vals: T*)(implicit o: Ordering[T]): T = vals.max(o)
def min[T: Ordering](values: T*) = values.min
def max[T: Ordering](values: T*) = values.max
def clamp[T](value: T, min: T, max: T)(implicit o: Ordering[T]): T = if (o.gt(value, max)) max else if (o.lt(value, min)) min else value
@@ -66,17 +59,28 @@ object Misc {
def getBiomeByName(name: String) = BiomeGenBase.getBiomeGenArray.find(x => x != null && x.biomeName == name).orNull
def haveModVersion(spec: String): Boolean = {
val req = VersionParser.parseVersionReference(spec)
val modid = req.getLabel
private lazy val modLookup = {
val mods = new util.ArrayList[ModContainer]
val nameLookup = new util.HashMap[String, ModContainer]
if (!Loader.instance.getIndexedModList.containsKey(modid)) return false
nameLookup.putAll(Loader.instance().getIndexedModList)
ModAPIManager.INSTANCE.injectAPIModContainers(mods, nameLookup)
val found: ArtifactVersion = Loader.instance.getIndexedModList.get(modid).getProcessedVersion
import scala.collection.JavaConverters._
nameLookup.asScala
}
if (found == null || !req.containsVersion(found)) return false
def haveModVersion(modId: String) = {
val spec = VersionParser.parseVersionReference(modId)
modLookup.contains(spec.getLabel) && spec.containsVersion(modLookup(spec.getLabel).getProcessedVersion)
}
return true
def getModVersion(modId: String) =
modLookup.get(modId) map (_.getVersion)
def getModVersionString(modId: String): String = {
val cont = modLookup.getOrElse(modId, return "NOT FOUND")
cont.getModId + " " + cont.getVersion
}
// Because writing this every time is awkward
@@ -86,13 +90,55 @@ object Misc {
def asInstanceOpt[T](v: Any, cls: Class[T]) =
if (cls.isInstance(v)) Some(v.asInstanceOf[T]) else None
// Same thing but in a way that's easier to use with map, etc.
def asInstanceOpt[T](cls: Class[T])(v: Any) =
if (cls.isInstance(v)) Some(v.asInstanceOf[T]) else None
def getNeighbourTile[T](origin: TileEntity, dir: ForgeDirection, cls: Class[T]) =
Option(origin.getWorldObj.getTileEntity(origin.xCoord + dir.offsetX,
origin.yCoord + dir.offsetY, origin.zCoord + dir.offsetZ)) flatMap (asInstanceOpt(_, cls))
def applyMutator[T](f: (T) => Unit, init: T): T = {
@inline def applyMutator[T](f: (T) => Unit, init: T): T = {
f(init)
init
}
@inline def applyMutator[T](init: T)(f: (T) => Unit) = {
f(init)
init
}
def nextInSeq[T](seq: Seq[T], elem: T) = {
val pos = seq.indexOf(elem)
if (pos < 0 || pos == seq.size - 1)
seq.head
else
seq(pos + 1)
}
def prevInSeq[T](seq: Seq[T], elem: T) = {
val pos = seq.indexOf(elem)
if (pos <= 0)
seq.last
else
seq(pos - 1)
}
def getFluidIcon(fs: FluidStack): IIcon =
if (fs != null && fs.getFluid != null && fs.getFluid.getIcon != null)
fs.getFluid.getIcon(fs)
else
Client.blockMissingIcon
def getFluidIcon(f: Fluid): IIcon =
if (f != null) getFluidIcon(new FluidStack(f, 1)) else Client.blockMissingIcon
def getFluidColor(fs: FluidStack): Int =
if (fs != null && fs.getFluid != null) fs.getFluid.getColor(fs) else 0xFFFFFF
def getFluidColor(f: Fluid): Int =
if (f != null) getFluidColor(new FluidStack(f, 1)) else 0xFFFFFF
lazy val lineSeparator = System.getProperty("line.separator")
}
+30
View File
@@ -0,0 +1,30 @@
/*
* Copyright (c) bdew, 2013 - 2015
* https://github.com/bdew/bdlib
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.async
import scala.concurrent.{Future, Promise}
object Async {
def inOtherThread[T](f: => T) = {
val p = Promise[T]()
val t = new Thread(new Runnable {
override def run(): Unit =
try {
p.success(f)
} catch {
case t: Throwable => p.failure(t)
}
})
t.start()
p.future
}
def inServerThread[T](f: => T) = Future(f)(ServerTickExecutionContext)
}
@@ -0,0 +1,55 @@
/*
* 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.async
import cpw.mods.fml.common.FMLCommonHandler
import cpw.mods.fml.common.eventhandler.SubscribeEvent
import cpw.mods.fml.common.gameevent.TickEvent.ServerTickEvent
import net.bdew.lib.BdLib
import scala.collection.mutable
import scala.concurrent.ExecutionContext
object ServerTickExecutionContext extends ExecutionContext {
private val queue = mutable.Queue.empty[Runnable]
FMLCommonHandler.instance.bus.register(this)
BdLib.logDebug("Installed ServerTickExecutionContext")
private def getNextBatch = this.synchronized {
if (queue.nonEmpty) {
val res = queue.toList
queue.clear()
res
} else List.empty
}
override def execute(runnable: Runnable): Unit =
this.synchronized {
queue += runnable
}
override def reportFailure(cause: Throwable): Unit =
BdLib.logErrorException("Error in execution context", cause)
def doSingleLoop(): Unit = {
for (r <- getNextBatch) {
try {
r.run()
} catch {
case t: Throwable => reportFailure(t)
}
}
}
@SubscribeEvent
def onTick(ev: ServerTickEvent): Unit = doSingleLoop()
}
+1 -1
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.block
+6 -4
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.block
@@ -18,9 +18,11 @@ 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 isValid(w: IBlockAccess) = y >= 0 && y < 256 // hardcoded because getHeight is unavailable on servers :(
def block(w: IBlockAccess) = if (isValid(w)) Option(w.getBlock(x, y, z)) else None
def tile(w: IBlockAccess) = if (isValid(w)) Option(w.getTileEntity(x, y, z)) else None
def meta(w: IBlockAccess) = if (isValid(w)) w.getBlockMetadata(x, y, z) else 0
def blockIs(w: IBlockAccess, other: Block) = block(w).contains(other)
+21
View File
@@ -0,0 +1,21 @@
/*
* 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.block
import net.minecraft.block.Block
import net.minecraft.item.ItemBlock
/**
* If defined on a block - defines a custom ItemBlock class that will be used when registering
* Supported by BlockManager and Machine
*/
trait HasItemBlock extends Block {
def ItemBlockClass: Class[_ <: ItemBlock]
}
+1 -1
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.block
@@ -0,0 +1,29 @@
/*
* 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.block
import java.util
import net.minecraft.block.Block
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.{ItemBlock, ItemStack}
trait BlockTooltip extends Block with HasItemBlock {
override val ItemBlockClass: Class[_ <: ItemBlock] = classOf[ItemBlockTooltip]
def getTooltip(stack: ItemStack, player: EntityPlayer, advanced: Boolean): List[String]
}
class ItemBlockTooltip(b: Block) extends ItemBlock(b) {
override def addInformation(stack: ItemStack, player: EntityPlayer, list: util.List[_], advanced: Boolean): Unit = {
import scala.collection.JavaConversions._
if (b.isInstanceOf[BlockTooltip])
list.asInstanceOf[util.List[String]].addAll(b.asInstanceOf[BlockTooltip].getTooltip(stack, player, advanced))
}
}
+110
View File
@@ -0,0 +1,110 @@
/*
* 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.block
import java.util
import net.bdew.lib.nbt.NBT
import net.bdew.lib.tile.TileExtended
import net.minecraft.block.Block
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.util.MovingObjectPosition
import net.minecraft.world.World
/**
* Mixin for blocks to keep their data when broken
* Must have a TileEntity that extends TileKeepData
*/
trait BlockKeepData extends Block with HasItemBlock {
this: HasTE[_ <: TileKeepData] =>
override val ItemBlockClass: Class[_ <: ItemBlockKeepData] = classOf[ItemBlockKeepData]
def getSavedBlock(world: World, x: Int, y: Int, z: Int, metadata: Int) = {
val stack = new ItemStack(getItemDropped(metadata, world.rand, 0), 1, damageDropped(metadata))
getTE(world, x, y, z).saveToItem(stack)
stack
}
override def getDrops(world: World, x: Int, y: Int, z: Int, metadata: Int, fortune: Int): util.ArrayList[ItemStack] = {
val drops = new util.ArrayList[ItemStack]()
drops.add(getSavedBlock(world, x, y, z, metadata))
drops
}
override def removedByPlayer(world: World, player: EntityPlayer, x: Int, y: Int, z: Int, willHarvest: Boolean): Boolean =
if (willHarvest)
true
else
super.removedByPlayer(world, player, x, y, z, willHarvest)
override def harvestBlock(world: World, player: EntityPlayer, x: Int, y: Int, z: Int, meta: Int): Unit = {
super.harvestBlock(world, player, x, y, z, meta)
world.setBlockToAir(x, y, z)
}
override def getPickBlock(target: MovingObjectPosition, world: World, x: Int, y: Int, z: Int, player: EntityPlayer): ItemStack = {
getSavedBlock(world, x, y, z, world.getBlockMetadata(x, y, z))
}
/**
* Override for special actions on placing
* ItemStack might or might not contain actual data
* Called with the TE created and added to world, after onBlockPlacedBy & co
*/
def restoreTileEntity(world: World, x: Int, y: Int, z: Int, is: ItemStack, player: EntityPlayer) = getTE(world, x, y, z).loadFromItem(is)
}
/**
* Mixin for tile entities to keep their data when broken
* Block class has to extend BlockKeepData
*/
trait TileKeepData extends TileExtended {
/**
* Override to modify data that will be stored in an item
* @param t Automatically serialized data
* @return Modified serialized data
*/
def afterTileBreakSave(t: NBTTagCompound) = t
/**
* Override to modify data that will be load from an item
* After the tile entity is fully constructed and added to world
* @param t Automatically serialized data
* @return Modified serialized data
*/
def beforeTileBreakLoad(t: NBTTagCompound) = t
final def saveToItem(is: ItemStack): Unit = {
if (!is.hasTagCompound) is.setTagCompound(new NBTTagCompound)
is.getTagCompound.setTag("data", afterTileBreakSave(NBT.from(persistSave.trigger)))
}
final def loadFromItem(is: ItemStack): Unit = {
if (is.hasTagCompound && is.getTagCompound.hasKey("data")) {
persistLoad.trigger(beforeTileBreakLoad(is.getTagCompound.getCompoundTag("data")))
}
}
}
/**
* Custom ItemBlock that handles loading data to the Tile Entity
*/
class ItemBlockKeepData(b: Block) extends ItemBlockTooltip(b) {
override def placeBlockAt(stack: ItemStack, player: EntityPlayer, world: World, x: Int, y: Int, z: Int, side: Int, hitX: Float, hitY: Float, hitZ: Float, metadata: Int): Boolean = {
if (super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata)) {
if (!world.isRemote && b.isInstanceOf[BlockKeepData])
b.asInstanceOf[BlockKeepData].restoreTileEntity(world, x, y, z, stack, player)
true
} else false
}
}
+1 -1
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.block
+25 -6
View File
@@ -4,35 +4,54 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.config
import cpw.mods.fml.common.ObfuscationReflectionHelper
import cpw.mods.fml.common.registry.GameRegistry
import net.bdew.lib.Misc
import net.bdew.lib.block.{HasTE, NamedBlock}
import net.bdew.lib.block.{HasItemBlock, HasTE, NamedBlock}
import net.minecraft.block.Block
import net.minecraft.creativetab.CreativeTabs
import net.minecraft.item.ItemStack
import net.minecraft.item.{ItemBlock, ItemStack}
import net.minecraft.tileentity.TileEntity
class BlockManager(creativeTab: CreativeTabs) {
def regBlock[T <: NamedBlock](block: T): T = regBlock(block, block.name)
def regBlock[T <: Block](block: T, name: String, addStack: Boolean = false): T = {
GameRegistry.registerBlock(block, name)
def regSpecial[T <: NamedBlock](block: T, addStack: Boolean = false, skipTileEntityReg: Boolean = false): T =
regBlock(block, block.name, addStack, skipTileEntityReg)
def regBlock[T <: Block](block: T, name: String, addStack: Boolean = false, skipTileEntityReg: Boolean = false): T = {
val itemClass: Class[_ <: ItemBlock] = if (block.isInstanceOf[HasItemBlock])
block.asInstanceOf[HasItemBlock].ItemBlockClass
else
classOf[ItemBlock]
GameRegistry.registerBlock(block, itemClass, name)
block.setCreativeTab(creativeTab)
if (addStack)
GameRegistry.registerCustomItemStack(name, new ItemStack(block))
if (block.isInstanceOf[HasTE[_]])
if (block.isInstanceOf[HasTE[_]] && !skipTileEntityReg)
GameRegistry.registerTileEntity(block.asInstanceOf[HasTE[_]].TEClass,
"%s.%s".format(Misc.getActiveModId, name))
return block
}
/**
* Registers a legacy TE name->class mapping. Stolen from GameRegistry.registerTileEntityWithAlternatives
*/
def registerLegacyTileEntity(name: String, cls: Class[_ <: TileEntity]): Unit = {
val teMappings: java.util.Map[String, Class[_]] = ObfuscationReflectionHelper.getPrivateValue(classOf[TileEntity], null, "field_" + "145855_i", "nameToClassMap")
if (!teMappings.containsKey(name))
teMappings.put(name, cls)
}
def load() {}
}
+1 -1
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.config
+1 -1
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.config
+1 -1
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.config
+17 -11
View File
@@ -4,25 +4,31 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.covers
import cpw.mods.fml.relauncher.{Side, SideOnly}
import net.bdew.lib.Misc
import net.bdew.lib.block.HasTE
import net.bdew.lib.items.ItemUtils
import net.minecraft.block.Block
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.util.IIcon
import net.minecraft.world.{IBlockAccess, World}
import net.minecraftforge.common.util.ForgeDirection
trait BlockCoverable[T <: TileCoverable] extends HasTE[T] {
override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer, face: Int, xoffs: Float, yoffs: Float, zoffs: Float): Boolean = {
@SideOnly(Side.CLIENT)
override def getRenderType = CoverRenderer.id
override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer, face: Int, xOffs: Float, yOffs: Float, zOffs: Float): Boolean = {
val te = getTE(world, x, y, z)
val side = Misc.forgeDirection(face)
if (player.getCurrentEquippedItem == null && player.isSneaking) {
for (cover <- Option(te.covers(side).cval)) {
for (cover <- Option(te.covers(side).value)) {
if (!world.isRemote) {
te.covers(side) := null
te.onCoversChanged()
@@ -39,7 +45,7 @@ trait BlockCoverable[T <: TileCoverable] extends HasTE[T] {
if te.isValidCover(side, activeStack) && coverItem.isValidTile(te, activeStack)
} {
if (!world.isRemote) {
for (cover <- Option(te.covers(side).cval))
for (cover <- Option(te.covers(side).value))
ItemUtils.throwItemAt(world, te.xCoord + side.offsetX, te.yCoord + side.offsetY, te.zCoord + side.offsetZ, cover.copy())
te.covers(side) := activeStack.splitStack(1)
@@ -50,19 +56,19 @@ trait BlockCoverable[T <: TileCoverable] extends HasTE[T] {
return true
}
super.onBlockActivated(world, x, y, z, player, face, xoffs, yoffs, zoffs)
super.onBlockActivated(world, x, y, z, player, face, xOffs, yOffs, zOffs)
}
override def getIcon(w: IBlockAccess, x: Int, y: Int, z: Int, side: Int) =
(for {
coverStack <- Option(getTE(w, x, y, z).covers(Misc.forgeDirection(side)).cval)
coverItem <- Option(coverStack.getItem) flatMap (Misc.asInstanceOpt(_, classOf[ItemCover]))
def getCoverIcon(w: IBlockAccess, x: Int, y: Int, z: Int, side: ForgeDirection): Option[IIcon] =
for {
coverStack <- Option(getTE(w, x, y, z).covers(side).value)
coverItemMaybe <- Option(coverStack.getItem)
coverItem <- Misc.asInstanceOpt(coverItemMaybe, classOf[ItemCover])
} yield coverItem.getCoverIcon(coverStack)
) getOrElse super.getIcon(w, x, y, z, side)
override def breakBlock(world: World, x: Int, y: Int, z: Int, block: Block, meta: Int) {
if (!world.isRemote)
for ((dir, covOpt) <- getTE(world, x, y, z).covers; cover <- Option(covOpt.cval))
for ((dir, covOpt) <- getTE(world, x, y, z).covers; cover <- Option(covOpt.value))
ItemUtils.throwItemAt(world, x, y, z, cover)
super.breakBlock(world, x, y, z, block, meta)
}
@@ -0,0 +1,34 @@
/*
* Copyright (c) bdew, 2013 - 2014
* https://github.com/bdew/bdlib
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.covers
import net.bdew.lib.Misc
import net.bdew.lib.render.connected.ConnectedHelper
import net.bdew.lib.render.{BaseBlockRenderHandler, RenderUtils}
import net.minecraft.block.Block
import net.minecraft.client.renderer.RenderBlocks
import net.minecraft.world.IBlockAccess
import net.minecraftforge.common.util.ForgeDirection
object CoverRenderer extends BaseBlockRenderHandler {
override def renderInventoryBlock(block: Block, metadata: Int, modelId: Int, renderer: RenderBlocks) =
RenderUtils.renderSimpleBlockItem(block, metadata, renderer)
override def renderWorldBlock(world: IBlockAccess, x: Int, y: Int, z: Int, block: Block, modelId: Int, renderer: RenderBlocks) = {
renderer.renderStandardBlock(block, x, y, z)
for {
blockCov <- Misc.asInstanceOpt(block, classOf[BlockCoverable[_]])
face <- ForgeDirection.VALID_DIRECTIONS
icon <- blockCov.getCoverIcon(world, x, y, z, face)
if block.shouldSideBeRendered(world, x + face.offsetX, y + face.offsetY, z + face.offsetZ, face.ordinal())
} ConnectedHelper.draw(face, 8).doDraw(ConnectedHelper.Vec3F(x, y, z), icon)
true
}
}
+2 -2
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.covers
@@ -15,7 +15,7 @@ import net.minecraftforge.common.util.ForgeDirection
trait ItemCover extends Item {
/**
* @return Icon to render, MUST be on terrain spritesheet (0), not item!
* @return Icon to render, MUST be on terrain sprite sheet (0), not item!
*/
def getCoverIcon(stack: ItemStack): IIcon
+2 -2
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.covers
@@ -33,7 +33,7 @@ trait TileCoverable extends TileDataSlots {
def tickCovers() =
for {
(dir, coverSlot) <- covers
coverStack <- Option(coverSlot.cval)
coverStack <- Option(coverSlot.value)
coverItem <- Option(coverStack.getItem) flatMap (Misc.asInstanceOpt(_, classOf[ItemCover]))
} {
coverItem.tickCover(this, dir, coverStack)
+6 -6
View File
@@ -4,16 +4,16 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.data
import net.bdew.lib.data.base.{DataSlotVal, TileDataSlots, UpdateKind}
import net.bdew.lib.data.base.{DataSlotContainer, DataSlotVal, UpdateKind}
import net.minecraft.nbt.NBTTagCompound
case class DataSlotBoolean(name: String, parent: TileDataSlots, default: Boolean = false) extends DataSlotVal[Boolean] {
var cval = default
def save(t: NBTTagCompound, kind: UpdateKind.Value) = t.setBoolean(name, cval)
def load(t: NBTTagCompound, kind: UpdateKind.Value) = cval = t.getBoolean(name)
case class DataSlotBoolean(name: String, parent: DataSlotContainer, default: Boolean = false) extends DataSlotVal[Boolean] {
var value = default
def save(t: NBTTagCompound, kind: UpdateKind.Value) = t.setBoolean(name, value)
def load(t: NBTTagCompound, kind: UpdateKind.Value) = value = t.getBoolean(name)
}
@@ -4,17 +4,17 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.data
import net.bdew.lib.data.base.{DataSlotVal, TileDataSlots, UpdateKind}
import net.bdew.lib.data.base.{DataSlotContainer, DataSlotVal, UpdateKind}
import net.minecraft.nbt.NBTTagCompound
import net.minecraftforge.common.util.ForgeDirection
case class DataSlotDirection(name: String, parent: TileDataSlots) extends DataSlotVal[ForgeDirection] {
var cval = ForgeDirection.UP
def save(t: NBTTagCompound, kind: UpdateKind.Value) = t.setByte(name, cval.ordinal().toByte)
def load(t: NBTTagCompound, kind: UpdateKind.Value) = cval = ForgeDirection.getOrientation(t.getByte(name))
case class DataSlotDirection(name: String, parent: DataSlotContainer) extends DataSlotVal[ForgeDirection] {
var value = ForgeDirection.UP
def save(t: NBTTagCompound, kind: UpdateKind.Value) = t.setByte(name, value.ordinal().toByte)
def load(t: NBTTagCompound, kind: UpdateKind.Value) = value = ForgeDirection.getOrientation(t.getByte(name))
}
@@ -0,0 +1,18 @@
/*
* Copyright (c) bdew, 2013 - 2014
* https://github.com/bdew/bdlib
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.data
import net.bdew.lib.data.base.{DataSlotContainer, DataSlotNumeric, UpdateKind}
import net.minecraft.nbt.NBTTagCompound
case class DataSlotDouble(name: String, parent: DataSlotContainer, default: Double = 0) extends DataSlotNumeric[Double](default) {
def save(t: NBTTagCompound, kind: UpdateKind.Value) = t.setDouble(name, value)
def load(t: NBTTagCompound, kind: UpdateKind.Value) = value = t.getDouble(name)
}
+5 -5
View File
@@ -4,15 +4,15 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.data
import net.bdew.lib.data.base.{DataSlotNumeric, TileDataSlots, UpdateKind}
import net.bdew.lib.data.base.{DataSlotContainer, DataSlotNumeric, UpdateKind}
import net.minecraft.nbt.NBTTagCompound
case class DataSlotFloat(name: String, parent: TileDataSlots, default: Float = 0) extends DataSlotNumeric[Float](default) {
def save(t: NBTTagCompound, kind: UpdateKind.Value) = t.setFloat(name, cval)
def load(t: NBTTagCompound, kind: UpdateKind.Value) = cval = t.getFloat(name)
case class DataSlotFloat(name: String, parent: DataSlotContainer, default: Float = 0) extends DataSlotNumeric[Float](default) {
def save(t: NBTTagCompound, kind: UpdateKind.Value) = t.setFloat(name, value)
def load(t: NBTTagCompound, kind: UpdateKind.Value) = value = t.getFloat(name)
}
@@ -0,0 +1,31 @@
/*
* 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.data
import net.bdew.lib.data.base.{DataSlotContainer, UpdateKind}
import net.minecraft.nbt.NBTTagCompound
import net.minecraftforge.fluids.{Fluid, FluidRegistry}
case class DataSlotFluidOption(name: String, parent: DataSlotContainer) extends DataSlotOption[Fluid] {
setUpdate(UpdateKind.SAVE, UpdateKind.GUI)
override def save(t: NBTTagCompound, kind: UpdateKind.Value) {
value foreach { x => t.setString(name, x.getName) }
}
override def load(t: NBTTagCompound, kind: UpdateKind.Value): Unit = {
if (t.hasKey(name)) {
val fluidName = t.getString(name)
if (FluidRegistry.isFluidRegistered(fluidName)) {
value = Option(FluidRegistry.getFluid(fluidName))
} else unset()
} else unset()
}
}
+11 -11
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.data
@@ -12,25 +12,25 @@ package net.bdew.lib.data
import java.util.UUID
import com.mojang.authlib.GameProfile
import net.bdew.lib.data.base.{DataSlotVal, TileDataSlots, UpdateKind}
import net.bdew.lib.data.base.{DataSlotContainer, DataSlotVal, UpdateKind}
import net.minecraft.nbt.NBTTagCompound
import org.apache.commons.lang3.StringUtils
case class DataSlotGameProfile(name: String, parent: TileDataSlots) extends DataSlotVal[GameProfile] {
override var cval: GameProfile = null
case class DataSlotGameProfile(name: String, parent: DataSlotContainer) extends DataSlotVal[GameProfile] {
override var value: GameProfile = null
override def load(t: NBTTagCompound, kind: UpdateKind.Value) = {
cval = if (t.hasKey(name + "_uid") || t.hasKey(name + "_name")) {
val uid = if (t.hasKey(name + "_uid")) UUID.fromString(t.getString(name + "_uid")) else null
val uname = if (t.hasKey(name + "_name")) t.getString(name + "_name") else null
new GameProfile(uid, uname)
value = if (t.hasKey(name + "_uid") || t.hasKey(name + "_name")) {
val uId = if (t.hasKey(name + "_uid")) UUID.fromString(t.getString(name + "_uid")) else null
val uName = if (t.hasKey(name + "_name")) t.getString(name + "_name") else null
new GameProfile(uId, uName)
} else null
}
override def save(t: NBTTagCompound, kind: UpdateKind.Value) = {
if (cval != null) {
Option(cval.getId) map (id => t.setString(name + "_uid", id.toString))
Option(cval.getName) filterNot (name => StringUtils.isBlank(name)) map (name => t.setString(name + "_name", name))
if (value != null) {
Option(value.getId) foreach (id => t.setString(name + "_uid", id.toString))
Option(value.getName) filterNot (name => StringUtils.isBlank(name)) foreach (name => t.setString(name + "_name", name))
}
}
}
+5 -5
View File
@@ -4,15 +4,15 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.data
import net.bdew.lib.data.base.{DataSlotNumeric, TileDataSlots, UpdateKind}
import net.bdew.lib.data.base.{DataSlotContainer, DataSlotNumeric, UpdateKind}
import net.minecraft.nbt.NBTTagCompound
case class DataSlotInt(name: String, parent: TileDataSlots, default: Int = 0) extends DataSlotNumeric[Int](default) {
def save(t: NBTTagCompound, kind: UpdateKind.Value) = t.setInteger(name, cval)
def load(t: NBTTagCompound, kind: UpdateKind.Value) = cval = t.getInteger(name)
case class DataSlotInt(name: String, parent: DataSlotContainer, default: Int = 0) extends DataSlotNumeric[Int](default) {
def save(t: NBTTagCompound, kind: UpdateKind.Value) = t.setInteger(name, value)
def load(t: NBTTagCompound, kind: UpdateKind.Value) = value = t.getInteger(name)
}
@@ -9,13 +9,12 @@
package net.bdew.lib.data
import net.bdew.lib.Misc
import net.bdew.lib.data.base.{DataSlot, TileDataSlots, UpdateKind}
import net.bdew.lib.data.base.{DataSlot, DataSlotContainer, UpdateKind}
import net.bdew.lib.tile.inventory.BaseInventory
import net.minecraft.item.ItemStack
import net.minecraft.nbt.{NBTTagCompound, NBTTagList}
case class DataSlotInventory(name: String, parent: TileDataSlots, size: Int) extends DataSlot with BaseInventory {
case class DataSlotInventory(name: String, parent: DataSlotContainer, size: Int) extends DataSlot with BaseInventory {
setUpdate(UpdateKind.SAVE)
override def getSizeInventory = size
@@ -23,9 +22,10 @@ case class DataSlotInventory(name: String, parent: TileDataSlots, size: Int) ext
override def load(t: NBTTagCompound, kind: UpdateKind.Value) {
inv = new Array[ItemStack](getSizeInventory)
for (nbtItem <- Misc.iterNbtCompoundList(t, name)) {
import net.bdew.lib.nbt._
for (nbtItem <- t.getList[NBTTagCompound](name)) {
val slot = nbtItem.getByte("Slot")
if (slot >= 0 && slot < inv.size) {
if (slot >= 0 && slot < inv.length) {
inv(slot) = ItemStack.loadItemStackFromNBT(nbtItem)
}
}
@@ -4,29 +4,29 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.data
import net.bdew.lib.data.base.{DataSlotVal, TileDataSlots, UpdateKind}
import net.bdew.lib.data.base.{DataSlotContainer, DataSlotVal, 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
case class DataSlotItemStack(name: String, parent: DataSlotContainer) extends DataSlotVal[ItemStack] {
var value: ItemStack = null
override def update(v: ItemStack) = {
if (!ItemStack.areItemStacksEqual(v, cval)) {
cval = if (v == null) null else v.copy()
if (!ItemStack.areItemStacksEqual(v, value)) {
value = if (v == null) null else v.copy()
parent.dataSlotChanged(this)
}
}
def save(t: NBTTagCompound, kind: UpdateKind.Value) = {
val tag = new NBTTagCompound()
if (cval != null) cval.writeToNBT(tag)
if (value != null) value.writeToNBT(tag)
t.setTag(name, tag)
}
def load(t: NBTTagCompound, kind: UpdateKind.Value) = cval = ItemStack.loadItemStackFromNBT(t.getCompoundTag(name))
def load(t: NBTTagCompound, kind: UpdateKind.Value) = value = ItemStack.loadItemStackFromNBT(t.getCompoundTag(name))
}
@@ -0,0 +1,63 @@
/*
* 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.data
import java.io.{ByteArrayInputStream, ByteArrayOutputStream, DataInputStream, DataOutputStream}
import net.bdew.lib.data.base.{DataSlot, DataSlotContainer, UpdateKind}
import net.minecraft.nbt.NBTTagCompound
import scala.collection.mutable
case class DataSlotMovingAverage(name: String, parent: DataSlotContainer, size: Int) extends DataSlot {
val values = mutable.Queue.empty[Double]
var average: Double = 0
setUpdate(UpdateKind.GUI, UpdateKind.SAVE)
def reset() {
values.clear()
average = 0
}
def update(v: Double) = {
values += v
if (values.length > size)
values.dequeue()
average = values.sum / values.length
parent.dataSlotChanged(this)
}
override def save(t: NBTTagCompound, kind: UpdateKind.Value) {
if (kind == UpdateKind.GUI) {
t.setDouble(name, average)
} else {
val b = new ByteArrayOutputStream()
val o = new DataOutputStream(b)
o.writeByte(values.size)
values.foreach(o.writeDouble)
t.setByteArray(name, b.toByteArray)
o.close()
}
}
override def load(t: NBTTagCompound, kind: UpdateKind.Value) {
if (kind == UpdateKind.GUI) {
average = t.getDouble(name)
} else {
values.clear()
if (t.hasKey(name)) {
val i = new DataInputStream(new ByteArrayInputStream(t.getByteArray(name)))
val len = i.readByte()
values ++= (for (x <- 0 until Math.min(len, size)) yield i.readDouble())
i.close()
}
}
}
}
+4 -4
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.data
@@ -12,15 +12,15 @@ 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
override var value: Option[T] = None
def set(v: T) {
if (v == null) sys.error("Null should never be used with DataSlotOption")
cval = Some(v)
value = Some(v)
}
def unset() {
cval = None
value = None
}
override def isSame(v: Option[T]) = {
+6 -6
View File
@@ -4,16 +4,16 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.data
import net.bdew.lib.data.base.{DataSlotVal, TileDataSlots, UpdateKind}
import net.bdew.lib.data.base.{DataSlotContainer, DataSlotVal, UpdateKind}
import net.minecraft.nbt.NBTTagCompound
case class DataSlotString(name: String, parent: TileDataSlots, default: String = null) extends DataSlotVal[String] {
var cval: String = default
def save(t: NBTTagCompound, kind: UpdateKind.Value) = if (cval != null) t.setString(name, cval)
def load(t: NBTTagCompound, kind: UpdateKind.Value) = cval = if (t.hasKey(name)) t.getString(name) else null
case class DataSlotString(name: String, parent: DataSlotContainer, default: String = null) extends DataSlotVal[String] {
var value: String = default
def save(t: NBTTagCompound, kind: UpdateKind.Value) = if (value != null) t.setString(name, value)
def load(t: NBTTagCompound, kind: UpdateKind.Value) = value = if (t.hasKey(name)) t.getString(name) else null
}
+12 -10
View File
@@ -4,19 +4,19 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.data
import net.bdew.lib.data.base.{DataSlot, TileDataSlots, UpdateKind}
import net.bdew.lib.data.base.{DataSlot, DataSlotContainer, UpdateKind}
import net.minecraft.nbt.NBTTagCompound
import net.minecraftforge.fluids.{FluidStack, FluidTank, IFluidTank}
import net.minecraftforge.fluids._
abstract class DataSlotTankBase(sz: Int) extends FluidTank(sz) with IFluidTank with DataSlot {
var oldStack: FluidStack = null
parent.serverTick.listen(checkUpdate)
parent.onServerTick(checkUpdate)
updateKind = Set(UpdateKind.GUI, UpdateKind.SAVE)
@@ -50,28 +50,30 @@ abstract class DataSlotTankBase(sz: Int) extends FluidTank(sz) with IFluidTank w
if (sendCapacityOnUpdateKind.contains(k))
setCapacity(tag.getInteger("size"))
}
override def setFluid(fluid: FluidStack) = execWithChangeNotify(super.setFluid(fluid))
override def setCapacity(capacity: Int) = execWithChangeNotify(super.setCapacity(capacity))
override def drain(maxDrain: Int, doDrain: Boolean) =
if (doDrain)
execWithChangeNotify(super.drain(maxDrain, true))
execWithChangeNotifyConditional[FluidStack](super.drain(maxDrain, true), _ != null)
else
super.drain(maxDrain, false)
override def fill(resource: FluidStack, doFill: Boolean) =
if (doFill)
execWithChangeNotify(super.fill(resource, true))
execWithChangeNotifyConditional[Int](super.fill(resource, true), _ > 0)
else
super.fill(resource, false)
}
case class DataSlotTank(name: String, parent: TileDataSlots, size: Int) extends DataSlotTankBase(size)
case class DataSlotTank(name: String, parent: DataSlotContainer, size: Int) extends DataSlotTankBase(size)
case class DataSlotTankRestricted(name: String, parent: TileDataSlots, var size: Int, fluidID: Int) extends DataSlotTankBase(size) {
def fill(amount: Int, doFill: Boolean) = super.fill(new FluidStack(fluidID, amount), doFill)
case class DataSlotTankRestricted(name: String, parent: DataSlotContainer, var size: Int, filterFluid: Fluid) extends DataSlotTankBase(size) {
def fill(amount: Int, doFill: Boolean) = super.fill(new FluidStack(filterFluid, amount), doFill)
override def fill(resource: FluidStack, doFill: Boolean): Int = {
if ((resource != null) && (resource.fluidID != fluidID)) return 0
if ((resource != null) && (resource.getFluid != filterFluid)) return 0
return super.fill(resource, doFill)
}
}
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.data.base
+9 -2
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.data.base
@@ -19,7 +19,7 @@ trait DataSlot {
* Tile Entity that owns this slot
* Accessed in constructor, so should be in parameters or a lazy val, otherwise will crash
*/
val parent: TileDataSlots
val parent: DataSlotContainer
/**
* Unique name
@@ -41,6 +41,13 @@ trait DataSlot {
v
}
def execWithChangeNotifyConditional[T](f: => T, condition: T => Boolean): T = {
val v = f
if (condition(v))
parent.dataSlotChanged(this)
v
}
def setUpdate(vals: UpdateKind.Value*): this.type = {
updateKind = vals.toSet
return this
@@ -0,0 +1,77 @@
/*
* Copyright (c) bdew, 2013 - 2014
* https://github.com/bdew/bdlib
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.data.base
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.world.World
import scala.collection.mutable
/**
* Base Trait for objects that can contain Data Slots, this allows implementing them on things that aren't TEs
*/
trait DataSlotContainer {
// Can't use getWorldObj - it fails to get remapped and stuff breaks in obfuscated environment
def getWorldObject: World
/**
* Called when a dataslot value changes
*/
def dataSlotChanged(slot: DataSlot): Unit
/**
* Register a function to run on every server tick
*/
def onServerTick(f: () => Unit): Unit
/**
* List of dataslots in this container
*/
val dataSlots = mutable.HashMap.empty[String, DataSlot]
/**
* The value of getTotalWorldTime when the last change happened
*/
var lastChange = 0L
/**
* The value of getTotalWorldTime when the last GUI packet was sent happened
*/
var lastGuiPacket = 0L
final val TRACE = false
def doSave(kind: UpdateKind.Value, t: NBTTagCompound) {
if (kind == UpdateKind.GUI)
t.setLong("BDLib_TS", getWorldObject.getTotalWorldTime)
for ((n, s) <- dataSlots if s.updateKind.contains(kind)) {
s.save(t, kind)
if (TRACE) printf("%s: %s S=> %s\n".format(kind, n, t.getTag(n)))
}
}
def doLoad(kind: UpdateKind.Value, t: NBTTagCompound) {
if (kind == UpdateKind.GUI) {
val ts = t.getLong("BDLib_TS")
if (ts > lastGuiPacket) {
lastGuiPacket = ts
} else {
return
}
}
for ((n, s) <- dataSlots if s.updateKind.contains(kind)) {
if (TRACE) printf("%s: %s L<= %s\n".format(kind, n, t.getTag(n)))
s.load(t, kind)
}
}
}
@@ -4,19 +4,24 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.data.base
/**
* Base class for data slots that hold numeric values
* adds convinience operators to modify the value
* adds convenience operators to modify the value
*/
abstract class DataSlotNumeric[T](default: T)(implicit n: Numeric[T]) extends DataSlotVal[T] {
var cval = default
def +=(that: T) = update(n.plus(cval, that))
def -=(that: T) = update(n.minus(cval, that))
def *=(that: T) = update(n.times(cval, that))
var value = default
def +=(that: T) = update(n.plus(value, that))
def -=(that: T) = update(n.minus(value, that))
def *=(that: T) = update(n.times(value, that))
/* Special Int versions, using the conversion from numeric */
def +=(that: Int) = update(n.plus(value, n.fromInt(that)))
def -=(that: Int) = update(n.minus(value, n.fromInt(that)))
def *=(that: Int) = update(n.times(value, n.fromInt(that)))
}
@@ -4,18 +4,18 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.data.base
/**
* Base class for data slots that hold values with ordering operators, adds more convinience operators
* Base class for data slots that hold values with ordering operators, adds more convenience operators
* TODO: Do i need this? normal operators can be used with the implicit conversion
*/
abstract class DataSlotOrdered[T](implicit n: Ordering[T]) extends DataSlotVal[T] {
def :>(that: T) = n.compare(cval, that) > 0
def :<(that: T) = n.compare(cval, that) < 0
def :>=(that: T) = n.compare(cval, that) >= 0
def :<=(that: T) = n.compare(cval, that) <= 0
def :>(that: T) = n.compare(value, that) > 0
def :<(that: T) = n.compare(value, that) < 0
def :>=(that: T) = n.compare(value, that) >= 0
def :<=(that: T) = n.compare(value, that) <= 0
}
+8 -8
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.data.base
@@ -13,27 +13,27 @@ import scala.language.implicitConversions
/**
* Base trait for data slots that hold primitive values
* Defines some convinience operators to access the value and an implicit conversion to the value
* Defines some convenience operators to access the value and an implicit conversion to the value
*/
trait DataSlotVal[T] extends DataSlot {
var cval: T
var value: T
def isSame(v: T) = v == cval
def isSame(v: T) = v == value
def :=(that: T) = update(that)
def :!=(that: T) = cval != that
def :==(that: T) = cval == that
def :!=(that: T) = value != that
def :==(that: T) = value == that
def update(v: T) {
if (!isSame(v)) {
cval = v
value = v
parent.dataSlotChanged(this)
}
}
}
object DataSlotVal {
implicit def slot2val[T](slot: DataSlotVal[T]): T = slot.cval
implicit def slot2val[T](slot: DataSlotVal[T]): T = slot.value
}
+15 -30
View File
@@ -1,10 +1,10 @@
/*
* 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
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.data.base
@@ -14,40 +14,25 @@ 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]
var lastChange = 0L
final val TRACE = false
def doSave(kind: UpdateKind.Value, t: NBTTagCompound) {
for ((n, s) <- dataSlots if s.updateKind.contains(kind)) {
s.save(t, kind)
if (TRACE) printf("%s: %s S=> %s\n".format(kind, n, t.getTag(n)))
}
}
def doLoad(kind: UpdateKind.Value, t: NBTTagCompound) {
for ((n, s) <- dataSlots if s.updateKind.contains(kind)) {
if (TRACE) printf("%s: %s L<= %s\n".format(kind, n, t.getTag(n)))
s.load(t, kind)
if (kind == UpdateKind.WORLD && s.updateKind.contains(UpdateKind.RENDER))
getWorldObj.markBlockRangeForRenderUpdate(xCoord, yCoord, zCoord, xCoord, yCoord, zCoord)
}
}
trait TileDataSlots extends TileExtended with DataSlotContainer {
persistSave.listen(doSave(UpdateKind.SAVE, _))
persistLoad.listen(doLoad(UpdateKind.SAVE, _))
sendClientUpdate.listen(doSave(UpdateKind.WORLD, _))
handleClientUpdate.listen(doLoad(UpdateKind.WORLD, _))
handleClientUpdate.listen { tag =>
doLoad(UpdateKind.WORLD, tag)
if (dataSlots.values.exists(_.updateKind.contains(UpdateKind.RENDER)))
getWorldObj.markBlockRangeForRenderUpdate(xCoord, yCoord, zCoord, xCoord, yCoord, zCoord)
}
def dataSlotChanged(slot: DataSlot) {
override def getWorldObject = getWorldObj
override def onServerTick(f: () => Unit) = serverTick.listen(f)
override def dataSlotChanged(slot: DataSlot) = {
if (getWorldObj != null) {
if (slot.updateKind.contains(UpdateKind.GUI))
lastChange = getWorldObj.getTotalWorldTime
if (slot.updateKind.contains(UpdateKind.WORLD))
if (!getWorldObj.isRemote && slot.updateKind.contains(UpdateKind.WORLD))
getWorldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
if (slot.updateKind.contains(UpdateKind.SAVE))
getWorldObj.markTileEntityChunkModified(xCoord, yCoord, zCoord, this)
@@ -57,7 +42,7 @@ trait TileDataSlots extends TileExtended {
def getDataSlotPacket: Packet = {
val tag = new NBTTagCompound()
doSave(UpdateKind.GUI, tag)
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, ACT_GUI, tag)
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, ACT_GUI, tag)
}
override protected def extDataPacket(id: Int, data: NBTTagCompound) {
+1 -1
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.data.base
+3 -1
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.gui
@@ -28,5 +28,7 @@ abstract class BaseContainer(te: IInventory) extends NoInvContainer {
getSlot(slot).putStack(stack)
return null
}
override def canInteractWith(player: EntityPlayer) = te.isUseableByPlayer(player)
}
+1 -1
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.gui
+2 -2
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.gui
@@ -16,7 +16,7 @@ case class BaseRect[T: Numeric](x: T, y: T, w: T, h: T) {
def this(p: BasePoint[T], w: T, h: T) = this(p.x, p.y, w, h)
def contains(p: BasePoint[T]) = n.gteq(p.x, x) && n.gteq(p.y, y) && n.lteq(p.x, x2) && n.lteq(p.y, y2)
def contains(p: BasePoint[T]) = n.gteq(p.x, x) && n.gteq(p.y, y) && n.lt(p.x, x2) && n.lt(p.y, y2)
def origin = BasePoint(x, y)
+2 -2
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.gui
@@ -56,7 +56,7 @@ abstract class BaseScreen(cont: Container, xSz: Int, ySz: Int) extends GuiContai
import scala.collection.JavaConversions._
if (tip.size > 0)
if (tip.nonEmpty)
drawHoveringText(tip, x, y, getFontRenderer)
}
+1 -1
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.gui
+3 -3
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.gui
@@ -44,6 +44,6 @@ object Color {
final val magenta = Color(1, 0, 1)
final val gray = Color(0.5F, 0.5F, 0.5F)
final val lightgray = Color(0.75F, 0.75F, 0.75F)
final val darkgray = Color(0.25F, 0.25F, 0.25F)
final val lightGray = Color(0.75F, 0.75F, 0.75F)
final val darkGray = Color(0.25F, 0.25F, 0.25F)
}
+1 -1
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.gui
+1 -1
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.gui
+7 -7
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.gui
@@ -16,17 +16,17 @@ import net.minecraft.world.World
import scala.collection.mutable
class GuiHandler extends IGuiHandler {
val guis = mutable.Map.empty[Int, GuiProvider]
val GUIs = mutable.Map.empty[Int, GuiProvider]
def register(p: GuiProvider) = {
if (guis.isDefinedAt(p.guiId))
sys.error("GUI ID Collision - %d was registered for %s and attemted to register by %s".format(p.guiId, guis(p.guiId), p))
guis += (p.guiId -> p)
if (GUIs.isDefinedAt(p.guiId))
sys.error("GUI ID Collision - %d was registered for %s and attempted to register by %s".format(p.guiId, GUIs(p.guiId), p))
GUIs += (p.guiId -> p)
}
def getServerGuiElement(ID: Int, player: EntityPlayer, world: World, x: Int, y: Int, z: Int): AnyRef =
guis(ID).getContainer(world.getTileEntity(x, y, z), player)
GUIs(ID).getContainer(world.getTileEntity(x, y, z), player)
def getClientGuiElement(ID: Int, player: EntityPlayer, world: World, x: Int, y: Int, z: Int): AnyRef =
guis(ID).getGui(world.getTileEntity(x, y, z), player)
GUIs(ID).getGui(world.getTileEntity(x, y, z), player)
}
+1 -1
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.gui
+5 -5
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.gui
@@ -28,13 +28,13 @@ abstract class NoInvContainer extends Container {
addSlotToContainer(new Slot(inv, i, xOffs + i * 18, yOffsHotbar))
}
override def slotClick(slotnum: Int, button: Int, modifiers: Int, player: EntityPlayer): ItemStack = {
if (inventorySlots.isDefinedAt(slotnum)) {
val slot = getSlot(slotnum)
override def slotClick(slotNum: Int, button: Int, modifiers: Int, player: EntityPlayer): ItemStack = {
if (inventorySlots.isDefinedAt(slotNum)) {
val slot = getSlot(slotNum)
if (slot != null && slot.isInstanceOf[SlotClickable])
return slot.asInstanceOf[SlotClickable].onClick(button, modifiers, player)
}
return super.slotClick(slotnum, button, modifiers, player)
return super.slotClick(slotNum, button, modifiers, player)
}
override def transferStackInSlot(player: EntityPlayer, slot: Int): ItemStack = null
+1 -1
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.gui
+1 -1
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.gui
+9 -2
View File
@@ -4,11 +4,12 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.gui
import net.bdew.lib.Client
import net.minecraft.client.Minecraft
import net.minecraft.client.renderer.texture.TextureMap
import net.minecraft.util.{IIcon, ResourceLocation}
@@ -29,7 +30,13 @@ class InterpolatedTexture(val texture: Texture, rect: Rect) extends Texture {
def v2 = rect.y2 * (texture.v2 - texture.v1) + texture.v1
}
class IconWrapper(val resource: ResourceLocation, val icon: IIcon) extends Texture {
class IconWrapper(val resource: ResourceLocation, aIcon: IIcon) extends Texture {
val icon = if (aIcon == null) {
if (resource == Texture.ITEMS) Client.itemMissingIcon
else if (resource == Texture.BLOCKS) Client.blockMissingIcon
else sys.error("Attempt to create IconWrapper for null IIcon")
} else aIcon
def u1 = icon.getMinU
def u2 = icon.getMaxU
def v1 = icon.getMinV
+1 -1
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.gui
+9 -5
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib
@@ -15,13 +15,17 @@ package object gui {
import scala.language.implicitConversions
implicit def awt2point(p: java.awt.Point) = BasePoint(p.x, p.y)
implicit def awt2point(p: java.awt.Point): BasePoint[Int] = BasePoint(p.x, p.y)
implicit def point2awt(p: BasePoint[Int]): java.awt.Point = new java.awt.Point(p.x, p.y)
implicit def tuple2point[T: Numeric](p: (T, T)) = BasePoint(p._1, p._2)
implicit def tuple2point[T: Numeric](p: (T, T)): BasePoint[T] = BasePoint(p._1, p._2)
// Converts different kinds of Point/Rect as long as there's an implicit for the underlying type
implicit def pointconvert[T, R](a: BasePoint[R])(implicit f: R => T, n: Numeric[T]) = BasePoint[T](f(a.x), f(a.y))
implicit def rectconvert[T, R](a: BaseRect[R])(implicit f: R => T, n: Numeric[T]) = BaseRect[T](f(a.x), f(a.y), f(a.w), f(a.h))
implicit def pointConvert[T, R](a: BasePoint[R])(implicit f: R => T, n: Numeric[T]): BasePoint[T] =
BasePoint[T](f(a.x), f(a.y))
implicit def rectConvert[T, R](a: BaseRect[R])(implicit f: R => T, n: Numeric[T]): BaseRect[T] =
BaseRect[T](f(a.x), f(a.y), f(a.w), f(a.h))
def Rect(x: Float, y: Float, w: Float, h: Float) = BaseRect(x, y, w, h)
def Point(x: Float, y: Float) = BasePoint(x, y)
+1 -1
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.gui.widgets
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.gui.widgets
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.gui.widgets
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.gui.widgets
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.gui.widgets
@@ -12,12 +12,12 @@ package net.bdew.lib.gui.widgets
import net.bdew.lib.data.base.DataSlotNumeric
import net.bdew.lib.gui._
class WidgetFillDataslot[T](val rect: Rect, val texture: Texture, dir: Direction.Direction, dslot: DataSlotNumeric[T], maxval: T)(implicit num: Numeric[T]) extends Widget {
class WidgetFillDataSlot[T](val rect: Rect, val texture: Texture, dir: Direction.Direction, dSlot: DataSlotNumeric[T], maxVal: T)(implicit num: Numeric[T]) extends Widget {
import num.mkNumericOps
override def draw(mouse: Point) {
val fill = dslot.cval.toFloat() / maxval.toFloat()
val fill = dSlot.value.toFloat() / maxVal.toFloat()
dir match {
case Direction.UP =>
parent.drawTextureInterpolate(rect, texture, 0, 1 - fill, 1, 1)
@@ -4,27 +4,23 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.gui.widgets
import java.text.DecimalFormat
import net.bdew.lib.Misc
import net.bdew.lib.data.DataSlotTankBase
import net.bdew.lib.gui.{Color, Point, Rect, Texture}
import net.bdew.lib.{DecFormat, Misc}
import org.lwjgl.opengl.GL11
import scala.collection.mutable
class WidgetFluidGauge(val rect: Rect, overlay: Texture, dslot: DataSlotTankBase) extends Widget {
val formater = new DecimalFormat("#,###")
class WidgetFluidGauge(val rect: Rect, overlay: Texture, dSlot: DataSlotTankBase) extends Widget {
override def handleTooltip(p: Point, tip: mutable.MutableList[String]) {
if (dslot.getFluid != null) {
tip += dslot.getFluid.getFluid.getLocalizedName(dslot.getFluid)
tip += "%s/%s mB".format(formater.format(dslot.getFluidAmount), formater.format(dslot.getCapacity))
if (dSlot.getFluid != null) {
tip += dSlot.getFluid.getFluid.getLocalizedName(dSlot.getFluid)
tip += "%s/%s mB".format(DecFormat.round(dSlot.getFluidAmount), DecFormat.round(dSlot.getCapacity))
} else {
tip += Misc.toLocal("bdlib.label.empty")
}
@@ -34,12 +30,12 @@ class WidgetFluidGauge(val rect: Rect, overlay: Texture, dslot: DataSlotTankBase
GL11.glEnable(GL11.GL_BLEND)
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA)
val fstack = dslot.getFluid
if (fstack != null && fstack.getFluid.getStillIcon != null) {
val icon = Texture(Texture.BLOCKS, fstack.getFluid.getStillIcon)
var fillHeight = if (dslot.getCapacity > 0) rect.h * fstack.amount / dslot.getCapacity else 0
val fStack = dSlot.getFluid
if (fStack != null) {
val color = Color.fromInt(Misc.getFluidColor(fStack))
val icon = Texture(Texture.BLOCKS, Misc.getFluidIcon(fStack))
var fillHeight = if (dSlot.getCapacity > 0) rect.h * fStack.amount / dSlot.getCapacity else 0
var yStart: Int = 0
val color = Color.fromInt(fstack.getFluid.getColor(fstack))
while (fillHeight > 0) {
if (fillHeight > 16) {
@@ -56,6 +52,7 @@ class WidgetFluidGauge(val rect: Rect, overlay: Texture, dslot: DataSlotTankBase
GL11.glColor3d(1, 1, 1)
GL11.glDisable(GL11.GL_BLEND)
parent.drawTexture(rect, overlay)
if (overlay != null)
parent.drawTexture(rect, overlay)
}
}
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.gui.widgets
@@ -4,14 +4,14 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.gui.widgets
import net.bdew.lib.gui.Rect
abstract class WidgetMultipane(rect: Rect) extends WidgetSubcontainer(rect) {
abstract class WidgetMultiPane(rect: Rect) extends WidgetSubContainer(rect) {
def getActivePane: BaseWidget
def addPane[T <: BaseWidget](w: T): T = {
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.gui.widgets
@@ -14,6 +14,6 @@ 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) + "%"
class WidgetProgressBar(rect: Rect, texture: Texture, dSlot: DataSlotFloat) extends WidgetFillDataSlot[Float](rect, texture, Direction.RIGHT, dSlot, 1) {
override def handleTooltip(p: Point, tip: mutable.MutableList[String]) = tip += "%.0f".format(dSlot.value * 100) + "%"
}
@@ -0,0 +1,16 @@
/*
* Copyright (c) bdew, 2013 - 2014
* https://github.com/bdew/bdlib
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.gui.widgets
import net.bdew.lib.gui._
case class WidgetSimpleIcon(rect: Rect, icon: Texture) extends Widget {
override def draw(mouse: Point) = parent.drawTexture(rect, icon)
}
@@ -4,14 +4,14 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.gui.widgets
import net.bdew.lib.gui._
class WidgetSubcontainer(val rect: Rect) extends BaseWidget with WidgetContainer with SimpleDrawTarget {
class WidgetSubContainer(val rect: Rect) extends BaseWidget with WidgetContainer with SimpleDrawTarget {
def getZLevel = parent.getZLevel
def getFontRenderer = parent.getFontRenderer
def getOffsetFromWindow = parent.getOffsetFromWindow + rect.origin
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.gui.widgets
+1 -1
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.items
+9 -9
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.items
@@ -25,11 +25,11 @@ object ItemUtils {
val dx = world.rand.nextFloat * 0.8
val dy = world.rand.nextFloat * 0.8
val dz = world.rand.nextFloat * 0.8
val entityitem: EntityItem = new EntityItem(world, x + dx, y + dy, z + dz, stack)
entityitem.motionX = world.rand.nextGaussian * 0.05
entityitem.motionY = world.rand.nextGaussian * 0.05 + 0.2
entityitem.motionZ = world.rand.nextGaussian * 0.05
world.spawnEntityInWorld(entityitem)
val entity = new EntityItem(world, x + dx, y + dy, z + dz, stack)
entity.motionX = world.rand.nextGaussian * 0.05
entity.motionY = world.rand.nextGaussian * 0.05 + 0.2
entity.motionZ = world.rand.nextGaussian * 0.05
world.spawnEntityInWorld(entity)
}
def dropItemToPlayer(world: World, player: EntityPlayer, stack: ItemStack) {
@@ -47,11 +47,11 @@ object ItemUtils {
return ItemStack.areItemStackTagsEqual(stack2, stack1)
}
def addStackToSlots(stack: ItemStack, inv: IInventory, slots: Iterable[Int], checkvalid: Boolean): ItemStack = {
def addStackToSlots(stack: ItemStack, inv: IInventory, slots: Iterable[Int], checkValid: Boolean): ItemStack = {
if (stack == null) return null
// Try merging into existing slots
for (slot <- slots if (!checkvalid || inv.isItemValidForSlot(slot, stack)) && isSameItem(stack, inv.getStackInSlot(slot))) {
for (slot <- slots if (!checkValid || inv.isItemValidForSlot(slot, stack)) && isSameItem(stack, inv.getStackInSlot(slot))) {
val target = inv.getStackInSlot(slot)
val toAdd = Misc.min(target.getMaxStackSize - target.stackSize, inv.getInventoryStackLimit - target.stackSize, stack.stackSize)
if (toAdd >= stack.stackSize) {
@@ -67,7 +67,7 @@ object ItemUtils {
}
// Now find empty slots and stick any leftovers there
for (slot <- slots if (!checkvalid || inv.isItemValidForSlot(slot, stack)) && inv.getStackInSlot(slot) == null) {
for (slot <- slots if (!checkValid || inv.isItemValidForSlot(slot, stack)) && inv.getStackInSlot(slot) == null) {
if (inv.getInventoryStackLimit < stack.stackSize) {
inv.setInventorySlotContents(slot, stack.splitStack(inv.getInventoryStackLimit))
} else {
+1 -1
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.items
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.items.inventory
@@ -15,15 +15,13 @@ import net.minecraft.inventory.Slot
import net.minecraft.item.ItemStack
class ContainerItemInventory(inv: InventoryItemAdapter, player: EntityPlayer) extends BaseContainer(inv) {
def canInteractWith(entityplayer: EntityPlayer) = entityplayer == player
override def slotClick(slotnum: Int, button: Int, modifiers: Int, player: EntityPlayer): ItemStack = {
if (slotnum > 0 && slotnum < inventorySlots.size()) {
val slot = inventorySlots.asInstanceOf[java.util.List[Slot]].get(slotnum)
override def slotClick(slotNum: Int, button: Int, modifiers: Int, player: EntityPlayer): ItemStack = {
if (slotNum > 0 && slotNum < inventorySlots.size()) {
val slot = inventorySlots.asInstanceOf[java.util.List[Slot]].get(slotNum)
if (slot.isSlotInInventory(inv.player.inventory, inv.slot))
return null
}
if (modifiers == 2 && button == inv.slot) return null
return super.slotClick(slotnum, button, modifiers, player)
return super.slotClick(slotNum, button, modifiers, player)
}
}
@@ -4,12 +4,11 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.items.inventory
import net.bdew.lib.Misc
import net.bdew.lib.tile.inventory.BaseInventory
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.ItemStack
@@ -23,10 +22,11 @@ class InventoryItemAdapter(val player: EntityPlayer, val slot: Int, val size: In
load()
def load() {
import net.bdew.lib.nbt._
val tag = getStack.getTagCompound
for (nbtItem <- Misc.iterNbtCompoundList(tag, tagName)) {
for (nbtItem <- tag.getList[NBTTagCompound](tagName)) {
val slot = nbtItem.getByte("Slot")
if (slot >= 0 && slot < inv.size) {
if (slot >= 0 && slot < inv.length) {
inv(slot) = ItemStack.loadItemStackFromNBT(nbtItem)
}
}
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.items.inventory
@@ -19,7 +19,7 @@ import net.minecraft.world.World
/**
* Mixin for items that have an internal inventory
* Subclasses are responsible for registering themself with the GuiHandler of their mod
* Subclasses are responsible for registering themselves with the GuiHandler of their mod
*/
trait ItemInventory extends Item with GuiProvider {
type TEClass = Any
+11 -3
View File
@@ -4,17 +4,18 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.machine
import cpw.mods.fml.common.registry.GameRegistry
import net.bdew.lib.Misc
import net.bdew.lib.block.HasTE
import net.bdew.lib.block.{HasItemBlock, HasTE}
import net.bdew.lib.recipes.gencfg.ConfigSection
import net.minecraft.block.Block
import net.minecraft.creativetab.CreativeTabs
import net.minecraft.item.ItemBlock
abstract class Machine[T <: Block](val name: String, blockConstruct: => T) {
var block: T = null.asInstanceOf[T]
@@ -24,7 +25,14 @@ abstract class Machine[T <: Block](val name: String, blockConstruct: => T) {
def regBlock(creativeTab: CreativeTabs) {
block = blockConstruct
GameRegistry.registerBlock(block, name)
val itemClass: Class[_ <: ItemBlock] = if (block.isInstanceOf[HasItemBlock])
block.asInstanceOf[HasItemBlock].ItemBlockClass
else
classOf[ItemBlock]
GameRegistry.registerBlock(block, itemClass, name)
block.setCreativeTab(creativeTab)
if (block.isInstanceOf[HasTE[_]]) {
GameRegistry.registerTileEntity(block.asInstanceOf[HasTE[_]].TEClass, "%s.%s".format(modId, name))
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.machine
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.machine
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.multiblock
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.multiblock
@@ -13,7 +13,7 @@ import net.bdew.lib.gui.{Color, Texture}
import net.minecraft.util.IIcon
trait ResourceProvider {
// Icons for rendering, *must* be on block spritesheet
// Icons for rendering, *must* be on block sprite sheet
def edge: IIcon
def disabled: IIcon
def output: IIcon
+8 -8
View File
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.multiblock
@@ -18,33 +18,33 @@ import scala.collection.mutable
object Tools {
def canConnect(world: World, core: BlockRef, kind: String): Boolean = {
val t = core.getTile[TileController](world).getOrElse(return false)
t.getNumOfMoudules(kind) < t.cfg.modules.getOrElse(kind, return false)
t.getNumOfModules(kind) < t.cfg.modules.getOrElse(kind, return false)
}
def findConnections(world: World, start: BlockRef, kind: String) =
(start.neighbours.values flatMap { case pos =>
(pos.tile(world) flatMap {
case t: TileModule => t.connected.cval
case t: TileModule => t.connected.value
case t: TileController => Some(pos)
case _ => None
}) filter (x => canConnect(world, x, kind))
}).toList.distinct
def getAdjancedConnected(w: World, core: BlockRef, pos: BlockRef, seen: mutable.Set[BlockRef]) =
def getConnectedNeighbours(w: World, core: BlockRef, pos: BlockRef, seen: mutable.Set[BlockRef]) =
pos.neighbours.values
.filterNot(seen.contains)
.flatMap(_.getTile[TileModule](w))
.filter(x => x.connected.contains(core))
.map(_.mypos)
.map(_.myPos)
def findReachableModules(world: World, core: BlockRef): Set[BlockRef] = {
val seen = mutable.Set.empty[BlockRef]
val queue = mutable.Queue.empty[BlockRef]
queue ++= getAdjancedConnected(world, core, core, seen)
while (queue.size > 0) {
queue ++= getConnectedNeighbours(world, core, core, seen)
while (queue.nonEmpty) {
val current = queue.dequeue()
seen.add(current)
queue ++= getAdjancedConnected(world, core, current, seen)
queue ++= getConnectedNeighbours(world, core, current, seen)
}
return seen.toSet
}
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.multiblock.block
@@ -33,7 +33,7 @@ abstract class BlockController[T <: TileController](val name: String, material:
override def canConnect(world: IBlockAccess, origin: BlockRef, target: BlockRef) =
getTE(world, origin).modules.contains(target)
override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer, meta: Int, xoffs: Float, yoffs: Float, zoffs: Float): Boolean = {
override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer, meta: Int, xOffs: Float, yOffs: Float, zOffs: Float): Boolean = {
if (player.isSneaking) return false
if (world.isRemote) return true
getTE(world, x, y, z).onClick(player)
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.multiblock.block
@@ -52,12 +52,12 @@ abstract class BlockModule[T <: TileModule](val name: String, val kind: String,
})
}
override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer, meta: Int, xoffs: Float, yoffs: Float, zoffs: Float): Boolean = {
override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer, meta: Int, xOffs: Float, yOffs: Float, zOffs: Float): Boolean = {
if (player.isSneaking) return false
if (world.isRemote) return true
val te = getTE(world, x, y, z)
(for {
p <- te.connected.cval
p <- te.connected.value
bl <- p.block(world)
} yield {
bl.onBlockActivated(world, p.x, p.y, p.z, player, meta, 0, 0, 0)
@@ -4,7 +4,7 @@
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.multiblock.block
@@ -16,8 +16,8 @@ import net.minecraft.world.IBlockAccess
import net.minecraftforge.common.util.ForgeDirection
trait BlockOutput[T <: TileOutput[_]] extends BlockModule[T] with BlockAdditionalRender {
def getAdjancedFaces(face: ForgeDirection, bp: BlockRef) = {
val sides = ConnectedHelper.faceAdjanced(face)
def getNeighbourFaces(face: ForgeDirection, bp: BlockRef) = {
val sides = ConnectedHelper.neighbourFaces(face)
Seq(
(BlockFace(bp, sides.top), resources.arrowTop),
(BlockFace(bp, sides.right), resources.arrowRight),
@@ -28,11 +28,11 @@ trait BlockOutput[T <: TileOutput[_]] extends BlockModule[T] with BlockAdditiona
def getFaceOverlays(world: IBlockAccess, x: Int, y: Int, z: Int, face: ForgeDirection): List[FaceOverlay] = {
var result = List.empty[FaceOverlay]
Option(getTE(world, x, y, z)) flatMap (_.getCore) map { core =>
Option(getTE(world, x, y, z)) flatMap (_.getCore) foreach { core =>
val bf = BlockFace(x, y, z, face)
if (core.outputFaces.contains(bf))
result :+= FaceOverlay(resources.output, resources.outputColors(core.outputFaces(bf)))
for ((bf, icon) <- getAdjancedFaces(face, bf.origin)) {
for ((bf, icon) <- getNeighbourFaces(face, bf.origin)) {
if (core.outputFaces.contains(bf))
result :+= FaceOverlay(icon, resources.outputColors(core.outputFaces(bf)))
}
Loaded 100 of 217 files, more files were not shown because too many files have changed in this diff. Show more