Compare commits

..
4 Commits
9 changed files with 99 additions and 20 deletions

No files matched your search

@@ -54,5 +54,7 @@ object DefaultContent {
registerMaterial(new GrassMicroMaterial, materialKey(grass)) registerMaterial(new GrassMicroMaterial, materialKey(grass))
MicroMaterialRegistry.remapName(oldKey(mycelium), materialKey(mycelium)) MicroMaterialRegistry.remapName(oldKey(mycelium), materialKey(mycelium))
registerMaterial(new TopMicroMaterial(mycelium), materialKey(mycelium)) registerMaterial(new TopMicroMaterial(mycelium), materialKey(mycelium))
registerMaterial(MissingMicroMaterial, MissingMicroMaterial.key)
} }
} }
@@ -133,15 +133,18 @@ object ItemMicroPart {
if (!stack.getTagCompound.hasKey("mat")) if (!stack.getTagCompound.hasKey("mat"))
return null return null
return MicroMaterialRegistry.getMaterial( MicroMaterialRegistry.getMaterial(
stack.getTagCompound.getString("mat") stack.getTagCompound.getString("mat")
) ) match {
case null => MissingMicroMaterial
case mat => mat
}
} }
def getMaterialID(stack: ItemStack): Int = { def getMaterialID(stack: ItemStack): Int = {
checkTagCompound(stack) checkTagCompound(stack)
if (!stack.getTagCompound.hasKey("mat")) if (!stack.getTagCompound.hasKey("mat"))
return 0 return MicroMaterialRegistry.getMissingId
return MicroMaterialRegistry.materialID( return MicroMaterialRegistry.materialID(
stack.getTagCompound.getString("mat") stack.getTagCompound.getString("mat")
@@ -114,6 +114,7 @@ object MicroMaterialRegistry {
private var maxCuttingStrength: Int = _ private var maxCuttingStrength: Int = _
private val remap = HashMap[String, String]() private val remap = HashMap[String, String]()
private var missingId: Int = 0
/** Register a micro material with unique identifier name /** Register a micro material with unique identifier name
*/ */
@@ -162,8 +163,17 @@ object MicroMaterialRegistry {
nameMap.clear() nameMap.clear()
for (i <- 0 until idMap.length) for (i <- 0 until idMap.length)
nameMap.put(idMap(i)._1, i) nameMap.put(idMap(i)._1, i)
missingId = nameMap.getOrElse(
MissingMicroMaterial.key,
throw new IllegalStateException(
"MissingMicroMaterial is not registered; the placeholder must never " +
"fall back to id 0."
)
)
} }
def getMissingId = missingId
private[microblock] def calcMaxCuttingStrength() { private[microblock] def calcMaxCuttingStrength() {
val it = Item.itemRegistry.iterator.asInstanceOf[JIterator[Item]] val it = Item.itemRegistry.iterator.asInstanceOf[JIterator[Item]]
maxCuttingStrength = it.flatMap { maxCuttingStrength = it.flatMap {
@@ -216,7 +226,7 @@ object MicroMaterialRegistry {
case Some(v) => v case Some(v) => v
case None => case None =>
logger.error("Missing mapping for part with ID: " + name) logger.error("Missing mapping for part with ID: " + name)
0 missingId
} }
def getMaterial(name: String) = def getMaterial(name: String) =
@@ -0,0 +1,55 @@
package codechicken.microblock
import codechicken.lib.render.uv.IconTransformation
import codechicken.lib.vec.{Cuboid6, Vector3}
import codechicken.microblock.MicroMaterialRegistry.IMicroMaterial
import codechicken.microblock.handler.MicroblockProxy
import cpw.mods.fml.relauncher.{Side, SideOnly}
import net.minecraft.block.Block
import net.minecraft.block.Block.SoundType
import net.minecraft.entity.Entity
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.init.Blocks
import net.minecraft.item.ItemStack
import net.minecraft.util.IIcon
/** Stand-in for a material whose name could not be resolved at load time.
* Renders the vanilla missing texture (magenta/black checkerboard) and behaves
* inertly. Resolving an unknown name to this placeholder keeps microblocks
* from silently becoming material id 0 (Blood Rune in GTNH).
*/
object MissingMicroMaterial extends IMicroMaterial {
val key = "forgemicroblock:missing"
@SideOnly(Side.CLIENT)
private var icon: IIcon = _
@SideOnly(Side.CLIENT)
override def loadIcons(): Unit = {
icon = MicroblockProxy.renderBlocks.getIconSafe(null)
}
@SideOnly(Side.CLIENT)
override def getBreakingIcon(side: Int): IIcon = icon
@SideOnly(Side.CLIENT)
override def renderMicroFace(
pos: Vector3,
pass: Int,
bounds: Cuboid6
): Unit = {
MaterialRenderHelper
.start(pos, pass, new IconTransformation(icon))
.lighting()
.render()
}
override def isTransparent: Boolean = false
override def getLightValue: Int = 0
override def getStrength(player: EntityPlayer): Float = 1f
override def getLocalizedName: String = "Missing Material"
override def getItem: ItemStack = new ItemStack(Blocks.stone)
override def getCutterStrength: Int = 0
override def getSound: SoundType = Block.soundTypeStone
override def explosionResistance(entity: Entity): Float = 6f
}
@@ -26,7 +26,14 @@ object MicroblockCPH extends MicroblockPH with IClientPacketHandler {
netHandler: INetHandlerPlayClient netHandler: INetHandlerPlayClient
) { ) {
packet.getType match { packet.getType match {
case 1 => handleMaterialRegistration(packet, netHandler) // In singleplayer the integrated server and this client share the one
// static registry, so the id-map packet is redundant. Skipping it avoids
// rebuilding (clearing) the shared maps on the netty thread while the
// server thread reads them - the race that turned microblocks into Blood
// Rune slabs.
case 1 =>
if (!mc.isSingleplayer)
handleMaterialRegistration(packet, netHandler)
} }
} }
@@ -18,10 +18,17 @@ object ControlKeyModifer {
implicit def playerControlValue(p: EntityPlayer) = new ControlKeyValue(p) implicit def playerControlValue(p: EntityPlayer) = new ControlKeyValue(p)
class ControlKeyValue(p: EntityPlayer) { class ControlKeyValue(p: EntityPlayer) {
def isControlDown = map(p) def isControlDown = {
if (p.worldObj.isRemote) {
isClientPressing
} else {
map(p)
}
}
} }
val map = HashMap[EntityPlayer, Boolean]().withDefaultValue(false) val map = HashMap[EntityPlayer, Boolean]().withDefaultValue(false)
var isClientPressing = false;
/** Implicit static for Java users. /** Implicit static for Java users.
*/ */
@@ -38,7 +45,6 @@ object ControlKeyHandler
) { ) {
import ControlKeyModifer._ import ControlKeyModifer._
var wasPressed = false var wasPressed = false
var oldPlayer: EntityPlayer = null
@SubscribeEvent @SubscribeEvent
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
@@ -47,19 +53,11 @@ object ControlKeyHandler
if (pressed != wasPressed) { if (pressed != wasPressed) {
wasPressed = pressed wasPressed = pressed
if (Minecraft.getMinecraft.getNetHandler != null) { if (Minecraft.getMinecraft.getNetHandler != null) {
map.put(Minecraft.getMinecraft.thePlayer, pressed) isClientPressing = pressed
val packet = new PacketCustom(MultipartCPH.channel, 1) val packet = new PacketCustom(MultipartCPH.channel, 1)
packet.writeBoolean(pressed) packet.writeBoolean(pressed)
packet.sendToServer() packet.sendToServer()
} }
} }
if (oldPlayer != null) {
if (oldPlayer != Minecraft.getMinecraft.thePlayer) {
map.remove(oldPlayer)
oldPlayer = Minecraft.getMinecraft.thePlayer
}
} else {
oldPlayer = Minecraft.getMinecraft.thePlayer
}
} }
} }
@@ -85,7 +85,9 @@ object MultipartRenderer
val state = CCRenderState.instance val state = CCRenderState.instance
state.resetInstance() state.resetInstance()
state.lightMatrix.locate(world, x, y, z) state.lightMatrix.locate(world, x, y, z)
return tmpart.renderStatic(new Vector3(x, y, z), pass) val b = tmpart.renderStatic(new Vector3(x, y, z), pass)
state.lightMatrix.access = null
b
} }
override def renderInventoryBlock( override def renderInventoryBlock(
@@ -252,7 +252,9 @@ abstract class TMultiPart {
* Incremental changes should be sent rather than the whole description * Incremental changes should be sent rather than the whole description
* packet if possible. * packet if possible.
*/ */
def sendDescUpdate() = writeDesc(getWriteStream) def sendDescUpdate() {
if (tile != null) writeDesc(getWriteStream)
}
/** Called when a part is added or removed from this block space. The part /** Called when a part is added or removed from this block space. The part
* parameter may be null if several things have changed. * parameter may be null if several things have changed.
@@ -9,8 +9,7 @@ import cpw.mods.fml.common.event.{
FMLServerStoppedEvent FMLServerStoppedEvent
} }
import cpw.mods.fml.common.Mod.EventHandler import cpw.mods.fml.common.Mod.EventHandler
import codechicken.multipart.MultiPartRegistry import codechicken.multipart.{ControlKeyModifer, MultiPartRegistry, Tags}
import codechicken.multipart.Tags
@Mod( @Mod(
modid = "ForgeMultipart", modid = "ForgeMultipart",
@@ -46,5 +45,6 @@ object MultipartMod {
@EventHandler @EventHandler
def serverStopped(event: FMLServerStoppedEvent) { def serverStopped(event: FMLServerStoppedEvent) {
MultipartSaveLoad.loadingWorld = null; MultipartSaveLoad.loadingWorld = null;
ControlKeyModifer.map.clear();
} }
} }