Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tag #21

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Tag #21

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.wispforest.affinity.client.render.entity.*;
import io.wispforest.affinity.client.render.item.AzaleaChestItemRenderer;
import io.wispforest.affinity.client.render.item.MangroveBasketItemRenderer;
import io.wispforest.affinity.client.render.item.VillagerArmsItemRenderer;
import io.wispforest.affinity.client.render.item.VoidResonantEtherealAmethystShardRenderer;
import io.wispforest.affinity.client.render.program.*;
import io.wispforest.affinity.client.screen.*;
Expand Down Expand Up @@ -101,6 +102,8 @@ public void onInitializeClient() {
BuiltinItemRendererRegistry.INSTANCE.register(AffinityBlocks.FIELD_COHERENCE_MODULATOR, new FieldCoherenceModulatorBlockEntityRenderer(null));
BuiltinItemRendererRegistry.INSTANCE.register(AffinityItems.VOID_RESONANT_ETHEREAL_AMETHYST_SHARD, new VoidResonantEtherealAmethystShardRenderer());
BuiltinItemRendererRegistry.INSTANCE.register(AffinityBlocks.AZALEA_CHEST, new AzaleaChestItemRenderer());
BuiltinItemRendererRegistry.INSTANCE.register(AffinityItems.VILLAGER_ARMS, new VillagerArmsItemRenderer());

PostItemRenderCallback.EVENT.register((stack, mode, leftHanded, matrices, vertexConsumers, light, overlay, model, item) -> {
boolean hasItemGlow = item != null && item.getComponent(AffinityComponents.ENTITY_FLAGS).hasFlag(EntityFlagComponent.ITEM_GLOW);
if (mode == ModelTransformationMode.GUI || (!stack.isOf(AffinityItems.DRAGON_DROP) && !hasItemGlow)) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,27 @@

public class VillagerArmatureBlockEntityRenderer extends AffinityBlockEntityRenderer<VillagerArmatureBlockEntity> {

public static final ModelPart ARMS;

static {
var rootPart = new ModelData().getRoot();
rootPart.addChild(
"arms",
ModelPartBuilder.create()
.uv(40, 38)
.cuboid(-4.0F, 2.1618F, -2.0F, 8.0F, 4.0F, 4.0F)
.uv(44, 22)
.cuboid(-8.0F, -1.8382F, -2.0F, 4.0F, 8.0F, 4.0F)
.uv(44, 22)
.mirrored()
.cuboid(4.0F, -1.8382F, -2.0F, 4.0F, 8.0F, 4.0F)
.mirrored(false),
ModelTransform.of(0.0F, 11.6667F, 2.0F, 2.356f, 0.0F, 0.0F)
);
ARMS = rootPart.createPart(64, 64);
}


public static final Transformation.Interpolation EXPO = (result, delta, keyframes, start, end, scale) -> {
var from = keyframes[start].target();
var to = keyframes[end].target();
Expand All @@ -31,58 +52,41 @@ public class VillagerArmatureBlockEntityRenderer extends AffinityBlockEntityRend
};

public static final Animation PUNCH_ANIMATION = Animation.Builder.create(0.3f)
.addBoneAnimation("arms", new Transformation(Transformation.Targets.ROTATE,
new Keyframe(0f, AnimationHelper.createRotationalVector(0.0F, 0.0F, 0.0F), EXPO),
new Keyframe(0.15f, AnimationHelper.createRotationalVector(-17.5F, 0.0F, 0.0F), EXPO),
new Keyframe(0.3f, AnimationHelper.createRotationalVector(0.0F, 0.0F, 0.0F), EXPO)
))
.addBoneAnimation("arms", new Transformation(Transformation.Targets.TRANSLATE,
new Keyframe(0f, AnimationHelper.createTranslationalVector(0.0F, 0.0F, 0.0F), EXPO),
new Keyframe(0.15f, AnimationHelper.createTranslationalVector(0.0F, 1.0F, 1.5F), EXPO),
new Keyframe(0.3f, AnimationHelper.createTranslationalVector(0.0F, 0.0F, 0.0F), EXPO)
))
.build();

private final ModelPart arms;
.addBoneAnimation("arms", new Transformation(
Transformation.Targets.ROTATE,
new Keyframe(0f, AnimationHelper.createRotationalVector(0.0F, 0.0F, 0.0F), EXPO),
new Keyframe(0.15f, AnimationHelper.createRotationalVector(-17.5F, 0.0F, 0.0F), EXPO),
new Keyframe(0.3f, AnimationHelper.createRotationalVector(0.0F, 0.0F, 0.0F), EXPO)
))
.addBoneAnimation("arms", new Transformation(
Transformation.Targets.TRANSLATE,
new Keyframe(0f, AnimationHelper.createTranslationalVector(0.0F, 0.0F, 0.0F), EXPO),
new Keyframe(0.15f, AnimationHelper.createTranslationalVector(0.0F, 1.0F, 1.5F), EXPO),
new Keyframe(0.3f, AnimationHelper.createTranslationalVector(0.0F, 0.0F, 0.0F), EXPO)
))
.build();

public VillagerArmatureBlockEntityRenderer(BlockEntityRendererFactory.Context ctx) {
super(ctx);

var rootPart = new ModelData().getRoot();
rootPart.addChild(
"arms",
ModelPartBuilder.create()
.uv(0, 16)
.cuboid(-4.0F, 2.1618F, -2.0F, 8.0F, 4.0F, 4.0F)
.uv(4, 0)
.cuboid(-8.0F, -1.8382F, -2.0F, 4.0F, 8.0F, 4.0F)
.uv(4, 0)
.mirrored()
.cuboid(4.0F, -1.8382F, -2.0F, 4.0F, 8.0F, 4.0F)
.mirrored(false),
ModelTransform.of(0.0F, 11.6667F, 2.0F, 2.356f, 0.0F, 0.0F)
);

this.arms = rootPart.createPart(32, 32);
}

@Override
protected void render(VillagerArmatureBlockEntity entity, float tickDelta, float frameDelta, long time, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) {
var animationState = entity.punchAnimationState;

this.arms.traverse().forEach(ModelPart::resetTransform);
ARMS.traverse().forEach(ModelPart::resetTransform);
animationState.update(entity.time() + tickDelta, 1f);
animationState.run(state -> animate(this.arms, PUNCH_ANIMATION, state.getTimeRunning(), 1f, new Vector3f()));
animationState.run(state -> animate(ARMS, PUNCH_ANIMATION, state.getTimeRunning(), 1f, new Vector3f()));

matrices.push();
matrices.translate(.5, 0, .5);
matrices.multiply(entity.getCachedState().get(VillagerArmatureBlock.FACING).getRotationQuaternion().rotateX((float) (Math.PI / -2)));

var buffer = vertexConsumers.getBuffer(RenderLayer.getEntitySolid(Affinity.id("textures/item/villager_arms.png")));
this.arms.render(matrices, buffer, light, overlay);
ARMS.render(matrices, buffer, light, overlay);

if (!entity.heldStack().isEmpty()) {
this.arms.getChild("arms").rotate(matrices);
ARMS.getChild("arms").rotate(matrices);
matrices.translate(0, .325, -.1);
matrices.multiply(new Quaternionf().rotationY((float) Math.PI).rotateX((float) Math.toRadians(100)));
this.ctx.getItemRenderer().renderItem(entity.heldStack(), ModelTransformationMode.THIRD_PERSON_RIGHT_HAND, light, overlay, matrices, vertexConsumers, entity.getWorld(), 0);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.wispforest.affinity.client.render.item;

import io.wispforest.affinity.client.render.blockentity.VillagerArmatureBlockEntityRenderer;
import io.wispforest.affinity.item.VillagerArmsItem;
import io.wispforest.affinity.mixin.VillagerClothingFeatureRendererAccessor;
import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.model.json.ModelTransformationMode;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RotationAxis;
import net.minecraft.village.VillagerProfession;

import java.util.function.UnaryOperator;

import static net.minecraft.entity.EntityType.VILLAGER;

public class VillagerArmsItemRenderer implements BuiltinItemRendererRegistry.DynamicItemRenderer {
public static final Identifier NORMIE = Identifier.ofVanilla("textures/entity/villager/villager.png");

@Override
public void render(ItemStack stack, ModelTransformationMode mode, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) {
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180));
matrices.translate(-0.5, -1/7f, -0.75);
this.renderArms(NORMIE, matrices, vertexConsumers, light, overlay);
var data = stack.get(VillagerArmsItem.VILLAGER_DATA);
if (data == null) return;
this.renderArms(this.findTexture("type", Registries.VILLAGER_TYPE.getId(data.getType())), matrices, vertexConsumers, light, overlay);
var profession = data.getProfession();
if (profession == VillagerProfession.NONE) return;
this.renderArms(this.findTexture("profession", Registries.VILLAGER_PROFESSION.getId(profession)), matrices, vertexConsumers, light, overlay);
if (profession == VillagerProfession.NITWIT) return;
this.renderArms(this.findTexture("profession_level", VillagerClothingFeatureRendererAccessor.affinity$LevelToIdMap().get(MathHelper.clamp(data.getLevel(), 1, VillagerClothingFeatureRendererAccessor.affinity$LevelToIdMap().size()))), matrices, vertexConsumers, light, overlay);
}

private void renderArms(Identifier id, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) {
var buffer = vertexConsumers.getBuffer(RenderLayer.getEntityCutoutNoCull(id));
VillagerArmatureBlockEntityRenderer.ARMS.render(matrices, buffer, light, overlay);
}

private Identifier findTexture(String keyType, Identifier keyId) {
return keyId.withPath(path -> "textures/entity/villager/" + keyType + "/" + path + ".png");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) {
pack.addProvider(AffinityRecipesProvider::new);
pack.addProvider(AffinityDynamicRegistryProvider::new);
pack.addProvider(AffinityEnchantmentTagProvider::new);
pack.addProvider(AffinityFluidTagProvider::new);

var blockTagProvider = pack.addProvider(AffinityBlockTagProvider::new);
pack.addProvider((output, registries) -> new AffinityItemTagProvider(output, registries, blockTagProvider));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.wispforest.affinity.datagen;

import io.wispforest.affinity.Affinity;
import io.wispforest.affinity.object.AffinityBlocks;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider;
import net.minecraft.fluid.Fluid;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.util.Identifier;

import java.util.concurrent.CompletableFuture;

public class AffinityFluidTagProvider extends FabricTagProvider.FluidTagProvider {

public static final TagKey<Fluid> ARCANE_FADE = TagKey.of(RegistryKeys.FLUID, Identifier.of("c","arcane_fade"));

public AffinityFluidTagProvider(FabricDataOutput output, CompletableFuture<RegistryWrapper.WrapperLookup> completableFuture) {
super(output, completableFuture);
}

@Override
@SuppressWarnings("UnstableApiUsage")
protected void configure(RegistryWrapper.WrapperLookup arg) {
var arcaneFadeInternal = TagKey.of(RegistryKeys.FLUID, Affinity.id("arcane_fade"));

this.getOrCreateTagBuilder(arcaneFadeInternal).add(AffinityBlocks.Fluids.ARCANE_FADE, AffinityBlocks.Fluids.ARCANE_FADE_FLOWING);
this.getOrCreateTagBuilder(ARCANE_FADE).addTag(arcaneFadeInternal);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
import io.wispforest.owo.registration.reflect.FieldRegistrationHandler;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider;
import net.fabricmc.fabric.api.tag.convention.v1.ConventionalBlockTags;
import net.fabricmc.fabric.api.tag.convention.v1.ConventionalItemTags;
import net.fabricmc.fabric.api.tag.convention.v2.ConventionalBlockTags;
import net.fabricmc.fabric.api.tag.convention.v2.ConventionalItemTags;
import net.minecraft.item.Item;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.registry.tag.ItemTags;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;

import java.util.concurrent.CompletableFuture;
Expand All @@ -30,6 +31,8 @@ public class AffinityItemTagProvider extends FabricTagProvider.ItemTagProvider {
public static final TagKey<Item> WISP_MATTER = TagKey.of(RegistryKeys.ITEM, Affinity.id("wisp_matter"));
public static final TagKey<Item> WISP_MIST = TagKey.of(RegistryKeys.ITEM, Affinity.id("wisp_mist"));

public static final TagKey<Item> AMETHYST_SHARDS = TagKey.of(RegistryKeys.ITEM, Affinity.id("amethyst_shards"));

public AffinityItemTagProvider(FabricDataOutput output, CompletableFuture<RegistryWrapper.WrapperLookup> completableFuture, @Nullable BlockTagProvider blockTagProvider) {
super(output, completableFuture, blockTagProvider);
}
Expand Down Expand Up @@ -72,6 +75,16 @@ protected void configure(RegistryWrapper.WrapperLookup arg) {

this.getOrCreateTagBuilder(ItemTags.SWORDS).addTag(TagKey.of(RegistryKeys.ITEM, Affinity.id("artifact_blades")));

this.getOrCreateTagBuilder(ItemTags.BOW_ENCHANTABLE).add(AZALEA_BOW);
this.getOrCreateTagBuilder(ConventionalItemTags.BOW_TOOLS).add(AZALEA_BOW);

this.getOrCreateTagBuilder(ItemTags.HEAD_ARMOR).add(EMERALD_CHESTPLATE);
this.getOrCreateTagBuilder(ItemTags.CHEST_ARMOR).add(EMERALD_CHESTPLATE);
this.getOrCreateTagBuilder(ItemTags.LEG_ARMOR).add(EMERALD_LEGGINGS);
this.getOrCreateTagBuilder(ItemTags.FOOT_ARMOR).add(EMERALD_BOOTS);

this.getOrCreateTagBuilder(TagKey.of(RegistryKeys.ITEM, Identifier.of("c","buckets/arcane_fade"))).add(ARCANE_FADE_BUCKET);

FieldRegistrationHandler.process(AffinityItems.class, (item, name, field) -> {
if (item instanceof StaffItem && !(item instanceof AethumFireExtinguisherItem)) {
this.getOrCreateTagBuilder(STAFFS).add(item);
Expand All @@ -84,6 +97,7 @@ protected void configure(RegistryWrapper.WrapperLookup arg) {
if (item instanceof WispMistItem) {
this.getOrCreateTagBuilder(WISP_MIST).add(item);
}

}, false);
}
}
32 changes: 26 additions & 6 deletions src/main/java/io/wispforest/affinity/item/AffinityItemGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,31 @@
import io.wispforest.owo.itemgroup.gui.ItemGroupButton;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.minecraft.block.Blocks;
import net.minecraft.component.type.PotionContentsComponent;
import net.minecraft.enchantment.EnchantmentLevelEntry;
import net.minecraft.item.EnchantedBookItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.Items;
import net.minecraft.item.*;
import net.minecraft.potion.Potion;
import net.minecraft.potion.Potions;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.Registries;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.village.VillagerData;
import net.minecraft.village.VillagerProfession;
import net.minecraft.village.VillagerType;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Objects;

import static io.wispforest.affinity.item.VillagerArmsItem.VILLAGER_DATA;
import static io.wispforest.affinity.object.AffinityBlocks.*;
import static io.wispforest.affinity.object.AffinityItems.*;

public class AffinityItemGroup {

private static OwoItemGroup GROUP;

public static void register() {
GROUP = OwoItemGroup.builder(Affinity.id("affinity"), () -> Icon.of(INERT_WISP_MATTER)).initializer(group -> {
//noinspection Convert2MethodRef
Expand Down Expand Up @@ -214,6 +216,24 @@ private static void initializeGroup(OwoItemGroup group) {
entries.add(INERT_WISP_SPAWN_EGG);
entries.add(WISE_WISP_SPAWN_EGG);
entries.add(VICIOUS_WISP_SPAWN_EGG);
var items = new ArrayList<ItemStack>();
for (var villagerProfession : Registries.VILLAGER_PROFESSION) {
var stack = VILLAGER_ARMS.getDefaultStack();
stack.set(VILLAGER_DATA, new VillagerData(VillagerType.PLAINS, villagerProfession, 5));
items.add(stack);
}
entries.addAll(items, ItemGroup.StackVisibility.PARENT_TAB_ONLY);
items.clear();
for (var villagerType : Registries.VILLAGER_TYPE) {
for (var villagerProfession : Registries.VILLAGER_PROFESSION) {
for (int i = 1; i < ((villagerProfession.equals(VillagerProfession.NITWIT) || villagerProfession.equals(VillagerProfession.NONE)) ? 2 : 6); i++) {
var stack = VILLAGER_ARMS.getDefaultStack();
stack.set(VILLAGER_DATA, new VillagerData(villagerType, villagerProfession, i));
items.add(stack);
}
}
}
entries.addAll(items, ItemGroup.StackVisibility.SEARCH_TAB_ONLY);
}, false);

group.addButton(ItemGroupButton.github(group, "https://github.com/wisp-forest/affinity"));
Expand Down
Loading