mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-11 22:31:52 +09:00
Loading item from module using Groovy
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
# Load order
|
||||
# Load Order
|
||||
# Modules are loaded from top to bottom.
|
||||
# And yes, you can disable basegame, but we don't recommend.
|
||||
# Acceptable formats:
|
||||
# module_name,description_in_English_no_comma,
|
||||
# module_name,description_in_English_no_comma,(external Jar 1);(external Jar 2); ...
|
||||
# module_name,description_in_English_no_comma,(entry_point.kts),(external Jars sep'd by semicolon)...
|
||||
# If entry_point is not given, the program will try to run <modulename>.kts.
|
||||
# if even that does not exist, an the program will quit with error.
|
||||
# and yes, you can disable basegame, but we don't recommend.
|
||||
|
||||
basegame,The base game,
|
||||
dwarventech,Dwarven technicians are emerged,
|
||||
basegame,The base game,basegame.groovy,
|
||||
dwarventech,Dwarven technicians are emerged from their hiding,,
|
||||
|
||||
|
1
assets/modules/basegame/LuaScriptTest.lua
Normal file
1
assets/modules/basegame/LuaScriptTest.lua
Normal file
@@ -0,0 +1 @@
|
||||
print "Hello, world!"
|
||||
9
assets/modules/basegame/basegame.groovy
Normal file
9
assets/modules/basegame/basegame.groovy
Normal file
@@ -0,0 +1,9 @@
|
||||
import net.torvald.terrarum.ModMgr
|
||||
|
||||
/**
|
||||
* Created by SKYHi14 on 2017-04-26.
|
||||
*/
|
||||
|
||||
static void invoke(String module) {
|
||||
ModMgr.GameItemLoader.invoke(module)
|
||||
}
|
||||
@@ -1,2 +1,2 @@
|
||||
"id";"filename"
|
||||
"8448";"testpick.lua"
|
||||
"8448";"testpick.groovy"
|
||||
|
97
assets/modules/basegame/items/testpick.groovy
Normal file
97
assets/modules/basegame/items/testpick.groovy
Normal file
@@ -0,0 +1,97 @@
|
||||
|
||||
/**
|
||||
* Created by SKYHi14 on 2017-04-26.
|
||||
*/
|
||||
|
||||
|
||||
import net.torvald.point.Point2d
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.gameactors.ActorWithPhysics
|
||||
import net.torvald.terrarum.itemproperties.Calculate
|
||||
import net.torvald.terrarum.itemproperties.InventoryItem
|
||||
import net.torvald.terrarum.itemproperties.Material
|
||||
import net.torvald.terrarum.tileproperties.Tile
|
||||
import org.jetbrains.annotations.NotNull
|
||||
import org.newdawn.slick.GameContainer
|
||||
|
||||
|
||||
|
||||
static InventoryItem invoke(int id) {
|
||||
return new TestPick(id)
|
||||
}
|
||||
|
||||
|
||||
class TestPick extends InventoryItem {
|
||||
|
||||
int originalID
|
||||
int dynamicID
|
||||
String originalName = "GROOVY_PICK"
|
||||
double baseMass = 10.0
|
||||
Double baseToolSize = 10.0
|
||||
boolean stackable = true
|
||||
int maxDurability = 147
|
||||
float durability = maxDurability
|
||||
int equipPosition = 9 //EquipPosition.HAND_GRIP
|
||||
String inventoryCategory = "tool" //Category.TOOL
|
||||
|
||||
// !! TEST MATERIAL !!
|
||||
Material material = new Material(0,0,0,0,0,0,0,0,1,0.0)
|
||||
|
||||
TestPick(int id) {
|
||||
originalID = id
|
||||
dynamicID = id
|
||||
name = "Groovy Pickaxe"
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isUnique() {
|
||||
return false
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isDynamic() {
|
||||
return true
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean primaryUse(@NotNull GameContainer gc, int delta) {
|
||||
int mouseTileX = Terrarum.getMouseTileX()
|
||||
int mouseTileY = Terrarum.getMouseTileY()
|
||||
|
||||
def mousePoint = new Point2d(mouseTileX, mouseTileY)
|
||||
def actorvalue = Terrarum.ingame.player.actorValue
|
||||
|
||||
using = true
|
||||
|
||||
// linear search filter (check for intersection with tilewise mouse point and tilewise hitbox)
|
||||
// return false if hitting actors
|
||||
Terrarum.ingame.actorContainer.forEach({
|
||||
if (it instanceof ActorWithPhysics && it.tilewiseHitbox.intersects(mousePoint))
|
||||
return false
|
||||
})
|
||||
|
||||
// return false if here's no tile
|
||||
if (Tile.AIR == Terrarum.ingame.world.getTileFromTerrain(mouseTileX, mouseTileY))
|
||||
return false
|
||||
|
||||
// filter passed, do the job
|
||||
double swingDmgToFrameDmg = delta.toDouble() / actorvalue.getAsDouble(AVKey.ACTION_INTERVAL)
|
||||
|
||||
Terrarum.ingame.world.inflictTerrainDamage(
|
||||
mouseTileX, mouseTileY,
|
||||
Calculate.pickaxePower(Terrarum.ingame.player, material) * swingDmgToFrameDmg
|
||||
)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean endPrimaryUse(@NotNull GameContainer gc, int delta) {
|
||||
using = false
|
||||
// reset action timer to zero
|
||||
Terrarum.ingame.player.actorValue.set(AVKey.__ACTION_TIMER, 0.0)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,14 @@
|
||||
"argn"; "9"; "0.91";"argentum/silver"
|
||||
"stal"; "14"; "1.73";"steel"
|
||||
"eaur"; "21"; "1.36";"elven aurichalcum"
|
||||
"tial"; "33"; "2.16";"titanium alloy"
|
||||
"tial"; "33"; "2.16";"titanium alloy (Ti6Al4V)"
|
||||
"admt"; "71"; "3.42";"adamant"
|
||||
|
||||
# idst: ID_STRING
|
||||
|
||||
# forcemod: related to attack points
|
||||
# Attack points = `4 * forcemod.sqrt()` for each strike
|
||||
|
||||
# endurance: multiplier, using copper as reference; determines durability of tools/weapons/armours/etc.
|
||||
|
||||
# Comments: do nothing; do not parse
|
||||
|
||||
|
3
assets/modules/basegame/test.groovy
Normal file
3
assets/modules/basegame/test.groovy
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
println("Hello, world!!")
|
||||
return 42
|
||||
Reference in New Issue
Block a user