mirror of
https://github.com/GTNewHorizons/bdlib.git
synced 2026-11-20 04:09:37 +00:00
Added HasItemBlock - trait that tells BlockManager and Machine to register custom ItemBlocks. Replaces old itemClass parameter. Version bumped to 1.9.0
This commit is contained in:
1 parent
fae2825e7b
commit
ebe2c1f34a
4 files changed
+42
-7
No files matched your search
+1
-1
@@ -1,4 +1,4 @@
|
||||
bdlib.version=1.8.2
|
||||
bdlib.version=1.9.0
|
||||
curseforge.id=70496
|
||||
|
||||
minecraft.version=1.7.10
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2015
|
||||
* 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
|
||||
* http://bdew.net/minecraft-mod-public-license/
|
||||
*/
|
||||
|
||||
package net.bdew.lib.block
|
||||
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.item.ItemBlock
|
||||
|
||||
/**
|
||||
* If defined on a block - defines a custom ItemBlock class that will be used when registering
|
||||
* Supported by BlockManager and Machine
|
||||
*/
|
||||
trait HasItemBlock extends Block {
|
||||
def ItemBlockClass: Class[_ <: ItemBlock]
|
||||
}
|
||||
@@ -12,7 +12,7 @@ package net.bdew.lib.config
|
||||
import cpw.mods.fml.common.ObfuscationReflectionHelper
|
||||
import cpw.mods.fml.common.registry.GameRegistry
|
||||
import net.bdew.lib.Misc
|
||||
import net.bdew.lib.block.{HasTE, NamedBlock}
|
||||
import net.bdew.lib.block.{HasItemBlock, HasTE, NamedBlock}
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.creativetab.CreativeTabs
|
||||
import net.minecraft.item.{ItemBlock, ItemStack}
|
||||
@@ -21,9 +21,15 @@ import net.minecraft.tileentity.TileEntity
|
||||
class BlockManager(creativeTab: CreativeTabs) {
|
||||
def regBlock[T <: NamedBlock](block: T): T = regBlock(block, block.name)
|
||||
|
||||
def regBlock[T <: NamedBlock](block: T, itemClass: Class[_ <: ItemBlock]): T = regBlock(block, block.name, itemClass)
|
||||
def regSpecial[T <: NamedBlock](block: T, addStack: Boolean = false, skipTileEntityReg: Boolean = false): T =
|
||||
regBlock(block, block.name, addStack, skipTileEntityReg)
|
||||
|
||||
def regBlock[T <: Block](block: T, name: String, addStack: Boolean = false, skipTileEntityReg: Boolean = false): T = {
|
||||
val itemClass: Class[_ <: ItemBlock] = if (block.isInstanceOf[HasItemBlock])
|
||||
block.asInstanceOf[HasItemBlock].ItemBlockClass
|
||||
else
|
||||
classOf[ItemBlock]
|
||||
|
||||
def regBlock[T <: Block](block: T, name: String, itemClass: Class[_ <: ItemBlock] = classOf[ItemBlock], addStack: Boolean = false): T = {
|
||||
GameRegistry.registerBlock(block, itemClass, name)
|
||||
|
||||
block.setCreativeTab(creativeTab)
|
||||
@@ -31,7 +37,7 @@ class BlockManager(creativeTab: CreativeTabs) {
|
||||
if (addStack)
|
||||
GameRegistry.registerCustomItemStack(name, new ItemStack(block))
|
||||
|
||||
if (block.isInstanceOf[HasTE[_]])
|
||||
if (block.isInstanceOf[HasTE[_]] && !skipTileEntityReg)
|
||||
GameRegistry.registerTileEntity(block.asInstanceOf[HasTE[_]].TEClass,
|
||||
"%s.%s".format(Misc.getActiveModId, name))
|
||||
|
||||
|
||||
@@ -11,10 +11,11 @@ package net.bdew.lib.machine
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry
|
||||
import net.bdew.lib.Misc
|
||||
import net.bdew.lib.block.HasTE
|
||||
import net.bdew.lib.block.{HasItemBlock, HasTE}
|
||||
import net.bdew.lib.recipes.gencfg.ConfigSection
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.creativetab.CreativeTabs
|
||||
import net.minecraft.item.ItemBlock
|
||||
|
||||
abstract class Machine[T <: Block](val name: String, blockConstruct: => T) {
|
||||
var block: T = null.asInstanceOf[T]
|
||||
@@ -24,7 +25,14 @@ abstract class Machine[T <: Block](val name: String, blockConstruct: => T) {
|
||||
|
||||
def regBlock(creativeTab: CreativeTabs) {
|
||||
block = blockConstruct
|
||||
GameRegistry.registerBlock(block, name)
|
||||
|
||||
val itemClass: Class[_ <: ItemBlock] = if (block.isInstanceOf[HasItemBlock])
|
||||
block.asInstanceOf[HasItemBlock].ItemBlockClass
|
||||
else
|
||||
classOf[ItemBlock]
|
||||
|
||||
GameRegistry.registerBlock(block, itemClass, name)
|
||||
|
||||
block.setCreativeTab(creativeTab)
|
||||
if (block.isInstanceOf[HasTE[_]]) {
|
||||
GameRegistry.registerTileEntity(block.asInstanceOf[HasTE[_]].TEClass, "%s.%s".format(modId, name))
|
||||
|
||||
Reference in new issue
Block a user