Search in sources :

Example 96 with CraftWorld

use of org.bukkit.craftbukkit.v1_13_R2.CraftWorld in project Village_Defense by Plajer.

the class ArenaInitializer1_11_R1 method spawnWolf.

public void spawnWolf(Location location, Player player) {
    net.minecraft.server.v1_11_R1.World McWorld = ((CraftWorld) location.getWorld()).getHandle();
    WorkingWolf wolf = new WorkingWolf(location.getWorld());
    wolf.setPosition(location.getX(), location.getY(), location.getZ());
    McWorld.addEntity(wolf, CreatureSpawnEvent.SpawnReason.CUSTOM);
    wolf.setCustomName(ChatManager.colorMessage("In-Game.Spawned-Wolf-Name").replaceAll("%player%", player.getName()));
    wolf.setCustomNameVisible(true);
    wolf.setInvisible(false);
    ((Wolf) wolf.getBukkitEntity()).setOwner(player);
    CreatureUtils.applyMetadata(wolf.getBukkitEntity(), this);
    this.addWolf((Wolf) wolf.getBukkitEntity());
}
Also used : WorkingWolf(pl.plajer.villagedefense3.creatures.v1_11_R1.WorkingWolf) WorkingWolf(pl.plajer.villagedefense3.creatures.v1_11_R1.WorkingWolf) Wolf(org.bukkit.entity.Wolf) CraftWorld(org.bukkit.craftbukkit.v1_11_R1.CraftWorld)

Example 97 with CraftWorld

use of org.bukkit.craftbukkit.v1_13_R2.CraftWorld in project MagicPlugin by elBukkit.

the class CompatibilityUtils method spawnProjectile.

@Override
public Projectile spawnProjectile(Class<?> projectileType, Location location, Vector direction, ProjectileSource source, float speed, float spread, float spreadLocations, Random random) {
    Constructor<? extends Object> constructor = null;
    ServerLevel nmsWorld = ((CraftWorld) location.getWorld()).getHandle();
    Projectile projectile = null;
    try {
        Object entityType = null;
        constructor = projectileType.getConstructor(net.minecraft.world.entity.EntityType.class, net.minecraft.world.level.Level.class);
        entityType = projectileEntityTypes.get(projectileType.getSimpleName());
        if (entityType == null) {
            throw new Exception("Failed to find entity type for projectile class " + projectileType.getName());
        }
        Object nmsProjectile = null;
        try {
            nmsProjectile = constructor.newInstance(entityType, nmsWorld);
        } catch (Exception ex) {
            nmsProjectile = null;
            platform.getLogger().log(Level.WARNING, "Error spawning projectile of class " + projectileType.getName(), ex);
        }
        if (nmsProjectile == null || !(nmsProjectile instanceof net.minecraft.world.entity.Entity)) {
            throw new Exception("Failed to spawn projectile of class " + projectileType.getName());
        }
        // Velocity must be set manually- EntityFireball.setDirection applies a crazy-wide gaussian distribution!
        if (nmsProjectile instanceof AbstractHurtingProjectile) {
            AbstractHurtingProjectile fireballIsh = (AbstractHurtingProjectile) nmsProjectile;
            // Taken from EntityArrow
            double spreadWeight = Math.min(0.4f, spread * 0.007499999832361937D);
            double dx = speed * (direction.getX() + (random.nextGaussian() * spreadWeight));
            double dy = speed * (direction.getY() + (random.nextGaussian() * spreadWeight));
            double dz = speed * (direction.getZ() + (random.nextGaussian() * spreadWeight));
            fireballIsh.xPower = dx * 0.1D;
            fireballIsh.yPower = dy * 0.1D;
            fireballIsh.zPower = dz * 0.1D;
        }
        net.minecraft.world.entity.Entity nmsEntity = ((net.minecraft.world.entity.Entity) nmsProjectile);
        Vector modifiedLocation = location.toVector().clone();
        if (Fireball.class.isAssignableFrom(projectileType) && spreadLocations > 0) {
            modifiedLocation.setX(modifiedLocation.getX() + direction.getX() + (random.nextGaussian() * spread / 5));
            modifiedLocation.setY(modifiedLocation.getY() + direction.getY() + (random.nextGaussian() * spread / 5));
            modifiedLocation.setZ(modifiedLocation.getZ() + direction.getZ() + (random.nextGaussian() * spread / 5));
        }
        nmsEntity.moveTo(modifiedLocation.getX(), modifiedLocation.getY(), modifiedLocation.getZ(), location.getYaw(), location.getPitch());
        if (nmsEntity instanceof net.minecraft.world.entity.projectile.Projectile) {
            net.minecraft.world.entity.projectile.Projectile nms = (net.minecraft.world.entity.projectile.Projectile) nmsEntity;
            nms.shoot(direction.getX(), direction.getY(), direction.getZ(), speed, spread);
        }
        Entity entity = nmsEntity.getBukkitEntity();
        if (entity == null || !(entity instanceof Projectile)) {
            throw new Exception("Got invalid bukkit entity from projectile of class " + projectileType.getName());
        }
        projectile = (Projectile) entity;
        if (source != null) {
            projectile.setShooter(source);
            nmsEntity.projectileSource = source;
        }
        nmsWorld.addEntity(nmsEntity, CreatureSpawnEvent.SpawnReason.DEFAULT);
    } catch (Throwable ex) {
        ex.printStackTrace();
        return null;
    }
    return projectile;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) FireworkRocketEntity(net.minecraft.world.entity.projectile.FireworkRocketEntity) Entity(org.bukkit.entity.Entity) HangingEntity(net.minecraft.world.entity.decoration.HangingEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) CraftEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity) FallingBlockEntity(net.minecraft.world.entity.item.FallingBlockEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) ItemEntity(net.minecraft.world.entity.item.ItemEntity) SignBlockEntity(net.minecraft.world.level.block.entity.SignBlockEntity) HumanEntity(org.bukkit.entity.HumanEntity) Projectile(org.bukkit.entity.Projectile) AbstractHurtingProjectile(net.minecraft.world.entity.projectile.AbstractHurtingProjectile) EntityType(org.bukkit.entity.EntityType) Fireball(net.minecraft.world.entity.projectile.Fireball) AbstractHurtingProjectile(net.minecraft.world.entity.projectile.AbstractHurtingProjectile) ServerLevel(net.minecraft.server.level.ServerLevel) Level(java.util.logging.Level) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld) BlockVector(org.bukkit.util.BlockVector) Vector(org.bukkit.util.Vector)

Example 98 with CraftWorld

use of org.bukkit.craftbukkit.v1_13_R2.CraftWorld in project MagicPlugin by elBukkit.

the class CompatibilityUtils method spawnFireworkEffect.

@Override
public Entity spawnFireworkEffect(Material fireworkMaterial, Server server, Location location, FireworkEffect effect, int power, Vector direction, Integer expectedLifespan, Integer ticksFlown, boolean silent) {
    Entity entity = null;
    try {
        if (fireworkMaterial == null) {
            return null;
        }
        ServerLevel level = ((CraftWorld) location.getWorld()).getHandle();
        ItemStack itemStack = new ItemStack(fireworkMaterial);
        FireworkMeta meta = (FireworkMeta) itemStack.getItemMeta();
        meta.addEffect(effect);
        meta.setPower(power);
        itemStack.setItemMeta(meta);
        Object item = platform.getItemUtils().getHandle(platform.getItemUtils().makeReal(itemStack));
        final FireworkRocketEntity fireworkHandle = new FireworkRocketEntity(level, location.getX(), location.getY(), location.getZ(), (net.minecraft.world.item.ItemStack) item);
        fireworkHandle.setSilent(silent);
        if (direction != null) {
            fireworkHandle.setDeltaMovement(new Vec3(direction.getX(), direction.getY(), direction.getZ()));
        }
        if (ticksFlown != null) {
            ReflectionUtils.setPrivateNeedsFixing(platform.getLogger(), fireworkHandle, FireworkRocketEntity.class, "life", "e", ticksFlown);
        }
        if (expectedLifespan != null) {
            fireworkHandle.lifetime = expectedLifespan;
        }
        if (direction == null) {
            ClientboundAddEntityPacket fireworkPacket = new ClientboundAddEntityPacket(fireworkHandle, CompatibilityConstants.FIREWORK_TYPE);
            int fireworkId = fireworkHandle.getId();
            SynchedEntityData watcher = fireworkHandle.getEntityData();
            ClientboundSetEntityDataPacket metadataPacket = new ClientboundSetEntityDataPacket(fireworkId, watcher, true);
            ClientboundEntityEventPacket statusPacket = new ClientboundEntityEventPacket(fireworkHandle, (byte) 17);
            ClientboundRemoveEntityPacket destroyPacket = new ClientboundRemoveEntityPacket(fireworkId);
            Collection<? extends Player> players = server.getOnlinePlayers();
            sendPacket(server, location, players, fireworkPacket);
            sendPacket(server, location, players, metadataPacket);
            sendPacket(server, location, players, statusPacket);
            sendPacket(server, location, players, destroyPacket);
            return null;
        }
        level.addEntity(fireworkHandle, CreatureSpawnEvent.SpawnReason.CUSTOM);
        entity = fireworkHandle.getBukkitEntity();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return entity;
}
Also used : FireworkRocketEntity(net.minecraft.world.entity.projectile.FireworkRocketEntity) Entity(org.bukkit.entity.Entity) HangingEntity(net.minecraft.world.entity.decoration.HangingEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) CraftEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity) FallingBlockEntity(net.minecraft.world.entity.item.FallingBlockEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) ItemEntity(net.minecraft.world.entity.item.ItemEntity) SignBlockEntity(net.minecraft.world.level.block.entity.SignBlockEntity) HumanEntity(org.bukkit.entity.HumanEntity) ServerLevel(net.minecraft.server.level.ServerLevel) SynchedEntityData(net.minecraft.network.syncher.SynchedEntityData) ClientboundAddEntityPacket(net.minecraft.network.protocol.game.ClientboundAddEntityPacket) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) FireworkRocketEntity(net.minecraft.world.entity.projectile.FireworkRocketEntity) ClientboundRemoveEntityPacket(net.minecraft.network.protocol.game.ClientboundRemoveEntityPacket) Vec3(net.minecraft.world.phys.Vec3) ClientboundEntityEventPacket(net.minecraft.network.protocol.game.ClientboundEntityEventPacket) ItemStack(org.bukkit.inventory.ItemStack) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld) ClientboundSetEntityDataPacket(net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket)

Example 99 with CraftWorld

use of org.bukkit.craftbukkit.v1_13_R2.CraftWorld in project MagicPlugin by elBukkit.

the class CompatibilityUtils method applyPhysics.

@Override
public boolean applyPhysics(Block block) {
    ServerLevel nmsWorld = ((CraftWorld) block.getWorld()).getHandle();
    BlockPos blockLocation = new BlockPos(block.getX(), block.getY(), block.getZ());
    net.minecraft.world.level.block.state.BlockState blockState = nmsWorld.getBlockState(blockLocation);
    clearItems(block.getLocation());
    platform.getDeprecatedUtils().setTypeAndData(block, Material.AIR, (byte) 0, false);
    return nmsWorld.setBlock(blockLocation, blockState, 3);
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) BlockPos(net.minecraft.core.BlockPos) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld)

Example 100 with CraftWorld

use of org.bukkit.craftbukkit.v1_13_R2.CraftWorld in project MagicPlugin by elBukkit.

the class CompatibilityUtils method createItemFrame.

@Override
public ItemFrame createItemFrame(Location location, BlockFace facing, Rotation rotation, ItemStack item) {
    ItemFrame newItemFrame = null;
    ServerLevel level = ((CraftWorld) location.getWorld()).getHandle();
    Direction directionEnum = null;
    try {
        directionEnum = Direction.valueOf(facing.name());
    } catch (Exception ex) {
        ex.printStackTrace();
        return null;
    }
    BlockPos blockLocation = new BlockPos(location.getX(), location.getY(), location.getZ());
    net.minecraft.world.entity.decoration.ItemFrame newEntity = new net.minecraft.world.entity.decoration.ItemFrame(level, blockLocation, directionEnum);
    Entity bukkitEntity = newEntity.getBukkitEntity();
    if (bukkitEntity != null && bukkitEntity instanceof ItemFrame) {
        newItemFrame = (ItemFrame) bukkitEntity;
        newItemFrame.setItem(platform.getItemUtils().getCopy(item));
        newItemFrame.setRotation(rotation);
    }
    return newItemFrame;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) FireworkRocketEntity(net.minecraft.world.entity.projectile.FireworkRocketEntity) Entity(org.bukkit.entity.Entity) HangingEntity(net.minecraft.world.entity.decoration.HangingEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) CraftEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity) FallingBlockEntity(net.minecraft.world.entity.item.FallingBlockEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) ItemEntity(net.minecraft.world.entity.item.ItemEntity) SignBlockEntity(net.minecraft.world.level.block.entity.SignBlockEntity) HumanEntity(org.bukkit.entity.HumanEntity) ItemFrame(org.bukkit.entity.ItemFrame) Direction(net.minecraft.core.Direction) BlockPos(net.minecraft.core.BlockPos) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld)

Aggregations

ServerLevel (net.minecraft.server.level.ServerLevel)133 Location (org.bukkit.Location)119 CraftWorld (org.bukkit.craftbukkit.v1_17_R1.CraftWorld)100 CraftWorld (org.bukkit.craftbukkit.v1_18_R1.CraftWorld)77 BlockPos (net.minecraft.core.BlockPos)69 CraftWorld (org.bukkit.craftbukkit.v1_18_R2.CraftWorld)69 CraftWorld (org.bukkit.craftbukkit.v1_16_R3.CraftWorld)57 ItemStack (org.bukkit.inventory.ItemStack)56 LivingEntity (org.bukkit.entity.LivingEntity)51 CraftWorld (org.bukkit.craftbukkit.v1_12_R1.CraftWorld)50 CraftWorld (org.bukkit.craftbukkit.v1_8_R3.CraftWorld)48 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)43 Entity (org.bukkit.entity.Entity)39 ArrayList (java.util.ArrayList)38 CraftWorld (org.bukkit.craftbukkit.v1_11_R1.CraftWorld)38 World (org.bukkit.World)32 Zombie (org.bukkit.entity.Zombie)32 ItemEntity (net.minecraft.world.entity.item.ItemEntity)29 List (java.util.List)28 UUID (java.util.UUID)28