use of net.minecraft.server.v1_16_R1.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_R1.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_R1.EntityItem in project MyPet by xXKeyleXx.
the class EntityMyZombifiedPiglin method handlePlayerInteraction.
public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) {
if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack) == EnumInteractionResult.CONSUME) {
return EnumInteractionResult.CONSUME;
}
if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) {
if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) {
boolean hadEquipment = false;
for (EquipmentSlot slot : EquipmentSlot.values()) {
ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot));
if (itemInSlot != null && itemInSlot.getItem() != Items.AIR) {
EntityItem entityitem = new EntityItem(this.world, this.locX(), this.locY() + 1, this.locZ(), itemInSlot);
entityitem.pickupDelay = 10;
entityitem.setMot(entityitem.getMot().add(0, this.random.nextFloat() * 0.05F, 0));
this.world.addEntity(entityitem);
getMyPet().setEquipment(slot, null);
hadEquipment = true;
}
}
if (hadEquipment) {
if (itemStack != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
try {
itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand));
} catch (Error e) {
// TODO REMOVE
itemStack.damage(1, entityhuman, (entityhuman1) -> {
try {
ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand);
} catch (IllegalAccessException | InvocationTargetException ex) {
ex.printStackTrace();
}
});
}
}
}
return EnumInteractionResult.CONSUME;
} else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) {
EquipmentSlot slot = EquipmentSlot.getSlotById(EntityInsentient.j(itemStack).c());
ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot));
if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
EntityItem entityitem = new EntityItem(this.world, this.locX(), this.locY() + 1, this.locZ(), itemInSlot);
entityitem.pickupDelay = 10;
entityitem.setMot(entityitem.getMot().add(0, this.random.nextFloat() * 0.05F, 0));
this.world.addEntity(entityitem);
}
getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack));
if (itemStack != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
itemStack.subtract(1);
if (itemStack.getCount() <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, ItemStack.b);
}
}
return EnumInteractionResult.CONSUME;
} else if (Configuration.MyPet.ZombifiedPiglin.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) {
if (itemStack != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
itemStack.subtract(1);
if (itemStack.getCount() <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, ItemStack.b);
}
}
getMyPet().setBaby(false);
return EnumInteractionResult.CONSUME;
}
}
return EnumInteractionResult.PASS;
}
use of net.minecraft.server.v1_16_R1.EntityItem in project MyPet by xXKeyleXx.
the class EntityMyVex method handlePlayerInteraction.
/**
* Is called when player rightclicks this MyPet
* return:
* true: there was a reaction on rightclick
* false: no reaction on rightclick
*/
@Override
public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) {
if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) {
return EnumInteractionResult.CONSUME;
}
if (getOwner().equals(entityhuman) && itemStack != null) {
if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) {
boolean hadEquipment = false;
for (EquipmentSlot slot : EquipmentSlot.values()) {
ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot));
if (itemInSlot != null && itemInSlot.getItem() != Items.AIR) {
EntityItem entityitem = new EntityItem(this.world, this.locX(), this.locY() + 1, this.locZ(), itemInSlot);
entityitem.pickupDelay = 10;
entityitem.setMot(entityitem.getMot().add(0, this.random.nextFloat() * 0.05F, 0));
this.world.addEntity(entityitem);
getMyPet().setEquipment(slot, null);
hadEquipment = true;
}
}
if (hadEquipment) {
if (itemStack != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
try {
itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand));
} catch (Error e) {
// TODO REMOVE
itemStack.damage(1, entityhuman, (entityhuman1) -> {
try {
ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand);
} catch (IllegalAccessException | InvocationTargetException ex) {
ex.printStackTrace();
}
});
}
}
}
return EnumInteractionResult.CONSUME;
} else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) {
EquipmentSlot slot = EquipmentSlot.getSlotById(j(itemStack).c());
if (slot == EquipmentSlot.MainHand) {
ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot));
if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
EntityItem entityitem = new EntityItem(this.world, this.locX(), this.locY() + 1, this.locZ(), itemInSlot);
entityitem.pickupDelay = 10;
entityitem.setMot(entityitem.getMot().add(0, this.random.nextFloat() * 0.05F, 0));
this.world.addEntity(entityitem);
}
getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack));
if (itemStack != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
itemStack.subtract(1);
if (itemStack.getCount() <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, ItemStack.b);
}
}
return EnumInteractionResult.CONSUME;
}
}
}
return EnumInteractionResult.PASS;
}
use of net.minecraft.server.v1_16_R1.EntityItem in project MyPet by xXKeyleXx.
the class EntityMyVindicator method handlePlayerInteraction.
/**
* Is called when player rightclicks this MyPet
* return:
* true: there was a reaction on rightclick
* false: no reaction on rightclick
*/
@Override
public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) {
if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) {
return EnumInteractionResult.CONSUME;
}
if (getOwner().equals(entityhuman) && itemStack != null) {
if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) {
boolean hadEquipment = false;
for (EquipmentSlot slot : EquipmentSlot.values()) {
ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot));
if (itemInSlot != null && itemInSlot.getItem() != Items.AIR) {
EntityItem entityitem = new EntityItem(this.world, this.locX(), this.locY() + 1, this.locZ(), itemInSlot);
entityitem.pickupDelay = 10;
entityitem.setMot(entityitem.getMot().add(0, this.random.nextFloat() * 0.05F, 0));
this.world.addEntity(entityitem);
getMyPet().setEquipment(slot, null);
hadEquipment = true;
}
}
if (hadEquipment) {
if (itemStack != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
try {
itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand));
} catch (Error e) {
// TODO REMOVE
itemStack.damage(1, entityhuman, (entityhuman1) -> {
try {
CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand);
} catch (IllegalAccessException | InvocationTargetException ex) {
ex.printStackTrace();
}
});
}
}
}
return EnumInteractionResult.CONSUME;
} else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) {
EquipmentSlot slot = EquipmentSlot.getSlotById(j(itemStack).c());
if (slot == EquipmentSlot.MainHand) {
ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot));
if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
EntityItem entityitem = new EntityItem(this.world, this.locX(), this.locY() + 1, this.locZ(), itemInSlot);
entityitem.pickupDelay = 10;
entityitem.setMot(entityitem.getMot().add(0, this.random.nextFloat() * 0.05F, 0));
this.world.addEntity(entityitem);
}
getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack));
if (itemStack != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
itemStack.subtract(1);
if (itemStack.getCount() <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, ItemStack.b);
}
}
return EnumInteractionResult.CONSUME;
}
} else if (itemStack.getItem() instanceof ItemBanner && getOwner().getPlayer().isSneaking() && canEquip()) {
ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(EquipmentSlot.Helmet));
if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
EntityItem entityitem = new EntityItem(this.world, this.locX(), this.locY() + 1, this.locZ(), itemInSlot);
entityitem.pickupDelay = 10;
entityitem.setMot(entityitem.getMot().add(0, this.random.nextFloat() * 0.05F, 0));
this.world.addEntity(entityitem);
}
getMyPet().setEquipment(EquipmentSlot.Helmet, CraftItemStack.asBukkitCopy(itemStack));
if (itemStack != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
itemStack.subtract(1);
if (itemStack.getCount() <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, ItemStack.b);
}
}
return EnumInteractionResult.CONSUME;
}
}
return EnumInteractionResult.PASS;
}
Aggregations