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

Added a 3d-printer skin upgrade for robots #3694

Open
wants to merge 1 commit into
base: master-MC1.7.10
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions src/main/resources/assets/opencomputers/lang/de_DE.lang
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ item.oc.UpgradeTank.name=Tank-Upgrade
item.oc.UpgradeTankController.name=Tankbedienungs-Upgrade
item.oc.UpgradeTractorBeam.name=Traktorstrahl-Upgrade
item.oc.UpgradeTrading.name=Handels-Upgrade
item.oc.UpgradeSkin0.name=Skin-Upgrade (Stufe 1)
item.oc.UpgradeSkin1.name=Skin-Upgrade (Stufe 2)
item.oc.UpgradeSkin2.name=Skin-Upgrade (Stufe 3)
item.oc.WirelessNetworkCard0.name=Drahtlosnetzwerkkarte (Stufe 1)
item.oc.WirelessNetworkCard1.name=Drahtlosnetzwerkkarte (Stufe 2)
item.oc.WorldSensorCard.name=Weltsensorkarte
Expand Down Expand Up @@ -384,10 +387,14 @@ oc:tooltip.UpgradeLeash=Erlaubt es manchen Geräten, wie etwa Drohnen, B- *getus
oc:tooltip.UpgradeNavigation=Erlaubt es Robotern, ihre Position und Ausrichtung zu bestimmen. Die Position ist relativ zur Mitte der Karte, die in diesem Upgrade verbaut wurde.
oc:tooltip.UpgradePiston=Dieses Upgrade ist sehr drückend. Es macht es möglich Blöcke zu verschieben, ähnlich dem Kolben. Es kann jedoch §lkeine§7 Entities bewegen.
oc:tooltip.UpgradeSign=Erlaubt das Lesen und Schreiben von Text auf Schildern.
oc:tooltip.UpgradeSkin0=Hast du dir deinen Roboter schon einmal angesehen und gedacht: "Das sieht langweilig aus, ich habe einen 3D-Drucker, den ich benutzen möchte"? Mit diesem Upgrade kannst du genau das. Du kannst deinem Roboter einen 3D-gedruckten Skin verpassen und ihm sogar 3D-gedruckte Arme mit maximal einem Gelenk geben. Obwohl die Arme nicht mit der Welt interagieren können, sehen sie cool aus.
oc:tooltip.UpgradeSkin1=Hast du dir deinen Roboter schon einmal angesehen und gedacht: "Das sieht langweilig aus, ich habe einen 3D-Drucker, den ich benutzen möchte"? Mit diesem Upgrade kannst du genau das. Du kannst deinem Roboter einen 3D-gedruckten Skin verpassen und ihm sogar 3D-gedruckte Arme mit maximal zwei Gelenken geben. Obwohl die Arme nicht mit der Welt interagieren können, sehen sie cool aus.
oc:tooltip.UpgradeSkin2=Hast du dir deinen Roboter schon einmal angesehen und gedacht: "Das sieht langweilig aus, ich habe einen 3D-Drucker, den ich benutzen möchte"? Mit diesem Upgrade kannst du genau das. Du kannst deinem Roboter einen 3D-gedruckten Skin verpassen und ihm sogar 3D-gedruckte Arme mit maximal drei Gelenken geben. Obwohl die Arme nicht mit der Welt interagieren können, sehen sie cool aus.
oc:tooltip.UpgradeSolarGenerator=Kann verwendet werden, um unterwegs Energie aus Sonnenlicht zu generieren. Benötigt eine ungehinderte Sicht zum Himmel über dem Roboter. Generiert Energie mit %s%% der Geschwindigkeit eines Stirlingmotors.
oc:tooltip.UpgradeTank=Dieses Upgrade gibt Robotern einen internen Tank. Ohne ein solches Upgrade können Roboter keine Flüssigkeiten verwahren.
oc:tooltip.UpgradeTankController=Dieses Upgrade erlaubt es dem Roboter, präziser mit externen Tanks zu interagieren, und erlaubt es ihm, Flüssigkeiten in und aus sich im Inventar befindlichen Tank-Gegenständen zu pumpen.
oc:tooltip.UpgradeTractorBeam=Stattet den Roboter mit unglaublich fortschrittlicher Technologie - Kosename: "Gegenstandsmagnet" - aus. Erlaubt es dem Roboter, Gegenstände, innerhalb von 3 Blöcken um sich herum, einzusammeln.
oc:tooltip.UpgradeTrading=Erlaubt Robotern und Dronen mit Dorfbewohnern zu handeln.
oc:tooltip.Waypoint=Ein Orientierungpunkt für Geräte mit einem Navigations-Upgrade.
oc:tooltip.WirelessNetworkCard=Erlaubt das drahtlose Senden von Netzwerknachrichten, zusätzlich zu normalen. Drahtlose Nachrichten werden nur gesendet, wenn eine §fSignalstärke§7 festgelegt wurde!
oc:tooltip.WorldSensorCard=Erlaubt es, Informationen über die Welt auszulesen, wie etwa Gravitation und ob die Atmosphäre atembar ist. Verwendung von Messergebnissen auf eigene Gefahr. Der Hersteller übernimmt keinerlei Garantie.
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/assets/opencomputers/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ item.oc.UpgradeTank.name=Tank Upgrade
item.oc.UpgradeTankController.name=Tank Controller Upgrade
item.oc.UpgradeTractorBeam.name=Tractor Beam Upgrade
item.oc.UpgradeTrading.name=Trading Upgrade
item.oc.UpgradeSkin0.name=Skin Upgrade (Tier 1)
item.oc.UpgradeSkin1.name=Skin Upgrade (Tier 2)
item.oc.UpgradeSkin2.name=Skin Upgrade (Tier 3)
item.oc.WirelessNetworkCard0.name=Wireless Network Card (Tier 1)
item.oc.WirelessNetworkCard1.name=Wireless Network Card (Tier 2)
item.oc.WorldSensorCard.name=World Sensor Card
Expand Down Expand Up @@ -385,6 +388,9 @@ oc:tooltip.UpgradeLeash=Allows some devices, such as drones, to bind Isaa- excus
oc:tooltip.UpgradeNavigation=Can be used to determine the position and orientation of a device. The position is relative to the center of the map that was used to craft this upgrade.
oc:tooltip.UpgradePiston=This upgrade is very pushy. It allows moving blocks, similar to when using a piston. It does §lnot§7 move entities, however.
oc:tooltip.UpgradeSign=Allows reading text on and writing text to signs.
oc:tooltip.UpgradeSkin0=Have you ever looked at your robot and thought 'This looks boring, I have a 3d printer that I wanna use'? With this upgrade, you can. You can apply a 3d-printed skin to your robot and even give it 3d-printed arms with a maximum of one joint. Although the arms can't interact with the world, they can look cool.
oc:tooltip.UpgradeSkin1=Have you ever looked at your robot and thought 'This looks boring, I have a 3d printer that I wanna use'? With this upgrade, you can. You can apply a 3d-printed skin to your robot and even give it 3d-printed arms with a maximum of two joints. Although the arms can't interact with the world, they can look cool.
oc:tooltip.UpgradeSkin2=Have you ever looked at your robot and thought 'This looks boring, I have a 3d printer that I wanna use'? With this upgrade, you can. You can apply a 3d-printed skin to your robot and even give it 3d-printed arms with a maximum of three joints. Although the arms can't interact with the world, they can look cool.
oc:tooltip.UpgradeSolarGenerator=Can be used to generate energy from sunlight on the go. Requires a clear line of sight to the sky above the device. Generates energy at %s%% of the speed of a Stirling Engine.
oc:tooltip.UpgradeTank=This upgrade provides a tank for fluid storage for robots and drones. Without one of these, they will not be able to store fluids internally.
oc:tooltip.UpgradeTankController=This upgrade allows robots and drones more control in how they interacts with external tanks, and allows them to transfer fluids into and out of fluid tank items in their inventory.
Expand Down
15 changes: 15 additions & 0 deletions src/main/resources/assets/opencomputers/recipes/default.recipes
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,21 @@ signUpgrade {
["oc:circuitChip1", stickWood, "oc:circuitChip1"]
[ingotIron, pistonStickyBase, ingotIron]]
}
skinUpgrade1 {
input: [["oc:circuitChip1", leather, "oc:circuitChip1"]
[leather, chest, leather]
["oc:circuitChip1", leather, "oc:circuitChip1"]]
}
skinUpgrade2 {
input: [["oc:circuitChip2", leather, "oc:circuitChip2"]
[leather, chest, leather]
["oc:circuitChip2", leather, "oc:circuitChip2"]]
}
skinUpgrade3 {
input: [["oc:circuitChip3", leather, "oc:circuitChip3"]
[leather, chest, leather]
["oc:circuitChip3", leather, "oc:circuitChip3"]]
}
solarGeneratorUpgrade {
input: [[blockGlass, blockGlass, blockGlass]
["oc:circuitChip3", blockLapis, "oc:circuitChip3"]
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/main/scala/li/cil/oc/Constants.scala
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ object Constants {
final val ServerTier2 = "server2"
final val ServerTier3 = "server3"
final val SignUpgrade = "signUpgrade"
final val SkinUpgradeTier1 = "skinUpgrade1"
final val SkinUpgradeTier2 = "skinUpgrade2"
final val SkinUpgradeTier3 = "skinUpgrade3"
final val SolarGeneratorUpgrade = "solarGeneratorUpgrade"
final val Tablet = "tablet"
final val TabletCaseCreative = "tabletCaseCreative"
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/li/cil/oc/client/PacketHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ object PacketHandler extends CommonPacketHandler {
val stack = p.readItemStack()
if (slot >= robot.getSizeInventory - robot.componentCount) {
robot.info.components(slot - (robot.getSizeInventory - robot.componentCount)) = stack
robot.cacheSkinComponentsForRendering(stack)
}
else t.robot.setInventorySlotContents(slot, stack)
case _ => // Invalid packet.
Expand Down
135 changes: 124 additions & 11 deletions src/main/scala/li/cil/oc/client/renderer/tileentity/RobotRenderer.scala
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
package li.cil.oc.client.renderer.tileentity

import com.google.common.base.Strings
import li.cil.oc.OpenComputers
import li.cil.oc.Settings
import li.cil.oc.{Constants, OpenComputers, Settings, api}
import li.cil.oc.api.driver.item.UpgradeRenderer
import li.cil.oc.api.driver.item.UpgradeRenderer.MountPointName
import li.cil.oc.api.event.RobotRenderEvent
import li.cil.oc.client.Textures
import li.cil.oc.client.renderer.block.BlockRenderer.patchedRenderer
import li.cil.oc.client.renderer.block.{BlockRenderer, Print}
import li.cil.oc.common.EventHandler
import li.cil.oc.common.component.UpgradeSkinComponent
import li.cil.oc.common.item.UpgradeSkin
import li.cil.oc.common.tileentity
import li.cil.oc.common.tileentity.Robot
import li.cil.oc.util.RenderState
import net.minecraft.block.Block
import net.minecraft.client.Minecraft
import net.minecraft.client.renderer.GLAllocation
import net.minecraft.client.renderer.RenderBlocks
import net.minecraft.client.renderer.Tessellator
import net.minecraft.client.renderer.entity.RenderManager
import net.minecraft.client.renderer.entity.RendererLivingEntity
import net.minecraft.client.renderer.{GLAllocation, OpenGlHelper, RenderBlocks, Tessellator}
import net.minecraft.client.renderer.entity.{RenderItem, RenderManager, RendererLivingEntity}
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer
import net.minecraft.entity.item.EntityItem
import net.minecraft.init.Items
import net.minecraft.item.ItemBlock
import net.minecraft.item.ItemStack
Expand Down Expand Up @@ -283,8 +285,8 @@ object RobotRenderer extends TileEntitySpecialRenderer {
val robot = proxy.robot
val worldTime = entity.getWorldObj.getTotalWorldTime + f

GL11.glPushMatrix()
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS)
GL11.glPushMatrix()
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5)

// If the move started while we were rendering and we have a reference to
Expand Down Expand Up @@ -330,7 +332,13 @@ object RobotRenderer extends TileEntitySpecialRenderer {
GL11.glTranslatef(-0.5f, -0.5f, -0.5f)

val offset = timeJitter + worldTime / 20.0
renderChassis(robot, offset)

val pass = MinecraftForgeClient.getRenderPass
val renderedBodySkin = renderSkins(robot, f)

if((!renderedBodySkin || !robot.hideBody) && pass == 0) {
renderChassis(robot, offset)
}

if (!robot.renderingErrored && x * x + y * y + z * z < 24 * 24) {
Option(robot.getStackInSlot(0)) match {
Expand Down Expand Up @@ -434,7 +442,7 @@ object RobotRenderer extends TileEntitySpecialRenderer {
case _ =>
}

if (MinecraftForgeClient.getRenderPass == 0) {
if (MinecraftForgeClient.getRenderPass == 0 && !robot.hideUpgrades) {
lazy val availableSlots = slotNameMapping.keys.to[mutable.Set]
lazy val wildcardRenderers = mutable.Buffer.empty[(ItemStack, UpgradeRenderer)]
lazy val slotMapping = Array.fill(mountPoints.length)(null: (ItemStack, UpgradeRenderer))
Expand Down Expand Up @@ -475,7 +483,7 @@ object RobotRenderer extends TileEntitySpecialRenderer {
GL11.glPopMatrix()

val name = robot.name
if (Settings.get.robotLabels && MinecraftForgeClient.getRenderPass == 1 && !Strings.isNullOrEmpty(name) && x * x + y * y + z * z < RendererLivingEntity.NAME_TAG_RANGE) {
if (!robot.hideNameTag && Settings.get.robotLabels && MinecraftForgeClient.getRenderPass == 1 && !Strings.isNullOrEmpty(name) && x * x + y * y + z * z < RendererLivingEntity.NAME_TAG_RANGE) {
GL11.glPushMatrix()

// This is pretty much copy-pasta from the entity's label renderer.
Expand Down Expand Up @@ -521,4 +529,109 @@ object RobotRenderer extends TileEntitySpecialRenderer {

RenderState.checkError(getClass.getName + ".renderTileEntityAt: leaving")
}

def renderSkins(robot: Robot, f: Float): Boolean = {
val pass = MinecraftForgeClient.getRenderPass

if(robot.skins(0).skin.isDefined || robot.skins(1).skin.isDefined || robot.skins(4).skin.isDefined) { // if(skinUpgrade.isDefined) {
val bodySkin = robot.skins(0)
val leftJ1Skin = robot.skins(1)
val leftJ2Skin = robot.skins(2)
val leftJ3Skin = robot.skins(3)
val rightJ1Skin = robot.skins(4)
val rightJ2Skin = robot.skins(5)
val rightJ3Skin = robot.skins(6)
GL11.glPushMatrix()
GL11.glTranslatef(0.5f, 0.53f, 0.5f)
GL11.glScalef(0.8f, 0.8f, 0.8f)

if(bodySkin.skin.isDefined) {
renderSkin(bodySkin, robot, f, pass)
}

if(leftJ1Skin.skin.isDefined) {
GL11.glPushMatrix()
GL11.glTranslatef(0.5f, 0f, 0f)
renderSkin(leftJ1Skin, robot, f, pass, 0.5f, 0, 0, false)
if(leftJ2Skin.skin.isDefined) {
GL11.glTranslatef(0.5f, 0f, 0f)
renderSkin(leftJ2Skin, robot, f, pass, 0.5f, 0, 0, false)
if(leftJ3Skin.skin.isDefined) {
GL11.glTranslatef(0.5f, 0f, 0f)
renderSkin(leftJ3Skin, robot, f, pass, 0.5f, 0, 0, false)
}
}
GL11.glPopMatrix()
}

if(rightJ1Skin.skin.isDefined) {
GL11.glPushMatrix()
GL11.glTranslatef(-0.5f, 0f, 0f)
renderSkin(rightJ1Skin, robot, f, pass, -0.5f, 0, 0, true)
if(rightJ2Skin.skin.isDefined) {
GL11.glTranslatef(-0.5f, 0f, 0f)
renderSkin(rightJ2Skin, robot, f, pass, -0.5f, 0, 0, true)
if(rightJ3Skin.skin.isDefined) {
GL11.glTranslatef(-0.5f, 0f, 0f)
renderSkin(rightJ3Skin, robot, f, pass, -0.5f, 0, 0, true)
}
}
GL11.glPopMatrix()
}

GL11.glPopMatrix()
}
robot.skins(0).skin.isDefined
}

def renderSkin(skinComponent: UpgradeSkinComponent, robot: Robot, f: Float, pass: Int): Unit = {
renderSkin(skinComponent, robot, f, pass, 0, 0, 0, false)
}

def renderSkin(skinComponent: UpgradeSkinComponent, robot: Robot, f: Float, pass: Int, offsetX: Float, offsetY: Float, offsetZ: Float, invertRot: Boolean): Unit = {
// val rotDir = if (invertRot) -1 else 1
val rotDir = 1
if(skinComponent.animationTicksTotal > 0) {
val remaining = (skinComponent.animationTicksLeft - f) / skinComponent.animationTicksTotal.toFloat
GL11.glRotatef(skinComponent.rotX - (skinComponent.rotX - skinComponent.oldRotX) * remaining, rotDir, 0, 0)
GL11.glRotatef(skinComponent.rotY - (skinComponent.rotY - skinComponent.oldRotY) * remaining, 0, rotDir, 0)
GL11.glRotatef(skinComponent.rotZ - (skinComponent.rotZ - skinComponent.oldRotZ) * remaining, 0, 0, rotDir)
} else {
GL11.glRotatef(skinComponent.rotX, rotDir, 0, 0)
GL11.glRotatef(skinComponent.rotY, 0, rotDir, 0)
GL11.glRotatef(skinComponent.rotZ, 0, 0, rotDir)
}
GL11.glTranslatef(offsetX, offsetY, offsetZ)

val brightness = robot.world.getLightBrightnessForSkyBlocks(robot.x, robot.y, robot.z, 0)
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, brightness % 65536, brightness / 65536)

val stack = skinComponent.skin.get
val itemRenderer = RenderManager.instance.itemRenderer
def renderPass(): Unit = {
val tint = stack.getItem.getColorFromItemStack(stack, pass)
val r = ((tint >> 16) & 0xFF) / 255f
val g = ((tint >> 8) & 0xFF) / 255f
val b = ((tint >> 0) & 0xFF) / 255f
GL11.glColor4f(r, g, b, 1)
itemRenderer.renderItem(Minecraft.getMinecraft.thePlayer, stack, pass)
}

if (stack.getItem.requiresMultipleRenderPasses()) {
val passes = stack.getItem.getRenderPasses(stack.getItemDamage)
if (pass < passes) {
renderPass()
}
// Tile entities only get two render passes, so if items need
// more, we have to fake them.
if (pass == 1 && passes > 2) {
for (fakePass <- 2 until passes) {
renderPass()
}
}
}
else if (pass == 0) {
renderPass()
}
}
}
104 changes: 104 additions & 0 deletions src/main/scala/li/cil/oc/common/component/UpgradeSkinComponent.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package li.cil.oc.common.component

import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound

class UpgradeSkinComponent(pName:String) {
val name = pName
var skin = None : Option[ItemStack]
var rotX = 0f
var rotY = 0f
var rotZ = 0f
var oldRotX = 0f
var oldRotY = 0f
var oldRotZ = 0f
var animationTicksLeft = 0
var animationTicksTotal = 0

def prepareRotationAnimation(pRotX: Float, pRotY: Float, pRotZ: Float, duration: Int): Unit = {
/*oldRotX = setOldRot(pRotX, rotX)
oldRotY = setOldRot(pRotY, rotY)
oldRotZ = setOldRot(pRotZ, rotZ)
rotX = floorMod(pRotX, 360)
rotY = floorMod(pRotY, 360)
rotZ = floorMod(pRotZ, 360)*/
oldRotX = rotX
oldRotY = rotY
oldRotZ = rotZ
rotX = pRotX
rotY = pRotY
rotZ = pRotZ
animationTicksTotal = duration
animationTicksLeft = duration
}

def setOldRot(newRot: Float, oldRot: Float): Float = {
if(newRot > 360) {
oldRot - 360
} else if(newRot < 0) {
oldRot + 360
} else {
oldRot
}
}

def floorMod(a: Float, b: Int): Float = {
var am = a % b
if (am < 0) {
am += b
}
am
}

def updateClient(): Unit = {
if(animationTicksLeft > 0) {
animationTicksLeft -= 1
if(animationTicksLeft == 0) {
animationTicksTotal = 0
}
}
}

def save(nbt: NBTTagCompound): Unit = {
val tag = new NBTTagCompound()

if(skin.isDefined) {
val skinNbt = new NBTTagCompound()
skin.get.writeToNBT(skinNbt)
tag.setTag("skin", skinNbt)
}
tag.setFloat("rotX", rotX)
tag.setFloat("rotY", rotY)
tag.setFloat("rotZ", rotZ)
tag.setFloat("oldRotX", oldRotX)
tag.setFloat("oldRotY", oldRotY)
tag.setFloat("oldRotZ", oldRotZ)
tag.setInteger("animationTicksLeft", animationTicksLeft)
tag.setInteger("animationTicksTotal", animationTicksTotal)

nbt.setTag("skin" + name, tag)
}

def load(nbt: NBTTagCompound): Unit = {
if(nbt.hasKey("skin" + name)) {
val tag = nbt.getCompoundTag("skin" + name)

if(tag.hasKey("skin")) {
skin = Some(ItemStack.loadItemStackFromNBT(tag.getCompoundTag("skin")))
} else {
skin = None
}
rotX = tag.getFloat("rotX")
rotY = tag.getFloat("rotY")
rotZ = tag.getFloat("rotZ")

if(tag.hasKey("animationTicksLeft")) {
oldRotX = tag.getFloat("oldRotX")
oldRotY = tag.getFloat("oldRotY")
oldRotZ = tag.getFloat("oldRotZ")
animationTicksLeft = tag.getInteger("animationTicksLeft")
animationTicksTotal = tag.getInteger("animationTicksTotal")
}
}
}
}
Loading