Finished Achievements.
This commit is contained in:
parent
37aaa8776f
commit
4e90cd73f6
7 changed files with 150 additions and 13 deletions
|
@ -9,10 +9,14 @@ import java.io.IOException;
|
|||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
@ -44,7 +48,8 @@ public class WorldSettings extends Configuration
|
|||
|
||||
File AEFolder;
|
||||
|
||||
public WorldSettings(File aeFolder) {
|
||||
public WorldSettings(File aeFolder)
|
||||
{
|
||||
super( new File( aeFolder.getPath() + File.separatorChar + "settings.cfg" ) );
|
||||
AEFolder = aeFolder;
|
||||
|
||||
|
@ -220,6 +225,7 @@ public class WorldSettings extends Configuration
|
|||
}
|
||||
|
||||
List<Integer> storageCellDims = new ArrayList();
|
||||
HashMap<Integer, UUID> idToUUID;
|
||||
|
||||
public void addStorageCellDim(int newDim)
|
||||
{
|
||||
|
@ -425,9 +431,40 @@ public class WorldSettings extends Configuration
|
|||
else
|
||||
{
|
||||
playerList.put( uuid, prop = new Property( uuid, "" + nextPlayer(), Property.Type.INTEGER ) );
|
||||
getUUIDMap().put( prop.getInt(), profile.getId() ); // add to reverse map
|
||||
save();
|
||||
return prop.getInt();
|
||||
}
|
||||
}
|
||||
|
||||
public HashMap<Integer, UUID> getUUIDMap()
|
||||
{
|
||||
if ( idToUUID == null )
|
||||
{
|
||||
idToUUID = new HashMap<Integer, UUID>();
|
||||
|
||||
ConfigCategory playerList = this.getCategory( "players" );
|
||||
|
||||
for (Entry<String, Property> b : playerList.getValues().entrySet())
|
||||
idToUUID.put( b.getValue().getInt(), UUID.fromString( b.getKey() ) );
|
||||
}
|
||||
|
||||
return idToUUID;
|
||||
}
|
||||
|
||||
public EntityPlayer getPlayerFromID(int playerID)
|
||||
{
|
||||
UUID id = getUUIDMap().get( playerID );
|
||||
|
||||
if ( id != null )
|
||||
{
|
||||
for (EntityPlayer player : CommonHelper.proxy.getPlayers())
|
||||
{
|
||||
if ( player.getUniqueID().equals( id ) )
|
||||
return player;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,4 +21,10 @@ public class PlayerRegistry implements IPlayerRegistry
|
|||
return WorldSettings.getInstance().getPlayerID( player.getGameProfile() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityPlayer findPlayer(int playerID)
|
||||
{
|
||||
return WorldSettings.getInstance().getPlayerFromID( playerID );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -52,22 +52,22 @@ public enum Achievements
|
|||
// done
|
||||
GlassCable(2, 0, AEApi.instance().parts().partCableGlass, AchievementType.Craft),
|
||||
|
||||
// TODO: detect stuff
|
||||
// done
|
||||
Networking1(4, -6, AEApi.instance().parts().partCableCovered, AchievementType.Custom),
|
||||
|
||||
// done
|
||||
Controller(4, -4, AEApi.instance().blocks().blockController, AchievementType.Craft),
|
||||
|
||||
// TODO: detect stuff
|
||||
// done
|
||||
Networking2(4, 0, AEApi.instance().parts().partCableSmart, AchievementType.Custom),
|
||||
|
||||
// TODO: detect stuff
|
||||
// done
|
||||
Networking3(4, 2, AEApi.instance().parts().partCableDense, AchievementType.Custom),
|
||||
|
||||
// done
|
||||
P2P(2, -2, AEApi.instance().parts().partP2PTunnelME, AchievementType.Craft),
|
||||
|
||||
// TODO: detect stuff
|
||||
// done
|
||||
Recursive(6, -2, AEApi.instance().blocks().blockInterface, AchievementType.Craft),
|
||||
|
||||
// done
|
||||
|
@ -112,21 +112,24 @@ public enum Achievements
|
|||
return stat;
|
||||
}
|
||||
|
||||
private Achievements(int x, int y, AEColoredItemDefinition which, AchievementType type) {
|
||||
private Achievements(int x, int y, AEColoredItemDefinition which, AchievementType type)
|
||||
{
|
||||
stack = which.stack( AEColor.Transparent, 1 );
|
||||
this.type = type;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
private Achievements(int x, int y, AEItemDefinition which, AchievementType type) {
|
||||
private Achievements(int x, int y, AEItemDefinition which, AchievementType type)
|
||||
{
|
||||
stack = which.stack( 1 );
|
||||
this.type = type;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
private Achievements(int x, int y, ItemStack which, AchievementType type) {
|
||||
private Achievements(int x, int y, ItemStack which, AchievementType type)
|
||||
{
|
||||
stack = which;
|
||||
this.type = type;
|
||||
this.x = x;
|
||||
|
|
49
me/cache/PathGridCache.java
vendored
49
me/cache/PathGridCache.java
vendored
|
@ -25,6 +25,7 @@ import appeng.api.networking.pathing.IPathingGrid;
|
|||
import appeng.api.util.DimensionalCoord;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.stats.Achievements;
|
||||
import appeng.me.GridConnection;
|
||||
import appeng.me.GridNode;
|
||||
import appeng.me.pathfinding.AdHocChannelUpdater;
|
||||
|
@ -33,6 +34,7 @@ import appeng.me.pathfinding.ControllerValidator;
|
|||
import appeng.me.pathfinding.IPathItem;
|
||||
import appeng.me.pathfinding.PathSegment;
|
||||
import appeng.tile.networking.TileController;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class PathGridCache implements IPathingGrid
|
||||
{
|
||||
|
@ -48,6 +50,9 @@ public class PathGridCache implements IPathingGrid
|
|||
int instance = Integer.MIN_VALUE;
|
||||
|
||||
int ticksUntilReady = 20;
|
||||
public int channelsInUse = 0;
|
||||
int lastChannels = 0;
|
||||
|
||||
final Set<TileController> controllers = new HashSet();
|
||||
final Set<IGridNode> requireChannels = new HashSet();
|
||||
final Set<IGridNode> blockDense = new HashSet();
|
||||
|
@ -59,7 +64,8 @@ public class PathGridCache implements IPathingGrid
|
|||
public int channelsByBlocks = 0;
|
||||
public double channelPowerUsage = 0.0;
|
||||
|
||||
public PathGridCache(IGrid g) {
|
||||
public PathGridCache(IGrid g)
|
||||
{
|
||||
myGrid = g;
|
||||
}
|
||||
|
||||
|
@ -79,6 +85,7 @@ public class PathGridCache implements IPathingGrid
|
|||
booting = true;
|
||||
updateNetwork = false;
|
||||
instance++;
|
||||
channelsInUse = 0;
|
||||
|
||||
if ( !AEConfig.instance.isFeatureEnabled( AEFeature.Channels ) )
|
||||
{
|
||||
|
@ -99,6 +106,8 @@ public class PathGridCache implements IPathingGrid
|
|||
used = 0;
|
||||
|
||||
int nodes = myGrid.getNodes().size();
|
||||
channelsInUse = used;
|
||||
|
||||
ticksUntilReady = 20 + Math.max( 0, nodes / 100 - 20 );
|
||||
channelsByBlocks = nodes * used;
|
||||
channelPowerUsage = (double) channelsByBlocks / 128.0;
|
||||
|
@ -164,6 +173,9 @@ public class PathGridCache implements IPathingGrid
|
|||
}
|
||||
}
|
||||
|
||||
// check for achievements
|
||||
achievementPost();
|
||||
|
||||
booting = false;
|
||||
channelPowerUsage = (double) channelsByBlocks / 128.0;
|
||||
myGrid.postEvent( new MENetworkBootingStatusChange() );
|
||||
|
@ -171,6 +183,41 @@ public class PathGridCache implements IPathingGrid
|
|||
}
|
||||
}
|
||||
|
||||
private void achievementPost()
|
||||
{
|
||||
if ( lastChannels != channelsInUse && AEConfig.instance.isFeatureEnabled( AEFeature.Channels ) )
|
||||
{
|
||||
Achievements currentBracket = getAchievementBracket( channelsInUse );
|
||||
Achievements lastBracket = getAchievementBracket( lastChannels );
|
||||
if ( currentBracket != lastBracket && currentBracket != null )
|
||||
{
|
||||
Set<Integer> players = new HashSet();
|
||||
for (IGridNode n : requireChannels)
|
||||
players.add( n.getPlayerID() );
|
||||
|
||||
for (int id : players)
|
||||
{
|
||||
Platform.addStat( id, currentBracket.getAchivement() );
|
||||
}
|
||||
}
|
||||
}
|
||||
lastChannels = channelsInUse;
|
||||
}
|
||||
|
||||
private Achievements getAchievementBracket(int ch)
|
||||
{
|
||||
if ( ch < 8 )
|
||||
return null;
|
||||
|
||||
if ( ch < 128 )
|
||||
return Achievements.Networking1;
|
||||
|
||||
if ( ch < 2048 )
|
||||
return Achievements.Networking2;
|
||||
|
||||
return Achievements.Networking3;
|
||||
}
|
||||
|
||||
private int calculateRequiredChanels()
|
||||
{
|
||||
int depth = 0;
|
||||
|
|
|
@ -25,7 +25,8 @@ public class PathSegment
|
|||
|
||||
PathGridCache pgc;
|
||||
|
||||
public PathSegment(PathGridCache myPGC, List open, Set semiopen, Set closed) {
|
||||
public PathSegment(PathGridCache myPGC, List open, Set semiopen, Set closed)
|
||||
{
|
||||
this.open = open;
|
||||
this.semiopen = semiopen;
|
||||
this.closed = closed;
|
||||
|
@ -110,6 +111,7 @@ public class PathSegment
|
|||
pi = pi.getControllerRoute();
|
||||
}
|
||||
|
||||
pgc.channelsInUse++;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -132,6 +134,7 @@ public class PathSegment
|
|||
pi = pi.getControllerRoute();
|
||||
}
|
||||
|
||||
pgc.channelsInUse++;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ import appeng.api.networking.ticking.ITickManager;
|
|||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.networking.ticking.TickingRequest;
|
||||
import appeng.api.parts.IPartCollsionHelper;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.parts.IPartRenderHelper;
|
||||
import appeng.api.storage.ICellContainer;
|
||||
import appeng.api.storage.IExternalStorageHandler;
|
||||
|
@ -44,7 +45,9 @@ import appeng.api.storage.data.IItemList;
|
|||
import appeng.api.util.IConfigManager;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.core.settings.TickRates;
|
||||
import appeng.core.stats.Achievements;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.helpers.IInterfaceHost;
|
||||
import appeng.helpers.IPriorityHost;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.storage.MEInventoryHandler;
|
||||
|
@ -72,7 +75,8 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
|
|||
|
||||
AppEngInternalAEInventory Config = new AppEngInternalAEInventory( this, 63 );
|
||||
|
||||
public PartStorageBus(ItemStack is) {
|
||||
public PartStorageBus(ItemStack is)
|
||||
{
|
||||
super( PartStorageBus.class, is );
|
||||
getConfigManager().registerSetting( Settings.ACCESS, AccessRestriction.READ_WRITE );
|
||||
getConfigManager().registerSetting( Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
|
||||
|
@ -285,6 +289,8 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
|
|||
|
||||
if ( inv != null )
|
||||
{
|
||||
checkInterfaceVsStorageBus( target, side.getOpposite() );
|
||||
|
||||
handler = new MEInventoryHandler( inv, StorageChannel.ITEMS );
|
||||
|
||||
handler.myAccess = (AccessRestriction) this.getConfigManager().getSetting( Settings.ACCESS );
|
||||
|
@ -332,6 +338,27 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
|
|||
return handler;
|
||||
}
|
||||
|
||||
private void checkInterfaceVsStorageBus(TileEntity target, ForgeDirection side)
|
||||
{
|
||||
IInterfaceHost achiv = null;
|
||||
|
||||
if ( target instanceof IInterfaceHost )
|
||||
achiv = (IInterfaceHost) target;
|
||||
|
||||
if ( target instanceof IPartHost )
|
||||
{
|
||||
Object part = ((IPartHost) target).getPart( side );
|
||||
if ( part instanceof IInterfaceHost )
|
||||
achiv = (IInterfaceHost) part;
|
||||
}
|
||||
|
||||
if ( achiv != null )
|
||||
{
|
||||
Platform.addStat( achiv.getActionableNode().getPlayerID(), Achievements.Recursive.getAchivement() );
|
||||
Platform.addStat( getActionableNode().getPlayerID(), Achievements.Recursive.getAchivement() );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer)
|
||||
|
|
|
@ -42,9 +42,11 @@ import net.minecraft.nbt.NBTTagString;
|
|||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S21PacketChunkData;
|
||||
import net.minecraft.server.management.PlayerManager;
|
||||
import net.minecraft.stats.Achievement;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityChest;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
@ -385,7 +387,8 @@ public class Platform
|
|||
{
|
||||
switch (id)
|
||||
{
|
||||
case 10: {
|
||||
case 10:
|
||||
{
|
||||
NBTTagCompound ctA = (NBTTagCompound) A;
|
||||
NBTTagCompound ctB = (NBTTagCompound) B;
|
||||
|
||||
|
@ -511,7 +514,8 @@ public class Platform
|
|||
hash += id;
|
||||
switch (id)
|
||||
{
|
||||
case 10: {
|
||||
case 10:
|
||||
{
|
||||
NBTTagCompound ctA = (NBTTagCompound) A;
|
||||
|
||||
Set<String> cA = ctA.func_150296_c();
|
||||
|
@ -1822,4 +1826,14 @@ public class Platform
|
|||
assert player.worldObj.isRemote : "Valid only on client";
|
||||
return (float) (player.posY + player.getEyeHeight() - player.getDefaultEyeHeight());
|
||||
}
|
||||
|
||||
public static void addStat(int playerID, Achievement achivement)
|
||||
{
|
||||
EntityPlayer p = AEApi.instance().registries().players().findPlayer( playerID );
|
||||
if ( p != null )
|
||||
{
|
||||
p.addChatMessage( new ChatComponentText( "RWAR!" ) );
|
||||
// p.addStat( achivement, 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue