use of net.minecraft.server.v1_13_R1.WorldServer in project SSB-OneBlock by BG-Software-LLC.
the class NMSAdapter_v1_12_R1 method simulateToolBreak.
@Override
public void simulateToolBreak(Player bukkitPlayer, org.bukkit.block.Block bukkitBlock) {
EntityPlayer entityPlayer = ((CraftPlayer) bukkitPlayer).getHandle();
ItemStack itemStack = entityPlayer.getItemInMainHand();
WorldServer worldServer = ((CraftWorld) bukkitBlock.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
IBlockData blockData = worldServer.getType(blockPosition);
assert itemStack != null;
itemStack.a(worldServer, blockData, blockPosition, entityPlayer);
}
use of net.minecraft.server.v1_13_R1.WorldServer in project SSB-OneBlock by BG-Software-LLC.
the class NMSAdapter_v1_16_R3 method setBlock.
@Override
public void setBlock(Location location, Material type, byte data, String nbt) {
assert location.getWorld() != null;
WorldServer worldServer = ((CraftWorld) location.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ());
worldServer.removeTileEntity(blockPosition);
location.getBlock().setType(type);
if (nbt != null) {
try {
ArgumentBlock argumentBlock = new ArgumentBlock(new StringReader(nbt), false).a(true);
ArgumentTileLocation tileLocation = new ArgumentTileLocation(argumentBlock.getBlockData(), argumentBlock.getStateMap().keySet(), argumentBlock.c());
tileLocation.a(worldServer, blockPosition, 2);
worldServer.update(blockPosition, tileLocation.a().getBlock());
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
use of net.minecraft.server.v1_13_R1.WorldServer in project SSB-OneBlock by BG-Software-LLC.
the class NMSAdapter_v1_16_R3 method simulateToolBreak.
@Override
public void simulateToolBreak(Player bukkitPlayer, org.bukkit.block.Block bukkitBlock) {
EntityPlayer entityPlayer = ((CraftPlayer) bukkitPlayer).getHandle();
ItemStack itemStack = entityPlayer.getItemInMainHand();
WorldServer worldServer = ((CraftWorld) bukkitBlock.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
IBlockData blockData = worldServer.getType(blockPosition);
assert itemStack != null;
itemStack.a(worldServer, blockData, blockPosition, entityPlayer);
}
use of net.minecraft.server.v1_13_R1.WorldServer 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_13_R1.WorldServer in project custom-items-gradle by knokko.
the class Raytracer method raytrace.
/**
* <p>Performs a raytrace from {@code startLocation} towards {@code startLocation + vector}.
* The {@code vector} determines both the direction and the maximum distance of the raytrace!</p>
*
* <p>If an intersection with any block or entity was found, a RaytraceResult representing the intersection
* that is closest to {@code startLocation} will be returned. If no such intersection was found, this
* method will return null.</p>
*
* <p>Entities included in {@code entitiesToExclude} and dropped item entities will be ignored by
* the raytrace.</p>
*
* @param startLocation The location from which the raytrace will start
* @param vector The direction and maximum distance of the raytrace
* @param entitiesToExclude An array of entities that will be ignored by this raytrace, may contain null
* @return A RaytraceResult for the nearest intersection, or null if no intersection was found
*/
public static RaytraceResult raytrace(Location startLocation, Vector vector, Entity... entitiesToExclude) {
// Important variables
World world = startLocation.getWorld();
Vec3D rayStart = new Vec3D(startLocation.getX(), startLocation.getY(), startLocation.getZ());
Vec3D velocityVec = new Vec3D(vector.getX(), vector.getY(), vector.getZ());
Vec3D rayEnd = new Vec3D(rayStart.x + velocityVec.x, rayStart.y + velocityVec.y, rayStart.z + velocityVec.z);
CraftWorld craftWorld = (CraftWorld) world;
WorldServer nmsWorld = craftWorld.getHandle();
// Start with infinity to make sure that any other distance will be shorter
double nearestDistanceSq = Double.POSITIVE_INFINITY;
Vec3D intersectionPos = null;
// The block raytrace
MovingObjectPosition rayResult = nmsWorld.rayTrace(rayStart, rayEnd, true, true, false);
if (rayResult != null && rayResult.type == EnumMovingObjectType.BLOCK) {
double blockDistanceSq = rayResult.pos.distanceSquared(rayStart);
if (blockDistanceSq < vector.lengthSquared()) {
intersectionPos = rayResult.pos;
nearestDistanceSq = blockDistanceSq;
}
}
// The entity raytrace
AxisAlignedBB movementBB = new AxisAlignedBB(rayStart.x, rayStart.y, rayStart.z, rayEnd.x, rayEnd.y, rayEnd.z);
List<net.minecraft.server.v1_12_R1.Entity> nmsEntityList = nmsWorld.getEntities(null, movementBB);
net.minecraft.server.v1_12_R1.Entity intersectedEntity = null;
entityListLoop: for (net.minecraft.server.v1_12_R1.Entity nmsEntity : nmsEntityList) {
// It's currently convenient to ignore dropped items
if (nmsEntity instanceof EntityItem)
continue entityListLoop;
// Since the entities in entitiesToExclude could be null, it's important to call equals() on craftEntity
CraftEntity craftEntity = nmsEntity.getBukkitEntity();
for (Entity exclude : entitiesToExclude) if (craftEntity.equals(exclude))
continue entityListLoop;
// Check if we intersect this entity and check if the distance to it is smaller than the nearest distance so far
MovingObjectPosition entityIntersection = nmsEntity.getBoundingBox().b(rayStart, rayEnd);
if (entityIntersection != null) {
double distanceSq = rayStart.distanceSquared(entityIntersection.pos);
if (distanceSq < nearestDistanceSq) {
nearestDistanceSq = distanceSq;
intersectedEntity = nmsEntity;
intersectionPos = entityIntersection.pos;
}
}
}
// Determining the final result
if (nearestDistanceSq < Double.POSITIVE_INFINITY) {
Location hitLocation = new Location(world, intersectionPos.x, intersectionPos.y, intersectionPos.z);
if (intersectedEntity != null) {
return RaytraceResult.hitEntity(intersectedEntity.getBukkitEntity(), hitLocation);
} else {
return RaytraceResult.hitBlock(hitLocation);
}
} else {
return null;
}
}
Aggregations