Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/delegate-manuals-to-dreamcraft' …
Browse files Browse the repository at this point in the history
…into dev
  • Loading branch information
Dream-Master committed Jan 20, 2024
2 parents 6569155 + 728d7da commit cacc27c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 41 deletions.
13 changes: 10 additions & 3 deletions src/main/java/tconstruct/client/TProxyClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import org.w3c.dom.Document;

import cpw.mods.fml.common.Loader;
import mantle.client.SmallFontRenderer;
import mantle.lib.client.MantleClientRegistry;
import tconstruct.TConstruct;
Expand Down Expand Up @@ -57,6 +58,15 @@ public void registerRenderer() {
public static ManualInfo manualData;

public void readManuals() {
initManualIcons();
initManualRecipes();
initManualPages();
if (!Loader.isModLoaded("dreamcraft")) {
readTinkersConstructManuals();
}
}

private void readTinkersConstructManuals() {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
String CurrentLanguage = Minecraft.getMinecraft().getLanguageManager().getCurrentLanguage().getLanguageCode();

Expand All @@ -73,9 +83,6 @@ public void readManuals() {
weaponry = weaponry_cl != null ? weaponry_cl
: readManual("/assets/tinker/manuals/en_US/weaponry.xml", dbFactory);

initManualIcons();
initManualRecipes();
initManualPages();
manualData = new ManualInfo();
}

Expand Down
24 changes: 14 additions & 10 deletions src/main/java/tconstruct/tools/items/Manual.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tconstruct.tools.items;

import java.util.List;
import java.util.Objects;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
Expand All @@ -11,11 +12,11 @@
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import mantle.books.BookData;
import mantle.books.BookDataStore;
import mantle.client.gui.GuiManual;
import mantle.items.abstracts.CraftingItem;
import tconstruct.TConstruct;
import tconstruct.achievements.TAchievements;
import tconstruct.client.TProxyClient;
import tconstruct.library.TConstructRegistry;

public class Manual extends CraftingItem {
Expand All @@ -41,22 +42,25 @@ public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer pla

@SideOnly(Side.CLIENT)
public void openBook(ItemStack stack, World world, EntityPlayer player) {
player.openGui(TConstruct.instance, mantle.client.MProxyClient.manualGuiID, world, 0, 0, 0);
FMLClientHandler.instance().displayGuiScreen(player, new GuiManual(stack, getData(stack)));
BookData data = BookDataStore.getBookfromName(TConstruct.modID, getBookName(stack.getItemDamage()));
if (Objects.nonNull(data)) {
player.openGui(TConstruct.instance, mantle.client.MProxyClient.manualGuiID, world, 0, 0, 0);
FMLClientHandler.instance().displayGuiScreen(player, new GuiManual(stack, data));
}
}

private BookData getData(ItemStack stack) {
switch (stack.getItemDamage()) {
private static String getBookName(int bookItemDamage) {
switch (bookItemDamage) {
case 0:
return TProxyClient.manualData.beginner;
return "tconstruct.manual.beginner";
case 1:
return TProxyClient.manualData.toolStation;
return "tconstruct.manual.toolstation";
case 2:
return TProxyClient.manualData.smeltery;
return "tconstruct.manual.smeltery";
case 4:
return TProxyClient.manualData.weaponry;
return "tconstruct.manual.weaponry";
default:
return TProxyClient.manualData.diary;
return "tconstruct.manual.diary";
}
}

Expand Down
44 changes: 16 additions & 28 deletions src/main/java/tconstruct/tools/items/ManualInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,65 +9,53 @@
import cpw.mods.fml.relauncher.Side;
import mantle.books.BookData;
import mantle.books.BookDataStore;
import tconstruct.TConstruct;
import tconstruct.client.TProxyClient;

/**
* This class is now just a constructor with side effects, so a glorified method call. TODO: Clean up when breaking API
* change is deemed acceptable.
*/
public class ManualInfo {
// static String[] name = new String[] { "beginner", "toolstation", "smeltery", "diary" };
// static String[] textureName = new String[] { "tinkerbook_diary", "tinkerbook_toolstation",
// "tinkerbook_smeltery", "tinkerbook_blue" };

BookData beginner = new BookData();
BookData toolStation = new BookData();
BookData smeltery = new BookData();
BookData diary = new BookData();
BookData weaponry = new BookData();

/*
* diary = readManual("/assets/tinker/manuals/diary.xml", dbFactory); volume1 =
* readManual("/assets/tinker/manuals/firstday.xml", dbFactory); volume2 =
* readManual("/assets/tinker/manuals/materials.xml", dbFactory); smelter =
* readManual("/assets/tinker/manuals/smeltery.xml", dbFactory);
*/

public ManualInfo() {
Side side = FMLCommonHandler.instance().getEffectiveSide();
beginner = initManual(
beginner,
initManual(
new BookData(),
"tconstruct.manual.beginner",
"\u00a7o" + StatCollector.translateToLocal("manual1.tooltip"),
side == Side.CLIENT ? TProxyClient.volume1 : null,
"tinker:tinkerbook_diary");
toolStation = initManual(
toolStation,
initManual(
new BookData(),
"tconstruct.manual.toolstation",
"\u00a7o" + StatCollector.translateToLocal("manual2.tooltip"),
side == Side.CLIENT ? TProxyClient.volume2 : null,
"tinker:tinkerbook_toolstation");
smeltery = initManual(
smeltery,
initManual(
new BookData(),
"tconstruct.manual.smeltery",
"\u00a7o" + StatCollector.translateToLocal("manual3.tooltip"),
side == Side.CLIENT ? TProxyClient.smelter : null,
"tinker:tinkerbook_smeltery");
diary = initManual(
diary,
initManual(
new BookData(),
"tconstruct.manual.diary",
"\u00a7o" + StatCollector.translateToLocal("manual4.tooltip"),
side == Side.CLIENT ? TProxyClient.diary : null,
"tinker:tinkerbook_blue");
weaponry = initManual(
weaponry,
initManual(
new BookData(),
"tconstruct.manual.weaponry",
"\u00a7o" + StatCollector.translateToLocal("manual5.tooltip"),
side == Side.CLIENT ? TProxyClient.weaponry : null,
"tinker:tinkerbook_green");
}

public BookData initManual(BookData data, String unlocName, String toolTip, Document xmlDoc, String itemImage) {
// proxy.readManuals();
data.unlocalizedName = unlocName;
data.toolTip = unlocName;
data.modID = "TConstruct";
data.modID = TConstruct.modID;
data.itemImage = new ResourceLocation(data.modID, itemImage);
data.doc = xmlDoc;
BookDataStore.addBook(data);
Expand Down

0 comments on commit cacc27c

Please sign in to comment.