mirror of
https://github.com/GTNewHorizons/bdlib.git
synced 2026-11-24 05:54:39 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da3e58b44b | ||
|
|
5bac374211 | ||
|
|
e41e203b7e | ||
|
|
0b87dd83e7 |
No files matched your search
+1
-1
@@ -14,7 +14,7 @@ buildscript {
|
|||||||
apply plugin: 'forge'
|
apply plugin: 'forge'
|
||||||
apply plugin: 'scala'
|
apply plugin: 'scala'
|
||||||
|
|
||||||
version = "1.2.2"
|
version = "1.2.3"
|
||||||
|
|
||||||
if (project.hasProperty('buildnum')) {
|
if (project.hasProperty('buildnum')) {
|
||||||
project.version = project.version + '.' + project.buildnum
|
project.version = project.version + '.' + project.buildnum
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ import cpw.mods.fml.common.versioning.{ArtifactVersion, VersionParser}
|
|||||||
import cpw.mods.fml.common.Loader
|
import cpw.mods.fml.common.Loader
|
||||||
import net.minecraftforge.oredict.ShapedOreRecipe
|
import net.minecraftforge.oredict.ShapedOreRecipe
|
||||||
import net.minecraft.world.biome.BiomeGenBase
|
import net.minecraft.world.biome.BiomeGenBase
|
||||||
|
import net.minecraftforge.common.ForgeDirection
|
||||||
|
import net.minecraft.tileentity.TileEntity
|
||||||
|
|
||||||
object Misc {
|
object Misc {
|
||||||
def iterNbtList[X](list: NBTTagList) =
|
def iterNbtList[X](list: NBTTagList) =
|
||||||
@@ -69,4 +71,16 @@ object Misc {
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Because writing this every time is awkward
|
||||||
|
def forgeDirection(i: Int) = ForgeDirection.values()(i)
|
||||||
|
|
||||||
|
// Easy replacement for various "if(foo.isInstanceOf[Bar]) foo.asInstanceOf[Bar]" constructs
|
||||||
|
def asInstanceOpt[T](v: Any, cls: Class[T]) =
|
||||||
|
if (cls.isInstance(v)) Some(v.asInstanceOf[T]) else None
|
||||||
|
|
||||||
|
def getNeighbourTile[T](origin: TileEntity, dir: ForgeDirection, cls: Class[T]) =
|
||||||
|
Option(origin.worldObj.getBlockTileEntity(origin.xCoord + dir.offsetX,
|
||||||
|
origin.yCoord + dir.offsetY, origin.zCoord + dir.offsetZ)) flatMap (asInstanceOpt(_, cls))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -13,8 +13,11 @@ import net.minecraft.item.ItemStack
|
|||||||
import net.minecraft.block.Block
|
import net.minecraft.block.Block
|
||||||
import cpw.mods.fml.common.registry.GameRegistry
|
import cpw.mods.fml.common.registry.GameRegistry
|
||||||
import net.bdew.lib.block.HasTE
|
import net.bdew.lib.block.HasTE
|
||||||
|
import net.bdew.lib.Misc
|
||||||
|
|
||||||
class BlockManager(val ids: IdManager) {
|
class BlockManager(val ids: IdManager, addOldTileNames: Boolean = true) {
|
||||||
|
|
||||||
|
def this(ids: IdManager) = this(ids, true)
|
||||||
|
|
||||||
def regBlockCls[T <: Block](blockCls: Class[T], name: String, addStack: Boolean = true): T = {
|
def regBlockCls[T <: Block](blockCls: Class[T], name: String, addStack: Boolean = true): T = {
|
||||||
val block = blockCls.getConstructor(classOf[Int]).newInstance(ids.getBlockId(name): Integer)
|
val block = blockCls.getConstructor(classOf[Int]).newInstance(ids.getBlockId(name): Integer)
|
||||||
@@ -28,7 +31,12 @@ class BlockManager(val ids: IdManager) {
|
|||||||
GameRegistry.registerCustomItemStack(name, new ItemStack(block))
|
GameRegistry.registerCustomItemStack(name, new ItemStack(block))
|
||||||
|
|
||||||
if (block.isInstanceOf[HasTE[_]])
|
if (block.isInstanceOf[HasTE[_]])
|
||||||
GameRegistry.registerTileEntity(block.asInstanceOf[HasTE[_]].TEClass, name)
|
if (addOldTileNames)
|
||||||
|
GameRegistry.registerTileEntityWithAlternatives(block.asInstanceOf[HasTE[_]].TEClass,
|
||||||
|
"%s.%s".format(Misc.getActiveModId, name), name)
|
||||||
|
else
|
||||||
|
GameRegistry.registerTileEntity(block.asInstanceOf[HasTE[_]].TEClass,
|
||||||
|
"%s.%s".format(Misc.getActiveModId, name))
|
||||||
|
|
||||||
return block
|
return block
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
|
* https://github.com/bdew/bdlib
|
||||||
|
*
|
||||||
|
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||||
|
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||||
|
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.bdew.lib.covers
|
||||||
|
|
||||||
|
import net.bdew.lib.block.HasTE
|
||||||
|
import net.minecraft.world.{IBlockAccess, World}
|
||||||
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
|
import net.bdew.lib.Misc
|
||||||
|
import net.bdew.lib.items.ItemUtils
|
||||||
|
|
||||||
|
trait BlockCoverable[T <: TileCoverable] extends HasTE[T] {
|
||||||
|
override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer, face: Int, xoffs: Float, yoffs: Float, zoffs: Float): Boolean = {
|
||||||
|
val te = getTE(world, x, y, z)
|
||||||
|
val side = Misc.forgeDirection(face)
|
||||||
|
|
||||||
|
if (player.getCurrentEquippedItem == null && player.isSneaking) {
|
||||||
|
for (cover <- Option(te.covers(side).cval)) {
|
||||||
|
if (!world.isRemote) {
|
||||||
|
te.covers(side) := null
|
||||||
|
te.onCoversChanged()
|
||||||
|
ItemUtils.dropItemToPlayer(world, player, cover)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for {
|
||||||
|
activeStack <- Option(player.getCurrentEquippedItem)
|
||||||
|
activeItem <- Option(activeStack.getItem)
|
||||||
|
coverItem <- Misc.asInstanceOpt(activeItem, classOf[ItemCover])
|
||||||
|
if te.isValidCover(side, activeStack) && coverItem.isValidTile(te, activeStack)
|
||||||
|
} {
|
||||||
|
if (!world.isRemote) {
|
||||||
|
for (cover <- Option(te.covers(side).cval))
|
||||||
|
ItemUtils.throwItemAt(world, te.xCoord + side.offsetX, te.yCoord + side.offsetY, te.zCoord + side.offsetZ, cover.copy())
|
||||||
|
|
||||||
|
te.covers(side) := activeStack.splitStack(1)
|
||||||
|
|
||||||
|
if (activeStack.stackSize <= 0) player.inventory.setInventorySlotContents(player.inventory.currentItem, null)
|
||||||
|
te.onCoversChanged()
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
super.onBlockActivated(world, x, y, z, player, face, xoffs, yoffs, zoffs)
|
||||||
|
}
|
||||||
|
|
||||||
|
override def getBlockTexture(w: IBlockAccess, x: Int, y: Int, z: Int, side: Int) =
|
||||||
|
(for {
|
||||||
|
coverStack <- Option(getTE(w, x, y, z).covers(Misc.forgeDirection(side)).cval)
|
||||||
|
coverItem <- Option(coverStack.getItem) flatMap (Misc.asInstanceOpt(_, classOf[ItemCover]))
|
||||||
|
} yield coverItem.getCoverIcon(coverStack)
|
||||||
|
) getOrElse super.getBlockTexture(w, x, y, z, side)
|
||||||
|
|
||||||
|
override def breakBlock(world: World, x: Int, y: Int, z: Int, blockId: Int, meta: Int) {
|
||||||
|
if (!world.isRemote)
|
||||||
|
for ((dir, covOpt) <- getTE(world, x, y, z).covers; cover <- Option(covOpt.cval))
|
||||||
|
ItemUtils.throwItemAt(world, x, y, z, cover)
|
||||||
|
super.breakBlock(world, x, y, z, blockId, meta)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
|
* https://github.com/bdew/bdlib
|
||||||
|
*
|
||||||
|
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||||
|
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||||
|
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.bdew.lib.covers
|
||||||
|
|
||||||
|
import net.minecraft.item.{ItemStack, Item}
|
||||||
|
import net.minecraftforge.common.ForgeDirection
|
||||||
|
import net.minecraft.util.Icon
|
||||||
|
|
||||||
|
trait ItemCover extends Item {
|
||||||
|
/**
|
||||||
|
* @return Icon to render, MUST be on terrain spritesheet (0), not item!
|
||||||
|
*/
|
||||||
|
def getCoverIcon(stack: ItemStack): Icon
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform tick, called on server only
|
||||||
|
*/
|
||||||
|
def tickCover(te: TileCoverable, side: ForgeDirection, cover: ItemStack)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if this cover can be installed on a specific TE
|
||||||
|
*/
|
||||||
|
def isValidTile(te: TileCoverable, cover: ItemStack): Boolean
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) bdew, 2013 - 2014
|
||||||
|
* https://github.com/bdew/bdlib
|
||||||
|
*
|
||||||
|
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||||
|
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||||
|
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.bdew.lib.covers
|
||||||
|
|
||||||
|
import net.bdew.lib.data.base.{UpdateKind, TileDataSlots}
|
||||||
|
import net.minecraftforge.common.ForgeDirection
|
||||||
|
import net.bdew.lib.data.DataSlotItemStack
|
||||||
|
import net.bdew.lib.Misc
|
||||||
|
import net.minecraft.item.ItemStack
|
||||||
|
|
||||||
|
trait TileCoverable extends TileDataSlots {
|
||||||
|
val covers = (ForgeDirection.VALID_DIRECTIONS map { x =>
|
||||||
|
x -> DataSlotItemStack("cover_" + x.toString.toLowerCase, this).setUpdate(UpdateKind.SAVE, UpdateKind.WORLD, UpdateKind.RENDER)
|
||||||
|
}).toMap
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a specific cover can be installed here
|
||||||
|
*/
|
||||||
|
def isValidCover(side: ForgeDirection, cover: ItemStack): Boolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when new covers are installed
|
||||||
|
*/
|
||||||
|
def onCoversChanged() {}
|
||||||
|
|
||||||
|
def tickCovers() =
|
||||||
|
for {
|
||||||
|
(dir, coverSlot) <- covers
|
||||||
|
coverStack <- Option(coverSlot.cval)
|
||||||
|
coverItem <- Option(coverStack.getItem) flatMap (Misc.asInstanceOpt(_, classOf[ItemCover]))
|
||||||
|
} {
|
||||||
|
coverItem.tickCover(this, dir, coverStack)
|
||||||
|
}
|
||||||
|
|
||||||
|
serverTick.listen(tickCovers)
|
||||||
|
}
|
||||||
@@ -13,9 +13,10 @@ import net.minecraft.entity.item.EntityItem
|
|||||||
import net.minecraft.item.{Item, ItemStack}
|
import net.minecraft.item.{Item, ItemStack}
|
||||||
import net.minecraft.world.World
|
import net.minecraft.world.World
|
||||||
import net.minecraft.entity.player.EntityPlayer
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
import net.minecraft.inventory.IInventory
|
import net.minecraft.inventory.{ISidedInventory, IInventory}
|
||||||
import net.bdew.lib.Misc
|
import net.bdew.lib.Misc
|
||||||
import java.util.Random
|
import java.util.Random
|
||||||
|
import net.minecraftforge.common.ForgeDirection
|
||||||
|
|
||||||
object ItemUtils {
|
object ItemUtils {
|
||||||
def throwItemAt(world: World, x: Int, y: Int, z: Int, stack: ItemStack) {
|
def throwItemAt(world: World, x: Int, y: Int, z: Int, stack: ItemStack) {
|
||||||
@@ -78,6 +79,11 @@ object ItemUtils {
|
|||||||
return stack
|
return stack
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def getAccessibleSlotsFromSide(inv: IInventory, side: ForgeDirection) =
|
||||||
|
(Misc.asInstanceOpt(inv, classOf[ISidedInventory])
|
||||||
|
map (_.getAccessibleSlotsFromSide(side.ordinal()).toList)
|
||||||
|
getOrElse (0 until inv.getSizeInventory))
|
||||||
|
|
||||||
def findItemInInventory(inv: IInventory, item: Item) =
|
def findItemInInventory(inv: IInventory, item: Item) =
|
||||||
Range(0, inv.getSizeInventory).map(x => x -> inv.getStackInSlot(x))
|
Range(0, inv.getSizeInventory).map(x => x -> inv.getStackInSlot(x))
|
||||||
.find({ case (slot, stack) => stack != null && stack.getItem == item })
|
.find({ case (slot, stack) => stack != null && stack.getItem == item })
|
||||||
|
|||||||
Reference in new issue
Block a user