mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-26 23:13:07 +00:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b42613eca8 | ||
|
|
deeb23c22d | ||
|
|
290dc4a815 | ||
|
|
9eb69cdc13 |
No files matched your search
@@ -27,4 +27,5 @@ whitelist.json
|
||||
*.iws
|
||||
src/main/resources/mixins.*.refmap.json
|
||||
*.bat
|
||||
*.sh
|
||||
layout.json
|
||||
+7
-7
@@ -1,15 +1,15 @@
|
||||
// Add your dependencies here
|
||||
|
||||
dependencies {
|
||||
implementation("com.github.GTNewHorizons:CodeChickenCore:1.4.19:dev")
|
||||
implementation("com.github.GTNewHorizons:CodeChickenCore:1.4.22:dev")
|
||||
compileOnly("com.cardinalstar.cubicchunks:CubicChunks1710:v0.1.8-alpha:dev")
|
||||
compileOnly("com.github.GTNewHorizons:Angelica:2.1.54:dev")
|
||||
runtimeOnlyNonPublishable("com.github.GTNewHorizons:Hodgepodge:2.7.174:dev")
|
||||
compileOnly("com.github.GTNewHorizons:Postea:1.2.5:dev") {transitive = false}
|
||||
devOnlyNonPublishable("com.github.GTNewHorizons:NotEnoughItems:2.8.114-GTNH:dev") {
|
||||
compileOnly("com.github.GTNewHorizons:Angelica:2.2.32:dev")
|
||||
runtimeOnlyNonPublishable("com.github.GTNewHorizons:Hodgepodge:2.7.216:dev")
|
||||
compileOnly("com.github.GTNewHorizons:Postea:1.2.7:dev") {transitive = false}
|
||||
devOnlyNonPublishable("com.github.GTNewHorizons:NotEnoughItems:2.8.160-GTNH:dev") {
|
||||
exclude group: 'com.github.GTNewHorizons', module: 'CodeChickenCore'
|
||||
}
|
||||
api("com.github.GTNewHorizons:GTNHLib:9.9.9:dev")
|
||||
// devOnlyNonPublishable("com.github.GTNewHorizons:Angelica:2.2.10:dev")
|
||||
compileOnly("com.github.GTNewHorizons:GTNHLib:0.11.54:dev")
|
||||
// devOnlyNonPublishable("com.github.GTNewHorizons:Angelica:2.2.32:dev")
|
||||
devOnlyNonPublishable("io.github.legacymoddingmc:unimixins:0.1.23:dev")
|
||||
}
|
||||
@@ -186,6 +186,11 @@ modrinthRelations =
|
||||
# Leave this empty if you don't want to publish on CurseForge.
|
||||
curseForgeProjectId =
|
||||
|
||||
# Comma-separated supported CurseForge environments: client, server (case-insensitive).
|
||||
# Use client or server for mods that only support one environment. Defaults to client,server.
|
||||
# These tags describe where the mod can run, not whether installation is required on both sides.
|
||||
curseForgeEnvironments = client,server
|
||||
|
||||
# The project's relations on CurseForge. You can use this to refer to other projects on CurseForge.
|
||||
# Syntax: type1:name1;type2:name2;...
|
||||
# Where type can be one of [requiredDependency, embeddedLibrary, optionalDependency, tool, incompatible],
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#This file is generated by updateDaemonJvm
|
||||
toolchainUrl.FREE_BSD.AARCH64=https\://api.foojay.io/disco/v3.0/ids/1630f7ebef05444cb27a2709ea0249b3/redirect
|
||||
toolchainUrl.FREE_BSD.X86_64=https\://api.foojay.io/disco/v3.0/ids/fa1e318c287360478e3c83a9a3ef1007/redirect
|
||||
toolchainUrl.LINUX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/1630f7ebef05444cb27a2709ea0249b3/redirect
|
||||
toolchainUrl.LINUX.X86_64=https\://api.foojay.io/disco/v3.0/ids/fa1e318c287360478e3c83a9a3ef1007/redirect
|
||||
toolchainUrl.MAC_OS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/c2dd35c9d0aaf0ba6ad0791320f99dfc/redirect
|
||||
toolchainUrl.MAC_OS.X86_64=https\://api.foojay.io/disco/v3.0/ids/e5810bd7fd1f8a586644409d395a7e55/redirect
|
||||
toolchainUrl.UNIX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/1630f7ebef05444cb27a2709ea0249b3/redirect
|
||||
toolchainUrl.UNIX.X86_64=https\://api.foojay.io/disco/v3.0/ids/fa1e318c287360478e3c83a9a3ef1007/redirect
|
||||
toolchainUrl.WINDOWS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/7b3c4877c0749019e6805bb61e421497/redirect
|
||||
toolchainUrl.WINDOWS.X86_64=https\://api.foojay.io/disco/v3.0/ids/8e1d9ee5d0f13e442218f6884a306da1/redirect
|
||||
toolchainUrl.FREE_BSD.AARCH64=https\://api.foojay.io/disco/v3.0/ids/539ea72837c6244075f8ee037babc29e/redirect
|
||||
toolchainUrl.FREE_BSD.X86_64=https\://api.foojay.io/disco/v3.0/ids/876dbbf00bf4ef6190f7da074cee903a/redirect
|
||||
toolchainUrl.LINUX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/539ea72837c6244075f8ee037babc29e/redirect
|
||||
toolchainUrl.LINUX.X86_64=https\://api.foojay.io/disco/v3.0/ids/876dbbf00bf4ef6190f7da074cee903a/redirect
|
||||
toolchainUrl.MAC_OS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/9064f22734b42ac03e85df04b632e167/redirect
|
||||
toolchainUrl.MAC_OS.X86_64=https\://api.foojay.io/disco/v3.0/ids/4d0277c49991306ac78048580fe34bcf/redirect
|
||||
toolchainUrl.UNIX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/539ea72837c6244075f8ee037babc29e/redirect
|
||||
toolchainUrl.UNIX.X86_64=https\://api.foojay.io/disco/v3.0/ids/876dbbf00bf4ef6190f7da074cee903a/redirect
|
||||
toolchainUrl.WINDOWS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/a9fa3b809e484a1e1ac4308a5dda661a/redirect
|
||||
toolchainUrl.WINDOWS.X86_64=https\://api.foojay.io/disco/v3.0/ids/aa99913fa6d767d899ffc96082da01ca/redirect
|
||||
toolchainVersion=25
|
||||
Vendored
BIN
Binary file not shown.
+3
-1
@@ -1,7 +1,9 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.0-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.7.1-bin.zip
|
||||
networkTimeout=10000
|
||||
retries=0
|
||||
retryBackOffMs=500
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
# gradlew start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
@@ -29,7 +29,7 @@
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
# ksh gradlew
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
@@ -57,7 +57,7 @@
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/b631911858264c0b6e4d6603d677ff5218766cee/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
|
||||
Vendored
+12
-23
@@ -19,12 +19,12 @@
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem gradlew startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
@rem Set local scope for the variables, and ensure extensions are enabled
|
||||
setlocal EnableExtensions
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@@ -51,7 +51,7 @@ echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
"%COMSPEC%" /c exit 1
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
@@ -65,29 +65,18 @@ echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
"%COMSPEC%" /c exit 1
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||
@rem Execute gradlew
|
||||
@rem endlocal doesn't take effect until after the line is parsed and variables are expanded
|
||||
@rem which allows us to clear the local environment before executing the java command
|
||||
endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
:exitWithErrorLevel
|
||||
@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts
|
||||
"%COMSPEC%" /c exit %ERRORLEVEL%
|
||||
+1
-1
@@ -17,5 +17,5 @@ pluginManagement {
|
||||
}
|
||||
|
||||
plugins {
|
||||
id 'com.gtnewhorizons.gtnhsettingsconvention' version '2.0.24'
|
||||
id 'com.gtnewhorizons.gtnhsettingsconvention' version '2.0.34'
|
||||
}
|
||||
@@ -199,7 +199,7 @@ object MicroRecipe extends IRecipe {
|
||||
def findMaterial(item: ItemStack): Int =
|
||||
MicroMaterialRegistry.getIdMap.find { m =>
|
||||
val mitem = m._2.getItem
|
||||
item.getItem == mitem.getItem &&
|
||||
m._2 != MissingMicroMaterial && item.getItem == mitem.getItem &&
|
||||
item.getItemDamage == mitem.getItemDamage &&
|
||||
ItemStack.areItemStackTagsEqual(item, mitem)
|
||||
} match {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package codechicken.microblock.handler
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent
|
||||
import cpw.mods.fml.common.eventhandler.{EventPriority, SubscribeEvent}
|
||||
import cpw.mods.fml.relauncher.SideOnly
|
||||
import cpw.mods.fml.relauncher.Side
|
||||
import net.minecraftforge.client.event.TextureStitchEvent
|
||||
@@ -14,7 +14,7 @@ import cpw.mods.fml.common.LoaderState
|
||||
import net.minecraft.util.MovingObjectPosition.MovingObjectType
|
||||
|
||||
object MicroblockEventHandler {
|
||||
@SubscribeEvent
|
||||
@SubscribeEvent(priority = EventPriority.LOW)
|
||||
@SideOnly(Side.CLIENT)
|
||||
def postTextureStitch(event: TextureStitchEvent.Post) {
|
||||
if (event.map.getTextureType == 0)
|
||||
|
||||
@@ -81,12 +81,14 @@ object MultipartGenerator extends ScratchBitSet {
|
||||
pos: BlockCoord,
|
||||
part: TMultiPart
|
||||
): TileMultipart = {
|
||||
val (tile, converted) = TileMultipart.getOrConvertTile2(world, pos)
|
||||
val (tile, converted) =
|
||||
if (world.isRemote) (TileMultipart.getTile(world, pos), false)
|
||||
else TileMultipart.getOrConvertTile2(world, pos)
|
||||
val bitset = setTraits(part, world.isRemote)
|
||||
|
||||
var ntile = tile
|
||||
if (ntile != null) {
|
||||
if (converted) { // perform client conversion
|
||||
if (converted) { // server-side conversion, then tell the clients
|
||||
ntile.partList(0).invalidateConvertedTile()
|
||||
world.setBlock(pos.x, pos.y, pos.z, MultipartProxy.block, 0, 0)
|
||||
silentAddTile(world, pos, ntile)
|
||||
|
||||
@@ -2,14 +2,19 @@ package codechicken.multipart.handler
|
||||
|
||||
import codechicken.multipart.{BlockMultipart, TileCache, TileMultipart}
|
||||
import cpw.mods.fml.common.eventhandler.{EventPriority, SubscribeEvent}
|
||||
import cpw.mods.fml.common.gameevent.{PlayerEvent, TickEvent}
|
||||
import cpw.mods.fml.common.gameevent.TickEvent
|
||||
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||
import net.minecraft.entity.player.EntityPlayerMP
|
||||
import net.minecraft.server.MinecraftServer
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import net.minecraft.util.MovingObjectPosition.MovingObjectType
|
||||
import net.minecraft.world.ChunkPosition
|
||||
import net.minecraftforge.client.event.DrawBlockHighlightEvent
|
||||
import net.minecraftforge.event.world._
|
||||
|
||||
import java.util.List
|
||||
import scala.collection.JavaConverters._
|
||||
|
||||
object MultipartEventHandler {
|
||||
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||
def tileEntityLoad(event: ChunkDataEvent.Load) {
|
||||
@@ -65,19 +70,13 @@ object MultipartEventHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
def playerLogout(event: PlayerEvent.PlayerLoggedOutEvent) {
|
||||
MultipartSPH.onPlayerLogout(event.player)
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
def playerChangedDimension(event: PlayerEvent.PlayerChangedDimensionEvent) {
|
||||
MultipartSPH.onPlayerChangedDimension(event.player, event.fromDim)
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
def serverTick(event: TickEvent.ServerTickEvent) {
|
||||
if (event.phase == TickEvent.Phase.END)
|
||||
MultipartSPH.onTickEnd()
|
||||
MultipartSPH.onTickEnd(
|
||||
MinecraftServer.getServer.getConfigurationManager.playerEntityList
|
||||
.asInstanceOf[List[EntityPlayerMP]]
|
||||
.asScala
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -24,9 +24,8 @@ import java.io.DataOutputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
import net.minecraft.world.ChunkCoordIntPair
|
||||
import MultipartProxy._
|
||||
import com.gtnewhorizon.gtnhlib.api.world.WorldContextRegistry
|
||||
import com.gtnewhorizon.gtnhlib.api.world.WorldContextRegistry.WorldAddress
|
||||
import codechicken.multipart.PacketScheduler
|
||||
import java.util.LinkedList
|
||||
import scala.collection.JavaConversions._
|
||||
import net.minecraft.network.play.{INetHandlerPlayServer, INetHandlerPlayClient}
|
||||
import net.minecraft.network.play.server.S40PacketDisconnect
|
||||
@@ -36,22 +35,6 @@ import net.minecraft.network.NetHandlerPlayServer
|
||||
class MultipartPH {
|
||||
val channel = MultipartMod
|
||||
val registryChannel = "ForgeMultipart"
|
||||
|
||||
/** Writes the address of a world into the ForgeMultipart payload. */
|
||||
def writeWorld(packet: PacketCustom, world: World): PacketCustom = {
|
||||
val address = WorldContextRegistry.addressOf(world)
|
||||
packet.writeInt(address.hostDimensionId)
|
||||
packet.writeInt(address.subId)
|
||||
packet.writeString(address.namespace)
|
||||
packet
|
||||
}
|
||||
|
||||
def readWorldAddress(packet: PacketCustom): WorldAddress = {
|
||||
val hostDimensionId = packet.readInt
|
||||
val subId = packet.readInt
|
||||
val namespace = packet.readString()
|
||||
new WorldAddress(hostDimensionId, namespace, subId)
|
||||
}
|
||||
}
|
||||
|
||||
object MultipartCPH extends MultipartPH with IClientPacketHandler {
|
||||
@@ -63,16 +46,8 @@ object MultipartCPH extends MultipartPH with IClientPacketHandler {
|
||||
try {
|
||||
packet.getType match {
|
||||
case 1 => handlePartRegistration(packet, netHandler)
|
||||
case 2 =>
|
||||
handleCompressedTileDesc(
|
||||
packet,
|
||||
WorldContextRegistry.getClientWorld(readWorldAddress(packet))
|
||||
)
|
||||
case 3 =>
|
||||
handleCompressedTileData(
|
||||
packet,
|
||||
WorldContextRegistry.getClientWorld(readWorldAddress(packet))
|
||||
)
|
||||
case 2 => handleCompressedTileDesc(packet, mc.theWorld)
|
||||
case 3 => handleCompressedTileData(packet, mc.theWorld)
|
||||
}
|
||||
} catch {
|
||||
case e: RuntimeException
|
||||
@@ -141,20 +116,12 @@ object MultipartSPH
|
||||
|
||||
private val updateMap = Map[World, Map[BlockCoord, MCByteStream]]()
|
||||
|
||||
private type WatchMap = HashMap[EntityPlayerMP, Set[ChunkCoordIntPair]]
|
||||
with MultiMap[EntityPlayerMP, ChunkCoordIntPair]
|
||||
|
||||
private def newWatchMap: WatchMap =
|
||||
new HashMap[EntityPlayerMP, Set[ChunkCoordIntPair]]
|
||||
with MultiMap[EntityPlayerMP, ChunkCoordIntPair]
|
||||
|
||||
/** Watches are separated by world first, because a chunk coordinate only
|
||||
* means something inside one world, and the same player may watch chunks in
|
||||
* a host world and in virtual worlds inside it. The world is recorded when
|
||||
* the watch happens and never re-derived from the player afterwards.
|
||||
/** These maps are keyed by entityID so that new player instances with the
|
||||
* same entity id don't conflict world references
|
||||
*/
|
||||
private val chunkWatchers = Map[World, WatchMap]()
|
||||
private val newWatchers = Map[World, WatchMap]()
|
||||
private val chunkWatchers = new HashMap[Int, Set[ChunkCoordIntPair]]
|
||||
with MultiMap[Int, ChunkCoordIntPair]
|
||||
private val newWatchers = Map[Int, LinkedList[ChunkCoordIntPair]]()
|
||||
|
||||
def handlePacket(
|
||||
packet: PacketCustom,
|
||||
@@ -173,11 +140,8 @@ object MultipartSPH
|
||||
}
|
||||
|
||||
def onWorldUnload(world: World) {
|
||||
if (!world.isRemote) {
|
||||
if (!world.isRemote)
|
||||
updateMap.remove(world)
|
||||
chunkWatchers.remove(world)
|
||||
newWatchers.remove(world)
|
||||
}
|
||||
}
|
||||
|
||||
def getTileStream(world: World, pos: BlockCoord) =
|
||||
@@ -199,144 +163,58 @@ object MultipartSPH
|
||||
}
|
||||
)
|
||||
|
||||
def onTickEnd() {
|
||||
def onTickEnd(players: Seq[EntityPlayerMP]) {
|
||||
PacketScheduler.sendScheduled()
|
||||
|
||||
for ((world, m) <- updateMap if !m.isEmpty) {
|
||||
if (chunkWatchers.contains(world))
|
||||
sendUpdates(
|
||||
world,
|
||||
m,
|
||||
world,
|
||||
pos => new ChunkCoordIntPair(pos.x >> 4, pos.z >> 4)
|
||||
)
|
||||
else
|
||||
// The world is not watched directly, it is embedded in a host world.
|
||||
sendUpdates(
|
||||
world,
|
||||
m,
|
||||
WorldContextRegistry.getHostWorld(world),
|
||||
pos =>
|
||||
WorldContextRegistry.getHostChunk(
|
||||
world,
|
||||
new ChunkCoordIntPair(pos.x >> 4, pos.z >> 4)
|
||||
)
|
||||
)
|
||||
for (p <- players if chunkWatchers.containsKey(p.getEntityId)) {
|
||||
updateMap.get(p.worldObj) match {
|
||||
case Some(m) if !m.isEmpty =>
|
||||
val chunks = chunkWatchers(p.getEntityId)
|
||||
val packet = new PacketCustom(channel, 3).compress()
|
||||
var send = false
|
||||
for (
|
||||
(pos, stream) <- m
|
||||
if chunks(new ChunkCoordIntPair(pos.x >> 4, pos.z >> 4))
|
||||
) {
|
||||
send = true
|
||||
packet.writeByteArray(stream.getBytes)
|
||||
packet.writeByte(255) // terminator
|
||||
}
|
||||
if (send) {
|
||||
packet.writeInt(Int.MaxValue) // terminator
|
||||
packet.sendToPlayer(p)
|
||||
}
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
updateMap.foreach(_._2.clear())
|
||||
|
||||
for (
|
||||
(world, watchers) <- newWatchers;
|
||||
(p, chunks) <- watchers;
|
||||
c <- chunks
|
||||
) {
|
||||
sendDescription(world, p, c)
|
||||
chunkWatchers.getOrElseUpdate(world, newWatchMap).addBinding(p, c)
|
||||
// Chunks embedded in this one become visible with it.
|
||||
for (
|
||||
(subWorld, subChunks) <- WorldContextRegistry
|
||||
.getVisibleChunks(world, c);
|
||||
sc <- subChunks
|
||||
) sendDescription(subWorld, p, sc)
|
||||
for (p <- players if newWatchers.containsKey(p.getEntityId)) {
|
||||
for (c <- newWatchers(p.getEntityId)) {
|
||||
val chunk = p.worldObj.getChunkFromChunkCoords(c.chunkXPos, c.chunkZPos)
|
||||
val pkt = getDescPacket(
|
||||
chunk,
|
||||
chunk.chunkTileEntityMap
|
||||
.asInstanceOf[JMap[_, TileEntity]]
|
||||
.values
|
||||
.iterator
|
||||
)
|
||||
if (pkt != null) pkt.sendToPlayer(p)
|
||||
chunkWatchers.addBinding(p.getEntityId, c)
|
||||
}
|
||||
}
|
||||
newWatchers.clear()
|
||||
}
|
||||
|
||||
private def sendUpdates(
|
||||
world: World,
|
||||
updates: Map[BlockCoord, MCByteStream],
|
||||
watchWorld: World,
|
||||
hostChunk: BlockCoord => ChunkCoordIntPair
|
||||
) {
|
||||
for (
|
||||
watchers <- chunkWatchers.get(watchWorld);
|
||||
(p, chunks) <- watchers
|
||||
) {
|
||||
val packet = writeWorld(new PacketCustom(channel, 3).compress(), world)
|
||||
var send = false
|
||||
for ((pos, stream) <- updates) {
|
||||
val c = hostChunk(pos)
|
||||
if (c != null && chunks(c)) {
|
||||
send = true
|
||||
packet.writeByteArray(stream.getBytes)
|
||||
packet.writeByte(255) // terminator
|
||||
}
|
||||
}
|
||||
if (send) {
|
||||
packet.writeInt(Int.MaxValue) // terminator
|
||||
packet.sendToPlayer(p)
|
||||
}
|
||||
def onChunkWatch(p: EntityPlayer, c: ChunkCoordIntPair) {
|
||||
newWatchers.getOrElseUpdate(p.getEntityId, new LinkedList).add(c)
|
||||
}
|
||||
|
||||
def onChunkUnWatch(p: EntityPlayer, c: ChunkCoordIntPair) {
|
||||
newWatchers.get(p.getEntityId) match {
|
||||
case Some(chunks) => chunks.remove(c)
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
|
||||
private def sendDescription(
|
||||
world: World,
|
||||
p: EntityPlayerMP,
|
||||
c: ChunkCoordIntPair
|
||||
) {
|
||||
val chunk = world.getChunkFromChunkCoords(c.chunkXPos, c.chunkZPos)
|
||||
val pkt = getDescPacket(
|
||||
chunk,
|
||||
chunk.chunkTileEntityMap
|
||||
.asInstanceOf[JMap[_, TileEntity]]
|
||||
.values
|
||||
.iterator
|
||||
)
|
||||
if (pkt != null) pkt.sendToPlayer(p)
|
||||
}
|
||||
|
||||
def onChunkWatch(p: EntityPlayerMP, c: ChunkCoordIntPair) {
|
||||
val hostPlayer = WorldContextRegistry.getHostPlayer(p.worldObj, p)
|
||||
newWatchers
|
||||
.getOrElseUpdate(p.worldObj, newWatchMap)
|
||||
.addBinding(hostPlayer, c)
|
||||
}
|
||||
|
||||
def onChunkUnWatch(p: EntityPlayerMP, c: ChunkCoordIntPair) {
|
||||
val hostPlayer = WorldContextRegistry.getHostPlayer(p.worldObj, p)
|
||||
removeBinding(newWatchers, p.worldObj, hostPlayer, c)
|
||||
removeBinding(chunkWatchers, p.worldObj, hostPlayer, c)
|
||||
}
|
||||
|
||||
private def removeBinding(
|
||||
map: Map[World, WatchMap],
|
||||
world: World,
|
||||
p: EntityPlayerMP,
|
||||
c: ChunkCoordIntPair
|
||||
) {
|
||||
map.get(world) match {
|
||||
case Some(watchers) =>
|
||||
watchers.removeBinding(p, c)
|
||||
if (watchers.isEmpty) map.remove(world)
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
def onPlayerLogout(p: EntityPlayer) = p match {
|
||||
case mp: EntityPlayerMP =>
|
||||
for (map <- Seq(chunkWatchers, newWatchers)) {
|
||||
for ((world, watchers) <- map.toSeq) {
|
||||
watchers.remove(mp)
|
||||
if (watchers.isEmpty) map.remove(world)
|
||||
}
|
||||
}
|
||||
case _ =>
|
||||
}
|
||||
|
||||
def onPlayerChangedDimension(p: EntityPlayer, fromDimension: Int) = p match {
|
||||
case mp: EntityPlayerMP =>
|
||||
for (map <- Seq(chunkWatchers, newWatchers)) {
|
||||
for (
|
||||
(world, watchers) <- map.toSeq
|
||||
if WorldContextRegistry
|
||||
.getHostWorld(world)
|
||||
.provider
|
||||
.dimensionId == fromDimension
|
||||
) {
|
||||
watchers.remove(mp)
|
||||
if (watchers.isEmpty) map.remove(world)
|
||||
}
|
||||
}
|
||||
case _ =>
|
||||
chunkWatchers.removeBinding(p.getEntityId, c)
|
||||
}
|
||||
|
||||
def getDescPacket(chunk: Chunk, it: Iterator[TileEntity]): PacketCustom = {
|
||||
@@ -354,7 +232,8 @@ object MultipartSPH
|
||||
}
|
||||
}
|
||||
if (num != 0) {
|
||||
return writeWorld(new PacketCustom(channel, 2).compress(), chunk.worldObj)
|
||||
return new PacketCustom(channel, 2)
|
||||
.compress()
|
||||
.writeInt(chunk.xPosition)
|
||||
.writeInt(chunk.zPosition)
|
||||
.writeShort(num)
|
||||
|
||||
Reference in new issue
Block a user