Skip to content

Commit

Permalink
Add Persistent argument to Spawn, to allow you to spawn monsters that…
Browse files Browse the repository at this point in the history
… don't get removed completely when you move far away.

Some entities, such as animals, are persistent by default in Minecraft.
  • Loading branch information
davidcernat committed Oct 11, 2013
1 parent 47b283b commit 6548861
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/aufdemrand/denizen/objects/dEntity.java
Expand Up @@ -1525,7 +1525,7 @@ else if ((float) getLivingEntity().getHealth() / maxHealth < 1)
// -->
if (attribute.startsWith("is_persistent")) {
if (isLivingEntity())
return new Element(getLivingEntity().getRemoveWhenFarAway())
return new Element(!getLivingEntity().getRemoveWhenFarAway())
.getAttribute(attribute.fulfill(1));
else
return Element.FALSE
Expand Down
Expand Up @@ -1980,7 +1980,7 @@ public void registerCoreMembers() {

// <--[command]
// @Name Spawn
// @Usage spawn [<entity>|...] (<location>) (target:<entity>)
// @Usage spawn [<entity>|...] (<location>) (target:<entity>) (persistent)
// @Required 1
// @Stable stable
// @Short Spawns a list of entities at a certain location.
Expand All @@ -1994,7 +1994,7 @@ public void registerCoreMembers() {
// Todo
// -->
registerCoreMember(SpawnCommand.class,
"SPAWN", "spawn [<entity>|...] (<location>) (target:<entity>)", 1);
"SPAWN", "spawn [<entity>|...] (<location>) (target:<entity>) (persistent)", 1);


// <--[command]
Expand Down
Expand Up @@ -57,6 +57,12 @@ else if (!scriptEntry.hasObject("spread")
scriptEntry.addObject("spread", arg.asElement());
}

else if (!scriptEntry.hasObject("persistent")
&& arg.matches("persistent")) {

scriptEntry.addObject("persistent", "");
}

else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value);
}

Expand All @@ -82,12 +88,14 @@ public void execute(final ScriptEntry scriptEntry) throws CommandExecutionExcept
dLocation location = (dLocation) scriptEntry.getObject("location");
dEntity target = (dEntity) scriptEntry.getObject("target");
Element spread = scriptEntry.getElement("spread");
boolean persistent = scriptEntry.hasObject("persistent");

// Report to dB
dB.report(getName(), aH.debugObj("entities", entities.toString()) +
location.debug() +
(spread != null?spread.debug():"") +
(target != null ? target.debug() : ""));
(spread != null ?spread.debug() : "") +
(target != null ? target.debug() : "") +
(persistent == true ? aH.debugObj("persistent", persistent) : ""));

// Keep a dList of entities that can be called using <entry[name].spawned_entities>
// later in the script queue
Expand All @@ -113,6 +121,10 @@ public void execute(final ScriptEntry scriptEntry) throws CommandExecutionExcept

entityList.add(entity.toString());

if (persistent && entity.isLivingEntity()) {
entity.getLivingEntity().setRemoveWhenFarAway(false);
}

if (target != null && target.isLivingEntity()) {
entity.target(target.getLivingEntity());
}
Expand Down

1 comment on commit 6548861

@davidcernat
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: using this argument will make entities not get deleted completely when you move far away from them, but they will still get despawned. However, they will respawn when you approach them.

Please sign in to comment.