Skip to content

Commit

Permalink
Tidy up internal API and optimise imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Rover656 committed Sep 24, 2024
1 parent 7d3d5c4 commit 9ddc27b
Show file tree
Hide file tree
Showing 16 changed files with 21 additions and 51 deletions.
8 changes: 4 additions & 4 deletions src/main/java/com/enderio/regilite/Regilite.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
package com.enderio.regilite;

import com.enderio.regilite.blockentities.RegiliteBlockEntities;
import com.enderio.regilite.fluids.RegiliteFluidTypes;
import com.enderio.regilite.utils.BundledDataProvider;
import com.enderio.regilite.blocks.RegiliteBlocks;
import com.enderio.regilite.data.RegiliteDataProvider;
import com.enderio.regilite.events.EntityRendererEvents;
import com.enderio.regilite.events.ScreenEvents;
import com.enderio.regilite.blocks.RegiliteBlocks;
import com.enderio.regilite.fluids.RegiliteFluidTypes;
import com.enderio.regilite.items.RegiliteItems;
import com.enderio.regilite.lang.RegiliteLang;
import com.enderio.regilite.loot.RegiliteLootTables;
import com.enderio.regilite.tags.RegiliteTags;
import com.enderio.regilite.registry.EntityRegistry;
import com.enderio.regilite.registry.MenuRegistry;
import com.enderio.regilite.tags.RegiliteTags;
import com.enderio.regilite.utils.BundledDataProvider;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import it.unimi.dsi.fastutil.objects.ObjectList;
import net.minecraft.world.entity.EntityType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.enderio.regilite.Regilite;
import com.enderio.regilite.RegiliteModuleEvents;
import com.enderio.regilite.RegiliteRegistryModule;
import com.enderio.regilite.blocks.RegiliteBlocks;
import com.enderio.regilite.tags.RegiliteTags;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import it.unimi.dsi.fastutil.objects.ObjectList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.neoforge.client.event.EntityRenderersEvent;

public class RegiliteClientBlockEntities {
class RegiliteClientBlockEntities {
private final RegiliteBlockEntities regiliteBlockEntities;

public RegiliteClientBlockEntities(RegiliteBlockEntities regiliteBlockEntities) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent;
import net.neoforged.neoforge.client.model.generators.BlockStateProvider;
import net.neoforged.neoforge.registries.DeferredBlock;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@

import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.neoforge.client.event.RegisterColorHandlersEvent;
import org.jetbrains.annotations.ApiStatus;

@ApiStatus.Internal
public class RegiliteClientBlocks {
class RegiliteClientBlocks {
private final RegiliteBlocks regiliteBlocks;

public RegiliteClientBlocks(RegiliteBlocks regiliteBlocks) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

public class NewRegiliteDataProvider implements DataProvider {
private final String modId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
import net.neoforged.neoforge.common.data.ExistingFileHelper;
import net.neoforged.neoforge.data.event.GatherDataEvent;

import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
import net.minecraft.data.tags.IntrinsicHolderTagsProvider;
import net.minecraft.resources.ResourceKey;
import net.minecraft.tags.TagKey;
import net.minecraft.world.level.material.Fluid;
import net.neoforged.neoforge.common.data.ExistingFileHelper;
import net.neoforged.neoforge.fluids.FluidType;
import net.neoforged.neoforge.registries.DeferredHolder;
import org.jetbrains.annotations.Nullable;

Expand Down
9 changes: 1 addition & 8 deletions src/main/java/com/enderio/regilite/items/ItemBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import net.neoforged.neoforge.capabilities.ItemCapability;
import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent;
import net.neoforged.neoforge.registries.DeferredItem;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
Expand Down Expand Up @@ -90,11 +89,6 @@ public final ItemBuilder<T> tab(ResourceKey<CreativeModeTab> tab, Consumer<Creat
return this;
}

@ApiStatus.Internal
public Object2ObjectMap<ResourceKey<CreativeModeTab>, Consumer<CreativeModeTab.Output>> tabs() {
return tabs;
}

public ItemBuilder<T> modelProvider(BiConsumer<RegiliteItemModelProvider, DataGenContext<Item, T>> modelProvider) {
this.modelProvider = modelProvider;
return this;
Expand All @@ -110,8 +104,7 @@ public <TCap, TContext> ItemBuilder<T> capability(ItemCapability<TCap, TContext>
return this;
}

@ApiStatus.Internal
public void attachCapabilities(RegisterCapabilitiesEvent event) {
void attachCapabilities(RegisterCapabilitiesEvent event) {
for (var attachedCapability : attachedCapabilityList) {
attachedCapability.registerProvider(event, get());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@

package com.enderio.regilite.items;

import com.enderio.regilite.blocks.RegiliteBlocks;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.neoforge.client.event.RegisterColorHandlersEvent;
import org.jetbrains.annotations.ApiStatus;

@ApiStatus.Internal
public class RegiliteClientItems {
class RegiliteClientItems {
private final RegiliteItems regiliteItems;

public RegiliteClientItems(RegiliteItems regiliteItems) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import net.neoforged.neoforge.common.data.ExistingFileHelper;
import net.neoforged.neoforge.internal.versions.neoforge.NeoForgeVersion;

import java.util.List;
import java.util.Objects;

public class RegiliteItemModelProvider extends ItemModelProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void register(IEventBus modEventBus) {

private void onBuildCreativeTabs(BuildCreativeModeTabContentsEvent event) {
for (var item : items) {
var outputConsumer = item.tabs().get(event.getTabKey());
var outputConsumer = item.tabs.get(event.getTabKey());
if (outputConsumer != null) {
outputConsumer.accept(event);
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/enderio/regilite/lang/RegiliteLang.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.material.Fluid;
import net.neoforged.neoforge.common.data.LanguageProvider;
import net.neoforged.neoforge.data.event.GatherDataEvent;
import net.neoforged.neoforge.fluids.FluidType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// I don't think rich loot table support is something we need to provide, given I think its expressive enough in vanilla.
public class RegiliteLootTables implements RegiliteModuleDataGen {

private ObjectList<Supplier<LootTableProvider.SubProviderEntry>> providerFactories = new ObjectArrayList<>();
private final ObjectList<Supplier<LootTableProvider.SubProviderEntry>> providerFactories = new ObjectArrayList<>();

@ApiStatus.Internal
public RegiliteLootTables() {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/enderio/regilite/tags/RegiliteTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,16 @@ public void gatherProviders(GatherDataEvent event, Consumer<DataProvider> addPro

private class TagProvider<T> extends IntrinsicHolderTagsProvider<T> {

private final RegistryTagBuilder<T> tags;
private final RegistryTagBuilder<T> tagBuilder;

public TagProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> lookupProvider, String modId, @Nullable ExistingFileHelper existingFileHelper, RegistryTagBuilder<T> tags) {
super(output, tags.registry(), lookupProvider, tags::getKey, modId, existingFileHelper);
this.tags = tags;
public TagProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> lookupProvider, String modId, @Nullable ExistingFileHelper existingFileHelper, RegistryTagBuilder<T> tagBuilder) {
super(output, tagBuilder.registry(), lookupProvider, tagBuilder.keyExtractor, modId, existingFileHelper);
this.tagBuilder = tagBuilder;
}

@Override
protected void addTags(HolderLookup.Provider provider) {
for (var pair : tags.entrySet()) {
for (var pair : tagBuilder.tags.entrySet()) {
//noinspection unchecked
T[] items = (T[])pair.getValue().entries().map(Supplier::get).toArray();
tag(pair.getKey()).add(items);
Expand Down
18 changes: 2 additions & 16 deletions src/main/java/com/enderio/regilite/tags/RegistryTagBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,17 @@

import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectSet;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.tags.TagKey;
import org.jetbrains.annotations.ApiStatus;

import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;

public final class RegistryTagBuilder<T> {
private final ResourceKey<Registry<T>> registryKey;
private final Function<T, ResourceKey<T>> keyExtractor;
private final Object2ObjectMap<TagKey<T>, TagBuilder<T>> tags = new Object2ObjectOpenHashMap<>();
final Function<T, ResourceKey<T>> keyExtractor;
final Object2ObjectMap<TagKey<T>, TagBuilder<T>> tags = new Object2ObjectOpenHashMap<>();

public RegistryTagBuilder(ResourceKey<Registry<T>> registryKey, Function<T, ResourceKey<T>> keyExtractor) {
this.registryKey = registryKey;
Expand All @@ -41,15 +38,4 @@ public final void addToTags(Supplier<? extends T> entry, TagKey<T>... tags) {
tag(tag).add(entry);
}
}

@ApiStatus.Internal
public ObjectSet<Map.Entry<TagKey<T>, TagBuilder<T>>> entrySet() {
return tags.entrySet();
}

// Even though its internal only, feels nicer to expose it as a method instead of a getter for the func.
@ApiStatus.Internal
public ResourceKey<T> getKey(T value) {
return keyExtractor.apply(value);
}
}

0 comments on commit 9ddc27b

Please sign in to comment.