public EntityFunction createFunction() { final Type type = this.type; checkNotNull(type, "type can't be null"); return entity -> { EntityProperties registryType = entity.getFacet(EntityProperties.class); if (registryType != null) { if (type.matches(registryType)) { entity.remove(); return true; } } return false; }; }
@Override public Extent getExtent() { return entity.getExtent(); }
@Override public boolean remove() { Location location = entity.getLocation(); BaseEntity state = entity.getState(); boolean success = entity.remove(); if (state != null && success) { changeSet.add(new EntityRemove(location, state)); } return success; }
@Override public void redo(UndoContext context) throws WorldEditException { if (entity != null) { entity.remove(); entity = null; } }
@Nullable @Override public <T> T getFacet(Class<? extends T> cls) { return entity.getFacet(cls); } }
@Override public Location getLocation() { return entity.getLocation(); }
@Override public BaseEntity getState() { return entity.getState(); }
@Override public boolean setLocation(Location location) { // TODO Add a changeset for this. return entity.setLocation(location); }
@Override public void undo(UndoContext context) throws WorldEditException { if (entity != null) { entity.remove(); entity = null; } }
List<? extends Entity> entities = Lists.newArrayList(source.getEntities(region)); entities.removeIf(entity -> { EntityProperties properties = entity.getFacet(EntityProperties.class); return properties != null && !properties.isPasteable(); });
@Override public List<? extends Entity> getEntities(Region region) { List<Entity> filtered = new ArrayList<>(); for (Entity entity : entities) { if (region.contains(entity.getLocation().toVector().toBlockPoint())) { filtered.add(entity); } } return Collections.unmodifiableList(filtered); }
@Override public boolean apply(Entity entity) throws WorldEditException { BaseEntity state = entity.getState(); if (state != null) { Location newLocation; Location location = entity.getLocation(); Vector3 pivot = from.round().add(0.5, 0.5, 0.5); Vector3 newPosition = transform.apply(location.toVector().subtract(pivot)); Vector3 newDirection; newDirection = transform.isIdentity() ? entity.getLocation().getDirection() : transform.apply(location.getDirection()).subtract(transform.apply(Vector3.ZERO)).normalize(); newLocation = new Location(destination, newPosition.add(to.round().add(0.5, 0.5, 0.5)), newDirection); // Some entities store their position data in NBT state = transformNbtData(state); boolean success = destination.createEntity(newLocation, state) != null; // Remove if (isRemoving() && success) { entity.remove(); } return success; } else { return false; } }
entity.remove(); removed++;
/** * Returns whether an entity should be removed for the halt activity mode. * * @param entity The entity * @return true if it's to be removed */ public static boolean isIntensiveEntity(Entity entity) { EntityProperties properties = entity.getFacet(EntityProperties.class); return properties != null && (properties.isItem() || properties.isTNT() || properties.isExperienceOrb() || properties.isFallingBlock() || (properties.isLiving() && !(properties.isTamed()) && !(properties.isPlayerDerived()) && !properties.isArmorStand())); } }
@Override public Pattern call(CommandArgs args, CommandLocals locals) throws CommandException { String patternString = stringParser.call(args, locals); Actor actor = locals.get(Actor.class); LocalSession session = WorldEdit.getInstance().getSessionManager().get(actor); ParserContext parserContext = new ParserContext(); parserContext.setActor(actor); if (actor instanceof Entity) { Extent extent = ((Entity) actor).getExtent(); if (extent instanceof World) { parserContext.setWorld((World) extent); } } parserContext.setSession(session); try { return WorldEdit.getInstance().getPatternFactory().parseFromInput(patternString, parserContext); } catch (InputParseException e) { throw new CommandException(e.getMessage(), e); } }
@Override public BaseItem call(CommandArgs args, CommandLocals locals) throws CommandException { String itemString = stringParser.call(args, locals); Actor actor = locals.get(Actor.class); LocalSession session = WorldEdit.getInstance().getSessionManager().get(actor); ParserContext parserContext = new ParserContext(); parserContext.setActor(actor); if (actor instanceof Entity) { Extent extent = ((Entity) actor).getExtent(); if (extent instanceof World) { parserContext.setWorld((World) extent); } } parserContext.setSession(session); try { return WorldEdit.getInstance().getItemFactory().parseFromInput(itemString, parserContext); } catch (InputParseException e) { throw new CommandException(e.getMessage(), e); } }
/** * Gets an {@link BaseBlock} from a {@link ArgumentStack}. * * @param context the context * @return a pattern * @throws ParameterException on error * @throws WorldEditException on error */ @BindingMatch(type = {BaseBlock.class, BlockState.class, BlockStateHolder.class}, behavior = BindingBehavior.CONSUMES, consumedCount = 1) public BaseBlock getBaseBlock(ArgumentStack context) throws ParameterException, WorldEditException { Actor actor = context.getContext().getLocals().get(Actor.class); ParserContext parserContext = new ParserContext(); parserContext.setActor(context.getContext().getLocals().get(Actor.class)); if (actor instanceof Entity) { Extent extent = ((Entity) actor).getExtent(); if (extent instanceof World) { parserContext.setWorld((World) extent); } } parserContext.setSession(worldEdit.getSessionManager().get(actor)); try { return worldEdit.getBlockFactory().parseFromInput(context.next(), parserContext); } catch (NoMatchException e) { throw new ParameterException(e.getMessage(), e); } }
/** * Gets an {@link Pattern} from a {@link ArgumentStack}. * * @param context the context * @return a pattern * @throws ParameterException on error * @throws WorldEditException on error */ @BindingMatch(type = Pattern.class, behavior = BindingBehavior.CONSUMES, consumedCount = 1) public Pattern getPattern(ArgumentStack context) throws ParameterException, WorldEditException { Actor actor = context.getContext().getLocals().get(Actor.class); ParserContext parserContext = new ParserContext(); parserContext.setActor(context.getContext().getLocals().get(Actor.class)); if (actor instanceof Entity) { Extent extent = ((Entity) actor).getExtent(); if (extent instanceof World) { parserContext.setWorld((World) extent); } } parserContext.setSession(worldEdit.getSessionManager().get(actor)); try { return worldEdit.getPatternFactory().parseFromInput(context.next(), parserContext); } catch (NoMatchException e) { throw new ParameterException(e.getMessage(), e); } }
/** * Gets an {@link Mask} from a {@link ArgumentStack}. * * @param context the context * @return a pattern * @throws ParameterException on error * @throws WorldEditException on error */ @BindingMatch(type = Mask.class, behavior = BindingBehavior.CONSUMES, consumedCount = 1) public Mask getMask(ArgumentStack context) throws ParameterException, WorldEditException { Actor actor = context.getContext().getLocals().get(Actor.class); ParserContext parserContext = new ParserContext(); parserContext.setActor(context.getContext().getLocals().get(Actor.class)); if (actor instanceof Entity) { Extent extent = ((Entity) actor).getExtent(); if (extent instanceof World) { parserContext.setWorld((World) extent); } } parserContext.setSession(worldEdit.getSessionManager().get(actor)); try { return worldEdit.getMaskFactory().parseFromInput(context.next(), parserContext); } catch (NoMatchException e) { throw new ParameterException(e.getMessage(), e); } }