mirror of
https://github.com/GTNewHorizons/ForgeRelocation.git
synced 2026-11-12 16:37:30 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
21da7aae0e | ||
|
|
eacf6f7dd7 |
No files matched your search
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
dependencies {
|
dependencies {
|
||||||
api('com.github.GTNewHorizons:CodeChickenCore:1.4.3:dev')
|
api('com.github.GTNewHorizons:CodeChickenCore:1.4.17:dev')
|
||||||
api 'com.github.GTNewHorizons:MrTJPCore:1.3.6:dev'
|
api 'com.github.GTNewHorizons:MrTJPCore:1.3.7:dev'
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
#This file is generated by updateDaemonJvm
|
#This file is generated by updateDaemonJvm
|
||||||
toolchainUrl.FREE_BSD.AARCH64=https\://api.foojay.io/disco/v3.0/ids/1630f7ebef05444cb27a2709ea0249b3/redirect
|
toolchainUrl.FREE_BSD.AARCH64=https\://api.foojay.io/disco/v3.0/ids/97d46b5ff4df0bf61e95652a190a5567/redirect
|
||||||
toolchainUrl.FREE_BSD.X86_64=https\://api.foojay.io/disco/v3.0/ids/fa1e318c287360478e3c83a9a3ef1007/redirect
|
toolchainUrl.FREE_BSD.X86_64=https\://api.foojay.io/disco/v3.0/ids/9ef54a08e06b0754cee9fc95ed3a3134/redirect
|
||||||
toolchainUrl.LINUX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/1630f7ebef05444cb27a2709ea0249b3/redirect
|
toolchainUrl.LINUX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/97d46b5ff4df0bf61e95652a190a5567/redirect
|
||||||
toolchainUrl.LINUX.X86_64=https\://api.foojay.io/disco/v3.0/ids/fa1e318c287360478e3c83a9a3ef1007/redirect
|
toolchainUrl.LINUX.X86_64=https\://api.foojay.io/disco/v3.0/ids/9ef54a08e06b0754cee9fc95ed3a3134/redirect
|
||||||
toolchainUrl.MAC_OS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/c2dd35c9d0aaf0ba6ad0791320f99dfc/redirect
|
toolchainUrl.MAC_OS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/1df82b76031285ef2e6a4f59ffe9299d/redirect
|
||||||
toolchainUrl.MAC_OS.X86_64=https\://api.foojay.io/disco/v3.0/ids/e5810bd7fd1f8a586644409d395a7e55/redirect
|
toolchainUrl.MAC_OS.X86_64=https\://api.foojay.io/disco/v3.0/ids/c7d5be6a02945ac2e045048ee54a7d32/redirect
|
||||||
toolchainUrl.UNIX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/1630f7ebef05444cb27a2709ea0249b3/redirect
|
toolchainUrl.UNIX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/97d46b5ff4df0bf61e95652a190a5567/redirect
|
||||||
toolchainUrl.UNIX.X86_64=https\://api.foojay.io/disco/v3.0/ids/fa1e318c287360478e3c83a9a3ef1007/redirect
|
toolchainUrl.UNIX.X86_64=https\://api.foojay.io/disco/v3.0/ids/9ef54a08e06b0754cee9fc95ed3a3134/redirect
|
||||||
toolchainUrl.WINDOWS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/7b3c4877c0749019e6805bb61e421497/redirect
|
toolchainUrl.WINDOWS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/643f404f769811f5f265fd66f7af5d89/redirect
|
||||||
toolchainUrl.WINDOWS.X86_64=https\://api.foojay.io/disco/v3.0/ids/8e1d9ee5d0f13e442218f6884a306da1/redirect
|
toolchainUrl.WINDOWS.X86_64=https\://api.foojay.io/disco/v3.0/ids/38256085a73e137cb4937ea9c4807fec/redirect
|
||||||
toolchainVersion=25
|
toolchainVersion=25
|
||||||
+1
-1
@@ -17,7 +17,7 @@ pluginManagement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id 'com.gtnewhorizons.gtnhsettingsconvention' version '2.0.24'
|
id 'com.gtnewhorizons.gtnhsettingsconvention' version '2.0.27'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -17,7 +17,6 @@ import net.minecraft.client.Minecraft
|
|||||||
import net.minecraft.init.Blocks
|
import net.minecraft.init.Blocks
|
||||||
import net.minecraft.world.{ChunkCoordIntPair, World}
|
import net.minecraft.world.{ChunkCoordIntPair, World}
|
||||||
import net.minecraftforge.common.DimensionManager
|
import net.minecraftforge.common.DimensionManager
|
||||||
import scala.collection.concurrent.TrieMap
|
|
||||||
import scala.collection.mutable.{
|
import scala.collection.mutable.{
|
||||||
HashMap => MHashMap,
|
HashMap => MHashMap,
|
||||||
MultiMap => MMultiMap,
|
MultiMap => MMultiMap,
|
||||||
@@ -27,15 +26,14 @@ import scala.collection.mutable.{
|
|||||||
import scala.ref.WeakReference
|
import scala.ref.WeakReference
|
||||||
|
|
||||||
object MovementManager2 {
|
object MovementManager2 {
|
||||||
val serverRelocations = MHashMap[Int, WorldStructs]()
|
val serverRelocations = new WorldStructsMap
|
||||||
val clientRelocations = TrieMap[Int, WorldStructs]()
|
val clientRelocations = new WorldStructsMap
|
||||||
|
|
||||||
def relocationMap(isClient: Boolean) =
|
def relocationMap(isClient: Boolean) =
|
||||||
if (isClient) clientRelocations else serverRelocations
|
if (isClient) clientRelocations else serverRelocations
|
||||||
|
|
||||||
def getWorldStructs(w: World) =
|
def getWorldStructs(w: World) =
|
||||||
relocationMap(w.isRemote)
|
relocationMap(w.isRemote).getOrCreate(w.provider.dimensionId)
|
||||||
.getOrElseUpdate(w.provider.dimensionId, new WorldStructs)
|
|
||||||
|
|
||||||
def getWorld(dim: Int, isClient: Boolean) =
|
def getWorld(dim: Int, isClient: Boolean) =
|
||||||
if (!isClient) DimensionManager.getWorld(dim)
|
if (!isClient) DimensionManager.getWorld(dim)
|
||||||
@@ -135,7 +133,7 @@ object MovementManager2 {
|
|||||||
map.addBinding(MathLib.normal(b, moveDir), MathLib.basis(b, moveDir))
|
map.addBinding(MathLib.normal(b, moveDir), MathLib.basis(b, moveDir))
|
||||||
|
|
||||||
val shift = if ((moveDir & 1) == 1) 1 else -1
|
val shift = if ((moveDir & 1) == 1) 1 else -1
|
||||||
val rowB = Set.newBuilder[BlockRow]
|
val rowB = Array.newBuilder[BlockRow]
|
||||||
for (normal <- map.keys) {
|
for (normal <- map.keys) {
|
||||||
val line = map(normal).toArray
|
val line = map(normal).toArray
|
||||||
val sline =
|
val sline =
|
||||||
@@ -167,24 +165,26 @@ object MovementManager2 {
|
|||||||
|
|
||||||
def onTick(isClient: Boolean) {
|
def onTick(isClient: Boolean) {
|
||||||
val map = relocationMap(isClient)
|
val map = relocationMap(isClient)
|
||||||
for ((dim, ws) <- map) if (ws.nonEmpty) {
|
map.foreach { (dim, ws) =>
|
||||||
ws.pushAll()
|
if (ws.nonEmpty) {
|
||||||
val world = getWorld(dim, isClient)
|
ws.pushAll()
|
||||||
if (world != null)
|
val world = getWorld(dim, isClient)
|
||||||
for (bs <- ws.structs)
|
if (world != null)
|
||||||
for (br <- bs.rows)
|
for (bs <- ws.structs)
|
||||||
br.pushEntities(world, bs.progress)
|
for (br <- bs.rows)
|
||||||
|
br.pushEntities(world, bs.progress)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isClient) {
|
if (!isClient) {
|
||||||
val fin = map
|
map.foreach { (dim, ws) =>
|
||||||
.map(pair => (pair._1, pair._2.removeFinished()))
|
val finished = ws.removeFinished()
|
||||||
.filter(_._2.nonEmpty)
|
if (finished.nonEmpty) {
|
||||||
for ((dim, b) <- fin) {
|
val w = getWorld(dim, false)
|
||||||
val w = getWorld(dim, false)
|
if (w != null) for (s <- finished) {
|
||||||
if (w != null) for (s <- b) {
|
cycleMove(w, s)
|
||||||
cycleMove(w, s)
|
sendCycle(w, s)
|
||||||
sendCycle(w, s)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -221,33 +221,171 @@ object MovementManager2 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class WorldStructsMap {
|
||||||
|
private var dims = new Array[Int](4)
|
||||||
|
private var structs = new Array[WorldStructs](4)
|
||||||
|
private var size = 0
|
||||||
|
|
||||||
|
def getOrCreate(dim: Int): WorldStructs = synchronized {
|
||||||
|
var i = 0
|
||||||
|
while (i < size) {
|
||||||
|
if (dims(i) == dim) return structs(i)
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
val ws = new WorldStructs
|
||||||
|
if (size == dims.length) {
|
||||||
|
val nd = new Array[Int](dims.length * 2)
|
||||||
|
val ns = new Array[WorldStructs](dims.length * 2)
|
||||||
|
System.arraycopy(dims, 0, nd, 0, size)
|
||||||
|
System.arraycopy(structs, 0, ns, 0, size)
|
||||||
|
dims = nd
|
||||||
|
structs = ns
|
||||||
|
}
|
||||||
|
dims(size) = dim
|
||||||
|
structs(size) = ws
|
||||||
|
size += 1
|
||||||
|
ws
|
||||||
|
}
|
||||||
|
|
||||||
|
def foreach(f: (Int, WorldStructs) => Unit) {
|
||||||
|
val n = synchronized { size }
|
||||||
|
val ds = new Array[Int](n)
|
||||||
|
val ss = new Array[WorldStructs](n)
|
||||||
|
synchronized {
|
||||||
|
System.arraycopy(dims, 0, ds, 0, n)
|
||||||
|
System.arraycopy(structs, 0, ss, 0, n)
|
||||||
|
}
|
||||||
|
var i = 0
|
||||||
|
while (i < n) {
|
||||||
|
f(ds(i), ss(i))
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class WorldStructs {
|
class WorldStructs {
|
||||||
var structs: Set[BlockStruct] = Set.empty
|
private val noStructs = new Array[BlockStruct](0)
|
||||||
|
private var structsArr = new Array[BlockStruct](4)
|
||||||
|
private var numStructs = 0
|
||||||
|
|
||||||
def isEmpty = structs.isEmpty
|
def isEmpty = synchronized { numStructs == 0 }
|
||||||
|
|
||||||
def nonEmpty = !isEmpty
|
def nonEmpty = synchronized { numStructs > 0 }
|
||||||
|
|
||||||
def contains(x: Int, y: Int, z: Int) = structs.exists(_.contains(x, y, z))
|
def contains(x: Int, y: Int, z: Int): Boolean = synchronized {
|
||||||
|
var i = 0
|
||||||
|
while (i < numStructs) {
|
||||||
|
if (structsArr(i).contains(x, y, z)) return true
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
def addStruct(b: BlockStruct) { structs += b }
|
def addStruct(b: BlockStruct): Unit = synchronized {
|
||||||
|
var i = 0
|
||||||
|
while (i < numStructs) {
|
||||||
|
if (structsArr(i).id == b.id) return
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
if (numStructs == structsArr.length) {
|
||||||
|
val ns = new Array[BlockStruct](structsArr.length * 2)
|
||||||
|
System.arraycopy(structsArr, 0, ns, 0, numStructs)
|
||||||
|
structsArr = ns
|
||||||
|
}
|
||||||
|
structsArr(numStructs) = b
|
||||||
|
numStructs += 1
|
||||||
|
}
|
||||||
|
|
||||||
def pushAll() { structs.foreach(_.push()) }
|
def pushAll() = synchronized {
|
||||||
|
var i = 0
|
||||||
|
while (i < numStructs) {
|
||||||
|
structsArr(i).push()
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def removeFinished() = {
|
def removeFinished(): Array[BlockStruct] = synchronized {
|
||||||
val finished = structs.filter(_.isFinished)
|
var nf = 0
|
||||||
structs = structs.filterNot(_.isFinished)
|
var i = 0
|
||||||
|
while (i < numStructs) {
|
||||||
|
if (structsArr(i).isFinished) nf += 1
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nf == 0) return noStructs
|
||||||
|
|
||||||
|
val finished = new Array[BlockStruct](nf)
|
||||||
|
var finish = 0
|
||||||
|
var keep = 0
|
||||||
|
i = 0
|
||||||
|
while (i < numStructs) {
|
||||||
|
val s = structsArr(i)
|
||||||
|
if (s.isFinished) {
|
||||||
|
finished(finish) = s
|
||||||
|
finish += 1
|
||||||
|
} else {
|
||||||
|
structsArr(keep) = s
|
||||||
|
keep += 1
|
||||||
|
}
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
var j = keep
|
||||||
|
while (j < numStructs) {
|
||||||
|
structsArr(j) = null
|
||||||
|
j += 1
|
||||||
|
}
|
||||||
|
numStructs = keep
|
||||||
finished
|
finished
|
||||||
}
|
}
|
||||||
|
|
||||||
def removeStruct(s: BlockStruct) {
|
def removeStruct(s: BlockStruct) = synchronized {
|
||||||
structs = structs.filterNot(_ == s)
|
var keep = 0
|
||||||
|
var i = 0
|
||||||
|
while (i < numStructs) {
|
||||||
|
val cur = structsArr(i)
|
||||||
|
if (cur != s) {
|
||||||
|
structsArr(keep) = cur
|
||||||
|
keep += 1
|
||||||
|
}
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
var j = keep
|
||||||
|
while (j < numStructs) {
|
||||||
|
structsArr(j) = null
|
||||||
|
j += 1
|
||||||
|
}
|
||||||
|
numStructs = keep
|
||||||
}
|
}
|
||||||
|
|
||||||
def clear() { structs = Set.empty }
|
def clear() = synchronized {
|
||||||
|
var i = 0
|
||||||
|
while (i < numStructs) {
|
||||||
|
structsArr(i) = null
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
numStructs = 0
|
||||||
|
}
|
||||||
|
|
||||||
def getChunks: Set[ChunkCoordIntPair] = {
|
def foreachStruct(f: BlockStruct => Unit) = synchronized {
|
||||||
structs.flatMap(_.getChunks)
|
var i = 0
|
||||||
|
while (i < numStructs) {
|
||||||
|
f(structsArr(i))
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def structs: Array[BlockStruct] = synchronized {
|
||||||
|
java.util.Arrays.copyOf(structsArr, numStructs)
|
||||||
|
}
|
||||||
|
|
||||||
|
def getChunks: Set[ChunkCoordIntPair] = synchronized {
|
||||||
|
val c = Set.newBuilder[ChunkCoordIntPair]
|
||||||
|
var i = 0
|
||||||
|
while (i < numStructs) {
|
||||||
|
c ++= structsArr(i).getChunks
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
c.result()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,18 +421,27 @@ class MoveDesc(b: WeakReference[BlockStruct]) extends IMovementDescriptor {
|
|||||||
class BlockStruct {
|
class BlockStruct {
|
||||||
var id = -1
|
var id = -1
|
||||||
var speed = 1 / 16d
|
var speed = 1 / 16d
|
||||||
var rows: Set[BlockRow] = Set.empty
|
var rows: Array[BlockRow] = Array.empty
|
||||||
var callback = WeakReference[IMovementCallback](null)
|
var callback = WeakReference[IMovementCallback](null)
|
||||||
|
|
||||||
var progress = 0.0d
|
var progress = 0.0d
|
||||||
|
|
||||||
lazy val allBlocks = rows.flatMap(_.allBlocks)
|
lazy val allBlocks: Set[BlockCoord] = rows.iterator.flatMap(_.allBlocks).toSet
|
||||||
lazy val preMoveBlocks = rows.flatMap(_.preMoveBlocks)
|
lazy val preMoveBlocks: Set[BlockCoord] =
|
||||||
lazy val postMoveBlocks = rows.flatMap(_.postMoveBlocks)
|
rows.iterator.flatMap(_.preMoveBlocks).toSet
|
||||||
|
lazy val postMoveBlocks: Set[BlockCoord] =
|
||||||
|
rows.iterator.flatMap(_.postMoveBlocks).toSet
|
||||||
|
|
||||||
def moveDir = rows.head.moveDir
|
def moveDir = rows(0).moveDir
|
||||||
|
|
||||||
def contains(x: Int, y: Int, z: Int) = rows.exists(_.contains(x, y, z))
|
def contains(x: Int, y: Int, z: Int): Boolean = {
|
||||||
|
var i = 0
|
||||||
|
while (i < rows.length) {
|
||||||
|
if (rows(i).contains(x, y, z)) return true
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
def push() { progress = math.min(1.0, progress + speed) }
|
def push() { progress = math.min(1.0, progress + speed) }
|
||||||
|
|
||||||
@@ -337,10 +484,12 @@ class BlockStruct {
|
|||||||
case _ => false
|
case _ => false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override def hashCode() = id
|
||||||
|
|
||||||
def writeDesc(out: MCDataOutput) {
|
def writeDesc(out: MCDataOutput) {
|
||||||
out.writeFloat(progress.toFloat)
|
out.writeFloat(progress.toFloat)
|
||||||
out.writeFloat(speed.toFloat)
|
out.writeFloat(speed.toFloat)
|
||||||
out.writeByte(rows.size)
|
out.writeByte(rows.length)
|
||||||
for (r <- rows) {
|
for (r <- rows) {
|
||||||
out.writeLong(WorldLib.packCoords(r.pos))
|
out.writeLong(WorldLib.packCoords(r.pos))
|
||||||
out.writeByte(r.moveDir)
|
out.writeByte(r.moveDir)
|
||||||
@@ -351,7 +500,7 @@ class BlockStruct {
|
|||||||
def readDesc(in: MCDataInput) {
|
def readDesc(in: MCDataInput) {
|
||||||
progress = in.readFloat()
|
progress = in.readFloat()
|
||||||
speed = in.readFloat()
|
speed = in.readFloat()
|
||||||
val rb = Set.newBuilder[BlockRow]
|
val rb = Array.newBuilder[BlockRow]
|
||||||
for (i <- 0 until in.readUByte())
|
for (i <- 0 until in.readUByte())
|
||||||
rb += new BlockRow(
|
rb += new BlockRow(
|
||||||
WorldLib.unpackCoords(in.readLong()),
|
WorldLib.unpackCoords(in.readLong()),
|
||||||
@@ -370,12 +519,11 @@ class BlockRow(val pos: BlockCoord, val moveDir: Int, val size: Int) {
|
|||||||
def contains(x: Int, y: Int, z: Int) = {
|
def contains(x: Int, y: Int, z: Int) = {
|
||||||
import MathLib.{basis, normal, shift}
|
import MathLib.{basis, normal, shift}
|
||||||
|
|
||||||
import math.{max, min}
|
|
||||||
|
|
||||||
if (normal(x, y, z, moveDir) == normal(pos, moveDir)) {
|
if (normal(x, y, z, moveDir) == normal(pos, moveDir)) {
|
||||||
val b1 = basis(pos, moveDir)
|
val b1 = basis(pos, moveDir)
|
||||||
val b2 = b1 + size * shift(moveDir ^ 1)
|
val b2 = b1 + size * shift(moveDir ^ 1)
|
||||||
min(b1, b2) to max(b1, b2) contains basis(x, y, z, moveDir)
|
val b = basis(x, y, z, moveDir)
|
||||||
|
b >= math.min(b1, b2) && b <= math.max(b1, b2)
|
||||||
} else false
|
} else false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,11 @@ object MovingRenderer {
|
|||||||
private var frame = 0.0f
|
private var frame = 0.0f
|
||||||
private var renderBlocks: RenderBlocks = null
|
private var renderBlocks: RenderBlocks = null
|
||||||
|
|
||||||
|
private val renderStruct: BlockStruct => Unit = { s =>
|
||||||
|
for (b <- s.preMoveBlocks)
|
||||||
|
render(b.x, b.y, b.z, renderPos(s, frame))
|
||||||
|
}
|
||||||
|
|
||||||
private def mc = Minecraft.getMinecraft
|
private def mc = Minecraft.getMinecraft
|
||||||
private def world = mc.theWorld
|
private def world = mc.theWorld
|
||||||
|
|
||||||
@@ -101,9 +106,7 @@ object MovingRenderer {
|
|||||||
renderBlocks.renderAllFaces = true
|
renderBlocks.renderAllFaces = true
|
||||||
}
|
}
|
||||||
|
|
||||||
for (s <- MovementManager2.getWorldStructs(world).structs)
|
MovementManager2.getWorldStructs(world).foreachStruct(renderStruct)
|
||||||
for (b <- s.preMoveBlocks)
|
|
||||||
render(b.x, b.y, b.z, renderPos(s, frame))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def onTick() = {
|
def onTick() = {
|
||||||
|
|||||||
Reference in new issue
Block a user