use of net.minecraft.server.v1_16_R3.TileEntity in project WildLoaders by BG-Software-LLC.
the class NMSAdapter_v1_7_R4 method createLoader.
@Override
public ITileEntityChunkLoader createLoader(ChunkLoader chunkLoader) {
Location loaderLoc = chunkLoader.getLocation();
World world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
int x = loaderLoc.getBlockX(), y = loaderLoc.getBlockY(), z = loaderLoc.getBlockZ();
TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, x, y, z);
// noinspection unchecked
world.tileEntityList.add(tileEntityChunkLoader);
for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
// noinspection unchecked
chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> {
NBTTagCompound nbtTagCompound = new NBTTagCompound();
((TileEntity) tileEntity).b(nbtTagCompound);
nbtTagCompound.setShort("RequiredPlayerRange", (short) -1);
((TileEntity) tileEntity).a(nbtTagCompound);
});
}
return tileEntityChunkLoader;
}
use of net.minecraft.server.v1_16_R3.TileEntity in project WildLoaders by BG-Software-LLC.
the class NMSAdapter_v1_12_R1 method createLoader.
@Override
public ITileEntityChunkLoader createLoader(ChunkLoader chunkLoader) {
Location loaderLoc = chunkLoader.getLocation();
World world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ());
TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition);
world.tileEntityListTick.add(tileEntityChunkLoader);
for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> {
NBTTagCompound nbtTagCompound = new NBTTagCompound();
tileEntity.save(nbtTagCompound);
nbtTagCompound.setShort("RequiredPlayerRange", (short) -1);
try {
compoundLoadMethod.invoke(tileEntity, nbtTagCompound);
} catch (Throwable ex) {
tileEntity.a(nbtTagCompound);
}
});
}
return tileEntityChunkLoader;
}
use of net.minecraft.server.v1_16_R3.TileEntity in project WildLoaders by BG-Software-LLC.
the class NMSAdapter_v1_16_R3 method createLoader.
@Override
public ITileEntityChunkLoader createLoader(ChunkLoader chunkLoader) {
Location loaderLoc = chunkLoader.getLocation();
assert loaderLoc.getWorld() != null;
WorldServer world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ());
TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition);
world.tileEntityListTick.add(tileEntityChunkLoader);
for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = -1);
world.setForceLoaded(chunk.getPos().x, chunk.getPos().z, true);
}
return tileEntityChunkLoader;
}
use of net.minecraft.server.v1_16_R3.TileEntity in project Movecraft by APDevTeam.
the class IWorldHandler method rotateCraft.
@Override
public void rotateCraft(@NotNull Craft craft, @NotNull MovecraftLocation originPoint, @NotNull MovecraftRotation rotation) {
// *******************************************
// * Step one: Convert to Positions *
// *******************************************
HashMap<BlockPosition, BlockPosition> rotatedPositions = new HashMap<>();
MovecraftRotation counterRotation = rotation == MovecraftRotation.CLOCKWISE ? MovecraftRotation.ANTICLOCKWISE : MovecraftRotation.CLOCKWISE;
for (MovecraftLocation newLocation : craft.getHitBox()) {
rotatedPositions.put(locationToPosition(MathUtils.rotateVec(counterRotation, newLocation.subtract(originPoint)).add(originPoint)), locationToPosition(newLocation));
}
// *******************************************
// * Step two: Get the tiles *
// *******************************************
WorldServer nativeWorld = ((CraftWorld) craft.getWorld()).getHandle();
List<TileHolder> tiles = new ArrayList<>();
// get the tiles
for (BlockPosition position : rotatedPositions.keySet()) {
// TileEntity tile = nativeWorld.removeTileEntity(position);
TileEntity tile = removeTileEntity(nativeWorld, position);
if (tile == null)
continue;
tile.a(ROTATION[rotation.ordinal()]);
// get the nextTick to move with the tile
tiles.add(new TileHolder(tile, tickProvider.getNextTick(nativeWorld, position), position));
}
// *******************************************
// * Step three: Translate all the blocks *
// *******************************************
// blockedByWater=false means an ocean-going vessel
// TODO: Simplify
// TODO: go by chunks
// TODO: Don't move unnecessary blocks
// get the blocks and rotate them
HashMap<BlockPosition, IBlockData> blockData = new HashMap<>();
for (BlockPosition position : rotatedPositions.keySet()) {
blockData.put(position, nativeWorld.getType(position).a(ROTATION[rotation.ordinal()]));
}
// create the new block
for (Map.Entry<BlockPosition, IBlockData> entry : blockData.entrySet()) {
setBlockFast(nativeWorld, rotatedPositions.get(entry.getKey()), entry.getValue());
}
// TODO: go by chunks
for (TileHolder tileHolder : tiles) {
moveTileEntity(nativeWorld, rotatedPositions.get(tileHolder.getTilePosition()), tileHolder.getTile());
if (tileHolder.getNextTick() == null)
continue;
final long currentTime = nativeWorld.worldData.getTime();
nativeWorld.getBlockTickList().a(rotatedPositions.get(tileHolder.getNextTick().a), (Block) tileHolder.getNextTick().b(), (int) (tileHolder.getNextTick().b - currentTime), tileHolder.getNextTick().c);
}
// *******************************************
// * Step five: Destroy the leftovers *
// *******************************************
// TODO: add support for pass-through
Collection<BlockPosition> deletePositions = CollectionUtils.filter(rotatedPositions.keySet(), rotatedPositions.values());
for (BlockPosition position : deletePositions) {
setBlockFast(nativeWorld, position, Blocks.AIR.getBlockData());
}
}
use of net.minecraft.server.v1_16_R3.TileEntity in project Movecraft by APDevTeam.
the class IWorldHandler method translateCraft.
@Override
public void translateCraft(@NotNull Craft craft, @NotNull MovecraftLocation displacement, @NotNull org.bukkit.World world) {
// TODO: Add support for rotations
// A craftTranslateCommand should only occur if the craft is moving to a valid position
// *******************************************
// * Step one: Convert to Positions *
// *******************************************
BlockPosition translateVector = locationToPosition(displacement);
List<BlockPosition> positions = new ArrayList<>(craft.getHitBox().size());
craft.getHitBox().forEach((movecraftLocation) -> positions.add(locationToPosition((movecraftLocation)).b(translateVector)));
WorldServer oldNativeWorld = ((CraftWorld) craft.getWorld()).getHandle();
World nativeWorld = ((CraftWorld) world).getHandle();
// *******************************************
// * Step two: Get the tiles *
// *******************************************
List<TileHolder> tiles = new ArrayList<>();
// get the tiles
for (int i = 0, positionsSize = positions.size(); i < positionsSize; i++) {
BlockPosition position = positions.get(i);
if (oldNativeWorld.getType(position) == Blocks.AIR.getBlockData())
continue;
// TileEntity tile = nativeWorld.removeTileEntity(position);
TileEntity tile = removeTileEntity(oldNativeWorld, position);
if (tile == null)
continue;
// get the nextTick to move with the tile
// nativeWorld.capturedTileEntities.remove(position);
// nativeWorld.getChunkAtWorldCoords(position).getTileEntities().remove(position);
tiles.add(new TileHolder(tile, tickProvider.getNextTick(oldNativeWorld, position), position));
}
// *******************************************
// * Step three: Translate all the blocks *
// *******************************************
// blockedByWater=false means an ocean-going vessel
// TODO: Simplify
// TODO: go by chunks
// TODO: Don't move unnecessary blocks
// get the blocks and translate the positions
List<IBlockData> blockData = new ArrayList<>();
List<BlockPosition> newPositions = new ArrayList<>();
for (int i = 0, positionsSize = positions.size(); i < positionsSize; i++) {
BlockPosition position = positions.get(i);
blockData.add(oldNativeWorld.getType(position));
newPositions.add(position.a(translateVector));
}
// create the new block
for (int i = 0, positionSize = newPositions.size(); i < positionSize; i++) {
setBlockFast(nativeWorld, newPositions.get(i), blockData.get(i));
}
// TODO: go by chunks
for (int i = 0, tilesSize = tiles.size(); i < tilesSize; i++) {
TileHolder tileHolder = tiles.get(i);
moveTileEntity(nativeWorld, tileHolder.getTilePosition().a(translateVector), tileHolder.getTile());
if (tileHolder.getNextTick() == null)
continue;
final long currentTime = nativeWorld.worldData.getTime();
nativeWorld.getBlockTickList().a(tileHolder.getNextTick().a.a(translateVector), (Block) tileHolder.getNextTick().b(), (int) (tileHolder.getNextTick().b - currentTime), tileHolder.getNextTick().c);
}
// *******************************************
// * Step five: Destroy the leftovers *
// *******************************************
List<BlockPosition> deletePositions = positions;
if (oldNativeWorld == nativeWorld)
deletePositions = CollectionUtils.filter(positions, newPositions);
for (int i = 0, deletePositionsSize = deletePositions.size(); i < deletePositionsSize; i++) {
BlockPosition position = deletePositions.get(i);
setBlockFast(oldNativeWorld, position, Blocks.AIR.getBlockData());
}
}
Aggregations