Added workbench
This commit is contained in:
parent
d50d2412e1
commit
1fa1cf3d2e
4 changed files with 197 additions and 111 deletions
|
@ -12,7 +12,7 @@ import resonantinduction.archaic.firebox.{TileFirebox, TileHotPlate}
|
|||
import resonantinduction.archaic.fluid.grate.TileGrate
|
||||
import resonantinduction.archaic.fluid.gutter.TileGutter
|
||||
import resonantinduction.archaic.fluid.tank.TileTank
|
||||
import resonantinduction.archaic.process.{TileCastingMold, TileMillstone}
|
||||
import resonantinduction.archaic.process.{TileWorkbench, TileCastingMold, TileMillstone}
|
||||
import resonantinduction.core.{RICreativeTab, Reference}
|
||||
import resonantinduction.mechanical.mech.gear.ItemHandCrank
|
||||
;
|
||||
|
@ -36,6 +36,7 @@ object ArchaicContent extends ContentHolder
|
|||
var blockGrate: Block = new TileGrate
|
||||
var blockGutter: Block = new TileGutter
|
||||
var blockTank: Block = new TileTank
|
||||
var blockWorkbench: Block = new TileWorkbench
|
||||
|
||||
//Constructor
|
||||
manager.setTab(RICreativeTab)
|
||||
|
|
|
@ -35,8 +35,8 @@ class TileCastingMold extends TileInventory(Material.rock) with IFluidHandler wi
|
|||
|
||||
//Constructor
|
||||
setTextureName(Reference.prefix + "material_metal_side")
|
||||
normalRender(false)
|
||||
isOpaqueCube(false)
|
||||
normalRender = false
|
||||
isOpaqueCube = false
|
||||
|
||||
override def canUpdate: Boolean =
|
||||
{
|
||||
|
|
|
@ -1,32 +1,31 @@
|
|||
package resonantinduction.archaic.process
|
||||
|
||||
import cpw.mods.fml.common.network.ByteBufUtils
|
||||
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||
import io.netty.buffer.ByteBuf
|
||||
import net.minecraft.block.material.Material
|
||||
import net.minecraft.client.renderer.texture.IIconRegister
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraft.util.IIcon
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
import resonant.api.recipe.{MachineRecipes, RecipeResource}
|
||||
import resonant.lib.factory.resources.RecipeType
|
||||
import resonant.lib.network.discriminator.{PacketTile, PacketType}
|
||||
import resonant.lib.network.handle.IPacketReceiver
|
||||
import resonant.lib.network.discriminator.PacketType
|
||||
import resonant.lib.network.handle.{TPacketReceiver, TPacketSender}
|
||||
import resonant.lib.prefab.tile.TileInventory
|
||||
import resonant.lib.prefab.tile.spatial.SpatialBlock
|
||||
import resonant.lib.transform.vector.Vector3
|
||||
import resonant.lib.utility.inventory.InventoryUtility
|
||||
import resonant.lib.wrapper.ByteBufWrapper._
|
||||
import resonantinduction.core.Reference
|
||||
import resonantinduction.mechanical.mech.gear.ItemHandCrank
|
||||
import resonant.lib.transform.vector.Vector3
|
||||
|
||||
class TileMillstone extends TileInventory(Material.rock) with IPacketReceiver
|
||||
class TileMillstone extends TileInventory(Material.rock) with TPacketSender with TPacketReceiver
|
||||
{
|
||||
|
||||
private var grindCount: Int = 0
|
||||
|
||||
//Constructor
|
||||
maxSlots = 1
|
||||
setTextureName(Reference.prefix + "millstone_side")
|
||||
|
||||
override def onInventoryChanged
|
||||
|
@ -37,11 +36,12 @@ class TileMillstone extends TileInventory(Material.rock) with IPacketReceiver
|
|||
|
||||
def doGrind(spawnPos: Vector3)
|
||||
{
|
||||
val outputs: Array[RecipeResource] = MachineRecipes.INSTANCE.getOutput(RecipeType.GRINDER.name, getStackInSlot(0))
|
||||
val outputs = MachineRecipes.INSTANCE.getOutput(RecipeType.GRINDER.name, getStackInSlot(0))
|
||||
|
||||
if (outputs.length > 0)
|
||||
{
|
||||
grindCount += 1;
|
||||
if ( grindCount > 20)
|
||||
grindCount += 1
|
||||
if (grindCount > 20)
|
||||
{
|
||||
for (res <- outputs)
|
||||
{
|
||||
|
@ -68,38 +68,15 @@ class TileMillstone extends TileInventory(Material.rock) with IPacketReceiver
|
|||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Packets
|
||||
*/
|
||||
override def getDescPacket: PacketTile =
|
||||
{
|
||||
val nbt: NBTTagCompound = new NBTTagCompound
|
||||
this.writeToNBT(nbt)
|
||||
return new PacketTile(this, nbt)
|
||||
}
|
||||
|
||||
def read(data: ByteBuf, player: EntityPlayer, `type`: PacketType)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.readFromNBT(ByteBufUtils.readTag(data))
|
||||
}
|
||||
catch
|
||||
{
|
||||
case e: Exception =>
|
||||
{
|
||||
e.printStackTrace
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT) override def registerIcons(iconReg: IIconRegister)
|
||||
@SideOnly(Side.CLIENT)
|
||||
override def registerIcons(iconReg: IIconRegister)
|
||||
{
|
||||
SpatialBlock.icon.put("millstone_side", iconReg.registerIcon(Reference.prefix + "millstone_side"))
|
||||
SpatialBlock.icon.put("millstone_top", iconReg.registerIcon(Reference.prefix + "millstone_top"))
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT) override def getIcon(side: Int, meta: Int): IIcon =
|
||||
@SideOnly(Side.CLIENT)
|
||||
override def getIcon(side: Int, meta: Int): IIcon =
|
||||
{
|
||||
if (side == 0 || side == 1)
|
||||
{
|
||||
|
@ -148,4 +125,23 @@ class TileMillstone extends TileInventory(Material.rock) with IPacketReceiver
|
|||
world.markBlockForUpdate(xi, yi, zi)
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Packets
|
||||
*/
|
||||
/**
|
||||
* Override this method
|
||||
* Be sure to super this method or manually write the ID into the packet when sending
|
||||
*/
|
||||
override def write(buf: ByteBuf, id: Int)
|
||||
{
|
||||
super.write(buf, id)
|
||||
buf <<<< writeToNBT
|
||||
}
|
||||
|
||||
override def read(buf: ByteBuf, id: Int, packetType: PacketType)
|
||||
{
|
||||
super.read(buf, id, packetType)
|
||||
buf >>>> readFromNBT
|
||||
}
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
package resonantinduction.archaic.process
|
||||
|
||||
import net.minecraft.block.material.Material
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.item.{Item, ItemStack}
|
||||
import net.minecraft.util.ResourceLocation
|
||||
import net.minecraftforge.client.model.AdvancedModelLoader
|
||||
import net.minecraftforge.oredict.OreDictionary
|
||||
import resonant.api.recipe.{MachineRecipes, RecipeResource}
|
||||
import resonant.lib.factory.resources.RecipeType
|
||||
import resonant.lib.network.handle.{TPacketReceiver, TPacketSender}
|
||||
import resonant.lib.prefab.tile.TileInventory
|
||||
import resonant.lib.render.RenderUtility
|
||||
import resonant.lib.transform.vector.Vector3
|
||||
import resonant.lib.utility.inventory.InventoryUtility
|
||||
import resonantinduction.archaic.engineering.ItemHammer
|
||||
import resonantinduction.core.{Reference, ResonantInduction}
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Calclavia
|
||||
*/
|
||||
object TileWorkbench
|
||||
{
|
||||
val model = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain, Reference.modelPath + "workbench.obj"))
|
||||
}
|
||||
|
||||
class TileWorkbench extends TileInventory(Material.rock) with TPacketSender with TPacketReceiver
|
||||
{
|
||||
//Constructor
|
||||
maxSlots = 1
|
||||
setTextureName(Reference.prefix + "material_metal_side")
|
||||
normalRender = false
|
||||
isOpaqueCube = false
|
||||
|
||||
override def use(player: EntityPlayer, hitSide: Int, hit: Vector3): Boolean =
|
||||
{
|
||||
//The player is holding a hammer. Attempt to crush the item on the bench
|
||||
if (player.getCurrentEquippedItem != null)
|
||||
{
|
||||
if (player.getCurrentEquippedItem.getItem.isInstanceOf[ItemHammer])
|
||||
{
|
||||
val inputStack = getStackInSlot(0)
|
||||
|
||||
if (inputStack != null)
|
||||
{
|
||||
val oreName: String = OreDictionary.getOreName(OreDictionary.getOreID(inputStack))
|
||||
if (oreName != null && !(oreName == "Unknown"))
|
||||
{
|
||||
val outputs: Array[RecipeResource] = MachineRecipes.INSTANCE.getOutput(RecipeType.CRUSHER.name, oreName)
|
||||
if (outputs != null && outputs.length > 0)
|
||||
{
|
||||
if (!world.isRemote && world.rand.nextFloat < 0.2)
|
||||
{
|
||||
for (resource <- outputs)
|
||||
{
|
||||
val outputStack: ItemStack = resource.getItemStack.copy
|
||||
if (outputStack != null)
|
||||
{
|
||||
InventoryUtility.dropItemStack(world, new Vector3(player), outputStack, 0)
|
||||
inputStack.stackSize -= 1
|
||||
setInventorySlotContents(0, if (inputStack.stackSize <= 0) null else inputStack)
|
||||
}
|
||||
}
|
||||
}
|
||||
ResonantInduction.proxy.renderBlockParticle(world, new Vector3(x + 0.5, y + 0.5, z + 0.5), new Vector3((Math.random - 0.5f) * 3, (Math.random - 0.5f) * 3, (Math.random - 0.5f) * 3), Item.getIdFromItem(inputStack.getItem), 1)
|
||||
world.playSoundEffect(x + 0.5, y + 0.5, z + 0.5, Reference.prefix + "hammer", 0.5f, 0.8f + (0.2f * world.rand.nextFloat))
|
||||
player.addExhaustion(0.1f)
|
||||
player.getCurrentEquippedItem.damageItem(1, player)
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return interactCurrentItem(this, 0, player)
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
override def renderDynamic(pos: Vector3, frame: Float, pass: Int)
|
||||
{
|
||||
RenderUtility.bind(Reference.domain, Reference.modelPath + "workbench.png")
|
||||
TileWorkbench.model.renderAll()
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue