Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3d printer bugfixes (stacking & lighting) #3472

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,14 @@ trait SmartBlockModelBase extends IBakedModel {
private def shade(value: Int, brightness: Float) = (brightness * value).toInt max 0 min 255

protected def getFaceBrightness(face: EnumFacing): Float = {
face match {
/*face match {
case EnumFacing.DOWN => 0.5f
case EnumFacing.UP => 1.0f
case EnumFacing.NORTH | EnumFacing.SOUTH => 0.8f
case EnumFacing.WEST | EnumFacing.EAST => 0.6f
}
}*/

//minecraft already applies tint based on quad's facing, so there is no need to apply it second time
1.0f
}
}
29 changes: 26 additions & 3 deletions src/main/scala/li/cil/oc/common/item/data/PrintData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import li.cil.oc.Constants
import li.cil.oc.Settings
import li.cil.oc.api
import li.cil.oc.common.IMC
import li.cil.oc.common.item.data.PrintData.Shape
import li.cil.oc.util.ExtendedAABB._
import li.cil.oc.util.ExtendedNBT._
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.nbt.{NBTBase, NBTTagCompound, NBTTagList}
import net.minecraft.util.math.AxisAlignedBB
import net.minecraftforge.common.util.Constants.NBT

Expand Down Expand Up @@ -97,13 +98,35 @@ class PrintData extends ItemData(Constants.BlockName.Print) {
nbt.setBoolean(IsButtonModeTag, isButtonMode)
nbt.setInteger(RedstoneLevelTag, redstoneLevel)
nbt.setBoolean(PressurePlateTag, pressurePlate)
nbt.setNewTagList(StateOffTag, stateOff.map(PrintData.shapeToNBT))
nbt.setNewTagList(StateOnTag, stateOn.map(PrintData.shapeToNBT))
setNewShapeSet(nbt, StateOffTag, stateOff)
setNewShapeSet(nbt, StateOnTag, stateOn)
nbt.setBoolean(IsBeaconBaseTag, isBeaconBase)
nbt.setByte(LightLevelTag, lightLevel.toByte)
nbt.setBoolean(NoclipOffTag, noclipOff)
nbt.setBoolean(NoclipOnTag, noclipOn)
}

// Shapes are stored in a set and sets do not have an order, that means NBT shape lists may be in any order.
// Because NBT list comparison considers order of tags in a list, and prints may have arbitrarily ordered list of shapes,
// the comparison fails and minecraft considers two identical prints different.
// One possible solution is to sort the shapes before serializing them to NBT
private def setNewShapeSet(nbt: NBTTagCompound, name: String, values: Iterable[Shape]) = {
val seq = values.toSeq.sortWith(compareShape);
nbt.setNewTagList(name, seq.map(PrintData.shapeToNBT))
}

private def compareShape(a: Shape, b: Shape): Boolean = {
import scala.math.Ordering.Implicits._
if (a.bounds.minX != b.bounds.minX) return a.bounds.minX > b.bounds.minX;
if (a.bounds.minY != b.bounds.minY) return a.bounds.minY > b.bounds.minY;
if (a.bounds.minZ != b.bounds.minZ) return a.bounds.minZ > b.bounds.minZ;
if (a.bounds.maxX != b.bounds.maxX) return a.bounds.maxX > b.bounds.maxX;
if (a.bounds.maxY != b.bounds.maxY) return a.bounds.maxY > b.bounds.maxY;
if (a.bounds.maxZ != b.bounds.maxZ) return a.bounds.maxZ > b.bounds.maxZ;
if (a.tint != b.tint) return a.tint > b.tint;
if (a.texture != b.texture) return a.texture > b.texture;
false
}
}

object PrintData {
Expand Down