DummyCore first build(1.1dev)

First time the code of DummyCore was putted to GitHub. You can look up
the explanations in the code itself.
This commit is contained in:
Modbder committed 2013-09-11 12:35:15 +04:00
commit b3efe0c897
19 files changed
+1899

No files matched your search

+93
View File
@@ -0,0 +1,93 @@
package DummyCore.Blocks;
import java.util.Hashtable;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraftforge.common.Configuration;
import DummyCore.Core.Core;
import DummyCore.Core.CoreInitialiser;
import DummyCore.Items.MultiItem;
import DummyCore.Utils.IDummyMultiBlock;
import DummyCore.Utils.IDummyMultiItem;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
/**
*
* @author Modbder
* @version From DummyCore 1.0
* @Description Use this class to register new blocks in your game.
* This will automatically add your blocks to the corresponding creative tab
*/
public class BlocksRegistry {
/**
* Used to check the creative tab block belongs to
*/
public static Hashtable<Block,String> blocksList = new Hashtable();
/**
* Use this to register new simple blocks.
* @version From DummyCore 1.0
* @param b - the block to be registered.
* @param name - in-game name of the block. Will be written to the corresponding .lang file
* @param modClass - class file of your mod. If registered from the mod itself, use getClass(), else just put in this field something like YourModClassName.class
* @param blockClass - used, if you want to register a block, that has an ItemBlock. Can be null.
*/
public static void registerBlock(Block b, String name, Class modClass, Class blockClass)
{
String blockName = name;
Configuration conf = Core.getLangFileForMod(modClass);
conf.load();
blockName = conf.get("Blocks Names", b.getUnlocalizedName(), name).getString();
conf.save();
if(blockClass == null)
{
GameRegistry.registerBlock(b, Core.getModName(Core.getIdForMod(modClass))+".block."+name);
}else
{
GameRegistry.registerBlock(b, blockClass, Core.getModName(Core.getIdForMod(modClass))+".block."+name);
}
LanguageRegistry.addName(b, blockName);
b.setCreativeTab(Core.getBlockTabForMod(modClass));
blocksList.put(b, Core.getBlockTabForMod(modClass).getTabLabel());
}
/**
* Use this to add your block to the MultiBlock storage system. This will add your block to the DummyCore creative tab. This does not requires creating new Block variable, and allows you to register lots of blocks, while not using more ID's
* @param unlocalisedName - the name of your block in code. Always remember to check this! This is the way to get your blocks if you need to!
* @param inGameName - in-game name of the block. Will be written to the corresponding .lang file
* @param texturePath - path to the texture file, that will be used for this block. Should be modname:texturename
* @param multiBlockHandler - should be an initialized! object, that implements IDummyMultiBlock. Usually it is just an empty .class file. Used to handle different actions, happening with your multiblock. Always remember to check for your block's name! Can be null, then none of actions will be handled.
* @param modClass - class file of your mod. If registered from the mod itself, use getClass(), else just put in this field something like YourModClassName.class
* @version From DummyCore 1.1
*/
public static void registerMultiBlock(String unlocalisedName, String inGameName, String texturePath, IDummyMultiBlock multiBlockHandler, Class modClass)
{
String blockName = inGameName;
Configuration conf = Core.getLangFileForMod(modClass);
conf.load();
blockName = conf.get("Blocks Names", unlocalisedName, inGameName).getString();
conf.save();
if(multiBlockHandler != null)
{
MultiBlock.registerMultiBlock(unlocalisedName, inGameName, texturePath, multiBlockHandler);
}else
{
MultiBlock.registerMultiBlock(unlocalisedName, inGameName, texturePath);
}
}
/**
* Used to handle the single id for all of the multiblocks. Do not change this!
* @return the id of all the multiblocks
* @version From DummyCore 1.1
*/
public static int getMultiBlockID()
{
return CoreInitialiser.mBlock.blockuid;
}
}
+123
View File
@@ -0,0 +1,123 @@
package DummyCore.Blocks;
import java.util.List;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
/**
* @author Modbder
* @version From DummyCore 1.1
* @Description This is used for MultiBlocks handling. Do not change anything here! No explanation will be given to any functions in here, because you do not need this.
*/
public class ItemMultiBlock extends ItemBlock{
public ItemMultiBlock(int par1) {
super(par1);
}
@Override
public boolean canPlaceItemBlockOnSide(World par1World, int par2, int par3, int par4, int par5, EntityPlayer par6EntityPlayer, ItemStack par7ItemStack)
{
for(int i = 0; i < 1024; ++i)
{
if(MultiBlock.handler[i] != null)
return MultiBlock.handler[i].canPlaceItemBlockOnSide(par1World, par2, par3, par4, par5, par6EntityPlayer, par7ItemStack);
}
return super.canPlaceItemBlockOnSide(par1World, par2, par3, par4, par5, par6EntityPlayer, par7ItemStack);
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister par1IconRegister)
{
int amount = 0;
for(int i = 0; i < MultiBlock.blockNamesUnlocalisedList.size(); ++i)
{
if(MultiBlock.blockNamesUnlocalisedList.get(i) != null)
{
++amount;
}
}
if(amount > 0)
{
MultiBlock.icon = new Icon[amount];
for(int i = 0; i < MultiBlock.blockTextures.size(); ++i)
{
if(MultiBlock.blockTextures.get(i) != null)
{
MultiBlock.icon[i] = par1IconRegister.registerIcon(MultiBlock.blockTextures.get(i));
}
}
for(int i = 0; i < 1024; ++i)
{
if(MultiBlock.handler[i] != null)
MultiBlock.handler[i].registerIcons(par1IconRegister);
}
}
}
@Override
@SideOnly(Side.CLIENT)
public Icon getIconFromDamage(int par1)
{
return MultiBlock.icon[par1];
}
@Override
@SideOnly(Side.CLIENT)
public String getItemDisplayName(ItemStack par1ItemStack)
{
return MultiBlock.blockNames.get(par1ItemStack.getItemDamage());
}
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
for(int i = 0; i < MultiBlock.blockNamesUnlocalisedList.size(); ++i)
if(MultiBlock.blockNamesUnlocalisedList.get(i) != null)
par3List.add(i, new ItemStack(par1,1,i));
}
@Override
public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5)
{
for(int i = 0; i < 1024; ++i)
{
if(MultiBlock.handler[i] != null)
MultiBlock.handler[i].onItemBlockUpdate(par1ItemStack, par2World, par3Entity, par4, par5);
}
}
@Override
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
{
for(int i = 0; i < 1024; ++i)
{
if(MultiBlock.handler[i] != null)
MultiBlock.handler[i].addInformation(par1ItemStack, par2EntityPlayer, par3List, par4);
}
}
@Override
public EnumRarity getRarity(ItemStack par1ItemStack)
{
for(int i = 0; i < 1024; ++i)
{
if(MultiBlock.handler[i] != null)
return MultiBlock.handler[i].getRarity(par1ItemStack);
}
return EnumRarity.common;
}
}
+264
View File
@@ -0,0 +1,264 @@
package DummyCore.Blocks;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Random;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import DummyCore.Utils.IDummyMultiBlock;
import DummyCore.Utils.IDummyMultiItem;
import DummyCore.Utils.MiscUtils;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.Icon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
/**
* @author Modbder
* @version From DummyCore 1.1
* @Description Used to handle all the multiblocks. Do not change anything here! Some explanation to the required functions will be given.
*/
public class MultiBlock extends Block{
protected static List<String> blockNames = new ArrayList();
protected static List<String> blockNamesUnlocalisedList = new ArrayList();
protected static Hashtable<String,Integer> blockNamesUnlocalised = new Hashtable();
protected static List<String> blockTextures = new ArrayList();
protected static int id = -1;
public static int blockuid;
protected static Icon[] icon;
protected static IDummyMultiBlock[] handler = new IDummyMultiBlock[1024];
public MultiBlock(int par1) {
super(par1, Material.circuits);
blockuid = par1;
}
private static void addBlockName(int i, String name)
{
blockNames.add(i, name);
}
private static void addBlockNameMain(int i, String name)
{
blockNamesUnlocalisedList.add(i, name);
}
private static void addBlockTexture(int i, String texture)
{
blockTextures.add(i, texture);
}
private static int getNextFreeID()
{
return ++id;
}
private static void registerMain(int i, String s)
{
blockNamesUnlocalised.put(s, i);
addBlockNameMain(i,s);
}
/**
* Used to get the metadata(aka. damage) of your block.
* @version From DummyCore 1.1
* @param unlocalisedName - name of your block. Remember, that this is the in-code name!
* @return the metadata, that was given to your block.
*/
public static int getMetadataByName(String unlocalisedName)
{
int i = -1;
if(blockNamesUnlocalised.containsKey(unlocalisedName))
{
i = blockNamesUnlocalised.get(unlocalisedName);
}else
{
throw new RuntimeException("No blocks with "+unlocalisedName+" index were found!");
}
return i;
}
/**
* Used to get the corresponding ItemStack of your block.
* @version From DummyCore 1.1
* @param unlocalisedName - name of your block. Remember, that this is the in-code name!
* @param size - the size of this stack. max is 64.
* @return automatically generated ItemStack for your block, with MultiBlock id, metadata of your block and size that was given.
*/
public static ItemStack getStackByName(String unlocalisedName, int size)
{
ItemStack s = new ItemStack(blockuid,getMetadataByName(unlocalisedName),size);
return s;
}
/**
* Used to register multiblocks without handler.
* @version From DummyCore 1.1
* @param unlocalisedName - name of your block. Remember, that this is the in-code name!
* @param inGameName - in-game name of the block.
* @param texturePath - path to the texture file, that will be used for this block. Should be modname:texturename
*/
public static void registerMultiBlock(String unlocalisedName, String inGameName, String texturePath)
{
int blockMeta = getNextFreeID();
registerMain(blockMeta,unlocalisedName);
addBlockName(blockMeta,inGameName);
addBlockTexture(blockMeta,texturePath);
}
/**
* Used to register multiblocks with handler.
* @param unlocalisedName - name of your block. Remember, that this is the in-code name!
* @param inGameName - in-game name of the block.
* @param texturePath - path to the texture file, that will be used for this block. Should be modname:texturename
* @param multiblockHandler - should be an initialized! object, that implements IDummyMultiBlock. Usually it is just an empty .class file. Used to handle different actions, happening with your multiblock. Always remember to check for your block's name!
*/
public static void registerMultiBlock(String unlocalisedName, String inGameName, String texturePath, IDummyMultiBlock multiblockHandler)
{
registerMultiBlock(unlocalisedName,inGameName,texturePath);
handler[getMetadataByName(unlocalisedName)] = multiblockHandler;
}
@Override
public float getBlockHardness(World par1World, int par2, int par3, int par4)
{
for(int i = 0; i < 1024; ++i)
{
if(handler[i] != null)
return handler[i].getBlockHardness(MiscUtils.getBlock(par1World, par2, par3, par4),par1World, par2, par3, par4);
}
return this.blockHardness;
}
@SideOnly(Side.CLIENT)
@Override
public float getBlockBrightness(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
{
for(int i = 0; i < 1024; ++i)
{
if(handler[i] != null)
return handler[i].getBlockBrightness(MiscUtils.getBlock(par1IBlockAccess, par2, par3, par4),par1IBlockAccess, par2, par3, par4);
}
return super.getBlockBrightness(par1IBlockAccess, par2, par3, par4);
}
@SideOnly(Side.CLIENT)
@Override
public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
{
for(int i = 0; i < 1024; ++i)
{
if(handler[i] != null)
return handler[i].getBlockTexture(MiscUtils.getBlock(par1IBlockAccess, par2, par3, par4), par1IBlockAccess, par2, par3, par4, par5);
}
return icon[par1IBlockAccess.getBlockMetadata(par2,par3,par4)];
}
@SideOnly(Side.CLIENT)
@Override
public AxisAlignedBB getSelectedBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
{
for(int i = 0; i < 1024; ++i)
{
if(handler[i] != null)
return handler[i].getSelectedBoundingBoxFromPool(MiscUtils.getBlock(par1World, par2, par3, par4), par1World, par2, par3, par4);
}
return super.getSelectedBoundingBoxFromPool(par1World, par2, par3, par4);
}
public static String getUnlocalisedNameByMetadata(int meta)
{
return blockNamesUnlocalisedList.get(meta);
}
@Override
public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
{
for(int i = 0; i < 1024; ++i)
{
if(handler[i] != null)
return handler[i].getCollisionBoundingBoxFromPool(MiscUtils.getBlock(par1World, par2, par3, par4), par1World, par2, par3, par4);
}
return super.getCollisionBoundingBoxFromPool(par1World, par2, par3, par4);
}
@SideOnly(Side.CLIENT)
@Override
public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random)
{
for(int i = 0; i < 1024; ++i)
{
if(handler[i] != null)
handler[i].randomDisplayTick(MiscUtils.getBlock(par1World, par2, par3, par4), par1World, par2, par3, par4, par5Random);
}
super.randomDisplayTick(par1World, par2, par3, par4, par5Random);
}
@Override
public void onBlockDestroyedByPlayer(World par1World, int par2, int par3, int par4, int par5)
{
for(int i = 0; i < 1024; ++i)
{
if(handler[i] != null)
handler[i].onBlockDestroyedByPlayer(MiscUtils.getBlock(par1World, par2, par3, par4), par1World, par2, par3, par4, par5);
}
super.onBlockDestroyedByPlayer(par1World, par2, par3, par4, par5);
}
@Override
public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
{
for(int i = 0; i < 1024; ++i)
{
if(handler[i] != null)
handler[i].onNeighborBlockChange(MiscUtils.getBlock(par1World, par2, par3, par4), par1World, par2, par3, par4, par5);
}
super.onNeighborBlockChange(par1World, par2, par3, par4, par5);
}
@Override
public void onBlockAdded(World par1World, int par2, int par3, int par4)
{
for(int i = 0; i < 1024; ++i)
{
if(handler[i] != null)
handler[i].onBlockAdded(MiscUtils.getBlock(par1World, par2, par3, par4), par1World, par2, par3, par4);
}
super.onBlockAdded(par1World, par2, par3, par4);
}
@Override
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
{
for(int i = 0; i < 1024; ++i)
{
if(handler[i] != null)
return handler[i].onBlockActivated(MiscUtils.getBlock(par1World, par2, par3, par4), par1World, par2, par3, par4, par5EntityPlayer, par6, par7, par8, par9);
}
return super.onBlockActivated(par1World, par2, par3, par4, par5EntityPlayer, par6, par7, par8, par9);
}
@Override
public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
{
for(int i = 0; i < 1024; ++i)
{
if(handler[i] != null)
handler[i].setBlockBoundsBasedOnState(MiscUtils.getBlock(par1IBlockAccess, par2, par3, par4), par1IBlockAccess, par2, par3, par4);
}
super.setBlockBoundsBasedOnState(par1IBlockAccess, par2, par3, par4);
}
@Override
public int damageDropped(int par1)
{
return par1;
}
}
+218
View File
@@ -0,0 +1,218 @@
package DummyCore.Core;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.ConcurrentModificationException;
import java.util.HashMap;
import java.util.List;
import DummyCore.CreativeTabs.CreativePageBlocks;
import DummyCore.CreativeTabs.CreativePageItems;
import DummyCore.Utils.IDummyConfig;
import DummyCore.Utils.Notifier;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraftforge.common.Configuration;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.registry.LanguageRegistry;
public class Core {
private static HashMap modList = new HashMap<Class,Integer>();
private static HashMap langFilesList = new HashMap<Integer,Configuration>();
private static HashMap configurationList = new HashMap<Integer,Configuration>();
private static List modNameList = new ArrayList<String>();
private static CreativeTabs[] blocksTabs = new CreativeTabs[512];
private static CreativeTabs[] itemsTabs = new CreativeTabs[512];
private static Configuration[] config = new Configuration[512];
private static IDummyConfig[] configurationHandlers = new IDummyConfig[512];
private static int modID;
private static boolean[] isConfigLoaded = new boolean[512];
private static void registerMod(Class c, String name) throws RuntimeException
{
if(!modList.containsKey(c))
{
int modId = getNextModId();
if(modId < 0 || modId >= 512)
{
throw new RuntimeException("Mod "+name+" is trying to be registered with wrong id "+modId);
}
modList.put(c, modId);
modNameList.add(modId, name);
blocksTabs[modId] = new CreativePageBlocks(name);
itemsTabs[modId] = new CreativePageItems(name);
Notifier.notifySimple("Mod with name "+name+" and classpath "+c.getName()+".class using ID "+modId+" has been succesfully registered!");
}else
{
throw new RuntimeException("Mod "+name+" is already registered!");
}
}
private static void registerLangFileForMod(Class c, String path) throws IOException
{
File f = new File(path,getModName(getIdForMod(c))+".lang");
if(!f.exists())
f.createNewFile();
Configuration config = new Configuration(f);
langFilesList.put(getIdForMod(c),config);
Notifier.notifySimple("Language File for mod "+getModName(getIdForMod(c))+" was successfully created with path "+path+getModName(getIdForMod(c))+".lang");
}
private static void registerConfigurationFileForMod(Class c, String path) throws IOException
{
File file = new File(path,getModName(getIdForMod(c))+".cfg");
if(!file.exists())
file.createNewFile();
config[getIdForMod(c)] = new Configuration(file);
config[getIdForMod(c)].save();
configurationList.put(getIdForMod(c), config);
Notifier.notifySimple("Configuration File for mod "+getModName(getIdForMod(c))+" was successfully created with path "+path+getModName(getIdForMod(c))+".cfg");
}
/**
* Use this in you Pre-Initiasisation functions. This will register your mod in the DummyCore system and automatically create all config and .lang files.
* From DummyCore v1.1 you no longer need to use IMCEvent to register all blocks and items.
* @param c - class file of your mod. MUST be registered from the mod itself. Use getClass().
* @param modname - this name will be used to name CreativeTabs, config and .lang files.
* @param configPath - the path to your configuration file. You can use FMLPreInitialisationEvent.getModConfigurationDirectory().getAbsolutePath() to get your path.
* @param config - the initialised! object, that implements IDummyConfig.
* @throws IOException - If something has gone wrong the game will give the corresponding error report.
* @version From DummyCore 1.0.
* @Warning From DummyCore 1.1 no longer the function registerConfigurationHandler must be called.
*
*/
public static void registerModAbsolute(Class c, String modname, String configPath, IDummyConfig config) throws IOException
{
registerMod(c,modname);
registerLangFileForMod(c,configPath);
registerConfigurationFileForMod(c,configPath);
registerConfigurationHandler(config,c);
loadConfigForMod(getIdForMod(c));
}
private static int getNextModId()
{
int i = 0;
while(i < 512)
{
if(!modList.containsValue(i))
{
break;
}
++i;
}
return i;
}
/**
* Used to get the ID of the mod using .class file.
* @param m - the class file of the mod.
* @return The corresponding ID of the mod.
* @version From DummyCore 1.0
*/
public static int getIdForMod(Class m)
{
if(modList.containsKey(m))
{
return (Integer)modList.get(m);
}
return 0;
}
/**
* Used to get the name of the mod using .class file.
* @param i - the id of the mod.
* @return The corresponding name of the mod.
* @version From DummyCore 1.0
*/
public static String getModName(int i)
{
return (String)modNameList.get(i);
}
/**
* Used to get the config file of the mod using .class file.
* @param c - the class file of the mod.
* @return The corresponding config file of the mod.
* @version From DummyCore 1.0
*/
public static Configuration getConfigFileForMod(Class c)
{
return config[getIdForMod(c)];
}
/**
* Used to get the lang file of the mod using .class file.
* @param c - the class file of the mod.
* @return The corresponding lang file of the mod.
* @version From DummyCore 1.0
*/
public static Configuration getLangFileForMod(Class c)
{
return (Configuration) langFilesList.get(getIdForMod(c));
}
/**
* Used to register new Configuration Handlers of the mod.
* @param config - the initialised! object, that implements IDummyConfig.
* @param c - the class file of the mod. Use getClass(). Should only be called in the mod itself.
* @throws RuntimeException
* @version From DummyCore 1.0
*/
private static void registerConfigurationHandler(IDummyConfig config, Class c) throws RuntimeException
{
int modId = getIdForMod(c);
if(configurationHandlers[modId] == null)
{
configurationHandlers[modId] = config;
}else
{
throw new RuntimeException("Configuration handler for mod "+getModName(modId)+" is already registered!");
}
}
private static void loadConfigForMod(int t) throws RuntimeException
{
if(!isConfigLoaded[t])
{
if(configurationHandlers[t] != null && config[t] != null)
{
config[t].load();
configurationHandlers[t].load(config[t]);
config[t].save();
}
else
if((configurationHandlers[t] == null && config[t] != null) || (configurationHandlers[t] != null && config[t] == null))
{
//throw new RuntimeException("Either the configuration handler for config was not registered, or the IConfig was not registered. The ID for both elements is "+t);
}
isConfigLoaded[t] = true;
}else
{
throw new RuntimeException("Configuration handler was already initialised!");
}
}
/**
* Use this to get the creativetab of all mod items.
* @param c - the .class file of the mod.
* @return The corresponding Creative Tab
* @version From DummyCore 1.0
*/
public static CreativeTabs getItemTabForMod(Class c)
{
return itemsTabs[getIdForMod(c)];
}
/**
* Use this to get the creativetab of all mod blocks.
* @param c - the .class file of the mod.
* @return The corresponding Creative Tab
* @version From DummyCore 1.0
*/
public static CreativeTabs getBlockTabForMod(Class c)
{
return blocksTabs[getIdForMod(c)];
}
}
+83
View File
@@ -0,0 +1,83 @@
package DummyCore.Core;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.xml.bind.annotation.adapters.HexBinaryAdapter;
import org.apache.commons.io.HexDump;
import org.bouncycastle.util.encoders.Hex;
import org.bouncycastle.util.encoders.HexEncoder;
import org.bouncycastle.util.encoders.HexTranslator;
import net.minecraft.block.Block;
import net.minecraft.client.resources.ResourcePack;
import DummyCore.Blocks.BlocksRegistry;
import DummyCore.Blocks.ItemMultiBlock;
import DummyCore.Blocks.MultiBlock;
import DummyCore.Items.ItemRegistry;
import DummyCore.Items.MultiItem;
import DummyCore.Utils.DummyConfig;
import DummyCore.Utils.MathUtils;
import DummyCore.Utils.Notifier;
import cpw.mods.fml.common.DummyModContainer;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Metadata;
import cpw.mods.fml.common.ModMetadata;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLInterModComms.IMCEvent;
import cpw.mods.fml.common.registry.GameRegistry;
/**
* Do not change anythig here! This is used to initialise MultiBlocks and MultiItems.
* @author Home
* @version From DummyCore 1.0
*/
@Mod(modid = "DummyCore", name = "DummyCore", version = "1.1dev", useMetadata = true)
public class CoreInitialiser extends DummyModContainer{
public static final CoreInitialiser instance = new CoreInitialiser();
private static DummyConfig cfg = new DummyConfig();
@Metadata
public static ModMetadata meta = new ModMetadata()
{
String modId = "DummyCore";
String name = "DummyCore";
String version = "1.0dev";
String credits = "Modbder";
List<String> authorList = Arrays.asList(new String[] {
"Dummy Thinking Team; Modbder; TheDen2099"
});
String description ="Dummy Core is a required package to launch mods made by Dummy Thinking team.";
};
public CoreInitialiser()
{
super(meta);
}
@EventHandler
public void preInit(FMLPreInitializationEvent e) throws Exception
{
Core.registerModAbsolute(getClass(), "DummyCore", e.getModConfigurationDirectory().getAbsolutePath(),cfg);
}
@EventHandler
public void init(IMCEvent e)
{
mItem = (MultiItem)new MultiItem(cfg.MultiItemUID).setUnlocalizedName("DummyCore.MultiItem");
mItem.setCreativeTab(Core.getItemTabForMod(getClass()));
ItemRegistry.registerMultiItem("dummyDebugItem", "Debug Item From Dummy Core", null, null, getClass());
ItemRegistry.itemsList.put(mItem, Core.getItemTabForMod(getClass()).getTabLabel());
mBlock = (MultiBlock)new MultiBlock(cfg.MultiBlockUID).setHardness(1.0F).setResistance(1.0F).setUnlocalizedName("DummyCore.MultiBlock");
mBlock.setCreativeTab(Core.getBlockTabForMod(getClass()));
BlocksRegistry.registerMultiBlock("dummyDebugBlock", "Debug Block From Dummy Core", null, null, getClass());
GameRegistry.registerBlock(mBlock, ItemMultiBlock.class, Core.getModName(Core.getIdForMod(getClass()))+".block."+mBlock.getUnlocalizedName());
BlocksRegistry.blocksList.put(mBlock, Core.getBlockTabForMod(getClass()).getTabLabel());
}
public static MultiItem mItem;
public static MultiBlock mBlock;
}
@@ -0,0 +1,91 @@
package DummyCore.CreativeTabs;
import java.util.Random;
import java.util.UUID;
import DummyCore.Blocks.BlocksRegistry;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
/**
* @version From DummyCore 1.0
* @author Modbder
* Do not change anything here! Used to work with Blocks.
*/
public final class CreativePageBlocks extends CreativeTabs{
private int delayTime = 0;
private ItemStack displayStack = new ItemStack(Block.workbench,1,0);
private static Random rand = new Random(543643456);
private final String tabLabel;
public CreativePageBlocks(String m) {
super(m + " Blocks");
tabLabel = m + " Blocks";
}
public ItemStack getIconItemStack()
{
this.chooseRandomStack();
return this.displayStack;
}
private void chooseRandomStack()
{
++this.delayTime;
if(this.delayTime >= 40)
{
this.delayTime = 0;
Block[] blockList = initialiseBlocksList();
if(blockList != null && blockList.length >= 1)
{
int random = rand.nextInt(blockList.length);
if(blockList[random] != null)
if(blockList[random].getIcon(0,0) != null)
this.displayStack = new ItemStack(blockList[random],1,0);
}
}
}
private Block[] initialiseBlocksList()
{
int i = 0;
for(int t = 0; t < Block.blocksList.length; ++t)
{
Block b = Block.blocksList[t];
if(b != null)
{
if(b.getCreativeTabToDisplayOn() != null && b.getCreativeTabToDisplayOn() instanceof CreativePageBlocks && b.getIcon(0,0) != null && (BlocksRegistry.blocksList.get(b) == this.getTabLabel()))
{
++i;
}
}
}
Block[] blockList = new Block[i];
int r = 0;
for(int t = 0; t < Block.blocksList.length; ++t)
{
Block b = Block.blocksList[t];
if(b != null)
{
if(b.getCreativeTabToDisplayOn() != null && b.getCreativeTabToDisplayOn() instanceof CreativePageBlocks && b.getIcon(0,0) != null && (BlocksRegistry.blocksList.get(b) == this.getTabLabel()))
{
blockList[r] = b;
++r;
}
}
}
return blockList;
}
@SideOnly(Side.CLIENT)
@Override
public String getTranslatedTabLabel()
{
return this.tabLabel;
}
}
@@ -0,0 +1,94 @@
package DummyCore.CreativeTabs;
import java.util.Random;
import java.util.UUID;
import DummyCore.Blocks.BlocksRegistry;
import DummyCore.Items.ItemRegistry;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
/**
* @version From DummyCore 1.0
* @author Modbder
* Do not change anything here! Used to work with Items.
*/
public final class CreativePageItems extends CreativeTabs{
private int delayTime = 0;
private ItemStack displayStack = new ItemStack(Item.axeIron,1,0);
private static Random rand = new Random(965448655);
private final String tabLabel;
public CreativePageItems(String m) {
super(m + " Items");
tabLabel = m + " Items";
}
public ItemStack getIconItemStack()
{
this.chooseRandomStack();
return this.displayStack;
}
private void chooseRandomStack()
{
++this.delayTime;
if(this.delayTime >= 40)
{
this.delayTime = 0;
Item[] itemList = initialiseItemsList();
if(itemList != null && itemList.length >= 1)
{
int random = rand.nextInt(itemList.length);
if(itemList[random] != null)
if(itemList[random].getIconFromDamage(0) != null)
this.displayStack = new ItemStack(itemList[random],1,0);
}
}
}
private Item[] initialiseItemsList()
{
int i = 0;
for(int t = 0; t < Item.itemsList.length; ++t)
{
Item b = Item.itemsList[t];
if(b != null)
{
if(b.getCreativeTab() != null && b.getCreativeTab() instanceof CreativePageItems && b.getIconFromDamage(0) != null && (ItemRegistry.itemsList.get(b) == this.getTabLabel()))
{
++i;
}
}
}
Item[] itemsList = new Item[i];
int r = 0;
for(int t = 0; t < Item.itemsList.length; ++t)
{
Item b = Item.itemsList[t];
if(b != null)
{
if(b.getCreativeTab() != null && b.getCreativeTab() instanceof CreativePageItems && b.getIconFromDamage(0) != null && (ItemRegistry.itemsList.get(b) == this.getTabLabel()))
{
itemsList[r] = b;
++r;
}
}
}
return itemsList;
}
@SideOnly(Side.CLIENT)
@Override
public String getTranslatedTabLabel()
{
return this.tabLabel;
}
}
+82
View File
@@ -0,0 +1,82 @@
package DummyCore.Items;
import java.util.Hashtable;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraftforge.common.Configuration;
import DummyCore.Core.Core;
import DummyCore.Core.CoreInitialiser;
import DummyCore.Utils.IDummyMultiItem;
import cpw.mods.fml.common.registry.LanguageRegistry;
/**
*
* @author Modbder
* @version From DummyCore 1.0
* @Description Use this class to register new items in your game.
* This will automatically add your items to the corresponding creative tab
*/
public class ItemRegistry {
/**
* Used to check the creative tab item belongs to
*/
public static Hashtable<Item,String> itemsList = new Hashtable();
/**
* Use this to register new simple items.
* @version From DummyCore 1.0
* @param i - the item to be registered.
* @param name - in-game name of the item. Will be written to the corresponding .lang file
* @param modClass - class file of your mod. If registered from the mod itself, use getClass(), else just put in this field something like YourModClassName.class
*/
public static void registerItem(Item i, String name, Class modClass)
{
String itemName = name;
Configuration conf = Core.getLangFileForMod(modClass);
conf.load();
itemName = conf.get("Items Names", i.getUnlocalizedName(), name).getString();
conf.save();
LanguageRegistry.addName(i, itemName);
i.setCreativeTab(Core.getItemTabForMod(modClass));
itemsList.put(i, Core.getItemTabForMod(modClass).getTabLabel());
}
/**
* Use this to add your item to the MultiItem storage system. This will add your item to the DummyCore creative tab. This does not requires creating new Item variable, and allows you to register lots of items, while not using more ID's
* @param unlocalisedName - the name of your item in code. Always remember to check this! This is the way to get your items if you need to!
* @param inGameName - in-game name of the item. Will be written to the corresponding .lang file
* @param texturePath - path to the texture file, that will be used for this item. Should be modname:texturename
* @param multiItemHandler - should be an initialized! object, that implements IDummyMultiItem. Usually it is just an empty .class file. Used to handle different actions, happening with your multiitem. Always remember to check for your item's name! Can be null, then none of actions will be handled.
* @param modClass - class file of your mod. If registered from the mod itself, use getClass(), else just put in this field something like YourModClassName.class
* @version From DummyCore 1.1
*/
public static void registerMultiItem(String unlocalisedName, String inGameName, String texturePath, IDummyMultiItem multiItemHandler, Class modClass)
{
String itemName = inGameName;
Configuration conf = Core.getLangFileForMod(modClass);
conf.load();
itemName = conf.get("Items Names", unlocalisedName, inGameName).getString();
conf.save();
if(multiItemHandler != null)
{
MultiItem.registerMultiItem(unlocalisedName, inGameName, texturePath, multiItemHandler);
}else
{
MultiItem.registerMultiItem(unlocalisedName, inGameName, texturePath);
}
}
/**
* Used to handle the single id for all of the multiitems. Do not change this!
* @return the id of all the multiitems
* @version From DummyCore 1.1
*/
public static int getMultiItemID()
{
return CoreInitialiser.mItem.itemuid;
}
}
+265
View File
@@ -0,0 +1,265 @@
package DummyCore.Items;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import DummyCore.Utils.IDummyMultiItem;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
/**
* @author Modbder
* @version From DummyCore 1.1
* @Description Used to handle all the multiitems. Do not change anything here! Some explanation to the required functions will be given.
*/
public class MultiItem extends Item{
private static List<String> itemNames = new ArrayList();
private static List<String> itemNamesUnlocalisedList = new ArrayList();
private static Hashtable<String,Integer> itemNamesUnlocalised = new Hashtable();
private static List<String> itemTextures = new ArrayList();
private static int id = -1;
public static int itemuid;
private static Icon[] icon;
private static IDummyMultiItem[] handler = new IDummyMultiItem[1024];
public MultiItem(int par1) {
super(par1);
setHasSubtypes(true);
setMaxDamage(0);
itemuid = par1;
// TODO Auto-generated constructor stub
}
private static void addItemName(int i, String name)
{
itemNames.add(i, name);
}
private static void addItemNameMain(int i, String name)
{
itemNamesUnlocalisedList.add(i, name);
}
private static void addItemTexture(int i, String texture)
{
itemTextures.add(i, texture);
}
private static int getNextFreeID()
{
return ++id;
}
private static void registerMain(int i, String s)
{
itemNamesUnlocalised.put(s, i);
addItemNameMain(i,s);
}
/**
* Used to get the metadata(aka. damage) of your item.
* @version From DummyCore 1.1
* @param unlocalisedName - name of your item. Remember, that this is the in-code name!
* @return the metadata, that was given to your item.
*/
public static int getMetadataByName(String unlocalisedName)
{
int i = -1;
if(itemNamesUnlocalised.containsKey(unlocalisedName))
{
i = itemNamesUnlocalised.get(unlocalisedName);
}else
{
throw new RuntimeException("No items with "+unlocalisedName+" index were found!");
}
return i;
}
/**
* Used to get the corresponding ItemStack of your item.
* @version From DummyCore 1.1
* @param unlocalisedName - name of your item. Remember, that this is the in-code name!
* @param size - the size of this stack. max is 64.
* @return automatically generated ItemStack for your item, with MultiItem id, metadata of your item and size that was given.
*/
public static ItemStack getStackByName(String unlocalisedName, int size)
{
ItemStack s = new ItemStack(itemuid,getMetadataByName(unlocalisedName),size);
return s;
}
/**
* This function is the opposite to the getMetadataByName. Used to get name of the item using it's metadata(aka. damage)
* @version From DummyCore 1.1
* @param meta - the metadata(aka. damage) of the item
* @return The corresponding in-code! name.
*/
public static String getUnlocalisedNameByMetadata(int meta)
{
return itemNamesUnlocalisedList.get(meta);
}
/**
* Used to register multiitems without handler.
* @version From DummyCore 1.1
* @param unlocalisedName - name of your item. Remember, that this is the in-code name!
* @param inGameName - in-game name of the item.
* @param texturePath - path to the texture file, that will be used for this item. Should be modname:texturename
*/
public static void registerMultiItem(String unlocalisedName, String inGameName, String texturePath)
{
int itemMeta = getNextFreeID();
registerMain(itemMeta,unlocalisedName);
addItemName(itemMeta,inGameName);
addItemTexture(itemMeta,texturePath);
}
/**
* Used to register multiitems with handler.
* @param unlocalisedName - name of your item. Remember, that this is the in-code name!
* @param inGameName - in-game name of the item.
* @param texturePath - path to the texture file, that will be used for this item. Should be modname:texturename
* @param multiItemHandler - should be an initialized! object, that implements IDummyMultiItem. Usually it is just an empty .class file. Used to handle different actions, happening with your multiitem. Always remember to check for your item's name!
*/
public static void registerMultiItem(String unlocalisedName, String inGameName, String texturePath, IDummyMultiItem multiItemHandler)
{
registerMultiItem(unlocalisedName,inGameName,texturePath);
handler[getMetadataByName(unlocalisedName)] = multiItemHandler;
}
@Override
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
{
for(int i = 0; i < 1024; ++i)
{
if(handler[i] != null)
return handler[i].onItemUse(par1ItemStack, par2EntityPlayer, par3World, par4, par5, par6, par7, par8, par9, par10);
}
return false;
}
@Override
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
{
for(int i = 0; i < 1024; ++i)
{
if(handler[i] != null)
return handler[i].onItemRightClick(par1ItemStack, par2World, par3EntityPlayer);
}
return par1ItemStack;
}
@Override
public boolean hitEntity(ItemStack par1ItemStack, EntityLivingBase par2EntityLivingBase, EntityLivingBase par3EntityLivingBase)
{
for(int i = 0; i < 1024; ++i)
{
if(handler[i] != null)
return handler[i].hitEntity(par1ItemStack, par2EntityLivingBase, par3EntityLivingBase);
}
return false;
}
@Override
public boolean onBlockDestroyed(ItemStack par1ItemStack, World par2World, int par3, int par4, int par5, int par6, EntityLivingBase par7EntityLivingBase)
{
for(int i = 0; i < 1024; ++i)
{
if(handler[i] != null)
return handler[i].onBlockDestroyed(par1ItemStack, par2World, par3, par4, par5, par6, par7EntityLivingBase);
}
return false;
}
@Override
public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5)
{
for(int i = 0; i < 1024; ++i)
{
if(handler[i] != null)
handler[i].onUpdate(par1ItemStack, par2World, par3Entity, par4, par5);
}
}
@Override
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
{
for(int i = 0; i < 1024; ++i)
{
if(handler[i] != null)
handler[i].addInformation(par1ItemStack, par2EntityPlayer, par3List, par4);
}
}
@Override
public EnumRarity getRarity(ItemStack par1ItemStack)
{
for(int i = 0; i < 1024; ++i)
{
if(handler[i] != null)
return handler[i].getRarity(par1ItemStack);
}
return EnumRarity.common;
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister par1IconRegister)
{
int amount = 0;
for(int i = 0; i < itemNamesUnlocalisedList.size(); ++i)
{
if(itemNamesUnlocalisedList.get(i) != null)
{
++amount;
}
}
if(amount > 0)
{
icon = new Icon[amount];
for(int i = 0; i < itemTextures.size(); ++i)
{
if(itemTextures.get(i) != null)
{
icon[i] = par1IconRegister.registerIcon(itemTextures.get(i));
}
}
}
}
@Override
@SideOnly(Side.CLIENT)
public Icon getIconFromDamage(int par1)
{
return icon[par1];
}
@Override
@SideOnly(Side.CLIENT)
public String getItemDisplayName(ItemStack par1ItemStack)
{
return itemNames.get(par1ItemStack.getItemDamage());
}
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
for(int i = 0; i < itemNamesUnlocalisedList.size(); ++i)
if(itemNamesUnlocalisedList.get(i) != null)
par3List.add(i, new ItemStack(par1,1,i));
}
}
+27
View File
@@ -0,0 +1,27 @@
package DummyCore.Utils;
/**
*
* @author Modbder
* @version From DummyCore 1.0
* @Description used to work with 2d coord system. Of course, should be a vec2D, but we are working with minecraft =)
*/
public class Coord2D {
public float x;
public float z;
public Coord2D(float i, float j)
{
this.x = i;
this.z = j;
}
public Coord2D()
{
this(0,0);
}
}
+47
View File
@@ -0,0 +1,47 @@
package DummyCore.Utils;
/**
*
* @author Modbder
* @version From DummyCore 1.1
* @Description Used to work with colors. Requires RGB colors, lesser than 256 to work. Can also convert them to the corresponding Hex value.
*/
public class DummyColor {
private int[] color = new int[3];
public DummyColor(int red, int green, int blue)
{
color[0] = red;
color[1] = green;
color[2] = blue;
}
public int getRed()
{
return color[0];
}
public int getGreen()
{
return color[1];
}
public int getBlue()
{
return color[2];
}
public int getColorInHex()
{
int ret = 0x000000;
int rHex = MathUtils.convertToHex(getRed());
int gHex = MathUtils.convertToHex(getGreen());
int bHex = MathUtils.convertToHex(getBlue());
rHex *= 10000;
gHex *= 100;
ret = rHex+gHex+bHex;
return ret;
}
}
+14
View File
@@ -0,0 +1,14 @@
package DummyCore.Utils;
import net.minecraftforge.common.Configuration;
public class DummyConfig implements IDummyConfig{
public int MultiItemUID;
public int MultiBlockUID;
public void load(Configuration config)
{
MultiItemUID = config.getItem("Multi Item Unique ID", 22899).getInt();
MultiBlockUID = config.getBlock("Multi Block Unique ID", 2480).getInt();
}
}
+39
View File
@@ -0,0 +1,39 @@
package DummyCore.Utils;
/**
*
* @author Modbder
* @version From DummyCore 1.1
* @Description Used to work with multi-colored light system, that will be implemented.
*/
public enum EnumLightColor {
BLACK(51,51,51),
RED(255,51,51),
GREEN(51,255,51),
BROWN(102,51,51),
BLUE(51,51,255),
PURPLE(255,51,255),
CYAN(51,153,255),
SILVER(153,153,153),
GRAY(102,102,102),
PINK(255,102,102),
LIME(102,255,51),
YELLOW(255,255,51),
LIGHTBLUE(153,153,255),
MAGENTA(255,51,204),
ORANGE(255,153,51),
WHITE(204,204,204)
;
private EnumLightColor(int red, int green, int blue)
{
mainColor = new DummyColor(red, green, blue);
}
private DummyColor mainColor;
public DummyColor getColor()
{
return mainColor;
}
}
+20
View File
@@ -0,0 +1,20 @@
package DummyCore.Utils;
import net.minecraftforge.common.Configuration;
/**
*
* @author Modbder
* @version From DummyCore 1.0
* @Description Your config class must implement this to work. Used for easier way of working with configs and for DummyCore handling.
*/
public interface IDummyConfig {
/**
* Automatically called every time your mod is registered in the DummyCore.
* @version From DummyCore 1.0
* @param config - Forge configuration file automatically created.
*/
public abstract void load(Configuration config);
}
+57
View File
@@ -0,0 +1,57 @@
package DummyCore.Utils;
import java.util.List;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.Icon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
/**
*
* @author Modbder
* @version From DummyCore 1.1
* Please remember to check your item's unlocalized name before any actions using MultiBlock.getUnlocalisedNameByMetadata(meta), otherwise every multiblock will function the same!
*/
public interface IDummyMultiBlock {
public boolean canPlaceItemBlockOnSide(World par1World, int par2, int par3, int par4, int par5, EntityPlayer par6EntityPlayer, ItemStack par7ItemStack);
public void onItemBlockUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5);
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4);
public EnumRarity getRarity(ItemStack par1ItemStack);
public float getBlockHardness(Block b, World par1World, int par2, int par3, int par4);
public float getBlockBrightness(Block b, IBlockAccess par1IBlockAccess, int par2, int par3, int par4);
public void registerIcons(IconRegister reg);
public Icon getBlockTexture(Block b, IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5);
public AxisAlignedBB getCollisionBoundingBoxFromPool(Block b, World par1World, int par2, int par3, int par4);
public AxisAlignedBB getSelectedBoundingBoxFromPool(Block b, World par1World, int par2, int par3, int par4);
public void randomDisplayTick(Block b, World par1World, int par2, int par3, int par4, Random par5Random);
public void onBlockDestroyedByPlayer(Block b, World par1World, int par2, int par3, int par4, int par5);
public void onNeighborBlockChange(Block b, World par1World, int par2, int par3, int par4, int par5);
public void onBlockAdded(Block b, World par1World, int par2, int par3, int par4);
public boolean onBlockActivated(Block b, World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9);
public void setBlockBoundsBasedOnState(Block b, IBlockAccess par1IBlockAccess, int par2, int par3, int par4);
}
+33
View File
@@ -0,0 +1,33 @@
package DummyCore.Utils;
import java.util.List;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
/**
*
* @author Modbder
* @version From DummyCore 1.1
* Please remember to check your item's unlocalized name before any actions using MultiItem.getUnlocalisedNameByMetadata(meta), otherwise every multiitem will function the same!
*/
public interface IDummyMultiItem {
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10);
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer);
public boolean hitEntity(ItemStack par1ItemStack, EntityLivingBase par2EntityLivingBase, EntityLivingBase par3EntityLivingBase);
public boolean onBlockDestroyed(ItemStack par1ItemStack, World par2World, int par3, int par4, int par5, int par6, EntityLivingBase par7EntityLivingBase);
public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5);
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4);
public EnumRarity getRarity(ItemStack par1ItemStack);
}
+113
View File
@@ -0,0 +1,113 @@
package DummyCore.Utils;
import java.util.Random;
/**
*
* @author Modbder
* @version From DummyCore 1.0
* @Description can be used to save you some time writing mathematical functions.
*
*/
public class MathUtils {
/**
* Used to get the size of a texture in pixels using current values. Very useful in any kind of progress bars in GUI
* @version From DummyCore 1.0
* @param current - the current value
* @param max - the maximum value
* @param textureSize - the maximum texture size
* @return Percentage-based int. For example, if the textureSize is 50, current is 100 and max is 200 this will return 25 - that is 50% of your texture size.
*/
public static int pixelatedTextureSize(int current, int max, int textureSize)
{
float m = (float)current/max*100;
float n = m/100*textureSize;
return (int)n;
}
/**
* Used to get the persentage between 2 numbers
* @version From DummyCore 1.0
* @param current - the current value
* @param max - the maximum value
* @return Percentage-based int. For example, if current is 100 and max is 200 this will return 50.
*/
public static int getPercentage(int current, int max)
{
float m = (float)current/max*100;
return (int)m;
}
/**
* Used to get the polar-based offset between 2 points in vec2D coord system.
* @version From DummyCore 1.0
* @param position - the current vec2D
* @param angle - the angle of offset
* @param distance - the distance the point will be offset
* @return new Coord2D with offset coords.
*/
public static Coord2D polarOffset(Coord2D position, float angle, float distance)
{
float d0 = (float) (position.x + Math.cos(angle * Math.PI / 180.0D) * distance);
float d1 = (float) (position.z + Math.sin(angle * Math.PI / 180.0D) * distance);
return new Coord2D(d0,d1);
}
/**
* Used to get a completely(-1.0D - 1.0D) random double.
* @version From DummyCore 1.0
* @param rand - the Random, that will randomise this.
* @return a random Double
*/
public static double randomDouble(Random rand)
{
return rand.nextDouble()-rand.nextDouble();
}
/**
* Used to get a completely(-1.0F - 1.0F) random float.
* @version From DummyCore 1.0
* @param rand - the Random, that will randomise this.
* @return a random Float
*/
public static float randomFloat(Random rand)
{
return rand.nextFloat()-rand.nextFloat();
}
/**
* Used to calculate difference between 2 float.
* @version From DummyCore 1.0
* @param pos1 - float #1
* @param pos2 - float #2
* @return always positive value of difference.
*/
public static float getDifference(float pos1, float pos2)
{
float diff = pos1-pos2;
return (float)(Math.sqrt(diff*diff));
}
/**
* Swaps 2 integers between eachother.
* @version From DummyCore 1.1
* @param a - first int to swap
* @param b - second int to swap
* @return int[2] with this 2 values swapped.
*/
public static int[] swap(int a, int b)
{
return new int[]{b,a};
}
/**
* Used to convert deciminal number to the Hexadeciminal.
* @version From DummyCore 1.1
* @param a - the int to be converted
* @return this integer, converted into hexadeciminal
*/
public static int convertToHex(int a)
{
return Integer.parseInt(Integer.toString(a),16);
}
}
+147
View File
@@ -0,0 +1,147 @@
package DummyCore.Utils;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
*
* @author Modbder
* @version From DummyCore 1.0
* @Description can be used to save you some time writing different functions.
*
*/
public class MiscUtils {
/**
* Used to bind texture from the mod. First string is the mod id, and the second is the texture path.
* @version From DummyCore 1.0
* @param mod - the in-code modname. always use small letters!
* @param texture - path to your thexture.
*/
@SideOnly(Side.CLIENT)
public static void bindTexture(String mod, String texture)
{
ResourceLocation loc = new ResourceLocation(mod,texture);
Minecraft.getMinecraft().func_110434_K().func_110577_a(loc);
loc = null;
}
/**
* Creates a new NBTTagCompound for the given ItemStack
* @version From DummyCore 1.0
* @param stack - the ItemStack to work with.
*/
public static void createNBTTag(ItemStack stack)
{
if(stack.hasTagCompound())
{
return;
}
NBTTagCompound itemTag = new NBTTagCompound();
stack.setTagCompound(itemTag);
}
/**
* used to get the ItemStack's tag compound.
* @version From DummyCore 1.0
* @param stack - the ItemStack to work with.
* @return NBTTagCompound of the ItemStack
*/
public static NBTTagCompound getStackTag(ItemStack stack)
{
createNBTTag(stack);
return stack.getTagCompound();
}
/**
* Used to drop items from IInventory when the block is broken.
* @version From DummyCore 1.0
* @param par1World - the World object
* @param par2 - X coordinate of the block
* @param par3 - Y coordinate of the block
* @param par4 - Z coordinate of the block
*/
public static void dropItemsOnBlockBreak(World par1World, int par2, int par3, int par4, int par5, int par6)
{
IInventory inv = (IInventory)par1World.getBlockTileEntity(par2, par3, par4);
if (inv != null)
{
for (int j1 = 0; j1 < inv.getSizeInventory(); ++j1)
{
ItemStack itemstack = inv.getStackInSlot(j1);
if (itemstack != null)
{
float f = par1World.rand.nextFloat() * 0.8F + 0.1F;
float f1 = par1World.rand.nextFloat() * 0.8F + 0.1F;
float f2 = par1World.rand.nextFloat() * 0.8F + 0.1F;
while (itemstack.stackSize > 0)
{
int k1 = par1World.rand.nextInt(21) + 10;
if (k1 > itemstack.stackSize)
{
k1 = itemstack.stackSize;
}
itemstack.stackSize -= k1;
EntityItem entityitem = new EntityItem(par1World, (double)((float)par2 + f), (double)((float)par3 + f1), (double)((float)par4 + f2), new ItemStack(itemstack.itemID, k1, itemstack.getItemDamage()));
if (itemstack.hasTagCompound())
{
entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
}
float f3 = 0.05F;
entityitem.motionX = (double)((float)par1World.rand.nextGaussian() * f3);
entityitem.motionY = (double)((float)par1World.rand.nextGaussian() * f3 + 0.2F);
entityitem.motionZ = (double)((float)par1World.rand.nextGaussian() * f3);
par1World.spawnEntityInWorld(entityitem);
}
}
}
par1World.func_96440_m(par2, par3, par4, par5);
}
}
/**
* More readable way of getting entity's health
* @version From DummyCore 1.0
* @param e - the Entity itself
* @return The amount of health that entity has.
*/
public static float getEntityHealth(EntityLivingBase e)
{
return e.func_110143_aJ();
}
/**
* Used to get the Block at the given coordinates. This returns the block itself!
* @version From DummyCore 1.1
* @param w - the world object.
* @param x - X coordinate of the block
* @param y - Y coordinate of the block
* @param z - Z coordinate of the block
* @return the Block that is at the given coordinates.
*/
public static Block getBlock(IBlockAccess w, int x, int y, int z)
{
Block ret = null;
ret = Block.blocksList[w.getBlockId(x, y, z)];
return ret;
}
}
+89
View File
@@ -0,0 +1,89 @@
package DummyCore.Utils;
import java.io.PrintStream;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import ViSuCraft.ViSuProject.Mod.ViSuMod;
import net.minecraft.client.Minecraft;
public class Notifier {
//======================================String Beginning Indexes===============================================//
private static String info = "[INFO]";
private static String warning = "[WARNING]";
private static String error = "[ERROR]";
private static String severe = "[SEVERE]";
//======================================String Second Indexes===============================================//
private static String dev = "[DEV]";
private static String debug = "[DEBUG]";
private static String stdout = "[STDOUT]";
//======================================String Ending Indexes===============================================//
private static String system = "[SYSTEM]";
private static String mod = "[DummyCore]";
private static StringBuilder builder = new StringBuilder();
public static void notify(String... s)
{
String begin = "";
String mid = "";
String end = "";
String mesg = s[3];
mid = s[1];
end = s[2];
String out = buildString(begin,mid,end,mesg);
publish(out);
}
public static void notifyDev(String s)
{
notify("",dev,mod,s);
}
public static void notifyDevCustomMod(String modname, String s)
{
modname = "["+modname+"]";
notify("",dev,modname,s);
}
public static void notifyDebugCustomMod(String modname, String s)
{
modname = "["+modname+"]";
notify("",debug,modname,s);
}
public static void notifyDebug(String s)
{
notify("",debug,mod,s);
}
public static void notifySystem(String s)
{
notify("","",system,s);
}
public static void notifySimple(String s)
{
notify("","",mod,s);
}
public static void notifyCustomMod(String modname,String s)
{
modname = "["+modname+"]";
notify("","",modname,s);
}
public static String buildString(String...strings)
{
return strings[0] + " " + strings[1] + " " + strings[2] + " " + strings[3] + " ";
}
public static void publish(String s)
{
System.out.println(s);
}
}