Last active
December 19, 2015 03:19
-
-
Save azenla/5889396 to your computer and use it in GitHub Desktop.
What MCore should be like
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package themike.core.block | |
import cpw.mods.fml.common.registry.GameRegistry | |
import cpw.mods.fml.relauncher.* | |
import net.minecraft.block.* | |
import net.minecraft.block.material.Material | |
import net.minecraft.client.renderer.texture.IconRegister | |
import net.minecraft.creativetab.CreativeTabs | |
import net.minecraft.item.ItemStack | |
import themike.core.item.ItemBlockBase | |
import net.minecraft.util.Icon | |
import themike.core.registry.BlockDataRegistry | |
import themike.core.registry.IconRegistry | |
/** | |
* A Block template making it so you don't have to reinvent the wheel every time for subblocks and texture registration. | |
* | |
* @author TheMike | |
*/ | |
public class BlockBase extends Block { | |
// Single blocks. | |
def blockPrefix | |
def textureName | |
// For subblocks only. | |
def hasSub = false | |
def blockList | |
def init(prefix, name) { | |
assert prefix != null, "Incorrect usage of the prefix definition! (BlockBase)" | |
assert name != null, "Incorrect usage of the name definition! (BlockBase)" | |
this.setUnlocalizedName(name as String) | |
this.blockPrefix = prefix | |
this.textureName = name | |
} | |
def subInit(int id, String name, List subblocks) { | |
assert subblocks != null, "Don't give me null subblocks! (BlockBase)" | |
this.hasSub = true | |
blockList = subblocks | |
BlockDataRegistry.addData(id, name, subblocks) | |
} | |
BlockBase(int par1, Material mat, String prefix, String name) { | |
super(par1, mat) | |
init(prefix, name) | |
GameRegistry.registerBlock(this, name) | |
} | |
BlockBase(int par1, Material mat, String prefix, String name, List subblocks) { | |
super(par1, mat) | |
init(prefix, name) | |
subInit(par1, name, subblocks) | |
GameRegistry.registerBlock(this, ItemBlockBase.class, name) | |
} | |
@Override | |
Icon getIcon(int side, int meta) { | |
if(hasSub) { | |
return IconRegistry.getIcon(blockList.get(meta) as String) | |
} else { | |
return IconRegistry.getIcon(this.textureName as String) | |
} | |
} | |
@Override | |
@SideOnly(Side.CLIENT) | |
void registerIcons(IconRegister register) { | |
if(hasSub) { | |
for(def name : blockList) { | |
IconRegistry.addIcon(name as String, register.registerIcon(this.blockPrefix + ":" + name)) | |
} | |
} else { | |
IconRegistry.addIcon(this.textureName as String, register.registerIcon(blockPrefix + ":" + textureName)) | |
} | |
} | |
@Override | |
void getSubBlocks(int ID, CreativeTabs tab, List subItems) { | |
if(hasSub) { | |
for (i in 0..(blockList.size() - 1)) { | |
subItems.add(new ItemStack(this, 1, i)) | |
} | |
} else { | |
subItems.add(new ItemStack(this, 1, 0)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment