Working spatial dimensions teleport.

This commit is contained in:
Sebastian Hartte
2020-06-13 01:11:31 +02:00
parent e83429e1bb
commit 94226f3219
22 changed files with 522 additions and 872 deletions
+51 -52
View File
@@ -20,19 +20,19 @@ package appeng.spatial;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.network.play.server.SChunkDataPacket;
import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.ITickList;
import net.minecraft.world.NextTickListEntry;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
import appeng.api.AEApi;
import appeng.api.movable.IMovableHandler;
@@ -42,6 +42,9 @@ import appeng.api.util.WorldCoord;
import appeng.core.AELog;
import appeng.core.worlddata.WorldData;
import appeng.util.Platform;
import net.minecraft.world.chunk.ChunkSection;
import net.minecraft.world.server.ServerChunkProvider;
import net.minecraft.world.server.ServerTickList;
public class CachedPlane
@@ -57,7 +60,7 @@ public class CachedPlane
private final Chunk[][] myChunks;
private final Column[][] myColumns;
private final List<TileEntity> tiles = new ArrayList<>();
private final List<NextTickListEntry> ticks = new ArrayList<>();
private final List<NextTickListEntry<Block>> ticks = new ArrayList<>();
private final World world;
private final IMovableRegistry reg = AEApi.instance().registries().movable();
private final List<WorldCoord> updates = new ArrayList<>();
@@ -121,13 +124,12 @@ public class CachedPlane
{
for( int cz = 0; cz < this.cz_size; cz++ )
{
final List<Entry<BlockPos, TileEntity>> rawTiles = new ArrayList<>();
final List<BlockPos> deadTiles = new ArrayList<>();
final Chunk c = w.getChunk( minCX + cx, minCZ + cz );
this.myChunks[cx][cz] = c;
rawTiles.addAll( ( (HashMap<BlockPos, TileEntity>) c.getTileEntityMap() ).entrySet() );
final List<Entry<BlockPos, TileEntity>> rawTiles = new ArrayList<>(c.getTileEntityMap().entrySet());
for( final Entry<BlockPos, TileEntity> tx : rawTiles )
{
final BlockPos cp = tx.getKey();
@@ -165,19 +167,15 @@ public class CachedPlane
c.getTileEntityMap().remove( cp );
}
final long k = this.getWorld().getGameTime();
final List<NextTickListEntry> list = this.getWorld().getPendingBlockUpdates( c, false );
if( list != null )
{
for( final NextTickListEntry entry : list )
{
final long gameTime = this.getWorld().getGameTime();
final ITickList<Block> pendingBlockTicks = this.getWorld().getPendingBlockTicks();
if (pendingBlockTicks instanceof ServerTickList) {
List<NextTickListEntry<Block>> pending = ((ServerTickList<Block>) pendingBlockTicks).getPending(c.getPos(), false, true);
for (final NextTickListEntry<Block> entry : pending) {
final BlockPos tePOS = entry.position;
if( tePOS.getX() >= minX && tePOS.getX() <= maxX && tePOS.getY() >= minY && tePOS.getY() <= maxY && tePOS.getZ() >= minZ && tePOS
.getZ() <= maxZ )
{
final NextTickListEntry newEntry = new NextTickListEntry( tePOS, entry.getBlock() );
newEntry.scheduledTime = entry.scheduledTime - k;
this.ticks.add( newEntry );
if (tePOS.getX() >= minX && tePOS.getX() <= maxX && tePOS.getY() >= minY && tePOS.getY() <= maxY && tePOS.getZ() >= minZ && tePOS
.getZ() <= maxZ) {
this.ticks.add(new NextTickListEntry<>(tePOS, entry.getTarget(), entry.scheduledTime - gameTime, entry.priority));
}
}
}
@@ -236,8 +234,8 @@ public class CachedPlane
a.fillData( src_y, aD );
b.fillData( dst_y, bD );
a.setBlockIDWithMetadata( src_y, bD );
b.setBlockIDWithMetadata( dst_y, aD );
a.setBlockState( src_y, bD );
b.setBlockState( dst_y, aD );
}
else
{
@@ -264,13 +262,13 @@ public class CachedPlane
this.addTile( tePOS.getX() - dst.x_offset, tePOS.getY() - dst.y_offset, tePOS.getZ() - dst.z_offset, te, dst, mr );
}
for( final NextTickListEntry entry : this.ticks )
for( final NextTickListEntry<Block> entry : this.ticks )
{
final BlockPos tePOS = entry.position;
dst.addTick( tePOS.getX() - this.x_offset, tePOS.getY() - this.y_offset, tePOS.getZ() - this.z_offset, entry );
}
for( final NextTickListEntry entry : dst.ticks )
for( final NextTickListEntry<Block> entry : dst.ticks )
{
final BlockPos tePOS = entry.position;
this.addTick( tePOS.getX() - dst.x_offset, tePOS.getY() - dst.y_offset, tePOS.getZ() - dst.z_offset, entry );
@@ -295,9 +293,10 @@ public class CachedPlane
}
}
private void addTick( final int x, final int y, final int z, final NextTickListEntry entry )
private void addTick( final int x, final int y, final int z, final NextTickListEntry<Block> entry )
{
this.world.scheduleUpdate( new BlockPos( x + this.x_offset, y + this.y_offset, z + this.z_offset ), entry.getBlock(), (int) entry.scheduledTime );
BlockPos where = new BlockPos(x + this.x_offset, y + this.y_offset, z + this.z_offset);
this.world.getPendingBlockTicks().scheduleTick(where, entry.getTarget(), (int) entry.scheduledTime, entry.priority);
}
private void addTile( final int x, final int y, final int z, final TileEntity te, final CachedPlane alternateDestination, final IMovableRegistry mr )
@@ -321,16 +320,9 @@ public class CachedPlane
final BlockPos pos = new BlockPos( x, y, z );
// attempt recovery...
te.setWorld( this.world );
te.setPos( pos );
c.c.addTileEntity( new BlockPos( c.x, y + y, c.z ), te );
// c.c.setChunkTileEntity( c.x, y + y, c.z, te );
c.c.addTileEntity(te);
if( c.c.isLoaded() )
{
this.world.addTileEntity( te );
this.world.notifyBlockUpdate( pos, this.world.getBlockState( pos ), this.world.getBlockState( pos ), z );
}
this.world.notifyBlockUpdate( pos, this.world.getBlockState( pos ), this.world.getBlockState( pos ), z );
}
mr.doneMoving( te );
@@ -355,9 +347,8 @@ public class CachedPlane
for( int z = 0; z < this.cz_size; z++ )
{
final Chunk c = this.myChunks[x][z];
c.resetRelightChecks();
c.generateSkylightMap();
c.setModified( true );
// FIXME: Light shit
c.markDirty();
}
}
@@ -371,12 +362,20 @@ public class CachedPlane
for( int y = 1; y < 255; y += 32 )
{
WorldData.instance().compassData().service().updateArea( this.getWorld(), c.x << 4, y, c.z << 4 );
WorldData.instance().compassData().service().updateArea( this.getWorld(), c.getPos().x << 4, y, c.getPos().z << 4 );
}
Platform.sendChunk( c, this.verticalBits );
// FIXME this was sending chunks to players...
SChunkDataPacket cdp = new SChunkDataPacket(c, verticalBits);
((ServerChunkProvider) world.getChunkProvider()).chunkManager.getTrackingPlayers(c.getPos(), false)
.forEach(spe -> spe.connection.sendPacket(cdp));
}
}
// FIXME check if this makes any sense at all to send changes to players asap
ServerChunkProvider serverChunkProvider = (ServerChunkProvider) world.getChunkProvider();
serverChunkProvider.tick(() -> false);
}
List<WorldCoord> getUpdates()
@@ -408,46 +407,46 @@ public class CachedPlane
this.z = z;
this.c = chunk;
final ExtendedBlockStorage[] storage = this.c.getBlockStorageArray();
final ChunkSection[] storage = this.c.getSections();
// make sure storage exists before hand...
for( int ay = 0; ay < chunkHeight; ay++ )
{
final int by = ( ay + chunkY );
ExtendedBlockStorage extendedblockstorage = storage[by];
ChunkSection extendedblockstorage = storage[by];
if( extendedblockstorage == null )
{
extendedblockstorage = storage[by] = new ExtendedBlockStorage( by << 4, this.c.getWorld().provider.hasSkyLight() );
extendedblockstorage = storage[by] = new ChunkSection( by << 4 );
}
}
}
private void setBlockIDWithMetadata( final int y, BlockStorageData data )
private void setBlockState(final int y, BlockStorageData data )
{
if( data.state == CachedPlane.this.matrixBlockState )
{
data.state = Platform.AIR_BLOCK.getDefaultState();
}
final ExtendedBlockStorage[] storage = this.c.getBlockStorageArray();
final ExtendedBlockStorage extendedBlockStorage = storage[y >> 4];
extendedBlockStorage.set( this.x, y & 15, this.z, data.state );
extendedBlockStorage.setBlockLight( this.x, y & 15, this.z, data.light );
final ChunkSection[] storage = this.c.getSections();
final ChunkSection extendedBlockStorage = storage[y >> 4];
extendedBlockStorage.setBlockState( this.x, y & 15, this.z, data.state );
// FIXME extendedBlockStorage.setBlockLight( this.x, y & 15, this.z, data.light );
}
private void fillData( final int y, BlockStorageData data )
{
final ExtendedBlockStorage[] storage = this.c.getBlockStorageArray();
final ExtendedBlockStorage extendedblockstorage = storage[y >> 4];
final ChunkSection[] storage = this.c.getSections();
final ChunkSection extendedblockstorage = storage[y >> 4];
data.state = extendedblockstorage.get( this.x, y & 15, this.z );
data.light = extendedblockstorage.getBlockLight( this.x, y & 15, this.z );
data.state = extendedblockstorage.getBlockState( this.x, y & 15, this.z );
// FIXME data.light = extendedblockstorage.getBlockLight( this.x, y & 15, this.z );
}
private boolean doNotSkip( final int y )
{
final ExtendedBlockStorage[] storage = this.c.getBlockStorageArray();
final ExtendedBlockStorage extendedblockstorage = storage[y >> 4];
if( CachedPlane.this.reg.isBlacklisted( extendedblockstorage.get( this.x, y & 15, this.z ).getBlock() ) )
final ChunkSection[] storage = this.c.getSections();
final ChunkSection extendedblockstorage = storage[y >> 4];
if( CachedPlane.this.reg.isBlacklisted( extendedblockstorage.getBlockState( this.x, y & 15, this.z ).getBlock() ) )
{
return false;
}
@@ -19,17 +19,37 @@
package appeng.spatial;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorldReader;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.surfacebuilders.SurfaceBuilder;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
public class BiomeGenStorage extends Biome
public class StorageCellBiome extends Biome
{
public BiomeGenStorage()
public static final StorageCellBiome INSTANCE = new StorageCellBiome();
static {
INSTANCE.setRegistryName("appliedenergistics2:storage");
}
public StorageCellBiome()
{
super( new Biome.Builder().precipitation(RainType.NONE).temperature(-100).parent(null) );
super( new Biome.Builder()
.surfaceBuilder(SurfaceBuilder.NOPE, SurfaceBuilder.STONE_STONE_GRAVEL_CONFIG)
.precipitation(RainType.NONE)
.category(Category.NONE)
.depth(0)
.scale(1)
// Copied from the vanilla void biome
.temperature(0.5F)
.downfall(0.5F)
.waterColor(4159204)
.waterFogColor(329011)
.parent(null) );
// FIXME this.decorator.treesPerChunk = 0;
// FIXME this.decorator.flowersPerChunk = 0;
// FIXME this.decorator.grassPerChunk = 0;
@@ -42,7 +62,22 @@ public class BiomeGenStorage extends Biome
@OnlyIn(Dist.CLIENT)
public int getSkyColor() {
return 0;
return 0x111111;
}
@Override
public boolean doesWaterFreeze(IWorldReader worldIn, BlockPos pos) {
return false;
}
@Override
public boolean doesWaterFreeze(IWorldReader worldIn, BlockPos water, boolean mustBeAtEdge) {
return false;
}
@Override
public boolean doesSnowGenerate(IWorldReader worldIn, BlockPos pos) {
return false;
}
}
@@ -19,9 +19,10 @@
package appeng.spatial;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.dimension.Dimension;
@@ -34,23 +35,21 @@ import net.minecraftforge.api.distmarker.OnlyIn;
import appeng.client.render.SpatialSkyRender;
import appeng.core.AppEng;
import javax.annotation.Nullable;
// FIXME: Rename suffix to Dimension
public class StorageWorldProvider extends Dimension
public class StorageCellDimension extends Dimension
{
private final Biome biome;
public StorageWorldProvider()
{
this.hasSkyLight = true;
this.biome = AppEng.instance().getStorageBiome();
this.biomeProvider = new BiomeProviderSingle( this.biome );
public StorageCellDimension(World world, DimensionType dimensionType) {
// FIXME: check light value
super(world, dimensionType, 1.0f);
}
@Override
public ChunkGenerator createChunkGenerator()
{
return new StorageChunkProvider( this.world, 0 );
return new StorageChunkGenerator( this.world );
}
@Override
@@ -97,12 +96,6 @@ public class StorageWorldProvider extends Dimension
return false;
}
@Override
public DimensionType getDimensionType()
{
return AppEng.instance().getStorageDimensionType();
}
@Override
public IRenderHandler getSkyRenderer()
{
@@ -115,24 +108,6 @@ public class StorageWorldProvider extends Dimension
return false;
}
@Override
public Vec3d getSkyColor( final Entity cameraEntity, final float partialTicks )
{
return new Vec3d( 0.07, 0.07, 0.07 );
}
@Override
public float getStarBrightness( final float par1 )
{
return 0;
}
@Override
public boolean canSnowAt( final BlockPos pos, final boolean checkLight )
{
return false;
}
@Override
public BlockPos getSpawnCoordinate()
{
@@ -140,7 +115,7 @@ public class StorageWorldProvider extends Dimension
}
@Override
public boolean isBlockHighHumidity( final BlockPos pos )
public boolean isHighHumidity( final BlockPos pos )
{
return false;
}
@@ -152,9 +127,20 @@ public class StorageWorldProvider extends Dimension
}
@Override
public Biome getBiomeForCoords( BlockPos pos )
{
return this.biome;
public boolean canDoRainSnowIce(Chunk chunk) {
return false;
}
@Nullable
@Override
public BlockPos findSpawn(ChunkPos chunkPosIn, boolean checkValid) {
return getSpawnCoordinate();
}
@Nullable
@Override
public BlockPos findSpawn(int posX, int posZ, boolean checkValid) {
return getSpawnCoordinate();
}
}
@@ -0,0 +1,65 @@
/*
* 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.spatial;
import appeng.client.render.SpatialSkyRender;
import appeng.core.AppEng;
import net.minecraft.entity.Entity;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.dimension.Dimension;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.gen.ChunkGenerator;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.IRenderHandler;
import net.minecraftforge.common.ModDimension;
import java.util.function.BiFunction;
public class StorageCellModDimension extends ModDimension
{
public static final StorageCellModDimension INSTANCE = new StorageCellModDimension();
static {
INSTANCE.setRegistryName(AppEng.MOD_ID, "storage_cell");
}
@Override
public BiFunction<World, DimensionType, ? extends Dimension> getFactory() {
return StorageCellDimension::new;
}
@Override
public void write(PacketBuffer buffer, boolean network) {
super.write(buffer, network);
}
@Override
public void read(PacketBuffer buffer, boolean network) {
super.read(buffer, network);
}
}
@@ -0,0 +1,104 @@
/*
* 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.spatial;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
import net.minecraft.world.biome.provider.BiomeProvider;
import net.minecraft.world.biome.provider.SingleBiomeProvider;
import net.minecraft.world.biome.provider.SingleBiomeProviderSettings;
import net.minecraft.world.chunk.IChunk;
import net.minecraft.world.gen.ChunkGenerator;
import appeng.api.AEApi;
import net.minecraft.world.gen.GenerationSettings;
import net.minecraft.world.gen.Heightmap;
import net.minecraft.world.gen.WorldGenRegion;
public class StorageChunkGenerator extends ChunkGenerator<GenerationSettings>
{
private final BlockState defaultBlockState;
public StorageChunkGenerator(final World world )
{
super( world, createBiomeProvider(), createSettings() );
this.defaultBlockState = AEApi.instance().definitions().blocks().matrixFrame().block().getDefaultState();
}
private static BiomeProvider createBiomeProvider() {
SingleBiomeProviderSettings biomeSettings = new SingleBiomeProviderSettings(null);
biomeSettings.setBiome(StorageCellBiome.INSTANCE);
return new SingleBiomeProvider(biomeSettings);
}
private static GenerationSettings createSettings() {
return new GenerationSettings();
}
@Override
public void generateSurface(WorldGenRegion region, IChunk chunk) {
this.fillChunk( chunk );
chunk.setModified( false );
}
private void fillChunk( IChunk chunk )
{
BlockPos.Mutable mutPos = new BlockPos.Mutable();
for( int cx = 0; cx < 16; cx++ )
{
mutPos.setX(cx);
for( int cz = 0; cz < 16; cz++ )
{
// FIXME: It's likely a bad idea to fill Y in the inner-loop given the storage layout of chunks
mutPos.setZ(cz);
for( int cy = 0; cy < 256; cy++ )
{
mutPos.setY(cy);
chunk.setBlockState(mutPos, defaultBlockState, false);
}
}
}
}
@Override
public int getGroundHeight() {
return 0;
}
@Override
public void makeBase(IWorld worldIn, IChunk chunkIn) {
}
@Override
public int func_222529_a(int p_222529_1_, int p_222529_2_, Heightmap.Type heightmapType) {
return 0;
}
@Override
public void decorate(WorldGenRegion region) {
// Do not decorate chunks at all
}
}
@@ -1,118 +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.spatial;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.BlockState;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.gen.ChunkGeneratorOverworld;
import appeng.api.AEApi;
import appeng.core.AppEng;
public class StorageChunkProvider extends ChunkGeneratorOverworld
{
private final World world;
public StorageChunkProvider( final World world, final long i )
{
super( world, i, false, null );
this.world = world;
}
@Override
public Chunk generateChunk( final int x, final int z )
{
final Chunk chunk = new Chunk( this.world, x, z );
final byte[] biomes = chunk.getBiomeArray();
Biome biome = AppEng.instance().getStorageBiome();
byte biomeId = (byte) Biome.getIdForBiome( biome );
for( int k = 0; k < biomes.length; ++k )
{
biomes[k] = biomeId;
}
AEApi.instance().definitions().blocks().matrixFrame().maybeBlock().ifPresent( block -> this.fillChunk( chunk, block.getDefaultState() ) );
chunk.setModified( false );
if( !chunk.isTerrainPopulated() )
{
chunk.setTerrainPopulated( true );
chunk.resetRelightChecks();
}
return chunk;
}
private void fillChunk( Chunk chunk, BlockState defaultState )
{
for( int cx = 0; cx < 16; cx++ )
{
for( int cz = 0; cz < 16; cz++ )
{
for( int cy = 0; cy < 256; cy++ )
{
chunk.setBlockState( new BlockPos( cx, cy, cz ), defaultState );
}
}
}
}
@Override
public void populate( final int par2, final int par3 )
{
}
@Override
public List getPossibleCreatures( final EnumCreatureType creatureType, final BlockPos pos )
{
return new ArrayList();
}
@Override
public boolean generateStructures( Chunk chunkIn, int x, int z )
{
return false;
}
@Override
public BlockPos getNearestStructurePos( World worldIn, String structureName, BlockPos position, boolean p_180513_4_ )
{
return null;
}
@Override
public void recreateStructures( Chunk chunkIn, int x, int z )
{
}
}
+21 -29
View File
@@ -21,6 +21,7 @@ package appeng.spatial;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
@@ -30,7 +31,7 @@ import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.ServerWorld;
import net.minecraft.world.chunk.ChunkStatus;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.util.ITeleporter;
@@ -91,37 +92,34 @@ public class StorageHelper
}
// Are we riding something? Teleport it instead.
if( entity.isRiding() )
if( entity.isPassenger() )
{
return this.teleportEntity( entity.getRidingEntity(), link );
}
// Is something riding us? Handle it first.
final List<Entity> passangers = entity.getPassengers();
final List<Entity> passangersOnOtherSide = new ArrayList<>();
if( !passangers.isEmpty() )
final List<Entity> passengers = entity.getPassengers();
final List<Entity> passengersOnOtherSide = new ArrayList<>(passengers.size());
for( Entity passenger : passengers )
{
for( Entity passanger : passangers )
{
passanger.dismountRidingEntity();
passangersOnOtherSide.add( this.teleportEntity( passanger, link ) );
}
// We keep track of all so we can remount them on the other side.
passenger.stopRiding();
passengersOnOtherSide.add( this.teleportEntity( passenger, link ) );
}
// We keep track of all so we can remount them on the other side.
// load the chunk!
newWorld.getChunkProvider().provideChunk( MathHelper.floor( link.x ) >> 4, MathHelper.floor( link.z ) >> 4 );
newWorld.getChunkProvider().getChunk( MathHelper.floor( link.x ) >> 4, MathHelper.floor( link.z ) >> 4, ChunkStatus.FULL, true );
if( entity instanceof ServerPlayerEntity && link.dim.provider instanceof StorageWorldProvider )
if( entity instanceof ServerPlayerEntity && link.dim.getDimension() instanceof StorageCellDimension)
{
AppEng.instance().getAdvancementTriggers().getSpatialExplorer().trigger( (ServerPlayerEntity) entity );
}
entity.changeDimension( link.dim.getDimension().getType(), new METeleporter( link ) );
if( !passangersOnOtherSide.isEmpty() )
if( !passengersOnOtherSide.isEmpty() )
{
for( Entity passanger : passangersOnOtherSide )
for( Entity passanger : passengersOnOtherSide )
{
passanger.startRiding( entity, true );
}
@@ -195,12 +193,12 @@ public class StorageHelper
for( final WorldCoord wc : cDst.getUpdates() )
{
cSrc.getWorld().notifyNeighborsOfStateChange( wc.getPos(), Platform.AIR_BLOCK, true );
cSrc.getWorld().notifyNeighborsOfStateChange( wc.getPos(), Platform.AIR_BLOCK );
}
for( final WorldCoord wc : cSrc.getUpdates() )
{
cSrc.getWorld().notifyNeighborsOfStateChange( wc.getPos(), Platform.AIR_BLOCK, true );
cSrc.getWorld().notifyNeighborsOfStateChange( wc.getPos(), Platform.AIR_BLOCK );
}
this.transverseEdges( srcX - 1, srcY - 1, srcZ - 1, srcX + scaleX + 1, srcY + scaleY + 1, srcZ + scaleZ + 1, new TriggerUpdates( srcWorld ) );
@@ -208,14 +206,6 @@ public class StorageHelper
this.transverseEdges( srcX, srcY, srcZ, srcX + scaleX, srcY + scaleY, srcZ + scaleZ, new TriggerUpdates( srcWorld ) );
this.transverseEdges( dstX, dstY, dstZ, dstX + scaleX, dstY + scaleY, dstZ + scaleZ, new TriggerUpdates( dstWorld ) );
/*
* IChunkProvider cp = destination.getChunkProvider(); if ( cp instanceof ChunkProviderServer ) {
* ChunkProviderServer
* srv = (ChunkProviderServer) cp; srv.unloadAllChunks(); }
* cp.unloadQueuedChunks();
*/
}
private static class TriggerUpdates implements ISpatialVisitor
@@ -283,10 +273,12 @@ public class StorageHelper
}
@Override
public void placeEntity( World world, Entity entity, float yaw )
{
entity.setLocationAndAngles( this.destination.x, this.destination.y, this.destination.z, yaw, entity.rotationPitch );
entity.motionX = entity.motionY = entity.motionZ = 0.0D;
public Entity placeEntity(Entity entity, ServerWorld currentWorld, ServerWorld destWorld, float yaw, Function<Boolean, Entity> repositionEntity) {
Entity newEntity = repositionEntity.apply(false);
newEntity.rotationYaw = yaw;
newEntity.setPositionAndUpdate( this.destination.x, this.destination.y, this.destination.z );
newEntity.setMotion(0, 0, 0);
return newEntity;
}
}
}