mirror of
https://github.com/GTNewHorizons/bdlib.git
synced 2026-11-24 05:54:39 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
57a1192dc0 | ||
|
|
81e051b592 | ||
|
|
a6eb495fe1 | ||
|
|
2d539e8013 | ||
|
|
c44729536c | ||
|
|
35def010a3 | ||
|
|
911f7aa159 | ||
|
|
3aef519c25 | ||
|
|
6c59b25e2c | ||
|
|
014c1c5e6e | ||
|
|
7fd040e65a | ||
|
|
ece84599f9 | ||
|
|
174af254e8 | ||
|
|
71185838f6 | ||
|
|
f2cdba7800 | ||
|
|
89b54300e3 | ||
|
|
9ee12091e6 | ||
|
|
08ccf07dfb | ||
|
|
382c21f732 | ||
|
|
17e4bf3a2f | ||
|
|
ebe2c1f34a | ||
|
|
fae2825e7b | ||
|
|
b2e138f3cd | ||
|
|
9d897d0663 | ||
|
|
497917185c | ||
|
|
9ff7a75604 | ||
|
|
f8bb1e8fbb | ||
|
|
a530c66680 | ||
|
|
26af828491 | ||
|
|
1c0913d674 | ||
|
|
895cfd9cb6 | ||
|
|
f43dd28e03 | ||
|
|
289f8f7120 | ||
|
|
e7787fb9ca | ||
|
|
58e336f8a9 | ||
|
|
bea6a13896 | ||
|
|
793ceb0024 | ||
|
|
66d9be58c8 | ||
|
|
87d64208c8 | ||
|
|
6f6496c1e3 | ||
|
|
934e984abf | ||
|
|
4900537a82 | ||
|
|
31b5ab9d52 | ||
|
|
8a4ccf7d81 | ||
|
|
429107215f | ||
|
|
0c60d596b6 | ||
|
|
da35094895 | ||
|
|
83d30f12c2 | ||
|
|
8d4484ca18 | ||
|
|
624df87299 | ||
|
|
18b4f19dab | ||
|
|
00b32712a0 | ||
|
|
2a008aa093 | ||
|
|
745170415e | ||
|
|
69b8e80c5f | ||
|
|
93ccc42429 | ||
|
|
dc567bd1be | ||
|
|
516133ee0a | ||
|
|
28de3620a2 | ||
|
|
61ba86d451 | ||
|
|
8e65772cae | ||
|
|
284cdfc970 | ||
|
|
bae688c366 | ||
|
|
d3952b69d0 | ||
|
|
399abf1054 | ||
|
|
f66b97d0cc | ||
|
|
13778072c0 | ||
|
|
7dc95fcce1 | ||
|
|
b71db73b11 | ||
|
|
530d5add82 | ||
|
|
3dd917b2a0 | ||
|
|
8f44111b4c | ||
|
|
8415ee7a00 | ||
|
|
6439ef8f08 | ||
|
|
dc59ee3d31 | ||
|
|
9ae4935fd9 | ||
|
|
0929ba9278 | ||
|
|
1003aa1d6a | ||
|
|
64c0484c2d | ||
|
|
8e90643ea1 | ||
|
|
a232ce52f3 | ||
|
|
35b3a77582 | ||
|
|
be3a1cf2aa | ||
|
|
e0f5d0ceda | ||
|
|
e4169f7a5d | ||
|
|
eb75a26c40 | ||
|
|
3431a6910e | ||
|
|
02598183b8 | ||
|
|
70c19bff5b | ||
|
|
6a78467232 | ||
|
|
561833db33 | ||
|
|
0e345e6675 | ||
|
|
e78e565ec8 | ||
|
|
573330efd3 | ||
|
|
5e7c8bda2f | ||
|
|
9346d95052 | ||
|
|
f0169a15e5 | ||
|
|
1da90af3f1 | ||
|
|
b015636514 | ||
|
|
610be18c74 | ||
|
|
9c977904ab | ||
|
|
cc107d7466 | ||
|
|
4284f11ec4 | ||
|
|
300726e660 | ||
|
|
02850b9f85 | ||
|
|
1618931c6d | ||
|
|
5854625700 | ||
|
|
8bbab862ab | ||
|
|
9e83d04487 | ||
|
|
9202b27340 | ||
|
|
70ee9fabd6 | ||
|
|
78d9bed924 | ||
|
|
92517cdcec | ||
|
|
bcb8edc8a5 | ||
|
|
9a837361e7 | ||
|
|
5ae0461f10 | ||
|
|
b3f8fb3c56 | ||
|
|
023ae4d77f | ||
|
|
b1e0e70fc4 | ||
|
|
5f01716310 | ||
|
|
0976fb4acc | ||
|
|
4effeafbb7 | ||
|
|
e0d3609e66 | ||
|
|
5a1c150a03 | ||
|
|
c5a7fc3d51 | ||
|
|
9787c4836e | ||
|
|
cd833163af | ||
|
|
5a9aedb4d5 | ||
|
|
2a7bbaeb97 | ||
|
|
58125ee291 | ||
|
|
d9cc8ace82 | ||
|
|
32617ff592 | ||
|
|
64683a0208 | ||
|
|
f593458511 | ||
|
|
e6b38472ce | ||
|
|
e6c0ef2c68 | ||
|
|
56110d8ec5 | ||
|
|
f000d11c54 | ||
|
|
913d4f48a6 | ||
|
|
a25553edaf | ||
|
|
82328d10ec | ||
|
|
12f19fc410 | ||
|
|
7c275f434a | ||
|
|
f960050f9c | ||
|
|
87dd7c34c5 | ||
|
|
9fdc6bd880 | ||
|
|
490433a7f4 | ||
|
|
71bef762a6 | ||
|
|
5eef56811b | ||
|
|
5a3fa7ef75 | ||
|
|
2d799bb797 | ||
|
|
03d9b0fef0 | ||
|
|
9b0ed5b0b5 | ||
|
|
e2c7940539 | ||
|
|
cd85553fa1 | ||
|
|
bbe994c28c | ||
|
|
79e308941d | ||
|
|
7a5982bf37 | ||
|
|
5166576d30 | ||
|
|
da3e58b44b | ||
|
|
5bac374211 | ||
|
|
e41e203b7e | ||
|
|
0b87dd83e7 | ||
|
|
49a2f0baec | ||
|
|
35be9bff77 | ||
|
|
2a995f1c05 | ||
|
|
423351bfee | ||
|
|
d67bd24eda | ||
|
|
a10e90a1e1 | ||
|
|
517c3f347f | ||
|
|
0831386798 | ||
|
|
0b45c61c51 | ||
|
|
65aa8a0f66 | ||
|
|
446f2b6e60 | ||
|
|
ecdcdfb05f | ||
|
|
d1d3df184f | ||
|
|
522ac5b57b | ||
|
|
7acca5475f | ||
|
|
1b86f5f7cc | ||
|
|
819197cf1e | ||
|
|
1e71bf7dd9 | ||
|
|
0549f95088 | ||
|
|
06f0007bca | ||
|
|
54499cdb2e | ||
|
|
d80d89acf1 | ||
|
|
926f006f68 | ||
|
|
4697c96cf2 | ||
|
|
8891cfff06 | ||
|
|
971fd94532 | ||
|
|
a9e1e88ff2 | ||
|
|
c9c014a3a9 | ||
|
|
3001309a85 | ||
|
|
07fbbb0267 | ||
|
|
561f176682 | ||
|
|
5f9c311f41 | ||
|
|
78c5ec1362 | ||
|
|
c2a1cc09e3 | ||
|
|
273735a976 | ||
|
|
26137a88d7 | ||
|
|
81a0d00a8b | ||
|
|
5d7c0cd5e8 | ||
|
|
4e2df02b8a | ||
|
|
82e88157f2 | ||
|
|
7b588d896d | ||
|
|
938ea4f3d5 | ||
|
|
1541b96a5a | ||
|
|
17329115a2 | ||
|
|
3966305a61 | ||
|
|
31573cc8fc | ||
|
|
563ae0a328 | ||
|
|
13cef01a2d | ||
|
|
1296b32110 | ||
|
|
005c300d8f | ||
|
|
4754c209ae | ||
|
|
b89d445b17 | ||
|
|
7eefbb1a31 | ||
|
|
4268019935 | ||
|
|
78a69acc44 | ||
|
|
e3bf80e1c9 | ||
|
|
f4f126fed2 | ||
|
|
97b3e0ea1d | ||
|
|
9f6e2d7533 | ||
|
|
9819600b15 | ||
|
|
12a1327e53 | ||
|
|
c495fb8b33 | ||
|
|
0b94b006ec | ||
|
|
c4dbda8a20 | ||
|
|
2698d93444 | ||
|
|
b4cc77d3cc | ||
|
|
2c94505c97 | ||
|
|
2c3607e113 | ||
|
|
b34192d8c2 | ||
|
|
0212f20f69 | ||
|
|
3b31e285d2 | ||
|
|
041f570109 | ||
|
|
745cf43928 | ||
|
|
914815fee7 | ||
|
|
bed3149880 | ||
|
|
302429f340 | ||
|
|
b6fe2dc14d |
No files matched your search
+9
-8
@@ -1,9 +1,10 @@
|
|||||||
/.gradle
|
/bin
|
||||||
/build
|
|
||||||
/deps
|
|
||||||
/eclipse
|
|
||||||
/out
|
/out
|
||||||
|
/build
|
||||||
*.ipr
|
/run
|
||||||
*.iml
|
/deps/run
|
||||||
*.iws
|
/eclipse
|
||||||
|
/.gradle
|
||||||
|
/*.iml
|
||||||
|
/*.ipr
|
||||||
|
/.idea
|
||||||
+48
-38
@@ -1,42 +1,54 @@
|
|||||||
buildscript {
|
buildscript {
|
||||||
|
configurations.all {
|
||||||
|
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
|
||||||
|
}
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
maven {
|
|
||||||
name = "bdew"
|
|
||||||
url = "http://jenkins.bdew.net/maven"
|
|
||||||
}
|
|
||||||
maven {
|
maven {
|
||||||
name = "forge"
|
name = "forge"
|
||||||
url = "http://files.minecraftforge.net/maven"
|
url = "http://files.minecraftforge.net/maven"
|
||||||
}
|
}
|
||||||
|
maven {
|
||||||
|
name = "sonatype"
|
||||||
|
url = "https://oss.sonatype.org/content/repositories/snapshots/"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'net.minecraftforge.gradle:ForgeGradle:1.0-SNAPSHOT'
|
classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
apply plugin: 'forge'
|
|
||||||
apply plugin: 'scala'
|
apply plugin: 'scala'
|
||||||
|
apply plugin: 'forge'
|
||||||
|
|
||||||
version = "0.9.2"
|
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')) {
|
if (project.hasProperty('buildnum')) {
|
||||||
project.version = project.version + '.' + project.buildnum
|
ext.simpleVersion = "${config.bdlib.version}.${project.buildnum}"
|
||||||
} else {
|
} else {
|
||||||
project.version = "0-SNAPSHOT"
|
ext.simpleVersion = "${config.bdlib.version}-DEV"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
version = simpleVersion + '-mc' + config.minecraft.version
|
||||||
|
|
||||||
group = "net.bdew"
|
group = "net.bdew"
|
||||||
archivesBaseName = "bdlib"
|
archivesBaseName = "bdlib"
|
||||||
ext.versuffix = "mc164"
|
|
||||||
|
|
||||||
minecraft {
|
minecraft {
|
||||||
version = "1.6.4-9.11.1.964"
|
version = "${config.minecraft.version}-${config.forge.version}"
|
||||||
|
replace("BDLIB_VER", simpleVersion.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
import org.apache.tools.ant.filters.ReplaceTokens
|
import org.apache.tools.ant.filters.ReplaceTokens
|
||||||
|
|
||||||
def myTokens = [BdLibVer: project.version]
|
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
main {
|
main {
|
||||||
@@ -46,31 +58,15 @@ sourceSets {
|
|||||||
resources {
|
resources {
|
||||||
srcDir 'resources'
|
srcDir 'resources'
|
||||||
}
|
}
|
||||||
|
output.resourcesDir = output.classesDir // Hack for IDEA
|
||||||
}
|
}
|
||||||
processed {
|
|
||||||
scala {
|
|
||||||
srcDir 'build/stage'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
task stage(type: Sync) {
|
|
||||||
inputs.property "tokens", myTokens
|
|
||||||
from sourceSets.main.scala
|
|
||||||
into 'build/stage'
|
|
||||||
filter(ReplaceTokens, tokens: myTokens)
|
|
||||||
}
|
|
||||||
|
|
||||||
compileScala {
|
|
||||||
source = sourceSets.processed.scala
|
|
||||||
dependsOn stage
|
|
||||||
}
|
}
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
inputs.property "tokens", myTokens
|
inputs.property "tokens", minecraft.replacements
|
||||||
from(sourceSets.main.resources.srcDirs) {
|
from(sourceSets.main.resources.srcDirs) {
|
||||||
include 'mcmod.info'
|
include 'mcmod.info'
|
||||||
filter(ReplaceTokens, tokens: myTokens)
|
filter(ReplaceTokens, tokens: minecraft.replacements)
|
||||||
}
|
}
|
||||||
|
|
||||||
from(sourceSets.main.resources.srcDirs) {
|
from(sourceSets.main.resources.srcDirs) {
|
||||||
@@ -79,15 +75,18 @@ processResources {
|
|||||||
}
|
}
|
||||||
|
|
||||||
task sourceJar(type: Jar) {
|
task sourceJar(type: Jar) {
|
||||||
from sourceSets.main.allSource
|
classifier "sources"
|
||||||
}
|
}
|
||||||
|
|
||||||
task deobfJar(type: Jar) {
|
task deobfJar(type: Jar) {
|
||||||
from sourceSets.main.output
|
from sourceSets.main.output
|
||||||
|
classifier "dev"
|
||||||
|
duplicatesStrategy "exclude"
|
||||||
}
|
}
|
||||||
|
|
||||||
jar {
|
afterEvaluate { project ->
|
||||||
appendix = project.versuffix
|
// Fudge the inputs of source jars so we get the version after replacements
|
||||||
|
tasks.getByPath(":sourceJar").from(tasks.getByPath(":sourceMainScala").outputs.files)
|
||||||
}
|
}
|
||||||
|
|
||||||
artifacts {
|
artifacts {
|
||||||
@@ -101,10 +100,7 @@ publishing {
|
|||||||
publications {
|
publications {
|
||||||
maven(MavenPublication) {
|
maven(MavenPublication) {
|
||||||
artifact deobfJar
|
artifact deobfJar
|
||||||
|
artifact sourceJar
|
||||||
artifact sourceJar {
|
|
||||||
classifier "sources"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
repositories {
|
repositories {
|
||||||
@@ -112,4 +108,18 @@ publishing {
|
|||||||
url "file://var/www/maven"
|
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
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
bdlib.version=1.9.4
|
||||||
|
curseforge.id=70496
|
||||||
|
|
||||||
|
minecraft.version=1.7.10
|
||||||
|
forge.version=10.13.4.1558-1.7.10
|
||||||
Vendored
BIN
Binary file not shown.
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
#Thu Nov 28 11:30:59 IST 2013
|
#Wed Jul 02 15:54:47 CDT 2014
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=http\://services.gradle.org/distributions/gradle-1.9-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-bin.zip
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
bdlib.multiblock.face.north=Sever
|
||||||
|
bdlib.multiblock.face.south=Jih
|
||||||
|
bdlib.multiblock.face.east=Západ
|
||||||
|
bdlib.multiblock.face.west=Východ
|
||||||
|
bdlib.multiblock.face.up=Vršek
|
||||||
|
bdlib.multiblock.face.down=Spodek
|
||||||
|
|
||||||
|
bdlib.multiblock.disabled=Zakázáno
|
||||||
|
bdlib.multiblock.incomplete=Tento stroj není kompletní, ještě potřebuje alespoň:
|
||||||
|
bdlib.multiblock.notconnected=Nepřipojeno ke správnému stroji
|
||||||
|
bdlib.multiblock.toomanyoutputs=Připojeno příliš mnoho výstupů, nemohu získat nové připojení
|
||||||
|
|
||||||
|
bdlib.rsmode.always=Vždy ZAPNUTO
|
||||||
|
bdlib.rsmode.never=Zakázáno
|
||||||
|
bdlib.rsmode.rs_on=Povoleno při ruditovém signálu
|
||||||
|
bdlib.rsmode.rs_off=Zakázáno při ruditovém signálu
|
||||||
|
|
||||||
|
bdlib.label.empty=Prázdný
|
||||||
|
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
bdlib.multiblock.face.north=North
|
||||||
|
bdlib.multiblock.face.south=South
|
||||||
|
bdlib.multiblock.face.east=East
|
||||||
|
bdlib.multiblock.face.west=West
|
||||||
|
bdlib.multiblock.face.up=Top
|
||||||
|
bdlib.multiblock.face.down=Bottom
|
||||||
|
|
||||||
|
bdlib.multiblock.disabled=Disabled
|
||||||
|
bdlib.multiblock.incomplete=This machine is incomplete, it requires at least:
|
||||||
|
bdlib.multiblock.notconnected=Not connected to a valid machine
|
||||||
|
bdlib.multiblock.toomanyoutputs=Too many outputs connected, unable to attach new connection
|
||||||
|
bdlib.multiblock.tip.module=Can be installed in:
|
||||||
|
bdlib.multiblock.tip.controller=Possible modules:
|
||||||
|
bdlib.multiblock.tip.module.range= * %s (%s - %s)
|
||||||
|
bdlib.multiblock.tip.module.max= * %s (up to %s)
|
||||||
|
|
||||||
|
bdlib.rsmode.always=Always ON
|
||||||
|
bdlib.rsmode.never=Disabled
|
||||||
|
bdlib.rsmode.rs_on=Enable on redstone
|
||||||
|
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
|
||||||
@@ -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
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
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 sorties connectées, impossible d'ajouter une nouvelle connexion
|
||||||
|
bdlib.multiblock.tip.module=Peut être installé dans :
|
||||||
|
bdlib.multiblock.tip.controller=Modules possibles:
|
||||||
|
bdlib.multiblock.tip.module.range= * %s (%s - %s)
|
||||||
|
bdlib.multiblock.tip.module.max= * %s (plus de %s)
|
||||||
|
|
||||||
|
bdlib.rsmode.always=Toujours actif
|
||||||
|
bdlib.rsmode.never=Désactivé
|
||||||
|
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
|
||||||
@@ -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
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
bdlib.multiblock.face.north=Север
|
||||||
|
bdlib.multiblock.face.south=Юг
|
||||||
|
bdlib.multiblock.face.east=Восток
|
||||||
|
bdlib.multiblock.face.west=Запад
|
||||||
|
bdlib.multiblock.face.up=Верх
|
||||||
|
bdlib.multiblock.face.down=Низ
|
||||||
|
|
||||||
|
bdlib.multiblock.disabled=Отключено
|
||||||
|
bdlib.multiblock.incomplete=Этот механизм не завершён, ему требуется как минимум:
|
||||||
|
bdlib.multiblock.notconnected=Не подключено к верному механизму
|
||||||
|
bdlib.multiblock.toomanyoutputs=Слишком много выходов подсоединено, нельзя установить новое соединение
|
||||||
|
|
||||||
|
bdlib.rsmode.always=Всегда ВКЛ.
|
||||||
|
bdlib.rsmode.never=Отключен
|
||||||
|
bdlib.rsmode.rs_on=Включение по сигналу красного камня
|
||||||
|
bdlib.rsmode.rs_off=Отключение по сигналу красного камня
|
||||||
|
|
||||||
|
bdlib.label.empty=Пусто
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
bdlib.multiblock.face.north=北方
|
||||||
|
bdlib.multiblock.face.south=南方
|
||||||
|
bdlib.multiblock.face.east=东方
|
||||||
|
bdlib.multiblock.face.west=西方
|
||||||
|
bdlib.multiblock.face.up=顶部
|
||||||
|
bdlib.multiblock.face.down=底部
|
||||||
|
|
||||||
|
bdlib.multiblock.disabled=停用
|
||||||
|
bdlib.multiblock.incomplete=这台多方块结构机器未搭建完成, 它至少需要安装一个:
|
||||||
|
bdlib.multiblock.notconnected=未连接有效机器
|
||||||
|
bdlib.multiblock.toomanyoutputs=连接的输出接口过多, 无法连接新的接口
|
||||||
|
|
||||||
|
bdlib.rsmode.always=一直启用
|
||||||
|
bdlib.rsmode.never=一直停用
|
||||||
|
bdlib.rsmode.rs_on=接收到红石信号时启用
|
||||||
|
bdlib.rsmode.rs_off=接收到红石信号时停用
|
||||||
|
|
||||||
|
bdlib.label.empty=空
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
"modid": "bdlib",
|
"modid": "bdlib",
|
||||||
"name": "BD Lib",
|
"name": "BD Lib",
|
||||||
"description": "",
|
"description": "",
|
||||||
"version": "@BdLibVer@",
|
"version": "@BDLIB_VER@",
|
||||||
"url": "bdew.net/mods/",
|
"url": "bdew.net/mods/",
|
||||||
"updateUrl": "",
|
"updateUrl": "",
|
||||||
"authorList": [
|
"authorList": [
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
rootProject.name = 'bdlib'
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* 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 java.util.Locale
|
||||||
|
|
||||||
|
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(Locale.US))) 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
|
||||||
|
}
|
||||||
@@ -1,11 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
package net.bdew.lib
|
||||||
|
|
||||||
import cpw.mods.fml.common.Mod
|
import cpw.mods.fml.common.Mod.EventHandler
|
||||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent
|
import cpw.mods.fml.common.event.{FMLPreInitializationEvent, FMLServerStartingEvent, FMLServerStoppingEvent}
|
||||||
|
import cpw.mods.fml.common.{FMLCommonHandler, Mod}
|
||||||
|
import net.bdew.lib.multiblock.network.NetHandler
|
||||||
|
import net.bdew.lib.tooltip.TooltipHandler
|
||||||
|
import net.minecraft.command.CommandHandler
|
||||||
|
import org.apache.logging.log4j.Logger
|
||||||
|
|
||||||
@Mod(modid = "bdlib", version = "@BdLibVer@", modLanguage = "scala")
|
@Mod(modid = "bdlib", name = "BD lib", version = "BDLIB_VER", modLanguage = "scala")
|
||||||
object BdLib {
|
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) {
|
def preInit(ev: FMLPreInitializationEvent) {
|
||||||
ev.getModLog.info("bdlib @BdLibVer@ loaded")
|
log = ev.getModLog
|
||||||
|
log.info("bdlib BDLIB_VER loaded")
|
||||||
|
log.debug("List of loaded APIs: " + ApiReporter.APIs)
|
||||||
|
FMLCommonHandler.instance().registerCrashCallable(ApiReporter)
|
||||||
|
NetHandler.init()
|
||||||
|
if (ev.getSide.isClient) {
|
||||||
|
TooltipHandler.init()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
def serverStarting(event: FMLServerStartingEvent) {
|
||||||
|
val commandHandler = event.getServer.getCommandManager.asInstanceOf[CommandHandler]
|
||||||
|
commandHandler.registerCommand(CommandDumpRegistry)
|
||||||
|
commandHandler.registerCommand(CommandOreDistribution)
|
||||||
|
onServerStarting.trigger(event)
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
def serverStopping(event: FMLServerStoppingEvent) {
|
||||||
|
onServerStopping.trigger(event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft
|
||||||
|
import net.minecraft.client.renderer.texture.TextureMap
|
||||||
|
import org.lwjgl.input.Keyboard
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Misc functions and shortcuts for client-side code
|
||||||
|
*/
|
||||||
|
object Client {
|
||||||
|
def minecraft = Minecraft.getMinecraft
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* 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 com.google.common.collect.Table
|
||||||
|
import cpw.mods.fml.common.registry.GameData
|
||||||
|
import cpw.mods.fml.relauncher.FMLInjectionData
|
||||||
|
import net.minecraft.command.{CommandBase, ICommandSender}
|
||||||
|
import net.minecraft.item.ItemStack
|
||||||
|
import net.minecraftforge.fluids.FluidRegistry
|
||||||
|
import net.minecraftforge.oredict.OreDictionary
|
||||||
|
|
||||||
|
object CommandDumpRegistry extends CommandBase {
|
||||||
|
def getCommandName = "dumpregistry"
|
||||||
|
override def getRequiredPermissionLevel = 2
|
||||||
|
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?
|
||||||
|
val dumpFile = new File(mcHome, "registry.dump")
|
||||||
|
val dumpWriter = new BufferedWriter(new FileWriter(dumpFile))
|
||||||
|
import scala.collection.JavaConversions._
|
||||||
|
try {
|
||||||
|
dumpWriter.write("==== BLOCKS ====\n")
|
||||||
|
dumpWriter.write(GameData.getBlockRegistry.map(GameData.getBlockRegistry.getNameForObject).toList.sorted.mkString("\n"))
|
||||||
|
dumpWriter.write("\n\n")
|
||||||
|
|
||||||
|
dumpWriter.write("==== ITEMS ====\n")
|
||||||
|
dumpWriter.write(GameData.getItemRegistry.map(GameData.getItemRegistry.getNameForObject).toList.sorted.mkString("\n"))
|
||||||
|
dumpWriter.write("\n\n")
|
||||||
|
|
||||||
|
dumpWriter.write("==== CUSTOM STACKS ====\n")
|
||||||
|
val stacksField = classOf[GameData].getDeclaredField("customItemStacks")
|
||||||
|
stacksField.setAccessible(true)
|
||||||
|
val stacksData = stacksField.get(null).asInstanceOf[Table[String, String, ItemStack]]
|
||||||
|
dumpWriter.write(stacksData.cellSet().map(x => x.getRowKey + ":" + x.getColumnKey).toList.sorted.mkString("\n"))
|
||||||
|
dumpWriter.write("\n\n")
|
||||||
|
|
||||||
|
dumpWriter.write("==== ORE DICT ====\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")
|
||||||
|
dumpWriter.write(FluidRegistry.getRegisteredFluids.map(_._1).toList.sorted.mkString("\n"))
|
||||||
|
dumpWriter.write("\n\n")
|
||||||
|
|
||||||
|
CommandBase.func_152373_a(sender, this, "Registry dumped to " + dumpFile.getCanonicalPath)
|
||||||
|
} catch {
|
||||||
|
case e: Throwable =>
|
||||||
|
CommandBase.func_152373_a(sender, this, "Failed to save registry dump: " + e)
|
||||||
|
BdLib.logErrorException("Failed to save registry dump", e)
|
||||||
|
} finally {
|
||||||
|
dumpWriter.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
|
* https://github.com/bdew/bdlib
|
||||||
|
*
|
||||||
|
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||||
|
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||||
|
* http://bdew.net/minecraft-mod-public-license/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.bdew.lib
|
||||||
|
|
||||||
|
import net.minecraft.creativetab.CreativeTabs
|
||||||
|
import net.minecraft.item.Item
|
||||||
|
|
||||||
|
class CreativeTabContainer {
|
||||||
|
|
||||||
|
class Tab(name: String, item: => Item) extends CreativeTabs(name) {
|
||||||
|
override def getTabIconItem = item
|
||||||
|
}
|
||||||
|
|
||||||
|
BdLib.logInfo("Loaded creative tabs for %s", Misc.getActiveModId)
|
||||||
|
|
||||||
|
def init() {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
|
* https://github.com/bdew/bdlib
|
||||||
|
*
|
||||||
|
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||||
|
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||||
|
* http://bdew.net/minecraft-mod-public-license/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.bdew.lib
|
||||||
|
|
||||||
|
import java.text.DecimalFormat
|
||||||
|
|
||||||
|
object DecFormat {
|
||||||
|
val thousandsFmt = new DecimalFormat("#,##0")
|
||||||
|
val dec2Fmt = new DecimalFormat("#,##0.00")
|
||||||
|
val dec1Fmt = new DecimalFormat("#,##0.0")
|
||||||
|
|
||||||
|
def round(x: Double) = thousandsFmt.format(x).replace('\u00A0', ' ')
|
||||||
|
def round(x: Float) = thousandsFmt.format(x).replace('\u00A0', ' ')
|
||||||
|
def round(x: Int) = thousandsFmt.format(x).replace('\u00A0', ' ')
|
||||||
|
|
||||||
|
def dec2(x: Double) = dec2Fmt.format(x).replace('\u00A0', ' ')
|
||||||
|
def dec2(x: Float) = dec2Fmt.format(x).replace('\u00A0', ' ')
|
||||||
|
def dec2(x: Int) = dec2Fmt.format(x).replace('\u00A0', ' ')
|
||||||
|
|
||||||
|
def short(x: Double) = (if (x > 10) thousandsFmt.format(x) else if (x > 1) dec1Fmt.format(x) else dec2Fmt.format(x)).replace('\u00A0', ' ')
|
||||||
|
def short(x: Float) = (if (x > 10) thousandsFmt.format(x) else if (x > 1) dec1Fmt.format(x) else dec2Fmt.format(x)).replace('\u00A0', ' ')
|
||||||
|
def short(x: Int) = (if (x > 10) thousandsFmt.format(x) else if (x > 1) dec1Fmt.format(x) else dec2Fmt.format(x)).replace('\u00A0', ' ')
|
||||||
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) bdew, 2013
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
* https://github.com/bdew/bdlib
|
* https://github.com/bdew/bdlib
|
||||||
*
|
*
|
||||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
* 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
|
* 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
|
package net.bdew.lib
|
||||||
@@ -12,7 +12,7 @@ package net.bdew.lib
|
|||||||
class EventBase[T] extends {
|
class EventBase[T] extends {
|
||||||
var listeners = Seq.empty[T]
|
var listeners = Seq.empty[T]
|
||||||
def listen(x: T) = listeners :+= x
|
def listen(x: T) = listeners :+= x
|
||||||
def hasListeners = listeners.size > 0
|
def hasListeners = listeners.nonEmpty
|
||||||
}
|
}
|
||||||
|
|
||||||
class Event0 extends EventBase[() => Unit] {
|
class Event0 extends EventBase[() => Unit] {
|
||||||
@@ -28,7 +28,7 @@ class Event2[T, R] extends EventBase[(T, R) => Unit] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
object Event {
|
object Event {
|
||||||
def apply(t: Unit) = new Event0
|
def apply() = new Event0
|
||||||
def apply[T] = new Event1[T]
|
def apply[T] = new Event1[T]
|
||||||
def apply[T, R] = new Event2[T, R]
|
def apply[T, R] = new Event2[T, R]
|
||||||
}
|
}
|
||||||
+131
-22
@@ -1,38 +1,45 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) bdew, 2013
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
* https://github.com/bdew/bdlib
|
* https://github.com/bdew/bdlib
|
||||||
*
|
*
|
||||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
* 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
|
* 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
|
package net.bdew.lib
|
||||||
|
|
||||||
|
import java.util
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
import cpw.mods.fml.common.registry.GameRegistry
|
import cpw.mods.fml.common.registry.GameRegistry
|
||||||
import net.minecraft.nbt.{NBTTagCompound, NBTTagList}
|
import cpw.mods.fml.common.versioning.VersionParser
|
||||||
import net.minecraft.util.StatCollector
|
import cpw.mods.fml.common.{Loader, ModAPIManager, ModContainer}
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import cpw.mods.fml.common.versioning.{ArtifactVersion, VersionParser}
|
import net.minecraft.nbt.NBTTagCompound
|
||||||
import cpw.mods.fml.common.Loader
|
import net.minecraft.tileentity.TileEntity
|
||||||
|
import net.minecraft.util.{IIcon, StatCollector}
|
||||||
|
import net.minecraft.world.biome.BiomeGenBase
|
||||||
|
import net.minecraftforge.common.util.ForgeDirection
|
||||||
|
import net.minecraftforge.fluids.{Fluid, FluidStack}
|
||||||
import net.minecraftforge.oredict.ShapedOreRecipe
|
import net.minecraftforge.oredict.ShapedOreRecipe
|
||||||
|
|
||||||
object Misc {
|
object Misc {
|
||||||
def iterNbtList[X](list: NBTTagList) =
|
def getActiveModId = Option(Loader.instance().activeModContainer().getModId) getOrElse "<UNKNOWN>"
|
||||||
for (i <- 0 until list.tagCount()) yield list.tagAt(i).asInstanceOf[X]
|
|
||||||
|
|
||||||
def toLocal(s: String) = StatCollector.translateToLocal(s)
|
def toLocal(s: String) = StatCollector.translateToLocal(s)
|
||||||
def toLocalF(s: String, params: Any*) = StatCollector.translateToLocal(s).format(params: _*)
|
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]) =
|
def flattenRecipe(pattern: Seq[String], items: Map[Char, AnyRef]) =
|
||||||
pattern ++ items.map {
|
pattern ++ items.flatMap {
|
||||||
case (k, v) => Seq(new Character(k), v)
|
case (k, v) => Seq(new Character(k), v)
|
||||||
}.flatten
|
}
|
||||||
|
|
||||||
def wrapTag(n: String, f: (NBTTagCompound) => Any)(t: NBTTagCompound) {
|
def wrapTag(n: String, f: (NBTTagCompound) => Any)(t: NBTTagCompound) {
|
||||||
val p = t.getCompoundTag(n)
|
val p = t.getCompoundTag(n)
|
||||||
f(p)
|
f(p)
|
||||||
t.setCompoundTag(n, p)
|
t.setTag(n, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
def addRecipe(result: ItemStack, pattern: Seq[String], items: Map[Char, AnyRef]) =
|
def addRecipe(result: ItemStack, pattern: Seq[String], items: Map[Char, AnyRef]) =
|
||||||
@@ -41,26 +48,128 @@ object Misc {
|
|||||||
def addRecipeOD(result: ItemStack, pattern: Seq[String], items: Map[Char, AnyRef]) =
|
def addRecipeOD(result: ItemStack, pattern: Seq[String], items: Map[Char, AnyRef]) =
|
||||||
GameRegistry.addRecipe(new ShapedOreRecipe(result, flattenRecipe(pattern, items): _*))
|
GameRegistry.addRecipe(new ShapedOreRecipe(result, flattenRecipe(pattern, items): _*))
|
||||||
|
|
||||||
def min[T](vals: T*)(implicit o: Ordering[T]): T = vals.min(o)
|
def min[T: Ordering](values: T*) = values.min
|
||||||
def max[T](vals: T*)(implicit o: Ordering[T]): T = vals.max(o)
|
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
|
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
|
||||||
|
|
||||||
def iterSome[T](list: Seq[T], indexes: Iterable[Int]): Iterable[T] = for (i <- indexes) yield list(i)
|
def iterSome[T](list: Seq[T], indexes: Iterable[Int]): Iterable[T] = for (i <- indexes) yield list(i)
|
||||||
def iterSomeEnum[T](list: Seq[T], indexes: Iterable[Int]): Iterable[(Int, T)] = for (i <- indexes) yield i -> list(i)
|
def iterSomeEnum[T](list: Seq[T], indexes: Iterable[Int]): Iterable[(Int, T)] = for (i <- indexes) yield i -> list(i)
|
||||||
|
|
||||||
def filterType[T](from: Iterable[_], cls: Class[T]) = from.filter(cls.isInstance).asInstanceOf[Iterable[T]]
|
def filterType[T](from: Iterable[_], cls: Class[T]) = from.filter(cls.isInstance).asInstanceOf[Iterable[T]]
|
||||||
|
|
||||||
def haveModVersion(spec: String): Boolean = {
|
def getBiomeByName(name: String) = BiomeGenBase.getBiomeGenArray.find(x => x != null && x.biomeName == name).orNull
|
||||||
val req = VersionParser.parseVersionReference(spec)
|
|
||||||
val modid = req.getLabel
|
|
||||||
|
|
||||||
if (!Loader.instance.getIndexedModList.containsKey(modid)) return false
|
private lazy val modLookup = {
|
||||||
|
val mods = new util.ArrayList[ModContainer]
|
||||||
|
val nameLookup = new util.HashMap[String, ModContainer]
|
||||||
|
|
||||||
val found: ArtifactVersion = Loader.instance.getIndexedModList.get(modid).getProcessedVersion
|
nameLookup.putAll(Loader.instance().getIndexedModList)
|
||||||
|
ModAPIManager.INSTANCE.injectAPIModContainers(mods, nameLookup)
|
||||||
|
|
||||||
if (found == null || !req.containsVersion(found)) return false
|
import scala.collection.JavaConverters._
|
||||||
|
nameLookup.asScala
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def haveModVersion(modId: String) = {
|
||||||
|
val spec = VersionParser.parseVersionReference(modId)
|
||||||
|
modLookup.contains(spec.getLabel) && spec.containsVersion(modLookup(spec.getLabel).getProcessedVersion)
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
def forgeDirection(i: Int) = ForgeDirection.values()(i)
|
||||||
|
|
||||||
|
// Easy replacement for various "if(foo.isInstanceOf[Bar]) foo.asInstanceOf[Bar]" constructs
|
||||||
|
def asInstanceOpt[T](v: Any, cls: Class[T]) =
|
||||||
|
if (cls.isInstance(v)) Some(v.asInstanceOf[T]) else None
|
||||||
|
|
||||||
|
// Same thing but in a way that's easier to use with map, etc.
|
||||||
|
def asInstanceOpt[T](cls: Class[T])(v: Any) =
|
||||||
|
if (cls.isInstance(v)) Some(v.asInstanceOf[T]) else None
|
||||||
|
|
||||||
|
def getNeighbourTile[T](origin: TileEntity, dir: ForgeDirection, cls: Class[T]) =
|
||||||
|
Option(origin.getWorldObj.getTileEntity(origin.xCoord + dir.offsetX,
|
||||||
|
origin.yCoord + dir.offsetY, origin.zCoord + dir.offsetZ)) flatMap (asInstanceOpt(_, cls))
|
||||||
|
|
||||||
|
@inline def applyMutator[T](f: (T) => Unit, init: T): T = {
|
||||||
|
f(init)
|
||||||
|
init
|
||||||
|
}
|
||||||
|
|
||||||
|
@inline def applyMutator[T](init: T)(f: (T) => Unit) = {
|
||||||
|
f(init)
|
||||||
|
init
|
||||||
|
}
|
||||||
|
|
||||||
|
def 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")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides something like java try-with-resources in scala
|
||||||
|
*/
|
||||||
|
def withAutoClose[T <: AutoCloseable, R](o: T)(f: T => R): R = {
|
||||||
|
val res = try {
|
||||||
|
f(o)
|
||||||
|
} catch {
|
||||||
|
case t1: Throwable =>
|
||||||
|
if (o != null) {
|
||||||
|
try {
|
||||||
|
o.close()
|
||||||
|
} catch {
|
||||||
|
case t2: Throwable =>
|
||||||
|
t1.addSuppressed(t2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw t1
|
||||||
|
}
|
||||||
|
if (o != null)
|
||||||
|
o.close()
|
||||||
|
res
|
||||||
|
}
|
||||||
|
|
||||||
|
def iconName(domain: String, name: String, path: String*) =
|
||||||
|
if (path.isEmpty)
|
||||||
|
"%s:%s".format(domain, name).toLowerCase(Locale.US)
|
||||||
|
else
|
||||||
|
"%s:%s/%s".format(domain, name, path.mkString("/")).toLowerCase(Locale.US)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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()
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
|
* https://github.com/bdew/bdlib
|
||||||
|
*
|
||||||
|
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||||
|
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||||
|
* http://bdew.net/minecraft-mod-public-license/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.bdew.lib.block
|
||||||
|
|
||||||
|
import net.minecraftforge.common.util.ForgeDirection
|
||||||
|
|
||||||
|
case class BlockFace(x: Int, y: Int, z: Int, face: ForgeDirection) {
|
||||||
|
def origin = BlockRef(x, y, z)
|
||||||
|
def target = origin.neighbour(face)
|
||||||
|
def opposite = face.getOpposite
|
||||||
|
}
|
||||||
|
|
||||||
|
object BlockFace {
|
||||||
|
def apply(bp: BlockRef, face: ForgeDirection) = new BlockFace(bp.x, bp.y, bp.z, face)
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
|
* https://github.com/bdew/bdlib
|
||||||
|
*
|
||||||
|
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||||
|
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||||
|
* http://bdew.net/minecraft-mod-public-license/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.bdew.lib.block
|
||||||
|
|
||||||
|
import net.minecraft.block.Block
|
||||||
|
import net.minecraft.nbt.NBTTagCompound
|
||||||
|
import net.minecraft.tileentity.TileEntity
|
||||||
|
import net.minecraft.world.IBlockAccess
|
||||||
|
import net.minecraftforge.common.util.ForgeDirection
|
||||||
|
|
||||||
|
import scala.reflect.ClassTag
|
||||||
|
|
||||||
|
case class BlockRef(x: Int, y: Int, z: Int) {
|
||||||
|
def 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)
|
||||||
|
|
||||||
|
def neighbour(side: ForgeDirection) = BlockRef(x + side.offsetX, y + side.offsetY, z + side.offsetZ)
|
||||||
|
def neighbours = ForgeDirection.VALID_DIRECTIONS.map(x => x -> neighbour(x)).toMap
|
||||||
|
|
||||||
|
override def toString = "(x=%d y=%d z=%d)".format(x, y, z)
|
||||||
|
|
||||||
|
def getTile[T: ClassTag](w: IBlockAccess) = tile(w) flatMap { tile =>
|
||||||
|
val cls = implicitly[ClassTag[T]].runtimeClass
|
||||||
|
if (cls.isInstance(tile))
|
||||||
|
Some(tile.asInstanceOf[T])
|
||||||
|
else None
|
||||||
|
}
|
||||||
|
|
||||||
|
def ==(tx: Int, ty: Int, tz: Int) = x == tx && y == ty && z == tz
|
||||||
|
|
||||||
|
def getBlock[T: ClassTag](w: IBlockAccess) = block(w) flatMap { block =>
|
||||||
|
val cls = implicitly[ClassTag[T]].runtimeClass
|
||||||
|
if (cls.isInstance(block))
|
||||||
|
Some(block.asInstanceOf[T])
|
||||||
|
else None
|
||||||
|
}
|
||||||
|
|
||||||
|
def writeToNBT(tag: NBTTagCompound) {
|
||||||
|
tag.setInteger("x", x)
|
||||||
|
tag.setInteger("y", y)
|
||||||
|
tag.setInteger("z", z)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
object BlockRef {
|
||||||
|
def fromTile(te: TileEntity) = BlockRef(te.xCoord, te.yCoord, te.zCoord)
|
||||||
|
def fromNBT(tag: NBTTagCompound) =
|
||||||
|
BlockRef(tag.getInteger("x"), tag.getInteger("y"), tag.getInteger("z"))
|
||||||
|
}
|
||||||
@@ -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,30 +1,34 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) bdew, 2013
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
* https://github.com/bdew/bdlib
|
* https://github.com/bdew/bdlib
|
||||||
*
|
*
|
||||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
* 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
|
* 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
|
package net.bdew.lib.block
|
||||||
|
|
||||||
import net.minecraft.block.{ITileEntityProvider, Block}
|
import net.bdew.lib.BdLib
|
||||||
import net.minecraft.world.{IBlockAccess, World}
|
import net.minecraft.block.{Block, ITileEntityProvider}
|
||||||
import net.minecraft.tileentity.TileEntity
|
import net.minecraft.tileentity.TileEntity
|
||||||
import cpw.mods.fml.common.FMLCommonHandler
|
import net.minecraft.world.{IBlockAccess, World}
|
||||||
|
|
||||||
trait HasTE[T] extends Block with ITileEntityProvider {
|
trait HasTE[T] extends Block with ITileEntityProvider {
|
||||||
val TEClass: Class[_ <: TileEntity]
|
val TEClass: Class[_ <: TileEntity]
|
||||||
def createNewTileEntity(world: World): TileEntity = TEClass.newInstance()
|
|
||||||
|
def createNewTileEntity(world: World, meta: Int): TileEntity = TEClass.newInstance()
|
||||||
|
|
||||||
|
def getTE(w: IBlockAccess, ref: BlockRef): T = getTE(w, ref.x, ref.y, ref.z)
|
||||||
|
|
||||||
def getTE(w: IBlockAccess, x: Int, y: Int, z: Int): T = {
|
def getTE(w: IBlockAccess, x: Int, y: Int, z: Int): T = {
|
||||||
var t = w.getBlockTileEntity(x, y, z)
|
var t = w.getTileEntity(x, y, z)
|
||||||
if ((t == null) || !TEClass.isInstance(t)) {
|
if ((t == null) || !TEClass.isInstance(t)) {
|
||||||
FMLCommonHandler.instance().getFMLLogger.severe("Tile entity for block %s at (%d,%d,%d) is corrupt or missing - recreating".format(this, x, y, z))
|
BdLib.logError("Tile entity for block %s at (%d,%d,%d) is corrupt or missing - recreating", this, x, y, z)
|
||||||
w match {
|
w match {
|
||||||
case ww: World =>
|
case ww: World =>
|
||||||
t = createNewTileEntity(ww)
|
t = createNewTileEntity(ww, w.getBlockMetadata(x, y, z))
|
||||||
ww.setBlockTileEntity(x, y, z, t)
|
ww.setTileEntity(x, y, z, t)
|
||||||
case _ =>
|
case _ =>
|
||||||
sys.error("Unable to recreate TE")
|
sys.error("Unable to recreate TE")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
|
* https://github.com/bdew/bdlib
|
||||||
|
*
|
||||||
|
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||||
|
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||||
|
* http://bdew.net/minecraft-mod-public-license/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.bdew.lib.block
|
||||||
|
|
||||||
|
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||||
|
import net.bdew.lib.Misc
|
||||||
|
import net.minecraft.block.Block
|
||||||
|
import net.minecraft.block.material.Material
|
||||||
|
import net.minecraft.client.renderer.texture.IIconRegister
|
||||||
|
|
||||||
|
import scala.language.implicitConversions
|
||||||
|
|
||||||
|
trait NamedBlock extends Block {
|
||||||
|
def name: String
|
||||||
|
}
|
||||||
|
|
||||||
|
class SimpleBlock(val name: String, material: Material) extends Block(material) with NamedBlock {
|
||||||
|
val modId = Misc.getActiveModId
|
||||||
|
setBlockName(modId + "." + name)
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
override def registerBlockIcons(reg: IIconRegister) {
|
||||||
|
blockIcon = reg.registerIcon(Misc.iconName(modId, name))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* 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.config
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.ObfuscationReflectionHelper
|
||||||
|
import cpw.mods.fml.common.registry.GameRegistry
|
||||||
|
import net.bdew.lib.Misc
|
||||||
|
import net.bdew.lib.block.{HasItemBlock, HasTE, NamedBlock}
|
||||||
|
import net.minecraft.block.Block
|
||||||
|
import net.minecraft.creativetab.CreativeTabs
|
||||||
|
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 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[_]] && !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() {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* 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.config
|
||||||
|
|
||||||
|
import net.minecraftforge.fluids.{Fluid, FluidRegistry}
|
||||||
|
|
||||||
|
class FluidManager() {
|
||||||
|
def regFluid[T <: Fluid](fluid: T): T = {
|
||||||
|
FluidRegistry.registerFluid(fluid)
|
||||||
|
return fluid
|
||||||
|
}
|
||||||
|
def load() {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
|
* https://github.com/bdew/bdlib
|
||||||
|
*
|
||||||
|
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||||
|
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||||
|
* http://bdew.net/minecraft-mod-public-license/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.bdew.lib.config
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.registry.GameRegistry
|
||||||
|
import net.bdew.lib.items.{NamedItem, SimpleItem}
|
||||||
|
import net.minecraft.creativetab.CreativeTabs
|
||||||
|
import net.minecraft.item.{Item, ItemStack}
|
||||||
|
|
||||||
|
class ItemManager(creativeTab: CreativeTabs) {
|
||||||
|
def regSimpleItem(name: String): SimpleItem = regItem(new SimpleItem(name), name)
|
||||||
|
|
||||||
|
def regItem[T <: NamedItem](item: T): T = regItem[T](item, item.name)
|
||||||
|
|
||||||
|
def regItem[T <: Item](item: T, name: String, addStack: Boolean = false): T = {
|
||||||
|
GameRegistry.registerItem(item, name)
|
||||||
|
item.setCreativeTab(creativeTab)
|
||||||
|
if (addStack)
|
||||||
|
GameRegistry.registerCustomItemStack(name, new ItemStack(item))
|
||||||
|
return item
|
||||||
|
}
|
||||||
|
|
||||||
|
def load() {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* 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.config
|
||||||
|
|
||||||
|
import net.bdew.lib.Misc
|
||||||
|
import net.bdew.lib.gui.{GuiHandler, GuiProvider}
|
||||||
|
import net.bdew.lib.machine.Machine
|
||||||
|
import net.bdew.lib.multiblock.MachineCore
|
||||||
|
import net.bdew.lib.multiblock.block.BlockModule
|
||||||
|
import net.bdew.lib.recipes.gencfg.ConfigSection
|
||||||
|
import net.minecraft.creativetab.CreativeTabs
|
||||||
|
|
||||||
|
class MachineManager(val tuning: ConfigSection, guiHandler: GuiHandler, creativeTab: CreativeTabs) {
|
||||||
|
def registerMachine[R <: Machine[_]](machine: R): R = {
|
||||||
|
machine.tuning = tuning.getSection(machine.name)
|
||||||
|
if (machine.tuning.getBoolean("Enabled")) {
|
||||||
|
machine.enabled = true
|
||||||
|
machine.regBlock(creativeTab)
|
||||||
|
if (machine.isInstanceOf[GuiProvider])
|
||||||
|
guiHandler.register(machine.asInstanceOf[GuiProvider])
|
||||||
|
}
|
||||||
|
return machine
|
||||||
|
}
|
||||||
|
|
||||||
|
def load() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
trait MachineManagerMultiblock extends MachineManager {
|
||||||
|
var controllers = Set.empty[MachineCore]
|
||||||
|
|
||||||
|
override def registerMachine[R <: Machine[_]](machine: R): R = {
|
||||||
|
super.registerMachine(machine)
|
||||||
|
if (machine.enabled) {
|
||||||
|
Misc.asInstanceOpt(machine, classOf[MachineCore]) foreach { controllerMachine =>
|
||||||
|
controllers += controllerMachine
|
||||||
|
controllerMachine.getController.machine = controllerMachine
|
||||||
|
}
|
||||||
|
}
|
||||||
|
machine
|
||||||
|
}
|
||||||
|
|
||||||
|
def getMachinesForBlock(b: BlockModule[_]): Map[MachineCore, (Int, Int)] = {
|
||||||
|
(for (machine <- controllers; max <- machine.modules.get(b.kind)) yield {
|
||||||
|
machine ->(machine.required.getOrElse(b.kind, 0), max)
|
||||||
|
}).toMap
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
/*
|
||||||
|
* 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 cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||||
|
import net.bdew.lib.Misc
|
||||||
|
import net.bdew.lib.block.{BlockRef, HasTE}
|
||||||
|
import net.bdew.lib.items.ItemUtils
|
||||||
|
import net.minecraft.block.Block
|
||||||
|
import net.minecraft.entity.player.{EntityPlayer, EntityPlayerMP}
|
||||||
|
import net.minecraft.item.ItemStack
|
||||||
|
import net.minecraft.util.IIcon
|
||||||
|
import net.minecraft.world.{IBlockAccess, World}
|
||||||
|
import net.minecraftforge.common.util.ForgeDirection
|
||||||
|
|
||||||
|
trait BlockCoverable[T <: TileCoverable] extends HasTE[T] {
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
override def getRenderType = CoverRenderer.id
|
||||||
|
|
||||||
|
private def getCoverItem(w: IBlockAccess, x: Int, y: Int, z: Int, side: ForgeDirection): Option[(ItemCover, ItemStack, TileCoverable)] = {
|
||||||
|
val te = getTE(w, x, y, z)
|
||||||
|
for {
|
||||||
|
coverStack <- Option(te.covers(side).value)
|
||||||
|
coverItemMaybe <- Option(coverStack.getItem)
|
||||||
|
coverItem <- Misc.asInstanceOpt(coverItemMaybe, classOf[ItemCover])
|
||||||
|
} yield (coverItem, coverStack, te)
|
||||||
|
}
|
||||||
|
|
||||||
|
override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer, face: Int, xOffs: Float, yOffs: Float, zOffs: Float): Boolean = {
|
||||||
|
val te = getTE(world, x, y, z)
|
||||||
|
val side = Misc.forgeDirection(face)
|
||||||
|
|
||||||
|
// Shift+RightClick with empty hand should remove cover
|
||||||
|
if (player.getCurrentEquippedItem == null && player.isSneaking) {
|
||||||
|
for {
|
||||||
|
cover <- Option(te.covers(side).value)
|
||||||
|
coverItem <- Misc.asInstanceOpt(cover.getItem, classOf[ItemCover])
|
||||||
|
} {
|
||||||
|
if (!world.isRemote) {
|
||||||
|
te.covers(side) := null
|
||||||
|
te.onCoversChanged()
|
||||||
|
coverChanged(world, x, y, z, side)
|
||||||
|
ItemUtils.dropItemToPlayer(world, player, coverItem.onRemove(cover))
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If held item is cover - try to install it
|
||||||
|
for {
|
||||||
|
activeStack <- Option(player.getCurrentEquippedItem)
|
||||||
|
activeItem <- Option(activeStack.getItem)
|
||||||
|
coverItem <- Misc.asInstanceOpt(activeItem, classOf[ItemCover])
|
||||||
|
if te.isValidCover(side, activeStack) && coverItem.isValidTile(te, activeStack)
|
||||||
|
} {
|
||||||
|
if (!world.isRemote && player.isInstanceOf[EntityPlayerMP]) {
|
||||||
|
for {
|
||||||
|
oldCover <- Option(te.covers(side).value)
|
||||||
|
oldItem <- Misc.asInstanceOpt(oldCover.getItem, classOf[ItemCover])
|
||||||
|
} {
|
||||||
|
ItemUtils.throwItemAt(world, te.xCoord + side.offsetX, te.yCoord + side.offsetY, te.zCoord + side.offsetZ, oldItem.onRemove(oldCover))
|
||||||
|
}
|
||||||
|
|
||||||
|
te.covers(side) := coverItem.onInstall(te, side, activeStack.splitStack(1), player.asInstanceOf[EntityPlayerMP])
|
||||||
|
|
||||||
|
if (activeStack.stackSize <= 0)
|
||||||
|
player.inventory.setInventorySlotContents(player.inventory.currentItem, null)
|
||||||
|
|
||||||
|
te.onCoversChanged()
|
||||||
|
coverChanged(world, x, y, z, side)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// If has cover - let it handle the click
|
||||||
|
for ((item, stack, te) <- getCoverItem(world, x, y, z, side)) {
|
||||||
|
if (item.clickCover(te, side, stack, player)) return true
|
||||||
|
}
|
||||||
|
|
||||||
|
super.onBlockActivated(world, x, y, z, player, face, xOffs, yOffs, zOffs)
|
||||||
|
}
|
||||||
|
|
||||||
|
override def canProvidePower = true
|
||||||
|
|
||||||
|
override def isProvidingWeakPower(w: IBlockAccess, x: Int, y: Int, z: Int, side: Int): Int = {
|
||||||
|
val direction = Misc.forgeDirection(side).getOpposite
|
||||||
|
for ((item, stack, te) <- getCoverItem(w, x, y, z, direction)) {
|
||||||
|
if (item.isEmittingSignal(te, direction, stack)) return 15
|
||||||
|
}
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
|
def coverChanged(w: World, x: Int, y: Int, z: Int, side: ForgeDirection): Unit = {
|
||||||
|
val pos = BlockRef(x, y, z).neighbour(side)
|
||||||
|
w.notifyBlockOfNeighborChange(pos.x, pos.y, pos.z, pos.block(w).orNull)
|
||||||
|
}
|
||||||
|
|
||||||
|
def getCoverIcon(w: IBlockAccess, x: Int, y: Int, z: Int, side: ForgeDirection): Option[IIcon] =
|
||||||
|
for ((item, stack, te) <- getCoverItem(w, x, y, z, side))
|
||||||
|
yield item.getCoverIcon(te, side, stack)
|
||||||
|
|
||||||
|
override def breakBlock(world: World, x: Int, y: Int, z: Int, block: Block, meta: Int) {
|
||||||
|
if (!world.isRemote) {
|
||||||
|
val te = getTE(world, x, y, z)
|
||||||
|
for {
|
||||||
|
(dir, covOpt) <- te.covers
|
||||||
|
cover <- Option(covOpt.value)
|
||||||
|
item <- Misc.asInstanceOpt(cover.getItem, classOf[ItemCover])
|
||||||
|
} {
|
||||||
|
te.covers(dir) := null
|
||||||
|
ItemUtils.throwItemAt(world, x, y, z, item.onRemove(cover))
|
||||||
|
coverChanged(world, x, y, z, dir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.breakBlock(world, x, y, z, block, meta)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
|
* https://github.com/bdew/bdlib
|
||||||
|
*
|
||||||
|
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||||
|
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||||
|
* http://bdew.net/minecraft-mod-public-license/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.bdew.lib.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)
|
||||||
|
if (!renderer.hasOverrideBlockTexture)
|
||||||
|
for {
|
||||||
|
blockCov <- Misc.asInstanceOpt(block, classOf[BlockCoverable[_]])
|
||||||
|
face <- ForgeDirection.VALID_DIRECTIONS
|
||||||
|
icon <- blockCov.getCoverIcon(world, x, y, z, face)
|
||||||
|
if block.shouldSideBeRendered(world, x + face.offsetX, y + face.offsetY, z + face.offsetZ, face.ordinal())
|
||||||
|
} ConnectedHelper.draw(face, 8).doDraw(ConnectedHelper.Vec3F(x, y, z), icon)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* 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.covers
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.{EntityPlayer, EntityPlayerMP}
|
||||||
|
import net.minecraft.item.{Item, ItemStack}
|
||||||
|
import net.minecraft.util.IIcon
|
||||||
|
import net.minecraftforge.common.util.ForgeDirection
|
||||||
|
|
||||||
|
trait ItemCover extends Item {
|
||||||
|
/**
|
||||||
|
* @return true if tickCover should be called
|
||||||
|
*/
|
||||||
|
def isCoverTicking: Boolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param te Host TileEntity
|
||||||
|
* @param side Side the cover is installed on
|
||||||
|
* @param cover Cover ItemStack
|
||||||
|
* @return Icon to render, MUST be on terrain sprite sheet (0), not item!
|
||||||
|
*/
|
||||||
|
def getCoverIcon(te: TileCoverable, side: ForgeDirection, cover: ItemStack): IIcon
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform tick, called on server only
|
||||||
|
* @param te Host TileEntity
|
||||||
|
* @param side Side the cover is installed on
|
||||||
|
* @param cover Cover ItemStack
|
||||||
|
*/
|
||||||
|
def tickCover(te: TileCoverable, side: ForgeDirection, cover: ItemStack): Unit = {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if this cover can be installed on a specific TE
|
||||||
|
* @param te Potential host TileEntity
|
||||||
|
* @param cover Cover ItemStack
|
||||||
|
* @return true if can be installed
|
||||||
|
*/
|
||||||
|
def isValidTile(te: TileCoverable, cover: ItemStack): Boolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle click on covered side - called on both client and server
|
||||||
|
* @param te Host TileEntity
|
||||||
|
* @param side Side the cover is installed on
|
||||||
|
* @param cover Cover ItemStack
|
||||||
|
* @param player Player clicking the cover
|
||||||
|
* @return true if click was handled by cover
|
||||||
|
*/
|
||||||
|
def clickCover(te: TileCoverable, side: ForgeDirection, cover: ItemStack, player: EntityPlayer): Boolean = false
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if cover is emitting RS signal
|
||||||
|
* @param te Host TileEntity
|
||||||
|
* @param side Side the cover is installed on
|
||||||
|
* @param cover Cover ItemStack
|
||||||
|
* @return true if cover is emitting RS signal
|
||||||
|
*/
|
||||||
|
def isEmittingSignal(te: TileCoverable, side: ForgeDirection, cover: ItemStack): Boolean = false
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when cover is installed on a block - called only on server
|
||||||
|
* @param te Host TileEntity
|
||||||
|
* @param side Side the cover is installed on
|
||||||
|
* @param cover Cover ItemStack - do not modify!
|
||||||
|
* @param player Player entity doing the installation
|
||||||
|
* @return cover ItemStack - copy if modified
|
||||||
|
*/
|
||||||
|
def onInstall(te:TileCoverable, side: ForgeDirection, cover: ItemStack, player: EntityPlayerMP): ItemStack = cover
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when cover is removed from block or block is destroyed - called only on server
|
||||||
|
* @param cover Cover ItemStack - do not modify!
|
||||||
|
* @return cover ItemStack - copy if modified
|
||||||
|
*/
|
||||||
|
def onRemove(cover: ItemStack): ItemStack = cover
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
|
* https://github.com/bdew/bdlib
|
||||||
|
*
|
||||||
|
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||||
|
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||||
|
* http://bdew.net/minecraft-mod-public-license/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.bdew.lib.covers
|
||||||
|
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
|
import net.bdew.lib.Misc
|
||||||
|
import net.bdew.lib.data.DataSlotItemStack
|
||||||
|
import net.bdew.lib.data.base.{TileDataSlots, UpdateKind}
|
||||||
|
import net.minecraft.item.ItemStack
|
||||||
|
import net.minecraftforge.common.util.ForgeDirection
|
||||||
|
|
||||||
|
trait TileCoverable extends TileDataSlots {
|
||||||
|
val covers = (ForgeDirection.VALID_DIRECTIONS map { x =>
|
||||||
|
x -> DataSlotItemStack("cover_" + x.toString.toLowerCase(Locale.US), this).setUpdate(UpdateKind.SAVE, UpdateKind.WORLD, UpdateKind.RENDER)
|
||||||
|
}).toMap
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a specific cover can be installed here
|
||||||
|
*/
|
||||||
|
def isValidCover(side: ForgeDirection, cover: ItemStack): Boolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when new covers are installed
|
||||||
|
*/
|
||||||
|
def onCoversChanged() {}
|
||||||
|
|
||||||
|
def tickCovers() =
|
||||||
|
for {
|
||||||
|
(dir, coverSlot) <- covers
|
||||||
|
coverStack <- Option(coverSlot.value)
|
||||||
|
coverItem <- Option(coverStack.getItem) flatMap (Misc.asInstanceOpt(_, classOf[ItemCover]))
|
||||||
|
} {
|
||||||
|
coverItem.tickCover(this, dir, coverStack)
|
||||||
|
}
|
||||||
|
|
||||||
|
serverTick.listen(tickCovers)
|
||||||
|
}
|
||||||
@@ -1,19 +1,19 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) bdew, 2013
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
* https://github.com/bdew/bdlib
|
* https://github.com/bdew/bdlib
|
||||||
*
|
*
|
||||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
* 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
|
* 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
|
package net.bdew.lib.data
|
||||||
|
|
||||||
|
import net.bdew.lib.data.base.{DataSlotContainer, DataSlotVal, UpdateKind}
|
||||||
import net.minecraft.nbt.NBTTagCompound
|
import net.minecraft.nbt.NBTTagCompound
|
||||||
import net.bdew.lib.data.base.{UpdateKind, TileDataSlots, DataSlotVal}
|
|
||||||
|
|
||||||
case class DataSlotBoolean(name: String, parent: TileDataSlots, default: Boolean = false) extends DataSlotVal[Boolean] {
|
case class DataSlotBoolean(name: String, parent: DataSlotContainer, default: Boolean = false) extends DataSlotVal[Boolean] {
|
||||||
var cval = default
|
var value = default
|
||||||
def save(t: NBTTagCompound, kind: UpdateKind.Value) = t.setBoolean(name, cval)
|
def save(t: NBTTagCompound, kind: UpdateKind.Value) = t.setBoolean(name, value)
|
||||||
def load(t: NBTTagCompound, kind: UpdateKind.Value) = cval = t.getBoolean(name)
|
def load(t: NBTTagCompound, kind: UpdateKind.Value) = value = t.getBoolean(name)
|
||||||
}
|
}
|
||||||
@@ -1,20 +1,20 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) bdew, 2013
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
* https://github.com/bdew/bdlib
|
* https://github.com/bdew/bdlib
|
||||||
*
|
*
|
||||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
* 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
|
* 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
|
package net.bdew.lib.data
|
||||||
|
|
||||||
import net.bdew.lib.data.base.{TileDataSlots, UpdateKind, DataSlotVal}
|
import net.bdew.lib.data.base.{DataSlotContainer, DataSlotVal, UpdateKind}
|
||||||
import net.minecraftforge.common.ForgeDirection
|
|
||||||
import net.minecraft.nbt.NBTTagCompound
|
import net.minecraft.nbt.NBTTagCompound
|
||||||
|
import net.minecraftforge.common.util.ForgeDirection
|
||||||
|
|
||||||
case class DataSlotDirection(name: String, parent: TileDataSlots) extends DataSlotVal[ForgeDirection] {
|
case class DataSlotDirection(name: String, parent: DataSlotContainer) extends DataSlotVal[ForgeDirection] {
|
||||||
var cval = ForgeDirection.UP
|
var value = ForgeDirection.UP
|
||||||
def save(t: NBTTagCompound, kind: UpdateKind.Value) = t.setByte(name, cval.ordinal().toByte)
|
def save(t: NBTTagCompound, kind: UpdateKind.Value) = t.setByte(name, value.ordinal().toByte)
|
||||||
def load(t: NBTTagCompound, kind: UpdateKind.Value) = cval = ForgeDirection.getOrientation(t.getByte(name))
|
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)
|
||||||
|
}
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) bdew, 2013
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
* https://github.com/bdew/bdlib
|
* https://github.com/bdew/bdlib
|
||||||
*
|
*
|
||||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
* 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
|
* 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
|
package net.bdew.lib.data
|
||||||
|
|
||||||
|
import net.bdew.lib.data.base.{DataSlotContainer, DataSlotNumeric, UpdateKind}
|
||||||
import net.minecraft.nbt.NBTTagCompound
|
import net.minecraft.nbt.NBTTagCompound
|
||||||
import net.bdew.lib.data.base.{UpdateKind, TileDataSlots, DataSlotNumeric}
|
|
||||||
|
|
||||||
case class DataSlotFloat(name: String, parent: TileDataSlots, default: Float = 0) extends DataSlotNumeric[Float](default) {
|
case class DataSlotFloat(name: String, parent: DataSlotContainer, default: Float = 0) extends DataSlotNumeric[Float](default) {
|
||||||
def save(t: NBTTagCompound, kind: UpdateKind.Value) = t.setFloat(name, cval)
|
def save(t: NBTTagCompound, kind: UpdateKind.Value) = t.setFloat(name, value)
|
||||||
def load(t: NBTTagCompound, kind: UpdateKind.Value) = cval = t.getFloat(name)
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
|
* https://github.com/bdew/bdlib
|
||||||
|
*
|
||||||
|
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||||
|
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||||
|
* http://bdew.net/minecraft-mod-public-license/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.bdew.lib.data
|
||||||
|
|
||||||
|
import java.util.UUID
|
||||||
|
|
||||||
|
import com.mojang.authlib.GameProfile
|
||||||
|
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: DataSlotContainer) extends DataSlotVal[GameProfile] {
|
||||||
|
override var value: GameProfile = null
|
||||||
|
|
||||||
|
override def load(t: NBTTagCompound, kind: UpdateKind.Value) = {
|
||||||
|
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 (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))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) bdew, 2013
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
* https://github.com/bdew/bdlib
|
* https://github.com/bdew/bdlib
|
||||||
*
|
*
|
||||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
* 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
|
* 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
|
package net.bdew.lib.data
|
||||||
|
|
||||||
|
import net.bdew.lib.data.base.{DataSlotContainer, DataSlotNumeric, UpdateKind}
|
||||||
import net.minecraft.nbt.NBTTagCompound
|
import net.minecraft.nbt.NBTTagCompound
|
||||||
import net.bdew.lib.data.base.{UpdateKind, TileDataSlots, DataSlotNumeric}
|
|
||||||
|
|
||||||
case class DataSlotInt(name: String, parent: TileDataSlots, default: Int = 0) extends DataSlotNumeric[Int](default) {
|
case class DataSlotInt(name: String, parent: DataSlotContainer, default: Int = 0) extends DataSlotNumeric[Int](default) {
|
||||||
def save(t: NBTTagCompound, kind: UpdateKind.Value) = t.setInteger(name, cval)
|
def save(t: NBTTagCompound, kind: UpdateKind.Value) = t.setInteger(name, value)
|
||||||
def load(t: NBTTagCompound, kind: UpdateKind.Value) = cval = t.getInteger(name)
|
def load(t: NBTTagCompound, kind: UpdateKind.Value) = value = t.getInteger(name)
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
|
* https://github.com/bdew/bdlib
|
||||||
|
*
|
||||||
|
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||||
|
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||||
|
* http://bdew.net/minecraft-mod-public-license/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.bdew.lib.data
|
||||||
|
|
||||||
|
import net.bdew.lib.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: DataSlotContainer, size: Int) extends DataSlot with BaseInventory {
|
||||||
|
setUpdate(UpdateKind.SAVE)
|
||||||
|
|
||||||
|
override def getSizeInventory = size
|
||||||
|
override def markDirty() = parent.dataSlotChanged(this)
|
||||||
|
|
||||||
|
override def load(t: NBTTagCompound, kind: UpdateKind.Value) {
|
||||||
|
inv = new Array[ItemStack](getSizeInventory)
|
||||||
|
import net.bdew.lib.nbt._
|
||||||
|
for (nbtItem <- t.getList[NBTTagCompound](name)) {
|
||||||
|
val slot = nbtItem.getByte("Slot")
|
||||||
|
if (slot >= 0 && slot < inv.length) {
|
||||||
|
inv(slot) = ItemStack.loadItemStackFromNBT(nbtItem)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override def save(t: NBTTagCompound, kind: UpdateKind.Value) {
|
||||||
|
val itemList = new NBTTagList
|
||||||
|
for ((item, i) <- inv.view.zipWithIndex if item != null) {
|
||||||
|
val itemNbt: NBTTagCompound = new NBTTagCompound
|
||||||
|
itemNbt.setByte("Slot", i.asInstanceOf[Byte])
|
||||||
|
item.writeToNBT(itemNbt)
|
||||||
|
itemList.appendTag(itemNbt)
|
||||||
|
}
|
||||||
|
t.setTag(name, itemList)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1,32 +1,32 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) bdew, 2013
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
* https://github.com/bdew/bdlib
|
* https://github.com/bdew/bdlib
|
||||||
*
|
*
|
||||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
* 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
|
* 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
|
package net.bdew.lib.data
|
||||||
|
|
||||||
import net.bdew.lib.data.base.{TileDataSlots, UpdateKind, DataSlotVal}
|
import net.bdew.lib.data.base.{DataSlotContainer, DataSlotVal, UpdateKind}
|
||||||
import net.minecraft.nbt.NBTTagCompound
|
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
|
import net.minecraft.nbt.NBTTagCompound
|
||||||
|
|
||||||
case class DataSlotItemStack(name: String, parent: TileDataSlots) extends DataSlotVal[ItemStack] {
|
case class DataSlotItemStack(name: String, parent: DataSlotContainer) extends DataSlotVal[ItemStack] {
|
||||||
var cval: ItemStack = null
|
var value: ItemStack = null
|
||||||
|
|
||||||
override def update(v: ItemStack) = {
|
override def update(v: ItemStack) = {
|
||||||
if (!ItemStack.areItemStacksEqual(v, cval)) {
|
if (!ItemStack.areItemStacksEqual(v, value)) {
|
||||||
cval = if (v == null) null else v.copy()
|
value = if (v == null) null else v.copy()
|
||||||
parent.dataSlotChanged(this)
|
parent.dataSlotChanged(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def save(t: NBTTagCompound, kind: UpdateKind.Value) = {
|
def save(t: NBTTagCompound, kind: UpdateKind.Value) = {
|
||||||
val tag = new NBTTagCompound()
|
val tag = new NBTTagCompound()
|
||||||
if (cval != null) cval.writeToNBT(tag)
|
if (value != null) value.writeToNBT(tag)
|
||||||
t.setCompoundTag(name, 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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
|
* https://github.com/bdew/bdlib
|
||||||
|
*
|
||||||
|
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||||
|
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||||
|
* http://bdew.net/minecraft-mod-public-license/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.bdew.lib.data
|
||||||
|
|
||||||
|
import net.bdew.lib.data.base.DataSlotVal
|
||||||
|
|
||||||
|
abstract class DataSlotOption[T] extends DataSlotVal[Option[T]] {
|
||||||
|
override var value: Option[T] = None
|
||||||
|
|
||||||
|
def set(v: T) {
|
||||||
|
if (v == null) sys.error("Null should never be used with DataSlotOption")
|
||||||
|
value = Some(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
def unset() {
|
||||||
|
value = None
|
||||||
|
}
|
||||||
|
|
||||||
|
override def isSame(v: Option[T]) = {
|
||||||
|
if (v == null) sys.error("Null should never be used with DataSlotOption")
|
||||||
|
super.isSame(v)
|
||||||
|
}
|
||||||
|
override def :=(that: Option[T]) = {
|
||||||
|
if (that == null) sys.error("Null should never be used with DataSlotOption")
|
||||||
|
super.:=(that)
|
||||||
|
}
|
||||||
|
override def :!=(that: Option[T]) = {
|
||||||
|
if (that == null) sys.error("Null should never be used with DataSlotOption")
|
||||||
|
super.:!=(that)
|
||||||
|
}
|
||||||
|
override def :==(that: Option[T]) = {
|
||||||
|
if (that == null) sys.error("Null should never be used with DataSlotOption")
|
||||||
|
super.:==(that)
|
||||||
|
}
|
||||||
|
override def update(v: Option[T]) = {
|
||||||
|
if (v == null) sys.error("Null should never be used with DataSlotOption")
|
||||||
|
super.update(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,19 +1,19 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) bdew, 2013
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
* https://github.com/bdew/bdlib
|
* https://github.com/bdew/bdlib
|
||||||
*
|
*
|
||||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
* 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
|
* 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
|
package net.bdew.lib.data
|
||||||
|
|
||||||
|
import net.bdew.lib.data.base.{DataSlotContainer, DataSlotVal, UpdateKind}
|
||||||
import net.minecraft.nbt.NBTTagCompound
|
import net.minecraft.nbt.NBTTagCompound
|
||||||
import net.bdew.lib.data.base.{UpdateKind, TileDataSlots, DataSlotVal}
|
|
||||||
|
|
||||||
case class DataSlotString(name: String, parent: TileDataSlots, default: String = null) extends DataSlotVal[String] {
|
case class DataSlotString(name: String, parent: DataSlotContainer, default: String = null) extends DataSlotVal[String] {
|
||||||
var cval: String = default
|
var value: String = default
|
||||||
def save(t: NBTTagCompound, kind: UpdateKind.Value) = if (cval != null) t.setString(name, cval)
|
def save(t: NBTTagCompound, kind: UpdateKind.Value) = if (value != null) t.setString(name, value)
|
||||||
def load(t: NBTTagCompound, kind: UpdateKind.Value) = cval = if (t.hasKey(name)) t.getString(name) else null
|
def load(t: NBTTagCompound, kind: UpdateKind.Value) = value = if (t.hasKey(name)) t.getString(name) else null
|
||||||
}
|
}
|
||||||
@@ -1,26 +1,27 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) bdew, 2013
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
* https://github.com/bdew/bdlib
|
* https://github.com/bdew/bdlib
|
||||||
*
|
*
|
||||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
* 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
|
* 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
|
package net.bdew.lib.data
|
||||||
|
|
||||||
import net.minecraftforge.fluids.{IFluidTank, FluidTank, FluidStack}
|
import net.bdew.lib.data.base.{DataSlot, DataSlotContainer, UpdateKind}
|
||||||
import net.minecraft.nbt.NBTTagCompound
|
import net.minecraft.nbt.NBTTagCompound
|
||||||
import net.bdew.lib.data.base.{UpdateKind, TileDataSlots, DataSlot}
|
import net.minecraftforge.fluids._
|
||||||
|
|
||||||
abstract class DataSlotTankBase(sz: Int) extends FluidTank(sz) with IFluidTank with DataSlot {
|
abstract class DataSlotTankBase(sz: Int) extends FluidTank(sz) with IFluidTank with DataSlot {
|
||||||
var oldStack: FluidStack = null
|
var oldStack: FluidStack = null
|
||||||
var size: Int
|
|
||||||
|
|
||||||
parent.serverTick.listen(checkUpdate)
|
parent.onServerTick(checkUpdate)
|
||||||
|
|
||||||
updateKind = Set(UpdateKind.GUI, UpdateKind.SAVE)
|
updateKind = Set(UpdateKind.GUI, UpdateKind.SAVE)
|
||||||
|
|
||||||
|
val sendCapacityOnUpdateKind = Set(UpdateKind.GUI)
|
||||||
|
|
||||||
def checkUpdate() {
|
def checkUpdate() {
|
||||||
if (!isSame(oldStack, fluid)) {
|
if (!isSame(oldStack, fluid)) {
|
||||||
oldStack = if (fluid == null) null else fluid.copy()
|
oldStack = if (fluid == null) null else fluid.copy()
|
||||||
@@ -37,26 +38,42 @@ abstract class DataSlotTankBase(sz: Int) extends FluidTank(sz) with IFluidTank w
|
|||||||
def save(t: NBTTagCompound, k: UpdateKind.Value) {
|
def save(t: NBTTagCompound, k: UpdateKind.Value) {
|
||||||
val tag = new NBTTagCompound()
|
val tag = new NBTTagCompound()
|
||||||
writeToNBT(tag)
|
writeToNBT(tag)
|
||||||
if (k == UpdateKind.GUI)
|
if (sendCapacityOnUpdateKind.contains(k))
|
||||||
tag.setInteger("size", size)
|
tag.setInteger("size", getCapacity)
|
||||||
t.setCompoundTag(name, tag)
|
t.setTag(name, tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
def load(t: NBTTagCompound, k: UpdateKind.Value) {
|
def load(t: NBTTagCompound, k: UpdateKind.Value) {
|
||||||
|
setFluid(null)
|
||||||
val tag = t.getCompoundTag(name)
|
val tag = t.getCompoundTag(name)
|
||||||
readFromNBT(tag)
|
readFromNBT(tag)
|
||||||
if (k == UpdateKind.GUI)
|
if (sendCapacityOnUpdateKind.contains(k))
|
||||||
size = tag.getInteger("size")
|
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)
|
||||||
|
execWithChangeNotifyConditional[FluidStack](super.drain(maxDrain, true), _ != null)
|
||||||
|
else
|
||||||
|
super.drain(maxDrain, false)
|
||||||
|
|
||||||
|
override def fill(resource: FluidStack, doFill: Boolean) =
|
||||||
|
if (doFill)
|
||||||
|
execWithChangeNotifyConditional[Int](super.fill(resource, true), _ > 0)
|
||||||
|
else
|
||||||
|
super.fill(resource, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
case class DataSlotTank(name: String, parent: TileDataSlots, var 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) {
|
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(fluidID, amount), doFill)
|
def fill(amount: Int, doFill: Boolean) = super.fill(new FluidStack(filterFluid, amount), doFill)
|
||||||
|
|
||||||
override def fill(resource: FluidStack, doFill: Boolean): Int = {
|
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)
|
return super.fill(resource, doFill)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,19 +1,19 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) bdew, 2013
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
* https://github.com/bdew/bdlib
|
* https://github.com/bdew/bdlib
|
||||||
*
|
*
|
||||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
* 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
|
* 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
|
package net.bdew.lib.data.base
|
||||||
|
|
||||||
|
import net.bdew.lib.gui.NoInvContainer
|
||||||
import net.minecraft.entity.player.EntityPlayerMP
|
import net.minecraft.entity.player.EntityPlayerMP
|
||||||
import net.bdew.lib.gui.BaseContainer
|
|
||||||
import net.minecraft.inventory.ICrafting
|
import net.minecraft.inventory.ICrafting
|
||||||
|
|
||||||
trait ContainerDataSlots extends BaseContainer {
|
trait ContainerDataSlots extends NoInvContainer {
|
||||||
val dataSource: TileDataSlots
|
val dataSource: TileDataSlots
|
||||||
var lastSentChange = dataSource.lastChange
|
var lastSentChange = dataSource.lastChange
|
||||||
|
|
||||||
@@ -21,19 +21,19 @@ trait ContainerDataSlots extends BaseContainer {
|
|||||||
super.addCraftingToCrafters(crafter)
|
super.addCraftingToCrafters(crafter)
|
||||||
if (crafter.isInstanceOf[EntityPlayerMP]) {
|
if (crafter.isInstanceOf[EntityPlayerMP]) {
|
||||||
val pkt = dataSource.getDataSlotPacket
|
val pkt = dataSource.getDataSlotPacket
|
||||||
crafter.asInstanceOf[EntityPlayerMP].playerNetServerHandler.sendPacketToPlayer(pkt)
|
crafter.asInstanceOf[EntityPlayerMP].playerNetServerHandler.sendPacket(pkt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override def detectAndSendChanges() {
|
override def detectAndSendChanges() {
|
||||||
super.detectAndSendChanges()
|
super.detectAndSendChanges()
|
||||||
// only send updates every 10 ticks
|
// only send updates every 10 ticks
|
||||||
if (dataSource.lastChange >= lastSentChange + 10 || (dataSource.lastChange > lastSentChange && lastSentChange + 10 < dataSource.worldObj.getTotalWorldTime)) {
|
if (dataSource.lastChange >= lastSentChange + 10 || (dataSource.lastChange > lastSentChange && lastSentChange + 10 < dataSource.getWorldObj.getTotalWorldTime)) {
|
||||||
lastSentChange = dataSource.lastChange
|
lastSentChange = dataSource.lastChange
|
||||||
val pkt = dataSource.getDataSlotPacket
|
val pkt = dataSource.getDataSlotPacket
|
||||||
|
|
||||||
for (player <- players)
|
for (player <- players)
|
||||||
player.playerNetServerHandler.sendPacketToPlayer(pkt)
|
player.playerNetServerHandler.sendPacket(pkt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) bdew, 2013
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
* https://github.com/bdew/bdlib
|
* https://github.com/bdew/bdlib
|
||||||
*
|
*
|
||||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
* 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
|
* 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
|
package net.bdew.lib.data.base
|
||||||
@@ -19,7 +19,7 @@ trait DataSlot {
|
|||||||
* Tile Entity that owns this slot
|
* Tile Entity that owns this slot
|
||||||
* Accessed in constructor, so should be in parameters or a lazy val, otherwise will crash
|
* Accessed in constructor, so should be in parameters or a lazy val, otherwise will crash
|
||||||
*/
|
*/
|
||||||
val parent: TileDataSlots
|
val parent: DataSlotContainer
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unique name
|
* Unique name
|
||||||
@@ -35,6 +35,19 @@ trait DataSlot {
|
|||||||
def save(t: NBTTagCompound, kind: UpdateKind.Value)
|
def save(t: NBTTagCompound, kind: UpdateKind.Value)
|
||||||
def load(t: NBTTagCompound, kind: UpdateKind.Value)
|
def load(t: NBTTagCompound, kind: UpdateKind.Value)
|
||||||
|
|
||||||
|
def execWithChangeNotify[T](f: => T): T = {
|
||||||
|
val v = f
|
||||||
|
parent.dataSlotChanged(this)
|
||||||
|
v
|
||||||
|
}
|
||||||
|
|
||||||
|
def 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 = {
|
def setUpdate(vals: UpdateKind.Value*): this.type = {
|
||||||
updateKind = vals.toSet
|
updateKind = vals.toSet
|
||||||
return this
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1,22 +1,27 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) bdew, 2013
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
* https://github.com/bdew/bdlib
|
* https://github.com/bdew/bdlib
|
||||||
*
|
*
|
||||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
* 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
|
* 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
|
package net.bdew.lib.data.base
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for data slots that hold numeric values
|
* 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] {
|
abstract class DataSlotNumeric[T](default: T)(implicit n: Numeric[T]) extends DataSlotVal[T] {
|
||||||
var cval = default
|
var value = default
|
||||||
def +=(that: T) = update(n.plus(cval, that))
|
def +=(that: T) = update(n.plus(value, that))
|
||||||
def -=(that: T) = update(n.minus(cval, that))
|
def -=(that: T) = update(n.minus(value, that))
|
||||||
def *=(that: T) = update(n.times(cval, 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)))
|
||||||
}
|
}
|
||||||
@@ -1,21 +1,21 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) bdew, 2013
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
* https://github.com/bdew/bdlib
|
* https://github.com/bdew/bdlib
|
||||||
*
|
*
|
||||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
* 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
|
* 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
|
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
|
* 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] {
|
abstract class DataSlotOrdered[T](implicit n: Ordering[T]) extends DataSlotVal[T] {
|
||||||
def :>(that: T) = n.compare(cval, that) > 0
|
def :>(that: T) = n.compare(value, that) > 0
|
||||||
def :<(that: T) = n.compare(cval, that) < 0
|
def :<(that: T) = n.compare(value, that) < 0
|
||||||
def :>=(that: T) = n.compare(cval, that) >= 0
|
def :>=(that: T) = n.compare(value, that) >= 0
|
||||||
def :<=(that: T) = n.compare(cval, that) <= 0
|
def :<=(that: T) = n.compare(value, that) <= 0
|
||||||
}
|
}
|
||||||
@@ -1,39 +1,39 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) bdew, 2013
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
* https://github.com/bdew/bdlib
|
* https://github.com/bdew/bdlib
|
||||||
*
|
*
|
||||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
* 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
|
* 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
|
package net.bdew.lib.data.base
|
||||||
|
|
||||||
import language.implicitConversions
|
import scala.language.implicitConversions
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base trait for data slots that hold primitive values
|
* 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 {
|
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) = update(that)
|
||||||
|
|
||||||
def :!=(that: T) = cval != that
|
def :!=(that: T) = value != that
|
||||||
def :==(that: T) = cval == that
|
def :==(that: T) = value == that
|
||||||
|
|
||||||
def update(v: T) {
|
def update(v: T) {
|
||||||
if (!isSame(v)) {
|
if (!isSame(v)) {
|
||||||
cval = v
|
value = v
|
||||||
parent.dataSlotChanged(this)
|
parent.dataSlotChanged(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object DataSlotVal {
|
object DataSlotVal {
|
||||||
implicit def slot2val[T](slot: DataSlotVal[T]): T = slot.cval
|
implicit def slot2val[T](slot: DataSlotVal[T]): T = slot.value
|
||||||
}
|
}
|
||||||
@@ -1,59 +1,48 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) bdew, 2013
|
* Copyright (c) bdew, 2013 - 2015
|
||||||
* https://github.com/bdew/bdlib
|
* https://github.com/bdew/bdlib
|
||||||
*
|
*
|
||||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
* 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
|
* 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
|
package net.bdew.lib.data.base
|
||||||
|
|
||||||
import net.minecraft.network.packet.Packet132TileEntityData
|
|
||||||
import scala.collection.mutable
|
|
||||||
import net.minecraft.nbt.NBTTagCompound
|
|
||||||
import net.bdew.lib.tile.TileExtended
|
import net.bdew.lib.tile.TileExtended
|
||||||
|
import net.minecraft.nbt.NBTTagCompound
|
||||||
|
import net.minecraft.network.Packet
|
||||||
|
import net.minecraft.network.play.server.S35PacketUpdateTileEntity
|
||||||
|
|
||||||
trait TileDataSlots extends TileExtended {
|
trait TileDataSlots extends TileExtended with DataSlotContainer {
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
persistSave.listen(doSave(UpdateKind.SAVE, _))
|
persistSave.listen(doSave(UpdateKind.SAVE, _))
|
||||||
persistLoad.listen(doLoad(UpdateKind.SAVE, _))
|
persistLoad.listen(doLoad(UpdateKind.SAVE, _))
|
||||||
sendClientUpdate.listen(doSave(UpdateKind.WORLD, _))
|
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
|
||||||
if (worldObj != null) {
|
|
||||||
|
override def onServerTick(f: () => Unit) = serverTick.listen(f)
|
||||||
|
|
||||||
|
override def dataSlotChanged(slot: DataSlot) = {
|
||||||
|
if (getWorldObj != null) {
|
||||||
if (slot.updateKind.contains(UpdateKind.GUI))
|
if (slot.updateKind.contains(UpdateKind.GUI))
|
||||||
lastChange = worldObj.getTotalWorldTime
|
lastChange = getWorldObj.getTotalWorldTime
|
||||||
if (slot.updateKind.contains(UpdateKind.WORLD))
|
if (!getWorldObj.isRemote && slot.updateKind.contains(UpdateKind.WORLD))
|
||||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
|
getWorldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
|
||||||
if (slot.updateKind.contains(UpdateKind.SAVE))
|
if (slot.updateKind.contains(UpdateKind.SAVE))
|
||||||
worldObj.markTileEntityChunkModified(xCoord, yCoord, zCoord, this)
|
getWorldObj.markTileEntityChunkModified(xCoord, yCoord, zCoord, this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def getDataSlotPacket: Packet132TileEntityData = {
|
def getDataSlotPacket: Packet = {
|
||||||
val tag = new NBTTagCompound()
|
val tag = new NBTTagCompound()
|
||||||
doSave(UpdateKind.GUI, tag)
|
doSave(UpdateKind.GUI, tag)
|
||||||
return new Packet132TileEntityData(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) {
|
override protected def extDataPacket(id: Int, data: NBTTagCompound) {
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) bdew, 2013
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
* https://github.com/bdew/bdlib
|
* https://github.com/bdew/bdlib
|
||||||
*
|
*
|
||||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
* 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
|
* 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
|
package net.bdew.lib.data.base
|
||||||
@@ -13,4 +13,5 @@ object UpdateKind extends Enumeration {
|
|||||||
val WORLD = Value("WORLD")
|
val WORLD = Value("WORLD")
|
||||||
val GUI = Value("GUI")
|
val GUI = Value("GUI")
|
||||||
val SAVE = Value("SAVE")
|
val SAVE = Value("SAVE")
|
||||||
|
val RENDER = Value("RENDER")
|
||||||
}
|
}
|
||||||
@@ -1,34 +1,20 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) bdew, 2013
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
* https://github.com/bdew/bdlib
|
* https://github.com/bdew/bdlib
|
||||||
*
|
*
|
||||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
* 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
|
* 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
|
package net.bdew.lib.gui
|
||||||
|
|
||||||
import net.minecraft.inventory.{IInventory, Slot, Container}
|
|
||||||
import net.minecraft.entity.player.{EntityPlayerMP, EntityPlayer, InventoryPlayer}
|
|
||||||
import net.minecraft.item.ItemStack
|
|
||||||
import net.bdew.lib.items.ItemUtils
|
import net.bdew.lib.items.ItemUtils
|
||||||
import net.bdew.lib.Misc
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
|
import net.minecraft.inventory.IInventory
|
||||||
abstract class BaseContainer(te: IInventory) extends Container {
|
import net.minecraft.item.ItemStack
|
||||||
|
|
||||||
import scala.collection.JavaConversions._
|
|
||||||
|
|
||||||
def players = Misc.filterType(crafters, classOf[EntityPlayerMP])
|
|
||||||
|
|
||||||
protected def bindPlayerInventory(inv: InventoryPlayer, xOffs: Int, yOffsInv: Int, yOffsHotbar: Int) {
|
|
||||||
for (i <- 0 until 3; j <- 0 until 9)
|
|
||||||
addSlotToContainer(new Slot(inv, j + i * 9 + 9, xOffs + j * 18, yOffsInv + i * 18))
|
|
||||||
|
|
||||||
for (i <- 0 until 9)
|
|
||||||
addSlotToContainer(new Slot(inv, i, xOffs + i * 18, yOffsHotbar))
|
|
||||||
}
|
|
||||||
|
|
||||||
|
abstract class BaseContainer(te: IInventory) extends NoInvContainer {
|
||||||
override def transferStackInSlot(player: EntityPlayer, slot: Int): ItemStack = {
|
override def transferStackInSlot(player: EntityPlayer, slot: Int): ItemStack = {
|
||||||
var stack = getSlot(slot).getStack
|
var stack = getSlot(slot).getStack
|
||||||
if (getSlot(slot).inventory == player.inventory) {
|
if (getSlot(slot).inventory == player.inventory) {
|
||||||
@@ -42,5 +28,7 @@ abstract class BaseContainer(te: IInventory) extends Container {
|
|||||||
getSlot(slot).putStack(stack)
|
getSlot(slot).putStack(stack)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override def canInteractWith(player: EntityPlayer) = te.isUseableByPlayer(player)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
|
||||||
|
case class BasePoint[T: Numeric](x: T, y: T) {
|
||||||
|
val n = implicitly[Numeric[T]]
|
||||||
|
|
||||||
|
import n.mkNumericOps
|
||||||
|
|
||||||
|
def this(p: BasePoint[T]) = this(p.x, p.y)
|
||||||
|
|
||||||
|
def +(that: BasePoint[T]) = BasePoint(this.x + that.x, this.y + that.y)
|
||||||
|
def +(xOff: T, yOff: T) = BasePoint(this.x + xOff, this.y + yOff)
|
||||||
|
def -(that: BasePoint[T]) = BasePoint(this.x - that.x, this.y - that.y)
|
||||||
|
def -(xOff: T, yOff: T) = BasePoint(this.x - xOff, this.y - yOff)
|
||||||
|
|
||||||
|
def map[R: Numeric](f: T => R) = new BasePoint(f(x), f(y))
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
|
* https://github.com/bdew/bdlib
|
||||||
|
*
|
||||||
|
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||||
|
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||||
|
* http://bdew.net/minecraft-mod-public-license/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.bdew.lib.gui
|
||||||
|
|
||||||
|
case class BaseRect[T: Numeric](x: T, y: T, w: T, h: T) {
|
||||||
|
val n = implicitly[Numeric[T]]
|
||||||
|
|
||||||
|
import n.mkNumericOps
|
||||||
|
|
||||||
|
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.lt(p.x, x2) && n.lt(p.y, y2)
|
||||||
|
|
||||||
|
def origin = BasePoint(x, y)
|
||||||
|
|
||||||
|
def map[R: Numeric](f: T => R) = new BaseRect(f(x), f(y), f(w), f(h))
|
||||||
|
|
||||||
|
def interpolate(xf1: Float, yf1: Float, xf2: Float, yf2: Float) =
|
||||||
|
new BaseRect[Float](
|
||||||
|
xf1 * w.toFloat() + x.toFloat(),
|
||||||
|
yf1 * h.toFloat() + y.toFloat(),
|
||||||
|
(xf2 - xf1) * w.toFloat(),
|
||||||
|
(yf2 - yf1) * h.toFloat()
|
||||||
|
)
|
||||||
|
|
||||||
|
def +(p: BasePoint[T]) = new BaseRect(origin + p, w, h)
|
||||||
|
def -(p: BasePoint[T]) = new BaseRect(origin - p, w, h)
|
||||||
|
|
||||||
|
def x1 = x
|
||||||
|
def x2 = x + w
|
||||||
|
def y1 = y
|
||||||
|
def y2 = y + h
|
||||||
|
}
|
||||||
@@ -1,32 +1,33 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) bdew, 2013
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
* https://github.com/bdew/bdlib
|
* https://github.com/bdew/bdlib
|
||||||
*
|
*
|
||||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
* 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
|
* 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
|
package net.bdew.lib.gui
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft
|
||||||
import net.minecraft.client.gui.inventory.GuiContainer
|
import net.minecraft.client.gui.inventory.GuiContainer
|
||||||
import net.minecraft.inventory.Container
|
import net.minecraft.inventory.Container
|
||||||
import scala.collection.mutable
|
|
||||||
import net.minecraft.client.gui.GuiButton
|
|
||||||
import net.bdew.lib.gui.widgets.Widget
|
|
||||||
import net.minecraft.util.ResourceLocation
|
|
||||||
import org.lwjgl.opengl.GL11
|
import org.lwjgl.opengl.GL11
|
||||||
|
|
||||||
|
import scala.collection.mutable
|
||||||
|
|
||||||
abstract class BaseScreen(cont: Container, xSz: Int, ySz: Int) extends GuiContainer(cont) {
|
abstract class BaseScreen(cont: Container, xSz: Int, ySz: Int) extends GuiContainer(cont) {
|
||||||
xSize = xSz
|
xSize = xSz
|
||||||
ySize = ySz
|
ySize = ySz
|
||||||
|
|
||||||
val widgets = mutable.MutableList.empty[Widget]
|
val widgets = new WidgetContainerWindow(this, xSz, ySz)
|
||||||
val texture: ResourceLocation
|
|
||||||
|
val background: Texture
|
||||||
|
|
||||||
def rect = new Rect(guiLeft, guiTop, xSize, ySize)
|
def rect = new Rect(guiLeft, guiTop, xSize, ySize)
|
||||||
|
|
||||||
def getFontRenderer = fontRenderer
|
def getFontRenderer = Minecraft.getMinecraft.fontRenderer
|
||||||
|
def getZLevel = zLevel
|
||||||
|
|
||||||
override def initGui() {
|
override def initGui() {
|
||||||
super.initGui()
|
super.initGui()
|
||||||
@@ -34,56 +35,38 @@ abstract class BaseScreen(cont: Container, xSz: Int, ySz: Int) extends GuiContai
|
|||||||
buttonList.clear()
|
buttonList.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
def addButton[T <: GuiButton](w: T): T = {
|
|
||||||
buttonList.asInstanceOf[java.util.ArrayList[GuiButton]].add(w)
|
|
||||||
return w
|
|
||||||
}
|
|
||||||
|
|
||||||
def addWidget[T <: Widget](w: T): T = {
|
|
||||||
widgets += w
|
|
||||||
w.parent = this
|
|
||||||
return w
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override def keyTyped(c: Char, i: Int) {
|
|
||||||
for (w <- widgets)
|
|
||||||
if (w.keyTyped(c, i))
|
|
||||||
return
|
|
||||||
super.keyTyped(c, i)
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override def mouseClicked(x: Int, y: Int, bt: Int) {
|
protected override def mouseClicked(x: Int, y: Int, bt: Int) {
|
||||||
super.mouseClicked(x, y, bt)
|
super.mouseClicked(x, y, bt)
|
||||||
val p = new Point(x, y) - rect.origin
|
widgets.mouseClicked(Point(x, y) - rect.origin, bt)
|
||||||
for (w <- widgets if w.rect.contains(p))
|
|
||||||
w.mouseClicked(p - w.rect.origin, bt)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override def drawGuiContainerForegroundLayer(x: Int, y: Int) {
|
protected override def keyTyped(c: Char, i: Int) =
|
||||||
for (w <- widgets)
|
if (!widgets.keyTyped(c, i))
|
||||||
w.draw()
|
super.keyTyped(c, i)
|
||||||
}
|
|
||||||
|
protected override def drawGuiContainerForegroundLayer(x: Int, y: Int) =
|
||||||
|
widgets.draw(Point(x, y) - rect.origin)
|
||||||
|
|
||||||
protected override def drawScreen(x: Int, y: Int, f: Float) {
|
protected override def drawScreen(x: Int, y: Int, f: Float) {
|
||||||
super.drawScreen(x, y, f)
|
super.drawScreen(x, y, f)
|
||||||
|
|
||||||
val tip = mutable.MutableList.empty[String]
|
val tip = mutable.MutableList.empty[String]
|
||||||
|
|
||||||
val p = new Point(x, y) - rect.origin
|
widgets.handleTooltip(Point(x, y) - rect.origin, tip)
|
||||||
for (w <- widgets if w.rect.contains(p))
|
|
||||||
w.handleTooltip(p - w.rect.origin, tip)
|
|
||||||
|
|
||||||
import collection.JavaConversions._
|
import scala.collection.JavaConversions._
|
||||||
|
|
||||||
if (tip.size > 0)
|
if (tip.nonEmpty)
|
||||||
drawHoveringText(tip, x, y, fontRenderer)
|
drawHoveringText(tip, x, y, getFontRenderer)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected def drawGuiContainerBackgroundLayer(f: Float, i: Int, j: Int) {
|
protected def drawGuiContainerBackgroundLayer(f: Float, x: Int, y: Int) {
|
||||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F)
|
if (background != null)
|
||||||
mc.renderEngine.bindTexture(texture)
|
widgets.drawTexture(rect, background)
|
||||||
val x = (width - xSize) / 2
|
|
||||||
val y = (height - ySize) / 2
|
GL11.glPushMatrix()
|
||||||
this.drawTexturedModalRect(x, y, 0, 0, xSize, ySize)
|
GL11.glTranslatef(rect.x, rect.y, 0)
|
||||||
|
widgets.drawBackground(Point(x, y) - rect.origin)
|
||||||
|
GL11.glPopMatrix()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
|
||||||
|
import net.minecraft.inventory.{IInventory, Slot}
|
||||||
|
import org.lwjgl.opengl.GL11
|
||||||
|
|
||||||
|
class BaseSlot(inv: IInventory, slot: Int, x: Int, y: Int) extends Slot(inv, slot, x, y) {
|
||||||
|
override def getBackgroundIconIndex = {
|
||||||
|
// Workaround for bug in GuiContainer, color isn't reset if previous slot had an item with color.
|
||||||
|
GL11.glColor4d(1, 1, 1, 1)
|
||||||
|
super.getBackgroundIconIndex
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
|
* https://github.com/bdew/bdlib
|
||||||
|
*
|
||||||
|
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||||
|
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||||
|
* http://bdew.net/minecraft-mod-public-license/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.bdew.lib.gui
|
||||||
|
|
||||||
|
import net.bdew.lib.Misc
|
||||||
|
import org.lwjgl.opengl.GL11
|
||||||
|
|
||||||
|
case class Color(r: Float, g: Float, b: Float, a: Float = 1) {
|
||||||
|
def this(c: (Float, Float, Float)) = this(c._1, c._2, c._3)
|
||||||
|
def this(c: (Float, Float, Float, Float)) = this(c._1, c._2, c._3, c._4)
|
||||||
|
def activate() = GL11.glColor4f(r, g, b, a)
|
||||||
|
def asARGB =
|
||||||
|
Misc.clamp((a * 255).round, 0, 255) << 24 |
|
||||||
|
Misc.clamp((r * 255).round, 0, 255) << 16 |
|
||||||
|
Misc.clamp((g * 255).round, 0, 255) << 8 |
|
||||||
|
Misc.clamp((b * 255).round, 0, 255)
|
||||||
|
def asRGB =
|
||||||
|
Misc.clamp((r * 255).round, 0, 255) << 16 |
|
||||||
|
Misc.clamp((g * 255).round, 0, 255) << 8 |
|
||||||
|
Misc.clamp((b * 255).round, 0, 255)
|
||||||
|
}
|
||||||
|
|
||||||
|
object Color {
|
||||||
|
def fromRGB(r: Int, g: Int, b: Int, a: Int = 255) = Color(r / 255F, g / 255F, b / 255F, a / 255F)
|
||||||
|
def fromInt(v: Int) = Color(
|
||||||
|
((v >> 16) & 0xFF) / 255F,
|
||||||
|
((v >> 8) & 0xFF) / 255F,
|
||||||
|
(v & 0xFF) / 255F
|
||||||
|
)
|
||||||
|
final val white = Color(1, 1, 1)
|
||||||
|
final val black = Color(0, 0, 0)
|
||||||
|
final val red = Color(1, 0, 0)
|
||||||
|
final val green = Color(0, 1, 0)
|
||||||
|
final val blue = Color(0, 0, 1)
|
||||||
|
final val yellow = Color(1, 1, 0)
|
||||||
|
final val cyan = Color(0, 1, 1)
|
||||||
|
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)
|
||||||
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) bdew, 2013
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
* https://github.com/bdew/bdlib
|
* https://github.com/bdew/bdlib
|
||||||
*
|
*
|
||||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
* 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
|
* 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
|
package net.bdew.lib.gui
|
||||||
@@ -12,7 +12,7 @@ package net.bdew.lib.gui
|
|||||||
object Direction extends Enumeration {
|
object Direction extends Enumeration {
|
||||||
type Direction = Value
|
type Direction = Value
|
||||||
val UP = Value("UP")
|
val UP = Value("UP")
|
||||||
val DOWN = Value("UP")
|
val DOWN = Value("DOWN")
|
||||||
val LEFT = Value("UP")
|
val LEFT = Value("LEFT")
|
||||||
val RIGHT = Value("UP")
|
val RIGHT = Value("RIGHT")
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
|
* https://github.com/bdew/bdlib
|
||||||
|
*
|
||||||
|
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||||
|
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||||
|
* http://bdew.net/minecraft-mod-public-license/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.bdew.lib.gui
|
||||||
|
|
||||||
|
import net.minecraft.client.gui.FontRenderer
|
||||||
|
import net.minecraft.client.renderer.Tessellator
|
||||||
|
|
||||||
|
trait DrawTarget {
|
||||||
|
def getZLevel: Float
|
||||||
|
def getFontRenderer: FontRenderer
|
||||||
|
def drawTexture(r: Rect, t: Texture, color: Color = Color.white)
|
||||||
|
def drawText(text: String, p: Point, color: Color, shadow: Boolean)
|
||||||
|
def drawTextMultiline(text: String, r: Rect, color: Color)
|
||||||
|
|
||||||
|
def drawTextureInterpolate(r: Rect, t: Texture, x1: Float, y1: Float, x2: Float, y2: Float, color: Color = Color.white) =
|
||||||
|
drawTexture(r.interpolate(x1, y1, x2, y2), Texture.interpolate(t, x1, y1, x2, y2), color)
|
||||||
|
}
|
||||||
|
|
||||||
|
trait SimpleDrawTarget extends DrawTarget {
|
||||||
|
private final val T = Tessellator.instance
|
||||||
|
|
||||||
|
def drawTexture(r: Rect, t: Texture, color: Color = Color.white) {
|
||||||
|
val z = getZLevel
|
||||||
|
t.bind()
|
||||||
|
color.activate()
|
||||||
|
T.startDrawingQuads()
|
||||||
|
T.addVertexWithUV(r.x1, r.y2, z, t.u1, t.v2)
|
||||||
|
T.addVertexWithUV(r.x2, r.y2, z, t.u2, t.v2)
|
||||||
|
T.addVertexWithUV(r.x2, r.y1, z, t.u2, t.v1)
|
||||||
|
T.addVertexWithUV(r.x1, r.y1, z, t.u1, t.v1)
|
||||||
|
T.draw()
|
||||||
|
}
|
||||||
|
|
||||||
|
def drawText(text: String, p: Point, color: Color, shadow: Boolean) =
|
||||||
|
getFontRenderer.drawString(text, p.x.round, p.y.round, color.asARGB, shadow)
|
||||||
|
|
||||||
|
def drawTextMultiline(text: String, r: Rect, color: Color) =
|
||||||
|
getFontRenderer.drawSplitString(text, r.x.round, r.y.round, r.w.round, color.asARGB)
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
|
* https://github.com/bdew/bdlib
|
||||||
|
*
|
||||||
|
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||||
|
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||||
|
* http://bdew.net/minecraft-mod-public-license/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.bdew.lib.gui
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.network.IGuiHandler
|
||||||
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
|
import net.minecraft.world.World
|
||||||
|
|
||||||
|
import scala.collection.mutable
|
||||||
|
|
||||||
|
class GuiHandler extends IGuiHandler {
|
||||||
|
val GUIs = mutable.Map.empty[Int, GuiProvider]
|
||||||
|
|
||||||
|
def register(p: GuiProvider) = {
|
||||||
|
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)
|
||||||
|
|
||||||
|
def getClientGuiElement(ID: Int, player: EntityPlayer, world: World, x: Int, y: Int, z: Int): AnyRef =
|
||||||
|
GUIs(ID).getGui(world.getTileEntity(x, y, z), player)
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
|
* https://github.com/bdew/bdlib
|
||||||
|
*
|
||||||
|
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||||
|
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||||
|
* http://bdew.net/minecraft-mod-public-license/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.bdew.lib.gui
|
||||||
|
|
||||||
|
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||||
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
|
import net.minecraft.tileentity.TileEntity
|
||||||
|
|
||||||
|
trait GuiProvider {
|
||||||
|
def guiId: Int
|
||||||
|
|
||||||
|
type TEClass
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
def getGui(te: TEClass, player: EntityPlayer): AnyRef
|
||||||
|
def getContainer(te: TEClass, player: EntityPlayer): AnyRef
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
def getGui(te: TileEntity, player: EntityPlayer): AnyRef =
|
||||||
|
if (te != null)
|
||||||
|
getGui(te.asInstanceOf[TEClass], player)
|
||||||
|
else null
|
||||||
|
|
||||||
|
def getContainer(te: TileEntity, player: EntityPlayer): AnyRef =
|
||||||
|
if (te != null)
|
||||||
|
getContainer(te.asInstanceOf[TEClass], player)
|
||||||
|
else null
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
|
||||||
|
import net.bdew.lib.Misc
|
||||||
|
import net.minecraft.entity.player.{EntityPlayer, EntityPlayerMP, InventoryPlayer}
|
||||||
|
import net.minecraft.inventory.{Container, Slot}
|
||||||
|
import net.minecraft.item.ItemStack
|
||||||
|
|
||||||
|
abstract class NoInvContainer extends Container {
|
||||||
|
|
||||||
|
import scala.collection.JavaConversions._
|
||||||
|
|
||||||
|
def players = Misc.filterType(crafters, classOf[EntityPlayerMP])
|
||||||
|
|
||||||
|
protected def bindPlayerInventory(inv: InventoryPlayer, xOffs: Int, yOffsInv: Int, yOffsHotbar: Int) {
|
||||||
|
for (i <- 0 until 3; j <- 0 until 9)
|
||||||
|
addSlotToContainer(new Slot(inv, j + i * 9 + 9, xOffs + j * 18, yOffsInv + i * 18))
|
||||||
|
|
||||||
|
for (i <- 0 until 9)
|
||||||
|
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)
|
||||||
|
if (slot != null && slot.isInstanceOf[SlotClickable])
|
||||||
|
return slot.asInstanceOf[SlotClickable].onClick(button, modifiers, player)
|
||||||
|
}
|
||||||
|
return super.slotClick(slotNum, button, modifiers, player)
|
||||||
|
}
|
||||||
|
|
||||||
|
override def transferStackInSlot(player: EntityPlayer, slot: Int): ItemStack = null
|
||||||
|
}
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) bdew, 2013
|
|
||||||
* https://github.com/bdew/bdlib
|
|
||||||
*
|
|
||||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
|
||||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
|
||||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
|
||||||
*/
|
|
||||||
|
|
||||||
package net.bdew.lib.gui
|
|
||||||
|
|
||||||
class Point(val x: Int, val y: Int) {
|
|
||||||
def this(p: Point) = this(p.x, p.y)
|
|
||||||
def +(that: Point) = new Point(this.x + that.x, this.y + that.y)
|
|
||||||
def -(that: Point) = new Point(this.x - that.x, this.y - that.y)
|
|
||||||
}
|
|
||||||
|
|
||||||
object Point {
|
|
||||||
|
|
||||||
import language.implicitConversions
|
|
||||||
|
|
||||||
implicit def awt2point(p: java.awt.Point): Point = new Point(p.x, p.y)
|
|
||||||
implicit def point2awt(p: Point): java.awt.Point = new java.awt.Point(p.x, p.y)
|
|
||||||
implicit def tuple2point(p: (Int, Int)): Point = new Point(p._1, p._2)
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) bdew, 2013
|
|
||||||
* https://github.com/bdew/bdlib
|
|
||||||
*
|
|
||||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
|
||||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
|
||||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
|
||||||
*/
|
|
||||||
|
|
||||||
package net.bdew.lib.gui
|
|
||||||
|
|
||||||
class Rect(val x: Int, val y: Int, val w: Int, val h: Int) {
|
|
||||||
def this(p: Point, w: Int, h: Int) = this(p.x, p.y, w, h)
|
|
||||||
def contains(p: Point) = p.x >= x && p.y >= y && p.x <= x + w && p.y <= y + h
|
|
||||||
def origin = new Point(x, y)
|
|
||||||
def +(p: Point) = new Rect(origin + p, w, h)
|
|
||||||
def -(p: Point) = new Rect(origin - p, w, h)
|
|
||||||
}
|
|
||||||
@@ -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.gui
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
|
import net.minecraft.inventory.Slot
|
||||||
|
import net.minecraft.item.ItemStack
|
||||||
|
|
||||||
|
trait SlotClickable extends Slot {
|
||||||
|
def onClick(button: Int, mods: Int, player: EntityPlayer): ItemStack
|
||||||
|
}
|
||||||
@@ -1,18 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) bdew, 2013
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
* https://github.com/bdew/bdlib
|
* https://github.com/bdew/bdlib
|
||||||
*
|
*
|
||||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
* 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
|
* 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
|
package net.bdew.lib.gui
|
||||||
|
|
||||||
import net.minecraft.inventory.IInventory
|
import net.minecraft.inventory.IInventory
|
||||||
import net.minecraft.inventory.Slot
|
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
|
|
||||||
class SlotValidating(inv: IInventory, slot: Int, x: Int, y: Int) extends Slot(inv, slot, x, y) {
|
class SlotValidating(inv: IInventory, slot: Int, x: Int, y: Int) extends BaseSlot(inv, slot, x, y) {
|
||||||
override def isItemValid(stack: ItemStack) = inventory.isItemValidForSlot(getSlotIndex, stack)
|
override def isItemValid(stack: ItemStack) = inventory.isItemValidForSlot(getSlotIndex, stack)
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
|
||||||
|
import net.bdew.lib.Client
|
||||||
|
import net.minecraft.client.Minecraft
|
||||||
|
import net.minecraft.client.renderer.texture.TextureMap
|
||||||
|
import net.minecraft.util.{IIcon, ResourceLocation}
|
||||||
|
|
||||||
|
trait Texture {
|
||||||
|
def u1: Float
|
||||||
|
def u2: Float
|
||||||
|
def v1: Float
|
||||||
|
def v2: Float
|
||||||
|
def bind(): Unit
|
||||||
|
}
|
||||||
|
|
||||||
|
class InterpolatedTexture(val texture: Texture, rect: Rect) extends Texture {
|
||||||
|
def bind() = texture.bind()
|
||||||
|
def u1 = rect.x1 * (texture.u2 - texture.u1) + texture.u1
|
||||||
|
def u2 = rect.x2 * (texture.u2 - texture.u1) + texture.u1
|
||||||
|
def v1 = rect.y1 * (texture.v2 - texture.v1) + texture.v1
|
||||||
|
def v2 = rect.y2 * (texture.v2 - texture.v1) + texture.v1
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
def v2 = icon.getMaxV
|
||||||
|
def bind() = Minecraft.getMinecraft.renderEngine.bindTexture(resource)
|
||||||
|
}
|
||||||
|
|
||||||
|
class Sprite(val resource: ResourceLocation, r: Rect, scale: Int = 256) extends Texture {
|
||||||
|
val rect = Rect(r.x / scale, r.y / scale, r.w / scale, r.h / scale)
|
||||||
|
def u1 = rect.x1
|
||||||
|
def u2 = rect.x2
|
||||||
|
def v1 = rect.y1
|
||||||
|
def v2 = rect.y2
|
||||||
|
def bind() = Minecraft.getMinecraft.renderEngine.bindTexture(resource)
|
||||||
|
}
|
||||||
|
|
||||||
|
class ScaledResourceLocation(path: String, val scale: Int = 256) extends ResourceLocation(path) {
|
||||||
|
def this(domain: String, path: String, scale: Int) = this(domain + ":" + path, scale)
|
||||||
|
def this(domain: String, path: String) = this(domain + ":" + path, 256)
|
||||||
|
}
|
||||||
|
|
||||||
|
object Texture {
|
||||||
|
val ITEMS = TextureMap.locationItemsTexture
|
||||||
|
val BLOCKS = TextureMap.locationBlocksTexture
|
||||||
|
|
||||||
|
// From minecraft Icon
|
||||||
|
def apply(res: ResourceLocation, i: IIcon) = new IconWrapper(res, i)
|
||||||
|
|
||||||
|
// From a ResourceLocation and position, scale optional
|
||||||
|
def apply(res: ResourceLocation, r: Rect) = new Sprite(res, r)
|
||||||
|
def apply(res: ResourceLocation, r: Rect, scale: Int) = new Sprite(res, r, scale)
|
||||||
|
def apply(res: ResourceLocation, u1: Float, v1: Float, w: Float, h: Float) = new Sprite(res, Rect(u1, v1, w, h))
|
||||||
|
def apply(res: ResourceLocation, u1: Float, v1: Float, w: Float, h: Float, scale: Int) = new Sprite(res, Rect(u1, v1, w, h), scale)
|
||||||
|
|
||||||
|
// From a path (with optional domain) and position, no scale
|
||||||
|
def apply(path: String, r: Rect) = new Sprite(new ResourceLocation(path), r)
|
||||||
|
def apply(path: String, u1: Float, v1: Float, w: Float, h: Float) = new Sprite(new ResourceLocation(path), Rect(u1, v1, w, h))
|
||||||
|
def apply(domain: String, path: String, r: Rect) = new Sprite(new ResourceLocation(domain, path), r)
|
||||||
|
def apply(domain: String, path: String, u1: Float, v1: Float, w: Float, h: Float) = new Sprite(new ResourceLocation(domain, path), Rect(u1, v1, w, h))
|
||||||
|
|
||||||
|
// From a path (with optional domain), position and scale
|
||||||
|
def apply(path: String, r: Rect, scale: Int) = new Sprite(new ResourceLocation(path), r, scale)
|
||||||
|
def apply(path: String, u1: Float, v1: Float, w: Float, h: Float, scale: Int) = new Sprite(new ResourceLocation(path), Rect(u1, v1, w, h), scale)
|
||||||
|
def apply(domain: String, path: String, r: Rect, scale: Int) = new Sprite(new ResourceLocation(domain, path), r, scale)
|
||||||
|
def apply(domain: String, path: String, u1: Float, v1: Float, w: Float, h: Float, scale: Int) = new Sprite(new ResourceLocation(domain, path), Rect(u1, v1, w, h), scale)
|
||||||
|
|
||||||
|
// From a ScaledResourceLocation and position
|
||||||
|
def apply(res: ScaledResourceLocation, r: Rect) = new Sprite(res, r, res.scale)
|
||||||
|
def apply(res: ScaledResourceLocation, u1: Float, v1: Float, w: Float, h: Float) = new Sprite(res, Rect(u1, v1, w, h), res.scale)
|
||||||
|
|
||||||
|
// A fraction of another Texture, parameters should be between 0 and 1
|
||||||
|
def interpolate(texture: Texture, rect: Rect) = new InterpolatedTexture(texture, rect)
|
||||||
|
def interpolate(texture: Texture, u1: Float, v1: Float, u2: Float, v2: Float) = new InterpolatedTexture(texture, Rect(u1, v1, u2 - u1, v2 - v1))
|
||||||
|
}
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) bdew, 2013
|
|
||||||
* https://github.com/bdew/bdlib
|
|
||||||
*
|
|
||||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
|
||||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
|
||||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
|
||||||
*/
|
|
||||||
|
|
||||||
package net.bdew.lib.gui
|
|
||||||
|
|
||||||
import net.minecraft.util.ResourceLocation
|
|
||||||
|
|
||||||
class TextureLocation(val resource: ResourceLocation, val p: Point) extends Point(p.x, p.y) {
|
|
||||||
def this(resource: ResourceLocation, x: Int, y: Int) = this(resource, new Point(x, y))
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
|
||||||
|
import net.bdew.lib.gui.widgets.BaseWidget
|
||||||
|
import net.minecraft.client.gui.FontRenderer
|
||||||
|
import org.lwjgl.opengl.GL11
|
||||||
|
|
||||||
|
import scala.collection.mutable
|
||||||
|
|
||||||
|
trait WidgetContainer extends DrawTarget {
|
||||||
|
val rect: Rect
|
||||||
|
val widgets = mutable.MutableList.empty[BaseWidget]
|
||||||
|
|
||||||
|
def activeWidgets: Iterable[BaseWidget] = widgets
|
||||||
|
|
||||||
|
def getFontRenderer: FontRenderer
|
||||||
|
|
||||||
|
def clear() = widgets.clear()
|
||||||
|
|
||||||
|
def add[T <: BaseWidget](w: T): T = {
|
||||||
|
widgets += w
|
||||||
|
w.init(this)
|
||||||
|
return w
|
||||||
|
}
|
||||||
|
|
||||||
|
def mouseClicked(p: Point, bt: Int) {
|
||||||
|
for (w <- activeWidgets)
|
||||||
|
if (w.rect.contains(p))
|
||||||
|
w.mouseClicked(p - w.rect.origin, bt)
|
||||||
|
else
|
||||||
|
w.looseFocus()
|
||||||
|
}
|
||||||
|
|
||||||
|
def keyTyped(c: Char, i: Int): Boolean = {
|
||||||
|
for (w <- activeWidgets)
|
||||||
|
if (w.keyTyped(c, i))
|
||||||
|
return true
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
def drawBackground(mouse: Point) {
|
||||||
|
val p = mouse - rect.origin
|
||||||
|
GL11.glPushMatrix()
|
||||||
|
GL11.glTranslatef(rect.origin.x, rect.origin.y, 0)
|
||||||
|
for (w <- activeWidgets) {
|
||||||
|
w.drawBackground(p)
|
||||||
|
}
|
||||||
|
GL11.glPopMatrix()
|
||||||
|
}
|
||||||
|
|
||||||
|
def draw(mouse: Point) {
|
||||||
|
val p = mouse - rect.origin
|
||||||
|
GL11.glPushMatrix()
|
||||||
|
GL11.glTranslatef(rect.origin.x, rect.origin.y, 0)
|
||||||
|
for (w <- activeWidgets) {
|
||||||
|
w.draw(p)
|
||||||
|
}
|
||||||
|
GL11.glPopMatrix()
|
||||||
|
}
|
||||||
|
|
||||||
|
def handleTooltip(p: Point, tip: mutable.MutableList[String]) {
|
||||||
|
for (w <- activeWidgets if w.rect.contains(p))
|
||||||
|
w.handleTooltip(p - w.rect.origin, tip)
|
||||||
|
}
|
||||||
|
|
||||||
|
def looseFocus() =
|
||||||
|
for (w <- activeWidgets)
|
||||||
|
w.looseFocus()
|
||||||
|
|
||||||
|
def getOffsetFromWindow: Point
|
||||||
|
}
|
||||||
|
|
||||||
|
class WidgetContainerWindow(val parent: BaseScreen, xSz: Int, ySz: Int) extends WidgetContainer with SimpleDrawTarget {
|
||||||
|
def getZLevel = parent.getZLevel
|
||||||
|
def getFontRenderer = parent.getFontRenderer
|
||||||
|
def getOffsetFromWindow = Point(0, 0)
|
||||||
|
val rect = Rect(0, 0, xSz, ySz)
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
|
||||||
|
package object gui {
|
||||||
|
type Rect = BaseRect[Float]
|
||||||
|
type Point = BasePoint[Float]
|
||||||
|
|
||||||
|
import scala.language.implicitConversions
|
||||||
|
|
||||||
|
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[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] =
|
||||||
|
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,26 +1,36 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) bdew, 2013
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
* https://github.com/bdew/bdlib
|
* https://github.com/bdew/bdlib
|
||||||
*
|
*
|
||||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
* 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
|
* 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
|
package net.bdew.lib.gui.widgets
|
||||||
|
|
||||||
import scala.collection.mutable
|
import net.bdew.lib.gui.{Point, Rect, WidgetContainer}
|
||||||
import net.bdew.lib.gui.{Point, BaseScreen, Rect}
|
|
||||||
import net.minecraft.util.ResourceLocation
|
|
||||||
import net.minecraft.client.Minecraft
|
|
||||||
|
|
||||||
trait Widget {
|
import scala.collection.mutable
|
||||||
|
|
||||||
|
trait BaseWidget {
|
||||||
|
val rect: Rect
|
||||||
|
var parent: WidgetContainer = null
|
||||||
|
def init(p: WidgetContainer) = parent = p
|
||||||
|
def handleTooltip(p: Point, tip: mutable.MutableList[String])
|
||||||
|
def mouseClicked(p: Point, button: Int)
|
||||||
|
def keyTyped(c: Char, i: Int): Boolean
|
||||||
|
def draw(mouse: Point)
|
||||||
|
def drawBackground(mouse: Point)
|
||||||
|
def looseFocus()
|
||||||
|
}
|
||||||
|
|
||||||
|
trait Widget extends BaseWidget {
|
||||||
val rect: Rect
|
val rect: Rect
|
||||||
var parent: BaseScreen = null
|
|
||||||
def handleTooltip(p: Point, tip: mutable.MutableList[String]) {}
|
def handleTooltip(p: Point, tip: mutable.MutableList[String]) {}
|
||||||
def mouseClicked(p: Point, button: Int) {}
|
def mouseClicked(p: Point, button: Int) {}
|
||||||
def keyTyped(c: Char, i: Int): Boolean = false
|
def keyTyped(c: Char, i: Int): Boolean = false
|
||||||
def draw() {}
|
def draw(mouse: Point) {}
|
||||||
|
def drawBackground(mouse: Point) {}
|
||||||
def bindTexture(res: ResourceLocation) = Minecraft.getMinecraft.renderEngine.bindTexture(res)
|
def looseFocus() {}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
|
* https://github.com/bdew/bdlib
|
||||||
|
*
|
||||||
|
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||||
|
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||||
|
* http://bdew.net/minecraft-mod-public-license/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.bdew.lib.gui.widgets
|
||||||
|
|
||||||
|
import net.bdew.lib.gui.{Point, Rect}
|
||||||
|
import net.minecraft.client.Minecraft
|
||||||
|
import net.minecraft.client.audio.PositionedSoundRecord
|
||||||
|
import net.minecraft.client.gui.GuiButton
|
||||||
|
import net.minecraft.util.ResourceLocation
|
||||||
|
|
||||||
|
class WidgetButton(val rect: Rect, text: String, clicked: WidgetButton => Unit)
|
||||||
|
extends GuiButton(0, rect.x.round, rect.y.round, rect.w.round, rect.h.round, text) with Widget {
|
||||||
|
|
||||||
|
override def mouseClicked(p: Point, button: Int) {
|
||||||
|
Minecraft.getMinecraft.getSoundHandler.playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F))
|
||||||
|
clicked(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override def draw(mouse: Point) = drawButton(Minecraft.getMinecraft, mouse.x.round, mouse.y.round)
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
|
* https://github.com/bdew/bdlib
|
||||||
|
*
|
||||||
|
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||||
|
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||||
|
* http://bdew.net/minecraft-mod-public-license/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.bdew.lib.gui.widgets
|
||||||
|
|
||||||
|
import net.bdew.lib.gui.{Point, Rect, Texture}
|
||||||
|
import net.minecraft.client.Minecraft
|
||||||
|
import net.minecraft.client.audio.PositionedSoundRecord
|
||||||
|
import net.minecraft.util.ResourceLocation
|
||||||
|
|
||||||
|
import scala.collection.mutable
|
||||||
|
|
||||||
|
class WidgetButtonIcon(p: Point, clicked: WidgetButtonIcon => Unit, baseTex: Texture, hoverTex: Texture) extends Widget {
|
||||||
|
val rect = new Rect(p, 16, 16)
|
||||||
|
val iconRect = new Rect(p +(1, 1), 14, 14)
|
||||||
|
|
||||||
|
var icon: Texture = null
|
||||||
|
var hover: String = null
|
||||||
|
|
||||||
|
override def draw(mouse: Point) {
|
||||||
|
if (rect.contains(mouse))
|
||||||
|
parent.drawTexture(rect, hoverTex)
|
||||||
|
else
|
||||||
|
parent.drawTexture(rect, baseTex)
|
||||||
|
|
||||||
|
if (icon != null)
|
||||||
|
parent.drawTexture(iconRect, icon)
|
||||||
|
}
|
||||||
|
|
||||||
|
override def handleTooltip(p: Point, tip: mutable.MutableList[String]) {
|
||||||
|
if (hover != null && hover > "")
|
||||||
|
tip += hover
|
||||||
|
}
|
||||||
|
|
||||||
|
override def mouseClicked(p: Point, button: Int) {
|
||||||
|
Minecraft.getMinecraft.getSoundHandler.playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F))
|
||||||
|
clicked(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* 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.{Color, Point, Rect}
|
||||||
|
|
||||||
|
class WidgetDynLabel(text: => String, x: Int, y: Int, color: Color) extends Widget {
|
||||||
|
val rect = new Rect(x, y, 0, 0)
|
||||||
|
override def draw(mouse: Point) {
|
||||||
|
parent.drawText(text, rect.origin, color, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,37 +1,32 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) bdew, 2013
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
* https://github.com/bdew/bdlib
|
* https://github.com/bdew/bdlib
|
||||||
*
|
*
|
||||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
* 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
|
* 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
|
package net.bdew.lib.gui.widgets
|
||||||
|
|
||||||
import net.bdew.lib.gui.{TextureLocation, Rect}
|
|
||||||
import net.bdew.lib.gui.Direction
|
|
||||||
import net.bdew.lib.data.base.DataSlotNumeric
|
import net.bdew.lib.data.base.DataSlotNumeric
|
||||||
|
import net.bdew.lib.gui._
|
||||||
|
|
||||||
class WidgetFillDataslot[T](val rect: Rect, val texture: TextureLocation, 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 {
|
||||||
|
|
||||||
def getFillArea(max: Int): Int = (num.toFloat(dslot) / num.toFloat(maxval) * max).round
|
import num.mkNumericOps
|
||||||
|
|
||||||
override def draw() {
|
override def draw(mouse: Point) {
|
||||||
bindTexture(texture.resource)
|
val fill = dSlot.value.toFloat() / maxVal.toFloat()
|
||||||
dir match {
|
dir match {
|
||||||
case Direction.UP =>
|
case Direction.UP =>
|
||||||
val fill = getFillArea(rect.h)
|
parent.drawTextureInterpolate(rect, texture, 0, 1 - fill, 1, 1)
|
||||||
parent.drawTexturedModalRect(rect.x, rect.y + rect.h - fill, texture.x, texture.y + rect.h - fill, rect.w, fill)
|
|
||||||
case Direction.DOWN =>
|
case Direction.DOWN =>
|
||||||
val fill = getFillArea(rect.h)
|
parent.drawTextureInterpolate(rect, texture, 0, 0, 1, fill)
|
||||||
parent.drawTexturedModalRect(rect.x, rect.y, texture.x, texture.y, rect.w, fill)
|
|
||||||
case Direction.LEFT =>
|
case Direction.LEFT =>
|
||||||
val fill = getFillArea(rect.w)
|
parent.drawTextureInterpolate(rect, texture, 1 - fill, 0, 1, 1)
|
||||||
parent.drawTexturedModalRect(rect.x + rect.w - fill, rect.y, texture.x + rect.w - fill, texture.y, fill, rect.h)
|
|
||||||
case Direction.RIGHT =>
|
case Direction.RIGHT =>
|
||||||
val fill = getFillArea(rect.w)
|
parent.drawTextureInterpolate(rect, texture, 0, 0, fill, 1)
|
||||||
parent.drawTexturedModalRect(rect.x, rect.y, texture.x, texture.y, fill, rect.h)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,60 +1,58 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) bdew, 2013
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
* https://github.com/bdew/bdlib
|
* https://github.com/bdew/bdlib
|
||||||
*
|
*
|
||||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
* 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
|
* 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
|
package net.bdew.lib.gui.widgets
|
||||||
|
|
||||||
import net.bdew.lib.gui.{Point, TextureLocation, Rect}
|
|
||||||
import net.bdew.lib.data.DataSlotTankBase
|
import net.bdew.lib.data.DataSlotTankBase
|
||||||
import scala.collection.mutable
|
import net.bdew.lib.gui.{Color, Point, Rect, Texture}
|
||||||
import net.minecraft.client.renderer.texture.TextureMap
|
import net.bdew.lib.{DecFormat, Misc}
|
||||||
import java.text.DecimalFormat
|
|
||||||
import net.bdew.lib.Misc
|
|
||||||
import org.lwjgl.opengl.GL11
|
import org.lwjgl.opengl.GL11
|
||||||
|
|
||||||
class WidgetFluidGauge(val rect: Rect, overlay: TextureLocation, dslot: DataSlotTankBase) extends Widget {
|
import scala.collection.mutable
|
||||||
val formater = new DecimalFormat("#,###")
|
|
||||||
|
|
||||||
|
class WidgetFluidGauge(val rect: Rect, overlay: Texture, dSlot: DataSlotTankBase) extends Widget {
|
||||||
override def handleTooltip(p: Point, tip: mutable.MutableList[String]) {
|
override def handleTooltip(p: Point, tip: mutable.MutableList[String]) {
|
||||||
if (dslot.getFluid != null) {
|
if (dSlot.getFluid != null) {
|
||||||
tip += dslot.getFluid.getFluid.getLocalizedName
|
tip += dSlot.getFluid.getFluid.getLocalizedName(dSlot.getFluid)
|
||||||
tip += "%s/%s mB".format(formater.format(dslot.getFluidAmount), formater.format(dslot.getCapacity))
|
tip += "%s/%s mB".format(DecFormat.round(dSlot.getFluidAmount), DecFormat.round(dSlot.getCapacity))
|
||||||
} else {
|
} else {
|
||||||
tip += Misc.toLocal("gendustry.label.empty")
|
tip += Misc.toLocal("bdlib.label.empty")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override def draw() {
|
override def draw(mouse: Point) {
|
||||||
GL11.glEnable(GL11.GL_BLEND)
|
GL11.glEnable(GL11.GL_BLEND)
|
||||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA)
|
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA)
|
||||||
|
|
||||||
val fstack = dslot.getFluid
|
val fStack = dSlot.getFluid
|
||||||
if (fstack != null && fstack.getFluid.getStillIcon != null) {
|
if (fStack != null) {
|
||||||
val icon = fstack.getFluid.getStillIcon
|
val color = Color.fromInt(Misc.getFluidColor(fStack))
|
||||||
bindTexture(TextureMap.locationBlocksTexture)
|
val icon = Texture(Texture.BLOCKS, Misc.getFluidIcon(fStack))
|
||||||
var fillHeight: Int = (rect.h * fstack.amount / dslot.getCapacity).round
|
var fillHeight = if (dSlot.getCapacity > 0) rect.h * fStack.amount / dSlot.getCapacity else 0
|
||||||
var yStart: Int = 0
|
var yStart: Int = 0
|
||||||
|
|
||||||
while (fillHeight > 0) {
|
while (fillHeight > 0) {
|
||||||
if (fillHeight > 16) {
|
if (fillHeight > 16) {
|
||||||
parent.drawTexturedModelRectFromIcon(rect.x, rect.y + rect.h - 16 - yStart, icon, 16, 16)
|
parent.drawTexture(new Rect(rect.x, rect.y2 - 16 - yStart, rect.w, 16), icon, color)
|
||||||
fillHeight -= 16
|
fillHeight -= 16
|
||||||
} else {
|
} else {
|
||||||
parent.drawTexturedModelRectFromIcon(rect.x, rect.y + rect.h - fillHeight - yStart, icon, 16, fillHeight)
|
parent.drawTextureInterpolate(new Rect(rect.x, rect.y2 - 16 - yStart, rect.w, 16), icon, 0, 1 - fillHeight / 16, 1, 1, color)
|
||||||
fillHeight = 0
|
fillHeight = 0
|
||||||
}
|
}
|
||||||
yStart = yStart + 16
|
yStart = yStart + 16
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GL11.glColor3d(1, 1, 1)
|
||||||
GL11.glDisable(GL11.GL_BLEND)
|
GL11.glDisable(GL11.GL_BLEND)
|
||||||
|
|
||||||
bindTexture(overlay.resource)
|
if (overlay != null)
|
||||||
parent.drawTexturedModalRect(rect.x, rect.y, overlay.x, overlay.y, rect.w, rect.h)
|
parent.drawTexture(rect, overlay)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,19 +1,19 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) bdew, 2013
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
* https://github.com/bdew/bdlib
|
* https://github.com/bdew/bdlib
|
||||||
*
|
*
|
||||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
* 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
|
* 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
|
package net.bdew.lib.gui.widgets
|
||||||
|
|
||||||
import net.bdew.lib.gui.Rect
|
import net.bdew.lib.gui.{Color, Point, Rect}
|
||||||
|
|
||||||
class WidgetLabel(text: String, x: Int, y: Int, color: Int) extends Widget {
|
class WidgetLabel(text: String, x: Int, y: Int, color: Color) extends Widget {
|
||||||
val rect: Rect = new Rect(x, y, 0, 0)
|
val rect = new Rect(x, y, 0, 0)
|
||||||
override def draw() {
|
override def draw(mouse: Point) {
|
||||||
parent.getFontRenderer.drawString(text, x, y, color)
|
parent.drawText(text, rect.origin, color, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
|
* https://github.com/bdew/bdlib
|
||||||
|
*
|
||||||
|
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||||
|
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||||
|
* http://bdew.net/minecraft-mod-public-license/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.bdew.lib.gui.widgets
|
||||||
|
|
||||||
|
import net.bdew.lib.gui.Rect
|
||||||
|
|
||||||
|
abstract class WidgetMultiPane(rect: Rect) extends WidgetSubContainer(rect) {
|
||||||
|
def getActivePane: BaseWidget
|
||||||
|
|
||||||
|
def addPane[T <: BaseWidget](w: T): T = {
|
||||||
|
w.init(this)
|
||||||
|
return w
|
||||||
|
}
|
||||||
|
override def activeWidgets = super.activeWidgets ++: List(getActivePane)
|
||||||
|
}
|
||||||
@@ -1,18 +1,19 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) bdew, 2013
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
* https://github.com/bdew/bdlib
|
* https://github.com/bdew/bdlib
|
||||||
*
|
*
|
||||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
* 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
|
* 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
|
package net.bdew.lib.gui.widgets
|
||||||
|
|
||||||
import net.bdew.lib.gui.{Point, Direction, TextureLocation, Rect}
|
|
||||||
import net.bdew.lib.data.DataSlotFloat
|
import net.bdew.lib.data.DataSlotFloat
|
||||||
|
import net.bdew.lib.gui._
|
||||||
|
|
||||||
import scala.collection.mutable
|
import scala.collection.mutable
|
||||||
|
|
||||||
class WidgetProgressBar(rect: Rect, texture: TextureLocation, dslot: DataSlotFloat) extends WidgetFillDataslot[Float](rect, texture, Direction.RIGHT, dslot, 1) {
|
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) + "%"
|
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)
|
||||||
|
}
|
||||||
@@ -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.gui.widgets
|
||||||
|
|
||||||
|
import net.bdew.lib.gui._
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
@@ -1,19 +1,25 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) bdew, 2013
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
* https://github.com/bdew/bdlib
|
* https://github.com/bdew/bdlib
|
||||||
*
|
*
|
||||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
* 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
|
* 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
|
package net.bdew.lib.gui.widgets
|
||||||
|
|
||||||
import net.minecraft.client.gui.{FontRenderer, GuiTextField}
|
|
||||||
import net.bdew.lib.gui.{Point, Rect}
|
import net.bdew.lib.gui.{Point, Rect}
|
||||||
|
import net.minecraft.client.gui.{FontRenderer, GuiTextField}
|
||||||
|
|
||||||
class WidgetTextEdit(val rect: Rect, fr: FontRenderer) extends GuiTextField(fr, rect.x, rect.y, rect.w, rect.h) with Widget {
|
class WidgetTextEdit(val rect: Rect, fr: FontRenderer) extends GuiTextField(fr, rect.x.round, rect.y.round, rect.w.round, rect.h.round) with Widget {
|
||||||
override def mouseClicked(p: Point, button: Int) = super.mouseClicked(p.x + rect.x, p.y + rect.y, button)
|
|
||||||
|
override def mouseClicked(p: Point, button: Int) = {
|
||||||
|
val pp = p + rect.origin
|
||||||
|
super.mouseClicked(pp.x.round, pp.y.round, button)
|
||||||
|
}
|
||||||
|
|
||||||
|
override def looseFocus() = setFocused(false)
|
||||||
override def keyTyped(c: Char, i: Int): Boolean = super.textboxKeyTyped(c, i)
|
override def keyTyped(c: Char, i: Int): Boolean = super.textboxKeyTyped(c, i)
|
||||||
override def draw() = super.drawTextBox()
|
override def draw(mouse: Point) = super.drawTextBox()
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) bdew, 2013 - 2015
|
||||||
|
* https://github.com/bdew/bdlib
|
||||||
|
*
|
||||||
|
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||||
|
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||||
|
* http://bdew.net/minecraft-mod-public-license/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.bdew.lib.helpers
|
||||||
|
|
||||||
|
import net.minecraft.util._
|
||||||
|
|
||||||
|
import scala.language.implicitConversions
|
||||||
|
|
||||||
|
class RichChatComponent(v: IChatComponent) {
|
||||||
|
def &(that: IChatComponent) = v.appendSibling(that)
|
||||||
|
|
||||||
|
private def applyStyle(f: ChatStyle => Unit) = {
|
||||||
|
f(v.getChatStyle)
|
||||||
|
v
|
||||||
|
}
|
||||||
|
|
||||||
|
def setColor(c: EnumChatFormatting) = applyStyle(_.setColor(c))
|
||||||
|
def setBold(b: Boolean) = applyStyle(_.setBold(b))
|
||||||
|
def setItalic(b: Boolean) = applyStyle(_.setItalic(b))
|
||||||
|
def setObfuscated(b: Boolean) = applyStyle(_.setObfuscated(b))
|
||||||
|
def setStrikethrough(b: Boolean) = applyStyle(_.setStrikethrough(b))
|
||||||
|
def setUnderlined(b: Boolean) = applyStyle(_.setUnderlined(b))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
object ChatHelper {
|
||||||
|
|
||||||
|
object Color {
|
||||||
|
val BLACK = EnumChatFormatting.BLACK
|
||||||
|
val DARK_BLUE = EnumChatFormatting.DARK_BLUE
|
||||||
|
val DARK_GREEN = EnumChatFormatting.DARK_GREEN
|
||||||
|
val DARK_AQUA = EnumChatFormatting.DARK_AQUA
|
||||||
|
val DARK_RED = EnumChatFormatting.DARK_RED
|
||||||
|
val DARK_PURPLE = EnumChatFormatting.DARK_PURPLE
|
||||||
|
val GOLD = EnumChatFormatting.GOLD
|
||||||
|
val GRAY = EnumChatFormatting.GRAY
|
||||||
|
val DARK_GRAY = EnumChatFormatting.DARK_GRAY
|
||||||
|
val BLUE = EnumChatFormatting.BLUE
|
||||||
|
val GREEN = EnumChatFormatting.GREEN
|
||||||
|
val AQUA = EnumChatFormatting.AQUA
|
||||||
|
val RED = EnumChatFormatting.RED
|
||||||
|
val LIGHT_PURPLE = EnumChatFormatting.LIGHT_PURPLE
|
||||||
|
val YELLOW = EnumChatFormatting.YELLOW
|
||||||
|
val WHITE = EnumChatFormatting.WHITE
|
||||||
|
}
|
||||||
|
|
||||||
|
implicit def str2chat(s: String): ChatComponentText = new ChatComponentText(s)
|
||||||
|
implicit def str2rich(s: String): RichChatComponent = new RichChatComponent(new ChatComponentText(s))
|
||||||
|
implicit def pimpIChatComponent(v: IChatComponent): RichChatComponent = new RichChatComponent(v)
|
||||||
|
|
||||||
|
def C(s: String) = new ChatComponentText(s)
|
||||||
|
def L(s: String, params: IChatComponent*) = new ChatComponentTranslation(s, params: _*)
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
|
* https://github.com/bdew/bdlib
|
||||||
|
*
|
||||||
|
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||||
|
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||||
|
* http://bdew.net/minecraft-mod-public-license/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.bdew.lib.items
|
||||||
|
|
||||||
|
import net.minecraft.block.Block
|
||||||
|
import net.minecraft.item.{Item, ItemBlock, ItemStack}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows matching Items in ItemStacks in scala pattern matches
|
||||||
|
*/
|
||||||
|
object IStack {
|
||||||
|
def unapply(x: ItemStack): Option[Item] =
|
||||||
|
if (x == null || x.getItem == null)
|
||||||
|
None
|
||||||
|
else
|
||||||
|
Some(x.getItem)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows matching Blocks in ItemStacks in scala pattern matches
|
||||||
|
*/
|
||||||
|
object IStackBlock {
|
||||||
|
def unapply(x: ItemStack): Option[Block] =
|
||||||
|
if (x == null || x.getItem == null || !x.getItem.isInstanceOf[ItemBlock])
|
||||||
|
None
|
||||||
|
else
|
||||||
|
Some(x.getItem.asInstanceOf[ItemBlock].field_150939_a)
|
||||||
|
}
|
||||||
@@ -1,20 +1,23 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) bdew, 2013
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
* https://github.com/bdew/bdlib
|
* https://github.com/bdew/bdlib
|
||||||
*
|
*
|
||||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
* 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
|
* 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
|
package net.bdew.lib.items
|
||||||
|
|
||||||
import net.minecraft.entity.item.EntityItem
|
import java.util.Random
|
||||||
import net.minecraft.item.ItemStack
|
|
||||||
import net.minecraft.world.World
|
|
||||||
import net.minecraft.entity.player.EntityPlayer
|
|
||||||
import net.minecraft.inventory.IInventory
|
|
||||||
import net.bdew.lib.Misc
|
import net.bdew.lib.Misc
|
||||||
|
import net.minecraft.entity.item.EntityItem
|
||||||
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
|
import net.minecraft.inventory.{IInventory, ISidedInventory}
|
||||||
|
import net.minecraft.item.{Item, ItemStack}
|
||||||
|
import net.minecraft.world.World
|
||||||
|
import net.minecraftforge.common.util.ForgeDirection
|
||||||
|
|
||||||
object ItemUtils {
|
object ItemUtils {
|
||||||
def throwItemAt(world: World, x: Int, y: Int, z: Int, stack: ItemStack) {
|
def throwItemAt(world: World, x: Int, y: Int, z: Int, stack: ItemStack) {
|
||||||
@@ -22,11 +25,11 @@ object ItemUtils {
|
|||||||
val dx = world.rand.nextFloat * 0.8
|
val dx = world.rand.nextFloat * 0.8
|
||||||
val dy = world.rand.nextFloat * 0.8
|
val dy = world.rand.nextFloat * 0.8
|
||||||
val dz = 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)
|
val entity = new EntityItem(world, x + dx, y + dy, z + dz, stack)
|
||||||
entityitem.motionX = world.rand.nextGaussian * 0.05
|
entity.motionX = world.rand.nextGaussian * 0.05
|
||||||
entityitem.motionY = world.rand.nextGaussian * 0.05 + 0.2
|
entity.motionY = world.rand.nextGaussian * 0.05 + 0.2
|
||||||
entityitem.motionZ = world.rand.nextGaussian * 0.05
|
entity.motionZ = world.rand.nextGaussian * 0.05
|
||||||
world.spawnEntityInWorld(entityitem)
|
world.spawnEntityInWorld(entity)
|
||||||
}
|
}
|
||||||
|
|
||||||
def dropItemToPlayer(world: World, player: EntityPlayer, stack: ItemStack) {
|
def dropItemToPlayer(world: World, player: EntityPlayer, stack: ItemStack) {
|
||||||
@@ -37,34 +40,34 @@ object ItemUtils {
|
|||||||
def isSameItem(stack1: ItemStack, stack2: ItemStack): Boolean = {
|
def isSameItem(stack1: ItemStack, stack2: ItemStack): Boolean = {
|
||||||
if (stack1 == null || stack2 == null)
|
if (stack1 == null || stack2 == null)
|
||||||
return stack1 == stack2
|
return stack1 == stack2
|
||||||
if (stack1.itemID != stack2.itemID)
|
if (stack1.getItem != stack2.getItem)
|
||||||
return false
|
return false
|
||||||
if (stack1.getHasSubtypes && stack2.getItemDamage != stack1.getItemDamage)
|
if (stack1.getHasSubtypes && stack2.getItemDamage != stack1.getItemDamage)
|
||||||
return false
|
return false
|
||||||
return ItemStack.areItemStackTagsEqual(stack2, stack1)
|
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
|
if (stack == null) return null
|
||||||
|
|
||||||
// Try merging into existing slots
|
// 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 target = inv.getStackInSlot(slot)
|
||||||
val toAdd = Misc.min(target.getMaxStackSize - target.stackSize, inv.getInventoryStackLimit - target.stackSize, stack.stackSize)
|
val toAdd = Misc.min(target.getMaxStackSize - target.stackSize, inv.getInventoryStackLimit - target.stackSize, stack.stackSize)
|
||||||
if (toAdd >= stack.stackSize) {
|
if (toAdd >= stack.stackSize) {
|
||||||
target.stackSize += stack.stackSize
|
target.stackSize += stack.stackSize
|
||||||
stack.stackSize = 0
|
stack.stackSize = 0
|
||||||
inv.onInventoryChanged()
|
inv.markDirty()
|
||||||
return null
|
return null
|
||||||
} else if (toAdd > 0) {
|
} else if (toAdd > 0) {
|
||||||
target.stackSize += toAdd
|
target.stackSize += toAdd
|
||||||
stack.stackSize -= toAdd
|
stack.stackSize -= toAdd
|
||||||
inv.onInventoryChanged()
|
inv.markDirty()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now find empty slots and stick any leftovers there
|
// 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) {
|
if (inv.getInventoryStackLimit < stack.stackSize) {
|
||||||
inv.setInventorySlotContents(slot, stack.splitStack(inv.getInventoryStackLimit))
|
inv.setInventorySlotContents(slot, stack.splitStack(inv.getInventoryStackLimit))
|
||||||
} else {
|
} else {
|
||||||
@@ -76,4 +79,27 @@ object ItemUtils {
|
|||||||
|
|
||||||
return stack
|
return stack
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def getAccessibleSlotsFromSide(inv: IInventory, side: ForgeDirection) =
|
||||||
|
(Misc.asInstanceOpt(inv, classOf[ISidedInventory])
|
||||||
|
map (_.getAccessibleSlotsFromSide(side.ordinal()).toList)
|
||||||
|
getOrElse (0 until inv.getSizeInventory))
|
||||||
|
|
||||||
|
def findItemInInventory(inv: IInventory, item: Item) =
|
||||||
|
Range(0, inv.getSizeInventory).map(x => x -> inv.getStackInSlot(x))
|
||||||
|
.find({ case (slot, stack) => stack != null && stack.getItem == item })
|
||||||
|
.map({ case (slot, stack) => slot })
|
||||||
|
|
||||||
|
def copyWithRandomSize(template: ItemStack, max: Int, rand: Random) = {
|
||||||
|
val newSize = rand.nextInt(max)
|
||||||
|
val newStack = template.copy()
|
||||||
|
newStack.stackSize =
|
||||||
|
if (newSize > newStack.getMaxStackSize)
|
||||||
|
newStack.getMaxStackSize
|
||||||
|
else if (newSize <= 0)
|
||||||
|
1
|
||||||
|
else
|
||||||
|
newSize
|
||||||
|
newStack
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* 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.items
|
||||||
|
|
||||||
|
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||||
|
import net.bdew.lib.Misc
|
||||||
|
import net.minecraft.client.renderer.texture.IIconRegister
|
||||||
|
import net.minecraft.item.Item
|
||||||
|
|
||||||
|
trait NamedItem extends Item {
|
||||||
|
def name: String
|
||||||
|
}
|
||||||
|
|
||||||
|
class SimpleItem(val name: String) extends Item with NamedItem {
|
||||||
|
val modId = Misc.getActiveModId
|
||||||
|
setUnlocalizedName(modId + "." + name)
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
override def registerIcons(reg: IIconRegister) {
|
||||||
|
itemIcon = reg.registerIcon(Misc.iconName(modId, name))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* 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.items.inventory
|
||||||
|
|
||||||
|
import net.bdew.lib.gui.BaseContainer
|
||||||
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
|
import net.minecraft.inventory.Slot
|
||||||
|
import net.minecraft.item.ItemStack
|
||||||
|
|
||||||
|
class ContainerItemInventory(inv: InventoryItemAdapter, player: EntityPlayer) extends BaseContainer(inv) {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* 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.items.inventory
|
||||||
|
|
||||||
|
import net.bdew.lib.tile.inventory.BaseInventory
|
||||||
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
|
import net.minecraft.item.ItemStack
|
||||||
|
import net.minecraft.nbt.{NBTTagCompound, NBTTagList}
|
||||||
|
|
||||||
|
class InventoryItemAdapter(val player: EntityPlayer, val slot: Int, val size: Int, val tagName: String) extends BaseInventory {
|
||||||
|
def getSizeInventory = size
|
||||||
|
def getStack = player.inventory.getStackInSlot(slot)
|
||||||
|
|
||||||
|
if (getStack.hasTagCompound)
|
||||||
|
load()
|
||||||
|
|
||||||
|
def load() {
|
||||||
|
import net.bdew.lib.nbt._
|
||||||
|
val tag = getStack.getTagCompound
|
||||||
|
for (nbtItem <- tag.getList[NBTTagCompound](tagName)) {
|
||||||
|
val slot = nbtItem.getByte("Slot")
|
||||||
|
if (slot >= 0 && slot < inv.length) {
|
||||||
|
inv(slot) = ItemStack.loadItemStackFromNBT(nbtItem)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def markDirty() {
|
||||||
|
if (!getStack.hasTagCompound) getStack.setTagCompound(new NBTTagCompound)
|
||||||
|
val tag = getStack.getTagCompound
|
||||||
|
val itemList = new NBTTagList
|
||||||
|
for ((item, i) <- inv.view.zipWithIndex if item != null) {
|
||||||
|
val itemNbt: NBTTagCompound = new NBTTagCompound
|
||||||
|
itemNbt.setByte("Slot", i.asInstanceOf[Byte])
|
||||||
|
item.writeToNBT(itemNbt)
|
||||||
|
itemList.appendTag(itemNbt)
|
||||||
|
}
|
||||||
|
tag.setTag(tagName, itemList)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* 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.items.inventory
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.Loader
|
||||||
|
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||||
|
import net.bdew.lib.BdLib
|
||||||
|
import net.bdew.lib.gui.GuiProvider
|
||||||
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
|
import net.minecraft.item.Item
|
||||||
|
import net.minecraft.world.World
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mixin for items that have an internal inventory
|
||||||
|
* Subclasses are responsible for registering themselves with the GuiHandler of their mod
|
||||||
|
*/
|
||||||
|
trait ItemInventory extends Item with GuiProvider {
|
||||||
|
type TEClass = Any
|
||||||
|
def guiId: Int
|
||||||
|
val invSize: Int
|
||||||
|
val invTagName: String
|
||||||
|
val modObj = Loader.instance().activeModContainer().getMod
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
def makeGui(inv: InventoryItemAdapter, player: EntityPlayer): AnyRef
|
||||||
|
def makeContainer(inv: InventoryItemAdapter, player: EntityPlayer): ContainerItemInventory
|
||||||
|
|
||||||
|
def makeAdaptor(player: EntityPlayer) = new InventoryItemAdapter(player, player.inventory.currentItem, invSize, invTagName)
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
def getGui(te: TEClass, player: EntityPlayer) = {
|
||||||
|
val stack = player.inventory.getCurrentItem
|
||||||
|
if (stack.getItem == this) {
|
||||||
|
makeGui(makeAdaptor(player), player)
|
||||||
|
} else {
|
||||||
|
BdLib.logWarn("Attempt to open item container GUI without active item (%s)", this)
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def getContainer(te: TEClass, player: EntityPlayer) = {
|
||||||
|
val stack = player.inventory.getCurrentItem
|
||||||
|
if (stack.getItem == this) {
|
||||||
|
makeContainer(makeAdaptor(player), player)
|
||||||
|
} else {
|
||||||
|
BdLib.logWarn("Attempt to open item container GUI without active item by '%s' (%s)", player.getCommandSenderName, this)
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def doOpenGui(player: EntityPlayer, world: World) {
|
||||||
|
player.openGui(modObj, guiId, world, player.posX.toInt, player.posY.toInt, player.posZ.toInt)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loaded 100 of 230 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user