use of net.minecraft.server.v1_8_R2.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());
}
}
use of net.minecraft.server.v1_8_R2.TileEntity in project PaperDev by Kamillaova.
the class CraftBlockEntityState method update.
@Override
public boolean update(boolean force, boolean applyPhysics) {
boolean result = super.update(force, applyPhysics);
if (result && this.isPlaced()) {
TileEntity tile = getTileEntityFromWorld();
if (isApplicable(tile)) {
applyTo(tileEntityClass.cast(tile));
tile.update();
}
}
return result;
}
use of net.minecraft.server.v1_8_R2.TileEntity in project PaperDev by Kamillaova.
the class CraftJukebox method eject.
@Override
public boolean eject() {
requirePlaced();
TileEntity tileEntity = this.getTileEntityFromWorld();
if (!(tileEntity instanceof TileEntityRecordPlayer))
return false;
TileEntityRecordPlayer jukebox = (TileEntityRecordPlayer) tileEntity;
boolean result = !jukebox.getRecord().isEmpty();
CraftWorld world = (CraftWorld) this.getWorld();
((BlockJukeBox) Blocks.JUKEBOX).dropRecord(world.getHandle(), new BlockPosition(getX(), getY(), getZ()), null);
return result;
}
Aggregations