Work on server data and registries.
This commit is contained in:
@@ -39,7 +39,7 @@ public class BlockColorComponent implements IInitComponent
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize( Dist dist )
|
public void initialize()
|
||||||
{
|
{
|
||||||
Minecraft.getInstance().getBlockColors().register( this.blockColor, this.block );
|
Minecraft.getInstance().getBlockColors().register( this.blockColor, this.block );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,5 +27,5 @@ import appeng.bootstrap.IBootstrapComponent;
|
|||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface IInitComponent extends IBootstrapComponent
|
public interface IInitComponent extends IBootstrapComponent
|
||||||
{
|
{
|
||||||
void initialize( Dist dist );
|
void initialize();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public class ItemColorComponent implements IInitComponent
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize( Dist dist )
|
public void initialize()
|
||||||
{
|
{
|
||||||
Minecraft.getInstance().getItemColors().register( this.itemColor, this.item );
|
Minecraft.getInstance().getItemColors().register( this.itemColor, this.item );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ package appeng.core;
|
|||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import appeng.tile.AEBaseTile;
|
import appeng.tile.AEBaseTile;
|
||||||
|
import appeng.util.Platform;
|
||||||
import org.apache.logging.log4j.Level;
|
import org.apache.logging.log4j.Level;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@@ -56,8 +57,7 @@ public final class AELog
|
|||||||
*/
|
*/
|
||||||
private static Logger getLogger()
|
private static Logger getLogger()
|
||||||
{
|
{
|
||||||
// FIXME return Platform.isServer() ? SERVER : CLIENT;
|
return Platform.isServer() ? SERVER : CLIENT;
|
||||||
throw new IllegalStateException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -24,12 +24,16 @@ import java.lang.reflect.Field;
|
|||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
import appeng.bootstrap.components.IClientSetupComponent;
|
import appeng.bootstrap.components.IClientSetupComponent;
|
||||||
|
import appeng.bootstrap.components.IInitComponent;
|
||||||
import appeng.client.ClientHelper;
|
import appeng.client.ClientHelper;
|
||||||
import appeng.client.render.model.AutoRotatingModel;
|
import appeng.client.render.model.AutoRotatingModel;
|
||||||
import appeng.client.render.model.AutoRotatingModelLoader;
|
import appeng.client.render.model.AutoRotatingModelLoader;
|
||||||
import appeng.client.render.model.GlassModelLoader;
|
import appeng.client.render.model.GlassModelLoader;
|
||||||
import appeng.client.render.model.SkyCompassModelLoader;
|
import appeng.client.render.model.SkyCompassModelLoader;
|
||||||
import appeng.core.stats.AdvancementTriggers;
|
import appeng.core.stats.AdvancementTriggers;
|
||||||
|
import appeng.core.worlddata.WorldData;
|
||||||
|
import appeng.hooks.TickHandler;
|
||||||
|
import appeng.parts.PartPlacement;
|
||||||
import appeng.server.ServerHelper;
|
import appeng.server.ServerHelper;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
@@ -45,6 +49,7 @@ import net.minecraft.util.ResourceLocation;
|
|||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.eventbus.api.IEventBus;
|
import net.minecraftforge.eventbus.api.IEventBus;
|
||||||
import net.minecraftforge.fml.CrashReportExtender;
|
import net.minecraftforge.fml.CrashReportExtender;
|
||||||
import net.minecraftforge.fml.DistExecutor;
|
import net.minecraftforge.fml.DistExecutor;
|
||||||
@@ -58,6 +63,10 @@ import appeng.core.crash.ModCrashEnhancement;
|
|||||||
import appeng.services.export.ExportConfig;
|
import appeng.services.export.ExportConfig;
|
||||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||||
|
import net.minecraftforge.fml.event.server.FMLServerAboutToStartEvent;
|
||||||
|
import net.minecraftforge.fml.event.server.FMLServerStartedEvent;
|
||||||
|
import net.minecraftforge.fml.event.server.FMLServerStoppedEvent;
|
||||||
|
import net.minecraftforge.fml.event.server.FMLServerStoppingEvent;
|
||||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@@ -125,9 +134,22 @@ public final class AppEng
|
|||||||
// Register client-only events
|
// Register client-only events
|
||||||
DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> modEventBus.addListener(this::clientSetup));
|
DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> modEventBus.addListener(this::clientSetup));
|
||||||
DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> modEventBus.addListener(registration::modelRegistryEvent));
|
DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> modEventBus.addListener(registration::modelRegistryEvent));
|
||||||
|
|
||||||
|
MinecraftForge.EVENT_BUS.addListener( TickHandler.INSTANCE::unloadWorld );
|
||||||
|
MinecraftForge.EVENT_BUS.addListener( TickHandler.INSTANCE::onTick );
|
||||||
|
MinecraftForge.EVENT_BUS.addListener( this::serverAboutToStart );
|
||||||
|
MinecraftForge.EVENT_BUS.addListener( this::serverStopped );
|
||||||
|
MinecraftForge.EVENT_BUS.addListener( this::serverStopping );
|
||||||
|
|
||||||
|
MinecraftForge.EVENT_BUS.register( new PartPlacement() );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void commonSetup(FMLCommonSetupEvent event) {
|
private void commonSetup(FMLCommonSetupEvent event) {
|
||||||
|
|
||||||
|
ApiDefinitions definitions = Api.INSTANCE.definitions();
|
||||||
|
definitions.getRegistry().getBootstrapComponents( IInitComponent.class ).forEachRemaining(IInitComponent::initialize);
|
||||||
|
|
||||||
|
Registration.setupInternalRegistries();
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
@@ -283,26 +305,23 @@ public final class AppEng
|
|||||||
//
|
//
|
||||||
// imcHandler.handleIMCEvent( event );
|
// imcHandler.handleIMCEvent( event );
|
||||||
// }
|
// }
|
||||||
//
|
|
||||||
// @EventHandler
|
private void serverAboutToStart( final FMLServerStartedEvent evt )
|
||||||
// private void serverAboutToStart( final FMLServerAboutToStartEvent evt )
|
{
|
||||||
// {
|
WorldData.onServerAboutToStart( evt.getServer() );
|
||||||
// WorldData.onServerAboutToStart( evt.getServer() );
|
}
|
||||||
// }
|
|
||||||
//
|
private void serverStopping( final FMLServerStoppingEvent event )
|
||||||
// @EventHandler
|
{
|
||||||
// private void serverStopping( final FMLServerStoppingEvent event )
|
WorldData.instance().onServerStopping();
|
||||||
// {
|
}
|
||||||
// WorldData.instance().onServerStopping();
|
|
||||||
// }
|
private void serverStopped( final FMLServerStoppedEvent event )
|
||||||
//
|
{
|
||||||
// @EventHandler
|
WorldData.instance().onServerStoppped();
|
||||||
// private void serverStopped( final FMLServerStoppedEvent event )
|
TickHandler.INSTANCE.shutdown();
|
||||||
// {
|
}
|
||||||
// WorldData.instance().onServerStoppped();
|
|
||||||
// TickHandler.INSTANCE.shutdown();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @EventHandler
|
// @EventHandler
|
||||||
// private void serverStarting( final FMLServerStartingEvent evt )
|
// private void serverStarting( final FMLServerStartingEvent evt )
|
||||||
// {
|
// {
|
||||||
|
|||||||
@@ -19,6 +19,15 @@
|
|||||||
package appeng.core;
|
package appeng.core;
|
||||||
|
|
||||||
|
|
||||||
|
import appeng.api.features.IRegistryContainer;
|
||||||
|
import appeng.api.networking.IGridCacheRegistry;
|
||||||
|
import appeng.api.networking.crafting.ICraftingGrid;
|
||||||
|
import appeng.api.networking.energy.IEnergyGrid;
|
||||||
|
import appeng.api.networking.pathing.IPathingGrid;
|
||||||
|
import appeng.api.networking.security.ISecurityGrid;
|
||||||
|
import appeng.api.networking.spatial.ISpatialCache;
|
||||||
|
import appeng.api.networking.storage.IStorageGrid;
|
||||||
|
import appeng.api.networking.ticking.ITickManager;
|
||||||
import appeng.bootstrap.IModelRegistry;
|
import appeng.bootstrap.IModelRegistry;
|
||||||
import appeng.bootstrap.components.*;
|
import appeng.bootstrap.components.*;
|
||||||
import appeng.client.gui.implementations.GuiGrinder;
|
import appeng.client.gui.implementations.GuiGrinder;
|
||||||
@@ -32,7 +41,13 @@ import appeng.client.render.model.SkyCompassModel;
|
|||||||
import appeng.client.render.tesr.SkyChestTESR;
|
import appeng.client.render.tesr.SkyChestTESR;
|
||||||
import appeng.container.implementations.ContainerGrinder;
|
import appeng.container.implementations.ContainerGrinder;
|
||||||
import appeng.container.implementations.ContainerSkyChest;
|
import appeng.container.implementations.ContainerSkyChest;
|
||||||
|
import appeng.core.features.registries.cell.BasicCellHandler;
|
||||||
|
import appeng.core.features.registries.cell.BasicItemCellGuiHandler;
|
||||||
|
import appeng.core.features.registries.cell.CreativeCellHandler;
|
||||||
import appeng.core.stats.AeStats;
|
import appeng.core.stats.AeStats;
|
||||||
|
import appeng.core.stats.PartItemPredicate;
|
||||||
|
import appeng.fluids.registries.BasicFluidCellGuiHandler;
|
||||||
|
import appeng.me.cache.*;
|
||||||
import appeng.recipes.conditions.FeaturesEnabled;
|
import appeng.recipes.conditions.FeaturesEnabled;
|
||||||
import appeng.recipes.game.DisassembleRecipe;
|
import appeng.recipes.game.DisassembleRecipe;
|
||||||
import appeng.recipes.ingredients.PartIngredientSerializer;
|
import appeng.recipes.ingredients.PartIngredientSerializer;
|
||||||
@@ -46,6 +61,7 @@ import net.minecraft.inventory.container.ContainerType;
|
|||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.crafting.IRecipeSerializer;
|
import net.minecraft.item.crafting.IRecipeSerializer;
|
||||||
import net.minecraft.particles.ParticleType;
|
import net.minecraft.particles.ParticleType;
|
||||||
|
import net.minecraft.stats.Stats;
|
||||||
import net.minecraft.tileentity.TileEntityType;
|
import net.minecraft.tileentity.TileEntityType;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
@@ -150,50 +166,39 @@ final class Registration
|
|||||||
// {
|
// {
|
||||||
// registry.addNewSubItemResolver( new AEItemResolver() );
|
// registry.addNewSubItemResolver( new AEItemResolver() );
|
||||||
// }
|
// }
|
||||||
//
|
|
||||||
// public void initialize( @Nonnull final FMLInitializationEvent event, @Nonnull final File recipeDirectory )
|
public static void setupInternalRegistries()
|
||||||
// {
|
{
|
||||||
// Preconditions.checkNotNull( event );
|
final Api api = Api.INSTANCE;
|
||||||
// Preconditions.checkNotNull( recipeDirectory );
|
final IRegistryContainer registries = api.registries();
|
||||||
// Preconditions.checkArgument( !recipeDirectory.isFile() );
|
|
||||||
//
|
final IGridCacheRegistry gcr = registries.gridCache();
|
||||||
// final Api api = Api.INSTANCE;
|
gcr.registerGridCache( ITickManager.class, TickManagerCache.class );
|
||||||
// final IRegistryContainer registries = api.registries();
|
gcr.registerGridCache( IEnergyGrid.class, EnergyGridCache.class );
|
||||||
//
|
gcr.registerGridCache( IPathingGrid.class, PathGridCache.class );
|
||||||
// ApiDefinitions definitions = api.definitions();
|
gcr.registerGridCache( IStorageGrid.class, GridStorageCache.class );
|
||||||
// definitions.getRegistry().getBootstrapComponents( IInitComponent.class ).forEachRemaining( b -> b.initialize( event.getSide() ) );
|
gcr.registerGridCache( P2PCache.class, P2PCache.class );
|
||||||
//
|
gcr.registerGridCache( ISpatialCache.class, SpatialPylonCache.class );
|
||||||
// MinecraftForge.EVENT_BUS.register( TickHandler.INSTANCE );
|
gcr.registerGridCache( ISecurityGrid.class, SecurityCache.class );
|
||||||
//
|
gcr.registerGridCache( ICraftingGrid.class, CraftingGridCache.class );
|
||||||
// MinecraftForge.EVENT_BUS.register( new PartPlacement() );
|
|
||||||
//
|
registries.cell().addCellHandler( new BasicCellHandler() );
|
||||||
// final IGridCacheRegistry gcr = registries.gridCache();
|
registries.cell().addCellHandler( new CreativeCellHandler() );
|
||||||
// gcr.registerGridCache( ITickManager.class, TickManagerCache.class );
|
registries.cell().addCellGuiHandler( new BasicItemCellGuiHandler() );
|
||||||
// gcr.registerGridCache( IEnergyGrid.class, EnergyGridCache.class );
|
registries.cell().addCellGuiHandler( new BasicFluidCellGuiHandler() );
|
||||||
// gcr.registerGridCache( IPathingGrid.class, PathGridCache.class );
|
|
||||||
// gcr.registerGridCache( IStorageGrid.class, GridStorageCache.class );
|
api.definitions().materials().matterBall().maybeStack( 1 ).ifPresent( ammoStack ->
|
||||||
// gcr.registerGridCache( P2PCache.class, P2PCache.class );
|
{
|
||||||
// gcr.registerGridCache( ISpatialCache.class, SpatialPylonCache.class );
|
final double weight = 32;
|
||||||
// gcr.registerGridCache( ISecurityGrid.class, SecurityCache.class );
|
|
||||||
// gcr.registerGridCache( ICraftingGrid.class, CraftingGridCache.class );
|
registries.matterCannon().registerAmmo( ammoStack, weight );
|
||||||
//
|
} );
|
||||||
// registries.cell().addCellHandler( new BasicCellHandler() );
|
|
||||||
// registries.cell().addCellHandler( new CreativeCellHandler() );
|
PartItemPredicate.register();
|
||||||
// registries.cell().addCellGuiHandler( new BasicItemCellGuiHandler() );
|
// FIXME Stats.register();
|
||||||
// registries.cell().addCellGuiHandler( new BasicFluidCellGuiHandler() );
|
// FIXME this.advancementTriggers = new AdvancementTriggers( new CriterionTrigggerRegistry() );
|
||||||
//
|
}
|
||||||
// api.definitions().materials().matterBall().maybeStack( 1 ).ifPresent( ammoStack ->
|
|
||||||
// {
|
|
||||||
// final double weight = 32;
|
|
||||||
//
|
|
||||||
// registries.matterCannon().registerAmmo( ammoStack, weight );
|
|
||||||
// } );
|
|
||||||
//
|
|
||||||
// PartItemPredicate.register();
|
|
||||||
// Stats.register();
|
|
||||||
// this.advancementTriggers = new AdvancementTriggers( new CriterionTrigggerRegistry() );
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @SubscribeEvent
|
// @SubscribeEvent
|
||||||
// public void registerBiomes( RegistryEvent.Register<Biome> event )
|
// public void registerBiomes( RegistryEvent.Register<Biome> event )
|
||||||
// {
|
// {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ package appeng.core.features.registries;
|
|||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import appeng.core.AppEng;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
@@ -28,6 +29,8 @@ import net.minecraft.entity.player.PlayerEntity;
|
|||||||
import appeng.api.features.IPlayerRegistry;
|
import appeng.api.features.IPlayerRegistry;
|
||||||
import appeng.core.worlddata.WorldData;
|
import appeng.core.worlddata.WorldData;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
||||||
public class PlayerRegistry implements IPlayerRegistry
|
public class PlayerRegistry implements IPlayerRegistry
|
||||||
{
|
{
|
||||||
@@ -40,7 +43,7 @@ public class PlayerRegistry implements IPlayerRegistry
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return WorldData.instance().playerData().getPlayerID( username );
|
return WorldData.instance().playerData().getMePlayerId( username );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -53,6 +56,19 @@ public class PlayerRegistry implements IPlayerRegistry
|
|||||||
@Override
|
@Override
|
||||||
public PlayerEntity findPlayer( final int playerID )
|
public PlayerEntity findPlayer( final int playerID )
|
||||||
{
|
{
|
||||||
return WorldData.instance().playerData().getPlayerFromID( playerID );
|
UUID profileId = WorldData.instance().playerData().getProfileId(playerID);
|
||||||
|
if (profileId == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
for( final PlayerEntity player : AppEng.proxy.getPlayers() )
|
||||||
|
{
|
||||||
|
if( player.getUniqueID().equals( profileId ) )
|
||||||
|
{
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import appeng.services.CompassService;
|
|||||||
* @version rv3 - 30.05.2015
|
* @version rv3 - 30.05.2015
|
||||||
* @since rv3 30.05.2015
|
* @since rv3 30.05.2015
|
||||||
*/
|
*/
|
||||||
final class CompassData implements IWorldCompassData, IOnWorldStoppable
|
final class CompassData implements IWorldCompassData
|
||||||
{
|
{
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private final CompassService service;
|
private final CompassService service;
|
||||||
@@ -52,9 +52,4 @@ final class CompassData implements IWorldCompassData, IOnWorldStoppable
|
|||||||
return this.service;
|
return this.service;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onWorldStop()
|
|
||||||
{
|
|
||||||
this.service.kill();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Applied Energistics 2.
|
|
||||||
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
|
|
||||||
*
|
|
||||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package appeng.core.worlddata;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author thatsIch
|
|
||||||
* @version rv3 - 30.05.2015
|
|
||||||
* @since rv3 30.05.2015
|
|
||||||
*/
|
|
||||||
public interface IOnWorldStartable
|
|
||||||
{
|
|
||||||
void onWorldStart();
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Applied Energistics 2.
|
|
||||||
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
|
|
||||||
*
|
|
||||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package appeng.core.worlddata;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author thatsIch
|
|
||||||
* @version rv3 - 30.05.2015
|
|
||||||
* @since rv3 30.05.2015
|
|
||||||
*/
|
|
||||||
public interface IOnWorldStoppable
|
|
||||||
{
|
|
||||||
void onWorldStop();
|
|
||||||
}
|
|
||||||
@@ -32,15 +32,12 @@ import appeng.me.GridStorage;
|
|||||||
*/
|
*/
|
||||||
public interface IWorldGridStorageData
|
public interface IWorldGridStorageData
|
||||||
{
|
{
|
||||||
@Nullable
|
|
||||||
GridStorage getGridStorage( long storageID );
|
GridStorage getGridStorage( long storageID );
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
GridStorage getNewGridStorage();
|
GridStorage getNewGridStorage();
|
||||||
|
|
||||||
long nextGridStorage();
|
|
||||||
|
|
||||||
void destroyGridStorage( long id );
|
void destroyGridStorage( long id );
|
||||||
|
|
||||||
int getNextOrderedValue( String name );
|
int getNextOrderedValue( String name, int firstValue );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ import com.mojang.authlib.GameProfile;
|
|||||||
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author thatsIch
|
* @author thatsIch
|
||||||
@@ -33,8 +35,13 @@ import net.minecraft.entity.player.PlayerEntity;
|
|||||||
*/
|
*/
|
||||||
public interface IWorldPlayerData
|
public interface IWorldPlayerData
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Gets the UUID of the Minecraft profile associated with the given ME player id.
|
||||||
|
* @param playerID An ME player id.
|
||||||
|
* @return Null if the ME player id is unknown, otherwise the unique id of the Minecraft profile it originates from.
|
||||||
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
PlayerEntity getPlayerFromID( int playerID );
|
UUID getProfileId(int playerID );
|
||||||
|
|
||||||
int getPlayerID( GameProfile profile );
|
int getMePlayerId(GameProfile profile );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,54 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Applied Energistics 2.
|
|
||||||
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
|
|
||||||
*
|
|
||||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package appeng.core.worlddata;
|
|
||||||
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author thatsIch
|
|
||||||
* @version rv3 - 30.05.2015
|
|
||||||
* @since rv3 30.05.2015
|
|
||||||
*/
|
|
||||||
public interface IWorldPlayerMapping
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Tries to retrieve the UUID of a player.
|
|
||||||
* Might not be stored inside of the map.
|
|
||||||
* Should not happen though.
|
|
||||||
*
|
|
||||||
* @param id ID of the to be searched player
|
|
||||||
*
|
|
||||||
* @return maybe the UUID of the searched player
|
|
||||||
*/
|
|
||||||
@Nonnull
|
|
||||||
Optional<UUID> get( int id );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Put in new players when they join the server
|
|
||||||
*
|
|
||||||
* @param id id of new player
|
|
||||||
* @param uuid UUID of new player
|
|
||||||
*/
|
|
||||||
void put( int id, @Nonnull UUID uuid );
|
|
||||||
}
|
|
||||||
@@ -19,19 +19,19 @@
|
|||||||
package appeng.core.worlddata;
|
package appeng.core.worlddata;
|
||||||
|
|
||||||
|
|
||||||
import java.util.Optional;
|
import appeng.core.AELog;
|
||||||
import java.util.UUID;
|
import appeng.core.AppEng;
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
|
import com.google.common.collect.BiMap;
|
||||||
|
import com.google.common.collect.HashBiMap;
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import net.minecraft.nbt.CompoundNBT;
|
||||||
|
import net.minecraft.world.storage.WorldSavedData;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.Map;
|
||||||
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
|
import java.util.UUID;
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
import com.mojang.authlib.GameProfile;
|
|
||||||
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
|
|
||||||
import appeng.core.AppEng;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,97 +43,83 @@ import appeng.core.AppEng;
|
|||||||
* @version rv3 - 30.05.2015
|
* @version rv3 - 30.05.2015
|
||||||
* @since rv3 30.05.2015
|
* @since rv3 30.05.2015
|
||||||
*/
|
*/
|
||||||
final class PlayerData implements IWorldPlayerData, IOnWorldStartable, IOnWorldStoppable
|
final class PlayerData extends WorldSavedData implements IWorldPlayerData {
|
||||||
{
|
|
||||||
private static final String LAST_PLAYER_CATEGORY = "Counters";
|
|
||||||
private static final String LAST_PLAYER_KEY = "lastPlayer";
|
|
||||||
private static final int LAST_PLAYER_DEFAULT = 0;
|
|
||||||
|
|
||||||
private final CommentedFileConfig config;
|
public static final String NAME = AppEng.MOD_ID + "_players";
|
||||||
// FIXME private final IWorldPlayerMapping playerMapping;
|
public static final String TAG_PLAYER_IDS = "playerIds";
|
||||||
|
public static final String TAG_PROFILE_IDS = "profileIds";
|
||||||
|
|
||||||
private int lastPlayerID;
|
private final BiMap<UUID, Integer> mapping = HashBiMap.create();
|
||||||
|
|
||||||
public PlayerData( @Nonnull final CommentedFileConfig configFile )
|
// Caches the highest assigned player id + 1
|
||||||
{
|
private int nextPlayerId = 0;
|
||||||
Preconditions.checkNotNull( configFile );
|
|
||||||
|
|
||||||
this.config = configFile;
|
public PlayerData() {
|
||||||
|
super(NAME);
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME this.playerMapping = new PlayerMapping( config, "players." );
|
@Nullable
|
||||||
}
|
@Override
|
||||||
|
public UUID getProfileId(final int playerId) {
|
||||||
|
return this.mapping.inverse().get(playerId);
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Override
|
||||||
@Override
|
public int getMePlayerId(@Nonnull final GameProfile profile) {
|
||||||
public PlayerEntity getPlayerFromID( final int playerID )
|
Preconditions.checkNotNull(profile);
|
||||||
{
|
|
||||||
// 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;
|
final UUID uuid = profile.getId();
|
||||||
}
|
Integer playerId = mapping.get(uuid);
|
||||||
|
|
||||||
@Override
|
if (playerId == null) {
|
||||||
public int getPlayerID( @Nonnull final GameProfile profile )
|
playerId = this.nextPlayerId++;
|
||||||
{
|
this.mapping.put(profile.getId(), playerId);
|
||||||
return -1;
|
markDirty();
|
||||||
// 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()
|
AELog.info("Assigning ME player id {} to Minecraft profile {} ({})", playerId, profile.getId(), profile.getName());
|
||||||
{
|
}
|
||||||
// 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
|
return playerId;
|
||||||
public void onWorldStart()
|
}
|
||||||
{
|
|
||||||
// FIXME this.lastPlayerID = this.config.get( LAST_PLAYER_CATEGORY, LAST_PLAYER_KEY, LAST_PLAYER_DEFAULT ).getInt( LAST_PLAYER_DEFAULT );
|
|
||||||
|
|
||||||
this.config.save();
|
@Override
|
||||||
}
|
public void read(CompoundNBT nbt) {
|
||||||
|
int[] playerIds = nbt.getIntArray(TAG_PLAYER_IDS);
|
||||||
|
long[] profileIds = nbt.getLongArray(TAG_PROFILE_IDS);
|
||||||
|
|
||||||
@Override
|
if (playerIds.length * 2 != profileIds.length) {
|
||||||
public void onWorldStop()
|
throw new IllegalStateException("Plaer ID mapping is corrupted. "
|
||||||
{
|
+ playerIds.length + " player IDs vs. " + profileIds.length
|
||||||
this.config.save();
|
+ " profile IDs (latter must be 2 * the former)");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.mapping.clear();
|
||||||
|
int highestPlayerId = -1;
|
||||||
|
for (int i = 0; i < playerIds.length; i++) {
|
||||||
|
int playerId = playerIds[i];
|
||||||
|
UUID profileId = new UUID(profileIds[i * 2], profileIds[i * 2 + 1]);
|
||||||
|
highestPlayerId = Math.max(playerId, highestPlayerId);
|
||||||
|
mapping.put(profileId, playerId);
|
||||||
|
AELog.debug("AE player ID {} is assigned to profile ID {}", playerId, profileId);
|
||||||
|
}
|
||||||
|
this.nextPlayerId = highestPlayerId + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompoundNBT write(CompoundNBT compound) {
|
||||||
|
int index = 0;
|
||||||
|
int[] playerIds = new int[mapping.size()];
|
||||||
|
long[] profileIds = new long[mapping.size() * 2];
|
||||||
|
for (Map.Entry<UUID, Integer> entry : mapping.entrySet()) {
|
||||||
|
profileIds[index * 2] = entry.getKey().getMostSignificantBits();
|
||||||
|
profileIds[index * 2 + 1] = entry.getKey().getLeastSignificantBits();
|
||||||
|
playerIds[index++] = entry.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
compound.putIntArray(TAG_PLAYER_IDS, playerIds);
|
||||||
|
compound.putLongArray(TAG_PROFILE_IDS, profileIds);
|
||||||
|
|
||||||
|
return compound;
|
||||||
|
}
|
||||||
|
|
||||||
this.lastPlayerID = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,69 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Applied Energistics 2.
|
|
||||||
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
|
|
||||||
*
|
|
||||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package appeng.core.worlddata;
|
|
||||||
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
import com.electronwill.nightconfig.core.Config;
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrapper class for the player mappings.
|
|
||||||
* Will grant access to a pre initialized player map
|
|
||||||
* based on the "players" category in the settings.cfg
|
|
||||||
*/
|
|
||||||
final class PlayerMapping implements IWorldPlayerMapping
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* View of player mappings, is not immutable,
|
|
||||||
* since it needs to be edited upon runtime,
|
|
||||||
* cause new players can join
|
|
||||||
*/
|
|
||||||
private final Map<Integer, UUID> mappings;
|
|
||||||
|
|
||||||
public PlayerMapping( final Config config, String path )
|
|
||||||
{
|
|
||||||
final PlayerMappingsInitializer init = new PlayerMappingsInitializer( config, path );
|
|
||||||
|
|
||||||
this.mappings = init.getPlayerMappings();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
public Optional<UUID> get( final int id )
|
|
||||||
{
|
|
||||||
final UUID maybe = this.mappings.get( id );
|
|
||||||
|
|
||||||
return Optional.ofNullable( maybe );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void put( final int id, @Nonnull final UUID uuid )
|
|
||||||
{
|
|
||||||
Preconditions.checkNotNull( uuid );
|
|
||||||
|
|
||||||
this.mappings.put( id, uuid );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Applied Energistics 2.
|
|
||||||
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
|
|
||||||
*
|
|
||||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package appeng.core.worlddata;
|
|
||||||
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import com.electronwill.nightconfig.core.Config;
|
|
||||||
|
|
||||||
import appeng.core.AELog;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes a map of ID to UUID from the player list in the settings.cfg
|
|
||||||
*/
|
|
||||||
class PlayerMappingsInitializer
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Internal immutable mapping
|
|
||||||
*/
|
|
||||||
// FIXME private final Map<Integer, UUID> playerMappings;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the initializer for the player mappings.
|
|
||||||
* The map will be filled upon construction
|
|
||||||
* and will only be filled with valid entries.
|
|
||||||
* If an invalid entry is found, an warning is printed,
|
|
||||||
* mostly due to migration problems from 1.7.2 to 1.7.10
|
|
||||||
* where the UUIDs were introduced.
|
|
||||||
*
|
|
||||||
* @param playerList the category for the player list, generally extracted using the "players" tag
|
|
||||||
*/
|
|
||||||
PlayerMappingsInitializer(final Config config, String prefix )
|
|
||||||
{
|
|
||||||
// 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 }
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Getter
|
|
||||||
*
|
|
||||||
* @return Immutable map of the players mappings of their ID to their UUID
|
|
||||||
*/
|
|
||||||
public Map<Integer, UUID> getPlayerMappings()
|
|
||||||
{
|
|
||||||
return Collections.emptyMap(); //this.playerMappings; //FIXME
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -19,20 +19,15 @@
|
|||||||
package appeng.core.worlddata;
|
package appeng.core.worlddata;
|
||||||
|
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import appeng.core.AELog;
|
||||||
import java.util.Map;
|
import appeng.core.AppEng;
|
||||||
import java.util.WeakHashMap;
|
import appeng.me.GridStorage;
|
||||||
|
import net.minecraft.nbt.CompoundNBT;
|
||||||
|
import net.minecraft.world.storage.WorldSavedData;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import com.electronwill.nightconfig.core.CommentedConfig;
|
|
||||||
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
|
|
||||||
import appeng.core.AELog;
|
|
||||||
import appeng.me.GridStorage;
|
|
||||||
import appeng.me.GridStorageSearch;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -40,24 +35,26 @@ import appeng.me.GridStorageSearch;
|
|||||||
* @version rv3 - 30.05.2015
|
* @version rv3 - 30.05.2015
|
||||||
* @since rv3 30.05.2015
|
* @since rv3 30.05.2015
|
||||||
*/
|
*/
|
||||||
final class StorageData implements IWorldGridStorageData, IOnWorldStartable, IOnWorldStoppable
|
final class StorageData extends WorldSavedData implements IWorldGridStorageData
|
||||||
{
|
{
|
||||||
private static final String LAST_GRID_STORAGE_CATEGORY = "Counters";
|
|
||||||
private static final String LAST_GRID_STORAGE_KEY = "lastGridStorage";
|
|
||||||
private static final int LAST_GRID_STORAGE_DEFAULT = 0;
|
|
||||||
|
|
||||||
private static final String GRID_STORAGE_CATEGORY = "gridstorage";
|
public static final String NAME = AppEng.MOD_ID + "_storage";
|
||||||
|
|
||||||
private final Map<GridStorageSearch, WeakReference<GridStorageSearch>> loadedStorage = new WeakHashMap<>( 10 );
|
private static final String TAG_NEXT_ID = "nextId";
|
||||||
private final CommentedFileConfig config;
|
public static final String TAG_ORDERED_VALUES = "orderedValues";
|
||||||
|
public static final String TAG_STORAGE = "storage";
|
||||||
|
|
||||||
private long lastGridStorage;
|
private final Map<Long, GridStorage> storage = new HashMap<>();
|
||||||
|
|
||||||
public StorageData( @Nonnull final CommentedFileConfig settingsFile )
|
// id that will be assigned to the next new grid, this needs to be persisted
|
||||||
{
|
// because grids can be removed and we do not want to re-assign the same id twice
|
||||||
Preconditions.checkNotNull( settingsFile );
|
private long nextGridId;
|
||||||
|
|
||||||
this.config = settingsFile;
|
// Stores once-per-save values. I.e. which storage press to drop next in a spawned meteor
|
||||||
|
private final Map<String, Integer> orderedValues = new HashMap<>();
|
||||||
|
|
||||||
|
public StorageData() {
|
||||||
|
super(NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -67,25 +64,18 @@ final class StorageData implements IWorldGridStorageData, IOnWorldStartable, IOn
|
|||||||
*
|
*
|
||||||
* @return corresponding grid storage
|
* @return corresponding grid storage
|
||||||
*/
|
*/
|
||||||
@Nullable
|
|
||||||
@Override
|
@Override
|
||||||
public GridStorage getGridStorage( final long storageID )
|
public GridStorage getGridStorage( final long storageID )
|
||||||
{
|
{
|
||||||
return null;
|
GridStorage result = storage.get(storageID);
|
||||||
// FIXME final GridStorageSearch gss = new GridStorageSearch( storageID );
|
|
||||||
// FIXME final WeakReference<GridStorageSearch> result = this.loadedStorage.get( gss );
|
if( result == null )
|
||||||
// FIXME
|
{
|
||||||
// FIXME if( result == null || result.get() == null )
|
result = new GridStorage(storageID);
|
||||||
// FIXME {
|
storage.put(storageID, result);
|
||||||
// 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 );
|
return result;
|
||||||
// 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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -95,73 +85,80 @@ final class StorageData implements IWorldGridStorageData, IOnWorldStartable, IOn
|
|||||||
@Override
|
@Override
|
||||||
public GridStorage getNewGridStorage()
|
public GridStorage getNewGridStorage()
|
||||||
{
|
{
|
||||||
final long storageID = this.nextGridStorage();
|
return getGridStorage(nextGridId++);
|
||||||
final GridStorageSearch gss = new GridStorageSearch( storageID );
|
|
||||||
final GridStorage newStorage = new GridStorage( storageID, gss );
|
|
||||||
gss.setGridStorage( new WeakReference<>( newStorage ) );
|
|
||||||
this.loadedStorage.put( gss, new WeakReference<>( gss ) );
|
|
||||||
|
|
||||||
return newStorage;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long nextGridStorage()
|
|
||||||
{
|
|
||||||
// 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
|
@Override
|
||||||
public void destroyGridStorage( final long id )
|
public void destroyGridStorage( final long id )
|
||||||
{
|
{
|
||||||
// FIXME final String stringID = String.valueOf( id );
|
this.storage.remove(id);
|
||||||
// FIXME this.config.getCategory( "gridstorage" ).remove( stringID );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getNextOrderedValue( final String name )
|
public int getNextOrderedValue( final String name, int firstValue )
|
||||||
{
|
{
|
||||||
// FIXME final Property p = this.config.get( "orderedValues", name, 0 );
|
return orderedValues.merge(name, firstValue, (oldValue, value) -> oldValue + 1);
|
||||||
// FIXME final int myValue = p.getInt();
|
|
||||||
// FIXME p.set( myValue + 1 );
|
|
||||||
// FIXME return myValue;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onWorldStart()
|
public void read(CompoundNBT tag) {
|
||||||
{
|
|
||||||
// FIXME final String lastString = this.config.get( LAST_GRID_STORAGE_CATEGORY, LAST_GRID_STORAGE_KEY, LAST_GRID_STORAGE_DEFAULT ).getString();
|
nextGridId = tag.getLong(TAG_NEXT_ID);
|
||||||
// FIXME
|
|
||||||
// FIXME try
|
// Load serialized grid storage
|
||||||
// FIXME {
|
CompoundNBT storageTag = tag.getCompound(TAG_STORAGE);
|
||||||
// FIXME this.lastGridStorage = Long.parseLong( lastString );
|
for (String storageIdStr : storageTag.keySet()) {
|
||||||
// FIXME }
|
long storageId;
|
||||||
// FIXME catch( final NumberFormatException err )
|
try {
|
||||||
// FIXME {
|
storageId = Long.parseLong(storageIdStr);
|
||||||
// FIXME AELog.warn( "The config contained a value which was not represented as a Long: %s", lastString );
|
} catch (NumberFormatException e) {
|
||||||
// FIXME
|
AELog.warn("Unable to load grid storage with malformed id: '{}'", storageIdStr);
|
||||||
// FIXME this.lastGridStorage = 0;
|
continue;
|
||||||
// FIXME }
|
}
|
||||||
|
storage.put(storageId, new GridStorage(storageId, storageTag.getCompound(storageIdStr)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load ordered values map
|
||||||
|
CompoundNBT orderedValuesTag = tag.getCompound(TAG_ORDERED_VALUES);
|
||||||
|
this.orderedValues.clear();
|
||||||
|
for (String key : orderedValuesTag.keySet()) {
|
||||||
|
this.orderedValues.put(key, orderedValuesTag.getInt(key));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onWorldStop()
|
public CompoundNBT write(CompoundNBT tag) {
|
||||||
{
|
|
||||||
// FIXME // populate new data
|
tag.putLong(TAG_NEXT_ID, nextGridId);
|
||||||
// FIXME for( final GridStorageSearch gs : this.loadedStorage.keySet() )
|
|
||||||
// FIXME {
|
// Save serialized grid storage
|
||||||
// FIXME final GridStorage thisStorage = gs.getGridStorage().get();
|
CompoundNBT storageTag = new CompoundNBT();
|
||||||
// FIXME if( thisStorage != null && thisStorage.getGrid() != null && !thisStorage.getGrid().isEmpty() )
|
for (Map.Entry<Long, GridStorage> entry : storage.entrySet()) {
|
||||||
// FIXME {
|
|
||||||
// FIXME final String value = thisStorage.getValue();
|
GridStorage gridStorage = entry.getValue();
|
||||||
// FIXME this.config.get( GRID_STORAGE_CATEGORY, String.valueOf( thisStorage.getID() ), value ).set( value );
|
|
||||||
// FIXME }
|
if (gridStorage.getGrid() == null || gridStorage.getGrid().isEmpty()) {
|
||||||
// FIXME }
|
continue;
|
||||||
// FIXME
|
}
|
||||||
// FIXME this.config.save();
|
|
||||||
|
try {
|
||||||
|
entry.getValue().saveState();
|
||||||
|
} catch (Exception e) {
|
||||||
|
AELog.warn("Failed to save state of Grid {}, storing last known value instead.", entry.getKey(), e);
|
||||||
|
}
|
||||||
|
storageTag.put(String.valueOf(entry.getKey()), entry.getValue().dataObject());
|
||||||
|
}
|
||||||
|
tag.put(TAG_STORAGE, storageTag);
|
||||||
|
|
||||||
|
// Save ordered values
|
||||||
|
CompoundNBT orderedValuesTag = new CompoundNBT();
|
||||||
|
for (Map.Entry<String, Integer> entry : orderedValues.entrySet()) {
|
||||||
|
orderedValuesTag.putInt(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
tag.put(TAG_ORDERED_VALUES, orderedValuesTag);
|
||||||
|
|
||||||
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,30 +19,14 @@
|
|||||||
package appeng.core.worlddata;
|
package appeng.core.worlddata;
|
||||||
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import com.google.common.base.Preconditions;
|
||||||
import java.io.File;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import java.util.List;
|
import net.minecraft.world.dimension.DimensionType;
|
||||||
import java.util.concurrent.ThreadFactory;
|
import net.minecraft.world.server.ServerWorld;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
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 appeng.core.AEConfig;
|
|
||||||
import appeng.services.CompassService;
|
|
||||||
import appeng.services.compass.CompassThreadFactory;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Singleton access to anything related to world-based data.
|
* Singleton access to anything related to world-based data.
|
||||||
@@ -57,11 +41,10 @@ import appeng.services.compass.CompassThreadFactory;
|
|||||||
*/
|
*/
|
||||||
public final class WorldData implements IWorldData
|
public final class WorldData implements IWorldData
|
||||||
{
|
{
|
||||||
private static final String AE2_DIRECTORY_NAME = "AE2";
|
|
||||||
private static final String SETTING_FILE_NAME = "settings.cfg";
|
|
||||||
private static final String SPAWNDATA_DIR_NAME = "spawndata";
|
|
||||||
private static final String COMPASS_DIR_NAME = "compass";
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is null while no MinecraftServer exists.
|
||||||
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
private static IWorldData instance;
|
private static IWorldData instance;
|
||||||
|
|
||||||
@@ -70,44 +53,29 @@ public final class WorldData implements IWorldData
|
|||||||
private final IWorldCompassData compassData;
|
private final IWorldCompassData compassData;
|
||||||
private final IWorldSpawnData spawnData;
|
private final IWorldSpawnData spawnData;
|
||||||
|
|
||||||
private final List<IOnWorldStartable> startables;
|
private WorldData( @Nonnull final MinecraftServer server )
|
||||||
private final List<IOnWorldStoppable> stoppables;
|
|
||||||
|
|
||||||
private final File ae2directory;
|
|
||||||
private final File spawnDirectory;
|
|
||||||
private final File compassDirectory;
|
|
||||||
|
|
||||||
private final CommentedFileConfig sharedConfig;
|
|
||||||
|
|
||||||
private WorldData( @Nonnull final File worldDirectory )
|
|
||||||
{
|
{
|
||||||
Preconditions.checkNotNull( worldDirectory );
|
Preconditions.checkNotNull( server );
|
||||||
Preconditions.checkArgument( worldDirectory.isDirectory() );
|
|
||||||
|
|
||||||
this.ae2directory = new File( worldDirectory, AE2_DIRECTORY_NAME );
|
// Attach shared data to the server's overworld dimension
|
||||||
this.spawnDirectory = new File( this.ae2directory, SPAWNDATA_DIR_NAME );
|
ServerWorld overworld = server.getWorld(DimensionType.OVERWORLD);
|
||||||
this.compassDirectory = new File( this.ae2directory, COMPASS_DIR_NAME );
|
if (overworld == null) {
|
||||||
|
throw new IllegalStateException("The server doesn't have an Overworld dimension we could store our data on!");
|
||||||
|
}
|
||||||
|
|
||||||
final File settingsFile = new File( this.ae2directory, SETTING_FILE_NAME );
|
final PlayerData playerData = overworld.getSavedData().getOrCreate(PlayerData::new, PlayerData.NAME);
|
||||||
this.sharedConfig = CommentedFileConfig.of( settingsFile, TomlFormat.instance() );
|
final StorageData storageData = overworld.getSavedData().getOrCreate(StorageData::new, StorageData.NAME);
|
||||||
this.sharedConfig.load();
|
|
||||||
|
|
||||||
final PlayerData playerData = new PlayerData( this.sharedConfig );
|
// final ThreadFactory compassThreadFactory = new CompassThreadFactory();
|
||||||
final StorageData storageData = new StorageData( this.sharedConfig );
|
// final CompassService compassService = new CompassService( this.compassDirectory, compassThreadFactory );
|
||||||
|
// final CompassData compassData = new CompassData( this.compassDirectory, compassService );
|
||||||
final ThreadFactory compassThreadFactory = new CompassThreadFactory();
|
//
|
||||||
final CompassService compassService = new CompassService( this.compassDirectory, compassThreadFactory );
|
// final IWorldSpawnData spawnData = new SpawnData( this.spawnDirectory );
|
||||||
final CompassData compassData = new CompassData( this.compassDirectory, compassService );
|
|
||||||
|
|
||||||
final IWorldSpawnData spawnData = new SpawnData( this.spawnDirectory );
|
|
||||||
|
|
||||||
this.playerData = playerData;
|
this.playerData = playerData;
|
||||||
this.storageData = storageData;
|
this.storageData = storageData;
|
||||||
this.compassData = compassData;
|
this.compassData = null; // compassData;
|
||||||
this.spawnData = spawnData;
|
this.spawnData = null; // spawnData;
|
||||||
|
|
||||||
this.startables = Lists.<IOnWorldStartable>newArrayList( playerData, storageData );
|
|
||||||
this.stoppables = Lists.<IOnWorldStoppable>newArrayList( playerData, storageData, compassData );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -131,65 +99,19 @@ public final class WorldData implements IWorldData
|
|||||||
*/
|
*/
|
||||||
public static void onServerAboutToStart( MinecraftServer server )
|
public static void onServerAboutToStart( MinecraftServer server )
|
||||||
{
|
{
|
||||||
// FIXME: Possibly replace this with WorldData
|
instance = new WorldData(server);
|
||||||
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(), server ).getWorldDirectory();
|
|
||||||
}
|
|
||||||
final WorldData newInstance = new WorldData( worldDirectory );
|
|
||||||
|
|
||||||
instance = newInstance;
|
|
||||||
newInstance.onServerStarting();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onServerStarting()
|
|
||||||
{
|
|
||||||
// check if ae2 folder already exists, else create
|
|
||||||
if( !this.ae2directory.isDirectory() && !this.ae2directory.mkdir() )
|
|
||||||
{
|
|
||||||
throw new IllegalStateException( "Failed to create " + this.ae2directory.getAbsolutePath() );
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if compass folder already exists, else create
|
|
||||||
if( !this.compassDirectory.isDirectory() && !this.compassDirectory.mkdir() )
|
|
||||||
{
|
|
||||||
throw new IllegalStateException( "Failed to create " + this.compassDirectory.getAbsolutePath() );
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if spawn data dir already exists, else create
|
|
||||||
if( !this.spawnDirectory.isDirectory() && !this.spawnDirectory.mkdir() )
|
|
||||||
{
|
|
||||||
throw new IllegalStateException( "Failed to create " + this.spawnDirectory.getAbsolutePath() );
|
|
||||||
}
|
|
||||||
|
|
||||||
for( final IOnWorldStartable startable : this.startables )
|
|
||||||
{
|
|
||||||
startable.onWorldStart();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.startables.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onServerStopping()
|
public void onServerStopping()
|
||||||
{
|
{
|
||||||
for( final IOnWorldStoppable stoppable : this.stoppables )
|
compassData.service().kill();
|
||||||
{
|
|
||||||
stoppable.onWorldStop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onServerStoppped()
|
public void onServerStoppped()
|
||||||
{
|
{
|
||||||
Preconditions.checkNotNull( instance );
|
Preconditions.checkNotNull( instance );
|
||||||
|
|
||||||
this.stoppables.clear();
|
|
||||||
instance = null;
|
instance = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -144,7 +144,6 @@ public class TickHandler
|
|||||||
this.getRepo().clear();
|
this.getRepo().clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void unloadWorld( final WorldEvent.Unload ev )
|
public void unloadWorld( final WorldEvent.Unload ev )
|
||||||
{
|
{
|
||||||
if( Platform.isServer() ) // for no there is no reason to care about this on the client...
|
if( Platform.isServer() ) // for no there is no reason to care about this on the client...
|
||||||
@@ -170,7 +169,6 @@ public class TickHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onTick( final TickEvent ev )
|
public void onTick( final TickEvent ev )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -19,19 +19,13 @@
|
|||||||
package appeng.me;
|
package appeng.me;
|
||||||
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.ref.WeakReference;
|
|
||||||
import java.util.WeakHashMap;
|
|
||||||
|
|
||||||
import net.minecraft.nbt.CompressedStreamTools;
|
|
||||||
import net.minecraft.nbt.CompoundNBT;
|
|
||||||
|
|
||||||
import appeng.api.networking.IGrid;
|
import appeng.api.networking.IGrid;
|
||||||
import appeng.api.networking.IGridStorage;
|
import appeng.api.networking.IGridStorage;
|
||||||
import appeng.core.AELog;
|
|
||||||
import appeng.core.worlddata.WorldData;
|
import appeng.core.worlddata.WorldData;
|
||||||
|
import net.minecraft.nbt.CompoundNBT;
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
import java.util.WeakHashMap;
|
||||||
|
|
||||||
|
|
||||||
public class GridStorage implements IGridStorage
|
public class GridStorage implements IGridStorage
|
||||||
@@ -39,49 +33,30 @@ public class GridStorage implements IGridStorage
|
|||||||
|
|
||||||
private final long myID;
|
private final long myID;
|
||||||
private final CompoundNBT data;
|
private final CompoundNBT data;
|
||||||
private final GridStorageSearch mySearchEntry; // keep myself in the list until I'm
|
|
||||||
private final WeakHashMap<GridStorage, Boolean> divided = new WeakHashMap<>();
|
private final WeakHashMap<GridStorage, Boolean> divided = new WeakHashMap<>();
|
||||||
private WeakReference<IGrid> internalGrid = null;
|
private WeakReference<IGrid> internalGrid = null;
|
||||||
|
|
||||||
// lost...
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* for use with world settings
|
* for use with world settings
|
||||||
*
|
*
|
||||||
* @param id ID of grid storage
|
* @param id ID of grid storage
|
||||||
* @param gss grid storage search
|
|
||||||
*/
|
*/
|
||||||
public GridStorage( final long id, final GridStorageSearch gss )
|
public GridStorage( final long id )
|
||||||
{
|
{
|
||||||
this.myID = id;
|
this.myID = id;
|
||||||
this.mySearchEntry = gss;
|
|
||||||
this.data = new CompoundNBT();
|
this.data = new CompoundNBT();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* for use with world settings
|
* for use with world settings
|
||||||
*
|
*
|
||||||
* @param input array of bytes string
|
* @param data The Grid data.
|
||||||
* @param id ID of grid storage
|
* @param id ID of grid storage
|
||||||
* @param gss grid storage search
|
|
||||||
*/
|
*/
|
||||||
public GridStorage( final String input, final long id, final GridStorageSearch gss )
|
public GridStorage( final long id, final CompoundNBT data )
|
||||||
{
|
{
|
||||||
this.myID = id;
|
this.myID = id;
|
||||||
this.mySearchEntry = gss;
|
this.data = data;
|
||||||
CompoundNBT myTag = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
final byte[] byteData = javax.xml.bind.DatatypeConverter.parseBase64Binary( input );
|
|
||||||
myTag = CompressedStreamTools.readCompressed( new ByteArrayInputStream( byteData ) );
|
|
||||||
}
|
|
||||||
catch( final Throwable t )
|
|
||||||
{
|
|
||||||
myTag = new CompoundNBT();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.data = myTag;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -90,30 +65,16 @@ public class GridStorage implements IGridStorage
|
|||||||
public GridStorage()
|
public GridStorage()
|
||||||
{
|
{
|
||||||
this.myID = 0;
|
this.myID = 0;
|
||||||
this.mySearchEntry = null;
|
|
||||||
this.data = new CompoundNBT();
|
this.data = new CompoundNBT();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getValue()
|
public void saveState()
|
||||||
{
|
{
|
||||||
// FIXME final Grid currentGrid = (Grid) this.getGrid();
|
final Grid currentGrid = (Grid) this.getGrid();
|
||||||
// FIXME if( currentGrid != null )
|
if( currentGrid != null )
|
||||||
// FIXME {
|
|
||||||
// FIXME currentGrid.saveState();
|
|
||||||
// FIXME }
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
final ByteArrayOutputStream out = new ByteArrayOutputStream();
|
currentGrid.saveState();
|
||||||
CompressedStreamTools.writeCompressed( this.data, out );
|
|
||||||
return javax.xml.bind.DatatypeConverter.printBase64Binary( out.toByteArray() );
|
|
||||||
}
|
}
|
||||||
catch( final IOException e )
|
|
||||||
{
|
|
||||||
AELog.debug( e );
|
|
||||||
}
|
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IGrid getGrid()
|
public IGrid getGrid()
|
||||||
|
|||||||
@@ -1,77 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Applied Energistics 2.
|
|
||||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
|
||||||
*
|
|
||||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package appeng.me;
|
|
||||||
|
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
|
||||||
|
|
||||||
|
|
||||||
public class GridStorageSearch
|
|
||||||
{
|
|
||||||
|
|
||||||
private final long id;
|
|
||||||
private WeakReference<GridStorage> gridStorage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* for use with the world settings
|
|
||||||
*
|
|
||||||
* @param id ID of grid storage search
|
|
||||||
*/
|
|
||||||
public GridStorageSearch( final long id )
|
|
||||||
{
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode()
|
|
||||||
{
|
|
||||||
return ( (Long) this.id ).hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals( final Object obj )
|
|
||||||
{
|
|
||||||
if( obj == null )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if( this.getClass() != obj.getClass() )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
final GridStorageSearch other = (GridStorageSearch) obj;
|
|
||||||
if( this.id == other.id )
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public WeakReference<GridStorage> getGridStorage()
|
|
||||||
{
|
|
||||||
return this.gridStorage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGridStorage( final WeakReference<GridStorage> gridStorage )
|
|
||||||
{
|
|
||||||
this.gridStorage = gridStorage;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+1
-1
@@ -156,7 +156,7 @@ public class SecurityCache implements ISecurityGrid
|
|||||||
Preconditions.checkNotNull( perm );
|
Preconditions.checkNotNull( perm );
|
||||||
|
|
||||||
final GameProfile profile = player.getGameProfile();
|
final GameProfile profile = player.getGameProfile();
|
||||||
final int playerID = WorldData.instance().playerData().getPlayerID( profile );
|
final int playerID = WorldData.instance().playerData().getMePlayerId( profile );
|
||||||
|
|
||||||
return this.hasPermission( playerID, perm );
|
return this.hasPermission( playerID, perm );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ public class AENetworkProxy implements IGridBlock
|
|||||||
else if( this.node != null && this.owner != null )
|
else if( this.node != null && this.owner != null )
|
||||||
{
|
{
|
||||||
final GameProfile profile = this.owner.getGameProfile();
|
final GameProfile profile = this.owner.getGameProfile();
|
||||||
final int playerID = WorldData.instance().playerData().getPlayerID( profile );
|
final int playerID = WorldData.instance().playerData().getMePlayerId( profile );
|
||||||
|
|
||||||
this.node.setPlayerID( playerID );
|
this.node.setPlayerID( playerID );
|
||||||
this.owner = null;
|
this.owner = null;
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import java.util.Collection;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import appeng.core.Api;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
@@ -237,7 +238,7 @@ public final class MeteoritePlacer
|
|||||||
|
|
||||||
if( Math.random() > PRESSES_SPAWN_CHANCE )
|
if( Math.random() > PRESSES_SPAWN_CHANCE )
|
||||||
{
|
{
|
||||||
r = WorldData.instance().storageData().getNextOrderedValue( "presses" );
|
r = WorldData.instance().storageData().getNextOrderedValue( "presses", 0 );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user