mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-03-09 11:15:35 +00:00
Moved book lores to NBT, so much better
This commit is contained in:
parent
0a8ec4a389
commit
6e04fcd720
@ -27,7 +27,7 @@ public class GUIBookLore extends GuiScreen {
|
|||||||
protected static int sizeX = 272;
|
protected static int sizeX = 272;
|
||||||
protected static int sizeY = 182;
|
protected static int sizeY = 182;
|
||||||
|
|
||||||
protected BookLoreType type;
|
protected String key;
|
||||||
protected NBTTagCompound tag;
|
protected NBTTagCompound tag;
|
||||||
|
|
||||||
//judgement
|
//judgement
|
||||||
@ -39,19 +39,19 @@ public class GUIBookLore extends GuiScreen {
|
|||||||
public GUIBookLore(EntityPlayer player) {
|
public GUIBookLore(EntityPlayer player) {
|
||||||
ItemStack stack = player.getHeldItem();
|
ItemStack stack = player.getHeldItem();
|
||||||
if(!stack.hasTagCompound()) return;
|
if(!stack.hasTagCompound()) return;
|
||||||
this.type = BookLoreType.getTypeFromStack(stack);
|
|
||||||
|
|
||||||
if(type == null) return;
|
|
||||||
this.tag = stack.getTagCompound();
|
this.tag = stack.getTagCompound();
|
||||||
|
this.key = tag.getString("k");
|
||||||
|
if(key.isEmpty()) return;
|
||||||
|
|
||||||
this.color = tag.getInteger("cov_col");
|
this.color = tag.getInteger("cov_col");
|
||||||
if(color <= 0)
|
if(color <= 0)
|
||||||
color = 0x303030;
|
color = 0x303030;
|
||||||
this.maxPage = (int)Math.ceil(type.pages / 2D) - 1;
|
this.maxPage = (int)Math.ceil(tag.getInteger("p") / 2D) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initGui() {
|
public void initGui() {
|
||||||
if(type == null) this.mc.thePlayer.closeScreen();
|
if(key == null || key.isEmpty()) this.mc.thePlayer.closeScreen();
|
||||||
this.guiLeft = (this.width - this.sizeX) / 2;
|
this.guiLeft = (this.width - this.sizeX) / 2;
|
||||||
this.guiTop = (this.height - this.sizeY) / 2;
|
this.guiTop = (this.height - this.sizeY) / 2;
|
||||||
}
|
}
|
||||||
@ -93,13 +93,30 @@ public class GUIBookLore extends GuiScreen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void drawGuiContainerForegroundLayer(int x, int y) {
|
protected void drawGuiContainerForegroundLayer(int x, int y) {
|
||||||
String key = "book_lore." + type.keyI18n + ".page.";
|
String k = "book_lore." + key + ".page.";
|
||||||
|
|
||||||
for(int i = 0; i < 2; i++) {
|
for(int i = 0; i < 2; i++) {
|
||||||
int defacto = this.page * 2 + i; //TODO: force i18n to index from 0 instead of 1
|
int defacto = this.page * 2 + i; //TODO: force i18n to index from 0 instead of 1
|
||||||
|
|
||||||
if(defacto < this.type.pages) {
|
if(defacto < tag.getInteger("p")) {
|
||||||
String text = I18nUtil.resolveKey(key + defacto); //TODO tag-based argument formatting
|
String text;
|
||||||
|
NBTTagCompound argTag = tag.getCompoundTag("p" + defacto);
|
||||||
|
|
||||||
|
if(argTag.hasNoTags())
|
||||||
|
text = I18nUtil.resolveKey(k + defacto);
|
||||||
|
else {
|
||||||
|
List<String> args = new ArrayList();
|
||||||
|
int index = 1;
|
||||||
|
String arg = argTag.getString("a1");
|
||||||
|
|
||||||
|
while(!arg.isEmpty()) {
|
||||||
|
args.add(arg);
|
||||||
|
index++;
|
||||||
|
arg = argTag.getString("a" + index);
|
||||||
|
}
|
||||||
|
|
||||||
|
text = I18nUtil.resolveKey(k + defacto, args.toArray());
|
||||||
|
}
|
||||||
|
|
||||||
float scale = 1;
|
float scale = 1;
|
||||||
int width = 100;
|
int width = 100;
|
||||||
|
|||||||
@ -2,7 +2,10 @@ package com.hbm.items.special;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.math.NumberUtils;
|
||||||
|
|
||||||
import com.hbm.inventory.gui.GUIBookLore;
|
import com.hbm.inventory.gui.GUIBookLore;
|
||||||
|
import com.hbm.items.ModItems;
|
||||||
import com.hbm.lib.RefStrings;
|
import com.hbm.lib.RefStrings;
|
||||||
import com.hbm.main.MainRegistry;
|
import com.hbm.main.MainRegistry;
|
||||||
import com.hbm.tileentity.IGUIProvider;
|
import com.hbm.tileentity.IGUIProvider;
|
||||||
@ -41,20 +44,22 @@ public class ItemBookLore extends Item implements IGUIProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool) {
|
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool) {
|
||||||
BookLoreType type = BookLoreType.getTypeFromStack(stack);
|
if(!stack.hasTagCompound()) return;
|
||||||
|
String key = stack.stackTagCompound.getString("k");
|
||||||
|
if(key.isEmpty()) return;
|
||||||
|
|
||||||
if(type.hasAuthor) {
|
key = "book_lore." + key + ".author";
|
||||||
String unloc = I18nUtil.resolveKey("book_lore.author", I18nUtil.resolveKey("book_lore." + type.keyI18n + ".author"));
|
String loc = I18nUtil.resolveKey(key);
|
||||||
|
|
||||||
list.add(unloc);
|
list.add(I18nUtil.resolveKey("book_lore.author", loc));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUnlocalizedName(ItemStack stack) {
|
public String getUnlocalizedName(ItemStack stack) {
|
||||||
BookLoreType type = BookLoreType.getTypeFromStack(stack);
|
if(!stack.hasTagCompound()) return "book_lore.test";
|
||||||
|
String key = stack.stackTagCompound.getString("k");
|
||||||
|
|
||||||
return "book_lore." + type.keyI18n;
|
return "book_lore." + (key.isEmpty() ? "test" : key);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Textures
|
//Textures
|
||||||
@ -116,6 +121,28 @@ public class ItemBookLore extends Item implements IGUIProvider {
|
|||||||
return new GUIBookLore(player);
|
return new GUIBookLore(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ItemStack createBook(String key, int pages, int colorCov, int colorTit) {
|
||||||
|
ItemStack book = new ItemStack(ModItems.book_lore);
|
||||||
|
NBTTagCompound tag = new NBTTagCompound();
|
||||||
|
tag.setString("k", key);
|
||||||
|
tag.setShort("p", (short)pages);
|
||||||
|
tag.setInteger("cov_col", colorCov);
|
||||||
|
tag.setInteger("tit_col", colorTit);
|
||||||
|
|
||||||
|
book.stackTagCompound = tag;
|
||||||
|
return book;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addArgs(ItemStack book, int page, String... args) {
|
||||||
|
if(!book.hasTagCompound()) return;
|
||||||
|
NBTTagCompound data = new NBTTagCompound();
|
||||||
|
for(int i = 0; i < args.length; i++) {
|
||||||
|
data.setString("a" + (i + 1), args[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
book.stackTagCompound.setTag("p" + page, data);
|
||||||
|
}
|
||||||
|
//TODO remove this and fix any references
|
||||||
public enum BookLoreType {
|
public enum BookLoreType {
|
||||||
TEST(true, "test", 5),
|
TEST(true, "test", 5),
|
||||||
BOOK_IODINE(true, "book_iodine", 3) {
|
BOOK_IODINE(true, "book_iodine", 3) {
|
||||||
|
|||||||
@ -2,8 +2,11 @@ package com.hbm.items.tool;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.hbm.crafting.handlers.MKUCraftingHandler;
|
||||||
import com.hbm.handler.pollution.PollutionHandler;
|
import com.hbm.handler.pollution.PollutionHandler;
|
||||||
import com.hbm.handler.pollution.PollutionHandler.PollutionType;
|
import com.hbm.handler.pollution.PollutionHandler.PollutionType;
|
||||||
|
import com.hbm.items.ModItems;
|
||||||
|
import com.hbm.items.special.ItemBookLore;
|
||||||
import com.hbm.lib.Library;
|
import com.hbm.lib.Library;
|
||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
@ -32,7 +35,25 @@ public class ItemWandD extends Item {
|
|||||||
vnt.setSFX(new ExplosionEffectStandard());
|
vnt.setSFX(new ExplosionEffectStandard());
|
||||||
vnt.explode();*/
|
vnt.explode();*/
|
||||||
|
|
||||||
PollutionHandler.incrementPollution(world, pos.blockX, pos.blockY, pos.blockZ, PollutionType.SOOT, 15);
|
MKUCraftingHandler.generateRecipe(world);
|
||||||
|
ItemStack[] recipe = MKUCraftingHandler.MKURecipe;
|
||||||
|
|
||||||
|
if(recipe == null) //take no chances
|
||||||
|
return stack;
|
||||||
|
|
||||||
|
int r = 0;
|
||||||
|
for(int i = 0; i < 9; i++) {
|
||||||
|
if(recipe[i] != null && recipe[i].getItem() == ModItems.powder_iodine) {
|
||||||
|
r = i + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack book = ItemBookLore.createBook("book_iodine", 3, 0x4C407A, 0xFFF7C1);
|
||||||
|
ItemBookLore.addArgs(book, 2, String.valueOf(r));
|
||||||
|
player.inventory.addItemStackToInventory(book);
|
||||||
|
player.inventoryContainer.detectAndSendChanges();
|
||||||
|
|
||||||
|
//PollutionHandler.incrementPollution(world, pos.blockX, pos.blockY, pos.blockZ, PollutionType.SOOT, 15);
|
||||||
|
|
||||||
/*TimeAnalyzer.startCount("setBlock");
|
/*TimeAnalyzer.startCount("setBlock");
|
||||||
world.setBlock(pos.blockX, pos.blockY, pos.blockZ, Blocks.dirt);
|
world.setBlock(pos.blockX, pos.blockY, pos.blockZ, Blocks.dirt);
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 244 B After Width: | Height: | Size: 244 B |
Loading…
x
Reference in New Issue
Block a user