-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added CustomBiomesManager to add support for custom world generator…
…s and their biomes - Added a Terra generator integration for Custom Biomes - Added an entity arg parser to set entity type for spawners (`item: spawner entity:zombie`)
- Loading branch information
Showing
10 changed files
with
201 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
eco-api/src/main/java/com/willfp/eco/core/integrations/custombiomes/CustomBiome.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.willfp.eco.core.integrations.custombiomes; | ||
|
||
public class CustomBiome { | ||
private final String name; | ||
|
||
public CustomBiome(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
.../src/main/java/com/willfp/eco/core/integrations/custombiomes/CustomBiomesIntegration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.willfp.eco.core.integrations.custombiomes; | ||
|
||
import com.willfp.eco.core.integrations.Integration; | ||
import org.bukkit.Location; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Wrapper class for custom biome integrations. | ||
*/ | ||
public interface CustomBiomesIntegration extends Integration { | ||
/** | ||
* Get a biome at given location. (Supports vanilla biomes as well) | ||
* | ||
* @param location The location to get the biome at. | ||
* @return The found biome, null otherwise | ||
*/ | ||
@Nullable | ||
CustomBiome getBiome(Location location); | ||
} |
58 changes: 58 additions & 0 deletions
58
eco-api/src/main/java/com/willfp/eco/core/integrations/custombiomes/CustomBiomesManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.willfp.eco.core.integrations.custombiomes; | ||
|
||
import com.willfp.eco.core.Eco; | ||
import com.willfp.eco.core.integrations.IntegrationRegistry; | ||
import org.bukkit.Location; | ||
import org.bukkit.World; | ||
import org.bukkit.block.Biome; | ||
import org.bukkit.event.Listener; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public final class CustomBiomesManager { | ||
/** | ||
* A set of all registered biomes. | ||
*/ | ||
private static final IntegrationRegistry<CustomBiomesIntegration> REGISTRY = new IntegrationRegistry<>(); | ||
|
||
/** | ||
* Register a new biomes integration. | ||
* | ||
* @param biomesIntegration The biomes integration to register. | ||
*/ | ||
public static void register(@NotNull final CustomBiomesIntegration biomesIntegration) { | ||
if (biomesIntegration instanceof Listener) { | ||
Eco.get().getEcoPlugin().getEventManager().registerListener((Listener) biomesIntegration); | ||
} | ||
REGISTRY.register(biomesIntegration); | ||
} | ||
|
||
@Nullable | ||
public static CustomBiome getBiomeAt(@NotNull Location location) { | ||
World world = location.getWorld(); | ||
|
||
if (world == null) { | ||
return null; | ||
} | ||
|
||
Biome vanilla = world.getBiome(location); | ||
|
||
if (vanilla.name().equalsIgnoreCase("custom")) { | ||
for (CustomBiomesIntegration integration : REGISTRY) { | ||
CustomBiome biome = integration.getBiome(location); | ||
|
||
if (biome != null) { | ||
return biome; | ||
} | ||
} | ||
|
||
return null; | ||
} else { | ||
return new CustomBiome(vanilla.name()); | ||
} | ||
} | ||
|
||
private CustomBiomesManager() { | ||
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/items/ArgParserEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.willfp.eco.internal.items | ||
|
||
import com.willfp.eco.core.items.args.LookupArgParser | ||
import org.bukkit.block.CreatureSpawner | ||
import org.bukkit.entity.EntityType | ||
import org.bukkit.inventory.ItemStack | ||
import org.bukkit.inventory.meta.BlockStateMeta | ||
import org.bukkit.inventory.meta.ItemMeta | ||
import java.util.function.Predicate | ||
|
||
object ArgParserEntity : LookupArgParser { | ||
override fun parseArguments(args: Array<out String>, meta: ItemMeta): Predicate<ItemStack>? { | ||
if (meta !is BlockStateMeta) { | ||
return null | ||
} | ||
|
||
if (meta.hasBlockState() || meta.blockState !is CreatureSpawner) { | ||
return null | ||
} | ||
|
||
val state = meta.blockState as CreatureSpawner | ||
|
||
var type: String? = null | ||
|
||
for (arg in args) { | ||
val argSplit = arg.split(":") | ||
if (!argSplit[0].equals("entity", ignoreCase = true)) { | ||
continue | ||
} | ||
if (argSplit.size < 2) { | ||
continue | ||
} | ||
type = argSplit[1] | ||
} | ||
|
||
type ?: return null | ||
|
||
val entityType = runCatching { EntityType.valueOf(type.uppercase()) }.getOrNull() ?: return null | ||
|
||
state.spawnedType = entityType | ||
|
||
meta.blockState = state | ||
|
||
return Predicate { | ||
val testMeta = ((it.itemMeta as? BlockStateMeta) as? CreatureSpawner) ?: return@Predicate false | ||
|
||
testMeta.spawnedType?.name?.equals(type, true) == true | ||
} | ||
} | ||
|
||
override fun serializeBack(meta: ItemMeta): String? { | ||
if (meta !is BlockStateMeta) { | ||
return null | ||
} | ||
|
||
if (meta.hasBlockState() || meta.blockState !is CreatureSpawner) { | ||
return null | ||
} | ||
|
||
val state = meta.blockState as CreatureSpawner | ||
|
||
return state.spawnedType?.let { "entity:${state.spawnedType!!.name}" } ?: return null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...main/kotlin/com/willfp/eco/internal/spigot/integrations/custombiomes/CustomBiomesTerra.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.willfp.eco.internal.spigot.integrations.custombiomes | ||
|
||
import com.dfsek.terra.bukkit.world.BukkitAdapter | ||
import com.willfp.eco.core.integrations.custombiomes.CustomBiome | ||
import com.willfp.eco.core.integrations.custombiomes.CustomBiomesIntegration | ||
import org.bukkit.Location | ||
|
||
class CustomBiomesTerra: CustomBiomesIntegration { | ||
override fun getPluginName(): String { | ||
return "Terra" | ||
} | ||
|
||
override fun getBiome(location: Location?): CustomBiome? { | ||
if (location == null || location.world == null) { | ||
return null | ||
} | ||
|
||
val terraLocation = BukkitAdapter.adapt(location) ?: return null | ||
val terraWorld = BukkitAdapter.adapt(location.world!!) ?: return null | ||
val biomeProvider = terraWorld.biomeProvider ?: return null | ||
val biome = biomeProvider.getBiome(terraLocation, terraWorld.seed) ?: return null | ||
|
||
return CustomBiome(biome.id) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters