Work on GUIs (specifically to get SkyChest GUI)
This commit is contained in:
@@ -28,6 +28,7 @@ import appeng.core.features.AEFeature;
|
||||
import appeng.server.ServerHelper;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.particles.ParticleType;
|
||||
import net.minecraft.stats.StatType;
|
||||
@@ -121,6 +122,9 @@ public final class AppEng
|
||||
private void clientSetup(FMLClientSetupEvent event) {
|
||||
final ApiDefinitions definitions = Api.INSTANCE.definitions();
|
||||
definitions.getRegistry().getBootstrapComponents( IClientSetupComponent.class ).forEachRemaining(IClientSetupComponent::setup);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// @Nonnull
|
||||
|
||||
@@ -25,7 +25,6 @@ import appeng.api.definitions.ITileDefinition;
|
||||
import appeng.block.misc.BlockQuartzFixture;
|
||||
import appeng.block.spatial.BlockMatrixFrame;
|
||||
import appeng.block.storage.BlockSkyChest;
|
||||
import appeng.block.storage.SkyChestRenderingCustomizer;
|
||||
import appeng.bootstrap.*;
|
||||
import appeng.bootstrap.definitions.TileEntityDefinition;
|
||||
import appeng.client.render.tesr.SkyChestTESR;
|
||||
@@ -215,12 +214,10 @@ public final class ApiBlocks implements IBlocks
|
||||
this.skyStoneChest = registry.block( "sky_stone_chest", () -> new BlockSkyChest( BlockSkyChest.SkyChestType.STONE, skyStoneChestProps ) )
|
||||
.features( AEFeature.SKY_STONE, AEFeature.SKY_STONE_CHESTS )
|
||||
.tileEntity( skyChestTile )
|
||||
// .rendering( new SkyChestRenderingCustomizer( BlockSkyChest.SkyChestType.STONE ) )
|
||||
.build();
|
||||
this.smoothSkyStoneChest = registry.block( "smooth_sky_stone_chest", () -> new BlockSkyChest( BlockSkyChest.SkyChestType.BLOCK, skyStoneChestProps ) )
|
||||
.features( AEFeature.SKY_STONE, AEFeature.SKY_STONE_CHESTS )
|
||||
.tileEntity( skyChestTile )
|
||||
// .rendering( new SkyChestRenderingCustomizer( BlockSkyChest.SkyChestType.BLOCK ) )
|
||||
.build();
|
||||
|
||||
// this.skyCompass = registry.block( "sky_compass", BlockSkyCompass::new )
|
||||
|
||||
@@ -27,8 +27,6 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.common.network.IGuiHandler;
|
||||
import net.minecraftforge.fml.relauncher.ReflectionHelper;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
@@ -125,7 +123,7 @@ import appeng.tile.storage.TileSkyChest;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
public enum GuiBridge implements IGuiHandler
|
||||
public enum GuiBridge
|
||||
{
|
||||
GUI_Handler(),
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
@@ -73,7 +73,7 @@ public class PacketJEIRecipe extends AppEngPacket
|
||||
this.recipe = new ItemStack[9][];
|
||||
for( int x = 0; x < this.recipe.length; x++ )
|
||||
{
|
||||
final NBTTagList list = comp.getTagList( "#" + x, 10 );
|
||||
final ListNBT list = comp.getTagList( "#" + x, 10 );
|
||||
if( list.tagCount() > 0 )
|
||||
{
|
||||
this.recipe[x] = new ItemStack[list.tagCount()];
|
||||
|
||||
@@ -25,13 +25,11 @@ import java.util.UUID;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraftforge.common.config.ConfigCategory;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
|
||||
import appeng.core.AppEng;
|
||||
|
||||
@@ -51,38 +49,37 @@ final class PlayerData implements IWorldPlayerData, IOnWorldStartable, IOnWorldS
|
||||
private static final String LAST_PLAYER_KEY = "lastPlayer";
|
||||
private static final int LAST_PLAYER_DEFAULT = 0;
|
||||
|
||||
private final Configuration config;
|
||||
private final IWorldPlayerMapping playerMapping;
|
||||
private final CommentedFileConfig config;
|
||||
// FIXME private final IWorldPlayerMapping playerMapping;
|
||||
|
||||
private int lastPlayerID;
|
||||
|
||||
public PlayerData( @Nonnull final Configuration configFile )
|
||||
public PlayerData( @Nonnull final CommentedFileConfig configFile )
|
||||
{
|
||||
Preconditions.checkNotNull( configFile );
|
||||
|
||||
this.config = configFile;
|
||||
|
||||
final ConfigCategory playerList = this.config.getCategory( "players" );
|
||||
this.playerMapping = new PlayerMapping( playerList );
|
||||
// FIXME this.playerMapping = new PlayerMapping( config, "players." );
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PlayerEntity getPlayerFromID( final int playerID )
|
||||
{
|
||||
final Optional<UUID> maybe = this.playerMapping.get( playerID );
|
||||
|
||||
if( maybe.isPresent() )
|
||||
{
|
||||
final UUID uuid = maybe.get();
|
||||
for( final PlayerEntity player : AppEng.proxy.getPlayers() )
|
||||
{
|
||||
if( player.getUniqueID().equals( uuid ) )
|
||||
{
|
||||
return player;
|
||||
}
|
||||
}
|
||||
}
|
||||
// FIXME final Optional<UUID> maybe = this.playerMapping.get( playerID );
|
||||
// FIXME
|
||||
// FIXME if( maybe.isPresent() )
|
||||
// FIXME {
|
||||
// FIXME final UUID uuid = maybe.get();
|
||||
// FIXME for( final PlayerEntity player : AppEng.proxy.getPlayers() )
|
||||
// FIXME {
|
||||
// FIXME if( player.getUniqueID().equals( uuid ) )
|
||||
// FIXME {
|
||||
// FIXME return player;
|
||||
// FIXME }
|
||||
// FIXME }
|
||||
// FIXME }
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -90,42 +87,44 @@ final class PlayerData implements IWorldPlayerData, IOnWorldStartable, IOnWorldS
|
||||
@Override
|
||||
public int getPlayerID( @Nonnull final GameProfile profile )
|
||||
{
|
||||
Preconditions.checkNotNull( profile );
|
||||
Preconditions.checkNotNull( this.config.getCategory( "players" ) );
|
||||
Preconditions.checkState( profile.isComplete() );
|
||||
|
||||
final ConfigCategory players = this.config.getCategory( "players" );
|
||||
final String uuid = profile.getId().toString();
|
||||
final Property maybePlayerID = players.get( uuid );
|
||||
|
||||
if( maybePlayerID != null && maybePlayerID.isIntValue() )
|
||||
{
|
||||
return maybePlayerID.getInt();
|
||||
}
|
||||
else
|
||||
{
|
||||
final int newPlayerID = this.nextPlayer();
|
||||
final Property newPlayer = new Property( uuid, String.valueOf( newPlayerID ), Property.Type.INTEGER );
|
||||
players.put( uuid, newPlayer );
|
||||
this.playerMapping.put( newPlayerID, profile.getId() ); // add to reverse map
|
||||
this.config.save();
|
||||
|
||||
return newPlayerID;
|
||||
}
|
||||
return -1;
|
||||
// FIXME Preconditions.checkNotNull( profile );
|
||||
// FIXME Preconditions.checkNotNull( this.config.getCategory( "players" ) );
|
||||
// FIXME Preconditions.checkState( profile.isComplete() );
|
||||
// FIXME
|
||||
// FIXME final ConfigCategory players = this.config.getCategory( "players" );
|
||||
// FIXME final String uuid = profile.getId().toString();
|
||||
// FIXME final Property maybePlayerID = players.get( uuid );
|
||||
// FIXME
|
||||
// FIXME if( maybePlayerID != null && maybePlayerID.isIntValue() )
|
||||
// FIXME {
|
||||
// FIXME return maybePlayerID.getInt();
|
||||
// FIXME }
|
||||
// FIXME else
|
||||
// FIXME {
|
||||
// FIXME final int newPlayerID = this.nextPlayer();
|
||||
// FIXME final Property newPlayer = new Property( uuid, String.valueOf( newPlayerID ), Property.Type.INTEGER );
|
||||
// FIXME players.put( uuid, newPlayer );
|
||||
// FIXME this.playerMapping.put( newPlayerID, profile.getId() ); // add to reverse map
|
||||
// FIXME this.config.save();
|
||||
// FIXME
|
||||
// FIXME return newPlayerID;
|
||||
// FIXME }
|
||||
}
|
||||
|
||||
private int nextPlayer()
|
||||
{
|
||||
final int r = this.lastPlayerID;
|
||||
this.lastPlayerID++;
|
||||
this.config.get( LAST_PLAYER_CATEGORY, LAST_PLAYER_KEY, this.lastPlayerID ).set( this.lastPlayerID );
|
||||
return r;
|
||||
// FIXME final int r = this.lastPlayerID;
|
||||
// FIXME this.lastPlayerID++;
|
||||
// FIXME this.config.get( LAST_PLAYER_CATEGORY, LAST_PLAYER_KEY, this.lastPlayerID ).set( this.lastPlayerID );
|
||||
// FIXME return r;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWorldStart()
|
||||
{
|
||||
this.lastPlayerID = this.config.get( LAST_PLAYER_CATEGORY, LAST_PLAYER_KEY, LAST_PLAYER_DEFAULT ).getInt( LAST_PLAYER_DEFAULT );
|
||||
// FIXME this.lastPlayerID = this.config.get( LAST_PLAYER_CATEGORY, LAST_PLAYER_KEY, LAST_PLAYER_DEFAULT ).getInt( LAST_PLAYER_DEFAULT );
|
||||
|
||||
this.config.save();
|
||||
}
|
||||
|
||||
@@ -25,10 +25,9 @@ import java.util.UUID;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.electronwill.nightconfig.core.Config;
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import net.minecraftforge.common.config.ConfigCategory;
|
||||
|
||||
|
||||
/**
|
||||
* Wrapper class for the player mappings.
|
||||
@@ -44,9 +43,9 @@ final class PlayerMapping implements IWorldPlayerMapping
|
||||
*/
|
||||
private final Map<Integer, UUID> mappings;
|
||||
|
||||
public PlayerMapping( final ConfigCategory category )
|
||||
public PlayerMapping( final Config config, String path )
|
||||
{
|
||||
final PlayerMappingsInitializer init = new PlayerMappingsInitializer( category );
|
||||
final PlayerMappingsInitializer init = new PlayerMappingsInitializer( config, path );
|
||||
|
||||
this.mappings = init.getPlayerMappings();
|
||||
}
|
||||
|
||||
@@ -23,11 +23,9 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.minecraftforge.common.config.ConfigCategory;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
import com.electronwill.nightconfig.core.Config;
|
||||
|
||||
import appeng.core.AELog;
|
||||
import appeng.util.UUIDMatcher;
|
||||
|
||||
|
||||
/**
|
||||
@@ -38,7 +36,7 @@ class PlayerMappingsInitializer
|
||||
/**
|
||||
* Internal immutable mapping
|
||||
*/
|
||||
private final Map<Integer, UUID> playerMappings;
|
||||
// FIXME private final Map<Integer, UUID> playerMappings;
|
||||
|
||||
/**
|
||||
* Creates the initializer for the player mappings.
|
||||
@@ -50,35 +48,35 @@ class PlayerMappingsInitializer
|
||||
*
|
||||
* @param playerList the category for the player list, generally extracted using the "players" tag
|
||||
*/
|
||||
PlayerMappingsInitializer( final ConfigCategory playerList )
|
||||
PlayerMappingsInitializer(final Config config, String prefix )
|
||||
{
|
||||
// Matcher for UUIDs
|
||||
final UUIDMatcher matcher = new UUIDMatcher();
|
||||
|
||||
// Initial capacity for mappings
|
||||
final int capacity = playerList.size();
|
||||
|
||||
// Mappings for the IDs is a regular HashMap
|
||||
this.playerMappings = new HashMap<>( capacity );
|
||||
|
||||
// Iterates through every pair of UUID to ID
|
||||
for( final Map.Entry<String, Property> entry : playerList.getValues().entrySet() )
|
||||
{
|
||||
final String maybeUUID = entry.getKey();
|
||||
final int id = entry.getValue().getInt();
|
||||
|
||||
if( matcher.isUUID( maybeUUID ) )
|
||||
{
|
||||
final UUID uuidString = UUID.fromString( maybeUUID );
|
||||
|
||||
this.playerMappings.put( id, uuidString );
|
||||
}
|
||||
else
|
||||
{
|
||||
AELog.warn(
|
||||
"The configuration for players contained an outdated entry instead an expected UUID " + maybeUUID + " for the player " + id + ". Please clean this up." );
|
||||
}
|
||||
}
|
||||
// FIXME // Matcher for UUIDs
|
||||
// FIXME final UUIDMatcher matcher = new UUIDMatcher();
|
||||
// FIXME
|
||||
// FIXME // Initial capacity for mappings
|
||||
// FIXME final int capacity = playerList.size();
|
||||
// FIXME
|
||||
// FIXME // Mappings for the IDs is a regular HashMap
|
||||
// FIXME this.playerMappings = new HashMap<>( capacity );
|
||||
// FIXME
|
||||
// FIXME // Iterates through every pair of UUID to ID
|
||||
// FIXME for( final Map.Entry<String, Property> entry : playerList.getValues().entrySet() )
|
||||
// FIXME {
|
||||
// FIXME final String maybeUUID = entry.getKey();
|
||||
// FIXME final int id = entry.getValue().getInt();
|
||||
// FIXME
|
||||
// FIXME if( matcher.isUUID( maybeUUID ) )
|
||||
// FIXME {
|
||||
// FIXME final UUID uuidString = UUID.fromString( maybeUUID );
|
||||
// FIXME
|
||||
// FIXME this.playerMappings.put( id, uuidString );
|
||||
// FIXME }
|
||||
// FIXME else
|
||||
// FIXME {
|
||||
// FIXME AELog.warn(
|
||||
// FIXME "The configuration for players contained an outdated entry instead an expected UUID " + maybeUUID + " for the player " + id + ". Please clean this up." );
|
||||
// FIXME }
|
||||
// FIXME }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
@@ -33,6 +33,10 @@ import net.minecraftforge.common.util.INBTSerializable;
|
||||
|
||||
import appeng.api.storage.ISpatialDimension;
|
||||
import appeng.capabilities.Capabilities;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
||||
public class SpatialDimensionManager implements ISpatialDimension, ICapabilitySerializable<CompoundNBT>
|
||||
@@ -118,35 +122,36 @@ public class SpatialDimensionManager implements ISpatialDimension, ICapabilitySe
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Nonnull
|
||||
@Override
|
||||
public boolean hasCapability( Capability<?> capability, Direction facing )
|
||||
{
|
||||
return capability == Capabilities.SPATIAL_DIMENSION;
|
||||
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap) {
|
||||
if( cap == Capabilities.SPATIAL_DIMENSION )
|
||||
{
|
||||
return LazyOptional.of(() -> (T) this);
|
||||
}
|
||||
return LazyOptional.empty();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability( Capability<T> capability, Direction facing )
|
||||
{
|
||||
if( capability == Capabilities.SPATIAL_DIMENSION )
|
||||
{
|
||||
return (T) this;
|
||||
}
|
||||
return null;
|
||||
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
|
||||
return getCapability(cap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundNBT serializeNBT()
|
||||
{
|
||||
final CompoundNBT ret = new CompoundNBT();
|
||||
final NBTTagList list = new NBTTagList();
|
||||
final ListNBT list = new ListNBT();
|
||||
|
||||
for( Map.Entry<Integer, StorageCellData> entry : this.spatialData.entrySet() )
|
||||
{
|
||||
final CompoundNBT nbt = entry.getValue().serializeNBT();
|
||||
nbt.setInteger( NBT_SPATIAL_ID_KEY, entry.getKey() );
|
||||
list.appendTag( nbt );
|
||||
nbt.putInt( NBT_SPATIAL_ID_KEY, entry.getKey() );
|
||||
list.add( nbt );
|
||||
}
|
||||
ret.setTag( NBT_SPATIAL_DATA_KEY, list );
|
||||
ret.put( NBT_SPATIAL_DATA_KEY, list );
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -155,14 +160,14 @@ public class SpatialDimensionManager implements ISpatialDimension, ICapabilitySe
|
||||
{
|
||||
if( nbt.contains(NBT_SPATIAL_DATA_KEY) )
|
||||
{
|
||||
final NBTTagList list = (NBTTagList) nbt.getTag( NBT_SPATIAL_DATA_KEY );
|
||||
final ListNBT list = (ListNBT) nbt.get( NBT_SPATIAL_DATA_KEY );
|
||||
|
||||
this.spatialData.clear();
|
||||
for( int i = 0; i < list.tagCount(); ++i )
|
||||
for( int i = 0; i < list.size(); ++i )
|
||||
{
|
||||
final CompoundNBT entry = list.getCompoundTagAt( i );
|
||||
final CompoundNBT entry = list.getCompound( i );
|
||||
final StorageCellData data = new StorageCellData();
|
||||
final int id = entry.getInteger( NBT_SPATIAL_ID_KEY );
|
||||
final int id = entry.getInt( NBT_SPATIAL_ID_KEY );
|
||||
data.deserializeNBT( entry );
|
||||
this.spatialData.put( id, data );
|
||||
}
|
||||
@@ -228,18 +233,18 @@ public class SpatialDimensionManager implements ISpatialDimension, ICapabilitySe
|
||||
public CompoundNBT serializeNBT()
|
||||
{
|
||||
CompoundNBT nbt = new CompoundNBT();
|
||||
nbt.setInteger( NBT_DIM_X_KEY, this.contentDimension.getX() );
|
||||
nbt.setInteger( NBT_DIM_Y_KEY, this.contentDimension.getY() );
|
||||
nbt.setInteger( NBT_DIM_Z_KEY, this.contentDimension.getZ() );
|
||||
nbt.setInteger( NBT_OWNER_KEY, this.owner );
|
||||
nbt.putInt( NBT_DIM_X_KEY, this.contentDimension.getX() );
|
||||
nbt.putInt( NBT_DIM_Y_KEY, this.contentDimension.getY() );
|
||||
nbt.putInt( NBT_DIM_Z_KEY, this.contentDimension.getZ() );
|
||||
nbt.putInt( NBT_OWNER_KEY, this.owner );
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT( CompoundNBT nbt )
|
||||
{
|
||||
this.contentDimension = new BlockPos( nbt.getInteger( NBT_DIM_X_KEY ), nbt.getInteger( NBT_DIM_Y_KEY ), nbt.getInteger( NBT_DIM_Z_KEY ) );
|
||||
this.owner = nbt.getInteger( NBT_OWNER_KEY );
|
||||
this.contentDimension = new BlockPos( nbt.getInt( NBT_DIM_X_KEY ), nbt.getInt( NBT_DIM_Y_KEY ), nbt.getInt( NBT_DIM_Z_KEY ) );
|
||||
this.owner = nbt.getInt( NBT_OWNER_KEY );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
|
||||
import appeng.core.AELog;
|
||||
import net.minecraft.world.dimension.Dimension;
|
||||
|
||||
|
||||
/**
|
||||
@@ -57,25 +58,29 @@ final class SpawnData implements IWorldSpawnData
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGenerated( final Dimension dim, final int chunkX, final int chunkZ )
|
||||
public void setGenerated(final Dimension dim, final int chunkX, final int chunkZ )
|
||||
{
|
||||
int dimId = dim.getType().getId(); // FIXME This is most likely borked, see new string ids
|
||||
|
||||
synchronized( SpawnData.class )
|
||||
{
|
||||
final CompoundNBT data = this.loadSpawnData( dim, chunkX, chunkZ );
|
||||
final CompoundNBT data = this.loadSpawnData( dimId, chunkX, chunkZ );
|
||||
|
||||
// edit.
|
||||
data.putBoolean(chunkX + "," + chunkZ, true);
|
||||
|
||||
this.writeSpawnData( dim, chunkX, chunkZ, data );
|
||||
this.writeSpawnData( dimId, chunkX, chunkZ, data );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasGenerated( final Dimension dim, final int chunkX, final int chunkZ )
|
||||
{
|
||||
int dimId = dim.getType().getId(); // FIXME This is most likely borked, see new string ids
|
||||
|
||||
synchronized( SpawnData.class )
|
||||
{
|
||||
final CompoundNBT data = this.loadSpawnData( dim, chunkX, chunkZ );
|
||||
final CompoundNBT data = this.loadSpawnData( dimId, chunkX, chunkZ );
|
||||
return data.getBoolean( chunkX + "," + chunkZ );
|
||||
}
|
||||
}
|
||||
@@ -83,23 +88,25 @@ final class SpawnData implements IWorldSpawnData
|
||||
@Override
|
||||
public boolean addNearByMeteorites( final Dimension dim, final int chunkX, final int chunkZ, final CompoundNBT newData )
|
||||
{
|
||||
int dimId = dim.getType().getId(); // FIXME This is most likely borked, see new string ids
|
||||
|
||||
synchronized( SpawnData.class )
|
||||
{
|
||||
final CompoundNBT data = this.loadSpawnData( dim, chunkX, chunkZ );
|
||||
final CompoundNBT data = this.loadSpawnData( dimId, chunkX, chunkZ );
|
||||
|
||||
// edit.
|
||||
final int size = data.getInteger( "num" );
|
||||
data.setTag( String.valueOf( size ), newData );
|
||||
data.setInteger( "num", size + 1 );
|
||||
final int size = data.getInt( "num" );
|
||||
data.put( String.valueOf( size ), newData );
|
||||
data.putInt( "num", size + 1 );
|
||||
|
||||
this.writeSpawnData( dim, chunkX, chunkZ, data );
|
||||
this.writeSpawnData( dimId, chunkX, chunkZ, data );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<CompoundNBT> getNearByMeteorites( final int Dimension, final int chunkX, final int chunkZ )
|
||||
public Collection<CompoundNBT> getNearByMeteorites( final Dimension dim, final int chunkX, final int chunkZ )
|
||||
{
|
||||
final Collection<CompoundNBT> ll = new ArrayList<>();
|
||||
|
||||
@@ -112,15 +119,16 @@ final class SpawnData implements IWorldSpawnData
|
||||
final int cx = x + ( chunkX >> 4 );
|
||||
final int cz = z + ( chunkZ >> 4 );
|
||||
|
||||
final CompoundNBT data = this.loadSpawnData( dim, cx << 4, cz << 4 );
|
||||
// FIXME Using the numerical dimension id here is fishy
|
||||
final CompoundNBT data = this.loadSpawnData( dim.getType().getId(), cx << 4, cz << 4 );
|
||||
|
||||
if( data != null )
|
||||
{
|
||||
// edit.
|
||||
final int size = data.getInteger( "num" );
|
||||
final int size = data.getInt( "num" );
|
||||
for( int s = 0; s < size; s++ )
|
||||
{
|
||||
ll.add( data.getCompoundTag( String.valueOf( s ) ) );
|
||||
ll.add( data.getCompound( String.valueOf( s ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,11 +26,10 @@ import java.util.WeakHashMap;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.electronwill.nightconfig.core.CommentedConfig;
|
||||
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
|
||||
import appeng.core.AELog;
|
||||
import appeng.me.GridStorage;
|
||||
import appeng.me.GridStorageSearch;
|
||||
@@ -50,11 +49,11 @@ final class StorageData implements IWorldGridStorageData, IOnWorldStartable, IOn
|
||||
private static final String GRID_STORAGE_CATEGORY = "gridstorage";
|
||||
|
||||
private final Map<GridStorageSearch, WeakReference<GridStorageSearch>> loadedStorage = new WeakHashMap<>( 10 );
|
||||
private final Configuration config;
|
||||
private final CommentedFileConfig config;
|
||||
|
||||
private long lastGridStorage;
|
||||
|
||||
public StorageData( @Nonnull final Configuration settingsFile )
|
||||
public StorageData( @Nonnull final CommentedFileConfig settingsFile )
|
||||
{
|
||||
Preconditions.checkNotNull( settingsFile );
|
||||
|
||||
@@ -72,20 +71,21 @@ final class StorageData implements IWorldGridStorageData, IOnWorldStartable, IOn
|
||||
@Override
|
||||
public GridStorage getGridStorage( final long storageID )
|
||||
{
|
||||
final GridStorageSearch gss = new GridStorageSearch( storageID );
|
||||
final WeakReference<GridStorageSearch> result = this.loadedStorage.get( gss );
|
||||
|
||||
if( result == null || result.get() == null )
|
||||
{
|
||||
final String id = String.valueOf( storageID );
|
||||
final String data = this.config.get( "gridstorage", id, "" ).getString();
|
||||
final GridStorage thisStorage = new GridStorage( data, storageID, gss );
|
||||
gss.setGridStorage( new WeakReference<>( thisStorage ) );
|
||||
this.loadedStorage.put( gss, new WeakReference<>( gss ) );
|
||||
return thisStorage;
|
||||
}
|
||||
|
||||
return result.get().getGridStorage().get();
|
||||
return null;
|
||||
// FIXME final GridStorageSearch gss = new GridStorageSearch( storageID );
|
||||
// FIXME final WeakReference<GridStorageSearch> result = this.loadedStorage.get( gss );
|
||||
// FIXME
|
||||
// FIXME if( result == null || result.get() == null )
|
||||
// FIXME {
|
||||
// FIXME final String id = String.valueOf( storageID );
|
||||
// FIXME final String data = this.config.get( "gridstorage", id, "" ).getString();
|
||||
// FIXME final GridStorage thisStorage = new GridStorage( data, storageID, gss );
|
||||
// FIXME gss.setGridStorage( new WeakReference<>( thisStorage ) );
|
||||
// FIXME this.loadedStorage.put( gss, new WeakReference<>( gss ) );
|
||||
// FIXME return thisStorage;
|
||||
// FIXME }
|
||||
// FIXME
|
||||
// FIXME return result.get().getGridStorage().get();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,59 +107,61 @@ final class StorageData implements IWorldGridStorageData, IOnWorldStartable, IOn
|
||||
@Override
|
||||
public long nextGridStorage()
|
||||
{
|
||||
final long r = this.lastGridStorage;
|
||||
this.lastGridStorage++;
|
||||
this.config.get( "Counters", "lastGridStorage", this.lastGridStorage ).set( Long.toString( this.lastGridStorage ) );
|
||||
return r;
|
||||
// FIXME final long r = this.lastGridStorage;
|
||||
// FIXME this.lastGridStorage++;
|
||||
// FIXME this.config.get( "Counters", "lastGridStorage", this.lastGridStorage ).set( Long.toString( this.lastGridStorage ) );
|
||||
// FIXME return r;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyGridStorage( final long id )
|
||||
{
|
||||
final String stringID = String.valueOf( id );
|
||||
this.config.getCategory( "gridstorage" ).remove( stringID );
|
||||
// FIXME final String stringID = String.valueOf( id );
|
||||
// FIXME this.config.getCategory( "gridstorage" ).remove( stringID );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNextOrderedValue( final String name )
|
||||
{
|
||||
final Property p = this.config.get( "orderedValues", name, 0 );
|
||||
final int myValue = p.getInt();
|
||||
p.set( myValue + 1 );
|
||||
return myValue;
|
||||
// FIXME final Property p = this.config.get( "orderedValues", name, 0 );
|
||||
// FIXME final int myValue = p.getInt();
|
||||
// FIXME p.set( myValue + 1 );
|
||||
// FIXME return myValue;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWorldStart()
|
||||
{
|
||||
final String lastString = this.config.get( LAST_GRID_STORAGE_CATEGORY, LAST_GRID_STORAGE_KEY, LAST_GRID_STORAGE_DEFAULT ).getString();
|
||||
|
||||
try
|
||||
{
|
||||
this.lastGridStorage = Long.parseLong( lastString );
|
||||
}
|
||||
catch( final NumberFormatException err )
|
||||
{
|
||||
AELog.warn( "The config contained a value which was not represented as a Long: %s", lastString );
|
||||
|
||||
this.lastGridStorage = 0;
|
||||
}
|
||||
// FIXME final String lastString = this.config.get( LAST_GRID_STORAGE_CATEGORY, LAST_GRID_STORAGE_KEY, LAST_GRID_STORAGE_DEFAULT ).getString();
|
||||
// FIXME
|
||||
// FIXME try
|
||||
// FIXME {
|
||||
// FIXME this.lastGridStorage = Long.parseLong( lastString );
|
||||
// FIXME }
|
||||
// FIXME catch( final NumberFormatException err )
|
||||
// FIXME {
|
||||
// FIXME AELog.warn( "The config contained a value which was not represented as a Long: %s", lastString );
|
||||
// FIXME
|
||||
// FIXME this.lastGridStorage = 0;
|
||||
// FIXME }
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWorldStop()
|
||||
{
|
||||
// populate new data
|
||||
for( final GridStorageSearch gs : this.loadedStorage.keySet() )
|
||||
{
|
||||
final GridStorage thisStorage = gs.getGridStorage().get();
|
||||
if( thisStorage != null && thisStorage.getGrid() != null && !thisStorage.getGrid().isEmpty() )
|
||||
{
|
||||
final String value = thisStorage.getValue();
|
||||
this.config.get( GRID_STORAGE_CATEGORY, String.valueOf( thisStorage.getID() ), value ).set( value );
|
||||
}
|
||||
}
|
||||
|
||||
this.config.save();
|
||||
// FIXME // populate new data
|
||||
// FIXME for( final GridStorageSearch gs : this.loadedStorage.keySet() )
|
||||
// FIXME {
|
||||
// FIXME final GridStorage thisStorage = gs.getGridStorage().get();
|
||||
// FIXME if( thisStorage != null && thisStorage.getGrid() != null && !thisStorage.getGrid().isEmpty() )
|
||||
// FIXME {
|
||||
// FIXME final String value = thisStorage.getValue();
|
||||
// FIXME this.config.get( GRID_STORAGE_CATEGORY, String.valueOf( thisStorage.getID() ), value ).set( value );
|
||||
// FIXME }
|
||||
// FIXME }
|
||||
// FIXME
|
||||
// FIXME this.config.save();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package appeng.core.worlddata;
|
||||
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
@@ -26,12 +27,17 @@ import java.util.concurrent.ThreadFactory;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
|
||||
import com.electronwill.nightconfig.toml.TomlFormat;
|
||||
import com.electronwill.nightconfig.toml.TomlParser;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.dimension.Dimension;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.services.CompassService;
|
||||
@@ -71,7 +77,7 @@ public final class WorldData implements IWorldData
|
||||
private final File spawnDirectory;
|
||||
private final File compassDirectory;
|
||||
|
||||
// FIXME private final Configuration sharedConfig;
|
||||
private final CommentedFileConfig sharedConfig;
|
||||
|
||||
private WorldData( @Nonnull final File worldDirectory )
|
||||
{
|
||||
@@ -83,7 +89,8 @@ public final class WorldData implements IWorldData
|
||||
this.compassDirectory = new File( this.ae2directory, COMPASS_DIR_NAME );
|
||||
|
||||
final File settingsFile = new File( this.ae2directory, SETTING_FILE_NAME );
|
||||
this.sharedConfig = new Configuration( settingsFile, AEConfig.VERSION );
|
||||
this.sharedConfig = CommentedFileConfig.of( settingsFile, TomlFormat.instance() );
|
||||
this.sharedConfig.load();
|
||||
|
||||
final PlayerData playerData = new PlayerData( this.sharedConfig );
|
||||
final StorageData storageData = new StorageData( this.sharedConfig );
|
||||
@@ -124,10 +131,15 @@ public final class WorldData implements IWorldData
|
||||
*/
|
||||
public static void onServerAboutToStart( MinecraftServer server )
|
||||
{
|
||||
File worldDirectory = DimensionManager.getCurrentSaveRootDirectory();
|
||||
// FIXME: Possibly replace this with WorldData
|
||||
File worldDirectory = null;
|
||||
ServerWorld overworld = DimensionManager.getWorld(server, DimensionType.OVERWORLD, false, false);
|
||||
if (overworld != null) {
|
||||
worldDirectory = overworld.getSaveHandler().getWorldDirectory();
|
||||
}
|
||||
if( worldDirectory == null )
|
||||
{
|
||||
worldDirectory = server.getActiveAnvilConverter().getSaveLoader( server.getFolderName(), false ).getWorldDirectory();
|
||||
worldDirectory = server.getActiveAnvilConverter().getSaveLoader( server.getFolderName(), server ).getWorldDirectory();
|
||||
}
|
||||
final WorldData newInstance = new WorldData( worldDirectory );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user