2015-08-29 14:33:25 +02:00
|
|
|
/*
|
2016-05-16 22:52:27 +02:00
|
|
|
* This file ("ItemBooklet.java") is part of the Actually Additions mod for Minecraft.
|
2015-08-29 14:33:25 +02:00
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-05-16 22:52:27 +02:00
|
|
|
* http://ellpeck.de/actaddlicense
|
2015-08-29 14:33:25 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-05-16 22:54:42 +02:00
|
|
|
* © 2015-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;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.achievement.TheAchievements;
|
2016-01-17 12:17:24 +01:00
|
|
|
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;
|
2016-06-01 00:39:35 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.booklet.entry.EntrySet;
|
2016-01-05 04:47:35 +01:00
|
|
|
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;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
|
2015-12-22 16:08:53 +01:00
|
|
|
import net.minecraft.block.Block;
|
2016-07-04 20:15:41 +02:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2015-12-22 16:08:53 +01:00
|
|
|
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;
|
2015-12-22 16:08:53 +01:00
|
|
|
import net.minecraft.profiler.Profiler;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.ActionResult;
|
|
|
|
import net.minecraft.util.EnumActionResult;
|
2016-01-07 23:42:42 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.EnumHand;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.math.RayTraceResult;
|
|
|
|
import net.minecraft.util.text.TextFormatting;
|
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
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-05-29 23:49:35 +02:00
|
|
|
|
2015-12-22 16:08:53 +01:00
|
|
|
@Override
|
2016-03-18 23:47:22 +01:00
|
|
|
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing face, float hitX, float hitY, float hitZ){
|
2015-12-22 16:08:53 +01:00
|
|
|
if(player.isSneaking()){
|
2016-07-04 20:15:41 +02:00
|
|
|
IBlockState state = world.getBlockState(pos);
|
|
|
|
Block block = state.getBlock();
|
|
|
|
ItemStack blockStack = new ItemStack(block, 1, block.getMetaFromState(state));
|
2016-05-16 22:52:27 +02:00
|
|
|
BookletPage page = BookletUtils.getFirstPageForStack(blockStack);
|
|
|
|
if(page != null){
|
|
|
|
if(world.isRemote){
|
2016-05-19 20:05:12 +02:00
|
|
|
forcedEntry = new EntrySet(page, page.getChapter(), page.getChapter().getEntry(), ActuallyAdditionsAPI.BOOKLET_ENTRIES.indexOf(page.getChapter().getEntry())/GuiBooklet.CHAPTER_BUTTONS_AMOUNT+1);
|
2015-12-22 16:08:53 +01:00
|
|
|
}
|
2016-05-16 22:52:27 +02:00
|
|
|
this.onItemRightClick(stack, world, player, hand);
|
|
|
|
return EnumActionResult.SUCCESS;
|
2015-12-22 16:08:53 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-18 23:47:22 +01:00
|
|
|
return EnumActionResult.FAIL;
|
2015-12-22 16:08:53 +01:00
|
|
|
}
|
|
|
|
|
2016-05-29 23:49:35 +02:00
|
|
|
|
2016-02-01 17:49:55 +01:00
|
|
|
@Override
|
2016-05-29 23:49:35 +02:00
|
|
|
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand){
|
2016-02-01 17:49:55 +01:00
|
|
|
player.openGui(ActuallyAdditions.instance, GuiHandler.GuiTypes.BOOK.ordinal(), world, (int)player.posX, (int)player.posY, (int)player.posZ);
|
|
|
|
|
|
|
|
if(!world.isRemote){
|
2016-06-17 23:37:01 +02:00
|
|
|
player.addStat(TheAchievements.OPEN_BOOKLET.chieve);
|
2016-02-01 17:49:55 +01:00
|
|
|
}
|
2016-03-19 15:10:20 +01:00
|
|
|
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
|
2016-02-01 17:49:55 +01:00
|
|
|
}
|
|
|
|
|
2015-12-01 19:48:09 +01:00
|
|
|
@Override
|
|
|
|
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool){
|
2016-04-20 21:39:03 +02:00
|
|
|
list.add(StringUtil.localize("tooltip."+ModUtil.MOD_ID+"."+this.getBaseName()+".desc"));
|
2015-12-01 19:48:09 +01:00
|
|
|
}
|
|
|
|
|
2016-05-29 23:49:35 +02:00
|
|
|
|
2015-08-28 21:17:09 +02:00
|
|
|
@Override
|
2015-10-03 10:19:40 +02:00
|
|
|
public EnumRarity getRarity(ItemStack stack){
|
2016-01-07 23:42:42 +01:00
|
|
|
return EnumRarity.EPIC;
|
2015-08-28 21:17:09 +02:00
|
|
|
}
|
2015-12-22 16:08:53 +01:00
|
|
|
|
|
|
|
@Override
|
2016-03-18 23:47:22 +01:00
|
|
|
public void displayHud(Minecraft minecraft, EntityPlayer player, ItemStack stack, RayTraceResult posHit, Profiler profiler, ScaledResolution resolution){
|
2015-12-22 16:08:53 +01:00
|
|
|
if(posHit != null){
|
2016-07-04 20:15:41 +02:00
|
|
|
IBlockState state = minecraft.theWorld.getBlockState(posHit.getBlockPos());
|
|
|
|
Block block = state.getBlock();
|
2016-03-18 23:47:22 +01:00
|
|
|
if(block != null && !block.isAir(minecraft.theWorld.getBlockState(posHit.getBlockPos()), minecraft.theWorld, posHit.getBlockPos())){
|
2016-07-04 20:15:41 +02:00
|
|
|
ItemStack blockStack = new ItemStack(block, 1, block.getMetaFromState(state));
|
2016-05-16 22:52:27 +02:00
|
|
|
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...";
|
2015-12-22 16:08:53 +01:00
|
|
|
|
2016-05-16 22:52:27 +02:00
|
|
|
AssetUtil.renderStackToGui(page.getChapter().getDisplayItemStack() != null ? page.getChapter().getDisplayItemStack() : new ItemStack(InitItems.itemBooklet), resolution.getScaledWidth()/2-10, height+41, 1F);
|
|
|
|
minecraft.fontRendererObj.drawStringWithShadow(TextFormatting.YELLOW+""+TextFormatting.ITALIC+strg1, resolution.getScaledWidth()/2-minecraft.fontRendererObj.getStringWidth(strg1)/2, height+20, StringUtil.DECIMAL_COLOR_WHITE);
|
|
|
|
minecraft.fontRendererObj.drawStringWithShadow(TextFormatting.YELLOW+""+TextFormatting.ITALIC+strg2, resolution.getScaledWidth()/2-minecraft.fontRendererObj.getStringWidth(strg2)/2, height+30, StringUtil.DECIMAL_COLOR_WHITE);
|
|
|
|
minecraft.fontRendererObj.drawStringWithShadow(TextFormatting.GOLD+strg3, resolution.getScaledWidth()/2-minecraft.fontRendererObj.getStringWidth(strg3)/2, height+60, StringUtil.DECIMAL_COLOR_WHITE);
|
2015-12-22 16:08:53 +01:00
|
|
|
}
|
|
|
|
else{
|
2016-05-16 22:52:27 +02:00
|
|
|
String strg = TextFormatting.DARK_RED+"No Info available! Sorry :(";
|
2016-01-07 23:42:42 +01:00
|
|
|
minecraft.fontRendererObj.drawStringWithShadow(strg, resolution.getScaledWidth()/2-minecraft.fontRendererObj.getStringWidth(strg)/2, height+60, StringUtil.DECIMAL_COLOR_WHITE);
|
2015-12-22 16:08:53 +01:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 22:52:27 +02:00
|
|
|
else{
|
|
|
|
String strg = TextFormatting.DARK_GREEN+""+TextFormatting.ITALIC+"Sneak!";
|
|
|
|
minecraft.fontRendererObj.drawStringWithShadow(strg, resolution.getScaledWidth()/2-minecraft.fontRendererObj.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
|
|
|
}
|