Sneak-Right-Clicking with a book on a block from ActAdd will now open its page

This commit is contained in:
Ellpeck 2015-12-22 16:08:53 +01:00
parent 1806cd1820
commit 0b70946487
3 changed files with 91 additions and 6 deletions

View file

@ -17,6 +17,7 @@ import ellpeck.actuallyadditions.booklet.button.IndexButton;
import ellpeck.actuallyadditions.booklet.button.TexturedButton;
import ellpeck.actuallyadditions.booklet.entry.BookletEntryAllSearch;
import ellpeck.actuallyadditions.config.GuiConfiguration;
import ellpeck.actuallyadditions.items.ItemBooklet;
import ellpeck.actuallyadditions.proxy.ClientProxy;
import ellpeck.actuallyadditions.update.UpdateChecker;
import ellpeck.actuallyadditions.util.AssetUtil;
@ -306,6 +307,8 @@ public class GuiBooklet extends GuiScreen{
this.currentEntrySet.removeEntry();
if(ItemBooklet.forcedEntry == null){
//Open last entry or introductory entry
if(this.tryOpenMainPage && !PersistentClientData.getBoolean("BookAlreadyOpened")){
BookletUtils.openIndexEntry(this, InitBooklet.chapterIntro.entry, 1, true);
BookletUtils.openChapter(this, InitBooklet.chapterIntro, null);
@ -316,6 +319,13 @@ public class GuiBooklet extends GuiScreen{
PersistentClientData.openLastBookPage(this);
}
}
else{
//Open forced entry
BookletUtils.openIndexEntry(this, ItemBooklet.forcedEntry.entry, ItemBooklet.forcedEntry.pageInIndex, true);
BookletUtils.openChapter(this, ItemBooklet.forcedEntry.chapter, ItemBooklet.forcedEntry.page);
ItemBooklet.forcedEntry = null;
}
}
@Override
//For scrolling through pages

View file

@ -42,6 +42,14 @@ public class HudEvent{
profiler.startSection(ModUtil.MOD_ID+"Hud");
if(stack != null){
if(stack.getItem() instanceof IHudDisplay){
profiler.startSection("ItemHudDisplay");
((IHudDisplay)stack.getItem()).displayHud(minecraft, player, stack, posHit, profiler, event.resolution);
profiler.endSection();
}
}
if(posHit != null){
Block blockHit = minecraft.theWorld.getBlock(posHit.blockX, posHit.blockY, posHit.blockZ);
TileEntity tileHit = minecraft.theWorld.getTileEntity(posHit.blockX, posHit.blockY, posHit.blockZ);

View file

@ -14,20 +14,35 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ellpeck.actuallyadditions.ActuallyAdditions;
import ellpeck.actuallyadditions.achievement.TheAchievements;
import ellpeck.actuallyadditions.blocks.IHudDisplay;
import ellpeck.actuallyadditions.booklet.BookletUtils;
import ellpeck.actuallyadditions.booklet.EntrySet;
import ellpeck.actuallyadditions.booklet.GuiBooklet;
import ellpeck.actuallyadditions.booklet.InitBooklet;
import ellpeck.actuallyadditions.booklet.page.BookletPage;
import ellpeck.actuallyadditions.inventory.GuiHandler;
import ellpeck.actuallyadditions.items.base.ItemBase;
import ellpeck.actuallyadditions.util.AssetUtil;
import ellpeck.actuallyadditions.util.ModUtil;
import ellpeck.actuallyadditions.util.StringUtil;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.texture.IIconRegister;
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.EnumChatFormatting;
import net.minecraft.util.IIcon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import java.util.List;
public class ItemBooklet extends ItemBase{
public class ItemBooklet extends ItemBase implements IHudDisplay{
public static EntrySet forcedEntry;
public ItemBooklet(String name){
super(name);
@ -45,6 +60,25 @@ public class ItemBooklet extends ItemBase{
return stack;
}
@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;
}
@SuppressWarnings("unchecked")
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool){
@ -67,4 +101,37 @@ public class ItemBooklet extends ItemBase{
public IIcon getIcon(ItemStack stack, int pass){
return this.itemIcon;
}
@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){
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...";
AssetUtil.renderStackToGui(page.getChapter().displayStack != null ? page.getChapter().displayStack : new ItemStack(InitItems.itemBooklet), resolution.getScaledWidth()/2-10, resolution.getScaledHeight()-86, 1F);
minecraft.fontRenderer.drawStringWithShadow(EnumChatFormatting.YELLOW+""+EnumChatFormatting.ITALIC+strg1, resolution.getScaledWidth()/2-minecraft.fontRenderer.getStringWidth(strg1)/2, resolution.getScaledHeight()-70, StringUtil.DECIMAL_COLOR_WHITE);
minecraft.fontRenderer.drawStringWithShadow(EnumChatFormatting.YELLOW+""+EnumChatFormatting.ITALIC+strg2, resolution.getScaledWidth()/2-minecraft.fontRenderer.getStringWidth(strg2)/2, resolution.getScaledHeight()-60, StringUtil.DECIMAL_COLOR_WHITE);
minecraft.fontRenderer.drawStringWithShadow(EnumChatFormatting.GOLD+strg3, resolution.getScaledWidth()/2-minecraft.fontRenderer.getStringWidth(strg3)/2, resolution.getScaledHeight()-95, StringUtil.DECIMAL_COLOR_WHITE);
}
else{
String strg = EnumChatFormatting.DARK_RED+"No Info available! Sorry :(";
minecraft.fontRenderer.drawStringWithShadow(strg, resolution.getScaledWidth()/2-minecraft.fontRenderer.getStringWidth(strg)/2, resolution.getScaledHeight()-95, StringUtil.DECIMAL_COLOR_WHITE);
}
}
else{
String strg = EnumChatFormatting.DARK_GREEN+""+EnumChatFormatting.ITALIC+"Sneak!";
minecraft.fontRenderer.drawStringWithShadow(strg, resolution.getScaledWidth()/2-minecraft.fontRenderer.getStringWidth(strg)/2, resolution.getScaledHeight()-95, StringUtil.DECIMAL_COLOR_WHITE);
}
}
}
}
}
}