Search in sources :

Example 51 with WorldServer

use of net.minecraft.server.v1_8_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);
}
Also used : IBlockData(net.minecraft.server.v1_12_R1.IBlockData) BlockPosition(net.minecraft.server.v1_12_R1.BlockPosition) EntityPlayer(net.minecraft.server.v1_12_R1.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer) WorldServer(net.minecraft.server.v1_12_R1.WorldServer) ItemStack(net.minecraft.server.v1_12_R1.ItemStack) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld)

Example 52 with WorldServer

use of net.minecraft.server.v1_8_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();
        }
    }
}
Also used : ArgumentTileLocation(net.minecraft.server.v1_16_R3.ArgumentTileLocation) ArgumentBlock(net.minecraft.server.v1_16_R3.ArgumentBlock) BlockPosition(net.minecraft.server.v1_16_R3.BlockPosition) StringReader(com.mojang.brigadier.StringReader) WorldServer(net.minecraft.server.v1_16_R3.WorldServer) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld)

Example 53 with WorldServer

use of net.minecraft.server.v1_8_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);
}
Also used : IBlockData(net.minecraft.server.v1_16_R3.IBlockData) BlockPosition(net.minecraft.server.v1_16_R3.BlockPosition) EntityPlayer(net.minecraft.server.v1_16_R3.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) WorldServer(net.minecraft.server.v1_16_R3.WorldServer) ItemStack(net.minecraft.server.v1_16_R3.ItemStack) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld)

Example 54 with WorldServer

use of net.minecraft.server.v1_8_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());
    }
}
Also used : HashMap(java.util.HashMap) BlockPosition(net.minecraft.server.v1_16_R3.BlockPosition) ArrayList(java.util.ArrayList) WorldServer(net.minecraft.server.v1_16_R3.WorldServer) MovecraftRotation(net.countercraft.movecraft.MovecraftRotation) TileEntity(net.minecraft.server.v1_16_R3.TileEntity) IBlockData(net.minecraft.server.v1_16_R3.IBlockData) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld) HashMap(java.util.HashMap) Map(java.util.Map)

Example 55 with WorldServer

use of net.minecraft.server.v1_8_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;
    }
}
Also used : AxisAlignedBB(net.minecraft.server.v1_12_R1.AxisAlignedBB) Entity(org.bukkit.entity.Entity) CraftEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity) CraftEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity) WorldServer(net.minecraft.server.v1_12_R1.WorldServer) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld) World(org.bukkit.World) Vec3D(net.minecraft.server.v1_12_R1.Vec3D) MovingObjectPosition(net.minecraft.server.v1_12_R1.MovingObjectPosition) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld) EntityItem(net.minecraft.server.v1_12_R1.EntityItem) Location(org.bukkit.Location)

Aggregations

WorldServer (net.minecraft.server.v1_16_R3.WorldServer)24 WorldServer (net.minecraft.server.v1_12_R1.WorldServer)20 CraftWorld (org.bukkit.craftbukkit.v1_16_R3.CraftWorld)19 ArrayList (java.util.ArrayList)18 List (java.util.List)16 UUID (java.util.UUID)16 CraftWorld (org.bukkit.craftbukkit.v1_12_R1.CraftWorld)16 GameProfile (com.mojang.authlib.GameProfile)15 WorldServer (net.minecraft.server.v1_11_R1.WorldServer)15 Material (org.bukkit.Material)15 WorldServer (net.minecraft.server.v1_14_R1.WorldServer)14 WorldServer (net.minecraft.server.v1_15_R1.WorldServer)14 WorldServer (net.minecraft.server.v1_10_R1.WorldServer)13 Block (org.bukkit.block.Block)13 CraftWorld (org.bukkit.craftbukkit.v1_11_R1.CraftWorld)13 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)12 WorldServer (net.minecraft.server.v1_8_R3.WorldServer)12 LivingEntity (org.bukkit.entity.LivingEntity)12 CraftWorld (org.bukkit.craftbukkit.v1_10_R1.CraftWorld)11 WorldServer (net.minecraft.server.v1_13_R2.WorldServer)10