From 340d6cd93cc98a6f03bb5856ca9fcbb4e8a63e14 Mon Sep 17 00:00:00 2001 From: Modbder Date: Wed, 11 Sep 2013 01:46:05 -0700 Subject: [PATCH 1/9] Create README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..355b960 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +DummyCore +========= +This branch is a dev builds branch. +DummyCore is a package required for mods made by dummy thinking. It also can be used in another projects. +All sources are here, so you can create your mods using DummyCore, or even modify the core. From 88f6481a59490a0741a6e26c304f58bc4418f974 Mon Sep 17 00:00:00 2001 From: Modbder Date: Wed, 11 Sep 2013 20:04:12 +0400 Subject: [PATCH 2/9] Revert "DummyCore first build(1.1dev)" This reverts commit b3efe0c897a39e5d43dee4b4c6b3c7e5d1e15c25. --- DummyCore/Blocks/BlocksRegistry.java | 93 ------ DummyCore/Blocks/ItemMultiBlock.java | 123 -------- DummyCore/Blocks/MultiBlock.java | 264 ----------------- DummyCore/Core/Core.java | 218 -------------- DummyCore/Core/CoreInitialiser.java | 83 ------ .../CreativeTabs/CreativePageBlocks.java | 91 ------ DummyCore/CreativeTabs/CreativePageItems.java | 94 ------- DummyCore/Items/ItemRegistry.java | 82 ------ DummyCore/Items/MultiItem.java | 265 ------------------ DummyCore/Utils/Coord2D.java | 27 -- DummyCore/Utils/DummyColor.java | 47 ---- DummyCore/Utils/DummyConfig.java | 14 - DummyCore/Utils/EnumLightColor.java | 39 --- DummyCore/Utils/IDummyConfig.java | 20 -- DummyCore/Utils/IDummyMultiBlock.java | 57 ---- DummyCore/Utils/IDummyMultiItem.java | 33 --- DummyCore/Utils/MathUtils.java | 113 -------- DummyCore/Utils/MiscUtils.java | 147 ---------- DummyCore/Utils/Notifier.java | 89 ------ 19 files changed, 1899 deletions(-) delete mode 100644 DummyCore/Blocks/BlocksRegistry.java delete mode 100644 DummyCore/Blocks/ItemMultiBlock.java delete mode 100644 DummyCore/Blocks/MultiBlock.java delete mode 100644 DummyCore/Core/Core.java delete mode 100644 DummyCore/Core/CoreInitialiser.java delete mode 100644 DummyCore/CreativeTabs/CreativePageBlocks.java delete mode 100644 DummyCore/CreativeTabs/CreativePageItems.java delete mode 100644 DummyCore/Items/ItemRegistry.java delete mode 100644 DummyCore/Items/MultiItem.java delete mode 100644 DummyCore/Utils/Coord2D.java delete mode 100644 DummyCore/Utils/DummyColor.java delete mode 100644 DummyCore/Utils/DummyConfig.java delete mode 100644 DummyCore/Utils/EnumLightColor.java delete mode 100644 DummyCore/Utils/IDummyConfig.java delete mode 100644 DummyCore/Utils/IDummyMultiBlock.java delete mode 100644 DummyCore/Utils/IDummyMultiItem.java delete mode 100644 DummyCore/Utils/MathUtils.java delete mode 100644 DummyCore/Utils/MiscUtils.java delete mode 100644 DummyCore/Utils/Notifier.java diff --git a/DummyCore/Blocks/BlocksRegistry.java b/DummyCore/Blocks/BlocksRegistry.java deleted file mode 100644 index 3b8a9a8..0000000 --- a/DummyCore/Blocks/BlocksRegistry.java +++ /dev/null @@ -1,93 +0,0 @@ -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 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; - } - -} diff --git a/DummyCore/Blocks/ItemMultiBlock.java b/DummyCore/Blocks/ItemMultiBlock.java deleted file mode 100644 index e4f6159..0000000 --- a/DummyCore/Blocks/ItemMultiBlock.java +++ /dev/null @@ -1,123 +0,0 @@ -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; - } - -} diff --git a/DummyCore/Blocks/MultiBlock.java b/DummyCore/Blocks/MultiBlock.java deleted file mode 100644 index 108650b..0000000 --- a/DummyCore/Blocks/MultiBlock.java +++ /dev/null @@ -1,264 +0,0 @@ -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 blockNames = new ArrayList(); - protected static List blockNamesUnlocalisedList = new ArrayList(); - protected static Hashtable blockNamesUnlocalised = new Hashtable(); - protected static List 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; - } - -} diff --git a/DummyCore/Core/Core.java b/DummyCore/Core/Core.java deleted file mode 100644 index 8a3ae8f..0000000 --- a/DummyCore/Core/Core.java +++ /dev/null @@ -1,218 +0,0 @@ -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(); - private static HashMap langFilesList = new HashMap(); - private static HashMap configurationList = new HashMap(); - private static List modNameList = new ArrayList(); - 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)]; - } - -} diff --git a/DummyCore/Core/CoreInitialiser.java b/DummyCore/Core/CoreInitialiser.java deleted file mode 100644 index 1d0074d..0000000 --- a/DummyCore/Core/CoreInitialiser.java +++ /dev/null @@ -1,83 +0,0 @@ -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 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; - -} diff --git a/DummyCore/CreativeTabs/CreativePageBlocks.java b/DummyCore/CreativeTabs/CreativePageBlocks.java deleted file mode 100644 index 3fff81d..0000000 --- a/DummyCore/CreativeTabs/CreativePageBlocks.java +++ /dev/null @@ -1,91 +0,0 @@ -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; - } -} \ No newline at end of file diff --git a/DummyCore/CreativeTabs/CreativePageItems.java b/DummyCore/CreativeTabs/CreativePageItems.java deleted file mode 100644 index 0e9d019..0000000 --- a/DummyCore/CreativeTabs/CreativePageItems.java +++ /dev/null @@ -1,94 +0,0 @@ -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; - } -} \ No newline at end of file diff --git a/DummyCore/Items/ItemRegistry.java b/DummyCore/Items/ItemRegistry.java deleted file mode 100644 index cbf8ba0..0000000 --- a/DummyCore/Items/ItemRegistry.java +++ /dev/null @@ -1,82 +0,0 @@ -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 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; - } - -} diff --git a/DummyCore/Items/MultiItem.java b/DummyCore/Items/MultiItem.java deleted file mode 100644 index e841df4..0000000 --- a/DummyCore/Items/MultiItem.java +++ /dev/null @@ -1,265 +0,0 @@ -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 itemNames = new ArrayList(); - private static List itemNamesUnlocalisedList = new ArrayList(); - private static Hashtable itemNamesUnlocalised = new Hashtable(); - private static List 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)); - } - -} diff --git a/DummyCore/Utils/Coord2D.java b/DummyCore/Utils/Coord2D.java deleted file mode 100644 index bfe6905..0000000 --- a/DummyCore/Utils/Coord2D.java +++ /dev/null @@ -1,27 +0,0 @@ -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); - } - - - -} diff --git a/DummyCore/Utils/DummyColor.java b/DummyCore/Utils/DummyColor.java deleted file mode 100644 index fc40af8..0000000 --- a/DummyCore/Utils/DummyColor.java +++ /dev/null @@ -1,47 +0,0 @@ -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; - } - -} diff --git a/DummyCore/Utils/DummyConfig.java b/DummyCore/Utils/DummyConfig.java deleted file mode 100644 index 48dd50b..0000000 --- a/DummyCore/Utils/DummyConfig.java +++ /dev/null @@ -1,14 +0,0 @@ -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(); - } -} diff --git a/DummyCore/Utils/EnumLightColor.java b/DummyCore/Utils/EnumLightColor.java deleted file mode 100644 index c7e728a..0000000 --- a/DummyCore/Utils/EnumLightColor.java +++ /dev/null @@ -1,39 +0,0 @@ -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; - } - -} diff --git a/DummyCore/Utils/IDummyConfig.java b/DummyCore/Utils/IDummyConfig.java deleted file mode 100644 index 02eb63e..0000000 --- a/DummyCore/Utils/IDummyConfig.java +++ /dev/null @@ -1,20 +0,0 @@ -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); - -} diff --git a/DummyCore/Utils/IDummyMultiBlock.java b/DummyCore/Utils/IDummyMultiBlock.java deleted file mode 100644 index 6caee02..0000000 --- a/DummyCore/Utils/IDummyMultiBlock.java +++ /dev/null @@ -1,57 +0,0 @@ -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); -} diff --git a/DummyCore/Utils/IDummyMultiItem.java b/DummyCore/Utils/IDummyMultiItem.java deleted file mode 100644 index 0b6e774..0000000 --- a/DummyCore/Utils/IDummyMultiItem.java +++ /dev/null @@ -1,33 +0,0 @@ -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); -} diff --git a/DummyCore/Utils/MathUtils.java b/DummyCore/Utils/MathUtils.java deleted file mode 100644 index cd0140f..0000000 --- a/DummyCore/Utils/MathUtils.java +++ /dev/null @@ -1,113 +0,0 @@ -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); - } -} diff --git a/DummyCore/Utils/MiscUtils.java b/DummyCore/Utils/MiscUtils.java deleted file mode 100644 index 7d4cd79..0000000 --- a/DummyCore/Utils/MiscUtils.java +++ /dev/null @@ -1,147 +0,0 @@ -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; - } - -} diff --git a/DummyCore/Utils/Notifier.java b/DummyCore/Utils/Notifier.java deleted file mode 100644 index cc67cc5..0000000 --- a/DummyCore/Utils/Notifier.java +++ /dev/null @@ -1,89 +0,0 @@ -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); - } - -} From c5698e07fc73460a7ebb5fe1c97cc119f29a233e Mon Sep 17 00:00:00 2001 From: Modbder Date: Wed, 11 Sep 2013 20:04:30 +0400 Subject: [PATCH 3/9] Revert "Revert "DummyCore first build(1.1dev)"" This reverts commit 135e6fd7a9d1e3491137ad4633fdb3b51d9b5352. --- DummyCore/Blocks/BlocksRegistry.java | 93 ++++++ DummyCore/Blocks/ItemMultiBlock.java | 123 ++++++++ DummyCore/Blocks/MultiBlock.java | 264 +++++++++++++++++ DummyCore/Core/Core.java | 218 ++++++++++++++ DummyCore/Core/CoreInitialiser.java | 83 ++++++ .../CreativeTabs/CreativePageBlocks.java | 91 ++++++ DummyCore/CreativeTabs/CreativePageItems.java | 94 +++++++ DummyCore/Items/ItemRegistry.java | 82 ++++++ DummyCore/Items/MultiItem.java | 265 ++++++++++++++++++ DummyCore/Utils/Coord2D.java | 27 ++ DummyCore/Utils/DummyColor.java | 47 ++++ DummyCore/Utils/DummyConfig.java | 14 + DummyCore/Utils/EnumLightColor.java | 39 +++ DummyCore/Utils/IDummyConfig.java | 20 ++ DummyCore/Utils/IDummyMultiBlock.java | 57 ++++ DummyCore/Utils/IDummyMultiItem.java | 33 +++ DummyCore/Utils/MathUtils.java | 113 ++++++++ DummyCore/Utils/MiscUtils.java | 147 ++++++++++ DummyCore/Utils/Notifier.java | 89 ++++++ 19 files changed, 1899 insertions(+) create mode 100644 DummyCore/Blocks/BlocksRegistry.java create mode 100644 DummyCore/Blocks/ItemMultiBlock.java create mode 100644 DummyCore/Blocks/MultiBlock.java create mode 100644 DummyCore/Core/Core.java create mode 100644 DummyCore/Core/CoreInitialiser.java create mode 100644 DummyCore/CreativeTabs/CreativePageBlocks.java create mode 100644 DummyCore/CreativeTabs/CreativePageItems.java create mode 100644 DummyCore/Items/ItemRegistry.java create mode 100644 DummyCore/Items/MultiItem.java create mode 100644 DummyCore/Utils/Coord2D.java create mode 100644 DummyCore/Utils/DummyColor.java create mode 100644 DummyCore/Utils/DummyConfig.java create mode 100644 DummyCore/Utils/EnumLightColor.java create mode 100644 DummyCore/Utils/IDummyConfig.java create mode 100644 DummyCore/Utils/IDummyMultiBlock.java create mode 100644 DummyCore/Utils/IDummyMultiItem.java create mode 100644 DummyCore/Utils/MathUtils.java create mode 100644 DummyCore/Utils/MiscUtils.java create mode 100644 DummyCore/Utils/Notifier.java diff --git a/DummyCore/Blocks/BlocksRegistry.java b/DummyCore/Blocks/BlocksRegistry.java new file mode 100644 index 0000000..3b8a9a8 --- /dev/null +++ b/DummyCore/Blocks/BlocksRegistry.java @@ -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 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; + } + +} diff --git a/DummyCore/Blocks/ItemMultiBlock.java b/DummyCore/Blocks/ItemMultiBlock.java new file mode 100644 index 0000000..e4f6159 --- /dev/null +++ b/DummyCore/Blocks/ItemMultiBlock.java @@ -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; + } + +} diff --git a/DummyCore/Blocks/MultiBlock.java b/DummyCore/Blocks/MultiBlock.java new file mode 100644 index 0000000..108650b --- /dev/null +++ b/DummyCore/Blocks/MultiBlock.java @@ -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 blockNames = new ArrayList(); + protected static List blockNamesUnlocalisedList = new ArrayList(); + protected static Hashtable blockNamesUnlocalised = new Hashtable(); + protected static List 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; + } + +} diff --git a/DummyCore/Core/Core.java b/DummyCore/Core/Core.java new file mode 100644 index 0000000..8a3ae8f --- /dev/null +++ b/DummyCore/Core/Core.java @@ -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(); + private static HashMap langFilesList = new HashMap(); + private static HashMap configurationList = new HashMap(); + private static List modNameList = new ArrayList(); + 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)]; + } + +} diff --git a/DummyCore/Core/CoreInitialiser.java b/DummyCore/Core/CoreInitialiser.java new file mode 100644 index 0000000..1d0074d --- /dev/null +++ b/DummyCore/Core/CoreInitialiser.java @@ -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 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; + +} diff --git a/DummyCore/CreativeTabs/CreativePageBlocks.java b/DummyCore/CreativeTabs/CreativePageBlocks.java new file mode 100644 index 0000000..3fff81d --- /dev/null +++ b/DummyCore/CreativeTabs/CreativePageBlocks.java @@ -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; + } +} \ No newline at end of file diff --git a/DummyCore/CreativeTabs/CreativePageItems.java b/DummyCore/CreativeTabs/CreativePageItems.java new file mode 100644 index 0000000..0e9d019 --- /dev/null +++ b/DummyCore/CreativeTabs/CreativePageItems.java @@ -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; + } +} \ No newline at end of file diff --git a/DummyCore/Items/ItemRegistry.java b/DummyCore/Items/ItemRegistry.java new file mode 100644 index 0000000..cbf8ba0 --- /dev/null +++ b/DummyCore/Items/ItemRegistry.java @@ -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 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; + } + +} diff --git a/DummyCore/Items/MultiItem.java b/DummyCore/Items/MultiItem.java new file mode 100644 index 0000000..e841df4 --- /dev/null +++ b/DummyCore/Items/MultiItem.java @@ -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 itemNames = new ArrayList(); + private static List itemNamesUnlocalisedList = new ArrayList(); + private static Hashtable itemNamesUnlocalised = new Hashtable(); + private static List 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)); + } + +} diff --git a/DummyCore/Utils/Coord2D.java b/DummyCore/Utils/Coord2D.java new file mode 100644 index 0000000..bfe6905 --- /dev/null +++ b/DummyCore/Utils/Coord2D.java @@ -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); + } + + + +} diff --git a/DummyCore/Utils/DummyColor.java b/DummyCore/Utils/DummyColor.java new file mode 100644 index 0000000..fc40af8 --- /dev/null +++ b/DummyCore/Utils/DummyColor.java @@ -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; + } + +} diff --git a/DummyCore/Utils/DummyConfig.java b/DummyCore/Utils/DummyConfig.java new file mode 100644 index 0000000..48dd50b --- /dev/null +++ b/DummyCore/Utils/DummyConfig.java @@ -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(); + } +} diff --git a/DummyCore/Utils/EnumLightColor.java b/DummyCore/Utils/EnumLightColor.java new file mode 100644 index 0000000..c7e728a --- /dev/null +++ b/DummyCore/Utils/EnumLightColor.java @@ -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; + } + +} diff --git a/DummyCore/Utils/IDummyConfig.java b/DummyCore/Utils/IDummyConfig.java new file mode 100644 index 0000000..02eb63e --- /dev/null +++ b/DummyCore/Utils/IDummyConfig.java @@ -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); + +} diff --git a/DummyCore/Utils/IDummyMultiBlock.java b/DummyCore/Utils/IDummyMultiBlock.java new file mode 100644 index 0000000..6caee02 --- /dev/null +++ b/DummyCore/Utils/IDummyMultiBlock.java @@ -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); +} diff --git a/DummyCore/Utils/IDummyMultiItem.java b/DummyCore/Utils/IDummyMultiItem.java new file mode 100644 index 0000000..0b6e774 --- /dev/null +++ b/DummyCore/Utils/IDummyMultiItem.java @@ -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); +} diff --git a/DummyCore/Utils/MathUtils.java b/DummyCore/Utils/MathUtils.java new file mode 100644 index 0000000..cd0140f --- /dev/null +++ b/DummyCore/Utils/MathUtils.java @@ -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); + } +} diff --git a/DummyCore/Utils/MiscUtils.java b/DummyCore/Utils/MiscUtils.java new file mode 100644 index 0000000..7d4cd79 --- /dev/null +++ b/DummyCore/Utils/MiscUtils.java @@ -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; + } + +} diff --git a/DummyCore/Utils/Notifier.java b/DummyCore/Utils/Notifier.java new file mode 100644 index 0000000..cc67cc5 --- /dev/null +++ b/DummyCore/Utils/Notifier.java @@ -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); + } + +} From 572b21bd533f64f7064b1296550a4f3817a028e2 Mon Sep 17 00:00:00 2001 From: Modbder Date: Wed, 11 Sep 2013 20:05:46 +0400 Subject: [PATCH 4/9] 1.1 colored lights update Finally included the system of colored lightning! Also, some minor changes. --- DummyCore/Core/Core.java | 4 + DummyCore/Core/CoreInitialiser.java | 19 + DummyCore/Utils/BlockEmmitsColoredLight.java | 66 ++ DummyCore/Utils/ColoredLightHandler.java | 95 +++ DummyCore/Utils/Coord3D.java | 36 ++ DummyCore/Utils/EnumLightColor.java | 19 +- DummyCore/Utils/RendererColoredLight.java | 612 +++++++++++++++++++ 7 files changed, 850 insertions(+), 1 deletion(-) create mode 100644 DummyCore/Utils/BlockEmmitsColoredLight.java create mode 100644 DummyCore/Utils/ColoredLightHandler.java create mode 100644 DummyCore/Utils/Coord3D.java create mode 100644 DummyCore/Utils/RendererColoredLight.java diff --git a/DummyCore/Core/Core.java b/DummyCore/Core/Core.java index 8a3ae8f..b5438ac 100644 --- a/DummyCore/Core/Core.java +++ b/DummyCore/Core/Core.java @@ -9,14 +9,18 @@ import java.util.List; import DummyCore.CreativeTabs.CreativePageBlocks; import DummyCore.CreativeTabs.CreativePageItems; +import DummyCore.Utils.EnumLightColor; import DummyCore.Utils.IDummyConfig; import DummyCore.Utils.Notifier; +import net.minecraft.block.Block; 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 { + public static List lightBlocks = new ArrayList(); + public static List lightColors = new ArrayList(); private static HashMap modList = new HashMap(); private static HashMap langFilesList = new HashMap(); private static HashMap configurationList = new HashMap(); diff --git a/DummyCore/Core/CoreInitialiser.java b/DummyCore/Core/CoreInitialiser.java index 1d0074d..efc1615 100644 --- a/DummyCore/Core/CoreInitialiser.java +++ b/DummyCore/Core/CoreInitialiser.java @@ -18,10 +18,15 @@ import DummyCore.Blocks.ItemMultiBlock; import DummyCore.Blocks.MultiBlock; import DummyCore.Items.ItemRegistry; import DummyCore.Items.MultiItem; +import DummyCore.Utils.ColoredLightHandler; import DummyCore.Utils.DummyConfig; +import DummyCore.Utils.EnumLightColor; import DummyCore.Utils.MathUtils; import DummyCore.Utils.Notifier; +import DummyCore.Utils.RendererColoredLight; +import cpw.mods.fml.client.registry.RenderingRegistry; import cpw.mods.fml.common.DummyModContainer; +import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.Metadata; import cpw.mods.fml.common.ModMetadata; @@ -29,7 +34,10 @@ 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.network.NetworkMod; +import cpw.mods.fml.common.registry.EntityRegistry; import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.Side; /** * Do not change anythig here! This is used to initialise MultiBlocks and MultiItems. @@ -37,6 +45,7 @@ import cpw.mods.fml.common.registry.GameRegistry; * @version From DummyCore 1.0 */ @Mod(modid = "DummyCore", name = "DummyCore", version = "1.1dev", useMetadata = true) +@NetworkMod(clientSideRequired = true, serverSideRequired = false, channels = "DummyCore") public class CoreInitialiser extends DummyModContainer{ public static final CoreInitialiser instance = new CoreInitialiser(); private static DummyConfig cfg = new DummyConfig(); @@ -61,6 +70,10 @@ public class CoreInitialiser extends DummyModContainer{ @EventHandler public void preInit(FMLPreInitializationEvent e) throws Exception { + for(int i = 0; i < 16; ++i) + { + Core.lightColors.add(EnumLightColor.values()[i]); + } Core.registerModAbsolute(getClass(), "DummyCore", e.getModConfigurationDirectory().getAbsolutePath(),cfg); } @@ -76,6 +89,12 @@ public class CoreInitialiser extends DummyModContainer{ 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()); + EntityRegistry.registerModEntity(ColoredLightHandler.class, "DummyCore.ColoredLightHandler", 54, this, 64, 1, false); + Side s = FMLCommonHandler.instance().getEffectiveSide(); + if(s == Side.CLIENT) + { + RenderingRegistry.registerEntityRenderingHandler(ColoredLightHandler.class, new RendererColoredLight()); + } } public static MultiItem mItem; public static MultiBlock mBlock; diff --git a/DummyCore/Utils/BlockEmmitsColoredLight.java b/DummyCore/Utils/BlockEmmitsColoredLight.java new file mode 100644 index 0000000..1427930 --- /dev/null +++ b/DummyCore/Utils/BlockEmmitsColoredLight.java @@ -0,0 +1,66 @@ +package DummyCore.Utils; + +import DummyCore.Core.Core; +import net.minecraft.block.Block; +import net.minecraft.block.BlockContainer; +import net.minecraft.block.material.Material; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +/** + * @version From DummyCore 1.1 + * @author Modbder + * @Description make your blocks extend this to make the emmit colored lightning. Warning! Colored lightning is still in beta-testing, and for sure contains lots of bugs! + */ +public class BlockEmmitsColoredLight extends BlockContainer{ + + public BlockEmmitsColoredLight(int par1, Material par2Material) { + super(par1, par2Material); + if(!Core.lightBlocks.contains(this)) + Core.lightBlocks.add(this); + } + + /** + * Used to get the color of the light. Look in EnumLightColor to see more of the colors. + * @version From DummyCore 1.1 + * @param world - 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 color of the light the block will emit. + */ + public EnumLightColor getColor(IBlockAccess world, int x, int y, int z) + { + return EnumLightColor.WHITE; + } + + /** + * Used to get the brightness of the light. By default equivalents to the light amount, the block gives + * @version From DummyCore 1.1 + * @param world - 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 number from 0 to 15, corresponding to the light value + */ + public float getLightBrightness(IBlockAccess world, int x, int y, int z) + { + return this.lightValue[world.getBlockId(x, y, z)]; + } + + @Override + public int onBlockPlaced(World w, int x, int y, int z, int par5, float par6, float par7, float par8, int par9) + { + ColoredLightHandler light = new ColoredLightHandler(w, getColor(w,x,y,z).getLightID(), getLightBrightness(w,x,y,z)); + light.setPosition(x+0.5F, y+0.5F, z+0.5F); + if(!w.isRemote) + w.spawnEntityInWorld(light); + return super.onBlockPlaced(w, x, y, z, par5, par6, par7, par8, par9); + } + + @Override + public TileEntity createNewTileEntity(World world) { + return null; + } + +} diff --git a/DummyCore/Utils/ColoredLightHandler.java b/DummyCore/Utils/ColoredLightHandler.java new file mode 100644 index 0000000..758a7ea --- /dev/null +++ b/DummyCore/Utils/ColoredLightHandler.java @@ -0,0 +1,95 @@ +package DummyCore.Utils; +import DummyCore.Core.Core; +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; + +public class ColoredLightHandler extends Entity{ + private int renderColor; + private float colorSize; + + public ColoredLightHandler(World par1World) { + super(par1World); + setSize(0.4F,0.4F); + this.renderColor = 0; + this.colorSize = 0; + this.noClip = true; + this.ignoreFrustumCheck = true; + } + + public ColoredLightHandler(World par1World, int par2) { + this(par1World); + this.renderColor = par2; + } + + public ColoredLightHandler(World par1World, int par2, float par3) { + this(par1World); + this.renderColor = par2; + this.colorSize = par3; + } + + @Override + protected void entityInit() { + this.dataWatcher.addObject(12, 0); + this.dataWatcher.addObject(13, 0.0F); + } + + @Override + protected void readEntityFromNBT(NBTTagCompound nbttagcompound) { + setColor(nbttagcompound.getInteger("color")); + setColorSize(nbttagcompound.getFloat("colorSize")); + } + + @Override + protected void writeEntityToNBT(NBTTagCompound nbttagcompound) { + nbttagcompound.setInteger("color", getRenderColor()); + nbttagcompound.setFloat("colorSize", getRenderColorSize()); + } + + private void setColor(int i) + { + if(!this.worldObj.isRemote) + { + this.dataWatcher.updateObject(12, i); + } + this.renderColor = i; + } + + + private void setColorSize(float i) + { + if(!this.worldObj.isRemote) + { + this.dataWatcher.updateObject(13, i); + } + this.colorSize = i; + } + + public int getRenderColor() + { + return this.dataWatcher.getWatchableObjectInt(12); + } + + public float getRenderColorSize() + { + return this.dataWatcher.func_111145_d(13); + } + + @Override + public void moveEntity(double par1, double par3, double par5){} + + @Override + public void onUpdate() + { + this.posY = (int)this.posY; + Block b = MiscUtils.getBlock(worldObj, (int)posX, (int)posY-1, (int)posZ); + Block b1 = MiscUtils.getBlock(worldObj, (int)posX, (int)posY, (int)posZ); + if((b == null && b1 == null) || (!Core.lightBlocks.contains(b) && !Core.lightBlocks.contains(b1))) + { + this.setDead(); + } + super.onUpdate(); + } + +} diff --git a/DummyCore/Utils/Coord3D.java b/DummyCore/Utils/Coord3D.java new file mode 100644 index 0000000..374e171 --- /dev/null +++ b/DummyCore/Utils/Coord3D.java @@ -0,0 +1,36 @@ +package DummyCore.Utils; + +/** + * + * @author Modbder + * @version From DummyCore 1.1 + * @Description used to work with 3d coord system. Of course, should be a vec3D, but we are working with minecraft =) + */ +public class Coord3D { + + public float x; + public float y; + public float z; + + public Coord3D(double posX, double posY, double posZ) + { + this.x = (float) posX; + this.y = (float) posY; + this.z = (float) posZ; + } + + public Coord3D(float i, float k, float j) + { + this.x = i; + this.y = k; + this.z = j; + } + + public Coord3D() + { + this(0,0,0); + } + + + +} diff --git a/DummyCore/Utils/EnumLightColor.java b/DummyCore/Utils/EnumLightColor.java index c7e728a..95cbd58 100644 --- a/DummyCore/Utils/EnumLightColor.java +++ b/DummyCore/Utils/EnumLightColor.java @@ -1,10 +1,13 @@ package DummyCore.Utils; +import java.util.ArrayList; +import java.util.List; + /** * * @author Modbder * @version From DummyCore 1.1 - * @Description Used to work with multi-colored light system, that will be implemented. + * @Description Used to work with multi-colored light system. */ public enum EnumLightColor { BLACK(51,51,51), @@ -27,6 +30,7 @@ public enum EnumLightColor { private EnumLightColor(int red, int green, int blue) { mainColor = new DummyColor(red, green, blue); + colorID = setGlobal(); } private DummyColor mainColor; @@ -35,5 +39,18 @@ public enum EnumLightColor { { return mainColor; } + + private int setGlobal() + { + return ++globalID; + } + + public int getLightID() + { + return colorID; + } + + private int colorID = 0; + private static int globalID = -1; } diff --git a/DummyCore/Utils/RendererColoredLight.java b/DummyCore/Utils/RendererColoredLight.java new file mode 100644 index 0000000..d9e7242 --- /dev/null +++ b/DummyCore/Utils/RendererColoredLight.java @@ -0,0 +1,612 @@ +package DummyCore.Utils; + +import java.util.Random; + +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; + +import DummyCore.Core.Core; +import net.minecraft.block.Block; +import net.minecraft.block.BlockAnvil; +import net.minecraft.block.BlockHopper; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.ChestItemRenderHelper; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.entity.Render; +import net.minecraft.entity.Entity; +import net.minecraft.entity.boss.EntityDragon; +import net.minecraft.entity.projectile.EntityPotion; +import net.minecraft.item.ItemPotion; +import net.minecraft.potion.PotionHelper; +import net.minecraft.src.FMLRenderAccessLibrary; +import net.minecraft.util.Icon; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.IBlockAccess; + +public class RendererColoredLight extends Render{ + + private RenderBlocks blockRenderer = new RenderBlocks(); + @Override + public void doRender(Entity entity, double d0, double d1, double d2, + float f, float f1) { + if(entity instanceof ColoredLightHandler) + { + entity = (ColoredLightHandler)entity; + GL11.glDisable(GL11.GL_TEXTURE_2D); + GL11.glShadeModel(GL11.GL_SMOOTH); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE); + GL11.glDisable(GL11.GL_ALPHA_TEST); + GL11.glEnable(GL11.GL_CULL_FACE); + GL11.glDepthMask(false); + GL11.glPushMatrix(); + blockRenderer.blockAccess = entity.worldObj; + EnumLightColor lightColor = EnumLightColor.WHITE; + float lightSize = 1.0F; + Coord3D ePos = new Coord3D(entity.posX,entity.posY,entity.posZ); + Block b = MiscUtils.getBlock(entity.worldObj, (int)entity.posX, (int)entity.posY-1, (int)entity.posZ); + Block b1 = MiscUtils.getBlock(entity.worldObj, (int)entity.posX, (int)entity.posY, (int)entity.posZ); + if(b != null && Core.lightBlocks.contains(b) && b instanceof BlockEmmitsColoredLight) + { + lightColor = ((BlockEmmitsColoredLight)b).getColor(entity.worldObj, (int)entity.posX, (int)entity.posY-1, (int)entity.posZ); + lightSize = ((BlockEmmitsColoredLight)b).getLightBrightness(entity.worldObj, (int)entity.posX, (int)entity.posY-1, (int)entity.posZ); + } + if(b1 != null && Core.lightBlocks.contains(b1) && b1 instanceof BlockEmmitsColoredLight) + { + lightColor = ((BlockEmmitsColoredLight)b1).getColor(entity.worldObj, (int)entity.posX, (int)entity.posY, (int)entity.posZ); + lightSize = ((BlockEmmitsColoredLight)b1).getLightBrightness(entity.worldObj, (int)entity.posX, (int)entity.posY, (int)entity.posZ); + } + for(int x = -8; x < 8; ++x) + { + for(int y = -8; y < 8; ++y) + { + for(int z = -8; z < 8; ++z) + { + Coord3D bPos = new Coord3D(entity.posX+x,entity.posY+y,entity.posZ+z); + float posX = (bPos.x - ePos.x); + float posY = (bPos.y - ePos.y); + float posZ = (bPos.z - ePos.z); + posX = (float) Math.sqrt(posX*posX); + posY = (float) Math.sqrt(posY*posY); + posZ = (float) Math.sqrt(posZ*posZ); + float distance = (posX+posY+posZ)/3; + distance = (float) Math.sqrt(distance*distance); + float brightness = (lightSize/16) - (distance/4); + if(brightness<0)brightness=0; + //if(brightness > 0.6F) System.out.println(distance); + Block b11 = MiscUtils.getBlock(entity.worldObj, (int)entity.posX+x, (int)entity.posY+y-1, (int)entity.posZ+z); + if(b11 != null) + renderCorrectLight(d0+x+0.5D,d1+y-0.5D,d2+z+0.5D,brightness,entity.worldObj,b11,lightColor); + } + } + } + GL11.glPopMatrix(); + GL11.glDepthMask(true); + GL11.glDisable(GL11.GL_CULL_FACE); + GL11.glDisable(GL11.GL_BLEND); + GL11.glShadeModel(GL11.GL_FLAT); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glEnable(GL11.GL_TEXTURE_2D); + GL11.glEnable(GL11.GL_ALPHA_TEST); + } + } + + @Override + protected ResourceLocation func_110775_a(Entity entity) { + // TODO Auto-generated method stub + return new ResourceLocation("dummycore","textures/misc/lightmap.png"); + } + + protected void renderCorrectLight(double par2, double par4, double par6, float brightness,IBlockAccess w,Block block, EnumLightColor color) + { + Tessellator var3 = Tessellator.instance; + RenderHelper.disableStandardItemLighting(); + float var4 = 1; + float var5 = 0.0F; + float stability = 1; + int mru = 20000; + GL11.glPushMatrix(); + GL11.glTranslated(par2-0.5D, par4, par6-0.5D); + GL11.glScalef(1.0015F, 1.0015F, 1.0015F); + //blockRenderer.renderBlockAllFaces(Block.glass, (int)par2, (int)par4, (int)par6); + blockRenderer.useInventoryTint = true; + if(brightness > 0) + this.renderBlockAsItem(block, 0, brightness,color); + GL11.glPopMatrix(); + RenderHelper.enableStandardItemLighting(); + } + + public void renderBlockAsItem(Block par1Block, int par2, float par3, EnumLightColor color) + { + Tessellator tessellator = Tessellator.instance; + boolean flag = false; + + if (par1Block == Block.dispenser || par1Block == Block.dropper || par1Block == Block.furnaceIdle) + { + par2 = 3; + } + + int j; + float f1 = color.getColor().getRed(); + float f2 = color.getColor().getGreen(); + float f3 = color.getColor().getBlue(); + + if (blockRenderer.useInventoryTint) + { + f1 = f1 / 255.0F; + f2 = f2 / 255.0F; + f3 = f3 / 255.0F; + GL11.glColor4f(f1 * par3, f2 * par3, f3 * par3, par3); + } + + j = par1Block.getRenderType(); + blockRenderer.setRenderBoundsFromBlock(par1Block); + int k; + + if (j != 0 && j != 31 && j != 39 && j != 16 && j != 26) + { + if (j == 1) + { + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, -1.0F, 0.0F); + blockRenderer.drawCrossedSquares(par1Block, par2, -0.5D, -0.5D, -0.5D, 1.0F); + tessellator.draw(); + } + else if (j == 19) + { + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, -1.0F, 0.0F); + par1Block.setBlockBoundsForItemRender(); + blockRenderer.renderBlockStemSmall(par1Block, par2, blockRenderer.renderMaxY, -0.5D, -0.5D, -0.5D); + tessellator.draw(); + } + else if (j == 23) + { + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, -1.0F, 0.0F); + par1Block.setBlockBoundsForItemRender(); + tessellator.draw(); + } + else if (j == 13) + { + par1Block.setBlockBoundsForItemRender(); + GL11.glTranslatef(-0.5F, -0.5F, -0.5F); + f1 = 0.0625F; + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, -1.0F, 0.0F); + blockRenderer.renderFaceYNeg(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSide(par1Block, 0)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 1.0F, 0.0F); + blockRenderer.renderFaceYPos(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSide(par1Block, 1)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 0.0F, -1.0F); + tessellator.addTranslation(0.0F, 0.0F, f1); + blockRenderer.renderFaceZNeg(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSide(par1Block, 2)); + tessellator.addTranslation(0.0F, 0.0F, -f1); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 0.0F, 1.0F); + tessellator.addTranslation(0.0F, 0.0F, -f1); + blockRenderer.renderFaceZPos(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSide(par1Block, 3)); + tessellator.addTranslation(0.0F, 0.0F, f1); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(-1.0F, 0.0F, 0.0F); + tessellator.addTranslation(f1, 0.0F, 0.0F); + blockRenderer.renderFaceXNeg(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSide(par1Block, 4)); + tessellator.addTranslation(-f1, 0.0F, 0.0F); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(1.0F, 0.0F, 0.0F); + tessellator.addTranslation(-f1, 0.0F, 0.0F); + blockRenderer.renderFaceXPos(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSide(par1Block, 5)); + tessellator.addTranslation(f1, 0.0F, 0.0F); + tessellator.draw(); + GL11.glTranslatef(0.5F, 0.5F, 0.5F); + } + else if (j == 22) + { + GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F); + GL11.glTranslatef(-0.5F, -0.5F, -0.5F); + ChestItemRenderHelper.instance.renderChest(par1Block, par2, par3); + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + } + else if (j == 6) + { + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, -1.0F, 0.0F); + blockRenderer.renderBlockCropsImpl(par1Block, par2, -0.5D, -0.5D, -0.5D); + tessellator.draw(); + } + else if (j == 2) + { + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, -1.0F, 0.0F); + blockRenderer.renderTorchAtAngle(par1Block, -0.5D, -0.5D, -0.5D, 0.0D, 0.0D, 0); + tessellator.draw(); + } + else if (j == 10) + { + for (k = 0; k < 2; ++k) + { + if (k == 0) + { + blockRenderer.setRenderBounds(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 0.5D); + } + + if (k == 1) + { + blockRenderer.setRenderBounds(0.0D, 0.0D, 0.5D, 1.0D, 0.5D, 1.0D); + } + + GL11.glTranslatef(-0.5F, -0.5F, -0.5F); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, -1.0F, 0.0F); + blockRenderer.renderFaceYNeg(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSide(par1Block, 0)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 1.0F, 0.0F); + blockRenderer.renderFaceYPos(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSide(par1Block, 1)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 0.0F, -1.0F); + blockRenderer.renderFaceZNeg(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSide(par1Block, 2)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 0.0F, 1.0F); + blockRenderer.renderFaceZPos(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSide(par1Block, 3)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(-1.0F, 0.0F, 0.0F); + blockRenderer.renderFaceXNeg(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSide(par1Block, 4)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(1.0F, 0.0F, 0.0F); + blockRenderer.renderFaceXPos(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSide(par1Block, 5)); + tessellator.draw(); + GL11.glTranslatef(0.5F, 0.5F, 0.5F); + } + } + else if (j == 27) + { + k = 0; + GL11.glTranslatef(-0.5F, -0.5F, -0.5F); + tessellator.startDrawingQuads(); + + for (int l = 0; l < 8; ++l) + { + byte b0 = 0; + byte b1 = 1; + + if (l == 0) + { + b0 = 2; + } + + if (l == 1) + { + b0 = 3; + } + + if (l == 2) + { + b0 = 4; + } + + if (l == 3) + { + b0 = 5; + b1 = 2; + } + + if (l == 4) + { + b0 = 6; + b1 = 3; + } + + if (l == 5) + { + b0 = 7; + b1 = 5; + } + + if (l == 6) + { + b0 = 6; + b1 = 2; + } + + if (l == 7) + { + b0 = 3; + } + + float f4 = (float)b0 / 16.0F; + float f5 = 1.0F - (float)k / 16.0F; + float f6 = 1.0F - (float)(k + b1) / 16.0F; + k += b1; + blockRenderer.setRenderBounds((double)(0.5F - f4), (double)f6, (double)(0.5F - f4), (double)(0.5F + f4), (double)f5, (double)(0.5F + f4)); + tessellator.setNormal(0.0F, -1.0F, 0.0F); + blockRenderer.renderFaceYNeg(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSide(par1Block, 0)); + tessellator.setNormal(0.0F, 1.0F, 0.0F); + blockRenderer.renderFaceYPos(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSide(par1Block, 1)); + tessellator.setNormal(0.0F, 0.0F, -1.0F); + blockRenderer.renderFaceZNeg(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSide(par1Block, 2)); + tessellator.setNormal(0.0F, 0.0F, 1.0F); + blockRenderer.renderFaceZPos(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSide(par1Block, 3)); + tessellator.setNormal(-1.0F, 0.0F, 0.0F); + blockRenderer.renderFaceXNeg(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSide(par1Block, 4)); + tessellator.setNormal(1.0F, 0.0F, 0.0F); + blockRenderer.renderFaceXPos(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSide(par1Block, 5)); + } + + tessellator.draw(); + GL11.glTranslatef(0.5F, 0.5F, 0.5F); + blockRenderer.setRenderBounds(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D); + } + else if (j == 11) + { + for (k = 0; k < 4; ++k) + { + f2 = 0.125F; + + if (k == 0) + { + blockRenderer.setRenderBounds((double)(0.5F - f2), 0.0D, 0.0D, (double)(0.5F + f2), 1.0D, (double)(f2 * 2.0F)); + } + + if (k == 1) + { + blockRenderer.setRenderBounds((double)(0.5F - f2), 0.0D, (double)(1.0F - f2 * 2.0F), (double)(0.5F + f2), 1.0D, 1.0D); + } + + f2 = 0.0625F; + + if (k == 2) + { + blockRenderer.setRenderBounds((double)(0.5F - f2), (double)(1.0F - f2 * 3.0F), (double)(-f2 * 2.0F), (double)(0.5F + f2), (double)(1.0F - f2), (double)(1.0F + f2 * 2.0F)); + } + + if (k == 3) + { + blockRenderer.setRenderBounds((double)(0.5F - f2), (double)(0.5F - f2 * 3.0F), (double)(-f2 * 2.0F), (double)(0.5F + f2), (double)(0.5F - f2), (double)(1.0F + f2 * 2.0F)); + } + + GL11.glTranslatef(-0.5F, -0.5F, -0.5F); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, -1.0F, 0.0F); + blockRenderer.renderFaceYNeg(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSide(par1Block, 0)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 1.0F, 0.0F); + blockRenderer.renderFaceYPos(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSide(par1Block, 1)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 0.0F, -1.0F); + blockRenderer.renderFaceZNeg(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSide(par1Block, 2)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 0.0F, 1.0F); + blockRenderer.renderFaceZPos(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSide(par1Block, 3)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(-1.0F, 0.0F, 0.0F); + blockRenderer.renderFaceXNeg(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSide(par1Block, 4)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(1.0F, 0.0F, 0.0F); + blockRenderer.renderFaceXPos(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSide(par1Block, 5)); + tessellator.draw(); + GL11.glTranslatef(0.5F, 0.5F, 0.5F); + } + + blockRenderer.setRenderBounds(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D); + } + else if (j == 21) + { + for (k = 0; k < 3; ++k) + { + f2 = 0.0625F; + + if (k == 0) + { + blockRenderer.setRenderBounds((double)(0.5F - f2), 0.30000001192092896D, 0.0D, (double)(0.5F + f2), 1.0D, (double)(f2 * 2.0F)); + } + + if (k == 1) + { + blockRenderer.setRenderBounds((double)(0.5F - f2), 0.30000001192092896D, (double)(1.0F - f2 * 2.0F), (double)(0.5F + f2), 1.0D, 1.0D); + } + + f2 = 0.0625F; + + if (k == 2) + { + blockRenderer.setRenderBounds((double)(0.5F - f2), 0.5D, 0.0D, (double)(0.5F + f2), (double)(1.0F - f2), 1.0D); + } + + GL11.glTranslatef(-0.5F, -0.5F, -0.5F); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, -1.0F, 0.0F); + blockRenderer.renderFaceYNeg(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSide(par1Block, 0)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 1.0F, 0.0F); + blockRenderer.renderFaceYPos(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSide(par1Block, 1)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 0.0F, -1.0F); + blockRenderer.renderFaceZNeg(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSide(par1Block, 2)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 0.0F, 1.0F); + blockRenderer.renderFaceZPos(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSide(par1Block, 3)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(-1.0F, 0.0F, 0.0F); + blockRenderer.renderFaceXNeg(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSide(par1Block, 4)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(1.0F, 0.0F, 0.0F); + blockRenderer.renderFaceXPos(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSide(par1Block, 5)); + tessellator.draw(); + GL11.glTranslatef(0.5F, 0.5F, 0.5F); + } + } + else if (j == 32) + { + for (k = 0; k < 2; ++k) + { + if (k == 0) + { + blockRenderer.setRenderBounds(0.0D, 0.0D, 0.3125D, 1.0D, 0.8125D, 0.6875D); + } + + if (k == 1) + { + blockRenderer.setRenderBounds(0.25D, 0.0D, 0.25D, 0.75D, 1.0D, 0.75D); + } + + GL11.glTranslatef(-0.5F, -0.5F, -0.5F); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, -1.0F, 0.0F); + blockRenderer.renderFaceYNeg(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSideAndMetadata(par1Block, 0, par2)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 1.0F, 0.0F); + blockRenderer.renderFaceYPos(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSideAndMetadata(par1Block, 1, par2)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 0.0F, -1.0F); + blockRenderer.renderFaceZNeg(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSideAndMetadata(par1Block, 2, par2)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 0.0F, 1.0F); + blockRenderer.renderFaceZPos(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSideAndMetadata(par1Block, 3, par2)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(-1.0F, 0.0F, 0.0F); + blockRenderer.renderFaceXNeg(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSideAndMetadata(par1Block, 4, par2)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(1.0F, 0.0F, 0.0F); + blockRenderer.renderFaceXPos(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSideAndMetadata(par1Block, 5, par2)); + tessellator.draw(); + GL11.glTranslatef(0.5F, 0.5F, 0.5F); + } + + blockRenderer.setRenderBounds(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D); + } + else if (j == 35) + { + GL11.glTranslatef(-0.5F, -0.5F, -0.5F); + blockRenderer.renderBlockAnvilOrient((BlockAnvil)par1Block, 0, 0, 0, par2 << 2, true); + GL11.glTranslatef(0.5F, 0.5F, 0.5F); + } + else if (j == 34) + { + for (k = 0; k < 3; ++k) + { + if (k == 0) + { + blockRenderer.setRenderBounds(0.125D, 0.0D, 0.125D, 0.875D, 0.1875D, 0.875D); + blockRenderer.setOverrideBlockTexture(blockRenderer.getBlockIcon(Block.obsidian)); + } + else if (k == 1) + { + blockRenderer.setRenderBounds(0.1875D, 0.1875D, 0.1875D, 0.8125D, 0.875D, 0.8125D); + blockRenderer.setOverrideBlockTexture(blockRenderer.getBlockIcon(Block.beacon)); + } + else if (k == 2) + { + blockRenderer.setRenderBounds(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D); + blockRenderer.setOverrideBlockTexture(blockRenderer.getBlockIcon(Block.glass)); + } + + GL11.glTranslatef(-0.5F, -0.5F, -0.5F); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, -1.0F, 0.0F); + blockRenderer.renderFaceYNeg(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSideAndMetadata(par1Block, 0, par2)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 1.0F, 0.0F); + blockRenderer.renderFaceYPos(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSideAndMetadata(par1Block, 1, par2)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 0.0F, -1.0F); + blockRenderer.renderFaceZNeg(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSideAndMetadata(par1Block, 2, par2)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 0.0F, 1.0F); + blockRenderer.renderFaceZPos(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSideAndMetadata(par1Block, 3, par2)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(-1.0F, 0.0F, 0.0F); + blockRenderer.renderFaceXNeg(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSideAndMetadata(par1Block, 4, par2)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(1.0F, 0.0F, 0.0F); + blockRenderer.renderFaceXPos(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSideAndMetadata(par1Block, 5, par2)); + tessellator.draw(); + GL11.glTranslatef(0.5F, 0.5F, 0.5F); + } + + blockRenderer.setRenderBounds(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D); + blockRenderer.clearOverrideBlockTexture(); + } + else if (j == 38) + { + GL11.glTranslatef(-0.5F, -0.5F, -0.5F); + blockRenderer.renderBlockHopperMetadata((BlockHopper)par1Block, 0, 0, 0, 0, true); + GL11.glTranslatef(0.5F, 0.5F, 0.5F); + } + else + { + FMLRenderAccessLibrary.renderInventoryBlock(blockRenderer, par1Block, par2, j); + } + } + else + { + if (j == 16) + { + par2 = 1; + } + GL11.glColor4f(f1*par3, f2*par3, f3*par3,par3); + par1Block.setBlockBoundsForItemRender(); + blockRenderer.setRenderBoundsFromBlock(par1Block); + GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F); + GL11.glTranslatef(-0.5F, -0.5F, -0.5F); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, -1.0F, 0.0F); + blockRenderer.renderFaceYNeg(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSideAndMetadata(par1Block, 0, par2)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 1.0F, 0.0F); + blockRenderer.renderFaceYPos(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSideAndMetadata(par1Block, 1, par2)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 0.0F, -1.0F); + blockRenderer.renderFaceZNeg(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSideAndMetadata(par1Block, 2, par2)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 0.0F, 1.0F); + blockRenderer.renderFaceZPos(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSideAndMetadata(par1Block, 3, par2)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(-1.0F, 0.0F, 0.0F); + blockRenderer.renderFaceXNeg(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSideAndMetadata(par1Block, 4, par2)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(1.0F, 0.0F, 0.0F); + blockRenderer.renderFaceXPos(par1Block, 0.0D, 0.0D, 0.0D, blockRenderer.getBlockIconFromSideAndMetadata(par1Block, 5, par2)); + tessellator.draw(); + GL11.glTranslatef(0.5F, 0.5F, 0.5F); + } + } + +} From 025e1ce374a991649b30950de5af2b68035c747b Mon Sep 17 00:00:00 2001 From: Modbder Date: Wed, 11 Sep 2013 20:23:55 +0400 Subject: [PATCH 5/9] 1.1 Minor fixes Some more minor fixes. --- DummyCore/Blocks/MultiBlock.java | 12 ++++++++++++ DummyCore/Core/CoreInitialiser.java | 4 ++-- DummyCore/Utils/IDummyMultiBlock.java | 2 ++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/DummyCore/Blocks/MultiBlock.java b/DummyCore/Blocks/MultiBlock.java index 108650b..00095dd 100644 --- a/DummyCore/Blocks/MultiBlock.java +++ b/DummyCore/Blocks/MultiBlock.java @@ -160,6 +160,18 @@ public class MultiBlock extends Block{ return icon[par1IBlockAccess.getBlockMetadata(par2,par3,par4)]; } + @SideOnly(Side.CLIENT) + @Override + public Icon getIcon(int par1, int par2) + { + for(int i = 0; i < 1024; ++i) + { + if(handler[i] != null) + return handler[i].getIcon(par1, par2); + } + return this.icon[par2]; + } + @SideOnly(Side.CLIENT) @Override public AxisAlignedBB getSelectedBoundingBoxFromPool(World par1World, int par2, int par3, int par4) diff --git a/DummyCore/Core/CoreInitialiser.java b/DummyCore/Core/CoreInitialiser.java index efc1615..1d20d4a 100644 --- a/DummyCore/Core/CoreInitialiser.java +++ b/DummyCore/Core/CoreInitialiser.java @@ -82,11 +82,11 @@ public class CoreInitialiser extends DummyModContainer{ { 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.registerMultiItem("dummyDebugItem", "Debug Item From Dummy Core", "cake", 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()); + BlocksRegistry.registerMultiBlock("dummyDebugBlock", "Debug Block From Dummy Core", "comparator_on", null, getClass()); GameRegistry.registerBlock(mBlock, ItemMultiBlock.class, Core.getModName(Core.getIdForMod(getClass()))+".block."+mBlock.getUnlocalizedName()); BlocksRegistry.blocksList.put(mBlock, Core.getBlockTabForMod(getClass()).getTabLabel()); EntityRegistry.registerModEntity(ColoredLightHandler.class, "DummyCore.ColoredLightHandler", 54, this, 64, 1, false); diff --git a/DummyCore/Utils/IDummyMultiBlock.java b/DummyCore/Utils/IDummyMultiBlock.java index 6caee02..1bd32dc 100644 --- a/DummyCore/Utils/IDummyMultiBlock.java +++ b/DummyCore/Utils/IDummyMultiBlock.java @@ -54,4 +54,6 @@ public interface IDummyMultiBlock { 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); + + public Icon getIcon(int par1, int par2); } From 321814f61329e79e541d5dca5bd9f97a1614e9e6 Mon Sep 17 00:00:00 2001 From: Modbder Date: Fri, 20 Sep 2013 16:31:17 +0400 Subject: [PATCH 6/9] 1.2 update Sorted things properly, some minor changes, MultiItem now allows you to set the color of the stack. Also, DummyData system was added for you to store your variables in it more easy. --- DummyCore/Blocks/MultiBlock.java | 2 + .../Renderer}/RendererColoredLight.java | 34 ++++--- DummyCore/Core/CoreInitialiser.java | 21 +++-- DummyCore/Items/MultiItem.java | 53 +++++++++-- DummyCore/Utils/ColoredLightHandler.java | 2 +- DummyCore/Utils/DataStorage.java | 89 +++++++++++++++++++ DummyCore/Utils/DummyBounds.java | 24 +++++ DummyCore/Utils/DummyData.java | 30 +++++++ DummyCore/Utils/DummyDistance.java | 41 +++++++++ DummyCore/Utils/IDummyMultiItem.java | 2 + DummyCore/Utils/MathUtils.java | 13 ++- DummyCore/Utils/MiscUtils.java | 4 +- DummyCore/Utils/Notifier.java | 2 - 13 files changed, 284 insertions(+), 33 deletions(-) rename DummyCore/{Utils => Client/Renderer}/RendererColoredLight.java (96%) create mode 100644 DummyCore/Utils/DataStorage.java create mode 100644 DummyCore/Utils/DummyBounds.java create mode 100644 DummyCore/Utils/DummyData.java create mode 100644 DummyCore/Utils/DummyDistance.java diff --git a/DummyCore/Blocks/MultiBlock.java b/DummyCore/Blocks/MultiBlock.java index 00095dd..fc35c35 100644 --- a/DummyCore/Blocks/MultiBlock.java +++ b/DummyCore/Blocks/MultiBlock.java @@ -34,6 +34,7 @@ public class MultiBlock extends Block{ public static int blockuid; protected static Icon[] icon; protected static IDummyMultiBlock[] handler = new IDummyMultiBlock[1024]; + public static int blocks; public MultiBlock(int par1) { super(par1, Material.circuits); blockuid = par1; @@ -63,6 +64,7 @@ public class MultiBlock extends Block{ { blockNamesUnlocalised.put(s, i); addBlockNameMain(i,s); + ++blocks; } /** diff --git a/DummyCore/Utils/RendererColoredLight.java b/DummyCore/Client/Renderer/RendererColoredLight.java similarity index 96% rename from DummyCore/Utils/RendererColoredLight.java rename to DummyCore/Client/Renderer/RendererColoredLight.java index d9e7242..e043eee 100644 --- a/DummyCore/Utils/RendererColoredLight.java +++ b/DummyCore/Client/Renderer/RendererColoredLight.java @@ -1,4 +1,4 @@ -package DummyCore.Utils; +package DummyCore.Client.Renderer; import java.util.Random; @@ -6,6 +6,12 @@ import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; import DummyCore.Core.Core; +import DummyCore.Utils.BlockEmmitsColoredLight; +import DummyCore.Utils.ColoredLightHandler; +import DummyCore.Utils.Coord3D; +import DummyCore.Utils.DummyDistance; +import DummyCore.Utils.EnumLightColor; +import DummyCore.Utils.MiscUtils; import net.minecraft.block.Block; import net.minecraft.block.BlockAnvil; import net.minecraft.block.BlockHopper; @@ -65,14 +71,15 @@ public class RendererColoredLight extends Render{ for(int z = -8; z < 8; ++z) { Coord3D bPos = new Coord3D(entity.posX+x,entity.posY+y,entity.posZ+z); - float posX = (bPos.x - ePos.x); - float posY = (bPos.y - ePos.y); - float posZ = (bPos.z - ePos.z); - posX = (float) Math.sqrt(posX*posX); - posY = (float) Math.sqrt(posY*posY); - posZ = (float) Math.sqrt(posZ*posZ); - float distance = (posX+posY+posZ)/3; - distance = (float) Math.sqrt(distance*distance); + //float posX = (bPos.x - ePos.x); + //float posY = (bPos.y - ePos.y); + //float posZ = (bPos.z - ePos.z); + //posX = (float) Math.sqrt(posX*posX); + //posY = (float) Math.sqrt(posY*posY); + //posZ = (float) Math.sqrt(posZ*posZ); + //float distance = (posX+posY+posZ)/3; + float distance = new DummyDistance(bPos,ePos).getDistance(); + //distance = (float) Math.sqrt(distance*distance); float brightness = (lightSize/16) - (distance/4); if(brightness<0)brightness=0; //if(brightness > 0.6F) System.out.println(distance); @@ -94,7 +101,7 @@ public class RendererColoredLight extends Render{ } @Override - protected ResourceLocation func_110775_a(Entity entity) { + protected ResourceLocation getEntityTexture(Entity entity) { // TODO Auto-generated method stub return new ResourceLocation("dummycore","textures/misc/lightmap.png"); } @@ -118,7 +125,8 @@ public class RendererColoredLight extends Render{ RenderHelper.enableStandardItemLighting(); } - public void renderBlockAsItem(Block par1Block, int par2, float par3, EnumLightColor color) + @SuppressWarnings("unused") + public void renderBlockAsItem(Block par1Block, int par2, float par3, EnumLightColor color) { Tessellator tessellator = Tessellator.instance; boolean flag = false; @@ -145,7 +153,7 @@ public class RendererColoredLight extends Render{ blockRenderer.setRenderBoundsFromBlock(par1Block); int k; - if (j != 0 && j != 31 && j != 39 && j != 16 && j != 26) + if (false) { if (j == 1) { @@ -570,7 +578,7 @@ public class RendererColoredLight extends Render{ FMLRenderAccessLibrary.renderInventoryBlock(blockRenderer, par1Block, par2, j); } } - else + else if(j == 0) { if (j == 16) { diff --git a/DummyCore/Core/CoreInitialiser.java b/DummyCore/Core/CoreInitialiser.java index 1d20d4a..1c2bda1 100644 --- a/DummyCore/Core/CoreInitialiser.java +++ b/DummyCore/Core/CoreInitialiser.java @@ -12,10 +12,16 @@ import org.bouncycastle.util.encoders.HexEncoder; import org.bouncycastle.util.encoders.HexTranslator; import net.minecraft.block.Block; +import net.minecraft.client.particle.EntityDiggingFX; +import net.minecraft.client.particle.EntityFX; +import net.minecraft.client.particle.EntitySmokeFX; import net.minecraft.client.resources.ResourcePack; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; import DummyCore.Blocks.BlocksRegistry; import DummyCore.Blocks.ItemMultiBlock; import DummyCore.Blocks.MultiBlock; +import DummyCore.Client.Renderer.RendererColoredLight; import DummyCore.Items.ItemRegistry; import DummyCore.Items.MultiItem; import DummyCore.Utils.ColoredLightHandler; @@ -23,7 +29,6 @@ import DummyCore.Utils.DummyConfig; import DummyCore.Utils.EnumLightColor; import DummyCore.Utils.MathUtils; import DummyCore.Utils.Notifier; -import DummyCore.Utils.RendererColoredLight; import cpw.mods.fml.client.registry.RenderingRegistry; import cpw.mods.fml.common.DummyModContainer; import cpw.mods.fml.common.FMLCommonHandler; @@ -32,11 +37,13 @@ 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.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLInterModComms.IMCEvent; import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.registry.EntityRegistry; import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.common.registry.TickRegistry; import cpw.mods.fml.relauncher.Side; /** @@ -75,11 +82,6 @@ public class CoreInitialiser extends DummyModContainer{ Core.lightColors.add(EnumLightColor.values()[i]); } 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", "cake", null, getClass()); @@ -96,6 +98,13 @@ public class CoreInitialiser extends DummyModContainer{ RenderingRegistry.registerEntityRenderingHandler(ColoredLightHandler.class, new RendererColoredLight()); } } + + @EventHandler + public void postInit(FMLPostInitializationEvent e) + { + Notifier.notifySimple(MultiItem.items+" MultiItems registered."); + Notifier.notifySimple(MultiBlock.blocks+" MultiBlocks registered."); + } public static MultiItem mItem; public static MultiBlock mBlock; diff --git a/DummyCore/Items/MultiItem.java b/DummyCore/Items/MultiItem.java index e841df4..33743c8 100644 --- a/DummyCore/Items/MultiItem.java +++ b/DummyCore/Items/MultiItem.java @@ -32,8 +32,9 @@ public class MultiItem extends Item{ private static List itemTextures = new ArrayList(); private static int id = -1; public static int itemuid; - private static Icon[] icon; + private static Icon[] icon = new Icon[2048]; private static IDummyMultiItem[] handler = new IDummyMultiItem[1024]; + public static int items; public MultiItem(int par1) { super(par1); @@ -67,6 +68,7 @@ public class MultiItem extends Item{ { itemNamesUnlocalised.put(s, i); addItemNameMain(i,s); + ++items; } /** @@ -146,7 +148,11 @@ public class MultiItem extends Item{ 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); + { + boolean result = handler[i].onItemUse(par1ItemStack, par2EntityPlayer, par3World, par4, par5, par6, par7, par8, par9, par10); + if(result = true) + return result; + } } return false; } @@ -157,7 +163,11 @@ public class MultiItem extends Item{ for(int i = 0; i < 1024; ++i) { if(handler[i] != null) - return handler[i].onItemRightClick(par1ItemStack, par2World, par3EntityPlayer); + { + ItemStack result = handler[i].onItemRightClick(par1ItemStack, par2World, par3EntityPlayer); + if(result != null) + return result; + } } return par1ItemStack; } @@ -168,7 +178,11 @@ public class MultiItem extends Item{ for(int i = 0; i < 1024; ++i) { if(handler[i] != null) - return handler[i].hitEntity(par1ItemStack, par2EntityLivingBase, par3EntityLivingBase); + { + boolean result = handler[i].hitEntity(par1ItemStack, par2EntityLivingBase, par3EntityLivingBase); + if(result != false) + return result; + } } return false; } @@ -179,7 +193,11 @@ public class MultiItem extends Item{ for(int i = 0; i < 1024; ++i) { if(handler[i] != null) - return handler[i].onBlockDestroyed(par1ItemStack, par2World, par3, par4, par5, par6, par7EntityLivingBase); + { + boolean result = handler[i].onBlockDestroyed(par1ItemStack, par2World, par3, par4, par5, par6, par7EntityLivingBase); + if(result != false) + return result; + } } return false; } @@ -187,13 +205,29 @@ public class MultiItem extends Item{ @Override public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5) { - for(int i = 0; i < 1024; ++i) { + for(int i = 0; i < 1024; ++i) if(handler[i] != null) handler[i].onUpdate(par1ItemStack, par2World, par3Entity, par4, par5); } } + @Override + @SideOnly(Side.CLIENT) + public int getColorFromItemStack(ItemStack par1ItemStack, int par2) + { + for(int i = 0; i < 1024; ++i) + { + if(handler[i] != null) + { + int result = handler[i].getColorFromItemStack(par1ItemStack, par2); + if(result != -1) + return result; + } + } + return 16777215; + } + @Override public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) { @@ -210,7 +244,11 @@ public class MultiItem extends Item{ for(int i = 0; i < 1024; ++i) { if(handler[i] != null) - return handler[i].getRarity(par1ItemStack); + { + EnumRarity result = handler[i].getRarity(par1ItemStack); + if(result != EnumRarity.common) + return result; + } } return EnumRarity.common; } @@ -229,7 +267,6 @@ public class MultiItem extends Item{ } if(amount > 0) { - icon = new Icon[amount]; for(int i = 0; i < itemTextures.size(); ++i) { if(itemTextures.get(i) != null) diff --git a/DummyCore/Utils/ColoredLightHandler.java b/DummyCore/Utils/ColoredLightHandler.java index 758a7ea..74690b8 100644 --- a/DummyCore/Utils/ColoredLightHandler.java +++ b/DummyCore/Utils/ColoredLightHandler.java @@ -73,7 +73,7 @@ public class ColoredLightHandler extends Entity{ public float getRenderColorSize() { - return this.dataWatcher.func_111145_d(13); + return this.dataWatcher.getWatchableObjectFloat(13); } @Override diff --git a/DummyCore/Utils/DataStorage.java b/DummyCore/Utils/DataStorage.java new file mode 100644 index 0000000..5f02985 --- /dev/null +++ b/DummyCore/Utils/DataStorage.java @@ -0,0 +1,89 @@ +package DummyCore.Utils; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author Modbder + * @version From DummyCore 1.2 + * @Description used to store almost any kind of variable in a single String instance. + */ +public class DataStorage { + private static String dataString = ""; + + /** + * Adds the given DummyData to the data string + * @version From DummyCore 1.2 + * @param data - the data to be added to the string + */ + public static void addDataToString(DummyData data) + { + dataString = dataString.concat(data.toString()); + } + + /** + * Returns the data string, with all data written to it. Also resets the string, so this should be used only once, after you have stored all your data. + * @version From DummyCore 1.2 + * @return Correctly formated DataString + */ + public static String getDataString() + { + String ret = dataString; + dataString = ""; + return ret; + } + + /** + * Used to get your DummyData from the correctly formated string. + * @version From DummyCore 1.2 + * @param s - the string to extract data from + * @return - An array of all data from the given string + */ + public static DummyData[] parseData(String s) + { + String field = ""; + Object value = null; + List data = new ArrayList(); + for(int i = 0; i < s.length(); ++i) + { + if(i+2 < s.length() && s.substring(i, i+2).contains("||")) + { + int size = 0; + ForSize:for(int i1 = i; i1 < s.length();++i1) + { + if(s.charAt(i1) == ':') + break ForSize; + ++size; + } + field = s.substring(i+2, i+size); + } + if(i+1 < s.length() && s.substring(i, i+1).contains(":")) + { + int size = 0; + ForSize:for(int i1 = i; i1 < s.length();++i1) + { + if(s.charAt(i1) == '|') + break ForSize; + ++size; + } + value = s.substring(i+1, i+size); + } + if(field != "" && value != null) + { + DummyData date = new DummyData(field,value); + data.add(date); + field = ""; + value = null; + } + } + DummyData[] ret = new DummyData[data.size()]; + for(int i = 0; i < ret.length; ++i) + { + ret[i] = data.get(i); + } + return ret; + } + +} diff --git a/DummyCore/Utils/DummyBounds.java b/DummyCore/Utils/DummyBounds.java new file mode 100644 index 0000000..d88e323 --- /dev/null +++ b/DummyCore/Utils/DummyBounds.java @@ -0,0 +1,24 @@ +package DummyCore.Utils; + +/** + * + * @author Modbder + * @version From DummyCore 1.2 + * @Description Used to check, if the float is inbetween 2 others. + */ +public class DummyBounds { + private final float min; + private final float max; + + public DummyBounds(float m1, float m2) + { + min = m1; + max = m2; + } + + public boolean isInRange(float f) + { + return f > min && f < max; + } + +} diff --git a/DummyCore/Utils/DummyData.java b/DummyCore/Utils/DummyData.java new file mode 100644 index 0000000..df43a20 --- /dev/null +++ b/DummyCore/Utils/DummyData.java @@ -0,0 +1,30 @@ +package DummyCore.Utils; + +/** + * + * @author Modbder + * @version From DummyCore 1.2 + * @Description used to store almost any kind of variable using a special Data. When working, remember, that you can store any Object to the corresponding name. + */ +public class DummyData { + public final String fieldName; + public final String fieldValue; + public DummyData(String field, String value) + { + fieldName = field; + fieldValue = value; + } + + public DummyData(String field, Object value) + { + fieldName = field; + fieldValue = value.toString(); + } + + public String toString() + { + String ret = ""; + ret = ret.concat("||").concat(fieldName).concat(":").concat(fieldValue.toString()); + return ret; + } +} diff --git a/DummyCore/Utils/DummyDistance.java b/DummyCore/Utils/DummyDistance.java new file mode 100644 index 0000000..5f20894 --- /dev/null +++ b/DummyCore/Utils/DummyDistance.java @@ -0,0 +1,41 @@ +package DummyCore.Utils; + +/** + * + * @author Modbder + * @version From DummyCore 1.2 + * @Description Used to store the distance betwenn 2 points. + */ +public class DummyDistance { + private final float distance; + + public DummyDistance() + { + distance = 0; + } + + public DummyDistance(Coord3D first, Coord3D second) + { + float diffX = MathUtils.getDifference(first.x, second.x); + float diffY = MathUtils.getDifference(first.y, second.y); + float diffZ = MathUtils.getDifference(first.z, second.z); + distance = (diffX+diffY+diffZ)/3; + } + + public DummyDistance(Coord2D first, Coord2D second) + { + float diffX = MathUtils.getDifference(first.x, second.x); + float diffZ = MathUtils.getDifference(first.z, second.z); + distance = (diffX+diffZ)/2; + } + + public DummyDistance(float first, float second) + { + distance = MathUtils.getDifference(first, second); + } + + public float getDistance() + { + return this.distance; + } +} diff --git a/DummyCore/Utils/IDummyMultiItem.java b/DummyCore/Utils/IDummyMultiItem.java index 0b6e774..f7bbef4 100644 --- a/DummyCore/Utils/IDummyMultiItem.java +++ b/DummyCore/Utils/IDummyMultiItem.java @@ -28,6 +28,8 @@ public interface IDummyMultiItem { 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 int getColorFromItemStack(ItemStack par1ItemStack, int par2); public EnumRarity getRarity(ItemStack par1ItemStack); } diff --git a/DummyCore/Utils/MathUtils.java b/DummyCore/Utils/MathUtils.java index cd0140f..490a976 100644 --- a/DummyCore/Utils/MathUtils.java +++ b/DummyCore/Utils/MathUtils.java @@ -85,7 +85,7 @@ public class MathUtils { public static float getDifference(float pos1, float pos2) { float diff = pos1-pos2; - return (float)(Math.sqrt(diff*diff)); + return (float)module(diff); } /** @@ -110,4 +110,15 @@ public class MathUtils { { return Integer.parseInt(Integer.toString(a),16); } + + /** + * Used to get the always positive value of a double. + * @version From DummyCore 1.2 + * @param a - the double to be converted + * @return this double, but positive(>0) + */ + public static double module(double a) + { + return Math.sqrt(a*a); + } } diff --git a/DummyCore/Utils/MiscUtils.java b/DummyCore/Utils/MiscUtils.java index 7d4cd79..f264c21 100644 --- a/DummyCore/Utils/MiscUtils.java +++ b/DummyCore/Utils/MiscUtils.java @@ -32,7 +32,7 @@ public class MiscUtils { public static void bindTexture(String mod, String texture) { ResourceLocation loc = new ResourceLocation(mod,texture); - Minecraft.getMinecraft().func_110434_K().func_110577_a(loc); + Minecraft.getMinecraft().getTextureManager().bindTexture(loc); loc = null; } @@ -125,7 +125,7 @@ public class MiscUtils { */ public static float getEntityHealth(EntityLivingBase e) { - return e.func_110143_aJ(); + return e.getHealth(); } /** diff --git a/DummyCore/Utils/Notifier.java b/DummyCore/Utils/Notifier.java index cc67cc5..a810b45 100644 --- a/DummyCore/Utils/Notifier.java +++ b/DummyCore/Utils/Notifier.java @@ -5,8 +5,6 @@ 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 { From 1e2fb7a5299996ed2596c38e8135fae35a1ac0ee Mon Sep 17 00:00:00 2001 From: Modbder Date: Fri, 27 Sep 2013 18:17:43 +0400 Subject: [PATCH 7/9] 1.2 fixes and changes MultiBlocks and MultiItems fixes --- DummyCore/Blocks/ItemMultiBlock.java | 21 ++++++-- DummyCore/Blocks/MultiBlock.java | 67 +++++++++++++++++------- DummyCore/Items/MultiItem.java | 40 ++++++++------ DummyCore/Utils/GuiContainerLibrary.java | 53 +++++++++++++++++++ DummyCore/Utils/IDummyMultiBlock.java | 4 +- DummyCore/Utils/MathUtils.java | 2 + DummyCore/Utils/MiscUtils.java | 2 + 7 files changed, 147 insertions(+), 42 deletions(-) create mode 100644 DummyCore/Utils/GuiContainerLibrary.java diff --git a/DummyCore/Blocks/ItemMultiBlock.java b/DummyCore/Blocks/ItemMultiBlock.java index e4f6159..c1b8b8a 100644 --- a/DummyCore/Blocks/ItemMultiBlock.java +++ b/DummyCore/Blocks/ItemMultiBlock.java @@ -24,6 +24,8 @@ public class ItemMultiBlock extends ItemBlock{ public ItemMultiBlock(int par1) { super(par1); + this.setMaxDamage(0); + this.setHasSubtypes(true); } @Override @@ -31,7 +33,7 @@ public class ItemMultiBlock extends ItemBlock{ { for(int i = 0; i < 1024; ++i) { - if(MultiBlock.handler[i] != null) + if(MultiBlock.handler[i] != null && i == par7ItemStack.getItemDamage()) return MultiBlock.handler[i].canPlaceItemBlockOnSide(par1World, par2, par3, par4, par5, par6EntityPlayer, par7ItemStack); } return super.canPlaceItemBlockOnSide(par1World, par2, par3, par4, par5, par6EntityPlayer, par7ItemStack); @@ -94,7 +96,7 @@ public class ItemMultiBlock extends ItemBlock{ { for(int i = 0; i < 1024; ++i) { - if(MultiBlock.handler[i] != null) + if(MultiBlock.handler[i] != null && i == par1ItemStack.getItemDamage()) MultiBlock.handler[i].onItemBlockUpdate(par1ItemStack, par2World, par3Entity, par4, par5); } } @@ -102,10 +104,13 @@ public class ItemMultiBlock extends ItemBlock{ @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); + if(MultiBlock.handler[i] != null && par1ItemStack.getItemDamage() == i) + { + par3List = MultiBlock.handler[i].addInformation(par1ItemStack, par2EntityPlayer, par3List, par4); + } } } @@ -114,10 +119,16 @@ public class ItemMultiBlock extends ItemBlock{ { for(int i = 0; i < 1024; ++i) { - if(MultiBlock.handler[i] != null) + if(MultiBlock.handler[i] != null && par1ItemStack.getItemDamage() == i) return MultiBlock.handler[i].getRarity(par1ItemStack); } return EnumRarity.common; } + @Override + public int getMetadata(int par1) + { + return par1; + } + } diff --git a/DummyCore/Blocks/MultiBlock.java b/DummyCore/Blocks/MultiBlock.java index fc35c35..31a85f2 100644 --- a/DummyCore/Blocks/MultiBlock.java +++ b/DummyCore/Blocks/MultiBlock.java @@ -29,14 +29,15 @@ public class MultiBlock extends Block{ protected static List blockNames = new ArrayList(); protected static List blockNamesUnlocalisedList = new ArrayList(); protected static Hashtable blockNamesUnlocalised = new Hashtable(); + protected static Hashtable mbHandlers = new Hashtable(); protected static List blockTextures = new ArrayList(); protected static int id = -1; public static int blockuid; - protected static Icon[] icon; + public static Icon[] icon; protected static IDummyMultiBlock[] handler = new IDummyMultiBlock[1024]; public static int blocks; public MultiBlock(int par1) { - super(par1, Material.circuits); + super(par1, Material.web); blockuid = par1; } @@ -125,42 +126,50 @@ public class MultiBlock extends Block{ { registerMultiBlock(unlocalisedName,inGameName,texturePath); handler[getMetadataByName(unlocalisedName)] = multiblockHandler; + mbHandlers.put(multiblockHandler, getMetadataByName(unlocalisedName)); } @Override public float getBlockHardness(World par1World, int par2, int par3, int par4) { + int meta = par1World.getBlockMetadata(par2, par3, par4); for(int i = 0; i < 1024; ++i) { - if(handler[i] != null) + if(handler[i] != null && i == meta) + { 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) + public int getLightValue(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) { + int meta = par1IBlockAccess.getBlockMetadata(par2, par3, 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); + if(handler[i] != null && i == meta) + { + return (int)( handler[i].getBlockBrightness(MiscUtils.getBlock(par1IBlockAccess, par2, par3, par4),par1IBlockAccess, par2, par3, par4)*15); + } } - return super.getBlockBrightness(par1IBlockAccess, par2, par3, par4); + return super.getLightValue(par1IBlockAccess, par2, par3, par4); } - @SideOnly(Side.CLIENT) + /*@SideOnly(Side.CLIENT) @Override public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) { + int meta = par1IBlockAccess.getBlockMetadata(par2, par3, par4); for(int i = 0; i < 1024; ++i) { - if(handler[i] != null) + if(handler[i] != null && i == meta) 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 @@ -168,7 +177,7 @@ public class MultiBlock extends Block{ { for(int i = 0; i < 1024; ++i) { - if(handler[i] != null) + if(handler[i] != null && i == par2) return handler[i].getIcon(par1, par2); } return this.icon[par2]; @@ -178,9 +187,10 @@ public class MultiBlock extends Block{ @Override public AxisAlignedBB getSelectedBoundingBoxFromPool(World par1World, int par2, int par3, int par4) { + int meta = par1World.getBlockMetadata(par2, par3, par4); for(int i = 0; i < 1024; ++i) { - if(handler[i] != null) + if(handler[i] != null && i == meta) return handler[i].getSelectedBoundingBoxFromPool(MiscUtils.getBlock(par1World, par2, par3, par4), par1World, par2, par3, par4); } return super.getSelectedBoundingBoxFromPool(par1World, par2, par3, par4); @@ -194,9 +204,10 @@ public class MultiBlock extends Block{ @Override public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4) { + int meta = par1World.getBlockMetadata(par2, par3, par4); for(int i = 0; i < 1024; ++i) { - if(handler[i] != null) + if(handler[i] != null && i == meta) return handler[i].getCollisionBoundingBoxFromPool(MiscUtils.getBlock(par1World, par2, par3, par4), par1World, par2, par3, par4); } return super.getCollisionBoundingBoxFromPool(par1World, par2, par3, par4); @@ -206,9 +217,10 @@ public class MultiBlock extends Block{ @Override public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random) { + int meta = par1World.getBlockMetadata(par2, par3, par4); for(int i = 0; i < 1024; ++i) { - if(handler[i] != null) + if(handler[i] != null && i == meta) handler[i].randomDisplayTick(MiscUtils.getBlock(par1World, par2, par3, par4), par1World, par2, par3, par4, par5Random); } super.randomDisplayTick(par1World, par2, par3, par4, par5Random); @@ -217,9 +229,10 @@ public class MultiBlock extends Block{ @Override public void onBlockDestroyedByPlayer(World par1World, int par2, int par3, int par4, int par5) { + int meta = par1World.getBlockMetadata(par2, par3, par4); for(int i = 0; i < 1024; ++i) { - if(handler[i] != null) + if(handler[i] != null && i == meta) handler[i].onBlockDestroyedByPlayer(MiscUtils.getBlock(par1World, par2, par3, par4), par1World, par2, par3, par4, par5); } super.onBlockDestroyedByPlayer(par1World, par2, par3, par4, par5); @@ -228,9 +241,10 @@ public class MultiBlock extends Block{ @Override public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5) { + int meta = par1World.getBlockMetadata(par2, par3, par4); for(int i = 0; i < 1024; ++i) { - if(handler[i] != null) + if(handler[i] != null && i == meta) handler[i].onNeighborBlockChange(MiscUtils.getBlock(par1World, par2, par3, par4), par1World, par2, par3, par4, par5); } super.onNeighborBlockChange(par1World, par2, par3, par4, par5); @@ -239,9 +253,10 @@ public class MultiBlock extends Block{ @Override public void onBlockAdded(World par1World, int par2, int par3, int par4) { + int meta = par1World.getBlockMetadata(par2, par3, par4); for(int i = 0; i < 1024; ++i) { - if(handler[i] != null) + if(handler[i] != null && i == meta) handler[i].onBlockAdded(MiscUtils.getBlock(par1World, par2, par3, par4), par1World, par2, par3, par4); } super.onBlockAdded(par1World, par2, par3, par4); @@ -250,9 +265,10 @@ public class MultiBlock extends Block{ @Override public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) { + int meta = par1World.getBlockMetadata(par2, par3, par4); for(int i = 0; i < 1024; ++i) { - if(handler[i] != null) + if(handler[i] != null && i == meta) 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); @@ -261,14 +277,27 @@ public class MultiBlock extends Block{ @Override public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) { + int meta = par1IBlockAccess.getBlockMetadata(par2, par3, par4); for(int i = 0; i < 1024; ++i) { - if(handler[i] != null) + if(handler[i] != null && i == meta) handler[i].setBlockBoundsBasedOnState(MiscUtils.getBlock(par1IBlockAccess, par2, par3, par4), par1IBlockAccess, par2, par3, par4); } super.setBlockBoundsBasedOnState(par1IBlockAccess, par2, par3, par4); } + @SideOnly(Side.CLIENT) + @Override + public int getRenderColor(int par1) + { + for(int i = 0; i < 1024; ++i) + { + if(handler[i] != null && i == par1) + return handler[i].getRenderColor(par1); + } + return 16777215; + } + @Override public int damageDropped(int par1) { diff --git a/DummyCore/Items/MultiItem.java b/DummyCore/Items/MultiItem.java index 33743c8..c4a48af 100644 --- a/DummyCore/Items/MultiItem.java +++ b/DummyCore/Items/MultiItem.java @@ -6,6 +6,8 @@ import java.util.List; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import DummyCore.Core.CoreInitialiser; +import DummyCore.Utils.IDummyMultiBlock; import DummyCore.Utils.IDummyMultiItem; import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.IconRegister; @@ -29,6 +31,7 @@ public class MultiItem extends Item{ private static List itemNames = new ArrayList(); private static List itemNamesUnlocalisedList = new ArrayList(); private static Hashtable itemNamesUnlocalised = new Hashtable(); + protected static Hashtable miHandlers = new Hashtable(); private static List itemTextures = new ArrayList(); private static int id = -1; public static int itemuid; @@ -99,7 +102,7 @@ public class MultiItem extends Item{ */ public static ItemStack getStackByName(String unlocalisedName, int size) { - ItemStack s = new ItemStack(itemuid,getMetadataByName(unlocalisedName),size); + ItemStack s = new ItemStack(CoreInitialiser.mItem,getMetadataByName(unlocalisedName),size); return s; } @@ -140,18 +143,19 @@ public class MultiItem extends Item{ { registerMultiItem(unlocalisedName,inGameName,texturePath); handler[getMetadataByName(unlocalisedName)] = multiItemHandler; + miHandlers.put(multiItemHandler, getMetadataByName(unlocalisedName)); } @Override public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) { + int meta = par1ItemStack.getItemDamage(); for(int i = 0; i < 1024; ++i) { - if(handler[i] != null) + if(handler[i] != null && i == meta) { boolean result = handler[i].onItemUse(par1ItemStack, par2EntityPlayer, par3World, par4, par5, par6, par7, par8, par9, par10); - if(result = true) - return result; + return result; } } return false; @@ -160,12 +164,12 @@ public class MultiItem extends Item{ @Override public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { + int meta = par1ItemStack.getItemDamage(); for(int i = 0; i < 1024; ++i) { - if(handler[i] != null) + if(handler[i] != null && i == meta) { ItemStack result = handler[i].onItemRightClick(par1ItemStack, par2World, par3EntityPlayer); - if(result != null) return result; } } @@ -175,12 +179,12 @@ public class MultiItem extends Item{ @Override public boolean hitEntity(ItemStack par1ItemStack, EntityLivingBase par2EntityLivingBase, EntityLivingBase par3EntityLivingBase) { + int meta = par1ItemStack.getItemDamage(); for(int i = 0; i < 1024; ++i) { - if(handler[i] != null) + if(handler[i] != null && i == meta) { boolean result = handler[i].hitEntity(par1ItemStack, par2EntityLivingBase, par3EntityLivingBase); - if(result != false) return result; } } @@ -190,12 +194,12 @@ public class MultiItem extends Item{ @Override public boolean onBlockDestroyed(ItemStack par1ItemStack, World par2World, int par3, int par4, int par5, int par6, EntityLivingBase par7EntityLivingBase) { + int meta = par1ItemStack.getItemDamage(); for(int i = 0; i < 1024; ++i) { - if(handler[i] != null) + if(handler[i] != null && i == meta) { boolean result = handler[i].onBlockDestroyed(par1ItemStack, par2World, par3, par4, par5, par6, par7EntityLivingBase); - if(result != false) return result; } } @@ -206,8 +210,9 @@ public class MultiItem extends Item{ public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5) { { - for(int i = 0; i < 1024; ++i) - if(handler[i] != null) + int meta = par1ItemStack.getItemDamage(); + for(int i = 0; i < 1024; ++i) + if(handler[i] != null && i == meta) handler[i].onUpdate(par1ItemStack, par2World, par3Entity, par4, par5); } } @@ -216,12 +221,12 @@ public class MultiItem extends Item{ @SideOnly(Side.CLIENT) public int getColorFromItemStack(ItemStack par1ItemStack, int par2) { + int meta = par1ItemStack.getItemDamage(); for(int i = 0; i < 1024; ++i) { - if(handler[i] != null) + if(handler[i] != null && i == meta) { int result = handler[i].getColorFromItemStack(par1ItemStack, par2); - if(result != -1) return result; } } @@ -231,9 +236,10 @@ public class MultiItem extends Item{ @Override public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) { + int meta = par1ItemStack.getItemDamage(); for(int i = 0; i < 1024; ++i) { - if(handler[i] != null) + if(handler[i] != null && i == meta) handler[i].addInformation(par1ItemStack, par2EntityPlayer, par3List, par4); } } @@ -241,12 +247,12 @@ public class MultiItem extends Item{ @Override public EnumRarity getRarity(ItemStack par1ItemStack) { + int meta = par1ItemStack.getItemDamage(); for(int i = 0; i < 1024; ++i) { - if(handler[i] != null) + if(handler[i] != null && i == meta) { EnumRarity result = handler[i].getRarity(par1ItemStack); - if(result != EnumRarity.common) return result; } } diff --git a/DummyCore/Utils/GuiContainerLibrary.java b/DummyCore/Utils/GuiContainerLibrary.java new file mode 100644 index 0000000..e6bce92 --- /dev/null +++ b/DummyCore/Utils/GuiContainerLibrary.java @@ -0,0 +1,53 @@ +package DummyCore.Utils; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.client.gui.Gui; +import net.minecraft.inventory.Container; + +public class GuiContainerLibrary { + private static List gui = new ArrayList(); + private static List container = new ArrayList(); + private static List regInt = new ArrayList(); + + public static void registerGuiContainer(int id, Container c, Gui g) + { + regInt.add(id); + container.add(c); + gui.add(g); + } + + public static Container getContainerByID(int id) + { + int i = getListArg(id); + if(i > 0) + { + return container.get(i); + } + return null; + } + + public static Gui getGuiByID(int id) + { + int i = getListArg(id); + if(i > 0) + { + return gui.get(i); + } + return null; + } + + private static int getListArg(int id) + { + if(regInt.contains(id)) + { + for(int i = 0; i < regInt.size(); ++i) + { + if(regInt.get(i) == id) + return regInt.get(i); + } + } + return -1; + } +} diff --git a/DummyCore/Utils/IDummyMultiBlock.java b/DummyCore/Utils/IDummyMultiBlock.java index 1bd32dc..dce967a 100644 --- a/DummyCore/Utils/IDummyMultiBlock.java +++ b/DummyCore/Utils/IDummyMultiBlock.java @@ -27,7 +27,7 @@ public interface IDummyMultiBlock { 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 List addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4); public EnumRarity getRarity(ItemStack par1ItemStack); @@ -56,4 +56,6 @@ public interface IDummyMultiBlock { public void setBlockBoundsBasedOnState(Block b, IBlockAccess par1IBlockAccess, int par2, int par3, int par4); public Icon getIcon(int par1, int par2); + + public int getRenderColor(int par1); } diff --git a/DummyCore/Utils/MathUtils.java b/DummyCore/Utils/MathUtils.java index 490a976..274c605 100644 --- a/DummyCore/Utils/MathUtils.java +++ b/DummyCore/Utils/MathUtils.java @@ -20,6 +20,8 @@ public class MathUtils { */ public static int pixelatedTextureSize(int current, int max, int textureSize) { + if(current > max) + current = max; float m = (float)current/max*100; float n = m/100*textureSize; return (int)n; diff --git a/DummyCore/Utils/MiscUtils.java b/DummyCore/Utils/MiscUtils.java index f264c21..0694305 100644 --- a/DummyCore/Utils/MiscUtils.java +++ b/DummyCore/Utils/MiscUtils.java @@ -10,6 +10,8 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.chunk.storage.ExtendedBlockStorage; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; From a26de45a7760752d0737aead1772f86860566411 Mon Sep 17 00:00:00 2001 From: Modbder Date: Thu, 10 Oct 2013 21:46:48 +0400 Subject: [PATCH 8/9] 1.4 network update easy syncing your tile entities with the server/client. Also, DummyData can now be written to the .ddat files in the save directory. Finally, full functionality! --- DummyCore/Core/CoreInitialiser.java | 23 ++- DummyCore/Utils/DummyDataUtils.java | 219 ++++++++++++++++++++++++ DummyCore/Utils/DummyMenuAPI.java | 82 +++++++++ DummyCore/Utils/DummyPacketHandler.java | 66 +++++++ DummyCore/Utils/EnumGuiPosition.java | 18 ++ DummyCore/Utils/IMainMenu.java | 27 +++ DummyCore/Utils/ITEHasGameData.java | 11 ++ DummyCore/Utils/MathUtils.java | 46 +++++ DummyCore/Utils/MiscUtils.java | 97 +++++++++++ 9 files changed, 588 insertions(+), 1 deletion(-) create mode 100644 DummyCore/Utils/DummyDataUtils.java create mode 100644 DummyCore/Utils/DummyMenuAPI.java create mode 100644 DummyCore/Utils/DummyPacketHandler.java create mode 100644 DummyCore/Utils/EnumGuiPosition.java create mode 100644 DummyCore/Utils/IMainMenu.java create mode 100644 DummyCore/Utils/ITEHasGameData.java diff --git a/DummyCore/Core/CoreInitialiser.java b/DummyCore/Core/CoreInitialiser.java index 1c2bda1..7d5c426 100644 --- a/DummyCore/Core/CoreInitialiser.java +++ b/DummyCore/Core/CoreInitialiser.java @@ -1,5 +1,6 @@ package DummyCore.Core; +import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -26,6 +27,8 @@ import DummyCore.Items.ItemRegistry; import DummyCore.Items.MultiItem; import DummyCore.Utils.ColoredLightHandler; import DummyCore.Utils.DummyConfig; +import DummyCore.Utils.DummyDataUtils; +import DummyCore.Utils.DummyPacketHandler; import DummyCore.Utils.EnumLightColor; import DummyCore.Utils.MathUtils; import DummyCore.Utils.Notifier; @@ -40,7 +43,10 @@ import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLInterModComms.IMCEvent; +import cpw.mods.fml.common.event.FMLServerStartingEvent; +import cpw.mods.fml.common.event.FMLServerStoppingEvent; import cpw.mods.fml.common.network.NetworkMod; +import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.registry.EntityRegistry; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.TickRegistry; @@ -52,7 +58,7 @@ import cpw.mods.fml.relauncher.Side; * @version From DummyCore 1.0 */ @Mod(modid = "DummyCore", name = "DummyCore", version = "1.1dev", useMetadata = true) -@NetworkMod(clientSideRequired = true, serverSideRequired = false, channels = "DummyCore") +@NetworkMod(clientSideRequired = true, serverSideRequired = false, channels = {"DC.Packet.S","DC.Packet.C"}) public class CoreInitialiser extends DummyModContainer{ public static final CoreInitialiser instance = new CoreInitialiser(); private static DummyConfig cfg = new DummyConfig(); @@ -97,6 +103,9 @@ public class CoreInitialiser extends DummyModContainer{ { RenderingRegistry.registerEntityRenderingHandler(ColoredLightHandler.class, new RendererColoredLight()); } + DummyPacketHandler handler = new DummyPacketHandler(); + NetworkRegistry.instance().registerChannel(handler, "DC.Packet.S"); + NetworkRegistry.instance().registerChannel(handler, "DC.Packet.C"); } @EventHandler @@ -105,6 +114,18 @@ public class CoreInitialiser extends DummyModContainer{ Notifier.notifySimple(MultiItem.items+" MultiItems registered."); Notifier.notifySimple(MultiBlock.blocks+" MultiBlocks registered."); } + + @EventHandler + public void onServerStart(FMLServerStartingEvent e) + { + DummyDataUtils.load(e); + } + + @EventHandler + public void onServerStop(FMLServerStoppingEvent e) + { + DummyDataUtils.stop(); + } public static MultiItem mItem; public static MultiBlock mBlock; diff --git a/DummyCore/Utils/DummyDataUtils.java b/DummyCore/Utils/DummyDataUtils.java new file mode 100644 index 0000000..b9e4c74 --- /dev/null +++ b/DummyCore/Utils/DummyDataUtils.java @@ -0,0 +1,219 @@ +package DummyCore.Utils; + +import java.io.File; +import java.io.IOException; +import java.util.Hashtable; + +import javax.naming.spi.DirectoryManager; + +import net.minecraftforge.common.Configuration; + +import org.apache.commons.io.DirectoryWalker; +import org.apache.commons.io.filefilter.DirectoryFileFilter; +import org.bouncycastle.asn1.x500.DirectoryString; + +import cpw.mods.fml.common.discovery.DirectoryDiscoverer; +import cpw.mods.fml.common.event.FMLServerStartingEvent; + +/** + * + * @author Modbder + * @version From DummyCore 1.4 + * @Description used to store any String for players/worlds in the world save folder and get it. + */ +public class DummyDataUtils { + private static File mainWorldFile; + private static Configuration globalConfig; + private static Hashtable playerFiles = new Hashtable(); + private static Hashtable playerConfigs = new Hashtable(); + private static String getPath; + private static boolean isWorking; + + public static void load(FMLServerStartingEvent event) + { + String name = event.getServer().getFile(event.getServer().getFolderName()).getAbsolutePath(); + System.out.println(name); + int length = 0; + for(int i = 0; i < name.length(); ++i) + { + if(name.substring(0, i).contains("\\.\\")) + { + --length; + --length; + break; + } + ++length; + } + String print = name.substring(0,length); + print += "saves\\"; + print += event.getServer().getFolderName(); + print += "\\DummyData\\"; + File f = new File(print); + f.mkdirs(); + File file = new File(print+"GlobalData.ddat"); + try { + if(!file.exists()) + file.createNewFile(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return; + } + File f1 = new File(print+"/PlayerData/"); + f1.mkdirs(); + getPath = print; + mainWorldFile = file; + globalConfig = new Configuration(file); + isWorking = true; + } + + public static void stop() + { + mainWorldFile = null; + globalConfig = null; + playerFiles.clear(); + playerConfigs.clear(); + getPath = "no path"; + isWorking = false; + } + + private static File getDataFileForPlayer(String playerName) + { + if(!playerFiles.containsKey(playerName)) + { + File ret = new File(getPath+"/PlayerData/"+playerName+".ddat"); + if(!ret.exists()) + try { + ret.createNewFile(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return null; + } + playerFiles.put(playerName, ret); + return ret; + }else + { + return playerFiles.get(playerName); + } + + } + + private static Configuration getDataConfigForPlayer(String playerName) + { + if(!canWorkWithData())return null; + if(!playerConfigs.containsKey(playerName)) + { + playerConfigs.put(playerName, new Configuration(getDataFileForPlayer(playerName))); + } + return playerConfigs.get(playerName); + } + + /** + * Writes the given String to the GlobalData.ddat file with the key of dataName + * @version From DummyCore 1.4 + * @param modid - the id of your mod + * @param dataName - key of the data + * @param dataString - data to store + */ + public static void writeCustomDataForMod(String modid, String dataName, String dataString) + { + if(!canWorkWithData())return; + globalConfig.load(); + globalConfig.get(modid, dataName, dataString).set(dataString); + globalConfig.save(); + } + + + /** + * Writes the given String to the GlobalData.ddat file with the key of modid + * @version From DummyCore 1.4 + * @param modid - the id of your mod + * @param dataString - data to store + */ + public static void writeGlobalDataForMod(String modid, String dataString) + { + if(!canWorkWithData())return; + globalConfig.load(); + globalConfig.get(modid, modid, dataString).set(dataString); + globalConfig.save(); + } + + + /** + * Returns the String from the GlobalData.ddat file with the key of modid + * @version From DummyCore 1.4 + * @param modid - the id of your mod + * @return a string with the data, written to the ddat file. Returns "no data" if none was found + */ + public static String getGlobalDataForMod(String modid) + { + if(!canWorkWithData())return null; + globalConfig.load(); + String ret = globalConfig.get(modid, modid, "no data").getString(); + globalConfig.save(); + return ret; + } + + /** + * Returns the String from the GlobalData.ddat file with the custom key + * @version From DummyCore 1.4 + * @param modid - the id of your mod + * @param dataName - key of the data + * @return a string with the data, written to the ddat file. Returns "no data" if none was found + */ + public static String getCustomDataForMod(String modid, String dataName) + { + if(!canWorkWithData())return null; + globalConfig.load(); + String ret = globalConfig.get(modid, dataName, "no data").getString(); + globalConfig.save(); + return ret; + } + + /** + * Sets the given data to the ddat file of the player with given name. + * @version From DummyCore 1.4 + * @param playerName - name of the player + * @param modid - id of the mod + * @param dataName - key of the data + * @param dataValue - the data to store + */ + public static void setDataForPlayer(String playerName, String modid, String dataName, String dataValue) + { + if(!canWorkWithData())return; + Configuration config = getDataConfigForPlayer(playerName); + config.load(); + config.get(modid, dataName, dataValue).set(dataValue); + config.save(); + } + + /** + * Returns the String from the ddat file of the given player with the custom key + * @version From DummyCore 1.4 + * @param playerName - name of the player + * @param modid - id of the mod + * @param dataName - key of the data + * @return a string with the data, written to the ddat file. Returns "no data" if none was found + */ + public static String getDataForPlayer(String playerName, String modid, String dataName) + { + if(!canWorkWithData())return null; + Configuration config = getDataConfigForPlayer(playerName); + config.load(); + String ret = config.get(modid, dataName, "no data").getString(); + config.save(); + return ret; + } + + /** + * Used to check, if current world exists(for example, if the player is in the main menu returns false) + * @version From DummyCore 1.4 + * @return True, if there is a running world, false if not. + */ + public static boolean canWorkWithData() + { + return isWorking; + } + +} diff --git a/DummyCore/Utils/DummyMenuAPI.java b/DummyCore/Utils/DummyMenuAPI.java new file mode 100644 index 0000000..f8ffb2e --- /dev/null +++ b/DummyCore/Utils/DummyMenuAPI.java @@ -0,0 +1,82 @@ +package DummyCore.Utils; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiButtonLanguage; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.resources.I18n; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.storage.ISaveFormat; +import net.minecraft.world.storage.WorldInfo; + +public class DummyMenuAPI { + int height, width, ticks, scheduledTick, imageIndex; + Minecraft mc; + public static final List STANDART_MC_BUTTONS = new ArrayList(); + public static final ResourceLocation STANDART_MC_LETTERS = new ResourceLocation("textures/gui/title/minecraft.png"); + + public DummyMenuAPI(int height, int width) + { + this.width = width; + this.height = height; + mc = Minecraft.getMinecraft(); + initialiseButtonList(); + } + + public void renderStandartMenu(IMainMenu menu) + { + ResourceLocation[] loc = menu.getLetters(); + + } + + private void initialiseButtonList() + { + int i = height / 4 + 48; + STANDART_MC_BUTTONS.clear(); + STANDART_MC_BUTTONS.add(new GuiButton(0, width / 2 - 100, i + 72 + 12, 98, 20, I18n.getString("menu.options"))); + if (this.mc.isDemo()) + { + this.addDemoButtons(i, 24); + } + else + { + this.addSingleplayerMultiplayerButtons(i, 24); + } + STANDART_MC_BUTTONS.add(new GuiButton(0, this.width / 2 - 100, i + 72 + 12, 98, 20, I18n.getString("menu.options"))); + STANDART_MC_BUTTONS.add(new GuiButton(4, this.width / 2 + 2, i + 72 + 12, 98, 20, I18n.getString("menu.quit"))); + STANDART_MC_BUTTONS.add(new GuiButtonLanguage(5, this.width / 2 - 124, i + 72 + 12)); + } + + private void addDemoButtons(int par1, int par2) + { + GuiButton buttonResetDemo; + STANDART_MC_BUTTONS.add(new GuiButton(11, this.width / 2 - 100, par1, I18n.getString("menu.playdemo"))); + STANDART_MC_BUTTONS.add(buttonResetDemo = new GuiButton(12, this.width / 2 - 100, par1 + par2 * 1, I18n.getString("menu.resetdemo"))); + ISaveFormat isaveformat = this.mc.getSaveLoader(); + WorldInfo worldinfo = isaveformat.getWorldInfo("Demo_World"); + + if (worldinfo == null) + { + buttonResetDemo.enabled = false; + } + } + + private void addSingleplayerMultiplayerButtons(int par1, int par2) + { + GuiButton fmlModButton; + GuiButton minecraftRealmsButton; + STANDART_MC_BUTTONS.add(new GuiButton(1, this.width / 2 - 100, par1, I18n.getString("menu.singleplayer"))); + STANDART_MC_BUTTONS.add(new GuiButton(2, this.width / 2 - 100, par1 + par2 * 1, I18n.getString("menu.multiplayer"))); + //If Minecraft Realms is enabled, halve the size of both buttons and set them next to eachother. + fmlModButton = new GuiButton(6, this.width / 2 - 100, par1 + par2 * 2, "Mods"); + STANDART_MC_BUTTONS.add(fmlModButton); + minecraftRealmsButton = new GuiButton(14, this.width / 2 - 100, par1 + par2 * 2, I18n.getString("menu.online")); + minecraftRealmsButton.xPosition = this.width / 2 - 100; + STANDART_MC_BUTTONS.add(minecraftRealmsButton); + minecraftRealmsButton.drawButton = false; + } + +} diff --git a/DummyCore/Utils/DummyPacketHandler.java b/DummyCore/Utils/DummyPacketHandler.java new file mode 100644 index 0000000..ef3bfc5 --- /dev/null +++ b/DummyCore/Utils/DummyPacketHandler.java @@ -0,0 +1,66 @@ +package DummyCore.Utils; + +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; + +import net.minecraft.network.INetworkManager; +import net.minecraft.network.packet.Packet250CustomPayload; +import net.minecraft.tileentity.TileEntity; +import cpw.mods.fml.client.FMLClientHandler; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.network.IPacketHandler; +import cpw.mods.fml.common.network.Player; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.server.FMLServerHandler; + +public class DummyPacketHandler implements IPacketHandler{ + + @Override + public void onPacketData(INetworkManager manager, + Packet250CustomPayload packet, Player player) { + int x = 0; + int y = 0; + int z = 0; + String gameData = "data"; + try { + Side s = FMLCommonHandler.instance().getEffectiveSide(); + if(s == Side.CLIENT) + { + ByteArrayInputStream b = new ByteArrayInputStream(packet.data, 0, packet.length); + DataInputStream dis = new DataInputStream(b); + if(packet.channel.contains("DC.Packet.C")) + { + x = dis.readInt(); + y = dis.readInt(); + z = dis.readInt(); + gameData = dis.readUTF(); + TileEntity t = FMLClientHandler.instance().getClient().theWorld.getBlockTileEntity(x, y, z); + if(t instanceof ITEHasGameData && gameData != "data") + { + ((ITEHasGameData)t).setData(DataStorage.parseData(gameData)); + } + } + }else + { + ByteArrayInputStream b = new ByteArrayInputStream(packet.data, 0, packet.length); + DataInputStream dis = new DataInputStream(b); + if(packet.channel.contains("DC.Packet.S")) + { + x = dis.readInt(); + y = dis.readInt(); + z = dis.readInt(); + gameData = dis.readUTF(); + TileEntity t = FMLServerHandler.instance().getServer().getEntityWorld().getBlockTileEntity(x, y, z); + if(t instanceof ITEHasGameData && gameData != "data") + { + ((ITEHasGameData)t).setData(DataStorage.parseData(gameData)); + } + } + } + } catch (Exception e) { + e.printStackTrace(); + return; + } + } + +} diff --git a/DummyCore/Utils/EnumGuiPosition.java b/DummyCore/Utils/EnumGuiPosition.java new file mode 100644 index 0000000..6e1e8d2 --- /dev/null +++ b/DummyCore/Utils/EnumGuiPosition.java @@ -0,0 +1,18 @@ +package DummyCore.Utils; + +public enum EnumGuiPosition { + TOPLEFT, + TOPRIGHT, + BOTLEFT, + BOTRIGHT, + CENTER; + + public int x; + public int y; + EnumGuiPosition() + { + } + + + +} diff --git a/DummyCore/Utils/IMainMenu.java b/DummyCore/Utils/IMainMenu.java new file mode 100644 index 0000000..0ff65bf --- /dev/null +++ b/DummyCore/Utils/IMainMenu.java @@ -0,0 +1,27 @@ +package DummyCore.Utils; + +import java.util.List; + +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.util.ResourceLocation; + +public interface IMainMenu { + + public abstract ResourceLocation[] getBackgroundImages(); + + public abstract boolean shouldRenderFullScreen(int imageIndex); + + public abstract List getButtonList(); + + public abstract void render(); + + public abstract List getTextFor(EnumGuiPosition e); + + public abstract ResourceLocation[] getLetters(); + + public abstract boolean renderUnstandartLetters(); + + public abstract FontRenderer textRenderer(); + +} diff --git a/DummyCore/Utils/ITEHasGameData.java b/DummyCore/Utils/ITEHasGameData.java new file mode 100644 index 0000000..c8b593b --- /dev/null +++ b/DummyCore/Utils/ITEHasGameData.java @@ -0,0 +1,11 @@ +package DummyCore.Utils; + +public interface ITEHasGameData { + + public abstract String getData(); + + public abstract void setData(DummyData[] data); + + public abstract Coord3D getPosition(); + +} diff --git a/DummyCore/Utils/MathUtils.java b/DummyCore/Utils/MathUtils.java index 274c605..1f55fce 100644 --- a/DummyCore/Utils/MathUtils.java +++ b/DummyCore/Utils/MathUtils.java @@ -123,4 +123,50 @@ public class MathUtils { { return Math.sqrt(a*a); } + + public static boolean arrayContains(Object[] array, Object searched) + { + for(int i = 0; i < array.length; ++i) + { + if(array[i].equals(searched)) + return true; + } + return false; + } + + public static boolean arrayContains(int[] array, int searched) + { + for(int i = 0; i < array.length; ++i) + { + if(array[i] == searched) + return true; + } + return false; + } + + public static int getIntInArray(int[] array, int searched) + { + for(int i = 0; i < array.length; ++i) + { + if(array[i] == searched) + return i; + } + return -1; + } + + public static boolean isArrayTheSame(boolean[] array) + { + boolean previous = array[0]; + for(int i = 0; i < array.length; ++i) + { + if(array[i] == previous) + { + previous = array[i]; + }else + { + return false; + } + } + return true; + } } diff --git a/DummyCore/Utils/MiscUtils.java b/DummyCore/Utils/MiscUtils.java index 0694305..1ee1b26 100644 --- a/DummyCore/Utils/MiscUtils.java +++ b/DummyCore/Utils/MiscUtils.java @@ -1,5 +1,8 @@ package DummyCore.Utils; +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; + import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.entity.EntityLivingBase; @@ -7,11 +10,14 @@ import net.minecraft.entity.item.EntityItem; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.packet.Packet250CustomPayload; import net.minecraft.util.ResourceLocation; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.storage.ExtendedBlockStorage; +import net.minecraftforge.oredict.OreDictionary; +import cpw.mods.fml.common.network.PacketDispatcher; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -146,4 +152,95 @@ public class MiscUtils { return ret; } + + /** + * Adds the given ItemStack to the given inventory, also updating the inventory. + * @version From DummyCore 1.4 + * @param s - the stack to add + * @param i - the inventory for the stack + * @param remote - use world.isRemote here. This function is usually called on both sides, however, you can call it on server only, it will be ok, then put false in this field + * @return true if adding was successful, false if not. + */ + public static boolean addItemToInventory(ItemStack s, IInventory i, boolean remote) + { + + for(int p = 0; p < i.getSizeInventory();++p) + { + if(i.getStackInSlot(p) != null && i.getStackInSlot(p).itemID == s.itemID && i.getStackInSlot(p).getItemDamage() == s.getItemDamage() && i.getStackInSlot(p).stackSize+s.stackSize<=64) + { + ItemStack slot = i.getStackInSlot(p); + System.out.println(slot); + if(!remote) + { + i.setInventorySlotContents(p, new ItemStack(slot.itemID,slot.stackSize+s.stackSize,slot.getItemDamage())); + } + i.onInventoryChanged(); + return true; + } + } + for(int p = 0; p < i.getSizeInventory();++p) + { + if(i.getStackInSlot(p) == null && !remote) + { + i.setInventorySlotContents(p, s); + i.onInventoryChanged(); + return true; + } + } + return false; + } + + /** + * Used to check, if the Forge Ore Dictionary contains the given name in it. + * @version From DummyCore 1.4 + * @param oreName - the ore name to search + * @return true if OreDictionary cantains the given ore, false if not. + */ + public static boolean oreDictionaryContains(String oreName) + { + String[] names = OreDictionary.getOreNames(); + boolean ret = false; + for(int i = 0; i < names.length; ++i) + { + if(names[i].contains(oreName) || names[i] == oreName) + { + ret = true; + } + } + return ret; + } + + /** + * Used to sync the given tile entity with the given side using DummyCore packet handler. + * @version From DummyCore 1.4 + * @param t - the tileentity to sync. + * @param s - the side, that will accept the packet. + */ + public static void syncTileEntity(ITEHasGameData t, Side s) + { + String packetname = "DC.Packet."; + if(s == Side.CLIENT)packetname += "C"; + if(s == Side.SERVER)packetname += "S"; + Packet250CustomPayload m = new Packet250CustomPayload(); + ByteArrayOutputStream bos = new ByteArrayOutputStream(255); + DataOutputStream outputStream = new DataOutputStream(bos); + try + { + outputStream.writeInt((int) t.getPosition().x); + outputStream.writeInt((int) t.getPosition().y); + outputStream.writeInt((int) t.getPosition().z); + outputStream.writeUTF(t.getData()); + }catch (Exception ex) + { + ex.printStackTrace(); + return; + } + m.channel = packetname; + m.data = bos.toByteArray(); + m.length = bos.size(); + if(s == Side.SERVER) + PacketDispatcher.sendPacketToServer(m);; + if(s == Side.CLIENT) + PacketDispatcher.sendPacketToAllPlayers(m); + } } From 248e9e1398e4ae87c963412ed052e65627dc6c33 Mon Sep 17 00:00:00 2001 From: Modbder Date: Thu, 23 Jan 2014 15:16:27 +0400 Subject: [PATCH 9/9] 1.5 Misc updates --- DummyCore/Blocks/MultiBlock.java | 49 ++++++++++++++++++++++--- DummyCore/Utils/Coord2D.java | 5 ++- DummyCore/Utils/DummyPacketHandler.java | 1 + DummyCore/Utils/EnumRarityColor.java | 39 ++++++++++++++++++++ DummyCore/Utils/IDummyMultiBlock.java | 5 +++ 5 files changed, 92 insertions(+), 7 deletions(-) create mode 100644 DummyCore/Utils/EnumRarityColor.java diff --git a/DummyCore/Blocks/MultiBlock.java b/DummyCore/Blocks/MultiBlock.java index 31a85f2..d2c8f9c 100644 --- a/DummyCore/Blocks/MultiBlock.java +++ b/DummyCore/Blocks/MultiBlock.java @@ -33,14 +33,20 @@ public class MultiBlock extends Block{ protected static List blockTextures = new ArrayList(); protected static int id = -1; public static int blockuid; - public static Icon[] icon; + public static Icon[] icon = new Icon[4096]; protected static IDummyMultiBlock[] handler = new IDummyMultiBlock[1024]; public static int blocks; public MultiBlock(int par1) { super(par1, Material.web); blockuid = par1; + this.setTickRandomly(true); } + public int tickRate(World par1World) + { + return 50; + } + private static void addBlockName(int i, String name) { blockNames.add(i, name); @@ -175,12 +181,18 @@ public class MultiBlock extends Block{ @Override public Icon getIcon(int par1, int par2) { - for(int i = 0; i < 1024; ++i) - { - if(handler[i] != null && i == par2) - return handler[i].getIcon(par1, par2); + try { + for(int i = 0; i < 1024; ++i) + { + if(handler[i] != null && i == par2) + return handler[i].getIcon(par1, par2); + } + return this.icon[par2]; + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return null; } - return this.icon[par2]; } @SideOnly(Side.CLIENT) @@ -298,6 +310,31 @@ public class MultiBlock extends Block{ return 16777215; } + @Override + public ArrayList getBlockDropped(World world, int x, int y, int z, int metadata, int fortune) + { + for(int i = 0; i < 1024; ++i) + { + if(handler[i] != null && i == metadata) + { + ArrayList ret = handler[i].getBlockDropped(world, x, y, z, metadata, fortune); + if(ret != null) + return ret; + } + } + return super.getBlockDropped(world, x, y, z, metadata, fortune); + } + + @Override + public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random) + { + for(int i = 0; i < 1024; ++i) + { + if(handler[i] != null && i == par4) + handler[i].updateTick(par1World, par2, par3, par4, par5Random); + } + } + @Override public int damageDropped(int par1) { diff --git a/DummyCore/Utils/Coord2D.java b/DummyCore/Utils/Coord2D.java index bfe6905..8c16405 100644 --- a/DummyCore/Utils/Coord2D.java +++ b/DummyCore/Utils/Coord2D.java @@ -22,6 +22,9 @@ public class Coord2D { this(0,0); } - + public String toString() + { + return x+","+z; + } } diff --git a/DummyCore/Utils/DummyPacketHandler.java b/DummyCore/Utils/DummyPacketHandler.java index ef3bfc5..aa67ce5 100644 --- a/DummyCore/Utils/DummyPacketHandler.java +++ b/DummyCore/Utils/DummyPacketHandler.java @@ -22,6 +22,7 @@ public class DummyPacketHandler implements IPacketHandler{ int y = 0; int z = 0; String gameData = "data"; + System.out.println("data"); try { Side s = FMLCommonHandler.instance().getEffectiveSide(); if(s == Side.CLIENT) diff --git a/DummyCore/Utils/EnumRarityColor.java b/DummyCore/Utils/EnumRarityColor.java new file mode 100644 index 0000000..8cb4388 --- /dev/null +++ b/DummyCore/Utils/EnumRarityColor.java @@ -0,0 +1,39 @@ +package DummyCore.Utils; + +public enum EnumRarityColor { + BROKEN("8","Broken"), + COMMON("f","Common"), + GOOD("a","Good"), + UNCOMMON("2","Uncommon"), + RARE("9","Rare"), + UNIQUE("d","Unique"), + EPIC("e","Epic"), + LEGENDARY("6","Legendary"), + EXCEPTIONAL("b","Exceptional"), + PERFECT("3","Perfect"), + ULTIMATE("c","Ultimate"), + TURQUOISE("4","Turquoise"), + ; + EnumRarityColor(String s, String s1) + { + value = s; + name = s1; + } + + private String value; + private String name; + + public String getRarityColor() + { + String ret = new String(); + ret += "\247"; + ret+=value; + return ret; + } + + public String getName() + { + return name; + } + +} diff --git a/DummyCore/Utils/IDummyMultiBlock.java b/DummyCore/Utils/IDummyMultiBlock.java index dce967a..4fdb253 100644 --- a/DummyCore/Utils/IDummyMultiBlock.java +++ b/DummyCore/Utils/IDummyMultiBlock.java @@ -1,5 +1,6 @@ package DummyCore.Utils; +import java.util.ArrayList; import java.util.List; import java.util.Random; @@ -58,4 +59,8 @@ public interface IDummyMultiBlock { public Icon getIcon(int par1, int par2); public int getRenderColor(int par1); + + public ArrayList getBlockDropped(World world, int x, int y, int z, int metadata, int fortune); + + public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random); }