Compare commits

...
12 Commits
20 changed files with 544 additions and 118 deletions

No files matched your search

+1 -1
View File
@@ -25,6 +25,6 @@ whitelist.json
*.iml *.iml
*.ipr *.ipr
*.iws *.iws
src/main/resources/mixins.*.json src/main/resources/mixins.*.refmap.json
*.bat *.bat
layout.json layout.json
+8 -3
View File
@@ -1,10 +1,15 @@
// Add your dependencies here // Add your dependencies here
dependencies { dependencies {
implementation("com.github.GTNewHorizons:CodeChickenCore:1.4.12:dev") implementation("com.github.GTNewHorizons:CodeChickenCore:1.4.19:dev")
compileOnly("com.github.GTNewHorizons:Angelica:2.1.19: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} compileOnly("com.github.GTNewHorizons:Postea:1.2.5:dev") {transitive = false}
devOnlyNonPublishable("com.github.GTNewHorizons:NotEnoughItems:2.8.93-GTNH:dev") { devOnlyNonPublishable("com.github.GTNewHorizons:NotEnoughItems:2.8.114-GTNH:dev") {
exclude group: 'com.github.GTNewHorizons', module: 'CodeChickenCore' 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")
devOnlyNonPublishable("io.github.legacymoddingmc:unimixins:0.1.23:dev")
} }
+5 -5
View File
@@ -107,15 +107,15 @@ apiPackage =
accessTransformersFile = multipart_at.cfg accessTransformersFile = multipart_at.cfg
# Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled! # Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled!
usesMixins = false usesMixins = true
# Set to a non-empty string to configure mixins in a separate source set under src/VALUE, instead of src/main. # Set to a non-empty string to configure mixins in a separate source set under src/VALUE, instead of src/main.
# This can speed up compile times thanks to not running the mixin annotation processor on all input sources. # This can speed up compile times thanks to not running the mixin annotation processor on all input sources.
# Mixin classes will have access to "main" classes, but not the other way around. # Mixin classes will have access to "main" classes, but not the other way around.
separateMixinSourceSet = separateMixinSourceSet = mixin
# Adds some debug arguments like verbose output and class export. # Adds some debug arguments like verbose output and class export.
usesMixinDebug = false usesMixinDebug = true
# Specify the location of your implementation of IMixinConfigPlugin. Leave it empty otherwise. # Specify the location of your implementation of IMixinConfigPlugin. Leave it empty otherwise.
mixinPlugin = mixinPlugin =
@@ -123,12 +123,12 @@ mixinPlugin =
# Specify the package that contains all of your Mixins. The package must exist or # Specify the package that contains all of your Mixins. The package must exist or
# the build will fail. If you have a package property defined in your mixins.<modid>.json, # the build will fail. If you have a package property defined in your mixins.<modid>.json,
# it must match with this or the build will fail. # it must match with this or the build will fail.
mixinsPackage = mixinsPackage = multipart.mixin
# Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin! # Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin!
# This parameter is for legacy compatibility only # This parameter is for legacy compatibility only
# Example value: (coreModClass = asm.FMLPlugin) + (modGroup = com.myname.mymodid) -> com.myname.mymodid.asm.FMLPlugin # Example value: (coreModClass = asm.FMLPlugin) + (modGroup = com.myname.mymodid) -> com.myname.mymodid.asm.FMLPlugin
coreModClass = coreModClass = multipart.mixin.FMPMixinLoader
# If your project is only a consolidation of mixins or a core mod and does NOT contain a 'normal' mod ( = some class # If your project is only a consolidation of mixins or a core mod and does NOT contain a 'normal' mod ( = some class
# that is annotated with @Mod) you want this to be true. When in doubt: leave it on false! # that is annotated with @Mod) you want this to be true. When in doubt: leave it on false!
+1
View File
@@ -1,4 +1,5 @@
// Add any additional repositiroes for your dependencies here // Add any additional repositiroes for your dependencies here
repositories { repositories {
mavenLocal()
} }
@@ -0,0 +1,47 @@
package codechicken.multipart.mixin;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.gtnewhorizon.gtnhmixins.IEarlyMixinLoader;
import com.gtnewhorizon.gtnhmixins.builders.IMixins;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
@IFMLLoadingPlugin.MCVersion("1.7.10")
public class FMPMixinLoader implements IFMLLoadingPlugin, IEarlyMixinLoader {
@Override
public String[] getASMTransformerClass() {
return null;
}
@Override
public String getModContainerClass() {
return null;
}
@Override
public String getSetupClass() {
return null;
}
@Override
public void injectData(Map<String, Object> data) {}
@Override
public String getAccessTransformerClass() {
return null;
}
@Override
public String getMixinConfig() {
return "mixins.ForgeMultipart.early.json";
}
@Override
public List<String> getMixins(Set<String> loadedCoreMods) {
return IMixins.getEarlyMixins(Mixins.class, loadedCoreMods);
}
}
@@ -0,0 +1,24 @@
package codechicken.multipart.mixin;
import javax.annotation.Nonnull;
import com.gtnewhorizon.gtnhmixins.builders.IMixins;
import com.gtnewhorizon.gtnhmixins.builders.MixinBuilder;
public enum Mixins implements IMixins {
RENDER_GLOBAL_MIXIN(new MixinBuilder("Redirects part block break renders to ISBRHModel")
.addClientMixins("MixinRenderGlobal").addRequiredMod(TargetedMod.GTNHLIB).setPhase(Phase.EARLY));
private final MixinBuilder builder;
Mixins(MixinBuilder builder) {
this.builder = builder;
}
@Nonnull
@Override
public MixinBuilder getBuilder() {
return this.builder;
}
}
@@ -0,0 +1,31 @@
package codechicken.multipart.mixin;
import javax.annotation.Nonnull;
import com.gtnewhorizon.gtnhmixins.builders.ITargetMod;
import com.gtnewhorizon.gtnhmixins.builders.TargetModBuilder;
public enum TargetedMod implements ITargetMod {
GTNHLIB("GTNHLib Core", "gtnhlib");
private final TargetModBuilder builder;
TargetedMod(String modId) {
this(null, modId, null);
}
TargetedMod(String coreModClass, String modId) {
this(coreModClass, modId, null);
}
TargetedMod(String coreModClass, String modId, String targetClass) {
this.builder = new TargetModBuilder().setCoreModClass(coreModClass).setModId(modId).setTargetClass(targetClass);
}
@Nonnull
@Override
public TargetModBuilder getBuilder() {
return builder;
}
}
@@ -0,0 +1,11 @@
{
"required": true,
"minVersion": "0.8.5-GTNH",
"package": "codechicken.multipart.mixin.early",
"refmap": "mixins.ForgeMultipart.refmap.json",
"target": "@env(DEFAULT)",
"mixinextras": {
"minVersion": "0.5.0"
},
"compatibilityLevel": "JAVA_8"
}
@@ -0,0 +1,7 @@
{
"required": true,
"minVersion": "0.8.5-GTNH",
"refmap": "mixins.ForgeMultipart.refmap.json",
"target": "@env(DEFAULT)",
"compatibilityLevel": "JAVA_8"
}
@@ -0,0 +1,18 @@
package codechicken.multipart;
import net.minecraft.block.Block;
import net.minecraft.world.IBlockAccess;
public interface JsonModeledPart {
Block getBlock();
/**
* Use to give your part a world that can be used to define properties for rendering. For example having your world
* returning your block with some specific state such as meta you can override the getMeta for the input location to
* be the meta you desire
*
* @return The world to use
*/
IBlockAccess getRenderWorld();
}
@@ -122,9 +122,14 @@ object MultipartGenerator extends ScratchBitSet {
* adding it to the tick list * adding it to the tick list
*/ */
def silentAddTile(world: World, pos: BlockCoord, tile: TileEntity) { def silentAddTile(world: World, pos: BlockCoord, tile: TileEntity) {
tile.xCoord = pos.x;
tile.yCoord = pos.y;
tile.zCoord = pos.z;
val chunk = world.getChunkFromBlockCoords(pos.x, pos.z) val chunk = world.getChunkFromBlockCoords(pos.x, pos.z)
if (chunk != null) if (chunk != null) {
chunk.func_150812_a(pos.x & 15, pos.y, pos.z & 15, tile) chunk.addTileEntity(tile)
}
} }
/** Check if tile satisfies all the interfaces required by parts. If not, /** Check if tile satisfies all the interfaces required by parts. If not,
@@ -5,18 +5,14 @@ import codechicken.lib.vec.Vector3
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler
import cpw.mods.fml.client.registry.RenderingRegistry import cpw.mods.fml.client.registry.RenderingRegistry
import net.minecraft.block.Block import net.minecraft.block.Block
import net.minecraft.client.renderer.{Tessellator, RenderBlocks} import net.minecraft.client.renderer.{RenderBlocks, Tessellator}
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer
import net.minecraft.tileentity.TileEntity import net.minecraft.tileentity.TileEntity
import net.minecraft.world.IBlockAccess import net.minecraft.world.IBlockAccess
import net.minecraft.client.Minecraft
import net.minecraftforge.client.ForgeHooksClient
import net.minecraftforge.client.MinecraftForgeClient import net.minecraftforge.client.MinecraftForgeClient
import cpw.mods.fml.relauncher.SideOnly import cpw.mods.fml.relauncher.SideOnly
import cpw.mods.fml.relauncher.Side import cpw.mods.fml.relauncher.Side
import codechicken.lib.raytracer.ExtendedMOP import codechicken.multipart.RenderPartResolver
import codechicken.lib.lighting.LightMatrix
import com.gtnewhorizons.angelica.api.ThreadSafeISBRH
/** Internal class for rendering callbacks. Should be moved to the handler /** Internal class for rendering callbacks. Should be moved to the handler
* package * package
@@ -67,19 +63,15 @@ object MultipartRenderer
return false return false
if (renderer.hasOverrideBlockTexture) { if (renderer.hasOverrideBlockTexture) {
val hit = Minecraft.getMinecraft.objectMouseOver val part =
if ( RenderPartResolver.resolve(world, x, y, z)
hit != null && hit.blockX == x && hit.blockY == y && hit.blockZ == z && ExtendedMOP if (part != null) {
.getData(hit) part match {
.isInstanceOf[(_, _)] case isbrh: ISBRHPart =>
) { isbrh.renderWorldBlock(world, x, y, z, renderer)
val hitInfo: (Int, _) = ExtendedMOP.getData(hit) case _ =>
if ( part.drawBreaking(renderer)
hitInfo._1.isInstanceOf[ }
Int
] && hitInfo._1 >= 0 && hitInfo._1 < tmpart.partList.size
)
tmpart.partList(hitInfo._1).drawBreaking(renderer)
} }
return false return false
} }
@@ -0,0 +1,59 @@
package codechicken.multipart;
import net.minecraft.client.Minecraft;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.IBlockAccess;
import codechicken.lib.raytracer.ExtendedMOP;
import scala.Tuple2;
/**
* A helper class for resolving parts so we don't do a double look up
*/
public final class RenderPartResolver {
public static TMultiPart resolve(IBlockAccess world, int x, int y, int z) {
if (world == null) {
return null;
}
// Make sure the hit is actually this block.
MovingObjectPosition hit = Minecraft.getMinecraft().objectMouseOver;
if (hit == null || hit.blockX != x || hit.blockY != y || hit.blockZ != z) {
return null;
}
Object data = ExtendedMOP.getData(hit);
if (!(data instanceof Tuple2)) {
return null;
}
Tuple2<?, ?> hitInfo = (Tuple2<?, ?>) data;
Object indexObject = hitInfo._1();
if (!(indexObject instanceof Integer)) {
return null;
}
int index = (Integer) indexObject;
TileMultipartClient tile = getMultipartTile(world, x, y, z);
if (tile == null) {
return null;
}
// Needed because scala is stupid and the client tile doesn't expose what we need.
TileMultipart multipart = (TileMultipart) tile;
if (index < 0 || index >= multipart.jPartList().size()) {
return null;
}
return multipart.jPartList().get(index);
}
private static TileMultipartClient getMultipartTile(IBlockAccess world, int x, int y, int z) {
if (world.getTileEntity(x, y, z) instanceof TileMultipartClient) {
return (TileMultipartClient) world.getTileEntity(x, y, z);
}
return null;
}
}
@@ -30,7 +30,7 @@ import net.minecraft.util.{AxisAlignedBB, Vec3}
import java.lang.Iterable import java.lang.Iterable
import codechicken.lib.world.IChunkLoadTile import codechicken.lib.world.IChunkLoadTile
import net.minecraft.block.Block import com.gtnewhorizon.gtnhlib.client.model.ModelISBRH
import net.minecraft.client.renderer.RenderBlocks import net.minecraft.client.renderer.RenderBlocks
import net.minecraftforge.client.ForgeHooksClient import net.minecraftforge.client.ForgeHooksClient
@@ -78,7 +78,8 @@ class TileMultipart extends TileEntity with IChunkLoadTile {
val it = partList.iterator val it = partList.iterator
while (it.hasNext) { while (it.hasNext) {
val p = it.next() val p = it.next()
if (p.tile != null) f(p) // A replaced tile can still receive queued callbacks after its parts have moved.
if (p.tile == this) f(p)
} }
} }
@@ -534,6 +535,22 @@ trait TileMultipartClient extends TileMultipart {
return return
part match { part match {
case jsonModeledPart: JsonModeledPart =>
if (
ModelISBRH.INSTANCE
.get()
.renderWorldBlock(
jsonModeledPart.getRenderWorld,
vec.x.toInt,
vec.y.toInt,
vec.z.toInt,
jsonModeledPart.getBlock,
ModelISBRH.JSON_ISBRH_ID,
renderer
)
) {
rendered = true
}
case isbrh: ISBRHPart => case isbrh: ISBRHPart =>
if ( if (
isbrh.renderWorldBlock( isbrh.renderWorldBlock(
@@ -0,0 +1,18 @@
package codechicken.multipart.handler
import com.cardinalstar.cubicchunks.api.event.CubeEvent
import cpw.mods.fml.common.eventhandler.{EventPriority, SubscribeEvent}
import net.minecraftforge.common.MinecraftForge
import scala.collection.JavaConversions._
object CubicChunksCompat {
def init(): Unit = MinecraftForge.EVENT_BUS.register(this)
@SubscribeEvent(priority = EventPriority.HIGHEST)
def onTileEntitiesLoad(event: CubeEvent.DataLoad): Unit = {
val cube = event.cube
val world = event.world
MultipartSaveLoad.loadTiles(world, cube.cubeTileEntityMap)
}
}
@@ -1,30 +1,23 @@
package codechicken.multipart.handler package codechicken.multipart.handler
import codechicken.multipart.{ import codechicken.multipart.{BlockMultipart, TileCache, TileMultipart}
TileCache,
TileMultipart,
MultiPartRegistry,
BlockMultipart
}
import cpw.mods.fml.common.eventhandler.{EventPriority, SubscribeEvent} import cpw.mods.fml.common.eventhandler.{EventPriority, SubscribeEvent}
import net.minecraft.server.MinecraftServer import cpw.mods.fml.common.gameevent.{PlayerEvent, TickEvent}
import codechicken.lib.packet.PacketCustom import cpw.mods.fml.relauncher.{Side, SideOnly}
import net.minecraftforge.event.world._ import net.minecraft.tileentity.TileEntity
import java.util.EnumSet
import scala.collection.JavaConverters._
import java.util.List
import net.minecraft.entity.player.EntityPlayerMP
import cpw.mods.fml.relauncher.SideOnly
import cpw.mods.fml.relauncher.Side
import net.minecraftforge.client.event.DrawBlockHighlightEvent
import net.minecraft.util.MovingObjectPosition
import net.minecraft.util.MovingObjectPosition.MovingObjectType import net.minecraft.util.MovingObjectPosition.MovingObjectType
import cpw.mods.fml.common.gameevent.TickEvent import net.minecraft.world.ChunkPosition
import net.minecraftforge.client.event.DrawBlockHighlightEvent
import net.minecraftforge.event.world._
object MultipartEventHandler { object MultipartEventHandler {
@SubscribeEvent(priority = EventPriority.HIGHEST) @SubscribeEvent(priority = EventPriority.HIGHEST)
def tileEntityLoad(event: ChunkDataEvent.Load) { def tileEntityLoad(event: ChunkDataEvent.Load) {
MultipartSaveLoad.loadTiles(event.getChunk) MultipartSaveLoad.loadTiles(
event.getChunk.worldObj,
event.getChunk.chunkTileEntityMap
.asInstanceOf[java.util.Map[ChunkPosition, TileEntity]]
)
} }
@SubscribeEvent @SubscribeEvent
@@ -72,13 +65,19 @@ 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 @SubscribeEvent
def serverTick(event: TickEvent.ServerTickEvent) { def serverTick(event: TickEvent.ServerTickEvent) {
if (event.phase == TickEvent.Phase.END) if (event.phase == TickEvent.Phase.END)
MultipartSPH.onTickEnd( MultipartSPH.onTickEnd()
MinecraftServer.getServer.getConfigurationManager.playerEntityList
.asInstanceOf[List[EntityPlayerMP]]
.asScala
)
} }
} }
@@ -2,14 +2,16 @@ package codechicken.multipart.handler
import net.minecraft.tileentity.TileEntity import net.minecraft.tileentity.TileEntity
import net.minecraft.nbt.NBTTagCompound import net.minecraft.nbt.NBTTagCompound
import java.util.Map import java.util.Map
import net.minecraft.world.chunk.Chunk
import net.minecraft.world.ChunkPosition import net.minecraft.world.ChunkPosition
import codechicken.multipart.{MultipartHelper, TileMultipart} import codechicken.multipart.{MultipartHelper, TileMultipart}
import codechicken.lib.asm.ObfMapping import codechicken.lib.asm.ObfMapping
import net.minecraft.world.World import net.minecraft.world.World
import scala.collection.mutable import scala.collection.mutable
import codechicken.multipart.MultipartHelper.IPartTileConverter import codechicken.multipart.MultipartHelper.IPartTileConverter
import scala.collection.JavaConversions._ import scala.collection.JavaConversions._
/** Hack due to lack of TileEntityLoadEvent in forge /** Hack due to lack of TileEntityLoadEvent in forge
@@ -58,12 +60,9 @@ object MultipartSaveLoad {
field.get(null).asInstanceOf[Map[Class[_ <: TileEntity], String]] field.get(null).asInstanceOf[Map[Class[_ <: TileEntity], String]]
} }
def loadTiles(chunk: Chunk) { def loadTiles(world: World, tiles: Map[ChunkPosition, TileEntity]) {
loadingWorld = chunk.worldObj loadingWorld = world
val iterator = chunk.chunkTileEntityMap val iterator = tiles.entrySet.iterator
.asInstanceOf[Map[ChunkPosition, TileEntity]]
.entrySet
.iterator
while (iterator.hasNext) { while (iterator.hasNext) {
val e = iterator.next val e = iterator.next
var next = false var next = false
@@ -88,7 +87,7 @@ object MultipartSaveLoad {
if (!next) { if (!next) {
if (t != null) { if (t != null) {
t.setWorldObj(e.getValue.getWorldObj) t.setWorldObj(world)
t.validate() t.validate()
e.setValue(t) e.setValue(t)
} else } else
@@ -24,8 +24,9 @@ import java.io.DataOutputStream
import java.io.ByteArrayOutputStream import java.io.ByteArrayOutputStream
import net.minecraft.world.ChunkCoordIntPair import net.minecraft.world.ChunkCoordIntPair
import MultipartProxy._ import MultipartProxy._
import com.gtnewhorizon.gtnhlib.api.world.WorldContextRegistry
import com.gtnewhorizon.gtnhlib.api.world.WorldContextRegistry.WorldAddress
import codechicken.multipart.PacketScheduler import codechicken.multipart.PacketScheduler
import java.util.LinkedList
import scala.collection.JavaConversions._ import scala.collection.JavaConversions._
import net.minecraft.network.play.{INetHandlerPlayServer, INetHandlerPlayClient} import net.minecraft.network.play.{INetHandlerPlayServer, INetHandlerPlayClient}
import net.minecraft.network.play.server.S40PacketDisconnect import net.minecraft.network.play.server.S40PacketDisconnect
@@ -35,6 +36,22 @@ import net.minecraft.network.NetHandlerPlayServer
class MultipartPH { class MultipartPH {
val channel = MultipartMod val channel = MultipartMod
val registryChannel = "ForgeMultipart" 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 { object MultipartCPH extends MultipartPH with IClientPacketHandler {
@@ -46,8 +63,16 @@ object MultipartCPH extends MultipartPH with IClientPacketHandler {
try { try {
packet.getType match { packet.getType match {
case 1 => handlePartRegistration(packet, netHandler) case 1 => handlePartRegistration(packet, netHandler)
case 2 => handleCompressedTileDesc(packet, mc.theWorld) case 2 =>
case 3 => handleCompressedTileData(packet, mc.theWorld) handleCompressedTileDesc(
packet,
WorldContextRegistry.getClientWorld(readWorldAddress(packet))
)
case 3 =>
handleCompressedTileData(
packet,
WorldContextRegistry.getClientWorld(readWorldAddress(packet))
)
} }
} catch { } catch {
case e: RuntimeException case e: RuntimeException
@@ -116,12 +141,20 @@ object MultipartSPH
private val updateMap = Map[World, Map[BlockCoord, MCByteStream]]() private val updateMap = Map[World, Map[BlockCoord, MCByteStream]]()
/** These maps are keyed by entityID so that new player instances with the private type WatchMap = HashMap[EntityPlayerMP, Set[ChunkCoordIntPair]]
* same entity id don't conflict world references 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.
*/ */
private val chunkWatchers = new HashMap[Int, Set[ChunkCoordIntPair]] private val chunkWatchers = Map[World, WatchMap]()
with MultiMap[Int, ChunkCoordIntPair] private val newWatchers = Map[World, WatchMap]()
private val newWatchers = Map[Int, LinkedList[ChunkCoordIntPair]]()
def handlePacket( def handlePacket(
packet: PacketCustom, packet: PacketCustom,
@@ -140,8 +173,11 @@ object MultipartSPH
} }
def onWorldUnload(world: World) { def onWorldUnload(world: World) {
if (!world.isRemote) if (!world.isRemote) {
updateMap.remove(world) updateMap.remove(world)
chunkWatchers.remove(world)
newWatchers.remove(world)
}
} }
def getTileStream(world: World, pos: BlockCoord) = def getTileStream(world: World, pos: BlockCoord) =
@@ -163,58 +199,144 @@ object MultipartSPH
} }
) )
def onTickEnd(players: Seq[EntityPlayerMP]) { def onTickEnd() {
PacketScheduler.sendScheduled() PacketScheduler.sendScheduled()
for (p <- players if chunkWatchers.containsKey(p.getEntityId)) { for ((world, m) <- updateMap if !m.isEmpty) {
updateMap.get(p.worldObj) match { if (chunkWatchers.contains(world))
case Some(m) if !m.isEmpty => sendUpdates(
val chunks = chunkWatchers(p.getEntityId) world,
val packet = new PacketCustom(channel, 3).compress() m,
var send = false world,
for ( pos => new ChunkCoordIntPair(pos.x >> 4, pos.z >> 4)
(pos, stream) <- m )
if chunks(new ChunkCoordIntPair(pos.x >> 4, pos.z >> 4)) else
) { // The world is not watched directly, it is embedded in a host world.
send = true sendUpdates(
packet.writeByteArray(stream.getBytes) world,
packet.writeByte(255) // terminator m,
} WorldContextRegistry.getHostWorld(world),
if (send) { pos =>
packet.writeInt(Int.MaxValue) // terminator WorldContextRegistry.getHostChunk(
packet.sendToPlayer(p) world,
} new ChunkCoordIntPair(pos.x >> 4, pos.z >> 4)
case _ => )
} )
} }
updateMap.foreach(_._2.clear()) updateMap.foreach(_._2.clear())
for (p <- players if newWatchers.containsKey(p.getEntityId)) {
for (c <- newWatchers(p.getEntityId)) { for (
val chunk = p.worldObj.getChunkFromChunkCoords(c.chunkXPos, c.chunkZPos) (world, watchers) <- newWatchers;
val pkt = getDescPacket( (p, chunks) <- watchers;
chunk, c <- chunks
chunk.chunkTileEntityMap ) {
.asInstanceOf[JMap[_, TileEntity]] sendDescription(world, p, c)
.values chunkWatchers.getOrElseUpdate(world, newWatchMap).addBinding(p, c)
.iterator // Chunks embedded in this one become visible with it.
) for (
if (pkt != null) pkt.sendToPlayer(p) (subWorld, subChunks) <- WorldContextRegistry
chunkWatchers.addBinding(p.getEntityId, c) .getVisibleChunks(world, c);
} sc <- subChunks
) sendDescription(subWorld, p, sc)
} }
newWatchers.clear() newWatchers.clear()
} }
def onChunkWatch(p: EntityPlayer, c: ChunkCoordIntPair) { private def sendUpdates(
newWatchers.getOrElseUpdate(p.getEntityId, new LinkedList).add(c) 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 onChunkUnWatch(p: EntityPlayer, c: ChunkCoordIntPair) { private def sendDescription(
newWatchers.get(p.getEntityId) match { world: World,
case Some(chunks) => chunks.remove(c) p: EntityPlayerMP,
case _ => 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 _ =>
} }
chunkWatchers.removeBinding(p.getEntityId, c) }
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 _ =>
} }
def getDescPacket(chunk: Chunk, it: Iterator[TileEntity]): PacketCustom = { def getDescPacket(chunk: Chunk, it: Iterator[TileEntity]): PacketCustom = {
@@ -232,8 +354,7 @@ object MultipartSPH
} }
} }
if (num != 0) { if (num != 0) {
return new PacketCustom(channel, 2) return writeWorld(new PacketCustom(channel, 2).compress(), chunk.worldObj)
.compress()
.writeInt(chunk.xPosition) .writeInt(chunk.xPosition)
.writeInt(chunk.zPosition) .writeInt(chunk.zPosition)
.writeShort(num) .writeShort(num)
@@ -13,7 +13,7 @@ import codechicken.lib.packet.PacketCustom
import net.minecraft.world.ChunkCoordIntPair import net.minecraft.world.ChunkCoordIntPair
import codechicken.lib.vec.BlockCoord import codechicken.lib.vec.BlockCoord
import codechicken.lib.world.{TileChunkLoadHook, WorldExtensionManager} import codechicken.lib.world.{TileChunkLoadHook, WorldExtensionManager}
import cpw.mods.fml.common.FMLCommonHandler import cpw.mods.fml.common.{FMLCommonHandler, Loader}
import cpw.mods.fml.common.registry.GameRegistry import cpw.mods.fml.common.registry.GameRegistry
import net.minecraft.block.Block import net.minecraft.block.Block
import org.apache.logging.log4j.Logger import org.apache.logging.log4j.Logger
@@ -29,7 +29,7 @@ class MultipartProxy_serverImpl {
.setComment("Multipart API config file") .setComment("Multipart API config file")
GameRegistry.registerBlock( GameRegistry.registerBlock(
new BlockMultipart().setBlockName("multipart"), new BlockMultipart().setBlockName("codechicken/multipart"),
null, null,
"block" "block"
) )
@@ -90,6 +90,8 @@ class MultipartProxy_serverImpl {
TileChunkLoadHook.init() TileChunkLoadHook.init()
MultipartCompatiblity.load() MultipartCompatiblity.load()
if (Loader.isModLoaded("cubicchunks"))
CubicChunksCompat.init()
} }
def onTileClassBuilt(t: Class[_ <: TileEntity]) { def onTileClassBuilt(t: Class[_ <: TileEntity]) {
@@ -0,0 +1,70 @@
package codechicken.multipart.mixin.early;
import net.minecraft.block.Block;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.RenderGlobal;
import net.minecraft.util.IIcon;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import com.gtnewhorizon.gtnhlib.client.model.ModelISBRH;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import codechicken.multipart.JsonModeledPart;
import codechicken.multipart.RenderPartResolver;
import codechicken.multipart.TMultiPart;
@Mixin(RenderGlobal.class)
public class MixinRenderGlobal {
@Shadow
private WorldClient theWorld;
@Redirect(
method = "drawBlockDamageTexture(Lnet/minecraft/client/renderer/Tessellator;Lnet/minecraft/entity/EntityLivingBase;F)V",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/multiplayer/WorldClient;getBlock(III)Lnet/minecraft/block/Block;"))
private Block forgemultipart$redirectDamageBlock(WorldClient world, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
TMultiPart part = RenderPartResolver.resolve(world, x, y, z);
if (part instanceof JsonModeledPart) {
return ((JsonModeledPart) part).getBlock();
}
return block;
}
@WrapOperation(
method = "drawBlockDamageTexture(Lnet/minecraft/client/renderer/Tessellator;Lnet/minecraft/entity/EntityLivingBase;F)V",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/renderer/RenderBlocks;renderBlockUsingTexture(Lnet/minecraft/block/Block;IIILnet/minecraft/util/IIcon;)V"))
private void forgemultipart$redirectBreakingModeledPartDraw(RenderBlocks instance, Block block, int x, int y, int z,
IIcon overrideTexture, Operation<Void> original) {
TMultiPart candidatePart = RenderPartResolver.resolve(theWorld, x, y, z);
if (candidatePart instanceof JsonModeledPart) {
JsonModeledPart part = (JsonModeledPart) candidatePart;
instance.setOverrideBlockTexture(overrideTexture);
try {
ModelISBRH.INSTANCE.get().renderWorldBlock(
part.getRenderWorld(),
x,
y,
z,
part.getBlock(),
ModelISBRH.JSON_ISBRH_ID,
instance);
} finally {
instance.clearOverrideBlockTexture();
}
} else {
original.call(instance, block, x, y, z, overrideTexture);
}
}
}