Working spatial dimensions teleport.
This commit is contained in:
@@ -54,6 +54,10 @@ import net.minecraft.particles.ParticleType;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraft.world.gen.feature.Feature;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraft.world.gen.feature.Feature;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
@@ -62,6 +66,8 @@ import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
import net.minecraftforge.client.model.geometry.IModelGeometry;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.ModDimension;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.fml.CrashReportExtender;
|
||||
@@ -132,6 +138,8 @@ public final class AppEng
|
||||
modEventBus.addGenericListener(ContainerType.class, registration::registerContainerTypes);
|
||||
modEventBus.addGenericListener(IRecipeSerializer.class, registration::registerRecipeSerializers);
|
||||
modEventBus.addGenericListener(Feature.class, registration::registerWorldGen);
|
||||
modEventBus.addGenericListener(Biome.class, registration::registerBiomes);
|
||||
modEventBus.addGenericListener(ModDimension.class, registration::registerModDimension);
|
||||
modEventBus.addListener(registration::registerParticleFactories);
|
||||
modEventBus.addListener(registration::registerTextures);
|
||||
modEventBus.addListener(registration::registerCommands);
|
||||
|
||||
@@ -38,39 +38,7 @@ import appeng.api.networking.storage.IStorageGrid;
|
||||
import appeng.api.networking.ticking.ITickManager;
|
||||
import appeng.bootstrap.IModelRegistry;
|
||||
import appeng.bootstrap.components.*;
|
||||
import appeng.client.gui.implementations.GuiCellWorkbench;
|
||||
import appeng.client.gui.implementations.GuiChest;
|
||||
import appeng.client.gui.implementations.GuiCondenser;
|
||||
import appeng.client.gui.implementations.GuiCraftAmount;
|
||||
import appeng.client.gui.implementations.GuiCraftConfirm;
|
||||
import appeng.client.gui.implementations.GuiCraftingCPU;
|
||||
import appeng.client.gui.implementations.GuiCraftingStatus;
|
||||
import appeng.client.gui.implementations.GuiCraftingTerm;
|
||||
import appeng.client.gui.implementations.GuiDrive;
|
||||
import appeng.client.gui.implementations.GuiFormationPlane;
|
||||
import appeng.client.gui.implementations.GuiGrinder;
|
||||
import appeng.client.gui.implementations.GuiIOPort;
|
||||
import appeng.client.gui.implementations.GuiInscriber;
|
||||
import appeng.client.gui.implementations.GuiInterface;
|
||||
import appeng.client.gui.implementations.GuiInterfaceTerminal;
|
||||
import appeng.client.gui.implementations.GuiLevelEmitter;
|
||||
import appeng.client.gui.implementations.GuiMAC;
|
||||
import appeng.client.gui.implementations.GuiMEMonitorable;
|
||||
import appeng.client.gui.implementations.GuiMEPortableCell;
|
||||
import appeng.client.gui.implementations.GuiNetworkStatus;
|
||||
import appeng.client.gui.implementations.GuiNetworkTool;
|
||||
import appeng.client.gui.implementations.GuiPatternTerm;
|
||||
import appeng.client.gui.implementations.GuiPriority;
|
||||
import appeng.client.gui.implementations.GuiQNB;
|
||||
import appeng.client.gui.implementations.GuiQuartzKnife;
|
||||
import appeng.client.gui.implementations.GuiSecurityStation;
|
||||
import appeng.client.gui.implementations.GuiSkyChest;
|
||||
import appeng.client.gui.implementations.GuiSpatialIOPort;
|
||||
import appeng.client.gui.implementations.GuiStorageBus;
|
||||
import appeng.client.gui.implementations.GuiUpgradeable;
|
||||
import appeng.client.gui.implementations.GuiVibrationChamber;
|
||||
import appeng.client.gui.implementations.GuiWireless;
|
||||
import appeng.client.gui.implementations.GuiWirelessTerm;
|
||||
import appeng.client.gui.implementations.*;
|
||||
import appeng.client.render.effects.*;
|
||||
import appeng.client.render.model.BiometricCardModel;
|
||||
import appeng.client.render.model.DriveModel;
|
||||
@@ -99,7 +67,10 @@ import appeng.recipes.handlers.GrinderRecipeSerializer;
|
||||
import appeng.recipes.handlers.InscriberRecipe;
|
||||
import appeng.recipes.handlers.InscriberRecipeSerializer;
|
||||
import appeng.server.AECommand;
|
||||
import appeng.spatial.StorageCellBiome;
|
||||
import appeng.spatial.StorageCellModDimension;
|
||||
import appeng.tile.AEBaseTile;
|
||||
import appeng.worldgen.MeteoriteWorldGen;
|
||||
import net.minecraft.advancements.CriteriaTriggers;
|
||||
import appeng.worldgen.MeteoriteWorldGen;
|
||||
import net.minecraft.block.Block;
|
||||
@@ -109,10 +80,16 @@ import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.crafting.IRecipeSerializer;
|
||||
import net.minecraft.item.crafting.IRecipeType;
|
||||
import net.minecraft.particles.ParticleType;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraft.world.gen.GenerationStage;
|
||||
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
||||
import net.minecraft.world.gen.feature.Feature;
|
||||
import net.minecraft.world.gen.feature.IFeatureConfig;
|
||||
import net.minecraft.world.gen.feature.NoFeatureConfig;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraft.world.gen.GenerationStage;
|
||||
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
||||
@@ -124,8 +101,8 @@ import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.client.event.*;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.common.ModDimension;
|
||||
import net.minecraftforge.common.crafting.CraftingHelper;
|
||||
import net.minecraftforge.common.crafting.conditions.IConditionSerializer;
|
||||
import net.minecraftforge.common.extensions.IForgeContainerType;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
@@ -146,62 +123,8 @@ final class Registration
|
||||
advancementTriggers = new AdvancementTriggers( CriteriaTriggers::register );
|
||||
}
|
||||
|
||||
// DimensionType storageDimensionType;
|
||||
// int storageDimensionID;
|
||||
// Biome storageBiome;
|
||||
AdvancementTriggers advancementTriggers;
|
||||
|
||||
// private void registerSpatialBiome( IForgeRegistry<Biome> registry )
|
||||
// {
|
||||
// if( !AEConfig.instance().isFeatureEnabled( AEFeature.SPATIAL_IO ) )
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if( this.storageBiome == null )
|
||||
// {
|
||||
// this.storageBiome = new BiomeGenStorage();
|
||||
// }
|
||||
// registry.register( this.storageBiome.setRegistryName( "appliedenergistics2:storage_biome" ) );
|
||||
// }
|
||||
//
|
||||
// private void registerSpatialDimension()
|
||||
// {
|
||||
// final AEConfig config = AEConfig.instance();
|
||||
// if( !config.isFeatureEnabled( AEFeature.SPATIAL_IO ) )
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if( config.getStorageProviderID() == -1 )
|
||||
// {
|
||||
// final Set<Integer> ids = new HashSet<>();
|
||||
// for( DimensionType type : DimensionType.values() )
|
||||
// {
|
||||
// ids.add( type.getId() );
|
||||
// }
|
||||
//
|
||||
// int newId = -11;
|
||||
// while( ids.contains( newId ) )
|
||||
// {
|
||||
// --newId;
|
||||
// }
|
||||
// config.setStorageProviderID( newId );
|
||||
// config.save();
|
||||
// }
|
||||
//
|
||||
// this.storageDimensionType = DimensionType.register( "Storage Cell", "_cell", config.getStorageProviderID(), StorageWorldProvider.class, true );
|
||||
//
|
||||
// if( config.getStorageDimensionID() == -1 )
|
||||
// {
|
||||
// config.setStorageDimensionID( DimensionManager.getNextFreeDimId() );
|
||||
// config.save();
|
||||
// }
|
||||
// this.storageDimensionID = config.getStorageDimensionID();
|
||||
//
|
||||
// DimensionManager.registerDimension( this.storageDimensionID, this.storageDimensionType );
|
||||
// }
|
||||
|
||||
public static void setupInternalRegistries()
|
||||
{
|
||||
// TODO: Do not use the internal API
|
||||
@@ -233,13 +156,6 @@ final class Registration
|
||||
PartItemPredicate.register();
|
||||
}
|
||||
|
||||
// @SubscribeEvent
|
||||
// public void registerBiomes( RegistryEvent.Register<Biome> event )
|
||||
// {
|
||||
// final IForgeRegistry<Biome> registry = event.getRegistry();
|
||||
// this.registerSpatialBiome( registry );
|
||||
// }
|
||||
//
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
public void modelRegistryEvent( ModelRegistryEvent event )
|
||||
{
|
||||
@@ -837,33 +753,14 @@ final class Registration
|
||||
r.register( MeteoriteWorldGen.INSTANCE );
|
||||
}
|
||||
|
||||
// private static class ModelLoaderWrapper implements IModelRegistry
|
||||
// {
|
||||
//
|
||||
// @Override
|
||||
// public void registerItemVariants( Item item, ResourceLocation... names )
|
||||
// {
|
||||
// ModelLoader.registerItemVariants( item, names );
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void setCustomModelResourceLocation( Item item, int metadata, ModelResourceLocation model )
|
||||
// {
|
||||
// ModelLoader.setCustomModelResourceLocation( item, metadata, model );
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void setCustomMeshDefinition( Item item, ItemMeshDefinition meshDefinition )
|
||||
// {
|
||||
// ModelLoader.setCustomMeshDefinition( item, meshDefinition );
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void setCustomStateMapper( Block block, IStateMapper mapper )
|
||||
// {
|
||||
// ModelLoader.setCustomStateMapper( block, mapper );
|
||||
// }
|
||||
// }
|
||||
public void registerBiomes(RegistryEvent.Register<Biome> evt) {
|
||||
evt.getRegistry().register(StorageCellBiome.INSTANCE);
|
||||
}
|
||||
|
||||
public void registerModDimension(RegistryEvent.Register<ModDimension> evt)
|
||||
{
|
||||
evt.getRegistry().register(StorageCellModDimension.INSTANCE);
|
||||
}
|
||||
|
||||
public void registerTextures(TextureStitchEvent.Pre event) {
|
||||
SkyChestTESR.registerTextures(event);
|
||||
@@ -887,4 +784,5 @@ final class Registration
|
||||
final ApiDefinitions definitions = Api.INSTANCE.definitions();
|
||||
definitions.getRegistry().getBootstrapComponents( IModelBakeComponent.class ).forEachRemaining(c -> c.onModelBakeEvent(event));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -248,21 +248,23 @@ public final class ApiItems implements IItems
|
||||
.features( AEFeature.VIEW_CELL )
|
||||
.build();
|
||||
|
||||
FeatureFactory storageCells = registry.features( AEFeature.STORAGE_CELLS );
|
||||
this.cell1k = storageCells.item( "1k_storage_cell", props -> new BasicItemStorageCell(props, MaterialType.ITEM_1K_CELL_COMPONENT, 1 ) ).build();
|
||||
this.cell4k = storageCells.item( "4k_storage_cell", props -> new BasicItemStorageCell(props, MaterialType.ITEM_4K_CELL_COMPONENT, 4 ) ).build();
|
||||
this.cell16k = storageCells.item( "16k_storage_cell", props -> new BasicItemStorageCell(props, MaterialType.ITEM_16K_CELL_COMPONENT, 16 ) ).build();
|
||||
this.cell64k = storageCells.item( "64k_storage_cell", props -> new BasicItemStorageCell(props, MaterialType.ITEM_64K_CELL_COMPONENT, 64 ) ).build();
|
||||
Consumer<Item.Properties> storageCellProps = p -> p.maxStackSize(1);
|
||||
|
||||
this.fluidCell1k = storageCells.item( "1k_fluid_storage_cell", props -> new BasicFluidStorageCell(props, MaterialType.FLUID_1K_CELL_COMPONENT, 1 ) ).build();
|
||||
this.fluidCell4k = storageCells.item( "4k_fluid_storage_cell", props -> new BasicFluidStorageCell(props, MaterialType.FLUID_4K_CELL_COMPONENT, 4 ) ).build();
|
||||
this.fluidCell16k = storageCells.item( "16k_fluid_storage_cell", props -> new BasicFluidStorageCell(props, MaterialType.FLUID_16K_CELL_COMPONENT, 16 ) ).build();
|
||||
this.fluidCell64k = storageCells.item( "64k_fluid_storage_cell", props -> new BasicFluidStorageCell(props, MaterialType.FLUID_64K_CELL_COMPONENT, 64 ) ).build();
|
||||
FeatureFactory storageCells = registry.features( AEFeature.STORAGE_CELLS );
|
||||
this.cell1k = storageCells.item( "1k_storage_cell", props -> new BasicItemStorageCell(props, MaterialType.ITEM_1K_CELL_COMPONENT, 1 ) ).props(storageCellProps).build();
|
||||
this.cell4k = storageCells.item( "4k_storage_cell", props -> new BasicItemStorageCell(props, MaterialType.ITEM_4K_CELL_COMPONENT, 4 ) ).props(storageCellProps).build();
|
||||
this.cell16k = storageCells.item( "16k_storage_cell", props -> new BasicItemStorageCell(props, MaterialType.ITEM_16K_CELL_COMPONENT, 16 ) ).props(storageCellProps).build();
|
||||
this.cell64k = storageCells.item( "64k_storage_cell", props -> new BasicItemStorageCell(props, MaterialType.ITEM_64K_CELL_COMPONENT, 64 ) ).props(storageCellProps).build();
|
||||
|
||||
this.fluidCell1k = storageCells.item( "1k_fluid_storage_cell", props -> new BasicFluidStorageCell(props, MaterialType.FLUID_1K_CELL_COMPONENT, 1 ) ).props(storageCellProps).build();
|
||||
this.fluidCell4k = storageCells.item( "4k_fluid_storage_cell", props -> new BasicFluidStorageCell(props, MaterialType.FLUID_4K_CELL_COMPONENT, 4 ) ).props(storageCellProps).build();
|
||||
this.fluidCell16k = storageCells.item( "16k_fluid_storage_cell", props -> new BasicFluidStorageCell(props, MaterialType.FLUID_16K_CELL_COMPONENT, 16 ) ).props(storageCellProps).build();
|
||||
this.fluidCell64k = storageCells.item( "64k_fluid_storage_cell", props -> new BasicFluidStorageCell(props, MaterialType.FLUID_64K_CELL_COMPONENT, 64 ) ).props(storageCellProps).build();
|
||||
|
||||
FeatureFactory spatialCells = registry.features( AEFeature.SPATIAL_IO );
|
||||
this.spatialCell2 = spatialCells.item( "2_cubed_spatial_storage_cell", props -> new ItemSpatialStorageCell(props, 2 ) ).build();
|
||||
this.spatialCell16 = spatialCells.item( "16_cubed_spatial_storage_cell", props -> new ItemSpatialStorageCell(props, 16 ) ).build();
|
||||
this.spatialCell128 = spatialCells.item( "128_cubed_spatial_storage_cell", props -> new ItemSpatialStorageCell(props, 128 ) ).build();
|
||||
this.spatialCell2 = spatialCells.item( "2_cubed_spatial_storage_cell", props -> new ItemSpatialStorageCell(props, 2 ) ).props(storageCellProps).build();
|
||||
this.spatialCell16 = spatialCells.item( "16_cubed_spatial_storage_cell", props -> new ItemSpatialStorageCell(props, 16 ) ).props(storageCellProps).build();
|
||||
this.spatialCell128 = spatialCells.item( "128_cubed_spatial_storage_cell", props -> new ItemSpatialStorageCell(props, 128 ) ).props(storageCellProps).build();
|
||||
|
||||
this.facade = registry.item( "facade", ItemFacade::new )
|
||||
.features( AEFeature.FACADES )
|
||||
|
||||
@@ -19,164 +19,126 @@
|
||||
package appeng.core.worlddata;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
|
||||
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;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.spatial.StorageCellModDimension;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import net.minecraftforge.common.util.INBTSerializable;
|
||||
import net.minecraftforge.fml.server.ServerLifecycleHooks;
|
||||
|
||||
|
||||
public class SpatialDimensionManager implements ISpatialDimension, ICapabilitySerializable<CompoundNBT>
|
||||
public class SpatialDimensionManager implements ISpatialDimension
|
||||
{
|
||||
private static final String NBT_SPATIAL_DATA_KEY = "spatial_data";
|
||||
private static final String NBT_SPATIAL_ID_KEY = "id";
|
||||
|
||||
private World world;
|
||||
private Map<Integer, StorageCellData> spatialData = new HashMap<>();
|
||||
private static final int MAX_DIM_PER_PLAYER = 999;
|
||||
|
||||
private static final int MAX_CELL_DIMENSION = 512;
|
||||
|
||||
public SpatialDimensionManager( World world )
|
||||
{
|
||||
this.world = world;
|
||||
@Override
|
||||
public ServerWorld getWorld(DimensionType cellDim) {
|
||||
return DimensionManager.getWorld(getServer(), cellDim, true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld()
|
||||
public DimensionType createNewCellDimension( BlockPos contentSize, int owner )
|
||||
{
|
||||
return this.world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int createNewCellDimension( BlockPos contentSize, int owner )
|
||||
{
|
||||
int newId = this.getNextId();
|
||||
// Try to find a free dimension ID for the player
|
||||
ResourceLocation dimKey = null;
|
||||
for (int i = 1; i <= MAX_DIM_PER_PLAYER; i++) {
|
||||
dimKey = new ResourceLocation(AppEng.MOD_ID, "spatial_cell_" + owner + "_" + i);
|
||||
if (DimensionType.byName(dimKey) == null) {
|
||||
break;
|
||||
}
|
||||
dimKey = null;
|
||||
}
|
||||
if (dimKey == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
StorageCellData data = new StorageCellData();
|
||||
data.contentDimension = contentSize;
|
||||
data.owner = owner;
|
||||
|
||||
this.spatialData.put( newId, data );
|
||||
PacketBuffer extraData = new PacketBuffer(Unpooled.buffer());
|
||||
extraData.writeInt(owner);
|
||||
extraData.writeBlockPos(contentSize);
|
||||
|
||||
return newId;
|
||||
return DimensionManager.registerDimension(dimKey, StorageCellModDimension.INSTANCE, extraData, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteCellDimension( int cellStorageId )
|
||||
public void deleteCellDimension( DimensionType cellDim )
|
||||
{
|
||||
StorageCellData removed = this.spatialData.remove( cellStorageId );
|
||||
if( removed != null )
|
||||
{
|
||||
this.clearCellArea( cellStorageId, removed );
|
||||
AELog.info("Unregistering storage cell dimension %s", cellDim.getRegistryName());
|
||||
MinecraftServer server = getServer();
|
||||
ServerWorld world = DimensionManager.getWorld(server, cellDim, false, false);
|
||||
if (world != null) {
|
||||
DimensionManager.unloadWorld(world);
|
||||
}
|
||||
DimensionManager.unloadWorlds(server, true);
|
||||
DimensionManager.unregisterDimension(cellDim.getId());
|
||||
}
|
||||
|
||||
private static MinecraftServer getServer() {
|
||||
return ServerLifecycleHooks.getCurrentServer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCellDimension( int cellStorageId )
|
||||
public boolean isCellDimension( DimensionType cellDim )
|
||||
{
|
||||
return this.spatialData.containsKey( cellStorageId );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCellDimensionOwner( int cellStorageId )
|
||||
{
|
||||
StorageCellData cell = this.spatialData.get( cellStorageId );
|
||||
if( cell != null )
|
||||
{
|
||||
return cell.owner;
|
||||
// Check if the cell dimension type is even registered
|
||||
if (cellDim.getRegistryName() == null || !cellDim.getRegistryName().equals(DimensionType.getKey(cellDim))) {
|
||||
return false;
|
||||
}
|
||||
return -1;
|
||||
|
||||
return cellDim.getModType() instanceof StorageCellModDimension;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos getCellDimensionOrigin( int cellStorageId )
|
||||
public int getCellDimensionOwner( DimensionType cellDim )
|
||||
{
|
||||
if( this.isCellDimension( cellStorageId ) )
|
||||
{
|
||||
return this.getBlockPosFromId( cellStorageId );
|
||||
if (!(cellDim.getModType() instanceof StorageCellModDimension)) {
|
||||
return -1;
|
||||
}
|
||||
return null;
|
||||
|
||||
PacketBuffer data = cellDim.getData();
|
||||
if (data == null) {
|
||||
return -1;
|
||||
}
|
||||
data.readerIndex(0);
|
||||
return data.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos getCellContentSize( int cellStorageId )
|
||||
public BlockPos getCellDimensionOrigin( DimensionType cellDim )
|
||||
{
|
||||
StorageCellData cell = this.spatialData.get( cellStorageId );
|
||||
if( cell != null )
|
||||
{
|
||||
return cell.contentDimension;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Nonnull
|
||||
@Override
|
||||
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> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
|
||||
return getCapability(cap);
|
||||
// A region file is 512x512 blocks (32x32 chunks),
|
||||
// to avoid creating the 4 regions around 0,0,0,
|
||||
// we move the origin to the middle of region 0,0
|
||||
return new BlockPos(512 / 2, 61, 512 / 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundNBT serializeNBT()
|
||||
public BlockPos getCellContentSize( DimensionType cellDim )
|
||||
{
|
||||
final CompoundNBT ret = new CompoundNBT();
|
||||
final ListNBT list = new ListNBT();
|
||||
|
||||
for( Map.Entry<Integer, StorageCellData> entry : this.spatialData.entrySet() )
|
||||
{
|
||||
final CompoundNBT nbt = entry.getValue().serializeNBT();
|
||||
nbt.putInt( NBT_SPATIAL_ID_KEY, entry.getKey() );
|
||||
list.add( nbt );
|
||||
if (!(cellDim.getModType() instanceof StorageCellModDimension)) {
|
||||
return BlockPos.ZERO;
|
||||
}
|
||||
ret.put( NBT_SPATIAL_DATA_KEY, list );
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT( CompoundNBT nbt )
|
||||
{
|
||||
if( nbt.contains(NBT_SPATIAL_DATA_KEY) )
|
||||
{
|
||||
final ListNBT list = (ListNBT) nbt.get( NBT_SPATIAL_DATA_KEY );
|
||||
|
||||
this.spatialData.clear();
|
||||
for( int i = 0; i < list.size(); ++i )
|
||||
{
|
||||
final CompoundNBT entry = list.getCompound( i );
|
||||
final StorageCellData data = new StorageCellData();
|
||||
final int id = entry.getInt( NBT_SPATIAL_ID_KEY );
|
||||
data.deserializeNBT( entry );
|
||||
this.spatialData.put( id, data );
|
||||
}
|
||||
PacketBuffer data = cellDim.getData();
|
||||
if (data == null) {
|
||||
return BlockPos.ZERO;
|
||||
}
|
||||
}
|
||||
|
||||
private int getNextId()
|
||||
{
|
||||
return this.spatialData.keySet().stream().max( Integer::compare ).orElse( -1 ) + 1;
|
||||
data.readerIndex(4);
|
||||
return data.readBlockPos();
|
||||
}
|
||||
|
||||
private BlockPos getBlockPosFromId( int id )
|
||||
@@ -214,11 +176,6 @@ public class SpatialDimensionManager implements ISpatialDimension, ICapabilitySe
|
||||
return new BlockPos( posx, 64, posz );
|
||||
}
|
||||
|
||||
private void clearCellArea( int cellId, StorageCellData cell )
|
||||
{
|
||||
// TODO reset chunks?
|
||||
}
|
||||
|
||||
private static class StorageCellData implements INBTSerializable<CompoundNBT>
|
||||
{
|
||||
private static final String NBT_OWNER_KEY = "owner";
|
||||
|
||||
Reference in New Issue
Block a user