ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemBooklet.java

129 lines
6.5 KiB
Java
Raw Normal View History

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
2016-01-03 16:05:51 +01:00
* http://ellpeck.de/actaddlicense/
2015-08-29 14:33:25 +02:00
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2016-01-03 16:05:51 +01:00
* © 2016 Ellpeck
2015-08-29 14:33:25 +02:00
*/
2016-01-05 04:47:35 +01:00
package de.ellpeck.actuallyadditions.mod.items;
2015-08-28 21:17:09 +02:00
2016-01-05 14:57:50 +01:00
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.booklet.BookletPage;
import de.ellpeck.actuallyadditions.api.internal.EntrySet;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.achievement.TheAchievements;
import de.ellpeck.actuallyadditions.mod.blocks.IHudDisplay;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.booklet.BookletUtils;
import de.ellpeck.actuallyadditions.mod.booklet.GuiBooklet;
import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler;
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
2016-01-08 13:31:58 +01:00
import de.ellpeck.actuallyadditions.mod.util.PosUtil;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
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.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.profiler.Profiler;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.MovingObjectPosition;
2015-08-28 21:17:09 +02:00
import net.minecraft.world.World;
2016-01-07 18:20:59 +01:00
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
2015-08-28 21:17:09 +02:00
import java.util.List;
public class ItemBooklet extends ItemBase implements IHudDisplay{
2015-12-22 16:14:05 +01:00
@SideOnly(Side.CLIENT)
public static EntrySet forcedEntry;
2015-08-28 21:17:09 +02: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
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing face, float hitX, float hitY, float hitZ){
if(player.isSneaking()){
2016-01-08 13:31:58 +01:00
Block block = PosUtil.getBlock(pos, world);
ItemStack blockStack = new ItemStack(block, 1, PosUtil.getMetadata(pos, world));
if(blockStack != null){
BookletPage page = BookletUtils.getFirstPageForStack(blockStack);
if(page != null){
if(world.isRemote){
2016-01-05 14:57:50 +01:00
forcedEntry = new EntrySet(page, page.getChapter(), page.getChapter().getEntry(), ActuallyAdditionsAPI.bookletEntries.indexOf(page.getChapter().getEntry())/GuiBooklet.CHAPTER_BUTTONS_AMOUNT+1);
}
this.onItemRightClick(stack, world, player);
return true;
}
}
}
return false;
}
2016-02-01 17:49:55 +01:00
@Override
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);
if(!world.isRemote){
player.triggerAchievement(TheAchievements.OPEN_BOOKLET.ach);
}
return stack;
}
2015-12-01 19:48:09 +01:00
@SuppressWarnings("unchecked")
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool){
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
public void displayHud(Minecraft minecraft, EntityPlayer player, ItemStack stack, MovingObjectPosition posHit, Profiler profiler, ScaledResolution resolution){
if(posHit != null){
2016-01-08 13:31:58 +01:00
Block block = PosUtil.getBlock(posHit.getBlockPos(), minecraft.theWorld);
if(block != null && !block.isAir(minecraft.theWorld, posHit.getBlockPos())){
2016-01-08 13:31:58 +01:00
ItemStack blockStack = new ItemStack(block, 1, PosUtil.getMetadata(posHit.getBlockPos(), minecraft.theWorld));
if(blockStack != null){
int height = resolution.getScaledHeight()/5*3;
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...";
2016-01-05 14:57:50 +01:00
AssetUtil.renderStackToGui(page.getChapter().getDisplayItemStack() != null ? page.getChapter().getDisplayItemStack() : new ItemStack(InitItems.itemBooklet), resolution.getScaledWidth()/2-10, height+41, 1F);
minecraft.fontRendererObj.drawStringWithShadow(EnumChatFormatting.YELLOW+""+EnumChatFormatting.ITALIC+strg1, resolution.getScaledWidth()/2-minecraft.fontRendererObj.getStringWidth(strg1)/2, height+20, StringUtil.DECIMAL_COLOR_WHITE);
minecraft.fontRendererObj.drawStringWithShadow(EnumChatFormatting.YELLOW+""+EnumChatFormatting.ITALIC+strg2, resolution.getScaledWidth()/2-minecraft.fontRendererObj.getStringWidth(strg2)/2, height+30, StringUtil.DECIMAL_COLOR_WHITE);
minecraft.fontRendererObj.drawStringWithShadow(EnumChatFormatting.GOLD+strg3, resolution.getScaledWidth()/2-minecraft.fontRendererObj.getStringWidth(strg3)/2, height+60, StringUtil.DECIMAL_COLOR_WHITE);
}
else{
String strg = EnumChatFormatting.DARK_RED+"No Info available! Sorry :(";
minecraft.fontRendererObj.drawStringWithShadow(strg, resolution.getScaledWidth()/2-minecraft.fontRendererObj.getStringWidth(strg)/2, height+60, StringUtil.DECIMAL_COLOR_WHITE);
}
}
else{
String strg = EnumChatFormatting.DARK_GREEN+""+EnumChatFormatting.ITALIC+"Sneak!";
minecraft.fontRendererObj.drawStringWithShadow(strg, resolution.getScaledWidth()/2-minecraft.fontRendererObj.getStringWidth(strg)/2, height+60, StringUtil.DECIMAL_COLOR_WHITE);
}
}
}
}
}
2015-08-28 21:17:09 +02:00
}