Java Code Examples for net.minecraft.world.World#getEntities()
The following examples show how to use
net.minecraft.world.World#getEntities() .
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: DefaultMiscCapability.java From Wizardry with GNU Lesser General Public License v3.0 | 6 votes |
@Override @Nullable public EntityFairy getSelectedFairyEntity(World world) { if (selectedFairy == null) return null; for (EntityFairy entityFairy : world.getEntities(EntityFairy.class, input -> { if (input != null) { return input.getUniqueID().equals(selectedFairy); } return false; })) { if (entityFairy.getUniqueID().equals(selectedFairy)) return entityFairy; } return null; }
Example 2
Source File: RenderEventHandler.java From enderutilities with GNU Lesser General Public License v3.0 | 6 votes |
private void renderItemExtras(World world, EntityPlayer usingPlayer, EntityPlayer clientPlayer, float partialTicks) { ItemStack stack = EntityUtils.getHeldItemOfType(usingPlayer, EnderUtilitiesItems.BUILDERS_WAND); if (stack.isEmpty() == false && stack.getItem() == EnderUtilitiesItems.BUILDERS_WAND) { this.buildersWandRenderer.renderSelectedArea(world, usingPlayer, stack, clientPlayer, partialTicks); } stack = EntityUtils.getHeldItemOfType(usingPlayer, EnderUtilitiesItems.CHAIR_WAND); if (stack.isEmpty() == false) { List<EntityChair> chairs = world.getEntities(EntityChair.class, Predicates.alwaysTrue()); for (Entity entity : chairs) { RenderUtils.renderEntityDebugBoundingBox(entity, partialTicks, false, false); } } this.rulerRenderer.renderAllPositionPairs(usingPlayer, clientPlayer, partialTicks); }
Example 3
Source File: CraftingFluidBlock.java From the-hallow with MIT License | 5 votes |
@Override public void onEntityCollision(BlockState blockState, World world, BlockPos pos, Entity entity) { super.onEntityCollision(blockState, world, pos, entity); if(entity instanceof ItemEntity) { List<ItemEntity> entities = world.getEntities(ItemEntity.class, new Box(pos), e -> true); BasicInventory inventory = new BasicInventory(entities.size()); entities.forEach(itemEntity -> { //required for multi-input recipes ItemStack stack = itemEntity.getStack(); inventory.add(stack); }); Optional<FluidRecipe> match = world.getRecipeManager() .getFirstMatch(recipeType, inventory, world); if (match.isPresent()) { spawnCraftingResult(world, pos, match.get().craft(inventory)); for (Ingredient ingredient : match.get().getIngredients()) { for (ItemEntity testEntity : entities) { if (ingredient.test(testEntity.getStack())) { testEntity.getStack().decrement(1); break; } } } } } }
Example 4
Source File: DispenserBehaviorBucketCowsMixin.java From carpet-extra with GNU Lesser General Public License v3.0 | 5 votes |
@Inject( method = "dispenseSilently(Lnet/minecraft/util/math/BlockPointer;Lnet/minecraft/item/ItemStack;)Lnet/minecraft/item/ItemStack;", at = @At("HEAD"), cancellable = true ) private void milkCow(BlockPointer pointer, ItemStack stack, CallbackInfoReturnable<ItemStack> cir) { if (!CarpetExtraSettings.dispensersMilkCows) return; World world = pointer.getWorld(); if (!world.isClient) { BlockPos pos = pointer.getBlockPos().offset(pointer.getBlockState().get(DispenserBlock.FACING)); List<CowEntity> cows = world.getEntities(CowEntity.class, new Box(pos), e -> e.isAlive() && !e.isBaby()); if (!cows.isEmpty()) { stack.decrement(1); if (stack.isEmpty()) { cir.setReturnValue(new ItemStack(Items.MILK_BUCKET)); } else { if (((DispenserBlockEntity)pointer.getBlockEntity()).addToFirstFreeSlot(new ItemStack(Items.MILK_BUCKET)) < 0) { this.dispense(pointer, new ItemStack(Items.MILK_BUCKET)); } cir.setReturnValue(stack); } } } }
Example 5
Source File: ContainerLifecycleCommands.java From mobycraft with Apache License 2.0 | 5 votes |
public void killChaosMonkeys() { World world = sender.getEntityWorld(); int numberOfMonkeys = 0; for (EntityChaosMonkey entity : world.getEntities(EntityChaosMonkey.class, null)) { entity.setDead(); numberOfMonkeys++; } if (numberOfMonkeys == 0) { sendErrorMessage("There are no Chaos Monkeys in this world!"); } else { sendConfirmMessage("Killed " + numberOfMonkeys + " Chaos Monkeys."); } }
Example 6
Source File: ContainerLifecycleCommands.java From mobycraft with Apache License 2.0 | 5 votes |
public void killChaosMonkeys() { World world = sender.getEntityWorld(); int numberOfMonkeys = 0; for (EntityChaosMonkey entity : world.getEntities(EntityChaosMonkey.class, null)) { entity.setDead(); numberOfMonkeys++; } if (numberOfMonkeys == 0) { sendErrorMessage("There are no Chaos Monkeys in this world!"); } else { sendConfirmMessage("Killed " + numberOfMonkeys + " Chaos Monkeys."); } }
Example 7
Source File: Tracer.java From fabric-carpet with MIT License | 4 votes |
public static EntityHitResult rayTraceEntities(Entity source, Vec3d start, Vec3d end, Box box, Predicate<Entity> predicate, double maxSqDistance) { World world = source.world; double targetDistance = maxSqDistance; Entity target = null; Vec3d targetHitPos = null; for (Entity current : world.getEntities(source, box, predicate)) { Box currentBox = current.getBoundingBox().expand(current.getTargetingMargin()); Optional<Vec3d> currentHit = currentBox.rayTrace(start, end); if (currentBox.contains(start)) { if (targetDistance >= 0) { target = current; targetHitPos = currentHit.orElse(start); targetDistance = 0; } } else if (currentHit.isPresent()) { Vec3d currentHitPos = currentHit.get(); double currentDistance = start.squaredDistanceTo(currentHitPos); if (currentDistance < targetDistance || targetDistance == 0) { if (current.getRootVehicle() == source.getRootVehicle()) { if (targetDistance == 0) { target = current; targetHitPos = currentHitPos; } } else { target = current; targetHitPos = currentHitPos; targetDistance = currentDistance; } } } } if (target == null) return null; return new EntityHitResult(target, targetHitPos); }
Example 8
Source File: UnicornTrailRenderer.java From Wizardry with GNU Lesser General Public License v3.0 | 4 votes |
@SideOnly(Side.CLIENT) @SubscribeEvent public static void tick(TickEvent.ClientTickEvent event) { if (event.phase != TickEvent.Phase.END) return; World world = Minecraft.getMinecraft().world; if (world == null) return; List<EntityUnicorn> unicorns = world.getEntities(EntityUnicorn.class, input -> true); for (EntityUnicorn unicorn : unicorns) { if (unicorn == null) continue; if (unicorn.isDead) { positions.remove(unicorn); break; } positions.putIfAbsent(unicorn, new ArrayList<>()); List<Point> poses = positions.get(unicorn); if ((poses.size() >= 1000 || world.getTotalWorldTime() % 20 == 0) && !poses.isEmpty()) { poses.remove(0); } double mot = 0.05; if (poses.size() < 1000) { if (unicorn.motionX >= mot || unicorn.motionX <= -mot || unicorn.motionY >= mot || unicorn.motionY <= -mot || unicorn.motionZ >= mot || unicorn.motionZ <= -mot) { Vec3d backCenter = unicorn.getPositionVector(); Vec3d look = new Vec3d(unicorn.motionX, unicorn.motionY, unicorn.motionZ).normalize(); backCenter = backCenter.add(look.scale(-1)); Vec3d cross = look.crossProduct(new Vec3d(0, 1, 0)).normalize().scale(0.35f); poses.add(new Point(backCenter, cross, world.getTotalWorldTime())); } else if (!poses.isEmpty()) { poses.remove(0); } } } }