Skip to content

Commit

Permalink
Updated to 1.21.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucraft committed Sep 23, 2024
1 parent cb678fd commit 66454ce
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
package net.threetag.palladiumcore.registry;

import dev.architectury.injectables.annotations.ExpectPlatform;
import net.minecraft.core.HolderLookup;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.resources.PreparableReloadListener;

import java.util.function.Function;

public class ReloadListenerRegistry {

@ExpectPlatform
public static void register(PackType packType, ResourceLocation id, PreparableReloadListener listener) {
public static void registerClientListener(ResourceLocation id, PreparableReloadListener listener) {
throw new AssertionError();
}

@ExpectPlatform
public static void registerServerListener(ResourceLocation id, Function<HolderLookup.Provider, PreparableReloadListener> listener) {
throw new AssertionError();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.minecraft.core.HolderLookup;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.resources.PreparableReloadListener;
Expand All @@ -10,26 +11,36 @@

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.function.Function;

public class ReloadListenerRegistryImpl {

public static void register(PackType packType, ResourceLocation id, PreparableReloadListener listener) {
ResourceManagerHelper.get(packType).registerReloadListener(new IdentifiableResourceReloadListener() {
@Override
public static void registerClientListener(ResourceLocation id, PreparableReloadListener listener) {
var fabricListener = new Wrapper(id, listener);
ResourceManagerHelper.get(PackType.CLIENT_RESOURCES).registerReloadListener(fabricListener);
}

public static void registerServerListener(ResourceLocation id, Function<HolderLookup.Provider, PreparableReloadListener> listener) {
ResourceManagerHelper.get(PackType.SERVER_DATA).registerReloadListener(id, provider -> new Wrapper(id, listener.apply(provider)));
}

private record Wrapper(ResourceLocation id,
PreparableReloadListener listener) implements IdentifiableResourceReloadListener {

@Override
public ResourceLocation getFabricId() {
return id;
return this.id;
}

@Override
public String getName() {
return listener.getName();
return this.listener.getName();
}

@Override
public CompletableFuture<Void> reload(PreparationBarrier preparationBarrier, ResourceManager resourceManager, ProfilerFiller profilerFiller, ProfilerFiller profilerFiller2, Executor executor, Executor executor2) {
return listener.reload(preparationBarrier, resourceManager, profilerFiller, profilerFiller2, executor, executor2);
public CompletableFuture<Void> reload(PreparationBarrier preparationBarrier, ResourceManager resourceManager, ProfilerFiller preparationsProfiler, ProfilerFiller reloadProfiler, Executor backgroundExecutor, Executor gameExecutor) {
return listener.reload(preparationBarrier, resourceManager, preparationsProfiler, reloadProfiler, backgroundExecutor, gameExecutor);
}
});
}
}

}
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
org.gradle.jvmargs=-Xmx2048M

# MC/Arch Settings
minecraft_version=1.21
minecraft_version=1.21.1
enabled_platforms=fabric,neoforge
mappings=1.21:2024.06.23

Expand All @@ -13,11 +13,11 @@ mod_author=Lucraft
maven_group=net.threetag

# Common Dependencies
architectury_version=13.0.1
architectury_version=13.0.6

# Fabric Dependencies
fabric_loader_version=0.15.11
fabric_api_version=0.100.3+1.21
fabric_loader_version=0.16.5
fabric_api_version=0.104.0+1.21.1

# Forge Dependencies
neoforge_version=21.0.31-beta
neoforge_version=21.1.58
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Supplier;

Expand Down Expand Up @@ -52,19 +53,19 @@ private record ItemGroupEntriesWrapper(
public ItemStack findLast(ItemLike itemLike) {
ItemStack stack = null;

for (Map.Entry<ItemStack, CreativeModeTab.TabVisibility> entry : this.e.getEntries()) {
if (entry.getKey().is(itemLike.asItem())) {
stack = entry.getKey();
for (ItemStack entry : this.e.getParentEntries()) {
if (entry.is(itemLike.asItem())) {
stack = entry;
}
}

return stack;
}

public ItemStack findFirst(ItemLike itemLike) {
for (Map.Entry<ItemStack, CreativeModeTab.TabVisibility> entry : this.e.getEntries()) {
if (entry.getKey().is(itemLike.asItem())) {
return entry.getKey();
for (ItemStack entry : this.e.getParentEntries()) {
if (entry.is(itemLike.asItem())) {
return entry;
}
}
return null;
Expand Down Expand Up @@ -92,7 +93,7 @@ public void addAfter(ItemLike afterLast, ItemLike... item) {
@Override
public void addAfter(ItemLike afterLast, CreativeModeTab.TabVisibility visibility, ItemLike... item) {
for (ItemLike itemLike : Lists.reverse(Arrays.asList(item))) {
this.e.getEntries().putAfter(findLast(afterLast), itemLike.asItem().getDefaultInstance(), visibility);
this.e.insertAfter(findLast(afterLast), itemLike.asItem().getDefaultInstance(), visibility);
}
}

Expand All @@ -104,7 +105,7 @@ public void addBefore(ItemLike beforeFirst, ItemLike... item) {
@Override
public void addBefore(ItemLike beforeFirst, CreativeModeTab.TabVisibility visibility, ItemLike... item) {
for (ItemLike itemLike : item) {
this.e.getEntries().putBefore(findFirst(beforeFirst), itemLike.asItem().getDefaultInstance(), visibility);
this.e.insertBefore(Objects.requireNonNull(findFirst(beforeFirst)), itemLike.asItem().getDefaultInstance(), visibility);
}
}

Expand All @@ -130,7 +131,7 @@ public void addAfter(ItemLike afterLast, ItemStack... item) {
@Override
public void addAfter(ItemLike afterLast, CreativeModeTab.TabVisibility visibility, ItemStack... item) {
for (ItemStack stack : Lists.reverse(Arrays.asList(item))) {
this.e.getEntries().putAfter(findLast(afterLast), stack, visibility);
this.e.insertAfter(findLast(afterLast), stack, visibility);
}
}

Expand All @@ -142,7 +143,7 @@ public void addBefore(ItemLike beforeFirst, ItemStack... item) {
@Override
public void addBefore(ItemLike beforeFirst, CreativeModeTab.TabVisibility visibility, ItemStack... item) {
for (ItemStack stack : item) {
this.e.getEntries().putBefore(findFirst(beforeFirst), stack, visibility);
this.e.insertBefore(Objects.requireNonNull(findFirst(beforeFirst)), stack, visibility);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
package net.threetag.palladiumcore.registry.neoforge;

import net.minecraft.core.HolderLookup;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.resources.PreparableReloadListener;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.client.event.RegisterClientReloadListenersEvent;
import net.neoforged.neoforge.event.AddReloadListenerEvent;
import net.threetag.palladiumcore.PalladiumCore;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

@EventBusSubscriber(modid = PalladiumCore.MOD_ID, bus = EventBusSubscriber.Bus.GAME)
public class ReloadListenerRegistryImpl {

private static final List<PreparableReloadListener> SERVER_LISTENERS = new ArrayList<>();
private static final List<Function<HolderLookup.Provider, PreparableReloadListener>> SERVER_LISTENERS = new ArrayList<>();
private static final List<PreparableReloadListener> CLIENT_LISTENERS = new ArrayList<>();

public static void register(PackType type, ResourceLocation id, PreparableReloadListener listener) {
if (type == PackType.SERVER_DATA) {
SERVER_LISTENERS.add(listener);
} else if (type == PackType.CLIENT_RESOURCES) {
CLIENT_LISTENERS.add(listener);
}
public static void registerClientListener(ResourceLocation id, PreparableReloadListener listener) {
CLIENT_LISTENERS.add(listener);
}

public static void registerServerListener(ResourceLocation id, Function<HolderLookup.Provider, PreparableReloadListener> listener) {
SERVER_LISTENERS.add(listener);
}

@SubscribeEvent
public static void addReloadListeners(AddReloadListenerEvent e) {
for (PreparableReloadListener listener : SERVER_LISTENERS) {
e.addListener(listener);
for (Function<HolderLookup.Provider, PreparableReloadListener> listener : SERVER_LISTENERS) {
e.addListener(listener.apply(e.getRegistryAccess()));
}
}

Expand Down

0 comments on commit 66454ce

Please sign in to comment.