use of net.minecraft.server.v1_7_R4.Chunk in project RoseStacker by Rosewood-Development.
the class NMSHandlerImpl method createEntityFromNBT.
@Override
public LivingEntity createEntityFromNBT(StackedEntityDataEntry<?> serialized, Location location, boolean addToWorld, EntityType entityType) {
try {
NBTTagCompound nbt = (NBTTagCompound) serialized.get();
NBTTagList positionTagList = nbt.getList("Pos", 6);
if (positionTagList == null)
positionTagList = new NBTTagList();
this.setTag(positionTagList, 0, NBTTagDouble.a(location.getX()));
this.setTag(positionTagList, 1, NBTTagDouble.a(location.getY()));
this.setTag(positionTagList, 2, NBTTagDouble.a(location.getZ()));
nbt.set("Pos", positionTagList);
NBTTagList rotationTagList = nbt.getList("Rotation", 5);
if (rotationTagList == null)
rotationTagList = new NBTTagList();
this.setTag(rotationTagList, 0, NBTTagFloat.a(location.getYaw()));
this.setTag(rotationTagList, 1, NBTTagFloat.a(location.getPitch()));
nbt.set("Rotation", rotationTagList);
// Reset the UUID to resolve possible duplicates
nbt.a("UUID", UUID.randomUUID());
Optional<EntityTypes<?>> optionalEntity = EntityTypes.a(entityType.getKey().getKey());
if (optionalEntity.isPresent()) {
WorldServer world = ((CraftWorld) location.getWorld()).getHandle();
Entity entity = this.createCreature(optionalEntity.get(), world, nbt, null, null, new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()), EnumMobSpawn.COMMAND);
if (entity == null)
throw new NullPointerException("Unable to create entity from NBT");
// Load NBT
entity.load(nbt);
if (addToWorld) {
IChunkAccess ichunkaccess = world.getChunkAt(MathHelper.floor(entity.locX() / 16.0D), MathHelper.floor(entity.locZ() / 16.0D), ChunkStatus.FULL, true);
if (!(ichunkaccess instanceof Chunk))
throw new NullPointerException("Unable to spawn entity from NBT, couldn't get chunk");
ichunkaccess.a(entity);
method_WorldServer_registerEntity.invoke(world, entity);
entity.noDamageTicks = 0;
}
return (LivingEntity) entity.getBukkitEntity();
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of net.minecraft.server.v1_7_R4.Chunk in project RoseStacker by Rosewood-Development.
the class NMSHandlerImpl method spawnExistingEntity.
@Override
public void spawnExistingEntity(LivingEntity entity, SpawnReason spawnReason, boolean bypassSpawnEvent) {
Location location = entity.getLocation();
World world = location.getWorld();
if (world == null)
throw new IllegalArgumentException("Entity is not in a loaded world");
if (bypassSpawnEvent) {
IChunkAccess ichunkaccess = ((CraftWorld) world).getHandle().getChunkAt(MathHelper.floor(entity.getLocation().getX() / 16.0D), MathHelper.floor(entity.getLocation().getZ() / 16.0D), ChunkStatus.FULL, false);
if (!(ichunkaccess instanceof Chunk))
return;
ichunkaccess.a(((CraftEntity) entity).getHandle());
((CraftWorld) world).getHandle().addEntityChunk(((CraftEntity) entity).getHandle());
} else {
((CraftWorld) world).addEntity(((CraftEntity) entity).getHandle(), spawnReason);
}
}
use of net.minecraft.server.v1_7_R4.Chunk in project Movecraft by APDevTeam.
the class IWorldHandler method moveTileEntity.
private void moveTileEntity(@NotNull World nativeWorld, @NotNull BlockPosition newPosition, @NotNull TileEntity tile) {
Chunk chunk = nativeWorld.getChunkAtWorldCoords(newPosition);
tile.invalidateBlockCache();
tile.setLocation(nativeWorld, newPosition);
if (nativeWorld.captureBlockStates) {
tile.setLocation(nativeWorld, newPosition);
nativeWorld.capturedTileEntities.put(newPosition, tile);
return;
}
chunk.tileEntities.put(newPosition, tile);
}
use of net.minecraft.server.v1_7_R4.Chunk in project Movecraft by APDevTeam.
the class IWorldHandler method moveTileEntity.
private void moveTileEntity(@NotNull World nativeWorld, @NotNull BlockPosition newPosition, @NotNull TileEntity tile) {
Chunk chunk = nativeWorld.getChunkAtWorldCoords(newPosition);
tile.invalidateBlockCache();
tile.setWorld(nativeWorld);
tile.setPosition(newPosition);
if (nativeWorld.captureBlockStates) {
tile.setWorld(nativeWorld);
tile.setPosition(newPosition);
nativeWorld.capturedTileEntities.put(newPosition, tile);
return;
}
chunk.tileEntities.put(newPosition, tile);
}
use of net.minecraft.server.v1_7_R4.Chunk in project TheAPI by TheDevTec.
the class v1_7_R4 method getChunk.
@Override
public Object getChunk(World world, int x, int z) {
WorldServer sworld = ((CraftWorld) world).getHandle();
net.minecraft.server.v1_7_R4.Chunk loaded = ((ChunkProviderServer) sworld.L()).getChunkIfLoaded(x, z);
if (loaded == null) {
// load
try {
net.minecraft.server.v1_7_R4.Chunk chunk;
chunk = ((IChunkLoader) Ref.get(((ChunkProviderServer) sworld.L()), chunkLoader)).a(sworld, x, z);
if (chunk != null) {
chunk.lastSaved = sworld.getTime();
if (((ChunkProviderServer) sworld.L()).chunkProvider != null) {
((ChunkProviderServer) sworld.L()).chunkProvider.recreateStructures(x, z);
}
}
if (chunk != null) {
((ChunkProviderServer) sworld.L()).chunks.put(ChunkCoordIntPair.a(x, z), chunk);
postToMainThread(() -> {
chunk.addEntities();
});
loaded = chunk;
}
} catch (Exception e) {
}
}
if (loaded == null) {
// generate new chunk
ChunkRegionLoader loader = null;
if ((IChunkLoader) Ref.get(((ChunkProviderServer) sworld.L()), chunkLoader) instanceof ChunkRegionLoader) {
loader = (ChunkRegionLoader) Ref.get(((ChunkProviderServer) sworld.L()), chunkLoader);
}
if (loader != null && loader.chunkExists(sworld, x, z)) {
loaded = ChunkIOExecutor.syncChunkLoad(sworld, loader, (ChunkProviderServer) sworld.L(), x, z);
} else {
loaded = ((ChunkProviderServer) sworld.L()).originalGetChunkAt(x, z);
}
loaded = ((ChunkProviderServer) sworld.L()).chunkProvider.getOrCreateChunk(x, z);
((ChunkProviderServer) sworld.L()).chunks.put(ChunkCoordIntPair.a(x, z), loaded);
}
return loaded;
}
Aggregations