Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions libraries/biomes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Biomes API

The Biomes API provides events and utilities for registering and working with biomes.

## Registering Custom Biomes

Biome registration should be done in a listener to the `REGISTER_BIOMES` event. The `BiomeRegistry` class provides utility methods for registering biomes.

An example is shown below.

```java
package com.example;

import net.ornithemc.osl.biomes.api.BiomeEvents;
import net.ornithemc.osl.entrypoints.api.ModInitializer;

public class ExampleInitializer implements ModInitializer {

@Override
public void init() {
BiomeEvents.REGISTER_BIOMES.register(ExampleBiomes::init);
}
}
```

```java
package com.example;

import net.minecraft.world.biome.Biome;

import net.ornithemc.osl.biomes.api.BiomeRegistry;
import net.ornithemc.osl.core.util.NamespacedIdentifiers;

public final class ExampleBiomes {

public static final CookieBiome COOKIE = BiomeRegistry.register(NamespacedIdentifiers.from("example", "cookie"), new CookieBiome(new Biome.Settings().setName("Cookie")));

public static void init() {
}
}
```
1 change: 1 addition & 0 deletions libraries/biomes/biomes-mc1.8.2-pre5-mc15w51b/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
setUpModule(project)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
min_mc_version = 1.8.2-pre5
max_mc_version = 15w51b

minecraft_version = 1.8.9
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package net.ornithemc.osl.biomes.api;

import net.ornithemc.osl.core.api.events.Event;

/**
* Events related to the biomes lifecycle.
*/
public final class BiomeEvents {

/**
* This event is invoked upon game start-up, after Vanilla biome registration is finished.
*
* <p>
* Custom biome registration should be done in a listener of this event.
* Helper methods for registering biomes can be found in the {@linkplain
* BiomeRegistry} class.
*
* <p>
* Listeners to this event should be registered in your mod's entrypoint,
* and can be done as follows:
*
* <pre>
* {@code
* BiomeEvents.REGISTER_BIOMES.register(() -> {
* BiomeRegistry.register(NamespacedIdentifiers.from("example", "cookie"), new CookieBiome());
* });
* }
* </pre>
*
* @see BiomeRegistry
*/
public static final Event<Runnable> REGISTER_BIOMES = Event.runnable();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package net.ornithemc.osl.biomes.api;

import java.util.Set;

import net.minecraft.world.biome.Biome;

import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
import net.ornithemc.osl.biomes.impl.BiomeRegistryImpl;
import net.ornithemc.osl.registries.api.registry.ResourceKey;

/**
* Public access to the Biomes registry.
*/
public final class BiomeRegistry {

/**
* @return the numerical ID assigned to the given biome.
*/
public static int getId(Biome biome) {
return BiomeRegistryImpl.getId(biome);
}

/**
* @return the namespaced ID assigned to the given biome.
*/
public static NamespacedIdentifier getIdentifier(Biome biome) {
return BiomeRegistryImpl.getIdentifier(biome);
}

/**
* @return the resource key assigned to the given biome.
*/
public static ResourceKey<Biome> getKey(Biome biome) {
return BiomeRegistryImpl.getKey(biome);
}

/**
* @return the biome mapped to the given numerical ID.
*/
public static Biome getBiome(int id) {
return BiomeRegistryImpl.getBiome(id);
}

/**
* @return the biome mapped to the given namespaced ID.
*/
public static Biome getBiome(NamespacedIdentifier identifier) {
return BiomeRegistryImpl.getBiome(identifier);
}

/**
* @return the biome mapped to the given resource key.
*/
public static Biome getBiome(ResourceKey<Biome> key) {
return BiomeRegistryImpl.getBiome(key);
}

/**
* @return a set containing all namespaced IDs in the registry.
*/
public static Set<NamespacedIdentifier> identifierSet() {
return BiomeRegistryImpl.identifierSet();
}

/**
* @return a set containing all resource keys in the registry.
*/
public static Set<ResourceKey<Biome>> keySet() {
return BiomeRegistryImpl.keySet();
}

/**
* @param <T> the biome type.
* @param identifier the namespaced ID of the biome.
* @param biome the biome to register.
* @return the registered biome.
*/
public static <T extends Biome> T register(NamespacedIdentifier identifier, T biome) {
return BiomeRegistryImpl.register(identifier, biome);
}

/**
* @param <T> the biome type.
* @param key the resource key of the biome.
* @param biome the biome to register.
* @return the registered biome.
*/
public static <T extends Biome> T register(ResourceKey<Biome> key, T biome) {
return BiomeRegistryImpl.register(key, biome);
}

/**
* @param <T> the biome type.
* @param id the numerical ID of the biome.
* @param key the namespaced ID of the biome.
* @param biome the biome to register.
* @return the registered biome.
*
* @deprecated use {@linkplain #register(NamespacedIdentifier, Biome)}
* or {@linkplain #register(ResourceKey, Biome)} instead.
*/
@Deprecated
public static <T extends Biome> T register(int id, NamespacedIdentifier key, T biome) {
return BiomeRegistryImpl.register(id, key, biome);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package net.ornithemc.osl.biomes.api.biome;

import net.minecraft.world.biome.Biome;

import net.ornithemc.osl.biomes.impl.BiomeRegistryImpl;
import net.ornithemc.osl.registries.api.registry.Registry;

public interface BiomeExtension {

Registry<Biome> REGISTRY = BiomeRegistryImpl.REGISTRY;
int AUTO_ASSIGN_ID = -172;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package net.ornithemc.osl.biomes.impl;

import java.util.Set;

import net.minecraft.world.biome.Biome;

import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
import net.ornithemc.osl.biomes.api.BiomeEvents;
import net.ornithemc.osl.biomes.impl.biome.BiomeIdFixer;
import net.ornithemc.osl.registries.api.registry.Registries;
import net.ornithemc.osl.registries.api.registry.Registry;
import net.ornithemc.osl.registries.api.registry.RegistryKeys;
import net.ornithemc.osl.registries.api.registry.ResourceKey;
import net.ornithemc.osl.registries.api.registry.SyncedRegistries;
import net.ornithemc.osl.registries.impl.registry.RegistriesImpl;

public final class BiomeRegistryImpl {

public static final Registry<Biome> REGISTRY = Registries.registerSimple(RegistryKeys.BIOME, () -> Biome.BY_ID.getClass());

private static boolean locked = true;

public static int getId(Biome biome) {
return REGISTRY.getId(biome);
}

public static NamespacedIdentifier getIdentifier(Biome biome) {
return REGISTRY.getIdentifier(biome);
}

public static ResourceKey<Biome> getKey(Biome biome) {
return REGISTRY.getKey(biome);
}

public static Biome getBiome(int id) {
return REGISTRY.get(id);
}

public static Biome getBiome(NamespacedIdentifier identifier) {
return REGISTRY.get(identifier);
}

public static Biome getBiome(ResourceKey<Biome> key) {
return REGISTRY.get(key);
}

public static Set<NamespacedIdentifier> identifierSet() {
return REGISTRY.identifierSet();
}

public static Set<ResourceKey<Biome>> keySet() {
return REGISTRY.keySet();
}

@SuppressWarnings("deprecation")
public static <T extends Biome> T register(NamespacedIdentifier identifier, T biome) {
if (locked) {
throw new IllegalStateException("register called too early: registry locked!");
} else {
return Registry.register(REGISTRY, biome.id, identifier, biome);
}
}

@SuppressWarnings("deprecation")
public static <T extends Biome> T register(ResourceKey<Biome> key, T biome) {
if (locked) {
throw new IllegalStateException("register called too early: registry locked!");
} else {
return Registry.register(REGISTRY, biome.id, key, biome);
}
}

@Deprecated
public static <T extends Biome> T register(int id, NamespacedIdentifier key, T biome) {
if (locked) {
throw new IllegalStateException("register called too early: registry locked!");
} else {
if (biome.id != id) {
throw new IllegalArgumentException("ID " + id + " does not match biome ID " + biome.id + " for " + key);
}

return Registry.register(REGISTRY, id, key, biome);
}
}

public static void init() {
SyncedRegistries.register(RegistryKeys.BIOME);
SyncedRegistries.registerFixer(RegistryKeys.BIOME, NamespacedIdentifiers.from("biome/id"), new BiomeIdFixer());
}

public static void unlock() {
locked = false;
}

public static void registerBiomes() {
VanillaBiomes.init();
BiomeEvents.REGISTER_BIOMES.invoker().run();
}

public static void registerUnknownBiomes() {
for (Biome biome : Biome.BY_ID) {
if (biome != null && REGISTRY.getIdentifier(biome) == null) {
NamespacedIdentifier identifier = NamespacedIdentifiers.from("osl", "biome_" + biome.id);

RegistriesImpl.LOGGER.warn("Biome {}/{}", biome.id, biome.getClass().getSimpleName() + " was not registered to OSL's Biome registry! Adding it as '" + identifier + "'...");
BiomeRegistryImpl.register(identifier, biome);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package net.ornithemc.osl.biomes.impl;

import java.util.List;
import java.util.Set;

import org.objectweb.asm.tree.ClassNode;

import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;

public class BiomesMixinPlugin implements IMixinConfigPlugin {

public static final boolean BIOME_IDS_BEYOND_255_SUPPORTED = false;

@Override
public void onLoad(String mixinPackage) {
}

@Override
public String getRefMapperConfig() {
return null;
}

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
return true;
}

@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
}

@Override
public List<String> getMixins() {
return null;
}

@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
}

@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
}
}
Loading
Loading