mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-26 23:13:07 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7221176efd | ||
|
|
aa7d02cfb0 | ||
|
|
d2ce5b7362 | ||
|
|
09e2b847fc | ||
|
|
faa052f70c |
No files matched your search
@@ -3,6 +3,7 @@
|
||||
dependencies {
|
||||
implementation("com.github.GTNewHorizons:CodeChickenCore:1.4.12:dev")
|
||||
compileOnly("com.github.GTNewHorizons:Angelica:2.1.19:dev")
|
||||
compileOnly("com.github.GTNewHorizons:Postea:1.2.5:dev") {transitive = false}
|
||||
devOnlyNonPublishable("com.github.GTNewHorizons:NotEnoughItems:2.8.93-GTNH:dev") {
|
||||
exclude group: 'com.github.GTNewHorizons', module: 'CodeChickenCore'
|
||||
}
|
||||
|
||||
@@ -54,5 +54,7 @@ object DefaultContent {
|
||||
registerMaterial(new GrassMicroMaterial, materialKey(grass))
|
||||
MicroMaterialRegistry.remapName(oldKey(mycelium), materialKey(mycelium))
|
||||
registerMaterial(new TopMicroMaterial(mycelium), materialKey(mycelium))
|
||||
|
||||
registerMaterial(MissingMicroMaterial, MissingMicroMaterial.key)
|
||||
}
|
||||
}
|
||||
@@ -133,15 +133,18 @@ object ItemMicroPart {
|
||||
if (!stack.getTagCompound.hasKey("mat"))
|
||||
return null
|
||||
|
||||
return MicroMaterialRegistry.getMaterial(
|
||||
MicroMaterialRegistry.getMaterial(
|
||||
stack.getTagCompound.getString("mat")
|
||||
)
|
||||
) match {
|
||||
case null => MissingMicroMaterial
|
||||
case mat => mat
|
||||
}
|
||||
}
|
||||
|
||||
def getMaterialID(stack: ItemStack): Int = {
|
||||
checkTagCompound(stack)
|
||||
if (!stack.getTagCompound.hasKey("mat"))
|
||||
return 0
|
||||
return MicroMaterialRegistry.getMissingId
|
||||
|
||||
return MicroMaterialRegistry.materialID(
|
||||
stack.getTagCompound.getString("mat")
|
||||
|
||||
@@ -114,6 +114,7 @@ object MicroMaterialRegistry {
|
||||
private var maxCuttingStrength: Int = _
|
||||
|
||||
private val remap = HashMap[String, String]()
|
||||
private var missingId: Int = 0
|
||||
|
||||
/** Register a micro material with unique identifier name
|
||||
*/
|
||||
@@ -162,8 +163,17 @@ object MicroMaterialRegistry {
|
||||
nameMap.clear()
|
||||
for (i <- 0 until idMap.length)
|
||||
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() {
|
||||
val it = Item.itemRegistry.iterator.asInstanceOf[JIterator[Item]]
|
||||
maxCuttingStrength = it.flatMap {
|
||||
@@ -216,7 +226,7 @@ object MicroMaterialRegistry {
|
||||
case Some(v) => v
|
||||
case None =>
|
||||
logger.error("Missing mapping for part with ID: " + name)
|
||||
0
|
||||
missingId
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package codechicken.microblock.compat;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import com.gtnewhorizons.postea.api.IItemStackTransformationHandler;
|
||||
|
||||
import codechicken.microblock.MicroMaterialRegistry;
|
||||
|
||||
public class ItemMicroPartTransformer implements IItemStackTransformationHandler {
|
||||
|
||||
@Override
|
||||
public boolean apply(String originalItemId, NBTTagCompound stackTag) {
|
||||
if (!stackTag.hasKey("tag")) return false;
|
||||
NBTTagCompound tag = stackTag.getCompoundTag("tag");
|
||||
if (!tag.hasKey("mat")) return false;
|
||||
|
||||
String matName = tag.getString("mat");
|
||||
|
||||
// Goes through the remap layer, which is private
|
||||
int remappedId = MicroMaterialRegistry.materialID(matName);
|
||||
String remappedName = MicroMaterialRegistry.materialName(remappedId);
|
||||
|
||||
if (remappedName.equals(matName)) return false;
|
||||
|
||||
tag.setString("mat", remappedName);
|
||||
stackTag.setTag("tag", tag);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package codechicken.microblock.compat;
|
||||
|
||||
import com.gtnewhorizons.postea.api.ItemStackReplacementManager;
|
||||
|
||||
public class PosteaCompat {
|
||||
|
||||
public static void registerTransformers() {
|
||||
ItemStackReplacementManager
|
||||
.addTransformationHandler("ForgeMicroblock:microblock", new ItemMicroPartTransformer());
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,14 @@ object MicroblockCPH extends MicroblockPH with IClientPacketHandler {
|
||||
netHandler: INetHandlerPlayClient
|
||||
) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import net.minecraftforge.oredict.OreDictionary
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe
|
||||
import codechicken.lib.packet.PacketCustom
|
||||
import codechicken.microblock.compat.PosteaCompat
|
||||
import cpw.mods.fml.common.Loader
|
||||
import cpw.mods.fml.common.registry.GameRegistry
|
||||
import net.minecraft.client.renderer.RenderBlocks
|
||||
@@ -110,6 +111,9 @@ class MicroblockProxy_serverImpl {
|
||||
MicroblockSPH.registryChannel,
|
||||
MicroblockSPH
|
||||
)
|
||||
if (Loader.isModLoaded("postea")) {
|
||||
PosteaCompat.registerTransformers()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package codechicken.multipart
|
||||
import java.util.List
|
||||
import java.lang.Iterable
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.block.material.Material
|
||||
import net.minecraft.block.material.{MapColor, Material}
|
||||
import net.minecraft.entity.Entity
|
||||
import net.minecraft.util.AxisAlignedBB
|
||||
import net.minecraft.world.World
|
||||
@@ -12,6 +12,7 @@ import net.minecraft.util.Vec3
|
||||
import net.minecraft.util.MovingObjectPosition
|
||||
import codechicken.lib.raytracer.RayTracer
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
|
||||
import java.util.Random
|
||||
import java.util.ArrayList
|
||||
import net.minecraft.item.ItemStack
|
||||
@@ -68,7 +69,7 @@ object BlockMultipart {
|
||||
|
||||
/** Block class for all multiparts, should be internal use only.
|
||||
*/
|
||||
class BlockMultipart extends Block(Material.rock) {
|
||||
class BlockMultipart extends Block(new Material(MapColor.stoneColor)) {
|
||||
import BlockMultipart._
|
||||
|
||||
override def hasTileEntity(meta: Int = 0) = true
|
||||
@@ -256,10 +257,7 @@ class BlockMultipart extends Block(Material.rock) {
|
||||
|
||||
override def getRenderBlockPass = 1
|
||||
|
||||
override def canRenderInPass(pass: Int): Boolean = {
|
||||
MultipartRenderer.pass = pass
|
||||
return true
|
||||
}
|
||||
override def canRenderInPass(pass: Int): Boolean = true
|
||||
|
||||
override def getPickBlock(
|
||||
hit: MovingObjectPosition,
|
||||
|
||||
@@ -10,6 +10,8 @@ import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import net.minecraft.world.IBlockAccess
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraftforge.client.ForgeHooksClient
|
||||
import net.minecraftforge.client.MinecraftForgeClient
|
||||
import cpw.mods.fml.relauncher.SideOnly
|
||||
import cpw.mods.fml.relauncher.Side
|
||||
import codechicken.lib.raytracer.ExtendedMOP
|
||||
@@ -23,7 +25,6 @@ object MultipartRenderer
|
||||
extends TileEntitySpecialRenderer
|
||||
with ISimpleBlockRenderingHandler {
|
||||
TileMultipart.renderID = RenderingRegistry.getNextAvailableRenderId
|
||||
var pass: Int = 0
|
||||
|
||||
override def renderTileEntityAt(
|
||||
t: TileEntity,
|
||||
@@ -42,7 +43,7 @@ object MultipartRenderer
|
||||
state.useNormals = true
|
||||
|
||||
val pos = new Vector3(x, y, z)
|
||||
tmpart.renderDynamic(pos, f, pass)
|
||||
tmpart.renderDynamic(pos, f, MinecraftForgeClient.getRenderPass)
|
||||
}
|
||||
|
||||
override def getRenderId = TileMultipart.renderID
|
||||
@@ -85,7 +86,10 @@ object MultipartRenderer
|
||||
val state = CCRenderState.instance
|
||||
state.resetInstance()
|
||||
state.lightMatrix.locate(world, x, y, z)
|
||||
val b = tmpart.renderStatic(new Vector3(x, y, z), pass)
|
||||
val b = tmpart.renderStatic(
|
||||
new Vector3(x, y, z),
|
||||
ForgeHooksClient.getWorldRenderPass
|
||||
)
|
||||
state.lightMatrix.access = null
|
||||
b
|
||||
}
|
||||
|
||||
@@ -252,7 +252,9 @@ abstract class TMultiPart {
|
||||
* Incremental changes should be sent rather than the whole description
|
||||
* 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
|
||||
* parameter may be null if several things have changed.
|
||||
|
||||
@@ -562,7 +562,6 @@ trait TileMultipartClient extends TileMultipart {
|
||||
def randomDisplayTick(random: Random) {}
|
||||
|
||||
override def shouldRenderInPass(pass: Int) = {
|
||||
MultipartRenderer.pass = pass
|
||||
if (staticCache == null) updateRenderCache()
|
||||
hasDynamicParts
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user