Added ExtendedPlayerCapabilities to save if the player has gotten the book already, because the old method of saving it on the client side was stupid and didn't work like it should have anyways

This commit is contained in:
Ellpeck 2015-09-27 15:31:43 +02:00
parent 603ece50f2
commit d4e425fbd7
14 changed files with 116 additions and 142 deletions

View file

@ -29,6 +29,7 @@ import ellpeck.actuallyadditions.inventory.GuiHandler;
import ellpeck.actuallyadditions.items.InitForeignPaxels;
import ellpeck.actuallyadditions.items.InitItems;
import ellpeck.actuallyadditions.items.ItemCoffee;
import ellpeck.actuallyadditions.items.tools.table.InitToolTableTools;
import ellpeck.actuallyadditions.material.InitArmorMaterials;
import ellpeck.actuallyadditions.material.InitToolMaterials;
import ellpeck.actuallyadditions.misc.DispenserHandlerEmptyBucket;
@ -98,7 +99,7 @@ public class ActuallyAdditions{
HairyBallHandler.init();
TreasureChestHandler.init();
InitForeignPaxels.init();
//InitToolTableTools.init();
InitToolTableTools.init();
proxy.postInit(event);
ModUtil.LOGGER.info("PostInitialization Finished.");

View file

@ -93,13 +93,13 @@ public class InitBlocks{
public static Block blockSmileyCloud;
//public static Block blockToolTable;
public static Block blockToolTable;
public static void init(){
ModUtil.LOGGER.info("Initializing Blocks...");
//blockToolTable = new BlockToolTable();
//BlockUtil.register(blockToolTable);
blockToolTable = new BlockToolTable();
BlockUtil.register(blockToolTable);
blockSmileyCloud = new BlockSmileyCloud();
BlockUtil.register(blockSmileyCloud);

View file

@ -15,7 +15,11 @@ import cpw.mods.fml.relauncher.SideOnly;
import ellpeck.actuallyadditions.booklet.page.BookletPage;
import ellpeck.actuallyadditions.config.GuiConfiguration;
import ellpeck.actuallyadditions.update.UpdateChecker;
import ellpeck.actuallyadditions.util.*;
import ellpeck.actuallyadditions.util.AssetUtil;
import ellpeck.actuallyadditions.util.KeyUtil;
import ellpeck.actuallyadditions.util.ModUtil;
import ellpeck.actuallyadditions.util.StringUtil;
import ellpeck.actuallyadditions.util.playerdata.PersistantClientData;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
@ -123,7 +127,7 @@ public class GuiBooklet extends GuiScreen{
@Override
public void onGuiClosed(){
PersistantVariables.saveBookPage(this.currentIndexEntry, this.currentChapter, this.currentPage, this.pageOpenInIndex);
PersistantClientData.saveBookPage(this.currentIndexEntry, this.currentChapter, this.currentPage, this.pageOpenInIndex);
}
@Override
@ -167,14 +171,14 @@ public class GuiBooklet extends GuiScreen{
this.currentChapter = null;
this.currentIndexEntry = null;
if(!PersistantVariables.getBoolean("BookAlreadyOpened")){
if(!PersistantClientData.getBoolean("BookAlreadyOpened")){
this.openIndexEntry(InitBooklet.chapterIntro.entry, 1, true);
this.openChapter(InitBooklet.chapterIntro, null);
PersistantVariables.setBoolean("BookAlreadyOpened", true);
PersistantClientData.setBoolean("BookAlreadyOpened", true);
}
else{
PersistantVariables.openLastBookPage(this);
PersistantClientData.openLastBookPage(this);
}
}

View file

@ -29,8 +29,6 @@ public enum ConfigBoolValues{
PEARL_SHARD_DROP("Ender Pearl Shard", ConfigCategories.MOB_DROPS, true, "If the Ender Pearl Shard drops from Mobs"),
EMERALD_SHARD_CROP("Emerald Shard", ConfigCategories.MOB_DROPS, true, "If the Emerald Shard drops from Mobs"),
DO_WAILA_INFO("Waila Display Info", ConfigCategories.OTHER, true, "If the Shift Description should display in Waila too"),
DO_UPDATE_CHECK("Do Update Check", ConfigCategories.OTHER, true, "If Actually Additions should check for an Update on joining a World"),
DO_CRUSHER_SPAM("Crusher Debug", ConfigCategories.OTHER, false, "Print out Crusher Recipe Initializing Debug"),
DO_CAT_DROPS("Do Cat Drops", ConfigCategories.OTHER, true, "If Cats drop Hairy Balls on Occasion"),
@ -58,7 +56,7 @@ public enum ConfigBoolValues{
NEED_BOOKLET_FOR_KEYBIND_INFO("Booklet Quick Opening", ConfigCategories.TOOL_VALUES, true, "If the booklet should have to be inside the player's inventory to be able to hover over an item and press a keybind to quickly access the item's page"),
SHOW_NEED_BOOKLET_FOR_KEYBIND_INFO("Booklet Quick Opening Info", ConfigCategories.TOOL_VALUES, true, "If the 'Press key for more information'-button should show when the item has a page in the booklet"),
GIVE_BOOKLET_ON_FIRST_CRAFT("Give Booklet on First Craft", ConfigCategories.OTHER, true, "If the booklet should be given to the player when he first crafts something from the Mod (Reduces Packet Traffic a bit when turned off!)");
GIVE_BOOKLET_ON_FIRST_CRAFT("Give Booklet on First Craft", ConfigCategories.OTHER, true, "If the booklet should be given to the player when he first crafts something from the Mod");
public final String name;
public final String category;

View file

@ -16,12 +16,11 @@ import ellpeck.actuallyadditions.achievement.InitAchievements;
import ellpeck.actuallyadditions.achievement.TheAchievements;
import ellpeck.actuallyadditions.config.values.ConfigBoolValues;
import ellpeck.actuallyadditions.items.InitItems;
import ellpeck.actuallyadditions.network.PacketCheckBook;
import ellpeck.actuallyadditions.network.PacketHandler;
import ellpeck.actuallyadditions.util.INameableItem;
import ellpeck.actuallyadditions.util.playerdata.PersistantServerData;
import net.minecraft.block.Block;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
public class CraftEvent{
@ -32,8 +31,13 @@ public class CraftEvent{
if(ConfigBoolValues.GIVE_BOOKLET_ON_FIRST_CRAFT.isEnabled()){
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);
PersistantServerData data = PersistantServerData.get(event.player);
if(!data.bookGottenAlready){
data.bookGottenAlready = true;
EntityItem entityItem = new EntityItem(event.player.worldObj, event.player.posX, event.player.posY, event.player.posZ, new ItemStack(InitItems.itemLexicon));
entityItem.delayBeforeCanPickup = 0;
event.player.worldObj.spawnEntityInWorld(entityItem);
}
}
}

View file

@ -0,0 +1,29 @@
/*
* This file ("EntityConstructingEvent.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.event;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import ellpeck.actuallyadditions.util.ModUtil;
import ellpeck.actuallyadditions.util.playerdata.PersistantServerData;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.event.entity.EntityEvent;
public class EntityConstructingEvent{
@SubscribeEvent
public void onEntityConstructing(EntityEvent.EntityConstructing event){
if(event.entity instanceof EntityPlayer){
if(PersistantServerData.get((EntityPlayer)event.entity) == null){
event.entity.registerExtendedProperties(ModUtil.MOD_ID, new PersistantServerData());
}
}
}
}

View file

@ -26,6 +26,7 @@ public class InitEvents{
Util.registerEvent(new EntityLivingEvent());
Util.registerEvent(new BucketFillEvent());
Util.registerEvent(new LogoutEvent());
Util.registerEvent(new EntityConstructingEvent());
MinecraftForge.TERRAIN_GEN_BUS.register(new WorldDecorationEvent());
}

View file

@ -1,58 +0,0 @@
/*
* 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.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
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){
this.player = (EntityPlayer)Minecraft.getMinecraft().theWorld.getEntityByID(buf.readInt());
}
@Override
public void toBytes(ByteBuf buf){
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

@ -1,60 +0,0 @@
/*
* This file ("PacketGiveBook.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 ellpeck.actuallyadditions.items.InitItems;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
public class PacketGiveBook implements IMessage{
@SuppressWarnings("unused")
public PacketGiveBook(){
}
private EntityPlayer player;
public PacketGiveBook(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<PacketGiveBook, IMessage>{
@Override
public IMessage onMessage(PacketGiveBook message, MessageContext ctx){
EntityItem entityItem = new EntityItem(message.player.worldObj, message.player.posX, message.player.posY, message.player.posZ, new ItemStack(InitItems.itemLexicon));
entityItem.delayBeforeCanPickup = 0;
message.player.worldObj.spawnEntityInWorld(entityItem);
return null;
}
}
}

View file

@ -30,7 +30,5 @@ public class PacketHandler{
theNetwork.registerMessage(PacketSyncerToClient.Handler.class, PacketSyncerToClient.class, 1, Side.CLIENT);
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);
}
}

View file

@ -25,7 +25,11 @@ import ellpeck.actuallyadditions.event.RenderPlayerEventAA;
import ellpeck.actuallyadditions.event.TooltipEvent;
import ellpeck.actuallyadditions.tile.*;
import ellpeck.actuallyadditions.update.UpdateCheckerClientNotifier;
import ellpeck.actuallyadditions.util.*;
import ellpeck.actuallyadditions.util.AssetUtil;
import ellpeck.actuallyadditions.util.KeyBinds;
import ellpeck.actuallyadditions.util.ModUtil;
import ellpeck.actuallyadditions.util.Util;
import ellpeck.actuallyadditions.util.playerdata.PersistantClientData;
import net.minecraft.client.Minecraft;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
@ -40,7 +44,7 @@ public class ClientProxy implements IProxy{
public void preInit(FMLPreInitializationEvent event){
ModUtil.LOGGER.info("PreInitializing ClientProxy...");
PersistantVariables.setTheFile(new File(Minecraft.getMinecraft().mcDataDir, ModUtil.MOD_ID+"Data.dat"));
PersistantClientData.setTheFile(new File(Minecraft.getMinecraft().mcDataDir, ModUtil.MOD_ID+"Data.dat"));
KeyBinds.init();
}

View file

@ -71,7 +71,7 @@ public class TileEntityBase extends TileEntity{
GameRegistry.registerTileEntity(TileEntityXPSolidifier.class, ModUtil.MOD_ID_LOWER+":tileEntityXPSolidifier");
GameRegistry.registerTileEntity(TileEntityOreMagnet.class, ModUtil.MOD_ID_LOWER+":tileEntityOreMagnet");
GameRegistry.registerTileEntity(TileEntitySmileyCloud.class, ModUtil.MOD_ID_LOWER+":tileEntityCloud");
//GameRegistry.registerTileEntity(TileEntityToolTable.class, ModUtil.MOD_ID_LOWER+":tileEntityToolTable");
GameRegistry.registerTileEntity(TileEntityToolTable.class, ModUtil.MOD_ID_LOWER+":tileEntityToolTable");
}
@Override

View file

@ -8,7 +8,7 @@
* © 2015 Ellpeck
*/
package ellpeck.actuallyadditions.util;
package ellpeck.actuallyadditions.util.playerdata;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -17,6 +17,7 @@ import ellpeck.actuallyadditions.booklet.BookletIndexEntry;
import ellpeck.actuallyadditions.booklet.GuiBooklet;
import ellpeck.actuallyadditions.booklet.InitBooklet;
import ellpeck.actuallyadditions.booklet.page.BookletPage;
import ellpeck.actuallyadditions.util.ModUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
@ -26,7 +27,7 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
@SideOnly(Side.CLIENT)
public class PersistantVariables{
public class PersistantClientData{
private static File theFile;

View file

@ -0,0 +1,52 @@
/*
* This file ("PersistantServerPlayerData.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.util.playerdata;
import ellpeck.actuallyadditions.util.ModUtil;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.common.IExtendedEntityProperties;
public class PersistantServerData implements IExtendedEntityProperties{
public boolean bookGottenAlready;
@Override
public void saveNBTData(NBTTagCompound aComp){
NBTTagCompound compound = new NBTTagCompound();
compound.setBoolean("BookGotten", bookGottenAlready);
aComp.setTag(ModUtil.MOD_ID, compound);
}
@Override
public void loadNBTData(NBTTagCompound aComp){
NBTBase base = aComp.getTag(ModUtil.MOD_ID);
if(base != null && base instanceof NBTTagCompound){
NBTTagCompound compound = (NBTTagCompound)base;
this.bookGottenAlready = compound.getBoolean("BookGotten");
}
}
@Override
public void init(Entity entity, World world){
}
public static PersistantServerData get(EntityPlayer player){
return (PersistantServerData)player.getExtendedProperties(ModUtil.MOD_ID);
}
}