2015-08-29 14:33:25 +02:00
|
|
|
/*
|
|
|
|
* This file ("ItemBooklet.java") is part of the Actually Additions Mod for Minecraft.
|
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
|
|
|
* http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
|
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2015-11-02 20:55:19 +01:00
|
|
|
* © 2015 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
2015-12-30 22:02:15 +01:00
|
|
|
package de.ellpeck.actuallyadditions.items;
|
2015-08-28 21:17:09 +02:00
|
|
|
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2015-12-30 22:02:15 +01:00
|
|
|
import de.ellpeck.actuallyadditions.ActuallyAdditions;
|
|
|
|
import de.ellpeck.actuallyadditions.achievement.TheAchievements;
|
|
|
|
import de.ellpeck.actuallyadditions.blocks.IHudDisplay;
|
|
|
|
import de.ellpeck.actuallyadditions.booklet.BookletUtils;
|
|
|
|
import de.ellpeck.actuallyadditions.booklet.EntrySet;
|
|
|
|
import de.ellpeck.actuallyadditions.booklet.GuiBooklet;
|
|
|
|
import de.ellpeck.actuallyadditions.booklet.InitBooklet;
|
|
|
|
import de.ellpeck.actuallyadditions.booklet.page.BookletPage;
|
|
|
|
import de.ellpeck.actuallyadditions.inventory.GuiHandler;
|
|
|
|
import de.ellpeck.actuallyadditions.items.base.ItemBase;
|
|
|
|
import de.ellpeck.actuallyadditions.util.AssetUtil;
|
|
|
|
import de.ellpeck.actuallyadditions.util.ModUtil;
|
|
|
|
import de.ellpeck.actuallyadditions.util.StringUtil;
|
2015-12-22 16:08:53 +01:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.gui.ScaledResolution;
|
2015-08-28 21:17:09 +02:00
|
|
|
import net.minecraft.client.renderer.texture.IIconRegister;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.EnumRarity;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2015-12-22 16:08:53 +01:00
|
|
|
import net.minecraft.profiler.Profiler;
|
|
|
|
import net.minecraft.util.EnumChatFormatting;
|
2015-08-28 21:17:09 +02:00
|
|
|
import net.minecraft.util.IIcon;
|
2015-12-22 16:08:53 +01:00
|
|
|
import net.minecraft.util.MovingObjectPosition;
|
2015-08-28 21:17:09 +02:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
2015-11-15 19:02:18 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
2015-12-22 16:08:53 +01:00
|
|
|
public class ItemBooklet extends ItemBase implements IHudDisplay{
|
|
|
|
|
2015-12-22 16:14:05 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2015-12-22 16:08:53 +01:00
|
|
|
public static EntrySet forcedEntry;
|
2015-08-28 21:17:09 +02:00
|
|
|
|
2015-12-03 20:15:07 +01:00
|
|
|
public ItemBooklet(String name){
|
|
|
|
super(name);
|
2015-10-17 16:03:26 +02:00
|
|
|
this.setMaxStackSize(16);
|
2015-08-28 21:17:09 +02:00
|
|
|
this.setMaxDamage(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-10-03 10:19:40 +02:00
|
|
|
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player){
|
|
|
|
player.openGui(ActuallyAdditions.instance, GuiHandler.GuiTypes.BOOK.ordinal(), world, (int)player.posX, (int)player.posY, (int)player.posZ);
|
2015-11-13 20:34:57 +01:00
|
|
|
|
|
|
|
if(!world.isRemote){
|
|
|
|
player.triggerAchievement(TheAchievements.OPEN_BOOKLET.ach);
|
|
|
|
}
|
2015-10-03 10:19:40 +02:00
|
|
|
return stack;
|
2015-08-28 21:17:09 +02:00
|
|
|
}
|
|
|
|
|
2015-12-22 16:08:53 +01:00
|
|
|
@Override
|
|
|
|
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ){
|
|
|
|
if(player.isSneaking()){
|
|
|
|
Block block = world.getBlock(x, y, z);
|
|
|
|
ItemStack blockStack = new ItemStack(block, 1, world.getBlockMetadata(x, y, z));
|
|
|
|
if(blockStack != null){
|
|
|
|
BookletPage page = BookletUtils.getFirstPageForStack(blockStack);
|
|
|
|
if(page != null){
|
|
|
|
if(world.isRemote){
|
|
|
|
forcedEntry = new EntrySet(page, page.getChapter(), page.getChapter().entry, InitBooklet.entries.indexOf(page.getChapter().entry)/GuiBooklet.CHAPTER_BUTTONS_AMOUNT+1);
|
|
|
|
}
|
|
|
|
this.onItemRightClick(stack, world, player);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-01 19:48:09 +01:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Override
|
|
|
|
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool){
|
2015-12-03 20:15:07 +01:00
|
|
|
list.add(StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+"."+this.getBaseName()+".desc"));
|
2015-12-01 19:48:09 +01:00
|
|
|
}
|
|
|
|
|
2015-08-28 21:17:09 +02:00
|
|
|
@Override
|
2015-10-03 10:19:40 +02:00
|
|
|
public EnumRarity getRarity(ItemStack stack){
|
|
|
|
return EnumRarity.epic;
|
2015-08-28 21:17:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public void registerIcons(IIconRegister iconReg){
|
2015-12-03 20:15:07 +01:00
|
|
|
this.itemIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER+":"+this.getBaseName());
|
2015-08-28 21:17:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-10-03 10:19:40 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public IIcon getIcon(ItemStack stack, int pass){
|
|
|
|
return this.itemIcon;
|
2015-08-28 21:17:09 +02:00
|
|
|
}
|
2015-12-22 16:08:53 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void displayHud(Minecraft minecraft, EntityPlayer player, ItemStack stack, MovingObjectPosition posHit, Profiler profiler, ScaledResolution resolution){
|
|
|
|
if(posHit != null){
|
|
|
|
Block block = minecraft.theWorld.getBlock(posHit.blockX, posHit.blockY, posHit.blockZ);
|
|
|
|
if(block != null && !block.isAir(minecraft.theWorld, posHit.blockX, posHit.blockY, posHit.blockZ)){
|
|
|
|
ItemStack blockStack = new ItemStack(block, 1, minecraft.theWorld.getBlockMetadata(posHit.blockX, posHit.blockY, posHit.blockZ));
|
|
|
|
if(blockStack != null){
|
2015-12-22 20:43:41 +01:00
|
|
|
int height = resolution.getScaledHeight()/5*3;
|
2015-12-22 16:08:53 +01:00
|
|
|
if(player.isSneaking()){
|
|
|
|
BookletPage page = BookletUtils.getFirstPageForStack(blockStack);
|
|
|
|
if(page != null){
|
|
|
|
String strg1 = page.getChapter().getLocalizedName();
|
|
|
|
String strg2 = "Page "+page.getID();
|
|
|
|
String strg3 = "Right-Click to open...";
|
|
|
|
|
2015-12-22 20:43:41 +01:00
|
|
|
AssetUtil.renderStackToGui(page.getChapter().displayStack != null ? page.getChapter().displayStack : new ItemStack(InitItems.itemBooklet), resolution.getScaledWidth()/2-10, height+41, 1F);
|
|
|
|
minecraft.fontRenderer.drawStringWithShadow(EnumChatFormatting.YELLOW+""+EnumChatFormatting.ITALIC+strg1, resolution.getScaledWidth()/2-minecraft.fontRenderer.getStringWidth(strg1)/2, height+20, StringUtil.DECIMAL_COLOR_WHITE);
|
|
|
|
minecraft.fontRenderer.drawStringWithShadow(EnumChatFormatting.YELLOW+""+EnumChatFormatting.ITALIC+strg2, resolution.getScaledWidth()/2-minecraft.fontRenderer.getStringWidth(strg2)/2, height+30, StringUtil.DECIMAL_COLOR_WHITE);
|
|
|
|
minecraft.fontRenderer.drawStringWithShadow(EnumChatFormatting.GOLD+strg3, resolution.getScaledWidth()/2-minecraft.fontRenderer.getStringWidth(strg3)/2, height+60, StringUtil.DECIMAL_COLOR_WHITE);
|
2015-12-22 16:08:53 +01:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
String strg = EnumChatFormatting.DARK_RED+"No Info available! Sorry :(";
|
2015-12-22 20:43:41 +01:00
|
|
|
minecraft.fontRenderer.drawStringWithShadow(strg, resolution.getScaledWidth()/2-minecraft.fontRenderer.getStringWidth(strg)/2, height+60, StringUtil.DECIMAL_COLOR_WHITE);
|
2015-12-22 16:08:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
String strg = EnumChatFormatting.DARK_GREEN+""+EnumChatFormatting.ITALIC+"Sneak!";
|
2015-12-22 20:43:41 +01:00
|
|
|
minecraft.fontRenderer.drawStringWithShadow(strg, resolution.getScaledWidth()/2-minecraft.fontRenderer.getStringWidth(strg)/2, height+60, StringUtil.DECIMAL_COLOR_WHITE);
|
2015-12-22 16:08:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-28 21:17:09 +02:00
|
|
|
}
|