diff options
Diffstat (limited to 'src/Java')
-rw-r--r-- | src/Java/gtPlusPlus/GTplusplus.java | 3 | ||||
-rw-r--r-- | src/Java/gtPlusPlus/core/common/CommonProxy.java | 2 | ||||
-rw-r--r-- | src/Java/gtPlusPlus/core/handler/BookHandler.java | 108 | ||||
-rw-r--r-- | src/Java/gtPlusPlus/core/item/ModItems.java | 3 | ||||
-rw-r--r-- | src/Java/gtPlusPlus/core/item/general/books/ItemBaseBook.java | 60 | ||||
-rw-r--r-- | src/Java/gtPlusPlus/core/util/Utils.java | 10 | ||||
-rw-r--r-- | src/Java/gtPlusPlus/core/util/nbt/NBTUtils.java | 71 | ||||
-rw-r--r-- | src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/Gregtech4Content.java | 24 |
8 files changed, 222 insertions, 59 deletions
diff --git a/src/Java/gtPlusPlus/GTplusplus.java b/src/Java/gtPlusPlus/GTplusplus.java index a7de15d76d..2c08414743 100644 --- a/src/Java/gtPlusPlus/GTplusplus.java +++ b/src/Java/gtPlusPlus/GTplusplus.java @@ -27,6 +27,7 @@ import gregtech.api.util.Recipe_GT.Gregtech_Recipe_Map; import gtPlusPlus.core.block.ModBlocks; import gtPlusPlus.core.commands.CommandMath; import gtPlusPlus.core.common.CommonProxy; +import gtPlusPlus.core.handler.BookHandler; import gtPlusPlus.core.handler.Recipes.RegistrationHandler; import gtPlusPlus.core.handler.events.BlockEventHandler; import gtPlusPlus.core.handler.events.LoginEventHandler; @@ -268,7 +269,7 @@ public class GTplusplus implements ActionListener { this.dumpGtRecipeMap(Gregtech_Recipe_Map.sMatterFab2Recipes); this.dumpGtRecipeMap(Gregtech_Recipe_Map.sAlloyBlastSmelterRecipes); } - + BookHandler.runLater(); Utils.LOG_INFO("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); Utils.LOG_INFO("| Recipes succesfully Loaded: " + RegistrationHandler.recipesSuccess + " | Failed: " + RegistrationHandler.recipesFailed + " |"); diff --git a/src/Java/gtPlusPlus/core/common/CommonProxy.java b/src/Java/gtPlusPlus/core/common/CommonProxy.java index 16c755b23d..55bde81bb7 100644 --- a/src/Java/gtPlusPlus/core/common/CommonProxy.java +++ b/src/Java/gtPlusPlus/core/common/CommonProxy.java @@ -64,7 +64,7 @@ public class CommonProxy { } AddToCreativeTab.initialiseTabs(); COMPAT_IntermodStaging.preInit(); - + BookHandler.run(); //Registration of entities and renderers Utils.LOG_INFO("[Proxy] Calling Entity registrator."); registerEntities(); diff --git a/src/Java/gtPlusPlus/core/handler/BookHandler.java b/src/Java/gtPlusPlus/core/handler/BookHandler.java new file mode 100644 index 0000000000..ec42bd1f12 --- /dev/null +++ b/src/Java/gtPlusPlus/core/handler/BookHandler.java @@ -0,0 +1,108 @@ +package gtPlusPlus.core.handler; + +import java.util.HashMap; +import java.util.Map; + +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.item.ItemUtils; +import gtPlusPlus.core.util.recipe.RecipeUtils; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; + +public class BookHandler { + + public static int mBookKeeperCount = 0; + + public static Map<Integer, BookTemplate> mBookMap = new HashMap(); + + public static BookTemplate book_ThermalBoiler; + public static BookTemplate book_TestNovel; + public static BookTemplate book_ModularBauble; + + public static void run(){ + + Utils.LOG_INFO("Writing books."); + + //Thermal Boiler + book_ThermalBoiler = writeBookTemplate( + "Manual_Thermal_Boiler", "Thermal Boiler Manual", "Alkalus", + new String[] { + "This Book explains how to set up and run your Thermal Boiler. We are not responsible for any Damage done by this Book itself nor its content.", + "First you need to craft the following things for a Thermal Boiler to Function: The Main Boiler Block, 20 Thermal Containment Casings, two Input Hatches, two Output Hatches, a bunch of different Tools and a Maintenance Hatch.", + "To begin the building, lay out the first 3x3 layer of Machine Casings on the ground (with a Hatch in the Middle), then place the Boiler Block facing outward in the middle of one of the 3m wide Sides.", + "Now grab 3 other Hatches and place them on the remaining three 3m wide Sides also facing outwards. And now the four corners of the Machine need also a Machine Casing. There should only be a Hole left in the middle of the Cube.", + "So, now place a 3x3 of Machine Casings ontop, at the 3rd Layer with the last Hatch in the middle facing outwards as well.", + "When accessing the Boiler Block, it should now stop telling you, that the structure is incomplete (bottom Line of that Screen). Now go with a bunch of different Tools (Metal Hammer, Rubber Hammer, Screwdriver, Wrench, Soldering Iron and Crowbar)", + "to the Maintenance Hatch and access it. After that you grab the 6 Tools and rightclick the Slot with each of them in your Hand in the Maintenance GUI. Note that you need Soldering Tin/Lead in your Inventory to use the Soldering Iron.", + "The Main Block should now tell you that you need to use the Rubber Hammer on it to (re)activate the Machine. The Rubber Hammer can enable and disable Machines. The Machine disables itself after something important broke.", + "If you want to use Lava with this Device, then you should add a Lava Filter to extract additional Resources from the Lava. If the Filter breaks, the Machine won't explode like a Turbine would. If you use molten Salt, then you won't need a Filter.", + "You will get Obsidian when processing Lava, however if a Filter is used, you will get sometimes an Ingot instead of a Block of Obsidian. When using molten Salt, you will get the Salt back.", + "So, now for the Maintenance. After a few Hours of running nonstop, your Boiler will get small Problems, which don't prevent it from running, these Problems just decrease Efficiency. Every Problem listed on the Screen does -10% Efficiency.", + "To fix these Problems, just go to the Maintenance Hatch and click with the problem corresponding Tool on the Slot to repair. If all six possible runtime Problems happen, the Machine will auto-shutdown no matter what. No Explosion, it's just stopping.", + "The Thermal Boiler will produce 800 Liters of Steam per tick for about 5 or 6 Liters of Water per tick at reaching 100% Efficiency. In case of Lava it consumes 1666 Liters every Second.", + "A Thermal Boiler is worth about 33 small Thermal Generators, and as the Boilers get much less Efficient, when not having enough Fuel, you should consider making a large Nether Pump for Lava, or a good Nuclear Reactor for molten Salt.", + "Input and Output Slots are fully optional, you can place multiple ones of them or even none on the Machine. A Machine without Input couldn't process any Recipes, while a Machine without Output just voids all outputted Items and Liquids.", + "It might be useful to use the Screwdriver on the Output Hatches to determine what is outputted where." }); + + + + //Test Novel + book_TestNovel = writeBookTemplate( + "TestBook", "A Book about the Gardens", "Alkalus", + new String[] {"There was once a sad and lonely oak tree."}); + + //Test Novel + book_ModularBauble = writeBookTemplate( + "Manual_Modular_Bauble", "How to: Modular baubles", "Alkalus", + new String[] { + "There was once a sad and lonely oak tree.", + "There was once a sad and lonely oak tree.", + "There was once a sad and lonely oak tree.", + "There was once a sad and lonely oak tree.", + "There was once a sad and lonely oak tree.", + "There was once a sad and lonely oak tree."}); + } + + + + + public static ItemStack ItemBookWritten_ThermalBoiler; + public static ItemStack ItemBookWritten_ModularBaubles; + public static ItemStack ItemBookWritten_Test; + + public static void runLater(){ + ItemBookWritten_ThermalBoiler = writeBook(book_ThermalBoiler); + ItemBookWritten_ModularBaubles = writeBook(book_ModularBauble); + ItemBookWritten_Test = writeBook(book_TestNovel); + RecipeUtils.addShapelessGregtechRecipe(new ItemStack[]{ItemUtils.getSimpleStack(Items.writable_book), ItemUtils.getSimpleStack(Items.lava_bucket)}, ItemBookWritten_ThermalBoiler); + } + + private static ItemStack writeBook(BookTemplate mTemplate){ + return Utils.getWrittenBook(mTemplate.mMapping, mTemplate.mTitle, mTemplate.mAuthor, mTemplate.mPages); + } + + private static BookTemplate writeBookTemplate(String aMapping, String aTitle, String aAuthor, String[] aPages){ + mBookKeeperCount++; + BookTemplate mTemp = new BookTemplate(mBookKeeperCount, aMapping, aTitle, aAuthor, aPages); + mBookMap.put(mBookKeeperCount-1, mTemp); + return mTemp; + } + + public static class BookTemplate { + public final int mMeta; + public final String mMapping; + public final String mTitle; + public final String mAuthor; + public final String[] mPages; + + BookTemplate(int aMeta, String aMapping, String aTitle, String aAuthor, String[] aPages){ + this.mMeta = aMeta; + this.mMapping = aMapping; + this.mTitle = aTitle; + this.mAuthor = aAuthor; + this.mPages = aPages; + } + } +} + + diff --git a/src/Java/gtPlusPlus/core/item/ModItems.java b/src/Java/gtPlusPlus/core/item/ModItems.java index 0f25481831..ec0e21c7bb 100644 --- a/src/Java/gtPlusPlus/core/item/ModItems.java +++ b/src/Java/gtPlusPlus/core/item/ModItems.java @@ -308,7 +308,6 @@ public final class ModItems { //Start meta Item Generation ItemsFoods.load(); - itemCustomBook = new ItemBaseBook(); try{ @@ -807,5 +806,7 @@ public final class ModItems { //ItemBlockGtFrameBox = new ItemBlockGtFrameBox(ModBlocks.blockGtFrameSet1); //GameRegistry.registerItem(ItemBlockGtFrameBox, "itemGtFrameBoxSet1"); + + itemCustomBook = new ItemBaseBook(); } } diff --git a/src/Java/gtPlusPlus/core/item/general/books/ItemBaseBook.java b/src/Java/gtPlusPlus/core/item/general/books/ItemBaseBook.java index c7bf2e821e..5160ddd8ce 100644 --- a/src/Java/gtPlusPlus/core/item/general/books/ItemBaseBook.java +++ b/src/Java/gtPlusPlus/core/item/general/books/ItemBaseBook.java @@ -2,9 +2,12 @@ package gtPlusPlus.core.item.general.books; import java.util.List; +import cpw.mods.fml.common.registry.GameRegistry; +import gregtech.api.util.GT_OreDictUnificator; import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.handler.BookHandler; import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.item.ItemUtils; import gtPlusPlus.core.util.nbt.NBTUtils; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; @@ -17,35 +20,37 @@ public class ItemBaseBook extends ItemWritableBook{ public ItemBaseBook(){ this.setCreativeTab(AddToCreativeTab.tabMisc); this.setMaxStackSize(1); - this.setNoRepair(); - this.setMaxDamage(Short.MAX_VALUE); this.setTextureName(CORE.MODID+":"+"itemBook"); + this.setUnlocalizedName("itembookgt"); + GameRegistry.registerItem(this, "bookGT"); + GT_OreDictUnificator.registerOre("bookWritten", ItemUtils.getWildcardStack(this)); + GT_OreDictUnificator.registerOre("craftingBook", ItemUtils.getWildcardStack(this)); + } @Override public void getSubItems(Item item, CreativeTabs tab, List list) { - for (int i = 0; i < Utils.getBookCount(); i ++) { - list.add(new ItemStack(item, 1, i)); + for (int i = 0; i < BookHandler.mBookMap.size(); i ++) { + ItemStack bookstack = new ItemStack(item, 1, i); + NBTUtils.createIntegerTagCompound(bookstack, "stats", "mMeta", i); + NBTUtils.setString(bookstack, "title", BookHandler.mBookMap.get(i).mTitle); + list.add(bookstack); } } @Override public String getItemStackDisplayName(final ItemStack tItem) { - if (NBTUtils.hasKey(tItem, "mMeta")){ - return NBTUtils.getBookTitle(tItem); + if (NBTUtils.hasKey(tItem, "title")){ + return NBTUtils.getString(tItem, "title"); } + NBTUtils.tryIterateNBTData(tItem); return "GT++ Storybook"; } @Override - public boolean isDamageable() { - return false; - } - - @Override public void addInformation(ItemStack p_77624_1_, EntityPlayer p_77624_2_, List p_77624_3_, boolean p_77624_4_) { // TODO Auto-generated method stub - super.addInformation(p_77624_1_, p_77624_2_, p_77624_3_, p_77624_4_); + //super.addInformation(p_77624_1_, p_77624_2_, p_77624_3_, p_77624_4_); } @Override @@ -54,26 +59,23 @@ public class ItemBaseBook extends ItemWritableBook{ } @Override - public int getDamage(ItemStack stack) { - if (NBTUtils.hasKey(stack, "mMeta")){ - return NBTUtils.getInteger(stack, "mMeta"); - } - return 0; - } - - @Override - public int getDisplayDamage(ItemStack stack) { - return 0; - } - - @Override public boolean showDurabilityBar(ItemStack stack) { return false; } - @Override - public void setDamage(ItemStack stack, int damage) { - NBTUtils.setInteger(stack, "mMeta", damage); + /*@Override + public int getDamage(ItemStack stack) { + try { + return NBTUtils.getIntegerTagCompound(stack, "stats", "mMeta"); + } + catch (Throwable t) { + return 0; + } } + @Override + public void setDamage(ItemStack stack, int damage) { + NBTUtils.createIntegerTagCompound(stack, "stats", "mMeta", damage); + }*/ + } diff --git a/src/Java/gtPlusPlus/core/util/Utils.java b/src/Java/gtPlusPlus/core/util/Utils.java index 4d15c48097..fb009ce2ed 100644 --- a/src/Java/gtPlusPlus/core/util/Utils.java +++ b/src/Java/gtPlusPlus/core/util/Utils.java @@ -1,5 +1,7 @@ package gtPlusPlus.core.util; +import static gtPlusPlus.core.handler.BookHandler.mBookKeeperCount; + import java.awt.Color; import java.awt.Graphics; import java.io.File; @@ -21,6 +23,7 @@ import gregtech.api.util.GT_LanguageManager; import gregtech.api.util.GT_Log; import gregtech.api.util.GT_Utility; import gtPlusPlus.GTplusplus; +import gtPlusPlus.core.handler.BookHandler; import gtPlusPlus.core.item.ModItems; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.material.Material; @@ -780,7 +783,7 @@ public class Utils { if ((GT_Utility.isStringInvalid(aTitle)) || (GT_Utility.isStringInvalid(aAuthor)) || (aPages.length <= 0)) return null; sBookCount += 1; - rStack = new ItemStack(ModItems.itemCustomBook, 1); + rStack = new ItemStack(ModItems.itemCustomBook, 1, sBookCount); NBTTagCompound tNBT = new NBTTagCompound(); tNBT.setString("title", GT_LanguageManager.addStringLocalization( new StringBuilder().append("Book.").append(aTitle).append(".Name").toString(), aTitle)); @@ -809,11 +812,12 @@ public class Utils { .append(" at its creation. Gotta get 'em all!").toString())); tNBT.setTag("pages", tNBTList); rStack.setTagCompound(tNBT); - GT_Log.out.println(new StringBuilder().append("GT_Mod: Added Book to Book List - Mapping: '").append(aMapping) + GT_Log.out.println(new StringBuilder().append("GT++_Mod: Added Book to Book++ List - Mapping: '").append(aMapping) .append("' - Name: '").append(aTitle).append("' - Author: '").append(aAuthor).append("'") .toString()); - NBTUtils.setInteger(rStack, "mMeta", sBookCount); + NBTUtils.createIntegerTagCompound(rStack, "stats", "mMeta", sBookCount); CORE.sBookList.put(aMapping, rStack); + Utils.LOG_INFO("Creating book: "+aTitle+" by "+aAuthor+". Using Meta "+sBookCount+"."); return GT_Utility.copy(new Object[]{rStack}); } diff --git a/src/Java/gtPlusPlus/core/util/nbt/NBTUtils.java b/src/Java/gtPlusPlus/core/util/nbt/NBTUtils.java index 3005c53f1b..c5f3942997 100644 --- a/src/Java/gtPlusPlus/core/util/nbt/NBTUtils.java +++ b/src/Java/gtPlusPlus/core/util/nbt/NBTUtils.java @@ -259,5 +259,76 @@ public class NBTUtils { } return false; } + + public static boolean createIntegerTagCompound(ItemStack rStack, String tagName, String keyName, int keyValue){ + final NBTTagCompound tagMain = new NBTTagCompound(); + final NBTTagCompound tagNBT = new NBTTagCompound(); + tagNBT.setInteger(keyName, keyValue); + tagMain.setTag(tagName, tagNBT); + rStack.setTagCompound(tagMain); + return true; + } + + public static boolean createLongTagCompound(ItemStack rStack, String tagName, String keyName, long keyValue){ + final NBTTagCompound tagMain = new NBTTagCompound(); + final NBTTagCompound tagNBT = new NBTTagCompound(); + tagNBT.setLong(keyName, keyValue); + tagMain.setTag(tagName, tagNBT); + rStack.setTagCompound(tagMain); + return true; + } + + public static boolean createStringTagCompound(ItemStack rStack, String tagName, String keyName, String keyValue){ + final NBTTagCompound tagMain = new NBTTagCompound(); + final NBTTagCompound tagNBT = new NBTTagCompound(); + tagNBT.setString(keyName, keyValue); + tagMain.setTag(tagName, tagNBT); + rStack.setTagCompound(tagMain); + return true; + } + + public static int getIntegerTagCompound(ItemStack aStack, String tagName, String keyName){ + NBTTagCompound aNBT = aStack.getTagCompound(); + if (aNBT != null) { + aNBT = aNBT.getCompoundTag(tagName); + if (aNBT != null) { + return aNBT.getInteger(keyName); + } + } + return 0; + } + + public static long getLongTagCompound(ItemStack aStack, String tagName, String keyName){ + NBTTagCompound aNBT = aStack.getTagCompound(); + if (aNBT != null) { + aNBT = aNBT.getCompoundTag(tagName); + if (aNBT != null) { + return aNBT.getLong(keyName); + } + } + return 0L; + } + + public static String getStringTagCompound(ItemStack aStack, String tagName, String keyName){ + NBTTagCompound aNBT = aStack.getTagCompound(); + if (aNBT != null) { + aNBT = aNBT.getCompoundTag(tagName); + if (aNBT != null) { + return aNBT.getString(keyName); + } + } + return null; + } + + public static boolean hasKeyInTagCompound(ItemStack stack, String tag, String key){ + NBTTagCompound aNBT = stack.getTagCompound(); + if (aNBT != null) { + aNBT = aNBT.getCompoundTag(tag); + if (aNBT.hasKey(key)) { + return true; + } + } + return false; + } } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/Gregtech4Content.java b/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/Gregtech4Content.java index 67005cacf0..72f8ba73bb 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/Gregtech4Content.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/Gregtech4Content.java @@ -72,30 +72,6 @@ public class Gregtech4Content { Utils.LOG_INFO("Gregtech 4 Content | Registering Thermal Boiler."); GregtechItemList.GT4_Thermal_Boiler .set(new GT4Entity_ThermalBoiler(875, "gtplusplus.thermal.boiler", "Thermal Boiler").getStackForm(1L)); - - - - //Thermal Boiler Manual - ItemStack manual_Boiler = Utils.getWrittenBook( - "Manual_Thermal_Boiler", "Thermal Boiler Manual", "Alkalus", - new String[] { - "This Book explains how to set up and run your Thermal Boiler. We are not responsible for any Damage done by this Book itself nor its content.", - "First you need to craft the following things for a Thermal Boiler to Function: The Main Boiler Block, 20 Thermal Containment Casings, two Input Hatches, two Output Hatches, a bunch of different Tools and a Maintenance Hatch.", - "To begin the building, lay out the first 3x3 layer of Machine Casings on the ground (with a Hatch in the Middle), then place the Boiler Block facing outward in the middle of one of the 3m wide Sides.", - "Now grab 3 other Hatches and place them on the remaining three 3m wide Sides also facing outwards. And now the four corners of the Machine need also a Machine Casing. There should only be a Hole left in the middle of the Cube.", - "So, now place a 3x3 of Machine Casings ontop, at the 3rd Layer with the last Hatch in the middle facing outwards as well.", - "When accessing the Boiler Block, it should now stop telling you, that the structure is incomplete (bottom Line of that Screen). Now go with a bunch of different Tools (Metal Hammer, Rubber Hammer, Screwdriver, Wrench, Soldering Iron and Crowbar)", - "to the Maintenance Hatch and access it. After that you grab the 6 Tools and rightclick the Slot with each of them in your Hand in the Maintenance GUI. Note that you need Soldering Tin/Lead in your Inventory to use the Soldering Iron.", - "The Main Block should now tell you that you need to use the Rubber Hammer on it to (re)activate the Machine. The Rubber Hammer can enable and disable Machines. The Machine disables itself after something important broke.", - "If you want to use Lava with this Device, then you should add a Lava Filter to extract additional Resources from the Lava. If the Filter breaks, the Machine won't explode like a Turbine would. If you use molten Salt, then you won't need a Filter.", - "You will get Obsidian when processing Lava, however if a Filter is used, you will get sometimes an Ingot instead of a Block of Obsidian. When using molten Salt, you will get the Salt back.", - "So, now for the Maintenance. After a few Hours of running nonstop, your Boiler will get small Problems, which don't prevent it from running, these Problems just decrease Efficiency. Every Problem listed on the Screen does -10% Efficiency.", - "To fix these Problems, just go to the Maintenance Hatch and click with the problem corresponding Tool on the Slot to repair. If all six possible runtime Problems happen, the Machine will auto-shutdown no matter what. No Explosion, it's just stopping.", - "The Thermal Boiler will produce 800 Liters of Steam per tick for about 5 or 6 Liters of Water per tick at reaching 100% Efficiency. In case of Lava it consumes 1666 Liters every Second.", - "A Thermal Boiler is worth about 33 small Thermal Generators, and as the Boilers get much less Efficient, when not having enough Fuel, you should consider making a large Nether Pump for Lava, or a good Nuclear Reactor for molten Salt.", - "Input and Output Slots are fully optional, you can place multiple ones of them or even none on the Machine. A Machine without Input couldn't process any Recipes, while a Machine without Output just voids all outputted Items and Liquids.", "It might be useful to use the Screwdriver on the Output Hatches to determine what is outputted where." }); - - RecipeUtils.addShapelessGregtechRecipe(new ItemStack[]{ItemUtils.getSimpleStack(Items.writable_book), ItemUtils.getSimpleStack(Items.lava_bucket)}, manual_Boiler); } } |