2019-12-11 01:11:52 +00:00
/ *
* WorldEdit , a Minecraft world manipulation toolkit
* Copyright ( C ) sk89q < http : //www.sk89q.com>
* Copyright ( C ) WorldEdit team and contributors
*
2020-08-25 01:31:47 +00:00
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
2019-12-11 01:11:52 +00:00
* ( at your option ) any later version .
*
2020-08-25 01:31:47 +00:00
* This program 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 General Public License for more details .
2019-12-11 01:11:52 +00:00
*
2020-08-25 01:31:47 +00:00
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < https : //www.gnu.org/licenses/>.
2019-12-11 01:11:52 +00:00
* /
package com.sk89q.worldedit.bukkit.adapter.impl ;
import com.boydti.fawe.Fawe ;
import com.boydti.fawe.FaweCache ;
import com.boydti.fawe.beta.IChunkGet ;
import com.boydti.fawe.beta.implementation.packet.ChunkPacket ;
2020-10-05 17:41:41 +00:00
import com.boydti.fawe.bukkit.adapter.mc1_16_2.BlockMaterial_1_16_2 ;
import com.boydti.fawe.bukkit.adapter.mc1_16_2.BukkitAdapter_1_16_2 ;
import com.boydti.fawe.bukkit.adapter.mc1_16_2.BukkitGetBlocks_1_16_2 ;
import com.boydti.fawe.bukkit.adapter.mc1_16_2.FAWEWorldNativeAccess_1_16 ;
import com.boydti.fawe.bukkit.adapter.mc1_16_2.MapChunkUtil_1_16_2 ;
2020-08-23 15:18:29 +00:00
import com.boydti.fawe.bukkit.adapter.mc1_16_2.nbt.LazyCompoundTag_1_16_2 ;
2019-12-11 01:11:52 +00:00
import com.sk89q.jnbt.CompoundTag ;
2020-10-05 17:41:41 +00:00
import com.sk89q.jnbt.StringTag ;
2019-12-11 01:11:52 +00:00
import com.sk89q.jnbt.Tag ;
import com.sk89q.worldedit.EditSession ;
import com.sk89q.worldedit.blocks.BaseItemStack ;
import com.sk89q.worldedit.blocks.TileEntityBlock ;
import com.sk89q.worldedit.bukkit.BukkitAdapter ;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter ;
import com.sk89q.worldedit.bukkit.adapter.CachedBukkitAdapter ;
import com.sk89q.worldedit.bukkit.adapter.IDelegateBukkitImplAdapter ;
import com.sk89q.worldedit.entity.BaseEntity ;
import com.sk89q.worldedit.entity.LazyBaseEntity ;
2020-03-23 04:02:04 +00:00
import com.sk89q.worldedit.internal.wna.WorldNativeAccess ;
2019-12-11 01:11:52 +00:00
import com.sk89q.worldedit.regions.Region ;
import com.sk89q.worldedit.registry.state.Property ;
2020-03-08 06:09:36 +00:00
import com.sk89q.worldedit.util.SideEffect ;
import com.sk89q.worldedit.util.SideEffectSet ;
2019-12-11 01:11:52 +00:00
import com.sk89q.worldedit.world.biome.BiomeType ;
2020-10-05 17:41:41 +00:00
import com.sk89q.worldedit.world.block.BaseBlock ;
2019-12-11 01:11:52 +00:00
import com.sk89q.worldedit.world.block.BlockState ;
2020-10-05 17:41:41 +00:00
import com.sk89q.worldedit.world.block.BlockStateHolder ;
import com.sk89q.worldedit.world.block.BlockType ;
import com.sk89q.worldedit.world.block.BlockTypes ;
import com.sk89q.worldedit.world.block.BlockTypesCache ;
2019-12-11 01:11:52 +00:00
import com.sk89q.worldedit.world.entity.EntityType ;
import com.sk89q.worldedit.world.registry.BlockMaterial ;
2020-10-05 17:41:41 +00:00
import net.minecraft.server.v1_16_R2.BiomeBase ;
import net.minecraft.server.v1_16_R2.Block ;
import net.minecraft.server.v1_16_R2.BlockPosition ;
import net.minecraft.server.v1_16_R2.Chunk ;
import net.minecraft.server.v1_16_R2.ChunkCoordIntPair ;
import net.minecraft.server.v1_16_R2.ChunkSection ;
import net.minecraft.server.v1_16_R2.Entity ;
import net.minecraft.server.v1_16_R2.EntityPlayer ;
import net.minecraft.server.v1_16_R2.EntityTypes ;
import net.minecraft.server.v1_16_R2.IBlockData ;
import net.minecraft.server.v1_16_R2.IRegistry ;
import net.minecraft.server.v1_16_R2.ItemStack ;
import net.minecraft.server.v1_16_R2.MinecraftKey ;
import net.minecraft.server.v1_16_R2.MinecraftServer ;
import net.minecraft.server.v1_16_R2.NBTBase ;
import net.minecraft.server.v1_16_R2.NBTTagCompound ;
import net.minecraft.server.v1_16_R2.NBTTagInt ;
import net.minecraft.server.v1_16_R2.PacketPlayOutMapChunk ;
import net.minecraft.server.v1_16_R2.PlayerChunk ;
import net.minecraft.server.v1_16_R2.TileEntity ;
import net.minecraft.server.v1_16_R2.World ;
import net.minecraft.server.v1_16_R2.WorldServer ;
2019-12-11 01:11:52 +00:00
import org.bukkit.Bukkit ;
import org.bukkit.Location ;
import org.bukkit.block.data.BlockData ;
2020-08-23 15:18:29 +00:00
import org.bukkit.craftbukkit.v1_16_R2.CraftChunk ;
import org.bukkit.craftbukkit.v1_16_R2.CraftWorld ;
import org.bukkit.craftbukkit.v1_16_R2.block.CraftBlock ;
import org.bukkit.craftbukkit.v1_16_R2.block.data.CraftBlockData ;
import org.bukkit.craftbukkit.v1_16_R2.entity.CraftEntity ;
import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer ;
import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack ;
2019-12-11 01:11:52 +00:00
import org.bukkit.entity.Player ;
2020-03-23 04:02:04 +00:00
import java.lang.ref.WeakReference ;
2020-02-21 02:28:28 +00:00
import java.util.Map ;
import java.util.OptionalInt ;
2020-03-08 06:09:36 +00:00
import java.util.Set ;
2020-02-21 02:28:28 +00:00
import java.util.function.Supplier ;
import java.util.stream.Stream ;
2020-10-05 17:41:41 +00:00
import javax.annotation.Nullable ;
2020-02-21 02:28:28 +00:00
import static com.google.common.base.Preconditions.checkNotNull ;
2020-08-23 15:18:29 +00:00
public final class FAWE_Spigot_v1_16_R2 extends CachedBukkitAdapter implements IDelegateBukkitImplAdapter < NBTBase > {
private final Spigot_v1_16_R2 parent ;
2020-03-26 20:08:36 +00:00
private char [ ] ibdToStateOrdinal ;
2019-12-11 01:11:52 +00:00
// ------------------------------------------------------------------------
// Code that may break between versions of Minecraft
// ------------------------------------------------------------------------
2020-08-23 15:18:29 +00:00
public FAWE_Spigot_v1_16_R2 ( ) throws NoSuchFieldException , NoSuchMethodException {
this . parent = new Spigot_v1_16_R2 ( ) ;
2019-12-11 01:11:52 +00:00
}
@Override
public BukkitImplAdapter < NBTBase > getParent ( ) {
return parent ;
}
private synchronized boolean init ( ) {
2020-10-05 17:41:41 +00:00
if ( ibdToStateOrdinal ! = null & & ibdToStateOrdinal [ 1 ] ! = 0 ) {
return false ;
}
2020-03-26 20:08:36 +00:00
ibdToStateOrdinal = new char [ Block . REGISTRY_ID . a ( ) ] ; // size
for ( int i = 0 ; i < ibdToStateOrdinal . length ; i + + ) {
2019-12-11 01:11:52 +00:00
BlockState state = BlockTypesCache . states [ i ] ;
2020-08-23 15:18:29 +00:00
BlockMaterial_1_16_2 material = ( BlockMaterial_1_16_2 ) state . getMaterial ( ) ;
2019-12-11 01:11:52 +00:00
int id = Block . REGISTRY_ID . getId ( material . getState ( ) ) ;
2020-03-26 20:08:36 +00:00
ibdToStateOrdinal [ id ] = state . getOrdinalChar ( ) ;
2019-12-11 01:11:52 +00:00
}
return true ;
}
@Override
public BlockMaterial getMaterial ( BlockType blockType ) {
2019-12-25 02:34:20 +00:00
Block block = getBlock ( blockType ) ;
2020-08-23 15:18:29 +00:00
return new BlockMaterial_1_16_2 ( block ) ;
2019-12-11 01:11:52 +00:00
}
@Override
public BlockMaterial getMaterial ( BlockState state ) {
IBlockData bs = ( ( CraftBlockData ) Bukkit . createBlockData ( state . getAsString ( ) ) ) . getState ( ) ;
2020-08-23 15:18:29 +00:00
return new BlockMaterial_1_16_2 ( bs . getBlock ( ) , bs ) ;
2019-12-11 01:11:52 +00:00
}
public Block getBlock ( BlockType blockType ) {
return IRegistry . BLOCK . get ( new MinecraftKey ( blockType . getNamespace ( ) , blockType . getResource ( ) ) ) ;
}
@SuppressWarnings ( " deprecation " )
@Override
public BaseBlock getBlock ( Location location ) {
checkNotNull ( location ) ;
CraftWorld craftWorld = ( ( CraftWorld ) location . getWorld ( ) ) ;
int x = location . getBlockX ( ) ;
int y = location . getBlockY ( ) ;
int z = location . getBlockZ ( ) ;
2019-12-11 22:47:34 +00:00
final WorldServer handle = craftWorld . getHandle ( ) ;
Chunk chunk = handle . getChunkAt ( x > > 4 , z > > 4 ) ;
final BlockPosition blockPos = new BlockPosition ( x , y , z ) ;
2019-12-11 01:11:52 +00:00
org . bukkit . block . Block bukkitBlock = location . getBlock ( ) ;
BlockState state = BukkitAdapter . adapt ( bukkitBlock . getBlockData ( ) ) ;
if ( state . getBlockType ( ) . getMaterial ( ) . hasContainer ( ) ) {
2019-12-11 22:47:34 +00:00
// Read the NBT data
TileEntity te = chunk . a ( blockPos , Chunk . EnumTileEntityState . CHECK ) ;
2019-12-11 01:11:52 +00:00
if ( te ! = null ) {
NBTTagCompound tag = new NBTTagCompound ( ) ;
2019-12-11 22:47:34 +00:00
te . save ( tag ) ; // readTileEntityIntoTag - load data
2019-12-11 01:11:52 +00:00
return state . toBaseBlock ( ( CompoundTag ) toNative ( tag ) ) ;
}
}
return state . toBaseBlock ( ) ;
}
2020-03-08 06:09:36 +00:00
@Override
public Set < SideEffect > getSupportedSideEffects ( ) {
return SideEffectSet . defaults ( ) . getSideEffectsToApply ( ) ;
}
public boolean setBlock ( org . bukkit . Chunk chunk , int x , int y , int z , BlockStateHolder state , boolean update ) {
2019-12-11 01:11:52 +00:00
CraftChunk craftChunk = ( CraftChunk ) chunk ;
Chunk nmsChunk = craftChunk . getHandle ( ) ;
World nmsWorld = nmsChunk . getWorld ( ) ;
2019-12-11 22:47:34 +00:00
BlockPosition blockPos = new BlockPosition ( x , y , z ) ;
2020-08-23 15:18:29 +00:00
IBlockData blockData = ( ( BlockMaterial_1_16_2 ) state . getMaterial ( ) ) . getState ( ) ;
2019-12-11 01:11:52 +00:00
ChunkSection [ ] sections = nmsChunk . getSections ( ) ;
int y4 = y > > 4 ;
ChunkSection section = sections [ y4 ] ;
IBlockData existing ;
if ( section = = null ) {
2020-08-23 15:18:29 +00:00
existing = ( ( BlockMaterial_1_16_2 ) BlockTypes . AIR . getDefaultState ( ) . getMaterial ( ) ) . getState ( ) ;
2019-12-11 01:11:52 +00:00
} else {
existing = section . getType ( x & 15 , y & 15 , z & 15 ) ;
}
2019-12-11 22:47:34 +00:00
nmsChunk . removeTileEntity ( blockPos ) ; // Force delete the old tile entity
2019-12-11 01:11:52 +00:00
CompoundTag nativeTag = state instanceof BaseBlock ? ( ( BaseBlock ) state ) . getNbtData ( ) : null ;
if ( nativeTag ! = null | | existing instanceof TileEntityBlock ) {
2019-12-11 22:47:34 +00:00
nmsWorld . setTypeAndData ( blockPos , blockData , 0 ) ;
2019-12-11 01:11:52 +00:00
// remove tile
if ( nativeTag ! = null ) {
// We will assume that the tile entity was created for us,
// though we do not do this on the Forge version
2019-12-11 22:47:34 +00:00
TileEntity tileEntity = nmsWorld . getTileEntity ( blockPos ) ;
2019-12-11 01:11:52 +00:00
if ( tileEntity ! = null ) {
NBTTagCompound tag = ( NBTTagCompound ) fromNative ( nativeTag ) ;
2019-12-11 22:47:34 +00:00
tag . set ( " x " , NBTTagInt . a ( x ) ) ;
tag . set ( " y " , NBTTagInt . a ( y ) ) ;
tag . set ( " z " , NBTTagInt . a ( z ) ) ;
2020-06-26 23:08:45 +00:00
tileEntity . load ( tileEntity . getBlock ( ) , tag ) ; // readTagIntoTileEntity - load data
2019-12-11 01:11:52 +00:00
}
}
} else {
2020-10-05 17:41:41 +00:00
if ( existing = = blockData ) {
return true ;
}
2019-12-11 01:11:52 +00:00
if ( section = = null ) {
2020-10-05 17:41:41 +00:00
if ( blockData . isAir ( ) ) {
return true ;
}
2019-12-11 01:11:52 +00:00
sections [ y4 ] = section = new ChunkSection ( y4 < < 4 ) ;
}
2019-12-11 22:47:34 +00:00
nmsChunk . setType ( blockPos , blockData , false ) ;
2019-12-11 01:11:52 +00:00
}
if ( update ) {
2019-12-11 22:47:34 +00:00
nmsWorld . getMinecraftWorld ( ) . notify ( blockPos , existing , blockData , 0 ) ;
2019-12-11 01:11:52 +00:00
}
return true ;
}
2020-03-23 04:02:04 +00:00
@Override
public WorldNativeAccess < ? , ? , ? > createWorldNativeAccess ( org . bukkit . World world ) {
return new FAWEWorldNativeAccess_1_16 ( this ,
new WeakReference < > ( ( ( CraftWorld ) world ) . getHandle ( ) ) ) ;
}
2019-12-11 01:11:52 +00:00
@Nullable
private static String getEntityId ( Entity entity ) {
MinecraftKey minecraftkey = EntityTypes . getName ( entity . getEntityType ( ) ) ;
return minecraftkey = = null ? null : minecraftkey . toString ( ) ;
}
private static void readEntityIntoTag ( Entity entity , NBTTagCompound tag ) {
entity . save ( tag ) ;
}
@Override
public BaseEntity getEntity ( org . bukkit . entity . Entity entity ) {
checkNotNull ( entity ) ;
CraftEntity craftEntity = ( ( CraftEntity ) entity ) ;
Entity mcEntity = craftEntity . getHandle ( ) ;
String id = getEntityId ( mcEntity ) ;
if ( id ! = null ) {
EntityType type = com . sk89q . worldedit . world . entity . EntityTypes . get ( id ) ;
Supplier < CompoundTag > saveTag = ( ) - > {
NBTTagCompound tag = new NBTTagCompound ( ) ;
readEntityIntoTag ( mcEntity , tag ) ;
2020-10-05 17:41:41 +00:00
2020-07-29 20:43:52 +00:00
//add Id for AbstractChangeSet to work
CompoundTag natve = ( CompoundTag ) toNative ( tag ) ;
natve . getValue ( ) . put ( " Id " , new StringTag ( id ) ) ;
return natve ;
2019-12-11 01:11:52 +00:00
} ;
return new LazyBaseEntity ( type , saveTag ) ;
} else {
return null ;
}
}
@Override
public OptionalInt getInternalBlockStateId ( BlockState state ) {
2020-08-23 15:18:29 +00:00
BlockMaterial_1_16_2 material = ( BlockMaterial_1_16_2 ) state . getMaterial ( ) ;
2019-12-11 01:11:52 +00:00
IBlockData mcState = material . getCraftBlockData ( ) . getState ( ) ;
return OptionalInt . of ( Block . REGISTRY_ID . getId ( mcState ) ) ;
}
@Override
public BlockState adapt ( BlockData blockData ) {
CraftBlockData cbd = ( ( CraftBlockData ) blockData ) ;
IBlockData ibd = cbd . getState ( ) ;
return adapt ( ibd ) ;
}
public BlockState adapt ( IBlockData ibd ) {
2020-03-26 20:08:36 +00:00
return BlockTypesCache . states [ adaptToChar ( ibd ) ] ;
2019-12-11 01:11:52 +00:00
}
2020-03-26 20:08:36 +00:00
/ * *
* @deprecated
* Method unused . Use # adaptToChar ( IBlockData ) .
* /
@Deprecated
2019-12-11 01:11:52 +00:00
public int adaptToInt ( IBlockData ibd ) {
2020-03-26 20:08:36 +00:00
synchronized ( this ) {
try {
int id = Block . REGISTRY_ID . getId ( ibd ) ;
return ibdToStateOrdinal [ id ] ;
} catch ( NullPointerException e ) {
init ( ) ;
return adaptToInt ( ibd ) ;
}
2019-12-11 01:11:52 +00:00
}
}
public char adaptToChar ( IBlockData ibd ) {
2020-03-26 20:08:36 +00:00
synchronized ( this ) {
try {
int id = Block . REGISTRY_ID . getId ( ibd ) ;
return ibdToStateOrdinal [ id ] ;
} catch ( NullPointerException e ) {
init ( ) ;
return adaptToChar ( ibd ) ;
2020-10-05 17:41:41 +00:00
} catch ( ArrayIndexOutOfBoundsException e1 ) {
2020-03-26 20:08:36 +00:00
Fawe . debug ( " Attempted to convert " + ibd . getBlock ( ) + " with ID " + Block . REGISTRY_ID . getId ( ibd ) + " to char. ibdToStateOrdinal length: " + ibdToStateOrdinal . length + " . Defaulting to air! " ) ;
return 0 ;
}
2019-12-11 01:11:52 +00:00
}
}
@Override
2020-01-16 01:38:46 +00:00
public < B extends BlockStateHolder < B > > BlockData adapt ( B state ) {
2020-08-23 15:18:29 +00:00
BlockMaterial_1_16_2 material = ( BlockMaterial_1_16_2 ) state . getMaterial ( ) ;
2019-12-11 01:11:52 +00:00
return material . getCraftBlockData ( ) ;
}
2020-08-23 15:18:29 +00:00
private MapChunkUtil_1_16_2 mapUtil = new MapChunkUtil_1_16_2 ( ) ;
2019-12-11 01:11:52 +00:00
@Override
public void sendFakeChunk ( org . bukkit . World world , Player player , ChunkPacket packet ) {
WorldServer nmsWorld = ( ( CraftWorld ) world ) . getHandle ( ) ;
2020-08-23 15:18:29 +00:00
PlayerChunk map = BukkitAdapter_1_16_2 . getPlayerChunk ( nmsWorld , packet . getChunkX ( ) , packet . getChunkZ ( ) ) ;
2019-12-11 01:11:52 +00:00
if ( map ! = null & & map . hasBeenLoaded ( ) ) {
boolean flag = false ;
PlayerChunk . d players = map . players ;
Stream < EntityPlayer > stream = players . a ( new ChunkCoordIntPair ( packet . getChunkX ( ) , packet . getChunkZ ( ) ) , flag ) ;
EntityPlayer checkPlayer = player = = null ? null : ( ( CraftPlayer ) player ) . getHandle ( ) ;
stream . filter ( entityPlayer - > checkPlayer = = null | | entityPlayer = = checkPlayer )
. forEach ( entityPlayer - > {
synchronized ( packet ) {
PacketPlayOutMapChunk nmsPacket = ( PacketPlayOutMapChunk ) packet . getNativePacket ( ) ;
if ( nmsPacket = = null ) {
nmsPacket = mapUtil . create ( this , packet ) ;
packet . setNativePacket ( nmsPacket ) ;
}
try {
2020-01-29 20:01:38 +00:00
FaweCache . IMP . CHUNK_FLAG . get ( ) . set ( true ) ;
2019-12-11 01:11:52 +00:00
entityPlayer . playerConnection . sendPacket ( nmsPacket ) ;
} finally {
2020-01-29 20:01:38 +00:00
FaweCache . IMP . CHUNK_FLAG . get ( ) . set ( false ) ;
2019-12-11 01:11:52 +00:00
}
}
} ) ;
}
}
@Override
public Map < String , ? extends Property < ? > > getProperties ( BlockType blockType ) {
return getParent ( ) . getProperties ( blockType ) ;
}
@Override
public org . bukkit . inventory . ItemStack adapt ( BaseItemStack item ) {
ItemStack stack = new ItemStack ( IRegistry . ITEM . get ( MinecraftKey . a ( item . getType ( ) . getId ( ) ) ) , item . getAmount ( ) ) ;
stack . setTag ( ( ( NBTTagCompound ) fromNative ( item . getNbtData ( ) ) ) ) ;
return CraftItemStack . asCraftMirror ( stack ) ;
}
@Override
public BaseItemStack adapt ( org . bukkit . inventory . ItemStack itemStack ) {
final ItemStack nmsStack = CraftItemStack . asNMSCopy ( itemStack ) ;
final BaseItemStack weStack = new BaseItemStack ( BukkitAdapter . asItemType ( itemStack . getType ( ) ) , itemStack . getAmount ( ) ) ;
weStack . setNbtData ( ( ( CompoundTag ) toNative ( nmsStack . getTag ( ) ) ) ) ;
return weStack ;
}
@Override
public Tag toNative ( NBTBase foreign ) {
return parent . toNative ( foreign ) ;
}
@Override
public NBTBase fromNative ( Tag foreign ) {
2020-08-23 15:18:29 +00:00
if ( foreign instanceof LazyCompoundTag_1_16_2 ) {
return ( ( LazyCompoundTag_1_16_2 ) foreign ) . get ( ) ;
2019-12-11 01:11:52 +00:00
}
return parent . fromNative ( foreign ) ;
}
@Override
2020-04-28 15:16:51 +00:00
public boolean regenerate ( org . bukkit . World world , Region region , EditSession editSession ) {
2020-06-26 23:08:45 +00:00
// WorldServer originalWorld = ((CraftWorld) world).getHandle();
// ChunkProviderServer provider = originalWorld.getChunkProvider();
// if (!(provider instanceof ChunkProviderServer)) {
// return false;
// }
//
// File saveFolder = Files.createTempDir();
// // register this just in case something goes wrong
// // normally it should be deleted at the end of this method
// saveFolder.deleteOnExit();
// try {
// MinecraftServer server = originalWorld.getServer().getServer();
// Convertable.ConversionSession originalDataManager = server.convertable;
//// Convertable.ConversionSession saveHandler = new Convertable.ConversionSession(world.getName(), world.);
// WorldData newWorldData = new WorldData(originalWorld.worldData.a((NBTTagCompound) null),
// server.dataConverterManager, getDataVersion(), null);
// newWorldData.setName(UUID.randomUUID().toString());
//
// ChunkGenerator gen = world.getGenerator();
// Environment env = world.getEnvironment();
// try (WorldServer freshWorld = new WorldServer(server,
// server.executorService, originalDataManager,
// newWorldData,
// originalWorld.worldProvider.getDimensionManager(),
// originalWorld.getMethodProfiler(),
// server.worldLoadListenerFactory.create(11),
// env,
2020-10-05 17:41:41 +00:00
// gen) {
2020-06-26 23:08:45 +00:00
// @Override
// public boolean addEntityChunk(Entity entity) {
// //Fixes #320; Prevent adding entities so we aren't attempting to spawn them asynchronously
// return false;
// }
// }) {
//
// // Pre-gen all the chunks
// // We need to also pull one more chunk in every direction
// Fawe.get().getQueueHandler().startSet(true);
// try {
// IQueueExtent<IQueueChunk> extent = new SingleThreadQueueExtent();
2020-08-23 15:18:29 +00:00
// extent.init(null, (x, z) -> new BukkitGetBlocks_1_16_2(freshWorld, x, z) {
2020-06-26 23:08:45 +00:00
// @Override
// public Chunk ensureLoaded(World nmsWorld, int X, int Z) {
// Chunk cached = nmsWorld.getChunkIfLoaded(X, Z);
// if (cached != null) return cached;
// Future<Chunk> future = Fawe.get().getQueueHandler().sync((Supplier<Chunk>) () -> freshWorld.getChunkAt(X, Z));
// while (!future.isDone()) {
// // this feels so dirty
// freshWorld.getChunkProvider().runTasks();
// }
// try {
// return future.get();
// } catch (InterruptedException | ExecutionException e) {
// throw new RuntimeException(e);
// }
// }
// }, null);
// for (BlockVector3 vec : region) {
// editSession.setBlock(vec, extent.getFullBlock(vec));
// }
// } finally {
// Fawe.get().getQueueHandler().endSet(true);
// }
// } catch (IOException e) {
// throw new RuntimeException(e);
// }
// } catch (MaxChangedBlocksException e) {
// throw new RuntimeException(e);
// } finally {
// saveFolder.delete();
// }
// return true;
return false ; //TODO: rework or remove for 1.16
2019-12-11 01:11:52 +00:00
}
@Override
public IChunkGet get ( org . bukkit . World world , int chunkX , int chunkZ ) {
2020-08-23 15:18:29 +00:00
return new BukkitGetBlocks_1_16_2 ( world , chunkX , chunkZ ) ;
2019-12-11 01:11:52 +00:00
}
@Override
public int getInternalBiomeId ( BiomeType biome ) {
2020-08-23 16:31:33 +00:00
BiomeBase base = CraftBlock . biomeToBiomeBase ( MinecraftServer . getServer ( ) . aX ( ) . b ( IRegistry . ay ) , BukkitAdapter . adapt ( biome ) ) ;
2020-08-23 16:28:51 +00:00
return MinecraftServer . getServer ( ) . aX ( ) . b ( IRegistry . ay ) . a ( base ) ;
2019-12-11 01:11:52 +00:00
}
2019-12-11 22:47:34 +00:00
}