Fixed tooltip bugging sometimes & giving a player the book on crafting

This commit is contained in:
Ellpeck 2015-09-20 18:53:32 +02:00
parent acc36b6e3e
commit 657cde463f
4 changed files with 95 additions and 32 deletions

View file

@ -15,12 +15,12 @@ import cpw.mods.fml.common.gameevent.PlayerEvent;
import ellpeck.actuallyadditions.achievement.InitAchievements;
import ellpeck.actuallyadditions.achievement.TheAchievements;
import ellpeck.actuallyadditions.items.InitItems;
import ellpeck.actuallyadditions.network.PacketGiveBook;
import ellpeck.actuallyadditions.network.PacketCheckBook;
import ellpeck.actuallyadditions.network.PacketHandler;
import ellpeck.actuallyadditions.util.INameableItem;
import ellpeck.actuallyadditions.util.PersistantVariables;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
public class CraftEvent{
@ -29,10 +29,9 @@ public class CraftEvent{
public void onCraftedEvent(PlayerEvent.ItemCraftedEvent event){
checkAchievements(event.crafting, event.player, InitAchievements.CRAFTING_ACH);
if(event.player.worldObj.isRemote && event.crafting.getItem() != InitItems.itemLexicon && (event.crafting.getItem() instanceof INameableItem || Block.getBlockFromItem(event.crafting.getItem()) instanceof INameableItem)){
if(!PersistantVariables.getBoolean("BookGotten")){
PacketHandler.theNetwork.sendToServer(new PacketGiveBook(event.player));
PersistantVariables.setBoolean("BookGotten", true);
if(!event.player.worldObj.isRemote && event.crafting.getItem() != InitItems.itemLexicon && (event.crafting.getItem() instanceof INameableItem || Block.getBlockFromItem(event.crafting.getItem()) instanceof INameableItem)){
if(event.player instanceof EntityPlayerMP){
PacketHandler.theNetwork.sendTo(new PacketCheckBook(event.player), (EntityPlayerMP)event.player);
}
}
}

View file

@ -47,6 +47,7 @@ public class TooltipEvent{
GuiScreen screen = Minecraft.getMinecraft().currentScreen;
if(screen != null && !(screen instanceof GuiBooklet) && screen instanceof GuiContainer){
GuiContainer gui = (GuiContainer)screen;
if(gui.inventorySlots != null && gui.inventorySlots.inventorySlots != null && !gui.inventorySlots.inventorySlots.isEmpty()){
for(Object o : gui.inventorySlots.inventorySlots){
if(o instanceof Slot){
Slot slot = (Slot)o;
@ -85,6 +86,7 @@ public class TooltipEvent{
}
}
}
}
//Advanced Item Info
if(event.itemStack.getItem() != null){

View file

@ -0,0 +1,61 @@
/*
* This file ("PacketCheckBook.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 Ellpeck
*/
package ellpeck.actuallyadditions.network;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ellpeck.actuallyadditions.util.PersistantVariables;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
public class PacketCheckBook implements IMessage{
@SuppressWarnings("unused")
public PacketCheckBook(){
}
private EntityPlayer player;
public PacketCheckBook(EntityPlayer player){
this.player = player;
}
@Override
public void fromBytes(ByteBuf buf){
World world = DimensionManager.getWorld(buf.readInt());
this.player = (EntityPlayer)world.getEntityByID(buf.readInt());
}
@Override
public void toBytes(ByteBuf buf){
buf.writeInt(this.player.worldObj.provider.dimensionId);
buf.writeInt(this.player.getEntityId());
}
public static class Handler implements IMessageHandler<PacketCheckBook, IMessage>{
@Override
@SideOnly(Side.CLIENT)
public IMessage onMessage(PacketCheckBook message, MessageContext ctx){
if(!PersistantVariables.getBoolean("BookGotten")){
PacketHandler.theNetwork.sendToServer(new PacketGiveBook(message.player));
PersistantVariables.setBoolean("BookGotten", true);
}
return null;
}
}
}

View file

@ -31,5 +31,6 @@ public class PacketHandler{
theNetwork.registerMessage(PacketGuiNumber.Handler.class, PacketGuiNumber.class, 2, Side.SERVER);
theNetwork.registerMessage(PacketGuiString.Handler.class, PacketGuiString.class, 3, Side.SERVER);
theNetwork.registerMessage(PacketGiveBook.Handler.class, PacketGiveBook.class, 4, Side.SERVER);
theNetwork.registerMessage(PacketCheckBook.Handler.class, PacketCheckBook.class, 5, Side.CLIENT);
}
}