-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Got most things resolved - NeoForge fully working
- Loading branch information
1 parent
12bba51
commit ecfbb2e
Showing
18 changed files
with
492 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
package com.girafi.waddles; | ||
|
||
import com.girafi.waddles.init.PenguinRegistry; | ||
import com.girafi.waddles.init.WaddlesSounds; | ||
|
||
public class CommonClass { | ||
|
||
public static void init() { | ||
WaddlesSounds.load(); | ||
PenguinRegistry.load(); | ||
} | ||
} |
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
23 changes: 14 additions & 9 deletions
23
common/src/main/java/com/girafi/waddles/init/WaddlesSounds.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 |
---|---|---|
@@ -1,23 +1,28 @@ | ||
package com.girafi.waddles.init; | ||
|
||
import com.girafi.waddles.Constants; | ||
import com.girafi.waddles.registration.RegistrationProvider; | ||
import com.girafi.waddles.registration.RegistryObject; | ||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.sounds.SoundEvent; | ||
import net.minecraft.world.entity.EntityType; | ||
|
||
import java.util.HashMap; | ||
import java.util.function.Supplier; | ||
|
||
public class WaddlesSounds { | ||
public static final HashMap<String, Supplier<SoundEvent>> SOUND_MAP = new HashMap<>(); | ||
public static final Supplier<SoundEvent> ADELIE_AMBIENT = createSound("adelie.ambient"); | ||
public static final Supplier<SoundEvent> ADELIE_BABY_AMBIENT = createSound("adelie.baby.ambient"); | ||
public static final Supplier<SoundEvent> ADELIE_DEATH = createSound("adelie.death"); | ||
public static final Supplier<SoundEvent> ADELIE_HURT = createSound("adelie.hurt"); | ||
public static final RegistrationProvider<SoundEvent> SOUNDS = RegistrationProvider.get(BuiltInRegistries.SOUND_EVENT, Constants.MOD_ID); | ||
public static final RegistryObject<SoundEvent> ADELIE_AMBIENT = createSound("adelie.ambient"); | ||
public static final RegistryObject<SoundEvent> ADELIE_BABY_AMBIENT = createSound("adelie.baby.ambient"); | ||
public static final RegistryObject<SoundEvent> ADELIE_DEATH = createSound("adelie.death"); | ||
public static final RegistryObject<SoundEvent> ADELIE_HURT = createSound("adelie.hurt"); | ||
|
||
private static Supplier<SoundEvent> createSound(String name) { | ||
private static RegistryObject<SoundEvent> createSound(String name) { | ||
ResourceLocation resourceLocation = new ResourceLocation(Constants.MOD_ID, name); | ||
Supplier<SoundEvent> soundEvent = () -> SoundEvent.createVariableRangeEvent(resourceLocation); | ||
SOUND_MAP.put(name, soundEvent); | ||
return soundEvent; | ||
return SOUNDS.register(name, () -> SoundEvent.createVariableRangeEvent(resourceLocation)); | ||
} | ||
|
||
//Needed to statically initialize fields | ||
public static void load() {} | ||
} |
113 changes: 113 additions & 0 deletions
113
common/src/main/java/com/girafi/waddles/registration/RegistrationProvider.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,113 @@ | ||
package com.girafi.waddles.registration; | ||
|
||
import com.girafi.waddles.platform.Services; | ||
import net.minecraft.core.Registry; | ||
import net.minecraft.resources.ResourceKey; | ||
|
||
import java.util.Collection; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Utility class for multiloader registration. | ||
* <p> | ||
* Example usage: | ||
* <pre>{@code | ||
* public static final RegistrationProvider<Test> PROVIDER = RegistrationProvider.get(Test.REGISTRY, "modid"); | ||
* public static final RegistryObject<Test> OBJECT = PROVIDER.register("object", () -> new Test()); | ||
* | ||
* // The purpose of this method is to be called in the mod's constructor, in order to assure that the class is loaded, and that objects can be registered. | ||
* public static void loadClass(){} | ||
* }</pre> | ||
* | ||
* @param <T> the type of the objects that this class registers | ||
*/ | ||
public interface RegistrationProvider<T> { | ||
|
||
/** | ||
* Gets a provider for specified {@code modId} and {@code resourceKey}. <br> | ||
* It is <i>recommended</i> to store the resulted provider in a {@code static final} field to | ||
* the {@link Factory#INSTANCE factory} creating multiple providers for the same resource key and mod id. | ||
* | ||
* @param resourceKey the {@link ResourceKey} of the registry of the provider | ||
* @param modId the mod id that the provider will register objects for | ||
* @param <T> the type of the provider | ||
* @return the provider | ||
*/ | ||
static <T> RegistrationProvider<T> get(ResourceKey<? extends Registry<T>> resourceKey, String modId) { | ||
return Factory.INSTANCE.create(resourceKey, modId); | ||
} | ||
|
||
/** | ||
* Gets a provider for specified {@code modId} and {@code registry}. <br> | ||
* It is <i>recommended</i> to store the resulted provider in a {@code static final} field to | ||
* the {@link Factory#INSTANCE factory} creating multiple providers for the same resource key and mod id. | ||
* | ||
* @param registry the {@link Registry} of the provider | ||
* @param modId the mod id that the provider will register objects for | ||
* @param <T> the type of the provider | ||
* @return the provider | ||
*/ | ||
static <T> RegistrationProvider<T> get(Registry<T> registry, String modId) { | ||
return Factory.INSTANCE.create(registry, modId); | ||
} | ||
|
||
/** | ||
* Registers an object. | ||
* | ||
* @param name the name of the object | ||
* @param supplier a supplier of the object to register | ||
* @param <I> the type of the object | ||
* @return a wrapper containing the lazy registered object. <strong>Calling {@link RegistryObject#get() get} too early | ||
* on the wrapper might result in crashes!</strong> | ||
*/ | ||
<I extends T> RegistryObject<I> register(String name, Supplier<? extends I> supplier); | ||
|
||
/** | ||
* Gets all the objects currently registered. | ||
* | ||
* @return an <strong>immutable</strong> view of all the objects currently registered | ||
*/ | ||
Collection<RegistryObject<T>> getEntries(); | ||
|
||
/** | ||
* Gets the mod id that this provider registers objects for. | ||
* | ||
* @return the mod id | ||
*/ | ||
String getModId(); | ||
|
||
/** | ||
* Factory class for {@link RegistrationProvider registration providers}. <br> | ||
* This class is loaded using {@link java.util.ServiceLoader Service Loaders}, and only one | ||
* should exist per mod loader. | ||
*/ | ||
interface Factory { | ||
|
||
/** | ||
* The singleton instance of the {@link Factory}. This is different on each loader. | ||
*/ | ||
Factory INSTANCE = Services.load(Factory.class); | ||
|
||
/** | ||
* Creates a {@link RegistrationProvider}. | ||
* | ||
* @param resourceKey the {@link ResourceKey} of the registry to create this provider for | ||
* @param modId the mod id for which the provider will register objects | ||
* @param <T> the type of the provider | ||
* @return the provider | ||
*/ | ||
<T> RegistrationProvider<T> create(ResourceKey<? extends Registry<T>> resourceKey, String modId); | ||
|
||
/** | ||
* Creates a {@link RegistrationProvider}. | ||
* | ||
* @param registry the {@link Registry} to create this provider for | ||
* @param modId the mod id for which the provider will register objects | ||
* @param <T> the type of the provider | ||
* @return the provider | ||
*/ | ||
default <T> RegistrationProvider<T> create(Registry<T> registry, String modId) { | ||
return create(registry.key(), modId); | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
common/src/main/java/com/girafi/waddles/registration/RegistryObject.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,45 @@ | ||
package com.girafi.waddles.registration; | ||
|
||
import net.minecraft.core.Holder; | ||
import net.minecraft.resources.ResourceKey; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Represents a lazy wrapper for registry object. | ||
* | ||
* @param <T> the type of the object | ||
*/ | ||
public interface RegistryObject<T> extends Supplier<T> { | ||
|
||
/** | ||
* Gets the {@link ResourceKey} of the registry of the object wrapped. | ||
* | ||
* @return the {@link ResourceKey} of the registry | ||
*/ | ||
ResourceKey<T> getResourceKey(); | ||
|
||
/** | ||
* Gets the id of the object. | ||
* | ||
* @return the id of the object | ||
*/ | ||
ResourceLocation getId(); | ||
|
||
/** | ||
* Gets the object behind this wrapper. Calling this method too early | ||
* might result in crashes. | ||
* | ||
* @return the object behind this wrapper | ||
*/ | ||
@Override | ||
T get(); | ||
|
||
/** | ||
* Gets this object wrapped in a vanilla {@link Holder}. | ||
* | ||
* @return the holder | ||
*/ | ||
Holder<T> asHolder(); | ||
} |
6 changes: 5 additions & 1 deletion
6
common/src/main/resources/data/waddles/tags/worldgen/biome/spawn_include.json
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 |
---|---|---|
@@ -1,5 +1,9 @@ | ||
{ | ||
"values": [ | ||
"#forge:is_snowy" | ||
"#forge:is_snowy", | ||
{ | ||
"id": "#c:snowy", | ||
"required": false | ||
} | ||
] | ||
} |
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
94 changes: 94 additions & 0 deletions
94
fabric/src/main/java/com/girafi/waddles/platform/FabricRegistrationFactory.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,94 @@ | ||
package com.girafi.waddles.platform; | ||
|
||
import com.girafi.waddles.registration.RegistrationProvider; | ||
import com.girafi.waddles.registration.RegistryObject; | ||
import net.minecraft.core.Holder; | ||
import net.minecraft.core.Registry; | ||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.resources.ResourceKey; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.function.Supplier; | ||
|
||
public class FabricRegistrationFactory implements RegistrationProvider.Factory { | ||
|
||
@Override | ||
public <T> RegistrationProvider<T> create(ResourceKey<? extends Registry<T>> resourceKey, String modId) { | ||
return new Provider<>(modId, resourceKey); | ||
} | ||
|
||
@Override | ||
public <T> RegistrationProvider<T> create(Registry<T> registry, String modId) { | ||
return new Provider<>(modId, registry); | ||
} | ||
|
||
private static class Provider<T> implements RegistrationProvider<T> { | ||
private final String modId; | ||
private final Registry<T> registry; | ||
|
||
private final Set<RegistryObject<T>> entries = new HashSet<>(); | ||
private final Set<RegistryObject<T>> entriesView = Collections.unmodifiableSet(entries); | ||
|
||
@SuppressWarnings({"unchecked"}) | ||
private Provider(String modId, ResourceKey<? extends Registry<T>> key) { | ||
this.modId = modId; | ||
|
||
final var reg = BuiltInRegistries.REGISTRY.get(key.location()); | ||
if (reg == null) { | ||
throw new RuntimeException("Registry with name " + key.location() + " was not found!"); | ||
} | ||
registry = (Registry<T>) reg; | ||
} | ||
|
||
private Provider(String modId, Registry<T> registry) { | ||
this.modId = modId; | ||
this.registry = registry; | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public <I extends T> RegistryObject<I> register(String name, Supplier<? extends I> supplier) { | ||
final var rl = new ResourceLocation(modId, name); | ||
final var obj = Registry.register(registry, rl, supplier.get()); | ||
final var ro = new RegistryObject<I>() { | ||
final ResourceKey<I> key = ResourceKey.create((ResourceKey<? extends Registry<I>>) registry.key(), rl); | ||
|
||
@Override | ||
public ResourceKey<I> getResourceKey() { | ||
return key; | ||
} | ||
|
||
@Override | ||
public ResourceLocation getId() { | ||
return rl; | ||
} | ||
|
||
@Override | ||
public I get() { | ||
return obj; | ||
} | ||
|
||
@Override | ||
public Holder<I> asHolder() { | ||
return (Holder<I>) registry.getHolderOrThrow((ResourceKey<T>) this.key); | ||
} | ||
}; | ||
entries.add((RegistryObject<T>) ro); | ||
return ro; | ||
} | ||
|
||
@Override | ||
public Collection<RegistryObject<T>> getEntries() { | ||
return entriesView; | ||
} | ||
|
||
@Override | ||
public String getModId() { | ||
return modId; | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
.../resources/META-INF/services/com.girafi.waddles.registration.RegistrationProvider$Factory
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 @@ | ||
com.girafi.waddles.platform.FabricRegistrationFactory |
Oops, something went wrong.