diff --git a/src/main/scala/resonantinduction/atomic/machine/reactor/TileReactorCell.scala b/src/main/scala/resonantinduction/atomic/machine/reactor/TileReactorCell.scala index 9ccc712a2..a7d11c9b1 100644 --- a/src/main/scala/resonantinduction/atomic/machine/reactor/TileReactorCell.scala +++ b/src/main/scala/resonantinduction/atomic/machine/reactor/TileReactorCell.scala @@ -317,7 +317,7 @@ class TileReactorCell extends TileInventory(Material.iron) with IMultiBlockStruc { } - def getMultiBlockVectors: Array[Vector3] = + override def getMultiBlockVectors: java.lang.Iterable[Vector3] = { val vectors: List[Vector3] = new ArrayList[Vector3] val checkPosition: Vector3 = new Vector3(this) @@ -330,11 +330,11 @@ class TileReactorCell extends TileInventory(Material.iron) with IMultiBlockStruc } else { - return vectors.toArray(new Array[Vector3](0)) + return vectors } checkPosition.y += 1 } - return vectors.toArray(new Array[Vector3](0)) + return vectors } def getPosition: Vector3 = diff --git a/src/main/scala/resonantinduction/electrical/tesla/TileTesla.java b/src/main/scala/resonantinduction/electrical/tesla/TileTesla.java index 54e7797b4..6c55c0e9d 100644 --- a/src/main/scala/resonantinduction/electrical/tesla/TileTesla.java +++ b/src/main/scala/resonantinduction/electrical/tesla/TileTesla.java @@ -599,7 +599,7 @@ public class TileTesla extends TileElectric implements IMultiBlockStructure getMultiBlockVectors() { List vectors = new ArrayList(); @@ -621,7 +621,7 @@ public class TileTesla extends TileElectric implements IMultiBlockStructure= 10) - { - doWork(); - doWork = false; - place_delay = 0; - } - } - } - - public void work() - { - if (isIndirectlyPowered()) - { - doWork = true; - place_delay = 0; - } - } - - public void doWork() - { - if (isIndirectlyPowered()) - { - ForgeDirection dir = getDirection(); - Vector3 check = position().add(dir); - VectorWorld put = (VectorWorld) position().add(dir.getOpposite()); - - Block block = check.getBlock(world()); - - if (block != null) - { - int candidateMeta = world().getBlockMetadata(check.xi(), check.yi(), check.zi()); - boolean flag = true; - - //Get items dropped - ArrayList drops = block.getDrops(getWorldObj(), check.xi(), check.yi(), check.zi(), candidateMeta, 0); - - for (ItemStack stack : drops) - { - //Insert into tile if one exists - ItemStack insert = stack.copy(); - insert = getInvHandler().storeItem(insert, this.getDirection().getOpposite()); - //If not spit items into world - if (insert != null) - { - getInvHandler().throwItem(this.getDirection().getOpposite(), insert); - } - } - - //Destroy block - ResonantInduction.proxy().renderBlockParticle(worldObj, check.xi(), check.yi(), check.zi(), new Vector3((Math.random() - 0.5f) * 3, (Math.random() - 0.5f) * 3, (Math.random() - 0.5f) * 3), Block.getIdFromBlock(block), 1); - - getWorldObj().setBlockToAir(check.xi(), check.yi(), check.zi()); - getWorldObj().playAuxSFX(1012, check.xi(), check.yi(), check.zi(), 0); - - } - } - } - - @Override - public PacketTile getDescPacket() - { - NBTTagCompound nbt = new NBTTagCompound(); - writeToNBT(nbt); - return new PacketTile(this, nbt); - } - - @Override - @SideOnly(Side.CLIENT) - public IIcon getIcon(IBlockAccess access, int side) - { - int meta = access.getBlockMetadata(x(), y(), z()); - - if (side == meta) - { - return iconFront; - } - else if (side == (meta ^ 1)) - { - return iconBack; - } - - return getIcon(); - } - - @Override - @SideOnly(Side.CLIENT) - public IIcon getIcon(int side, int meta) - { - if (side == (meta ^ 1)) - { - return iconFront; - } - else if (side == meta) - { - return iconBack; - } - - return getIcon(); - } - - @Override - @SideOnly(Side.CLIENT) - public void registerIcons(IIconRegister iconRegister) - { - super.registerIcons(iconRegister); - iconFront = iconRegister.registerIcon(getTextureName() + "_front"); - iconBack = iconRegister.registerIcon(getTextureName() + "_back"); - } - - @Override - public void read(ByteBuf data, EntityPlayer player, PacketType type) - { - try - { - readFromNBT(ByteBufUtils.readTag(data)); - } - catch (Exception e) - { - e.printStackTrace(); - } - } -} diff --git a/src/main/scala/resonantinduction/mechanical/machine/edit/TileBreaker.scala b/src/main/scala/resonantinduction/mechanical/machine/edit/TileBreaker.scala new file mode 100644 index 000000000..9db529d82 --- /dev/null +++ b/src/main/scala/resonantinduction/mechanical/machine/edit/TileBreaker.scala @@ -0,0 +1,174 @@ +package resonantinduction.mechanical.machine.edit + +import java.util.ArrayList +import cpw.mods.fml.common.network.ByteBufUtils +import io.netty.buffer.ByteBuf +import net.minecraft.block.Block +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.minecraft.world.IBlockAccess +import net.minecraftforge.common.util.ForgeDirection +import resonant.api.IRotatable +import resonant.content.prefab.java.TileAdvanced +import resonant.lib.network.discriminator.PacketTile +import resonant.lib.network.discriminator.PacketType +import resonant.lib.network.handle.IPacketReceiver +import resonant.lib.utility.inventory.InternalInventoryHandler +import resonantinduction.core.ResonantInduction +import universalelectricity.core.transform.vector.Vector3 +import cpw.mods.fml.relauncher.Side +import cpw.mods.fml.relauncher.SideOnly +import universalelectricity.core.transform.vector.VectorWorld + +/** + * @author tgame14 + * @since 18/03/14 + */ +object TileBreaker +{ + @SideOnly(Side.CLIENT) private var iconFront: IIcon = null + @SideOnly(Side.CLIENT) private var iconBack: IIcon = null +} + +class TileBreaker extends TileAdvanced(Material.iron) with IRotatable with IPacketReceiver +{ + private var _doWork : Boolean = false + private var invHandler: InternalInventoryHandler = null + private var place_delay: Int = 0 + + def getInvHandler: InternalInventoryHandler = + { + if (invHandler == null) + { + invHandler = new InternalInventoryHandler(this) + } + return invHandler + } + + override def onAdded + { + work + } + + override def onNeighborChanged(block: Block) + { + work + } + + override def update + { + if (_doWork) + { + if (place_delay < java.lang.Byte.MAX_VALUE) + { + place_delay += 1 + } + if (place_delay >= 10) + { + _doWork = false + place_delay = 0 + } + } + } + + def work + { + if (isIndirectlyPowered) + { + _doWork = true + place_delay = 0 + } + } + + def doWork + { + if (isIndirectlyPowered) + { + val dir: ForgeDirection = getDirection + val check: Vector3 = position.add(dir) + val put: VectorWorld = position.add(dir.getOpposite).asInstanceOf[VectorWorld] + val block: Block = check.getBlock(world) + if (block != null) + { + val candidateMeta: Int = world.getBlockMetadata(check.xi, check.yi, check.zi) + val flag: Boolean = true + val drops: ArrayList[ItemStack] = block.getDrops(getWorldObj, check.xi, check.yi, check.zi, candidateMeta, 0) + import scala.collection.JavaConversions._ + for (stack <- drops) + { + var insert: ItemStack = stack.copy + insert = getInvHandler.storeItem(insert, this.getDirection.getOpposite) + if (insert != null) + { + getInvHandler.throwItem(this.getDirection.getOpposite, insert) + } + } + ResonantInduction.proxy.renderBlockParticle(worldObj, check.xi, check.yi, check.zi, new Vector3((Math.random - 0.5f) * 3, (Math.random - 0.5f) * 3, (Math.random - 0.5f) * 3), Block.getIdFromBlock(block), 1) + getWorldObj.setBlockToAir(check.xi, check.yi, check.zi) + getWorldObj.playAuxSFX(1012, check.xi, check.yi, check.zi, 0) + } + } + } + + override def getDescPacket: PacketTile = + { + val nbt: NBTTagCompound = new NBTTagCompound + writeToNBT(nbt) + return new PacketTile(this, nbt) + } + + @SideOnly(Side.CLIENT) override def getIcon(access: IBlockAccess, side: Int): IIcon = + { + val meta: Int = access.getBlockMetadata(x, y, z) + if (side == meta) + { + return TileBreaker.iconFront + } + else if (side == (meta ^ 1)) + { + return TileBreaker.iconBack + } + return getIcon + } + + @SideOnly(Side.CLIENT) + override def getIcon(side: Int, meta: Int): IIcon = + { + if (side == (meta ^ 1)) + { + return TileBreaker.iconFront + } + else if (side == meta) + { + return TileBreaker.iconBack + } + return getIcon + } + + @SideOnly(Side.CLIENT) + override def registerIcons(iconRegister: IIconRegister) + { + super.registerIcons(iconRegister) + TileBreaker.iconFront = iconRegister.registerIcon(getTextureName + "_front") + TileBreaker.iconBack = iconRegister.registerIcon(getTextureName + "_back") + } + + def read(data: ByteBuf, player: EntityPlayer, `type`: PacketType) + { + try + { + readFromNBT(ByteBufUtils.readTag(data)) + } + catch + { + case e: Exception => + { + e.printStackTrace + } + } + } +} \ No newline at end of file diff --git a/src/main/scala/resonantinduction/mechanical/machine/edit/TilePlacer.java b/src/main/scala/resonantinduction/mechanical/machine/edit/TilePlacer.java deleted file mode 100644 index 7bdefcb4b..000000000 --- a/src/main/scala/resonantinduction/mechanical/machine/edit/TilePlacer.java +++ /dev/null @@ -1,266 +0,0 @@ -package resonantinduction.mechanical.machine.edit; - -import java.util.EnumSet; - -import cpw.mods.fml.common.network.ByteBufUtils; -import io.netty.buffer.ByteBuf; -import net.minecraft.block.Block; -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.ChatComponentText; -import net.minecraft.util.IIcon; -import net.minecraft.world.IBlockAccess; -import net.minecraftforge.common.util.ForgeDirection; - -import org.lwjgl.opengl.GL11; - -import resonant.api.IRotatable; -import resonant.lib.network.discriminator.PacketTile; -import resonant.lib.network.discriminator.PacketType; -import resonant.lib.network.handle.IPacketReceiver; -import resonant.lib.render.RenderItemOverlayUtility; -import resonant.lib.utility.LanguageUtility; -import resonant.lib.utility.inventory.InternalInventoryHandler; -import resonant.lib.utility.inventory.InventoryUtility; -import universalelectricity.core.transform.vector.Vector3; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import resonant.lib.content.prefab.java.TileInventory; - -/** - * @author tgame14 - * @since 18/03/14 - */ -public class TilePlacer extends TileInventory implements IRotatable, IPacketReceiver -{ - @SideOnly(Side.CLIENT) - private static IIcon iconFront, iconBack; - private boolean doWork = false; - private boolean autoPullItems = false; - private byte placeDelay = 0; - private InternalInventoryHandler invHandler; - - public TilePlacer() - { - super(Material.rock); - setSizeInventory(1); - normalRender(false); - forceStandardRender(true); - renderStaticBlock_$eq(true); - this.rotationMask_$eq(Byte.parseByte("111111", 2)); - } - - public InternalInventoryHandler getInvHandler() - { - if (invHandler == null) - { - invHandler = new InternalInventoryHandler(this); - } - return invHandler; - } - - @Override - public void onAdded() - { - work(); - } - - @Override - public void onNeighborChanged(Block block) - { - work(); - } - - @Override - public void start() - { - super.start(); - } - - @Override - public void update() - { - super.update(); - if (autoPullItems && this.ticks() % 5 == 0) - { - if (getStackInSlot(0) == null) - { - this.setInventorySlotContents(0, this.getInvHandler().tryGrabFromPosition(this.getDirection().getOpposite(), 1)); - } - } - if (doWork) - { - if (placeDelay < Byte.MAX_VALUE) - { - placeDelay++; - } - - if (placeDelay >= 5) - { - doWork(); - doWork = false; - } - } - - } - - public void work() - { - if (isIndirectlyPowered()) - { - doWork = true; - placeDelay = 0; - } - } - - public void doWork() - { - //Tries to place the item stack into the world - int side = 0; - Vector3 placePos = position().add(getDirection()); - ItemStack placeStack = getStackInSlot(0); - - if (InventoryUtility.placeItemBlock(world(), placePos.xi(), placePos.yi(), placePos.zi(), placeStack, side)) - { - if (placeStack.stackSize <= 0) - { - setInventorySlotContents(0, null); - } - - markUpdate(); - doWork = false; - } - } - - @Override - public boolean use(EntityPlayer player, int hitSide, Vector3 hit) - { - interactCurrentItem(this, 0, player); - return true; - } - - public boolean configure(EntityPlayer player, int side, Vector3 hit) - { - if (player.isSneaking()) - { - this.autoPullItems = !this.autoPullItems; - player.addChatComponentMessage(new ChatComponentText("AutoExtract: " + this.autoPullItems)); - return true; - } - return super.configure(player, side, hit); - } - - @Override - public PacketTile getDescPacket() - { - NBTTagCompound nbt = new NBTTagCompound(); - writeToNBT(nbt); - return new PacketTile(this, nbt); - } - - @Override - public void onInventoryChanged() - { - sendPacket(getDescPacket()); - } - - @Override - public void read(ByteBuf data, EntityPlayer player, PacketType type) - { - try - { - readFromNBT(ByteBufUtils.readTag(data)); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - @Override - public void readFromNBT(NBTTagCompound nbt) - { - super.readFromNBT(nbt); - this.autoPullItems = nbt.getBoolean("autoPull"); - } - - /** - * Writes a tile entity to NBT. - */ - @Override - public void writeToNBT(NBTTagCompound nbt) - { - super.writeToNBT(nbt); - nbt.setBoolean("autoPull", this.autoPullItems); - } - - @Override - public boolean canStore(ItemStack stack, int slot, ForgeDirection side) - { - return side == this.getDirection().getOpposite() && slot == 0; - } - - @Override - @SideOnly(Side.CLIENT) - public IIcon getIcon(IBlockAccess access, int side) - { - int meta = access.getBlockMetadata(x(), y(), z()); - - if (side == meta) - { - return iconFront; - } - else if (side == (meta ^ 1)) - { - return iconBack; - } - - return getIcon(); - } - - @Override - @SideOnly(Side.CLIENT) - public IIcon getIcon(int side, int meta) - { - if (side == (meta ^ 1)) - { - return iconFront; - } - else if (side == meta) - { - return iconBack; - } - - return getIcon(); - } - - @Override - @SideOnly(Side.CLIENT) - public void registerIcons(IIconRegister iconRegister) - { - super.registerIcons(iconRegister); - iconFront = iconRegister.registerIcon(getTextureName() + "_front"); - iconBack = iconRegister.registerIcon(getTextureName() + "_back"); - } - - - @Override - public void renderDynamic(Vector3 position, float frame, int pass) - { - if (world() != null) - { - EnumSet set = EnumSet.allOf(ForgeDirection.class); - set.remove(getDirection()); - set.remove(getDirection().getOpposite()); - set.remove(ForgeDirection.UP); - set.remove(ForgeDirection.DOWN); - GL11.glPushMatrix(); - RenderItemOverlayUtility.renderItemOnSides(this, getStackInSlot(0), position.x(), position.y(), position.z(), LanguageUtility.getLocal("tooltip.noOutput"), set); - GL11.glPopMatrix(); - } - } -} diff --git a/src/main/scala/resonantinduction/mechanical/machine/edit/TilePlacer.scala b/src/main/scala/resonantinduction/mechanical/machine/edit/TilePlacer.scala new file mode 100644 index 000000000..66f6d02b0 --- /dev/null +++ b/src/main/scala/resonantinduction/mechanical/machine/edit/TilePlacer.scala @@ -0,0 +1,237 @@ +package resonantinduction.mechanical.machine.edit + +import java.util.EnumSet + +import cpw.mods.fml.common.network.ByteBufUtils +import cpw.mods.fml.relauncher.{Side, SideOnly} +import io.netty.buffer.ByteBuf +import net.minecraft.block.Block +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.{ChatComponentText, IIcon} +import net.minecraft.world.IBlockAccess +import net.minecraftforge.common.util.ForgeDirection +import org.lwjgl.opengl.GL11 +import resonant.api.IRotatable +import resonant.lib.content.prefab.java.TileInventory +import resonant.lib.network.discriminator.{PacketTile, PacketType} +import resonant.lib.network.handle.IPacketReceiver +import resonant.lib.render.RenderItemOverlayUtility +import resonant.lib.utility.LanguageUtility +import resonant.lib.utility.inventory.{InternalInventoryHandler, InventoryUtility} +import universalelectricity.core.transform.vector.Vector3 + +/** + * @author tgame14 + * @since 18/03/14 + */ +object TilePlacer +{ + @SideOnly(Side.CLIENT) private var iconFront: IIcon = null + @SideOnly(Side.CLIENT) private var iconBack: IIcon = null +} + +class TilePlacer extends TileInventory(Material.rock) with IRotatable with IPacketReceiver +{ + private var _doWork: Boolean = false + private var autoPullItems: Boolean = false + private var placeDelay: Int = 0 + private var invHandler: InternalInventoryHandler = null + + //Constructor + setSizeInventory(1) + normalRender = false + forceStandardRender = true + renderStaticBlock = true + this.rotationMask = 63 + + + def getInvHandler: InternalInventoryHandler = + { + if (invHandler == null) + { + invHandler = new InternalInventoryHandler(this) + } + return invHandler + } + + override def onAdded + { + work + } + + override def onNeighborChanged(block: Block) + { + work + } + + override def start + { + super.start + } + + override def update + { + super.update + if (autoPullItems && this.ticks % 5 == 0) + { + if (getStackInSlot(0) == null) + { + this.setInventorySlotContents(0, this.getInvHandler.tryGrabFromPosition(this.getDirection.getOpposite, 1)) + } + } + if (_doWork) + { + if (placeDelay < java.lang.Byte.MAX_VALUE) + { + placeDelay += 1 + } + if (placeDelay >= 5) + { + doWork + _doWork = false + } + } + } + + def work + { + if (isIndirectlyPowered) + { + _doWork = true + placeDelay = 0 + } + } + + def doWork + { + val side: Int = 0 + val placePos: Vector3 = position.add(getDirection) + val placeStack: ItemStack = getStackInSlot(0) + if (InventoryUtility.placeItemBlock(world, placePos.xi, placePos.yi, placePos.zi, placeStack, side)) + { + if (placeStack.stackSize <= 0) + { + setInventorySlotContents(0, null) + } + markUpdate + _doWork = false + } + } + + override def use(player: EntityPlayer, hitSide: Int, hit: Vector3): Boolean = + { + interactCurrentItem(this, 0, player) + return true + } + + override def configure(player: EntityPlayer, side: Int, hit: Vector3): Boolean = + { + if (player.isSneaking) + { + this.autoPullItems = !this.autoPullItems + player.addChatComponentMessage(new ChatComponentText("AutoExtract: " + this.autoPullItems)) + return true + } + return super.configure(player, side, hit) + } + + override def getDescPacket: PacketTile = + { + val nbt: NBTTagCompound = new NBTTagCompound + writeToNBT(nbt) + return new PacketTile(this, nbt) + } + + override def onInventoryChanged + { + sendPacket(getDescPacket) + } + + def read(data: ByteBuf, player: EntityPlayer, `type`: PacketType) + { + try + { + readFromNBT(ByteBufUtils.readTag(data)) + } + catch + { + case e: Exception => + { + e.printStackTrace + } + } + } + + override def readFromNBT(nbt: NBTTagCompound) + { + super.readFromNBT(nbt) + this.autoPullItems = nbt.getBoolean("autoPull") + } + + /** + * Writes a tile entity to NBT. + */ + override def writeToNBT(nbt: NBTTagCompound) + { + super.writeToNBT(nbt) + nbt.setBoolean("autoPull", this.autoPullItems) + } + + override def canStore(stack: ItemStack, slot: Int, side: ForgeDirection): Boolean = + { + return side == this.getDirection.getOpposite && slot == 0 + } + + @SideOnly(Side.CLIENT) override def getIcon(access: IBlockAccess, side: Int): IIcon = + { + val meta: Int = access.getBlockMetadata(x, y, z) + if (side == meta) + { + return TilePlacer.iconFront + } + else if (side == (meta ^ 1)) + { + return TilePlacer.iconBack + } + return getIcon + } + + @SideOnly(Side.CLIENT) override def getIcon(side: Int, meta: Int): IIcon = + { + if (side == (meta ^ 1)) + { + return TilePlacer.iconFront + } + else if (side == meta) + { + return TilePlacer.iconBack + } + return getIcon + } + + @SideOnly(Side.CLIENT) override def registerIcons(iconRegister: IIconRegister) + { + super.registerIcons(iconRegister) + TilePlacer.iconFront = iconRegister.registerIcon(getTextureName + "_front") + TilePlacer.iconBack = iconRegister.registerIcon(getTextureName + "_back") + } + + override def renderDynamic(position: Vector3, frame: Float, pass: Int) + { + if (world != null) + { + val set: EnumSet[ForgeDirection] = EnumSet.allOf(classOf[ForgeDirection]) + set.remove(getDirection) + set.remove(getDirection.getOpposite) + set.remove(ForgeDirection.UP) + set.remove(ForgeDirection.DOWN) + GL11.glPushMatrix + RenderItemOverlayUtility.renderItemOnSides(this, getStackInSlot(0), position.x, position.y, position.z, LanguageUtility.getLocal("tooltip.noOutput"), set) + GL11.glPopMatrix + } + } +} \ No newline at end of file diff --git a/src/main/scala/resonantinduction/mechanical/mech/turbine/TileTurbine.java b/src/main/scala/resonantinduction/mechanical/mech/turbine/TileTurbine.java index 2d579f2af..eb2f0f6b7 100644 --- a/src/main/scala/resonantinduction/mechanical/mech/turbine/TileTurbine.java +++ b/src/main/scala/resonantinduction/mechanical/mech/turbine/TileTurbine.java @@ -129,7 +129,7 @@ public class TileTurbine extends TileMechanical implements IMultiBlockStructure< } @Override - public Vector3[] getMultiBlockVectors() + public Iterable getMultiBlockVectors() { //TODO replace with helper class that takes a direction and size input Set vectors = new HashSet(); @@ -150,7 +150,7 @@ public class TileTurbine extends TileMechanical implements IMultiBlockStructure< } } - return vectors.toArray(new Vector3[0]); + return vectors; } @Override