Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package waDelma.tinyblocks;
- import java.io.File;
- import java.lang.reflect.Constructor;
- import java.lang.reflect.Field;
- import java.util.ArrayList;
- import java.util.List;
- import net.minecraft.client.Minecraft;
- import net.minecraft.server.MinecraftServer;
- import net.minecraft.item.EnumToolMaterial;
- import net.minecraft.client.settings.KeyBinding;
- import net.minecraftforge.common.Configuration;
- import net.minecraftforge.common.EnumHelper;
- import net.minecraftforge.common.MinecraftForge;
- import waDelma.tinyblocks.UI.PacketHandlerTinyblock;
- import waDelma.tinyblocks.UI.TinyblockKeyHandler;
- import waDelma.tinyblocks.UI.TinyblockTicker;
- import waDelma.tinyblocks.UI.UIHandler;
- import waDelma.tinyblocks.block.BlockTinyblock;
- import waDelma.tinyblocks.block.ItemTinyBlock;
- import waDelma.tinyblocks.block.TileEntityTinyblock;
- import waDelma.tinyblocks.handlers.CraftingHandler;
- import waDelma.tinyblocks.items.ItemGlue;
- import waDelma.tinyblocks.items.ItemOpticTransformer;
- import waDelma.tinyblocks.items.ItemSaw;
- import waDelma.tinyblocks.items.ItemStoneStick;
- import cpw.mods.fml.client.FMLClientHandler;
- import cpw.mods.fml.client.registry.KeyBindingRegistry;
- import cpw.mods.fml.client.registry.RenderingRegistry;
- import cpw.mods.fml.common.Mod;
- import cpw.mods.fml.common.Mod.Block;
- import cpw.mods.fml.common.Mod.Init;
- import cpw.mods.fml.common.Mod.Instance;
- import cpw.mods.fml.common.Mod.Item;
- import cpw.mods.fml.common.Mod.Metadata;
- import cpw.mods.fml.common.Mod.PreInit;
- import cpw.mods.fml.common.ModMetadata;
- import cpw.mods.fml.relauncher.Side;
- import cpw.mods.fml.relauncher.SideOnly;
- import cpw.mods.fml.common.event.FMLInitializationEvent;
- import cpw.mods.fml.common.event.FMLPreInitializationEvent;
- import cpw.mods.fml.common.network.NetworkMod;
- import cpw.mods.fml.common.network.NetworkRegistry;
- import cpw.mods.fml.common.registry.GameRegistry;
- import cpw.mods.fml.common.registry.TickRegistry;
- import cpw.mods.fml.server.FMLServerHandler;
- @Mod(modid = "Tinyblock", name = "Tinyblock", version = "1.4.5 V1")
- @NetworkMod(clientSideRequired = true, channels = { "keyPress" }, packetHandler = PacketHandlerTinyblock.class)
- public class mod_tinyblock {
- /*
- * Because I care not which ID is default...
- */
- private static final int MAX_BLOCK_ID = net.minecraft.block.Block.blocksList.length - 1;
- private static final int MAX_ITEM_ID = net.minecraft.item.Item.itemsList.length - 1 - 256;
- public static final String CATEGORY_NAME = "names";
- public static final String CATEGORY_UI = "UI";
- private int defaultKey = 46;// c
- private String configFilePath = "/config/Tinyblock.cfg";
- private String keyBingingDescription = "Use saw/glue tool";
- public String TinyblockTag = "Tinyblock";
- @SideOnly(Side.CLIENT)
- public KeyBinding uiKey;
- // private File configFile;
- private Configuration config;
- // private static int opticTransformerDefaultID = 2019;
- // public int opticTransformerID;
- @Item(name = "opticTransformer", typeClass = "ItemOpticTransformer.class")
- public static ItemOpticTransformer opticTransformer;
- private static int tinyblocksDefaultID = 150;
- // private static int sawDefaultIDWooden = 2012;
- // private static int sawDefaultIDIron = 2013;
- // private static int sawDefaultIDDiamond = 2014;
- // private static int sawDefaultIDFiery = 2015;
- //
- // private static int glueDefaultIDWeak = 2016;
- // private static int glueDefaultIDMedium = 2017;
- // private static int glueDefaultIDStrong = 2018;
- private static EnumToolMaterial FIERY;
- // SAWS
- @Material("WOOD")
- @Item(name = "sawWooden", typeClass = "ItemSaw.class")
- private ItemSaw sawWooden;
- @Material("IRON")
- @Item(name = "sawIron", typeClass = "ItemSaw.class")
- private ItemSaw sawIron;
- @Material("EMERALD")
- @Item(name = "sawDiamond", typeClass = "ItemSaw.class")
- private ItemSaw sawDiamond;
- @Material("FIERY")
- @Item(name = "sawFiery", typeClass = "ItemSaw.class")
- private ItemSaw sawFiery;
- // GLUES
- @Material("WOOD")
- @Item(name = "glueWeak", typeClass = "ItemGlue.class")
- private ItemGlue glueWeak;
- @Material("IRON")
- @Item(name = "glueMedium", typeClass = "ItemGlue.class")
- private ItemGlue glueMedium;
- @Material("EMERALD")
- @Item(name = "glueStrong", typeClass = "ItemGlue.class")
- private ItemGlue glueStrong;
- @Item(name = "stoneStick", typeClass = "ItemStoneStick.class")
- public ItemStoneStick stoneStick;
- @Metadata
- public ModMetadata meta;
- // private String path;
- private TinyblockKeyHandler keyhandler;
- //private List<Integer> listItemID;
- public UIHandler uiHandler;
- public String texturePath = "/texture/tinyblock_items.png";
- public String defaultTexturesPath = "/terrain.png";
- public int defaultColor = 0xf0f0f0;
- public int maxStacksize = 8 * 64;
- @SideOnly(Side.CLIENT)
- public int tinyBlockRenderID;
- // private static int tinyblockID;
- public RendererTinyblock renderer;
- // public static RendererTinyblockItem itemRenderer;
- @SideOnly(Side.SERVER)
- public MinecraftServer server;
- @SideOnly(Side.CLIENT)
- public Minecraft client;
- @Block(name = "tinyblock", itemTypeClass = ItemTinyBlock.class)
- public BlockTinyblock tinyblock;
- // public static Random random;
- public String opticTransformerName = "Optic Transformer";
- public String stoneStickName = "Stone Stick";
- public String[] sawNames = new String[] { "Wooden Saw", "Iron Saw",
- "Diamond Saw", "Fiery Saw" };
- public String[] glueNames = new String[] { "Tar Glue", "Mixed Glue",
- "Slime Glue" };
- private RecipeManager recipeManager;
- @Instance
- private static mod_tinyblock instance;
- public static mod_tinyblock instance() {
- return instance;
- }
- @PreInit
- public void preinit(FMLPreInitializationEvent event) {
- addInformationToModMeta();
- //listItemID = new ArrayList<Integer>();
- tinyblock = new BlockTinyblock(tinyblocksDefaultID);
- GameRegistry.registerBlock(tinyblock, ItemTinyBlock.class,
- TinyblockTag, meta.modId);
- GameRegistry
- .registerTileEntity(TileEntityTinyblock.class, TinyblockTag);
- NetworkRegistry.instance().registerGuiHandler(this, null);
- FIERY = EnumHelper.addToolMaterial("FIERY", 3, 3500, 6, 2, 16);
- GameRegistry.registerCraftingHandler(new CraftingHandler());
- }
- private void addInformationToModMeta() {
- meta.url = "www.minecraftforum.net/topic/1138677-125/";
- meta.credits = "MrBaconsock for original idea. Yoshi9048, PyroNox and Nocte for fleshing out original idea. ashly138 for making textures.";
- meta.authorList = new ArrayList();
- meta.authorList.add("Wa_delma");
- meta.description = "Allows you to cut both vanilla and modded whole blocks to size of eight of the blocks.";
- meta.screenshots = new String[] { "http://i.imgur.com/rHD7R.png" };
- meta.autogenerated = false;
- }
- public void populateItems() {
- for (Field field : this.getClass().getDeclaredFields()) {
- Item aItem = field.getAnnotation(Item.class);
- if (aItem != null) {
- try {
- Class c = field.getType();
- Constructor cons = c.getConstructors()[0];
- net.minecraft.item.Item item = (net.minecraft.item.Item) cons
- .newInstance(config.getItem(aItem.name(),
- MAX_ITEM_ID).getInt());
- item.setItemName(aItem.name());
- populateMaterial(field, item);
- field.set(this, item);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- }
- private void populateMaterial(Field field, net.minecraft.item.Item item) {
- Material material = field.getAnnotation(Material.class);
- if (material != null) {
- EnumToolMaterial toolMaterial = EnumToolMaterial.valueOf(material
- .value());
- item.setMaxDamage(toolMaterial.getMaxUses() * 4);
- }
- }
- // private int getFree() {
- // for (int n = 1; n < net.minecraft.item.Item.itemsList.length; n++) {
- // if (net.minecraft.item.Item.itemsList[n] == null
- // && !listItemID.contains(n)) {
- // listItemID.add(n);
- // return n;
- // }
- // }
- // return -1;
- // }
- @Init
- @SideOnly(Side.SERVER)
- public void initServer(FMLInitializationEvent event) {
- server = FMLServerHandler.instance().getServer();
- loadServerConfig();
- recipeManager = new RecipeManager();
- }
- @Init
- @SideOnly(Side.CLIENT)
- public void initClient(FMLInitializationEvent event) {
- // Packet packet = new PacketAskConfig();
- // FMLClientHandler.instance().sendPacket(packet);
- client = FMLClientHandler.instance().getClient();
- loadClientConfig();
- recipeManager = new RecipeManager();
- uiHandler = new UIHandler(client);
- TickRegistry.registerTickHandler(new TinyblockTicker(uiHandler),
- Side.CLIENT);
- uiKey = new KeyBinding(keyBingingDescription, defaultKey);
- keyhandler = new TinyblockKeyHandler(uiKey, uiHandler);
- KeyBindingRegistry.registerKeyBinding(keyhandler);
- renderer = new RendererTinyblock();
- tinyBlockRenderID = RenderingRegistry.getNextAvailableRenderId();
- RenderingRegistry.registerBlockHandler(tinyBlockRenderID, renderer);
- MinecraftForge.EVENT_BUS
- .register(new TinyblockDrawBlockHighlightEvent());
- // itemRenderer = new RendererTinyblockItem();
- // MinecraftForgeClient.registerItemRenderer(tinyblock.blockID,
- // itemRenderer);
- }
- @SideOnly(Side.SERVER)
- public void loadServerConfig() {
- createConfig(server.getFile(configFilePath), new ConfigAdder() {
- @Override
- public void add() {
- }
- });
- /*
- * tinyblockID = config.getBlockID(TinyblockTag, tinyblocksDefaultID);
- *
- * sawIDs[0] = config.getItemID(sawNames[0], sawDefaultIDWooden);
- * sawIDs[1] = config.getItemID(sawNames[1], sawDefaultIDIron);
- * sawIDs[2] = config.getItemID(sawNames[2], sawDefaultIDDiamond);
- * sawIDs[3] = config.getItemID(sawNames[3], sawDefaultIDFiery);
- *
- * glueIDs[0] = config.getItemID(glueNames[0], glueDefaultIDWeak);
- * glueIDs[1] = config.getItemID(glueNames[1], glueDefaultIDMedium);
- * glueIDs[2] = config.getItemID(glueNames[2], glueDefaultIDStrong);
- *
- * opticTransformerID = config.getItemID(opticTransformerTag,
- * opticTransformerDefaultID);
- */
- // uihandler = new UIHandler(minecraft, config);
- }
- @SideOnly(Side.CLIENT)
- private void loadClientConfig() {
- createConfig(new File(client.mcDataDir, configFilePath),
- new ConfigAdder() {
- @Override
- public void add() {
- UIHandler.setValues(config);
- }
- });
- }
- private void createConfig(File configFile, ConfigAdder adder) {
- config = new Configuration(configFile);
- config.load();
- adder.add();
- getNames(sawNames);
- getNames(glueNames);
- populateItems();
- config.save();
- // uihandler = new UIHandler(client, config);
- }
- private void getNames(String[] names) {
- for (String name : names) {
- name = config.get(CATEGORY_NAME, name.replace(" ", ""), name).value;
- }
- }
- /*
- * @Override public String getVersion(){ return version; }
- */
- /*
- * @Override public void keyboardEvent(KeyBinding keybinding){
- * if(keybinding.equals(UIkey)){ uihandler.UIKey(); } }
- */
- /*
- * @Override public void load(){ minecraft =
- * ModLoader.getMinecraftInstance(); random = new Random(); UIkey = new
- * KeyBinding(keyBingingDescription, defaultKey); TinyBlockRenderID =
- * ModLoader.getUniqueBlockModelID(this, false);
- *
- * itemRenderer = new RendererTinyblockItem(); blockRenderer = new
- * RendererTinyblockBlock(minecraft.theWorld);
- *
- * ModLoader.registerKey(this, UIkey, false);
- * MinecraftForgeClient.preloadTexture(defaultTexturesPath);
- *
- * MinecraftForgeClient.registerItemRenderer(tinyblockID, itemRenderer);
- * //MinecraftForgeClient.registerRenderLastHandler(sawRenderer);
- *
- * tinyblock = new BlockTinyblock(tinyblockID);
- *
- * int l = 256;//Block.blocksList.length; sawWooden = new ItemSaw(sawIDs[0]
- * - l, 0); sawIron = new ItemSaw(sawIDs[1] - l, 1); sawDiamond = new
- * ItemSaw(sawIDs[2] - l, 2); sawFiery = new ItemSaw(sawIDs[3] - l, 3);
- *
- * glueWeak = new ItemGlue(glueIDs[0] - l, 0); glueMedium = new
- * ItemGlue(glueIDs[1] - l, 1); glueStrong = new ItemGlue(glueIDs[2] - l,
- * 2);
- *
- * opticTransformer = new ItemOpticTransformer(opticTransformerID);
- *
- * MinecraftForge.EVENT_BUS.register(new
- * TinyblockDrawBlockHighlightEvent());
- * MinecraftForge.EVENT_BUS.register(new
- * TinyblockEventSaveHandler(minecraft));
- *
- * ModLoader.registerBlock(tinyblock, ItemTinyBlock.class);
- * ModLoader.registerTileEntity(TileEntityTinyblock.class, TinyblockTag);
- *
- * ModLoader.setInGameHook(this, true, false);
- *
- * ModLoader.addRecipe(new ItemStack(opticTransformer, 1, 0), new
- * Object[]{" GR", " BG", "D ", 'B', new ItemStack(Item.blazeRod, 1, 0),
- * 'G', new ItemStack(Item.ingotGold, 1, 0), 'D', new
- * ItemStack(Item.diamond, 1, 0), 'R', new ItemStack(Item.redstone, 1, 0)});
- *
- * //Saw recipes: ModLoader.addRecipe(new ItemStack(sawWooden, 1, 0), new
- * Object[]{"HSS", "HSS", "H ", 'H', new ItemStack(Item.stick, 1, 0), 'S',
- * new ItemStack(Block.stone, 1, 0)}); ModLoader.addRecipe(new
- * ItemStack(sawIron, 1, 0), new Object[]{"HSS", "HSS", "H ", 'H', new
- * ItemStack(Block.stone, 1, 0), 'S', new ItemStack(Item.ingotIron, 1, 0)});
- * ModLoader.addRecipe(new ItemStack(sawDiamond, 1, 0), new Object[]{"HWS",
- * "HWS", "H ", 'H', new ItemStack(Block.stone, 1, 0), 'W', new
- * ItemStack(Item.ingotIron, 1, 0), 'S', new ItemStack(Item.diamond, 1,
- * 0)}); ModLoader.addRecipe(new ItemStack(sawFiery, 1, 0), new
- * Object[]{"HWS", "HWS", "H ", 'H', new ItemStack(Item.blazeRod, 1, 0),
- * 'W', new ItemStack(Item.ingotIron, 1, 0), 'S', new
- * ItemStack(Item.diamond, 1, 0)});
- *
- * //Glue recipes: ModLoader.addShapelessRecipe(new ItemStack(glueWeak, 1,
- * 0), new Object[]{new ItemStack(Block.wood, 1, 2), new
- * ItemStack(Block.wood, 1, 2), new ItemStack(Item.glassBottle, 1, 0), new
- * ItemStack(Item.coal, 1, 0)}); ModLoader.addShapelessRecipe(new
- * ItemStack(glueMedium, 1, 0), new Object[]{new ItemStack(Block.wood, 1,
- * 2), new ItemStack(Item.slimeBall, 1, 0), new ItemStack(Item.glassBottle,
- * 1, 0), new ItemStack(Item.coal, 1, 0)}); ModLoader.addShapelessRecipe(new
- * ItemStack(glueStrong, 1, 0), new Object[]{new ItemStack(Item.slimeBall,
- * 1, 0), new ItemStack(Item.slimeBall, 1, 0), new
- * ItemStack(Item.glassBottle, 1, 0), new ItemStack(Item.coal, 1, 0)}); }
- */
- /*
- * @Override public boolean onTickInGame(float partialTicks, Minecraft
- * minecraft){ EntityPlayer player = minecraft.thePlayer;
- * if(!minecraft.inGameHasFocus || player.getSleepTimer() > 0 ||
- * player.capabilities.isCreativeMode || player.worldObj.isRemote) return
- * true; return uihandler.UIRender(); //return true; }
- */
- /*
- * @Override public boolean renderWorldBlock(RenderBlocks renderblocks,
- * IBlockAccess iblockaccess, int i, int j, int k, Block block, int l){
- * return blockRenderer.renderTinyblock(iblockaccess, i, j, k, l,
- * renderblocks, block); }
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement