mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-12-23 19:59:24 +01:00
Fixed tooltip bugging sometimes & giving a player the book on crafting
This commit is contained in:
parent
acc36b6e3e
commit
657cde463f
4 changed files with 95 additions and 32 deletions
|
@ -15,12 +15,12 @@ import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||||
import ellpeck.actuallyadditions.achievement.InitAchievements;
|
import ellpeck.actuallyadditions.achievement.InitAchievements;
|
||||||
import ellpeck.actuallyadditions.achievement.TheAchievements;
|
import ellpeck.actuallyadditions.achievement.TheAchievements;
|
||||||
import ellpeck.actuallyadditions.items.InitItems;
|
import ellpeck.actuallyadditions.items.InitItems;
|
||||||
import ellpeck.actuallyadditions.network.PacketGiveBook;
|
import ellpeck.actuallyadditions.network.PacketCheckBook;
|
||||||
import ellpeck.actuallyadditions.network.PacketHandler;
|
import ellpeck.actuallyadditions.network.PacketHandler;
|
||||||
import ellpeck.actuallyadditions.util.INameableItem;
|
import ellpeck.actuallyadditions.util.INameableItem;
|
||||||
import ellpeck.actuallyadditions.util.PersistantVariables;
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
public class CraftEvent{
|
public class CraftEvent{
|
||||||
|
@ -29,10 +29,9 @@ public class CraftEvent{
|
||||||
public void onCraftedEvent(PlayerEvent.ItemCraftedEvent event){
|
public void onCraftedEvent(PlayerEvent.ItemCraftedEvent event){
|
||||||
checkAchievements(event.crafting, event.player, InitAchievements.CRAFTING_ACH);
|
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(!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")){
|
if(event.player instanceof EntityPlayerMP){
|
||||||
PacketHandler.theNetwork.sendToServer(new PacketGiveBook(event.player));
|
PacketHandler.theNetwork.sendTo(new PacketCheckBook(event.player), (EntityPlayerMP)event.player);
|
||||||
PersistantVariables.setBoolean("BookGotten", true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,7 @@ public class TooltipEvent{
|
||||||
GuiScreen screen = Minecraft.getMinecraft().currentScreen;
|
GuiScreen screen = Minecraft.getMinecraft().currentScreen;
|
||||||
if(screen != null && !(screen instanceof GuiBooklet) && screen instanceof GuiContainer){
|
if(screen != null && !(screen instanceof GuiBooklet) && screen instanceof GuiContainer){
|
||||||
GuiContainer gui = (GuiContainer)screen;
|
GuiContainer gui = (GuiContainer)screen;
|
||||||
|
if(gui.inventorySlots != null && gui.inventorySlots.inventorySlots != null && !gui.inventorySlots.inventorySlots.isEmpty()){
|
||||||
for(Object o : gui.inventorySlots.inventorySlots){
|
for(Object o : gui.inventorySlots.inventorySlots){
|
||||||
if(o instanceof Slot){
|
if(o instanceof Slot){
|
||||||
Slot slot = (Slot)o;
|
Slot slot = (Slot)o;
|
||||||
|
@ -85,6 +86,7 @@ public class TooltipEvent{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Advanced Item Info
|
//Advanced Item Info
|
||||||
if(event.itemStack.getItem() != null){
|
if(event.itemStack.getItem() != null){
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -31,5 +31,6 @@ public class PacketHandler{
|
||||||
theNetwork.registerMessage(PacketGuiNumber.Handler.class, PacketGuiNumber.class, 2, Side.SERVER);
|
theNetwork.registerMessage(PacketGuiNumber.Handler.class, PacketGuiNumber.class, 2, Side.SERVER);
|
||||||
theNetwork.registerMessage(PacketGuiString.Handler.class, PacketGuiString.class, 3, Side.SERVER);
|
theNetwork.registerMessage(PacketGuiString.Handler.class, PacketGuiString.class, 3, Side.SERVER);
|
||||||
theNetwork.registerMessage(PacketGiveBook.Handler.class, PacketGiveBook.class, 4, Side.SERVER);
|
theNetwork.registerMessage(PacketGiveBook.Handler.class, PacketGiveBook.class, 4, Side.SERVER);
|
||||||
|
theNetwork.registerMessage(PacketCheckBook.Handler.class, PacketCheckBook.class, 5, Side.CLIENT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue