Java Code Examples for net.minecraft.entity.Entity#getDistanceSqToEntity()
The following examples show how to use
net.minecraft.entity.Entity#getDistanceSqToEntity() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TeleportHit.java From LiquidBounce with GNU General Public License v3.0 | 5 votes |
@EventTarget public void onMotion(MotionEvent event) { if(event.getEventState() != EventState.PRE) return; final Entity facedEntity = RaycastUtils.raycastEntity(100D, raycastedEntity -> raycastedEntity instanceof EntityLivingBase); if(mc.gameSettings.keyBindAttack.isKeyDown() && EntityUtils.isSelected(facedEntity, true) && facedEntity.getDistanceSqToEntity(mc.thePlayer) >= 1D) targetEntity = (EntityLivingBase) facedEntity; if(targetEntity != null) { if(!shouldHit) { shouldHit = true; return; } if(mc.thePlayer.fallDistance > 0F) { final Vec3 rotationVector = RotationUtils.getVectorForRotation(new Rotation(mc.thePlayer.rotationYaw, 0F)); final double x = mc.thePlayer.posX + rotationVector.xCoord * (mc.thePlayer.getDistanceToEntity(targetEntity) - 1.0F); final double z = mc.thePlayer.posZ + rotationVector.zCoord * (mc.thePlayer.getDistanceToEntity(targetEntity) - 1.0F); final double y = targetEntity.getPosition().getY() + 0.25D; PathUtils.findPath(x, y + 1.0D, z, 4D).forEach(pos -> mc.getNetHandler().addToSendQueue(new C03PacketPlayer.C04PacketPlayerPosition(pos.getX(), pos.getY(), pos.getZ(), false))); mc.thePlayer.swingItem(); mc.thePlayer.sendQueue.addToSendQueue(new C02PacketUseEntity(targetEntity, C02PacketUseEntity.Action.ATTACK)); mc.thePlayer.onCriticalHit(targetEntity); shouldHit = false; targetEntity = null; }else if(mc.thePlayer.onGround) mc.thePlayer.jump(); }else shouldHit = false; }
Example 2
Source File: WEntity.java From ForgeWurst with GNU General Public License v3.0 | 4 votes |
public static double getDistanceSq(Entity e1, Entity e2) { return e1.getDistanceSqToEntity(e2); }
Example 3
Source File: TileKnowledgeBook.java From Gadomancy with GNU Lesser General Public License v3.0 | 4 votes |
private void tryVortexUnfinishedResearchNotes() { float centerY = yCoord + 0.4F; List entityItems = worldObj.selectEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(xCoord - 0.5, centerY - 0.5, zCoord - 0.5, xCoord + 0.5, centerY + 0.5, zCoord + 0.5).expand(8, 8, 8), new IEntitySelector() { @Override public boolean isEntityApplicable(Entity e) { return !(e instanceof EntityPermanentItem) && !(e instanceof EntitySpecialItem) && e instanceof EntityItem && ((EntityItem) e).getEntityItem() != null && ((EntityItem) e).getEntityItem().getItem() instanceof ItemResearchNotes && shouldVortexResearchNote(((EntityItem) e).getEntityItem()); } }); Entity dummy = new EntityItem(worldObj); dummy.posX = xCoord + 0.5; dummy.posY = centerY + 0.5; dummy.posZ = zCoord + 0.5; //MC code. EntityItem entity = null; double d0 = Double.MAX_VALUE; for (Object entityItem : entityItems) { EntityItem entityIt = (EntityItem) entityItem; if (entityIt != dummy) { double d1 = dummy.getDistanceSqToEntity(entityIt); if (d1 <= d0) { entity = entityIt; d0 = d1; } } } if(entity == null) return; if(dummy.getDistanceToEntity(entity) < 1 && !worldObj.isRemote) { ItemStack inter = entity.getEntityItem(); inter.stackSize--; this.storedResearchNote = inter.copy(); this.storedResearchNote.stackSize = 1; EntityPermNoClipItem item = new EntityPermNoClipItem(entity.worldObj, xCoord + 0.5F, centerY + 0.3F, zCoord + 0.5F, storedResearchNote, xCoord, yCoord, zCoord); entity.worldObj.spawnEntityInWorld(item); item.motionX = 0; item.motionY = 0; item.motionZ = 0; item.hoverStart = entity.hoverStart; item.age = entity.age; item.noClip = true; timeSinceLastItemInfo = 0; if(inter.stackSize <= 0) entity.setDead(); entity.noClip = false; item.delayBeforeCanPickup = 60; worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); markDirty(); } else { entity.noClip = true; applyMovementVectors(entity); } }
Example 4
Source File: TileAuraPylon.java From Gadomancy with GNU Lesser General Public License v3.0 | 4 votes |
private void tryVortexPossibleItems() { TileAuraPylon io = getInputTile(); if (io == null) return; int masterY = yCoord + 1; float dst = ((float) (masterY - io.yCoord)) / 2F; float yC = masterY - dst; List entityItems = worldObj.selectEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(xCoord - 0.5, yC - 0.5, zCoord - 0.5, xCoord + 0.5, yC + 0.5, zCoord + 0.5).expand(8, 8, 8), new IEntitySelector() { @Override public boolean isEntityApplicable(Entity e) { return !(e instanceof EntityPermanentItem) && !(e instanceof EntitySpecialItem) && e instanceof EntityItem && ((EntityItem) e).getEntityItem() != null && ((EntityItem) e).getEntityItem().getItem() instanceof ItemCrystalEssence && ((ItemCrystalEssence) ((EntityItem) e).getEntityItem().getItem()).getAspects(((EntityItem) e).getEntityItem()) != null; } }); Entity dummy = new EntityItem(worldObj); dummy.posX = xCoord + 0.5; dummy.posY = yC + 0.5; dummy.posZ = zCoord + 0.5; //MC code. EntityItem entity = null; double d0 = Double.MAX_VALUE; for (Object entityItem : entityItems) { EntityItem entityIt = (EntityItem) entityItem; if (entityIt != dummy) { double d1 = dummy.getDistanceSqToEntity(entityIt); if (d1 <= d0) { entity = entityIt; d0 = d1; } } } if(entity == null) return; if(dummy.getDistanceToEntity(entity) < 1 && !worldObj.isRemote) { ItemStack inter = entity.getEntityItem(); inter.stackSize--; this.crystalEssentiaStack = inter.copy(); this.crystalEssentiaStack.stackSize = 1; EntityPermNoClipItem item = new EntityPermNoClipItem(entity.worldObj, xCoord + 0.5F, yC + 0.3F, zCoord + 0.5F, crystalEssentiaStack, xCoord, yCoord, zCoord); entity.worldObj.spawnEntityInWorld(item); item.motionX = 0; item.motionY = 0; item.motionZ = 0; item.hoverStart = entity.hoverStart; item.age = entity.age; item.noClip = true; timeSinceLastItemInfo = 0; holdingAspect = ((ItemCrystalEssence) crystalEssentiaStack.getItem()).getAspects(crystalEssentiaStack).getAspects()[0]; distributeAspectInformation(); if(inter.stackSize <= 0) entity.setDead(); entity.noClip = false; item.delayBeforeCanPickup = 60; worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); markDirty(); } else { entity.noClip = true; applyMovementVectors(entity); } }
Example 5
Source File: CommandDisassembleNear.java From archimedes-ships with MIT License | 4 votes |
@SuppressWarnings("unchecked") @Override public void processCommand(ICommandSender icommandsender, String[] astring) { if (icommandsender instanceof Entity) { double range = 16D; if (astring != null && astring.length > 0) { try { range = Integer.parseInt(astring[0]); } catch (NumberFormatException e) { throw new NumberInvalidException(); } } double rangesqrd = range * range; Entity player = (Entity) icommandsender; EntityShip ne = null; if (player.ridingEntity instanceof EntityShip) { ne = (EntityShip) player.ridingEntity; } else { double nd = 0D; double d; for (Entity entity : (List<Entity>) player.worldObj.getLoadedEntityList()) { if (entity instanceof EntityShip) { d = player.getDistanceSqToEntity(entity); if (d < rangesqrd && (ne == null || d < nd)) { ne = (EntityShip) entity; nd = d; } } } } if (ne == null) { icommandsender.addChatMessage(new ChatComponentText("No ship in a " + ((int) range) + " blocks' range")); return; } if (!ne.disassemble(false)) { icommandsender.addChatMessage(new ChatComponentText("Failed to disassemble ship; dropping to items")); ne.dropAsItems(); } ne.setDead(); } }