From d189efd987ac3f0945dd476b8492d97134d23d07 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Wed, 23 Jun 2021 00:16:24 -0700 Subject: [PATCH] Whoops missed some classes --- .../foundation/data/CreateEntityBuilder.java | 57 +++++++++++++++++++ .../render/RainbowDebugStateProvider.java | 27 +++++++++ 2 files changed, 84 insertions(+) create mode 100644 src/main/java/com/simibubi/create/foundation/data/CreateEntityBuilder.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/RainbowDebugStateProvider.java diff --git a/src/main/java/com/simibubi/create/foundation/data/CreateEntityBuilder.java b/src/main/java/com/simibubi/create/foundation/data/CreateEntityBuilder.java new file mode 100644 index 000000000..1cd900123 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/data/CreateEntityBuilder.java @@ -0,0 +1,57 @@ +package com.simibubi.create.foundation.data; + +import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry; +import com.jozufozu.flywheel.backend.instancing.entity.IEntityInstanceFactory; +import com.jozufozu.flywheel.backend.instancing.tile.ITileInstanceFactory; +import com.tterrag.registrate.AbstractRegistrate; +import com.tterrag.registrate.builders.BuilderCallback; +import com.tterrag.registrate.builders.EntityBuilder; + +import com.tterrag.registrate.util.OneTimeEventReceiver; +import com.tterrag.registrate.util.nullness.NonNullSupplier; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityClassification; +import net.minecraft.entity.EntityType; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; +import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; + +import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; + +@ParametersAreNonnullByDefault +public class CreateEntityBuilder extends EntityBuilder { + + @Nullable + private NonNullSupplier> instanceFactory; + + public static EntityBuilder create(AbstractRegistrate owner, P parent, String name, BuilderCallback callback, EntityType.IFactory factory, EntityClassification classification) { + return (new CreateEntityBuilder<>(owner, parent, name, callback, factory, classification)).defaultLang(); + } + + public CreateEntityBuilder(AbstractRegistrate owner, P parent, String name, BuilderCallback callback, EntityType.IFactory factory, EntityClassification classification) { + super(owner, parent, name, callback, factory, classification); + } + + public CreateEntityBuilder instance(NonNullSupplier> instanceFactory) { + if (this.instanceFactory == null) { + DistExecutor.runWhenOn(Dist.CLIENT, () -> this::registerInstance); + } + + this.instanceFactory = instanceFactory; + + return this; + } + + protected void registerInstance() { + OneTimeEventReceiver.addModListener(FMLClientSetupEvent.class, $ -> { + NonNullSupplier> instanceFactory = this.instanceFactory; + if (instanceFactory != null) { + InstancedRenderRegistry.getInstance().register(getEntry(), instanceFactory.get()); + } + + }); + } + +} diff --git a/src/main/java/com/simibubi/create/foundation/render/RainbowDebugStateProvider.java b/src/main/java/com/simibubi/create/foundation/render/RainbowDebugStateProvider.java new file mode 100644 index 000000000..59aa3eb15 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/RainbowDebugStateProvider.java @@ -0,0 +1,27 @@ +package com.simibubi.create.foundation.render; + +import com.jozufozu.flywheel.core.shader.spec.IBooleanStateProvider; +import com.simibubi.create.Create; +import com.simibubi.create.content.contraptions.KineticDebugger; + +import net.minecraft.util.ResourceLocation; + +public class RainbowDebugStateProvider implements IBooleanStateProvider { + + public static final RainbowDebugStateProvider INSTANCE = new RainbowDebugStateProvider(); + public static final ResourceLocation NAME = new ResourceLocation(Create.ID, "rainbow_debug"); + + protected RainbowDebugStateProvider() { + + } + + @Override + public boolean isTrue() { + return KineticDebugger.isActive(); + } + + @Override + public ResourceLocation getID() { + return NAME; + } +}