Merge pull request #3031 from patryk3211/curios-compatibility

Curios integration
This commit is contained in:
simibubi 2022-05-22 16:33:11 +02:00 committed by GitHub
commit ee33823ed0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 159 additions and 1 deletions

View file

@ -135,6 +135,10 @@ repositories {
//location of the maven for dynamic trees //location of the maven for dynamic trees
url 'https://harleyoconnor.com/maven' url 'https://harleyoconnor.com/maven'
} }
maven {
//location of the maven for curios api
url = "https://maven.theillusivec4.top/"
}
} }
configurations { configurations {
@ -157,6 +161,9 @@ dependencies {
compileOnly fg.deobf("mezz.jei:jei-${jei_minecraft_version}:${jei_version}:api") compileOnly fg.deobf("mezz.jei:jei-${jei_minecraft_version}:${jei_version}:api")
runtimeOnly fg.deobf("mezz.jei:jei-${jei_minecraft_version}:${jei_version}") runtimeOnly fg.deobf("mezz.jei:jei-${jei_minecraft_version}:${jei_version}")
compileOnly fg.deobf("top.theillusivec4.curios:curios-forge:${curios_minecraft_version}-${curios_version}:api")
runtimeOnly fg.deobf("top.theillusivec4.curios:curios-forge:${curios_minecraft_version}-${curios_version}")
// implementation fg.deobf("curse.maven:druidcraft-340991:3101903") // implementation fg.deobf("curse.maven:druidcraft-340991:3101903")
// implementation fg.deobf("com.ferreusveritas.dynamictrees:DynamicTrees-1.16.5:0.10.0-Beta25") // implementation fg.deobf("com.ferreusveritas.dynamictrees:DynamicTrees-1.16.5:0.10.0-Beta25")
// runtimeOnly fg.deobf("vazkii.arl:AutoRegLib:1.4-35.69") // runtimeOnly fg.deobf("vazkii.arl:AutoRegLib:1.4-35.69")

View file

@ -22,6 +22,8 @@ registrate_version = MC1.18.2-1.0.25
flywheel_version = 1.18-0.7.0.67 flywheel_version = 1.18-0.7.0.67
jei_minecraft_version = 1.18.2 jei_minecraft_version = 1.18.2
jei_version = 9.5.3.143 jei_version = 9.5.3.143
curios_minecraft_version = 1.18.2
curios_version = 5.0.7.0
# curseforge information # curseforge information
projectId = 328085 projectId = 328085

View file

@ -2,6 +2,9 @@ package com.simibubi.create;
import java.util.Random; import java.util.Random;
import com.simibubi.create.compat.Mods;
import com.simibubi.create.compat.curios.Curios;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -119,6 +122,8 @@ public class Create {
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, DistExecutor.unsafeRunWhenOn(Dist.CLIENT,
() -> () -> CreateClient.onCtorClient(modEventBus, forgeEventBus)); () -> () -> CreateClient.onCtorClient(modEventBus, forgeEventBus));
Mods.CURIOS.executeIfInstalled(() -> Curios::init);
} }
public static void init(final FMLCommonSetupEvent event) { public static void init(final FMLCommonSetupEvent event) {

View file

@ -12,7 +12,8 @@ import net.minecraftforge.fml.ModList;
*/ */
public enum Mods { public enum Mods {
DYNAMICTREES, DYNAMICTREES,
TCONSTRUCT; TCONSTRUCT,
CURIOS;
/** /**
* @return a boolean of whether the mod is loaded or not based on mod id * @return a boolean of whether the mod is loaded or not based on mod id

View file

@ -0,0 +1,43 @@
package com.simibubi.create.compat.curios;
import java.util.concurrent.atomic.AtomicBoolean;
import com.simibubi.create.AllItems;
import com.simibubi.create.content.contraptions.goggles.GogglesItem;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.InterModComms;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import top.theillusivec4.curios.api.CuriosCapability;
import top.theillusivec4.curios.api.SlotTypeMessage;
import top.theillusivec4.curios.api.SlotTypePreset;
import top.theillusivec4.curios.api.type.inventory.ICurioStacksHandler;
public class Curios {
public static void init() {
FMLJavaModLoadingContext.get().getModEventBus().addListener(Curios::onInterModEnqueue);
FMLJavaModLoadingContext.get().getModEventBus().addListener(Curios::onClientSetup);
GogglesItem.addIsWearingPredicate(player -> {
AtomicBoolean hasGoggles = new AtomicBoolean(false);
player.getCapability(CuriosCapability.INVENTORY).ifPresent(handler -> {
ICurioStacksHandler stacksHandler = handler.getCurios().get("head");
if(stacksHandler != null) hasGoggles.set(stacksHandler.getStacks().getStackInSlot(0).getItem() == AllItems.GOGGLES.get());
});
return hasGoggles.get();
});
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> FMLJavaModLoadingContext.get().getModEventBus().addListener(CuriosRenderers::onLayerRegister));
}
private static void onInterModEnqueue(final InterModEnqueueEvent event) {
InterModComms.sendTo("curios", SlotTypeMessage.REGISTER_TYPE, () -> SlotTypePreset.HEAD.getMessageBuilder().build());
}
private static void onClientSetup(final FMLClientSetupEvent event) {
CuriosRenderers.register();
}
}

View file

@ -0,0 +1,21 @@
package com.simibubi.create.compat.curios;
import com.simibubi.create.AllItems;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.geom.builders.LayerDefinition;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.event.EntityRenderersEvent;
import top.theillusivec4.curios.api.client.CuriosRendererRegistry;
@OnlyIn(Dist.CLIENT)
public class CuriosRenderers {
public static void register() {
CuriosRendererRegistry.register(AllItems.GOGGLES.get(), () -> new GogglesCurioRenderer(Minecraft.getInstance().getEntityModels().bakeLayer(GogglesCurioRenderer.LAYER)));
}
public static void onLayerRegister(final EntityRenderersEvent.RegisterLayerDefinitions event) {
event.registerLayerDefinition(GogglesCurioRenderer.LAYER, () -> LayerDefinition.create(GogglesCurioRenderer.mesh(), 1, 1));
}
}

View file

@ -0,0 +1,73 @@
package com.simibubi.create.compat.curios;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Vector3f;
import com.simibubi.create.Create;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.EntityModel;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.geom.ModelLayerLocation;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.CubeDeformation;
import net.minecraft.client.model.geom.builders.CubeListBuilder;
import net.minecraft.client.model.geom.builders.MeshDefinition;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.client.renderer.entity.RenderLayerParent;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import top.theillusivec4.curios.api.SlotContext;
import top.theillusivec4.curios.api.client.ICurioRenderer;
@OnlyIn(Dist.CLIENT)
public class GogglesCurioRenderer implements ICurioRenderer {
public static final ModelLayerLocation LAYER = new ModelLayerLocation(new ResourceLocation(Create.ID, "goggles"), "goggles");
private final HumanoidModel<LivingEntity> model;
public GogglesCurioRenderer(ModelPart part) {
this.model = new HumanoidModel<>(part);
}
@Override
public <T extends LivingEntity, M extends EntityModel<T>> void render(ItemStack stack, SlotContext slotContext, PoseStack matrixStack, RenderLayerParent<T, M> renderLayerParent, MultiBufferSource renderTypeBuffer, int light, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch) {
// Prepare values for transformation
model.setupAnim(slotContext.entity(), limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch);
model.prepareMobModel(slotContext.entity(), limbSwing, limbSwingAmount, partialTicks);
ICurioRenderer.followHeadRotations(slotContext.entity(), model.head);
// Translate and rotate with our head
matrixStack.pushPose();
matrixStack.translate(model.head.x / 16.0, model.head.y / 16.0, model.head.z / 16.0);
matrixStack.mulPose(Vector3f.YP.rotation(model.head.yRot));
matrixStack.mulPose(Vector3f.XP.rotation(model.head.xRot));
// Translate and scale to our head
matrixStack.translate(0, -0.25, 0);
matrixStack.mulPose(Vector3f.ZP.rotationDegrees(180.0f));
matrixStack.scale(0.625f, 0.625f, 0.625f);
if(!slotContext.entity().getItemBySlot(EquipmentSlot.HEAD).isEmpty()) {
matrixStack.mulPose(Vector3f.ZP.rotationDegrees(180.0f));
matrixStack.translate(0, -0.25, 0);
}
// Render
Minecraft.getInstance().getItemRenderer().renderStatic(stack, ItemTransforms.TransformType.HEAD, light, OverlayTexture.NO_OVERLAY, matrixStack, renderTypeBuffer, 0);
matrixStack.popPose();
}
public static MeshDefinition mesh() {
CubeListBuilder builder = new CubeListBuilder();
MeshDefinition mesh = HumanoidModel.createMesh(CubeDeformation.NONE, 0);
mesh.getRoot().addOrReplaceChild("head", builder, PartPose.ZERO);
return mesh;
}
}

View file

@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"create:goggles"
]
}