Some work on the workbench

This commit is contained in:
Calclavia 2015-01-02 16:13:07 +08:00
parent 2d758f287d
commit ab142ce7b7
3 changed files with 2552 additions and 7 deletions

File diff suppressed because it is too large Load diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

View file

@ -1,22 +1,36 @@
package resonantinduction.archaic.process package resonantinduction.archaic.process
import io.netty.buffer.ByteBuf
import net.minecraft.block.material.Material import net.minecraft.block.material.Material
import net.minecraft.entity.player.EntityPlayer import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.{Item, ItemStack} import net.minecraft.item.{Item, ItemStack}
import net.minecraft.util.ResourceLocation import net.minecraft.util.ResourceLocation
import net.minecraftforge.client.model.AdvancedModelLoader import net.minecraftforge.client.model.AdvancedModelLoader
import net.minecraftforge.oredict.OreDictionary import net.minecraftforge.oredict.OreDictionary
import resonant.api.recipe.{MachineRecipes, RecipeResource} import org.lwjgl.opengl.GL11
import resonant.api.recipe.MachineRecipes
import resonant.lib.factory.resources.RecipeType import resonant.lib.factory.resources.RecipeType
import resonant.lib.network.discriminator.PacketType
import resonant.lib.network.handle.{TPacketReceiver, TPacketSender} import resonant.lib.network.handle.{TPacketReceiver, TPacketSender}
import resonant.lib.prefab.tile.TileInventory import resonant.lib.prefab.tile.TileInventory
import resonant.lib.render.RenderUtility import resonant.lib.render.{RenderItemOverlayUtility, RenderUtility}
import resonant.lib.transform.vector.Vector3 import resonant.lib.transform.vector.Vector3
import resonant.lib.utility.inventory.InventoryUtility import resonant.lib.utility.inventory.InventoryUtility
import resonantinduction.archaic.engineering.ItemHammer import resonantinduction.archaic.engineering.ItemHammer
import resonantinduction.core.resource.content.{ItemDust, ItemRubble}
import resonantinduction.core.{Reference, ResonantInduction} import resonantinduction.core.{Reference, ResonantInduction}
import resonant.lib.wrapper.ByteBufWrapper._
/** /**
* The workbench is meant for manual ore and wood processing.
* It is also the core block in Resonant Induction that leads the player to all aspect of the mod.
*
* Functions:
* Crush ores -> rubble
* Grind rubble -> dust
*
* Cut logs -> slabs
* Glue slabs -> wood
* *
* @author Calclavia * @author Calclavia
*/ */
@ -29,7 +43,7 @@ class TileWorkbench extends TileInventory(Material.rock) with TPacketSender with
{ {
//Constructor //Constructor
maxSlots = 1 maxSlots = 1
setTextureName(Reference.prefix + "material_metal_side") setTextureName(Reference.prefix + "material_wood_side")
normalRender = false normalRender = false
isOpaqueCube = false isOpaqueCube = false
@ -48,14 +62,14 @@ class TileWorkbench extends TileInventory(Material.rock) with TPacketSender with
if (oreName != null && oreName != "Unknown") if (oreName != null && oreName != "Unknown")
{ {
val outputs: Array[RecipeResource] = MachineRecipes.INSTANCE.getOutput(RecipeType.CRUSHER.name, oreName) val outputs = MachineRecipes.INSTANCE.getOutput(RecipeType.CRUSHER.name, oreName)
if (outputs != null && outputs.length > 0) if (outputs != null && outputs.length > 0)
{ {
if (!world.isRemote && world.rand.nextFloat < 0.2) if (!world.isRemote && world.rand.nextFloat < 0.2)
{ {
for (resource <- outputs) for (resource <- outputs)
{ {
val outputStack: ItemStack = resource.getItemStack.copy val outputStack = resource.getItemStack.copy
if (outputStack != null) if (outputStack != null)
{ {
InventoryUtility.dropItemStack(world, new Vector3(player), outputStack, 0) InventoryUtility.dropItemStack(world, new Vector3(player), outputStack, 0)
@ -75,16 +89,53 @@ class TileWorkbench extends TileInventory(Material.rock) with TPacketSender with
} }
else else
{ {
return interactCurrentItem(this, 0, player) interactCurrentItem(this, 0, player)
onInventoryChanged()
return true
} }
} }
return false return false
} }
override def isItemValidForSlot(i: Int, itemStack: ItemStack): Boolean =
{
if (i == 0)
return itemStack.getItem.isInstanceOf[ItemRubble] || itemStack.getItem.isInstanceOf[ItemDust]
return false
}
/** Called each time the inventory changes */
override def onInventoryChanged()
{
super.onInventoryChanged()
sendDescPacket()
}
override def read(buf: ByteBuf, id: Int, packetType: PacketType)
{
super.read(buf, id, packetType)
buf <<< getInventory
}
override def write(buf: ByteBuf, id: Int)
{
super.write(buf, id)
buf >>> getInventory
}
/**
* Packets
*/
override def renderDynamic(pos: Vector3, frame: Float, pass: Int) override def renderDynamic(pos: Vector3, frame: Float, pass: Int)
{ {
GL11.glPushMatrix()
RenderItemOverlayUtility.renderTopOverlay(this, Array[ItemStack](getStackInSlot(0)), getDirection, 1, 1, pos.x, pos.y - 0.1, pos.z, 0.7f)
RenderUtility.bind(Reference.domain, Reference.modelPath + "workbench.png") RenderUtility.bind(Reference.domain, Reference.modelPath + "workbench.png")
TileWorkbench.model.renderAll() // TileWorkbench.model.renderAll()
GL11.glPopMatrix()
} }
} }