Skip to content

Commit

Permalink
update for lambda-based tag registration
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Oct 28, 2019
1 parent c3b139e commit 161ff21
Show file tree
Hide file tree
Showing 16 changed files with 3,552 additions and 5,143 deletions.
155 changes: 70 additions & 85 deletions plugin/src/main/java/com/denizenscript/denizen/objects/BiomeTag.java
Expand Up @@ -163,11 +163,8 @@ public static void registerTags() {
// Returns this biome's downfall type for when a world has weather.
// This can be RAIN, SNOW, or NONE.
// -->
registerTag("downfall_type", new TagRunnable.ObjectForm<BiomeTag>() {
@Override
public ObjectTag run(Attribute attribute, BiomeTag object) {
return new ElementTag(CoreUtilities.toLowerCase(object.biome.getDownfallType().name()));
}
registerTag("downfall_type", (attribute, object) -> {
return new ElementTag(CoreUtilities.toLowerCase(object.biome.getDownfallType().name()));
});

// <--[tag]
Expand All @@ -176,94 +173,85 @@ public ObjectTag run(Attribute attribute, BiomeTag object) {
// @description
// Returns the humidity of this biome.
// -->
registerTag("humidity", new TagRunnable.ObjectForm<BiomeTag>() {
@Override
public ObjectTag run(Attribute attribute, BiomeTag object) {
return new ElementTag(object.biome.getHumidity());
}
registerTag("humidity", (attribute, object) -> {
return new ElementTag(object.biome.getHumidity());
});
// <--[tag]
// @attribute <BiomeTag.temperature>
// @returns ElementTag(Decimal)
// @description
// Returns the temperature of this biome.
// -->
registerTag("temperature", new TagRunnable.ObjectForm<BiomeTag>() {
@Override
public ObjectTag run(Attribute attribute, BiomeTag object) {
return new ElementTag(object.biome.getTemperature());
}
registerTag("temperature", (attribute, object) -> {
return new ElementTag(object.biome.getTemperature());
});
// <--[tag]
// @attribute <BiomeTag.spawnable_entities>
// @returns ListTag(EntityTag)
// @description
// Returns all entities that spawn naturally in this biome.
// -->
registerTag("spawnable_entities", new TagRunnable.ObjectForm<BiomeTag>() {
@Override
public ObjectTag run(Attribute attribute, BiomeTag object) {
BiomeNMS biome = object.biome;

List<EntityType> entityTypes;

// <--[tag]
// @attribute <BiomeTag.spawnable_entities.ambient>
// @returns ListTag(EntityTag)
// @description
// Returns the entities that spawn naturally in ambient locations.
// Default examples: BAT
// -->
if (attribute.startsWith("ambient", 2)) {
attribute.fulfill(1);
entityTypes = biome.getAmbientEntities();
}

// <--[tag]
// @attribute <BiomeTag.spawnable_entities.creatures>
// @returns ListTag(EntityTag)
// @description
// Returns the entities that spawn naturally in creature locations.
// Default examples: PIG, COW, CHICKEN...
// -->
else if (attribute.startsWith("creatures", 2)) {
attribute.fulfill(1);
entityTypes = biome.getCreatureEntities();
}

// <--[tag]
// @attribute <BiomeTag.spawnable_entities.monsters>
// @returns ListTag(EntityTag)
// @description
// Returns the entities that spawn naturally in monster locations.
// Default examples: CREEPER, ZOMBIE, SKELETON...
// -->
else if (attribute.startsWith("monsters", 2)) {
attribute.fulfill(1);
entityTypes = biome.getMonsterEntities();
}

// <--[tag]
// @attribute <BiomeTag.spawnable_entities.water>
// @returns ListTag(EntityTag)
// @description
// Returns the entities that spawn naturally in underwater locations.
// Default examples: SQUID
// -->
else if (attribute.startsWith("water", 2)) {
attribute.fulfill(1);
entityTypes = biome.getWaterEntities();
}
else {
entityTypes = biome.getAllEntities();
}

ListTag list = new ListTag();
for (EntityType entityType : entityTypes) {
list.add(entityType.name());
}
return list;
registerTag("spawnable_entities", (attribute, object) -> {
BiomeNMS biome = object.biome;

List<EntityType> entityTypes;

// <--[tag]
// @attribute <BiomeTag.spawnable_entities.ambient>
// @returns ListTag(EntityTag)
// @description
// Returns the entities that spawn naturally in ambient locations.
// Default examples: BAT
// -->
if (attribute.startsWith("ambient", 2)) {
attribute.fulfill(1);
entityTypes = biome.getAmbientEntities();
}

// <--[tag]
// @attribute <BiomeTag.spawnable_entities.creatures>
// @returns ListTag(EntityTag)
// @description
// Returns the entities that spawn naturally in creature locations.
// Default examples: PIG, COW, CHICKEN...
// -->
else if (attribute.startsWith("creatures", 2)) {
attribute.fulfill(1);
entityTypes = biome.getCreatureEntities();
}

// <--[tag]
// @attribute <BiomeTag.spawnable_entities.monsters>
// @returns ListTag(EntityTag)
// @description
// Returns the entities that spawn naturally in monster locations.
// Default examples: CREEPER, ZOMBIE, SKELETON...
// -->
else if (attribute.startsWith("monsters", 2)) {
attribute.fulfill(1);
entityTypes = biome.getMonsterEntities();
}

// <--[tag]
// @attribute <BiomeTag.spawnable_entities.water>
// @returns ListTag(EntityTag)
// @description
// Returns the entities that spawn naturally in underwater locations.
// Default examples: SQUID
// -->
else if (attribute.startsWith("water", 2)) {
attribute.fulfill(1);
entityTypes = biome.getWaterEntities();
}
else {
entityTypes = biome.getAllEntities();
}

ListTag list = new ListTag();
for (EntityType entityType : entityTypes) {
list.add(entityType.name());
}
return list;
});

// <--[tag]
Expand All @@ -273,18 +261,15 @@ else if (attribute.startsWith("water", 2)) {
// Always returns 'Biome' for BiomeTag objects. All objects fetchable by the Object Fetcher will return the
// type of object that is fulfilling this attribute.
// -->
registerTag("type", new TagRunnable.ObjectForm<BiomeTag>() {
@Override
public ObjectTag run(Attribute attribute, BiomeTag object) {
return new ElementTag("Biome");
}
registerTag("type", (attribute, object) -> {
return new ElementTag("Biome");
});
}

public static ObjectTagProcessor<BiomeTag> tagProcessor = new ObjectTagProcessor<>();

public static void registerTag(String name, TagRunnable.ObjectForm<BiomeTag> runnable) {
tagProcessor.registerTag(name, runnable);
public static void registerTag(String name, TagRunnable.ObjectInterface<BiomeTag> runnable, String... variants) {
tagProcessor.registerTag(name, runnable, variants);
}

@Override
Expand Down

0 comments on commit 161ff21

Please sign in to comment.