Skip to content

Commit

Permalink
Fix some naming
Browse files Browse the repository at this point in the history
Signed-off-by: TheSilkMiner <thesilkminer@outlook.com>
  • Loading branch information
TheSilkMiner committed Jul 25, 2022
1 parent 990e192 commit 4aa0ded
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import java.util.List;

public interface BulletGameRegistry<T> extends GameRegistry<T> {
public interface DeferredGameRegistry<T> extends GameRegistry<T> {
List<Runnable> commands();

default void doRegistration() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.util.Objects;
import java.util.function.Supplier;

public final class ForgeGameRegistry<T extends IForgeRegistryEntry<T>> implements BulletGameRegistry<T> {
public final class ForgeGameRegistry<T extends IForgeRegistryEntry<T>> implements DeferredGameRegistry<T> {
private static final Map<ObjectType<?>, ForgeGameRegistry<?>> INSTANCES = new HashMap<>();
private static final Supplier<ModContainer> COT_CONTAINER = Suppliers.memoize(() -> ModList.get().getModContainerById(ContentTweakerConstants.MOD_ID).orElseThrow());

Expand Down Expand Up @@ -76,7 +76,7 @@ public List<Runnable> commands() {

@Override
public void doRegistration() {
this.withContainer(BulletGameRegistry.super::doRegistration);
this.withContainer(DeferredGameRegistry.super::doRegistration);
}

private void withContainer(final Runnable runnable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,49 +14,49 @@
import java.util.Objects;

public final class GameRegistryFactory {
private static final Map<ObjectType<?>, BulletGameRegistry<?>> REGISTRY_CACHE = new HashMap<>();
private static final Map<ObjectType<?>, DeferredGameRegistry<?>> REGISTRY_CACHE = new HashMap<>();

private GameRegistryFactory() {}

public static <T, U> BulletGameRegistry<T> findRegistryFromTypeAlone(final ObjectType<T> type) {
public static <T, U> DeferredGameRegistry<T> findRegistryFromTypeAlone(final ObjectType<T> type) {
Objects.requireNonNull(type);
return GenericUtil.uncheck(REGISTRY_CACHE.computeIfAbsent(type, it -> findRegistry(type, type.key())));
}

public static <T> BulletGameRegistry<T> findRegistryFromKey(final ObjectType<T> type, final ResourceKey<? extends Registry<T>> key) {
public static <T> DeferredGameRegistry<T> findRegistryFromKey(final ObjectType<T> type, final ResourceKey<? extends Registry<T>> key) {
Objects.requireNonNull(type);
Objects.requireNonNull(key);
return GenericUtil.uncheck(REGISTRY_CACHE.computeIfAbsent(type, it -> findRegistry(type, key)));
}

private static <T> BulletGameRegistry<T> findRegistry(final ObjectType<T> type, final ResourceKey<? extends Registry<T>> key) {
private static <T> DeferredGameRegistry<T> findRegistry(final ObjectType<T> type, final ResourceKey<? extends Registry<T>> key) {
final ResourceLocation registryId = Objects.requireNonNull(key).location();

// If this is a Forge registry, we need to use it because of Forge shenanigans and to avoid being limited to a slave
// If the registry is not a Forge registry, we can fall back to Vanilla
return Objects.requireNonNullElseGet(findForgeRegistry(type, registryId), () -> findVanillaRegistry(type, registryId));
}

private static <T, U extends IForgeRegistryEntry<U>> BulletGameRegistry<T> findForgeRegistry(final ObjectType<T> type, final ResourceLocation registryId) {
private static <T, U extends IForgeRegistryEntry<U>> DeferredGameRegistry<T> findForgeRegistry(final ObjectType<T> type, final ResourceLocation registryId) {
// Forge wants all types to implement IForgeRegistryEntry, so we need to check that
if (!IForgeRegistryEntry.class.isAssignableFrom(type.type())) {
return null;
}

// The type definitely extends IForgeRegistryEntry now, so we'll perform an unchecked cast and hope for the best
final BulletGameRegistry<U> captured = findForgeRegistryCapturing(GenericUtil.uncheck(type), registryId);
final DeferredGameRegistry<U> captured = findForgeRegistryCapturing(GenericUtil.uncheck(type), registryId);
return captured == null? null : GenericUtil.uncheck(captured);
}

private static <T extends IForgeRegistryEntry<T>> BulletGameRegistry<T> findForgeRegistryCapturing(final ObjectType<T> type, final ResourceLocation registryId) {
private static <T extends IForgeRegistryEntry<T>> DeferredGameRegistry<T> findForgeRegistryCapturing(final ObjectType<T> type, final ResourceLocation registryId) {
final ForgeRegistry<T> registry = RegistryManager.ACTIVE.getRegistry(registryId);
if (registry == null) {
return null;
}
return ForgeGameRegistry.of(type, registry);
}

private static <T> BulletGameRegistry<T> findVanillaRegistry(final ObjectType<T> type, final ResourceLocation registryId) {
private static <T> DeferredGameRegistry<T> findVanillaRegistry(final ObjectType<T> type, final ResourceLocation registryId) {
final Registry<T> registry = GenericUtil.uncheck(Registry.REGISTRY.get(registryId));
return VanillaGameRegistry.of(type, registry);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.util.function.Supplier;
import java.util.stream.Stream;

public final class VanillaGameRegistry<T> implements BulletGameRegistry<T> {
public final class VanillaGameRegistry<T> implements DeferredGameRegistry<T> {
private static final Map<ObjectType<?>, VanillaGameRegistry<?>> INSTANCES = new HashMap<>();

private final Registry<T> registry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected record GenerateFlags(boolean generateLootTable, boolean generateBlockI

// Compare with equality
private static final ResourceLocation DO_NOT_CLONE_DROPS = ContentTweakerConstants.rl("do_not_clone_drops");
private static final ResourceLocation DO_NOT_DROP_SHIT = ContentTweakerConstants.rl("do_not_drop_shit");
private static final ResourceLocation DO_NOT_DROP_DROPS = ContentTweakerConstants.rl("do_not_drop_drops");

private final BiFunction<ObjectHolder<? extends Block>, Consumer<ResourceManager>, BlockReference> registrationManager;

Expand Down Expand Up @@ -234,7 +234,7 @@ public T dropsLike(final BlockReference reference) {

@ZenCodeType.Method("noDrops")
public T noDrops() {
return this.dropsFrom(DO_NOT_DROP_SHIT);
return this.dropsFrom(DO_NOT_DROP_DROPS);
}

@ZenCodeType.Method("dropsNormally")
Expand Down Expand Up @@ -457,7 +457,7 @@ private BlockBehaviour.Properties make(
properties.jumpFactor(jump);
}
if (drops != null && drops != DO_NOT_CLONE_DROPS) {
if (drops == DO_NOT_DROP_SHIT) {
if (drops == DO_NOT_DROP_DROPS) {
properties.noDrops();
} else {
// Ugly, but you can only drop like another block, not a custom RL
Expand Down

0 comments on commit 4aa0ded

Please sign in to comment.