mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-17 03:05:30 -04:00
adapter block no longer needs to be configured. this was meant to keep the 'power' of the block in check, and that isn't really necessary anymore now that components per computer are limited. and it makes things so much easier!
This commit is contained in:
parent
c743b89571
commit
0a6a2693ef
@ -1,7 +1,6 @@
|
||||
package li.cil.oc.api.driver;
|
||||
|
||||
import li.cil.oc.api.network.ManagedEnvironment;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
@ -40,22 +39,6 @@ public interface Block {
|
||||
*/
|
||||
boolean worksWith(World world, int x, int y, int z);
|
||||
|
||||
/**
|
||||
* Used to determine the block types this driver handles.
|
||||
* <p/>
|
||||
* This is used to determine whether there is a driver for the specified
|
||||
* block type when an Adapter block is being configured, i.e. when the
|
||||
* player tries to place an item into the adapter's GUI.
|
||||
* <p/>
|
||||
* Note that the passed item stacks are not necessarily item blocks, they
|
||||
* can be anything at all.
|
||||
*
|
||||
* @param world the world containing the adapter that does the checking.
|
||||
* @param stack the item stack to check.
|
||||
* @return <tt>true</tt> if the block is supported; <tt>false</tt> otherwise.
|
||||
*/
|
||||
boolean worksWith(World world, ItemStack stack);
|
||||
|
||||
/**
|
||||
* Create a new managed environment interfacing the specified block.
|
||||
* <p/>
|
||||
|
@ -1,6 +1,5 @@
|
||||
package li.cil.oc.api.prefab;
|
||||
|
||||
import li.cil.oc.api.Driver;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
@ -8,16 +7,13 @@ import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
/**
|
||||
* If you wish to create a block component for a third-party block, i.e. a block
|
||||
* for which you do not control the tile entity, such as vanially blocks, you
|
||||
* for which you do not control the tile entity, such as vanilla blocks, you
|
||||
* will need a block driver.
|
||||
* <p/>
|
||||
* This prefab allows creating a driver that works for a specified list of item
|
||||
* stacks (to support different blocks with the same id but different metadata
|
||||
* values).
|
||||
* <p/>
|
||||
* Note that if you use this prefab you <em>must instantiate your driver in the
|
||||
* init phase</em>, since it automatically registers itself with OpenComputers.
|
||||
* <p/>
|
||||
* You still have to provide the implementation for creating its environment, if
|
||||
* any.
|
||||
*
|
||||
@ -29,11 +25,6 @@ public abstract class DriverBlock implements li.cil.oc.api.driver.Block {
|
||||
|
||||
protected DriverBlock(final ItemStack... blocks) {
|
||||
this.blocks = blocks.clone();
|
||||
|
||||
// Make the driver known with OpenComputers. This is required, otherwise
|
||||
// the mod won't know this driver exists. It must be called in the init
|
||||
// phase.
|
||||
Driver.add(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -41,22 +32,6 @@ public abstract class DriverBlock implements li.cil.oc.api.driver.Block {
|
||||
return worksWith(world.getBlockId(x, y, z), world.getBlockMetadata(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean worksWith(final World world, final ItemStack stack) {
|
||||
if (stack != null) {
|
||||
for (ItemStack supportedBlock : blocks) {
|
||||
if (stack.itemID == supportedBlock.itemID && (!stack.getHasSubtypes() || stack.getItemDamage() == supportedBlock.getItemDamage())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (stack.getItem() instanceof ItemBlock) {
|
||||
final ItemBlock reference = (ItemBlock) stack.getItem();
|
||||
return worksWith(reference.getBlockID(), reference.getMetadata(stack.getItemDamage()));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean worksWith(final int referenceId, final int referenceMetadata) {
|
||||
for (ItemStack supportedBlock : blocks) {
|
||||
if (supportedBlock != null && supportedBlock.getItem() instanceof ItemBlock) {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package li.cil.oc.api.prefab;
|
||||
|
||||
import li.cil.oc.api.Driver;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
@ -13,9 +12,6 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
* values). It also takes care of creating and getting the tag compound on an
|
||||
* item stack to save data to or load data from.
|
||||
* <p/>
|
||||
* Note that if you use this prefab you <em>must instantiate your driver in the
|
||||
* init phase</em>, since it automatically registers itself with OpenComputers.
|
||||
* <p/>
|
||||
* You still have to specify your component's slot type and provide the
|
||||
* implementation for creating its environment, if any.
|
||||
*
|
||||
@ -27,11 +23,6 @@ public abstract class DriverItem implements li.cil.oc.api.driver.Item {
|
||||
|
||||
protected DriverItem(final ItemStack... items) {
|
||||
this.items = items.clone();
|
||||
|
||||
// Make the driver known with OpenComputers. This is required, otherwise
|
||||
// the mod won't know this driver exists. It must be called in the init
|
||||
// phase.
|
||||
Driver.add(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -12,8 +12,6 @@ import net.minecraft.client.Minecraft
|
||||
object GuiHandler extends CommonGuiHandler {
|
||||
override def getClientGuiElement(id: Int, player: EntityPlayer, world: World, x: Int, y: Int, z: Int): AnyRef =
|
||||
world.getBlockTileEntity(x, y, z) match {
|
||||
case adapter: tileentity.Adapter if id == GuiType.Adapter.id =>
|
||||
new gui.Adapter(player.inventory, adapter)
|
||||
case computer: tileentity.Case if id == GuiType.Case.id =>
|
||||
new gui.Case(player.inventory, computer)
|
||||
case drive: tileentity.DiskDrive if id == GuiType.DiskDrive.id =>
|
||||
|
@ -1,15 +0,0 @@
|
||||
package li.cil.oc.client.gui
|
||||
|
||||
import li.cil.oc.common.container
|
||||
import li.cil.oc.common.tileentity
|
||||
import net.minecraft.entity.player.InventoryPlayer
|
||||
import net.minecraft.util.StatCollector
|
||||
|
||||
class Adapter(playerInventory: InventoryPlayer, val adapter: tileentity.Adapter) extends DynamicGuiContainer(new container.Adapter(playerInventory, adapter)) {
|
||||
override def drawGuiContainerForegroundLayer(mouseX: Int, mouseY: Int) = {
|
||||
super.drawGuiContainerForegroundLayer(mouseX, mouseY)
|
||||
fontRenderer.drawString(
|
||||
StatCollector.translateToLocal(adapter.getInvName),
|
||||
8, 6, 0x404040)
|
||||
}
|
||||
}
|
@ -9,8 +9,6 @@ import net.minecraft.world.World
|
||||
abstract class GuiHandler extends IGuiHandler {
|
||||
override def getServerGuiElement(id: Int, player: EntityPlayer, world: World, x: Int, y: Int, z: Int) =
|
||||
world.getBlockTileEntity(x, y, z) match {
|
||||
case adapter: tileentity.Adapter if id == GuiType.Adapter.id =>
|
||||
new container.Adapter(player.inventory, adapter)
|
||||
case computer: tileentity.Case if id == GuiType.Case.id =>
|
||||
new container.Case(player.inventory, computer)
|
||||
case drive: tileentity.DiskDrive if id == GuiType.DiskDrive.id =>
|
||||
|
@ -3,7 +3,6 @@ package li.cil.oc.common
|
||||
object GuiType extends Enumeration {
|
||||
val
|
||||
|
||||
Adapter,
|
||||
Case,
|
||||
DiskDrive,
|
||||
Rack,
|
||||
|
@ -1,8 +1,8 @@
|
||||
package li.cil.oc.common.block
|
||||
|
||||
import java.util
|
||||
import li.cil.oc.{OpenComputers, Settings}
|
||||
import li.cil.oc.common.{GuiType, tileentity}
|
||||
import li.cil.oc.Settings
|
||||
import li.cil.oc.common.tileentity
|
||||
import li.cil.oc.util.Tooltip
|
||||
import net.minecraft.client.renderer.texture.IconRegister
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
@ -42,17 +42,6 @@ class Adapter(val parent: SimpleDelegator) extends SimpleDelegate {
|
||||
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
||||
override def rightClick(world: World, x: Int, y: Int, z: Int, player: EntityPlayer,
|
||||
side: ForgeDirection, hitX: Float, hitY: Float, hitZ: Float) = {
|
||||
if (!player.isSneaking) {
|
||||
if (!world.isRemote) {
|
||||
player.openGui(OpenComputers, GuiType.Adapter.id, world, x, y, z)
|
||||
}
|
||||
true
|
||||
}
|
||||
else false
|
||||
}
|
||||
|
||||
override def neighborBlockChanged(world: World, x: Int, y: Int, z: Int, blockId: Int) =
|
||||
world.getBlockTileEntity(x, y, z) match {
|
||||
case adapter: tileentity.Adapter => adapter.neighborChanged()
|
||||
|
@ -1,34 +0,0 @@
|
||||
package li.cil.oc.common.container
|
||||
|
||||
import li.cil.oc.common.tileentity
|
||||
import net.minecraft.entity.player.{EntityPlayer, InventoryPlayer}
|
||||
import net.minecraft.inventory.Slot
|
||||
import net.minecraft.item.ItemStack
|
||||
|
||||
class Adapter(playerInventory: InventoryPlayer, adapter: tileentity.Adapter) extends Player(playerInventory, adapter) {
|
||||
addSlotToContainer(new ComponentSlot(otherInventory, 0, 80, 35) {
|
||||
override def decrStackSize(amount: Int) = {
|
||||
val stack = super.decrStackSize(math.max(amount, 1))
|
||||
if (stack == null || stack.stackSize < 1) null
|
||||
else stack
|
||||
}
|
||||
})
|
||||
addPlayerInventorySlots(8, 84)
|
||||
|
||||
override def slotClick(index: Int, mouseClick: Int, holdingShift: Int, player: EntityPlayer) = {
|
||||
if (index == 0) clearIfNecessary(player.inventory.getItemStack)
|
||||
super.slotClick(index, mouseClick, holdingShift, player)
|
||||
}
|
||||
|
||||
override protected def tryTransferStackInSlot(from: Slot, offset: Int, length: Int, intoPlayerInventory: Boolean) = {
|
||||
if (!intoPlayerInventory) clearIfNecessary(from.getStack)
|
||||
super.tryTransferStackInSlot(from, offset, length, intoPlayerInventory)
|
||||
}
|
||||
|
||||
private def clearIfNecessary(stack: ItemStack) {
|
||||
inventorySlots.get(0) match {
|
||||
case slot: Slot if stack == null || slot.isItemValid(stack) => slot.putStack(null)
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
}
|
@ -3,15 +3,12 @@ package li.cil.oc.common.tileentity
|
||||
import li.cil.oc.api.network._
|
||||
import li.cil.oc.server.driver
|
||||
import li.cil.oc.{Settings, api}
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.item.{ItemBlock, ItemStack}
|
||||
import net.minecraft.nbt.{NBTTagList, NBTTagCompound}
|
||||
import net.minecraftforge.common.ForgeDirection
|
||||
import scala.collection.convert.WrapAsScala._
|
||||
import scala.{Array, Some}
|
||||
|
||||
class Adapter extends Environment with Inventory with Analyzable {
|
||||
class Adapter extends Environment with Analyzable {
|
||||
val node = api.Network.newNode(this, Visibility.Network).create()
|
||||
|
||||
private val blocks = Array.fill[Option[(ManagedEnvironment, api.driver.Block)]](6)(None)
|
||||
@ -40,21 +37,15 @@ class Adapter extends Environment with Inventory with Analyzable {
|
||||
driver.Registry.blockDriverFor(world, x, y, z) match {
|
||||
case Some(newDriver) => blocks(d.ordinal()) match {
|
||||
case Some((oldEnvironment, driver)) =>
|
||||
if (newDriver != driver || !isBlockSupported(x, y, z)) {
|
||||
if (newDriver != driver) {
|
||||
// This is... odd. Maybe moved by some other mod?
|
||||
node.disconnect(oldEnvironment.node)
|
||||
if (isBlockSupported(x, y, z)) {
|
||||
val environment = newDriver.createEnvironment(world, x, y, z)
|
||||
blocks(d.ordinal()) = Some((environment, newDriver))
|
||||
blocksData(d.ordinal()) = Some(new BlockData(environment.getClass.getName, new NBTTagCompound()))
|
||||
node.connect(environment.node)
|
||||
}
|
||||
else {
|
||||
blocks(d.ordinal()) = None
|
||||
blocksData(d.ordinal()) = None
|
||||
}
|
||||
val environment = newDriver.createEnvironment(world, x, y, z)
|
||||
blocks(d.ordinal()) = Some((environment, newDriver))
|
||||
blocksData(d.ordinal()) = Some(new BlockData(environment.getClass.getName, new NBTTagCompound()))
|
||||
node.connect(environment.node)
|
||||
} // else: the more things change, the more they stay the same.
|
||||
case _ if isBlockSupported(x, y, z) =>
|
||||
case _ =>
|
||||
// A challenger appears.
|
||||
val environment = newDriver.createEnvironment(world, x, y, z)
|
||||
blocks(d.ordinal()) = Some((environment, newDriver))
|
||||
@ -65,7 +56,6 @@ class Adapter extends Environment with Inventory with Analyzable {
|
||||
}
|
||||
blocksData(d.ordinal()) = Some(new BlockData(environment.getClass.getName, new NBTTagCompound()))
|
||||
node.connect(environment.node)
|
||||
case _ => // Not supported by filter.
|
||||
}
|
||||
case _ => blocks(d.ordinal()) match {
|
||||
case Some((environment, driver)) =>
|
||||
@ -93,11 +83,6 @@ class Adapter extends Environment with Inventory with Analyzable {
|
||||
override def readFromNBT(nbt: NBTTagCompound) {
|
||||
super.readFromNBT(nbt)
|
||||
|
||||
items(0) match {
|
||||
case Some(stack) if !driver.Registry.hasBlockDriverFor(world, stack) => setInventorySlotContents(0, null)
|
||||
case _ =>
|
||||
}
|
||||
|
||||
val blocksNbt = nbt.getTagList(Settings.namespace + "adapter.blocks")
|
||||
(0 until (blocksNbt.tagCount min blocksData.length)).
|
||||
map(blocksNbt.tagAt).
|
||||
@ -132,50 +117,6 @@ class Adapter extends Environment with Inventory with Analyzable {
|
||||
nbt.setTag(Settings.namespace + "adapter.blocks", blocksNbt)
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
||||
def getSizeInventory = 1
|
||||
|
||||
def getInvName = Settings.namespace + "container.Adapter"
|
||||
|
||||
def getInventoryStackLimit = 0
|
||||
|
||||
override def getInventoryStackRequired = 0
|
||||
|
||||
def isItemValidForSlot(i: Int, stack: ItemStack) =
|
||||
stack != null && stack.stackSize > 0 && driver.Registry.hasBlockDriverFor(world, stack)
|
||||
|
||||
override def onInventoryChanged() {
|
||||
super.onInventoryChanged()
|
||||
neighborChanged()
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
||||
private def isBlockSupported(x: Int, y: Int, z: Int) =
|
||||
items(0) match {
|
||||
case Some(stack) =>
|
||||
(stack.getItem match {
|
||||
case itemBlock: ItemBlock =>
|
||||
// Straightforward item block check.
|
||||
val blockId = itemBlock.getBlockID
|
||||
val metadata = itemBlock.getMetadata(stack.getItemDamage)
|
||||
world.getBlockId(x, y, z) == blockId && world.getBlockMetadata(x, y, z) == metadata
|
||||
case _ => false
|
||||
}) || {
|
||||
// Backward check: dropped items from block.
|
||||
val blockId = world.getBlockId(x, y, z)
|
||||
val isValidBlock = blockId >= 0 && blockId < Block.blocksList.length && Block.blocksList(blockId) != null
|
||||
if (isValidBlock) {
|
||||
val block = Block.blocksList(blockId)
|
||||
stack.itemID == block.idDropped(0, world.rand, 0) &&
|
||||
stack.getItemDamage == block.getDamageValue(world, x, y, z)
|
||||
}
|
||||
else false
|
||||
}
|
||||
case _ => false
|
||||
}
|
||||
|
||||
private class BlockData(val name: String, val data: NBTTagCompound)
|
||||
|
||||
}
|
||||
|
@ -17,8 +17,6 @@ class CompoundBlockDriver(val blocks: driver.Block*) extends driver.Block {
|
||||
else new CompoundBlockEnvironment(tryGetName(world, x, y, z), list: _*)
|
||||
}
|
||||
|
||||
override def worksWith(world: World, stack: ItemStack) = blocks.forall(_.worksWith(world, stack))
|
||||
|
||||
override def worksWith(world: World, x: Int, y: Int, z: Int) = blocks.forall(_.worksWith(world, x, y, z))
|
||||
|
||||
override def equals(obj: Any) = obj match {
|
||||
|
@ -38,8 +38,6 @@ private[oc] object Registry extends api.detail.DriverAPI {
|
||||
if (!blocks.contains(driver)) items += driver
|
||||
}
|
||||
|
||||
def hasBlockDriverFor(world: World, stack: ItemStack) = blocks.exists(_.worksWith(world, stack))
|
||||
|
||||
def blockDriverFor(world: World, x: Int, y: Int, z: Int) =
|
||||
blocks.filter(_.worksWith(world, x, y, z)) match {
|
||||
case drivers if drivers.length == 1 => Some(drivers.head)
|
||||
|
@ -4,8 +4,6 @@ import li.cil.oc.api.driver
|
||||
import li.cil.oc.server.component
|
||||
import li.cil.oc.util.mods.RedstoneInMotion
|
||||
import net.minecraft.world.World
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.item.ItemStack
|
||||
|
||||
object Carriage extends driver.Block {
|
||||
def worksWith(world: World, x: Int, y: Int, z: Int) =
|
||||
@ -14,8 +12,6 @@ object Carriage extends driver.Block {
|
||||
case _ => false
|
||||
}
|
||||
|
||||
def worksWith(world: World, stack: ItemStack) = RedstoneInMotion.isCarriageController(stack)
|
||||
|
||||
def createEnvironment(world: World, x: Int, y: Int, z: Int) =
|
||||
world.getBlockTileEntity(x, y, z) match {
|
||||
case entity if RedstoneInMotion.isCarriageController(entity) => new component.Carriage(entity)
|
||||
|
@ -3,7 +3,6 @@ package li.cil.oc.server.driver.block
|
||||
import li.cil.oc.api.driver
|
||||
import li.cil.oc.server.component
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.item.{ItemBlock, ItemStack}
|
||||
import net.minecraft.tileentity.TileEntityCommandBlock
|
||||
import net.minecraft.world.World
|
||||
|
||||
@ -11,11 +10,6 @@ object CommandBlock extends driver.Block {
|
||||
def worksWith(world: World, x: Int, y: Int, z: Int) =
|
||||
world.getBlockId(x, y, z) == Block.commandBlock.blockID
|
||||
|
||||
def worksWith(world: World, stack: ItemStack) = stack != null && (stack.getItem match {
|
||||
case itemBlock: ItemBlock => itemBlock.getBlockID == Block.commandBlock.blockID
|
||||
case _ => false
|
||||
})
|
||||
|
||||
def createEnvironment(world: World, x: Int, y: Int, z: Int) =
|
||||
world.getBlockTileEntity(x, y, z) match {
|
||||
case block: TileEntityCommandBlock => new component.CommandBlock(block)
|
||||
|
@ -3,7 +3,6 @@ package li.cil.oc.server.driver.block
|
||||
import li.cil.oc.api.driver
|
||||
import li.cil.oc.server.component
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.item.{ItemBlock, ItemStack}
|
||||
import net.minecraft.tileentity.TileEntityNote
|
||||
import net.minecraft.world.World
|
||||
|
||||
@ -11,11 +10,6 @@ object NoteBlock extends driver.Block {
|
||||
def worksWith(world: World, x: Int, y: Int, z: Int) =
|
||||
world.getBlockId(x, y, z) == Block.music.blockID
|
||||
|
||||
def worksWith(world: World, stack: ItemStack) = stack != null && (stack.getItem match {
|
||||
case itemBlock: ItemBlock => itemBlock.getBlockID == Block.music.blockID
|
||||
case _ => false
|
||||
})
|
||||
|
||||
def createEnvironment(world: World, x: Int, y: Int, z: Int) =
|
||||
world.getBlockTileEntity(x, y, z) match {
|
||||
case block: TileEntityNote => new component.NoteBlock(block)
|
||||
|
@ -106,7 +106,6 @@ oc:gui.Terminal.InvalidKey=Ungültiger Schlüssel, vermutlich wurde eine andere
|
||||
oc:gui.Terminal.OutOfRange=Kein Signal.
|
||||
|
||||
# Containers
|
||||
oc:container.Adapter=Adapter
|
||||
oc:container.Case=Computer
|
||||
oc:container.DiskDrive=Diskettenlaufwerk
|
||||
oc:container.Rack=Serverschrank
|
||||
|
@ -106,7 +106,6 @@ oc:gui.Terminal.InvalidKey=Invalid key, most likely another terminal has been bo
|
||||
oc:gui.Terminal.OutOfRange=No signal.
|
||||
|
||||
# Containers
|
||||
oc:container.Adapter=Adapter
|
||||
oc:container.Case=Computer
|
||||
oc:container.DiskDrive=Disk Drive
|
||||
oc:container.Rack=Server Rack
|
||||
|
@ -76,7 +76,6 @@ oc:gui.Robot.TurnOff=Eteindre
|
||||
oc:gui.Robot.TurnOn=Allumer
|
||||
|
||||
# Containers
|
||||
oc:container.Adapter=Adaptateur
|
||||
oc:container.Case=Ordinateur
|
||||
oc:container.DiskDrive=Disque dur
|
||||
|
||||
|
@ -80,7 +80,6 @@ oc:gui.Robot.TurnOff=Desligar
|
||||
oc:gui.Robot.TurnOn=Ligar
|
||||
|
||||
# Containers
|
||||
oc:container.Adapter=Adaptador
|
||||
oc:container.Case=Computador
|
||||
oc:container.DiskDrive=Drive de Disquetes
|
||||
|
||||
|
@ -69,7 +69,6 @@ oc:gui.Robot.TurnOff=关闭
|
||||
oc:gui.Robot.TurnOn=开启
|
||||
|
||||
# Containers
|
||||
oc:container.Adapter=适配器
|
||||
oc:container.Case=计算机
|
||||
oc:container.DiskDrive=磁盘驱动
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user