use of org.bukkit.craftbukkit.v1_13_R1.CraftWorld in project Magma-1.16.x by magmafoundation.
the class CraftLivingEntity method launchProjectile.
@Override
@SuppressWarnings("unchecked")
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
net.minecraft.world.World world = ((CraftWorld) getWorld()).getHandle();
net.minecraft.entity.Entity launch = null;
if (Snowball.class.isAssignableFrom(projectile)) {
launch = new SnowballEntity(world, getHandle());
// ItemSnowball
((ThrowableEntity) launch).shootFromRotation(getHandle(), getHandle().xRot, getHandle().yRot, 0.0F, 1.5F, 1.0F);
} else if (Egg.class.isAssignableFrom(projectile)) {
launch = new EggEntity(world, getHandle());
// ItemEgg
((ThrowableEntity) launch).shootFromRotation(getHandle(), getHandle().xRot, getHandle().yRot, 0.0F, 1.5F, 1.0F);
} else if (EnderPearl.class.isAssignableFrom(projectile)) {
launch = new EnderPearlEntity(world, getHandle());
// EnderPearlItem
((ThrowableEntity) launch).shootFromRotation(getHandle(), getHandle().xRot, getHandle().yRot, 0.0F, 1.5F, 1.0F);
} else if (AbstractArrow.class.isAssignableFrom(projectile)) {
if (TippedArrow.class.isAssignableFrom(projectile)) {
launch = new ArrowEntity(world, getHandle());
((ArrowEntity) launch).setType(CraftPotionUtil.fromBukkit(new PotionData(PotionType.WATER, false, false)));
} else if (SpectralArrow.class.isAssignableFrom(projectile)) {
launch = new SpectralArrowEntity(world, getHandle());
} else if (Trident.class.isAssignableFrom(projectile)) {
launch = new TridentEntity(world, getHandle(), new net.minecraft.item.ItemStack(net.minecraft.item.Items.TRIDENT));
} else {
launch = new ArrowEntity(world, getHandle());
}
// ItemBow
((AbstractArrowEntity) launch).shootFromRotation(getHandle(), getHandle().xRot, getHandle().yRot, 0.0F, 3.0F, 1.0F);
} else if (ThrownPotion.class.isAssignableFrom(projectile)) {
if (LingeringPotion.class.isAssignableFrom(projectile)) {
launch = new PotionEntity(world, getHandle());
((PotionEntity) launch).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.LINGERING_POTION, 1)));
} else {
launch = new PotionEntity(world, getHandle());
((PotionEntity) launch).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.SPLASH_POTION, 1)));
}
// SplashPotionItem
((ThrowableEntity) launch).shootFromRotation(getHandle(), getHandle().xRot, getHandle().yRot, -20.0F, 0.5F, 1.0F);
} else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
launch = new ExperienceBottleEntity(world, getHandle());
// ExperienceBottleItem
((ThrowableEntity) launch).shootFromRotation(getHandle(), getHandle().xRot, getHandle().yRot, -20.0F, 0.7F, 1.0F);
} else if (FishHook.class.isAssignableFrom(projectile) && getHandle() instanceof PlayerEntity) {
launch = new FishingBobberEntity((PlayerEntity) getHandle(), world, 0, 0);
} else if (Fireball.class.isAssignableFrom(projectile)) {
Location location = getEyeLocation();
Vector direction = location.getDirection().multiply(10);
if (SmallFireball.class.isAssignableFrom(projectile)) {
launch = new SmallFireballEntity(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
} else if (WitherSkull.class.isAssignableFrom(projectile)) {
launch = new WitherSkullEntity(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
} else if (DragonFireball.class.isAssignableFrom(projectile)) {
launch = new DragonFireballEntity(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
} else {
launch = new FireballEntity(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
}
((DamagingProjectileEntity) launch).projectileSource = this;
launch.moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
} else if (LlamaSpit.class.isAssignableFrom(projectile)) {
Location location = getEyeLocation();
Vector direction = location.getDirection();
launch = net.minecraft.entity.EntityType.LLAMA_SPIT.create(world);
((LlamaSpitEntity) launch).setOwner(getHandle());
// LlamaEntity
((LlamaSpitEntity) launch).shoot(direction.getX(), direction.getY(), direction.getZ(), 1.5F, 10.0F);
launch.moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
} else if (ShulkerBullet.class.isAssignableFrom(projectile)) {
Location location = getEyeLocation();
launch = new ShulkerBulletEntity(world, getHandle(), null, null);
launch.moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
} else if (Firework.class.isAssignableFrom(projectile)) {
Location location = getEyeLocation();
launch = new FireworkRocketEntity(world, net.minecraft.item.ItemStack.EMPTY, getHandle());
launch.moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
}
Validate.notNull(launch, "Projectile not supported");
if (velocity != null) {
((T) launch.getBukkitEntity()).setVelocity(velocity);
}
world.addFreshEntity(launch);
return (T) launch.getBukkitEntity();
}
use of org.bukkit.craftbukkit.v1_13_R1.CraftWorld in project Magma-1.16.x by magmafoundation.
the class CraftItemFrame method update.
private void update() {
ItemFrameEntity old = this.getHandle();
ServerWorld world = ((CraftWorld) getWorld()).getHandle();
BlockPos position = old.getPos();
Direction direction = old.getDirection();
ItemStack item = old.getItem() != null ? old.getItem().copy() : null;
old.remove();
ItemFrameEntity frame = new ItemFrameEntity(world, position, direction);
frame.setItem(item);
world.addEntity(frame);
this.entity = frame;
}
use of org.bukkit.craftbukkit.v1_13_R1.CraftWorld in project Magma-1.16.x by magmafoundation.
the class CraftPainting method update.
private void update() {
ServerWorld world = ((CraftWorld) getWorld()).getHandle();
PaintingEntity painting = net.minecraft.entity.EntityType.PAINTING.create(world);
painting.pos = getHandle().pos;
painting.motive = getHandle().motive;
painting.setDirection(getHandle().getDirection());
getHandle().remove();
// because this occurs when the painting is broken, so it might be important
getHandle().hurtMarked = true;
world.addEntity(painting);
this.entity = painting;
}
use of org.bukkit.craftbukkit.v1_13_R1.CraftWorld in project LoliServer by Loli-Server.
the class CraftEventFactory method callBlockMultiPlaceEvent.
/**
* Block place methods
*/
public static BlockMultiPlaceEvent callBlockMultiPlaceEvent(ServerWorld world, PlayerEntity who, Hand hand, List<BlockState> blockStates, int clickedX, int clickedY, int clickedZ) {
CraftWorld craftWorld = world.getWorld();
CraftServer craftServer = world.getCBServer();
Player player = (Player) who.getBukkitEntity();
Block blockClicked = craftWorld.getBlockAt(clickedX, clickedY, clickedZ);
boolean canBuild = true;
for (int i = 0; i < blockStates.size(); i++) {
if (!canBuild(world, player, blockStates.get(i).getX(), blockStates.get(i).getZ())) {
canBuild = false;
break;
}
}
org.bukkit.inventory.ItemStack item;
if (hand == Hand.MAIN_HAND) {
item = player.getInventory().getItemInMainHand();
} else {
item = player.getInventory().getItemInOffHand();
}
BlockMultiPlaceEvent event = new BlockMultiPlaceEvent(blockStates, blockClicked, item, player, canBuild);
craftServer.getPluginManager().callEvent(event);
return event;
}
use of org.bukkit.craftbukkit.v1_13_R1.CraftWorld in project LoliServer by Loli-Server.
the class CraftEventFactory method callEntityDeathEvent.
public static EntityDeathEvent callEntityDeathEvent(LivingEntity victim, List<org.bukkit.inventory.ItemStack> drops) {
CraftLivingEntity entity = (CraftLivingEntity) victim.getBukkitEntity();
EntityDeathEvent event = new EntityDeathEvent(entity, drops, victim.expToDrop);
CraftWorld world = (CraftWorld) entity.getWorld();
Bukkit.getServer().getPluginManager().callEvent(event);
victim.expToDrop = event.getDroppedExp();
for (org.bukkit.inventory.ItemStack stack : event.getDrops()) {
if (stack == null || stack.getType() == Material.AIR || stack.getAmount() == 0)
continue;
// Paper - note: dropItem already clones due to this being bukkit -> NMS
world.dropItem(entity.getLocation(), stack);
if (stack instanceof CraftItemStack)
// Paper - destroy this item - if this ever leaks due to game bugs, ensure it doesn't dupe, but don't nuke bukkit stacks of manually added items
stack.setAmount(0);
}
victim.dropExperience();
return event;
}
Aggregations