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

Sieve right click #28

Merged
merged 2 commits into from
Oct 3, 2016
Merged
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
16 changes: 16 additions & 0 deletions src/main/kotlin/com/cout970/magneticraft/block/BlockTableSieve.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import com.cout970.magneticraft.tileentity.TileTableSieve
import net.minecraft.block.ITileEntityProvider
import net.minecraft.block.material.Material
import net.minecraft.block.state.IBlockState
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.ItemStack
import net.minecraft.tileentity.TileEntity
import net.minecraft.util.EnumFacing
import net.minecraft.util.EnumHand
import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.Vec3d
import net.minecraft.world.IBlockAccess
Expand All @@ -25,5 +29,17 @@ object BlockTableSieve : BlockBase(Material.WOOD, "table_sieve"), ITileEntityPro
override fun isFullCube(state: IBlockState?) = false
override fun isVisuallyOpaque() = false

override fun onBlockActivated(world: World, pos: BlockPos, state: IBlockState, player: EntityPlayer, hand: EnumHand, heldItem: ItemStack?, side: EnumFacing?, hitX: Float, hitY: Float, hitZ: Float): Boolean {
if (heldItem != null) {
val tile = world.getTileEntity(pos) as TileTableSieve
if (tile.getRecipe(heldItem) != null) {
val inserted = tile.inventory.insertItem(0, heldItem, false)
player.setHeldItem(hand, inserted)
return true
}
}
return false
}

override fun createNewTileEntity(worldIn: World?, meta: Int): TileEntity? = TileTableSieve()
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,15 @@ class TileTableSieve : TileBase(), ITickable {

fun suckItems() {
val aabb = AxisAlignedBB(pos, pos.up().add(1.0, 1.0, 1.0))
val items = worldObj.getEntitiesInAABBexcluding(null, aabb, { it is EntityItem })
val items = worldObj.getEntitiesWithinAABB(EntityItem::class.java, aabb)
for (i in items) {
if (i !is EntityItem) continue
val item = i.entityItem
if (getRecipe(item) == null) continue
val inserted = inventory.insertItem(0, item, true)
if (inserted == null) {
inventory.insertItem(0, item.copy(), false)
val inserted = inventory.insertItem(0, item, false)
if (inserted != null) {
i.setEntityItemStack(inserted)
} else {
i.setDead()
} else if (inserted.stackSize != item.stackSize) {
inventory.insertItem(0, item.copy(), false)
item.stackSize = inserted.stackSize
}
}
}
Expand Down