Files
Plex-FAWE/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/FallbackChunkGet.java
Matt 96dcb95b7c Javadoc and Formatting fixes. (#619)
Javadoc and Formatting fixes.

Also, extremely minor code changes which have been tested.
This commit is only part one of two commits that aim to fix problems with formatting in our project. In part two I will modify the Google Java Style Guide (since it closely matches our code style) for our project so there is guidance on how to format and document. 

* Updated PlotSquared URL
* Removed plugin acronyms
* Fixed a typo
* Fixed grammar
* Use modern block id's
* Update YouTube video URL
2020-10-05 13:41:41 -04:00

198 lines
6.0 KiB
Java

package com.boydti.fawe.beta.implementation.blocks;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.beta.IBlocks;
import com.boydti.fawe.beta.IChunkGet;
import com.boydti.fawe.beta.IChunkSet;
import com.boydti.fawe.beta.implementation.lighting.HeightMapType;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Future;
public class FallbackChunkGet implements IChunkGet {
private final int bx;
private final int bz;
private final Extent extent;
public FallbackChunkGet(Extent extent, int chunkX, int chunkZ) {
this.extent = extent;
this.bx = chunkX << 4;
this.bz = chunkZ << 4;
}
@Override
public BaseBlock getFullBlock(int x, int y, int z) {
return extent.getFullBlock(bx + x, y, bz + z);
}
@Override
public BiomeType getBiomeType(int x, int y, int z) {
return extent.getBiomeType(bx + x, y, bz + z);
}
@Override
public BlockState getBlock(int x, int y, int z) {
return extent.getBlock(bx + x, y, bz + z);
}
@Override public int getSkyLight(int x, int y, int z) {
return extent.getSkyLight(bx + x, y, bz + z);
}
@Override public int[] getHeightMap(HeightMapType type) {
return extent.getHeightMap(type);
}
@Override public int getEmmittedLight(int x, int y, int z) {
return extent.getEmmittedLight(bx + x, y, bz + z);
}
@Override
public CompoundTag getTile(int x, int y, int z) {
return extent.getFullBlock(bx + x, y, bz + z).getNbtData();
}
@Override
public Map<BlockVector3, CompoundTag> getTiles() {
return null;
}
@Override
public Set<CompoundTag> getEntities() {
List<? extends Entity> result = extent.getEntities(new CuboidRegion(BlockVector3.at(bx, 0, bz), BlockVector3.at(bx + 15, 255, bz + 15)));
if (result.isEmpty()) {
return Collections.emptySet();
}
HashSet<CompoundTag> set = new HashSet<>(result.size());
for (Entity entity : result) {
set.add(entity.getState().getNbtData());
}
return set;
}
@Override
public CompoundTag getEntity(UUID uuid) {
long checkMost = uuid.getMostSignificantBits();
long checkLeast = uuid.getLeastSignificantBits();
for (CompoundTag entityTag : getEntities()) {
long entMost = entityTag.getLong("UUIDMost");
if (entMost == checkMost) {
long entLeast = entityTag.getLong("UUIDLeast");
if (entLeast == checkLeast) {
return entityTag;
}
}
}
return null;
}
@Override public void setCreateCopy(boolean createCopy) {}
@Override public boolean isCreateCopy() {
return false;
}
@Override
public boolean trim(boolean aggressive) {
return true;
}
@Override
public boolean trim(boolean aggressive, int layer) {
return true;
}
@Override
public <T extends Future<T>> T call(IChunkSet set, Runnable finalize) {
for (int layer = 0; layer < 16; layer++) {
if (set.hasSection(layer)) {
char[] arr = set.load(layer);
int by = layer << 4;
for (int y = 0, i = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++, i++) {
char ordinal = arr[i];
if (ordinal != 0) {
BlockState block = BlockState.getFromOrdinal(ordinal);
extent.setBlock(bx + x, by + y, bz + z, block);
}
}
}
}
}
}
Map<BlockVector3, CompoundTag> tiles = set.getTiles();
if (!tiles.isEmpty()) {
for (Map.Entry<BlockVector3, CompoundTag> entry : tiles.entrySet()) {
BlockVector3 pos = entry.getKey();
extent.setTile(bx + pos.getX(), pos.getY(), bz + pos.getZ(), entry.getValue());
}
}
Set<CompoundTag> spawns = set.getEntities();
if (!spawns.isEmpty()) {
for (CompoundTag spawn : spawns) {
BaseEntity ent = new BaseEntity(spawn);
extent.createEntity(ent.getLocation(extent), ent);
}
}
Set<UUID> kills = set.getEntityRemoves();
if (!kills.isEmpty()) {
for (UUID kill : kills) {
extent.removeEntity(0, 0, 0, kill);
}
}
BiomeType[] biomes = set.getBiomes();
if (biomes != null) {
for (int z = 0, i = 0; z < 16; z++) {
for (int x = 0; x < 16; x++, i++) {
BiomeType biome = biomes[i];
if (biome != null) {
extent.setBiome(bx + x, 0, bz + z, biome);
}
}
}
}
return null;
}
@Override
public char[] load(int layer) {
char[] arr = FaweCache.IMP.SECTION_BITS_TO_CHAR.get();
int by = layer << 4;
for (int y = 0, i = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++, i++) {
arr[i] = getBlock(bx + x, by + y, bz + z).getOrdinalChar();
}
}
}
return arr;
}
@Override
public boolean hasSection(int layer) {
return true;
}
@Override
public IBlocks reset() {
return null;
}
}