use of net.minecraft.server.v1_16_R2.EntityItem in project WildChests by BG-Software-LLC.
the class NMSAdapter_v1_16_R3 method getNearbyItems.
@Override
public Stream<Item> getNearbyItems(Location location, int range, boolean onlyChunk, KeySet blacklisted, KeySet whitelisted) {
World world = ((CraftWorld) location.getWorld()).getHandle();
List<Entity> entityList = new ArrayList<>();
if (onlyChunk) {
Chunk chunk = ((CraftChunk) location.getChunk()).getHandle();
for (int i = 0; i < chunk.entitySlices.length; i++) entityList.addAll(chunk.entitySlices[i]);
entityList = entityList.stream().filter(entity -> entity instanceof EntityItem).collect(Collectors.toList());
} else {
AxisAlignedBB boundingBox = new AxisAlignedBB(location.getX() + range, location.getY() + range, location.getZ() + range, location.getX() - range, location.getY() - range, location.getZ() - range);
entityList = world.getEntities(null, boundingBox, entity -> entity instanceof EntityItem);
}
return entityList.stream().map(entity -> (Item) entity.getBukkitEntity()).filter(item -> !blacklisted.contains(item.getItemStack()) && (whitelisted.isEmpty() || whitelisted.contains(item.getItemStack())));
}
use of net.minecraft.server.v1_16_R2.EntityItem in project UltraCosmetics by iSach.
the class EntityUtil method spawnItem.
@Override
public Entity spawnItem(ItemStack itemStack, Location blockLocation) {
EntityItem ei = new EntityItem(((CraftWorld) blockLocation.clone().add(0.5D, 1.2D, 0.5D).getWorld()).getHandle(), blockLocation.clone().add(0.5D, 1.2D, 0.5D).getX(), blockLocation.clone().add(0.5D, 1.2D, 0.5D).getY(), blockLocation.clone().add(0.5D, 1.2D, 0.5D).getZ(), CraftItemStack.asNMSCopy(itemStack)) {
public boolean a(EntityItem entityitem) {
return false;
}
};
ei.getBukkitEntity().setVelocity(new Vector(0.0D, 0.25D, 0.0D));
ei.pickupDelay = 2147483647;
ei.getBukkitEntity().setCustomName(UltraCosmeticsData.get().getItemNoPickupString());
ei.pickupDelay = 20;
((CraftWorld) blockLocation.clone().add(0.5D, 1.2D, 0.5D).getWorld()).getHandle().addEntity(ei);
return ei.getBukkitEntity();
}
use of net.minecraft.server.v1_16_R2.EntityItem 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;
}
}
use of net.minecraft.server.v1_16_R2.EntityItem in project MyPet by xXKeyleXx.
the class EntityMyPig method handlePlayerInteraction.
public boolean handlePlayerInteraction(final EntityHuman entityhuman, EnumHand enumhand, final ItemStack itemStack) {
if (enumhand == EnumHand.OFF_HAND) {
if (itemStack != null) {
if (itemStack.getItem() == Items.LEAD) {
((WorldServer) this.world).getTracker().a(this, new PacketPlayOutAttachEntity(this, null));
entityhuman.a(EnumHand.OFF_HAND, null);
new BukkitRunnable() {
public void run() {
if (entityhuman instanceof EntityPlayer) {
entityhuman.a(EnumHand.OFF_HAND, itemStack);
Player p = (Player) entityhuman.getBukkitEntity();
if (!p.isOnline()) {
p.saveData();
}
}
}
}.runTaskLater(MyPetApi.getPlugin(), 5);
}
}
return true;
}
if (isMyPet() && myPet.getOwner().equals(entityhuman)) {
if (Configuration.Skilltree.Skill.Ride.RIDE_ITEM == null || Configuration.Skilltree.Skill.Ride.RIDE_ITEM.compare(itemStack)) {
if (myPet.getSkills().isActive(RideImpl.class) && canMove()) {
if (itemStack != null && itemStack.getItem() == Items.LEAD) {
((WorldServer) this.world).getTracker().a(this, new PacketPlayOutAttachEntity(this, null));
entityhuman.a(EnumHand.MAIN_HAND, null);
new BukkitRunnable() {
public void run() {
if (entityhuman instanceof EntityPlayer) {
entityhuman.a(EnumHand.MAIN_HAND, itemStack);
Player p = (Player) entityhuman.getBukkitEntity();
if (!p.isOnline()) {
p.saveData();
}
}
}
}.runTaskLater(MyPetApi.getPlugin(), 5);
}
getOwner().sendMessage("Unfortunately, pigs can not be ridden (Minecraft limitation)", 5000);
return true;
}
}
}
if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack)) {
return true;
}
if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) {
if (itemStack.getItem() == Items.SADDLE && !getMyPet().hasSaddle() && getOwner().getPlayer().isSneaking()) {
getMyPet().setSaddle(CraftItemStack.asBukkitCopy(itemStack));
if (!entityhuman.abilities.canInstantlyBuild) {
if (--itemStack.count <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null);
}
}
return true;
} else if (itemStack.getItem() == Items.SHEARS && getMyPet().hasSaddle() && getOwner().getPlayer().isSneaking()) {
EntityItem entityitem = new EntityItem(this.world, this.locX, this.locY + 1, this.locZ, CraftItemStack.asNMSCopy(getMyPet().getSaddle()));
entityitem.pickupDelay = 10;
entityitem.motY += (double) (this.random.nextFloat() * 0.05F);
this.world.addEntity(entityitem);
makeSound("entity.sheep.shear", 1.0F, 1.0F);
getMyPet().setSaddle(null);
if (!entityhuman.abilities.canInstantlyBuild) {
itemStack.damage(1, entityhuman);
}
return true;
} else if (Configuration.MyPet.Pig.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) {
if (!entityhuman.abilities.canInstantlyBuild) {
if (--itemStack.count <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null);
}
}
getMyPet().setBaby(false);
return true;
}
}
return false;
}
use of net.minecraft.server.v1_16_R2.EntityItem in project WildChests by BG-Software-LLC.
the class NMSAdapter_v1_12_R1 method getNearbyItems.
@Override
public Stream<Item> getNearbyItems(Location location, int range, boolean onlyChunk, KeySet blacklisted, KeySet whitelisted) {
World world = ((CraftWorld) location.getWorld()).getHandle();
List<Entity> entityList = new ArrayList<>();
if (onlyChunk) {
Chunk chunk = ((CraftChunk) location.getChunk()).getHandle();
for (int i = 0; i < chunk.entitySlices.length; i++) entityList.addAll(chunk.entitySlices[i]);
entityList = entityList.stream().filter(entity -> entity instanceof EntityItem).collect(Collectors.toList());
} else {
AxisAlignedBB boundingBox = new AxisAlignedBB(location.getX() + range, location.getY() + range, location.getZ() + range, location.getX() - range, location.getY() - range, location.getZ() - range);
entityList = world.getEntities(null, boundingBox, entity -> entity instanceof EntityItem);
}
return entityList.stream().map(entity -> (Item) entity.getBukkitEntity()).filter(item -> !blacklisted.contains(item.getItemStack()) && (whitelisted.isEmpty() || whitelisted.contains(item.getItemStack())));
}
Aggregations