Skip to content

Commit

Permalink
🌟 更新注册 API
Browse files Browse the repository at this point in the history
  • Loading branch information
Gu-ZT committed Aug 31, 2024
1 parent eed3236 commit 24cf9a3
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraft.world.level.block.state.BlockBehaviour;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand All @@ -25,7 +26,7 @@
@SuppressWarnings("unused")
public abstract class AbstractRegistrator {
protected final BuilderManager manager = new BuilderManager();
protected final Map<DataProviderType<?>, Consumer<? extends DataProvider>> dataProviders = Collections.synchronizedMap(new HashMap<>());
protected final Map<DataProviderType<?>, List<Consumer<? extends DataProvider>>> dataProviders = Collections.synchronizedMap(new HashMap<>());
private final String modid;

protected AbstractRegistrator(String modid) {
Expand Down Expand Up @@ -61,12 +62,19 @@ public <T extends Block> BlockBuilder<T> block(String id, Function<BlockBehaviou
}

public <P extends DataProvider> void data(DataProviderType<P> type, Consumer<P> consumer) {
this.dataProviders.put(type, consumer);
List<Consumer<? extends DataProvider>> list = this.dataProviders.getOrDefault(type, Collections.synchronizedList(new ArrayList<>()));
list.add(consumer);
this.dataProviders.put(type, list);
}

public void init() {
}

@SuppressWarnings("unchecked")
protected <P extends DataProvider> List<Consumer<P>> getDataProviders(DataProviderType<P> type) {
return (List<Consumer<P>>) (List<?>) this.dataProviders.getOrDefault(type, Collections.emptyList());
}

@SuppressWarnings("UnusedReturnValue")
public <T extends DataProvider> AbstractRegistrator initDatagen(DataGenerator generator) {
return this;
Expand Down

0 comments on commit 24cf9a3

Please sign in to comment.