Skip to content

Commit

Permalink
Merge fixes I
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Sep 22, 2024
1 parent 04ef4d5 commit 5982b79
Show file tree
Hide file tree
Showing 37 changed files with 420 additions and 1,124 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies {
modImplementation("net.fabricmc.fabric-api:fabric-api:${project.fabric_version}")
modApi(include(fabricApi.module("fabric-data-generation-api-v1", project.fabric_version))) // include datagen api
modApi(include("io.github.fabricators_of_create.Porting-Lib:tags:${project.porting_lib_version}")) { exclude(group: "io.vram") }
//modApi(include("io.github.fabricators_of_create.Porting-Lib:model_generators:${project.porting_lib_version}")) { exclude(group: "io.vram") }
modApi(include("io.github.fabricators_of_create.Porting-Lib:models:${project.porting_lib_version}")) { exclude(group: "io.vram") }
modApi(include("io.github.fabricators_of_create.Porting-Lib:data:${project.porting_lib_version}")) { exclude(group: "io.vram") }

compileOnly("org.projectlombok:lombok:1.18.22")
Expand Down
430 changes: 50 additions & 380 deletions src/main/java/com/tterrag/registrate/AbstractRegistrate.java

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions src/main/java/com/tterrag/registrate/Registrate.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package com.tterrag.registrate;

import lombok.extern.log4j.Log4j2;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.ModList;

import java.util.Optional;

@Log4j2
public class Registrate extends AbstractRegistrate<Registrate> {
Expand Down
14 changes: 2 additions & 12 deletions src/main/java/com/tterrag/registrate/builders/AbstractBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.tterrag.registrate.AbstractRegistrate;
import com.tterrag.registrate.fabric.RegistryObject;
import com.tterrag.registrate.fabric.RegistryUtil;
import com.tterrag.registrate.fabric.DeferredHolder;
import com.tterrag.registrate.providers.ProviderType;
import com.tterrag.registrate.providers.RegistrateLangProvider;
import com.tterrag.registrate.providers.RegistrateTagsProvider;
Expand All @@ -22,13 +21,10 @@
import net.minecraft.data.tags.TagsProvider;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagEntry;
import net.minecraft.tags.TagKey;

import java.util.Arrays;

import java.util.Arrays;

/**
* Base class which most builders should extend, instead of implementing [@link {@link Builder} directly.
* <p>
Expand Down Expand Up @@ -104,7 +100,7 @@ public final <TP extends TagsProvider<R> & RegistrateTagsProvider<R>> S tag(Prov
setData(type, (ctx, prov) -> tagsByType.get(type).stream()
.map(t -> (TagKey<R>) t)
.map(prov::addTag)
.forEach(b -> b.add(asTag())));
.forEach(b -> b.add(ResourceKey.create(getRegistryKey(), ResourceLocation.fromNamespaceAndPath(getOwner().getModid(), getName())))));
}
tagsByType.putAll(type, Arrays.asList(tags));
return (S) this;
Expand All @@ -119,12 +115,6 @@ public S asOptional(){
return (S) this;
}

protected TagEntry asTag() {
ResourceLocation id = ResourceLocation.fromNamespaceAndPath(getOwner().getModid(), getName());
if (isOptional) return TagEntry.optionalElement(id);
return TagEntry.element(id);
}

/**
* Remove a tag (or tags) from this entry of a given type. Useful to remove default tags on fluids, for example. Multiple calls will remove additional tags.
*
Expand Down
34 changes: 3 additions & 31 deletions src/main/java/com/tterrag/registrate/builders/BlockBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@
import com.google.gson.JsonElement;
import com.tterrag.registrate.AbstractRegistrate;
import com.tterrag.registrate.builders.BlockEntityBuilder.BlockEntityFactory;
import com.tterrag.registrate.fabric.DeferredHolder;
import com.tterrag.registrate.fabric.EnvExecutor;
import com.tterrag.registrate.fabric.RegistryObject;
import com.tterrag.registrate.providers.*;
import com.tterrag.registrate.providers.loot.RegistrateBlockLootTables;
import com.tterrag.registrate.providers.loot.RegistrateLootTableProvider.LootType;
import com.tterrag.registrate.util.RegistrateDistExecutor;
import com.tterrag.registrate.util.entry.BlockEntry;
import com.tterrag.registrate.util.entry.RegistryEntry;
import com.tterrag.registrate.util.nullness.*;
import io.github.fabricators_of_create.porting_lib.models.generators.block.BlockStateProvider;
import io.github.fabricators_of_create.porting_lib.models.generators.BlockStateProvider;
import net.fabricmc.api.EnvType;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry;
import net.minecraft.client.color.block.BlockColor;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
Expand Down Expand Up @@ -315,33 +314,6 @@ public BlockBuilder<T, P> recipe(NonNullBiConsumer<DataGenContext<Block, T>, Reg
return setData(ProviderType.RECIPE, cons);
}

@Nullable
private NonNullSupplier<Supplier<IClientBlockExtensions>> clientExtension;

/**
* Register a client extension for this block. The {@link IClientBlockExtensions} instance can be shared across many items.
*
* @param clientExtension
* The client extension to register for this block
* @return this {@link BlockBuilder}
*/
public BlockBuilder<T, P> clientExtension(NonNullSupplier<Supplier<IClientBlockExtensions>> clientExtension) {
if (this.clientExtension == null) {
RegistrateDistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> this::registerClientExtension);
}
this.clientExtension = clientExtension;
return this;
}

protected void registerClientExtension() {
OneTimeEventReceiver.addModListener(getOwner(), RegisterClientExtensionsEvent.class, e -> {
NonNullSupplier<Supplier<IClientBlockExtensions>> clientExtension = this.clientExtension;
if (clientExtension != null) {
e.registerBlock(clientExtension.get().get(), getEntry());
}
});
}

/**
* Assign {@link TagKey}{@code s} to this block. Multiple calls will add additional tags.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@
import java.util.HashSet;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier;

import com.tterrag.registrate.AbstractRegistrate;
import com.tterrag.registrate.fabric.DeferredHolder;
import com.tterrag.registrate.fabric.EnvExecutor;
import com.tterrag.registrate.fabric.RegistryObject;
import com.tterrag.registrate.mixin.accessor.BlockEntityRenderersAccessor;
import com.tterrag.registrate.util.RegistrateDistExecutor;
import com.tterrag.registrate.util.entry.BlockEntityEntry;
import com.tterrag.registrate.util.entry.RegistryEntry;
import com.tterrag.registrate.util.nullness.NonNullFunction;
import com.tterrag.registrate.util.nullness.NonNullSupplier;
import net.fabricmc.api.EnvType;
import net.minecraft.core.Registry;
import org.jetbrains.annotations.Nullable;

import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
Expand Down
13 changes: 1 addition & 12 deletions src/main/java/com/tterrag/registrate/builders/Builder.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import java.util.function.Function;

import com.tterrag.registrate.AbstractRegistrate;
import com.tterrag.registrate.fabric.RegistryObject;
import com.tterrag.registrate.fabric.RegistryUtil;
import com.tterrag.registrate.providers.DataGenContext;
import com.tterrag.registrate.providers.ProviderType;
import com.tterrag.registrate.providers.RegistrateProvider;
Expand Down Expand Up @@ -137,15 +135,6 @@ default <D extends RegistrateProvider> S addMiscData(ProviderType<? extends D> t
return (S) this;
}

/**
* Add data map associated with this builder
*/
default <D> S dataMap(DataMapType<R, D> type, D val) {
getOwner().addDataGenerator(ProviderType.DATA_MAP, e -> e.builder(type)
.add(DataGenContext.from(this).getId(), val, false));
return (S) this;
}

/**
* Add a callback to be invoked when this entry is registered. Can be called multiple times to add multiple callbacks.
* <p>
Expand Down Expand Up @@ -216,7 +205,7 @@ default <R2, T2 extends R2, P2, S2 extends Builder<R2, T2, P2, S2>> S2 transform
}

/**
* Register the entry and return the parent object. The {@link net.neoforged.neoforge.registries.DeferredHolder} will be created but not returned. It can be retrieved later with {@link AbstractRegistrate#get(ResourceKey)} or
* Register the entry and return the parent object. The {@link com.tterrag.registrate.fabric.DeferredHolder} will be created but not returned. It can be retrieved later with {@link AbstractRegistrate#get(ResourceKey)} or
* {@link AbstractRegistrate#get(String, ResourceKey)}.
*
* @return the parent object
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.tterrag.registrate.builders;

import com.tterrag.registrate.AbstractRegistrate;
import com.tterrag.registrate.fabric.RegistryObject;
import com.tterrag.registrate.fabric.RegistryUtil;
import com.tterrag.registrate.fabric.DeferredHolder;
import com.tterrag.registrate.util.entry.RegistryEntry;
import com.tterrag.registrate.util.nullness.NonNullFunction;
import com.tterrag.registrate.util.nullness.NonNullSupplier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import java.util.function.Supplier;

import com.tterrag.registrate.AbstractRegistrate;
import com.tterrag.registrate.fabric.DeferredHolder;
import com.tterrag.registrate.fabric.EnvExecutor;
import com.tterrag.registrate.fabric.RegistryObject;
import com.tterrag.registrate.mixin.accessor.SpawnPlacementsAccessor;
import com.tterrag.registrate.providers.DataGenContext;
import com.tterrag.registrate.providers.ProviderType;
Expand Down Expand Up @@ -169,7 +169,7 @@ public EntityBuilder<T, P> attributes(Supplier<AttributeSupplier.Builder> attrib
* When called more than once
*/
@SuppressWarnings("unchecked")
public EntityBuilder<T, P> spawnPlacement(SpawnPlacementType type, Heightmap.Types heightmap, SpawnPredicate<T> predicate, RegisterSpawnPlacementsEvent.Operation operation) {
public EntityBuilder<T, P> spawnPlacement(SpawnPlacementType type, Heightmap.Types heightmap, SpawnPredicate<T> predicate) {
if (spawnConfigured) {
throw new IllegalStateException("Cannot configure spawn placement more than once");
}
Expand Down Expand Up @@ -223,8 +223,7 @@ public EntityBuilder<T, P> defaultSpawnEgg(int primaryColor, int secondaryColor)
@SuppressWarnings({"unchecked" })
@Deprecated
public ItemBuilder<? extends SpawnEggItem, EntityBuilder<T, P>> spawnEgg(int primaryColor, int secondaryColor) {
var sup = asSupplier();
return getOwner().item(this, getName() + "_spawn_egg", p -> new DeferredSpawnEggItem((Supplier<EntityType<? extends Mob>>) (Supplier) sup, primaryColor, secondaryColor, p)).tab(CreativeModeTabs.SPAWN_EGGS)
return getOwner().item(this, getName() + "_spawn_egg", p -> new SpawnEggItem((EntityType<? extends Mob>) get().get(), primaryColor, secondaryColor, p)).tab(CreativeModeTabs.SPAWN_EGGS)
.model((ctx, prov) -> prov.withExistingParent(ctx.getName(), ResourceLocation.withDefaultNamespace("item/template_spawn_egg")));
}

Expand Down
Loading

0 comments on commit 5982b79

Please sign in to comment.