diff --git a/src/main/java/ellpeck/actuallyadditions/blocks/InitBlocks.java b/src/main/java/ellpeck/actuallyadditions/blocks/InitBlocks.java index 96b961668..5957b6520 100644 --- a/src/main/java/ellpeck/actuallyadditions/blocks/InitBlocks.java +++ b/src/main/java/ellpeck/actuallyadditions/blocks/InitBlocks.java @@ -100,14 +100,9 @@ public class InitBlocks{ public static Block blockLaserRelay; //TODO: Plan for Laser Power Transmitters: - //TODO: Connectable with Laser Wrench - //TODO: Generate a Network that is (maybe) stored via WorldSavedData - //TODO: Whenever a Transmitter is fed with energy, it tries to find a connector that is connected to a block that needs energy - //TODO: The power then gets transferred through a Laser Entity that will find its way past all of the transmitters on its way to the block in need - //TODO: Or maybe, instead, if I can't be bothered, the points will be connected through shiny lines that light up or flash when power is transmitted - //TODO: Save the Connections via an Array of "ConnectionPairs" which stores two connected lasers to make calculating the laser entity easier - //TODO: -> To find every laser one is connected to, just go through the array, find the laser itself and get the second part of the pair - //TODO: Notify Client of Connections through NBT -> Every laser adds itself to the connection list on the client + //TODO: When there is a block in the way, they don't render their laser and don't transmit + //TODO: They stay connected and can be connected together even though they're blocked + //TODO: If blocked, they display the block coords blocking them on right-click public static void init(){ ModUtil.LOGGER.info("Initializing Blocks..."); diff --git a/src/main/java/ellpeck/actuallyadditions/event/CraftEvent.java b/src/main/java/ellpeck/actuallyadditions/event/CraftEvent.java index b8fa438df..42aba2872 100644 --- a/src/main/java/ellpeck/actuallyadditions/event/CraftEvent.java +++ b/src/main/java/ellpeck/actuallyadditions/event/CraftEvent.java @@ -16,12 +16,14 @@ import ellpeck.actuallyadditions.achievement.InitAchievements; import ellpeck.actuallyadditions.achievement.TheAchievements; import ellpeck.actuallyadditions.config.values.ConfigBoolValues; import ellpeck.actuallyadditions.items.InitItems; +import ellpeck.actuallyadditions.misc.WorldData; import ellpeck.actuallyadditions.util.IActAddItemOrBlock; import ellpeck.actuallyadditions.util.playerdata.PersistentServerData; import net.minecraft.block.Block; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; public class CraftEvent{ @@ -31,9 +33,10 @@ 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 IActAddItemOrBlock || Block.getBlockFromItem(event.crafting.getItem()) instanceof IActAddItemOrBlock)){ - PersistentServerData data = PersistentServerData.get(event.player); - if(data != null && !data.bookGottenAlready){ - data.bookGottenAlready = true; + NBTTagCompound compound = PersistentServerData.getDataFromPlayer(event.player); + if(compound != null && !compound.getBoolean("BookGottenAlready")){ + compound.setBoolean("BookGottenAlready", true); + WorldData.makeDirty(); EntityItem entityItem = new EntityItem(event.player.worldObj, event.player.posX, event.player.posY, event.player.posZ, new ItemStack(InitItems.itemLexicon)); entityItem.delayBeforeCanPickup = 0; diff --git a/src/main/java/ellpeck/actuallyadditions/event/EntityConstructingEvent.java b/src/main/java/ellpeck/actuallyadditions/event/EntityConstructingEvent.java deleted file mode 100644 index 42b6cfa8f..000000000 --- a/src/main/java/ellpeck/actuallyadditions/event/EntityConstructingEvent.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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.PersistentServerData; -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 && !event.entity.worldObj.isRemote){ - if(PersistentServerData.get((EntityPlayer)event.entity) == null){ - event.entity.registerExtendedProperties(ModUtil.MOD_ID, new PersistentServerData()); - } - } - } -} diff --git a/src/main/java/ellpeck/actuallyadditions/event/InitEvents.java b/src/main/java/ellpeck/actuallyadditions/event/InitEvents.java index 55b03d352..04bb7365b 100644 --- a/src/main/java/ellpeck/actuallyadditions/event/InitEvents.java +++ b/src/main/java/ellpeck/actuallyadditions/event/InitEvents.java @@ -24,13 +24,13 @@ public class InitEvents{ ModUtil.LOGGER.info("Initializing Events..."); Util.registerEvent(new SmeltEvent()); + Util.registerEvent(new CraftEvent()); Util.registerEvent(new LivingDropEvent()); Util.registerEvent(new PickupEvent()); Util.registerEvent(new EntityLivingEvent()); Util.registerEvent(new BucketFillEvent()); Util.registerEvent(new LogoutEvent()); - Util.registerEvent(new EntityConstructingEvent()); Util.registerEvent(new WorldLoadEvent()); MinecraftForge.TERRAIN_GEN_BUS.register(new WorldDecorationEvent()); } diff --git a/src/main/java/ellpeck/actuallyadditions/misc/WorldData.java b/src/main/java/ellpeck/actuallyadditions/misc/WorldData.java index b39f9ed3d..dff1b4def 100644 --- a/src/main/java/ellpeck/actuallyadditions/misc/WorldData.java +++ b/src/main/java/ellpeck/actuallyadditions/misc/WorldData.java @@ -11,6 +11,7 @@ package ellpeck.actuallyadditions.misc; import ellpeck.actuallyadditions.util.ModUtil; +import ellpeck.actuallyadditions.util.playerdata.PersistentServerData; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.server.MinecraftServer; import net.minecraft.world.World; @@ -30,8 +31,8 @@ public class WorldData extends WorldSavedData{ @Override public void readFromNBT(NBTTagCompound compound){ + //Laser World Data int netAmount = compound.getInteger("LaserNetworkAmount"); - LaserRelayConnectionHandler.getInstance().networks.clear(); for(int i = 0; i < netAmount; i++){ ArrayList network = LaserRelayConnectionHandler.getInstance().readNetworkFromNBT(compound, "LaserNetwork"+i); @@ -39,16 +40,34 @@ public class WorldData extends WorldSavedData{ LaserRelayConnectionHandler.getInstance().networks.add(network); } } + + //Player Data + int dataSize = compound.getInteger("PersistentDataSize"); + PersistentServerData.playerSaveData.clear(); + for(int i = 0; i < dataSize; i++){ + PersistentServerData.PlayerSave aSave = PersistentServerData.PlayerSave.fromNBT(compound, "PlayerSaveData"+i); + if(aSave != null){ + PersistentServerData.playerSaveData.add(aSave); + } + } } @Override public void writeToNBT(NBTTagCompound compound){ + //Laser World Data int netAmount = LaserRelayConnectionHandler.getInstance().networks.size(); compound.setInteger("LaserNetworkAmount", netAmount); for(int i = 0; i < netAmount; i++){ LaserRelayConnectionHandler.getInstance().writeNetworkToNBT(LaserRelayConnectionHandler.getInstance().networks.get(i), compound, "LaserNetwork"+i); } + + //Player Data + compound.setInteger("PersistentDataSize", PersistentServerData.playerSaveData.size()); + for(int i = 0; i < PersistentServerData.playerSaveData.size(); i++){ + PersistentServerData.PlayerSave theSave = PersistentServerData.playerSaveData.get(i); + theSave.toNBT(compound, "PlayerSaveData"+i); + } } public static void makeDirty(){ diff --git a/src/main/java/ellpeck/actuallyadditions/util/playerdata/PersistentServerData.java b/src/main/java/ellpeck/actuallyadditions/util/playerdata/PersistentServerData.java index c7cd58aa6..78bbf2a84 100644 --- a/src/main/java/ellpeck/actuallyadditions/util/playerdata/PersistentServerData.java +++ b/src/main/java/ellpeck/actuallyadditions/util/playerdata/PersistentServerData.java @@ -10,47 +10,52 @@ 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 PersistentServerData implements IExtendedEntityProperties{ +import java.util.ArrayList; +import java.util.UUID; - public boolean bookGottenAlready; +public class PersistentServerData{ - public static PersistentServerData get(EntityPlayer player){ - IExtendedEntityProperties properties = player.getExtendedProperties(ModUtil.MOD_ID); - if(properties != null && properties instanceof PersistentServerData){ - return (PersistentServerData)properties; + public static ArrayList playerSaveData = new ArrayList(); + + public static NBTTagCompound getDataFromPlayer(EntityPlayer player){ + //Get Data from existing data + for(PlayerSave save : playerSaveData){ + if(save.thePlayerUUID.equals(player.getUniqueID())){ + return save.theCompound; + } } - return null; + + //Add Data if none is existant + PlayerSave aSave = new PlayerSave(player.getUniqueID(), new NBTTagCompound()); + playerSaveData.add(aSave); + return aSave.theCompound; } - @Override - public void saveNBTData(NBTTagCompound aComp){ - NBTTagCompound compound = new NBTTagCompound(); + public static class PlayerSave{ - compound.setBoolean("BookGotten", this.bookGottenAlready); + public UUID thePlayerUUID; + public NBTTagCompound theCompound; - aComp.setTag(ModUtil.MOD_ID, compound); - } + public PlayerSave(UUID theUUID, NBTTagCompound theCompound){ + this.thePlayerUUID = theUUID; + this.theCompound = theCompound; + } - @Override - public void loadNBTData(NBTTagCompound aComp){ - NBTBase base = aComp.getTag(ModUtil.MOD_ID); - if(base != null && base instanceof NBTTagCompound){ - NBTTagCompound compound = (NBTTagCompound)base; + public void toNBT(NBTTagCompound compound, String name){ + compound.setLong(name+"LeastSignificant", this.thePlayerUUID.getLeastSignificantBits()); + compound.setLong(name+"MostSignificant", this.thePlayerUUID.getMostSignificantBits()); - this.bookGottenAlready = compound.getBoolean("BookGotten"); + compound.setTag(name+"Tag", this.theCompound); + } + + public static PlayerSave fromNBT(NBTTagCompound compound, String name){ + UUID theID = new UUID(compound.getLong(name+"MostSignificant"), compound.getLong(name+"LeastSignificant")); + NBTTagCompound theCompound = compound.getCompoundTag(name+"Tag"); + return new PlayerSave(theID, theCompound); } } - @Override - public void init(Entity entity, World world){ - - } }