Skip to content

Commit

Permalink
Port to 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
Hidoni committed Jun 14, 2024
1 parent f898b1e commit ae90a88
Show file tree
Hide file tree
Showing 37 changed files with 117 additions and 117 deletions.
7 changes: 2 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
# 2.2.3+1.20.6 14/06/2024
- Fix bug where the first banner pattern would not actually be rendered

# 2.2.2+1.20.6 12/06/2024
- Initial 1.20.6 port
# 2.2.3+1.21 14/06/2024
- Initial 1.21 port
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public class Constants {

public static final Logger LOG = LoggerFactory.getLogger(MOD_NAME);

public static final ResourceLocation ELYTRA_BANNER_SHEET = new ResourceLocation(Constants.MOD_ID, "textures/atlas/elytra_patterns.png");
public static final ResourceLocation ELYTRA_BANNER_ATLAS = new ResourceLocation(Constants.MOD_ID, "elytra_patterns");
public static final ResourceLocation ELYTRA_LEFT_WING_TRIM_TYPE_PREDICATE = new ResourceLocation(Constants.MOD_ID, "left_wing_trim_type");
public static final ResourceLocation ELYTRA_RIGHT_WING_TRIM_TYPE_PREDICATE = new ResourceLocation(Constants.MOD_ID, "right_wing_trim_type");
public static final ResourceLocation ELYTRA_BANNER_SHEET = ResourceLocation.fromNamespaceAndPath(Constants.MOD_ID, "textures/atlas/elytra_patterns.png");
public static final ResourceLocation ELYTRA_BANNER_ATLAS = ResourceLocation.fromNamespaceAndPath(Constants.MOD_ID, "elytra_patterns");
public static final ResourceLocation ELYTRA_LEFT_WING_TRIM_TYPE_PREDICATE = ResourceLocation.fromNamespaceAndPath(Constants.MOD_ID, "left_wing_trim_type");
public static final ResourceLocation ELYTRA_RIGHT_WING_TRIM_TYPE_PREDICATE = ResourceLocation.fromNamespaceAndPath(Constants.MOD_ID, "right_wing_trim_type");
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
import java.util.function.Function;

public class CustomizableElytraLayerHelper<T extends LivingEntity> {
private static final ResourceLocation TEXTURE_GRAYSCALE_ELYTRA = new ResourceLocation(Constants.MOD_ID, "textures/entity/elytra.png");
private static final ResourceLocation TEXTURE_GRAYSCALE_ELYTRA = ResourceLocation.fromNamespaceAndPath(Constants.MOD_ID, "textures/entity/elytra.png");
private static final Function<ArmorTrim, ResourceLocation> elytraTrimLookup = Util.memoize(trim -> trim.pattern().value().assetId().withPath((path) -> "trims/models/elytra/" + path + "_" + trim.material().value().assetName()));
private static final ResourceLocation VANILLA_WINGS_LOCATION = new ResourceLocation("textures/entity/elytra.png");
private static final ResourceLocation VANILLA_WINGS_LOCATION = ResourceLocation.withDefaultNamespace("textures/entity/elytra.png");

private T entity = null;
private MultiBufferSource defaultBuffer = null;
Expand Down Expand Up @@ -88,29 +88,26 @@ public void renderWing(ElytraWingModel<T> wingModel, ItemStack wingStack, PoseSt
}

private void renderDyedWing(ElytraWingModel<T> wingModel, ItemStack wingStack, PoseStack poseStack, int packedLight, CustomizableElytraItem wingItem, ResourceLocation elytraTexture, boolean hasFoil) {
VertexConsumer elytraVertexConsumer = ItemRenderer.getArmorFoilBuffer(defaultBuffer, RenderType.armorCutoutNoCull(elytraTexture), false, hasFoil);
float[] rgba = CustomizationUtils.convertIntToRGBA(wingItem.getColor(wingStack));
wingModel.renderToBuffer(poseStack, elytraVertexConsumer, packedLight, OverlayTexture.NO_OVERLAY, rgba[0], rgba[1], rgba[2], rgba[3]);
VertexConsumer elytraVertexConsumer = ItemRenderer.getArmorFoilBuffer(defaultBuffer, RenderType.armorCutoutNoCull(elytraTexture), hasFoil);
wingModel.renderToBuffer(poseStack, elytraVertexConsumer, packedLight, OverlayTexture.NO_OVERLAY, wingItem.getColor(wingStack));
}

private void renderWingBannerPatterns(ElytraWingModel<T> wingModel, ItemStack wingStack, PoseStack poseStack, int packedLight, CustomizableElytraItem wingItem, ResourceLocation elytraTexture, boolean hasFoil) {
BannerPatternLayers bannerPatterns = wingItem.getBannerPatterns(wingStack);
// First render: Enchantment Glint
wingModel.renderToBuffer(poseStack, ItemRenderer.getFoilBufferDirect(defaultBuffer, RenderType.entityNoOutline(elytraTexture), false, hasFoil), packedLight, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F);
float[] baseColor = wingItem.getBaseColor(wingStack).getTextureDiffuseColors();
wingModel.renderToBuffer(poseStack, ItemRenderer.getFoilBufferDirect(defaultBuffer, RenderType.entityNoOutline(elytraTexture), false, hasFoil), packedLight, OverlayTexture.NO_OVERLAY);
// Second render: Base Layer
wingModel.renderToBuffer(poseStack, ItemRenderer.getFoilBuffer(defaultBuffer, RenderType.entityTranslucent(elytraTexture), false, false), packedLight, OverlayTexture.NO_OVERLAY, baseColor[0], baseColor[1], baseColor[2], 1.0F);
wingModel.renderToBuffer(poseStack, ItemRenderer.getFoilBuffer(defaultBuffer, RenderType.entityTranslucent(elytraTexture), false, false), packedLight, OverlayTexture.NO_OVERLAY, wingItem.getBaseColor(wingStack).getTextureDiffuseColor());
for (int i = 0; i < bannerPatterns.layers().size(); i++) {
BannerPatternLayers.Layer bannerAndColor = bannerPatterns.layers().get(i);
float[] colors = bannerAndColor.color().getTextureDiffuseColors();
Optional<ResourceKey<BannerPattern>> resourceKey = bannerAndColor.pattern().unwrapKey();
if (resourceKey.isPresent()) {
Material bannerMaterial = new Material(Constants.ELYTRA_BANNER_SHEET, getTextureLocation(resourceKey.get()));
Map<ResourceLocation, TextureAtlasSprite> texturesByName = ((TextureAtlasAccessor) bannerPatternAtlas).getTexturesByName();
if (texturesByName.get(bannerMaterial.texture()) != null) // Don't render this banner pattern if it's missing, silently hide the pattern
{
// Final renders: Pattern Layers
wingModel.renderToBuffer(poseStack, bannerMaterial.buffer(defaultBuffer, RenderType::entityTranslucent), packedLight, OverlayTexture.NO_OVERLAY, colors[0], colors[1], colors[2], 1.0F);
wingModel.renderToBuffer(poseStack, bannerMaterial.buffer(defaultBuffer, RenderType::entityTranslucent), packedLight, OverlayTexture.NO_OVERLAY, bannerAndColor.color().getTextureDiffuseColor());
}
}
}
Expand All @@ -124,8 +121,8 @@ private void renderBasicWing(ElytraWingModel<T> wingModel, ItemStack wingStack,
if (elytraTexture == null) {
elytraTexture = VANILLA_WINGS_LOCATION;
}
VertexConsumer vertexConsumer = ItemRenderer.getArmorFoilBuffer(defaultBuffer, RenderType.armorCutoutNoCull(elytraTexture), false, hasFoil);
wingModel.renderToBuffer(poseStack, vertexConsumer, packedLight, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F);
VertexConsumer vertexConsumer = ItemRenderer.getArmorFoilBuffer(defaultBuffer, RenderType.armorCutoutNoCull(elytraTexture), hasFoil);
wingModel.renderToBuffer(poseStack, vertexConsumer, packedLight, OverlayTexture.NO_OVERLAY);
}

@NotNull
Expand All @@ -139,7 +136,7 @@ private void renderWingTrim(ElytraWingModel<T> wingModel, ItemStack wingStack, P
ResourceLocation trimLocation = elytraTrimLookup.apply(trim);
TextureAtlasSprite sprite = armorTrimAtlas.getSprite(trimLocation);
VertexConsumer consumer = sprite.wrap(ItemRenderer.getFoilBufferDirect(defaultBuffer, Sheets.armorTrimsSheet(trim.pattern().value().decal()), true, hasFoil));
wingModel.renderToBuffer(poseStack, consumer, packedLight, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F);
wingModel.renderToBuffer(poseStack, consumer, packedLight, OverlayTexture.NO_OVERLAY);
});
}

Expand Down Expand Up @@ -168,6 +165,6 @@ private ResourceLocation getCapeTexture() {
}

private static ResourceLocation getTextureLocation(ResourceKey<BannerPattern> bannerIn) {
return new ResourceLocation(Constants.MOD_ID, "entity/elytra_banner/" + bannerIn.location().getPath());
return ResourceLocation.fromNamespaceAndPath(Constants.MOD_ID, "entity/elytra_banner/" + bannerIn.location().getPath());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import net.minecraft.core.component.DataComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.FastColor;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
Expand All @@ -31,22 +30,6 @@ public static ElytraCustomization getElytraCustomization(ItemStack elytra) {
return elytra.get(ModDataComponents.ELYTRA_CUSTOMIZATION.get());
}

public static int convertDyeColorToInt(DyeColor dyeColor) {
float[] colorValues = dyeColor.getTextureDiffuseColors();
int red = (int) (colorValues[0] * 255) << 16;
int green = (int) (colorValues[1] * 255) << 8;
int blue = (int) (colorValues[2] * 255);
return FastColor.ARGB32.opaque(red | green | blue);
}

public static float[] convertIntToRGBA(int color) {
float alphaValue = (float) (color >> 24 & 255) / 255.0F;
float redValue = (float) (color >> 16 & 255) / 255.0F;
float greenValue = (float) (color >> 8 & 255) / 255.0F;
float blueValue = (float) (color & 255) / 255.0F;
return new float[]{redValue, greenValue, blueValue, alphaValue};
}

public static List<Component> getElytraWingTooltipLines(ItemStack wing, Item.TooltipContext tooltipContext, TooltipFlag tooltipFlag) {
List<Component> lines = new ArrayList<>();
if (!(wing.getItem() instanceof CustomizableElytraItem item)) {
Expand Down Expand Up @@ -85,7 +68,7 @@ private static void getBannerComponents(ItemStack wing, Consumer<Component> comp
layer.pattern().unwrapKey()
.map(bannerPatternResourceKey -> bannerPatternResourceKey.location().toShortLanguageKey())
.ifPresent(location -> {
ResourceLocation bannerPatternLocation = new ResourceLocation(location);
ResourceLocation bannerPatternLocation = ResourceLocation.parse(location);
componentConsumer.accept(Component.translatable("block." + bannerPatternLocation.getNamespace() + ".banner." + bannerPatternLocation.getPath() + "." + layer.color().getName()).withStyle(ChatFormatting.GRAY)
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public int getColor(@NotNull ItemStack stack) {
return DyedItemColor.getOrDefault(stack, 0xFFFFFFFF);
}
if (this.hasBanner(stack)) {
DyeColor baseDyeColor = Objects.requireNonNull(stack.get(DataComponents.BASE_COLOR));
return CustomizationUtils.convertDyeColorToInt(baseDyeColor);
return Objects.requireNonNull(stack.get(DataComponents.BASE_COLOR)).getTextureDiffuseColor();
}
return 0xFFFFFFFF;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.ArmorDyeRecipe;
import net.minecraft.world.item.crafting.CraftingInput;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(ArmorDyeRecipe.class)
public class ArmorDyeRecipeMixin {
@Inject(method = "assemble(Lnet/minecraft/world/inventory/CraftingContainer;Lnet/minecraft/core/HolderLookup$Provider;)Lnet/minecraft/world/item/ItemStack;", at=@At(value = "RETURN"), cancellable = true)
private void handleCustomizableElytraItemDye(CraftingContainer $$0, HolderLookup.Provider $$1, CallbackInfoReturnable<ItemStack> cir) {
@Inject(method = "assemble(Lnet/minecraft/world/item/crafting/CraftingInput;Lnet/minecraft/core/HolderLookup$Provider;)Lnet/minecraft/world/item/ItemStack;", at=@At(value = "RETURN"), cancellable = true)
private void handleCustomizableElytraItemDye(CraftingInput inv, HolderLookup.Provider lookupProvider, CallbackInfoReturnable<ItemStack> cir) {
ItemStack stack = cir.getReturnValue();
if (stack.getItem() instanceof CustomizableElytraItem customizableElytraItem) {
if (!customizableElytraItem.canDye(stack)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ private ItemStack storeElytraStack(ItemStack elytra) {
return elytra;
}

@Redirect(method = "render(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;ILnet/minecraft/world/entity/LivingEntity;FFFFFF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/model/ElytraModel;renderToBuffer(Lcom/mojang/blaze3d/vertex/PoseStack;Lcom/mojang/blaze3d/vertex/VertexConsumer;IIFFFF)V"))
private void renderCustomizedElytraWings(ElytraModel<T> elytraModel, PoseStack poseStack, VertexConsumer vertexConsumer, int packedLight, int overlayTexture, float red, float green, float blue, float alpha) {
@Redirect(method = "render(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;ILnet/minecraft/world/entity/LivingEntity;FFFFFF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/model/ElytraModel;renderToBuffer(Lcom/mojang/blaze3d/vertex/PoseStack;Lcom/mojang/blaze3d/vertex/VertexConsumer;II)V"))
private void renderCustomizedElytraWings(ElytraModel<T> elytraModel, PoseStack poseStack, VertexConsumer vertexConsumer, int packedLight, int overlayTexture) {
ElytraCustomization customization = CustomizationUtils.getElytraCustomization(helper.getElytra());
if (!customization.isCustomized()) {
elytraModel.renderToBuffer(poseStack, vertexConsumer, packedLight, overlayTexture, red, green, blue, alpha);
elytraModel.renderToBuffer(poseStack, vertexConsumer, packedLight, overlayTexture);
return;
}
getParentModel().copyPropertiesTo(leftWing);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
Expand All @@ -29,8 +30,11 @@ public abstract class ElytraLayerMixin<T extends LivingEntity, M extends EntityM
@Shadow
@Final
private ElytraModel<T> elytraModel;
@Unique
private ElytraWingModel<T> leftWing;
@Unique
private ElytraWingModel<T> rightWing;
@Unique
private CustomizableElytraLayerHelper<T> helper;

public ElytraLayerMixin(RenderLayerParent<T, M> parent) {
Expand All @@ -56,11 +60,11 @@ private ItemStack storeElytraStack(ItemStack elytra) {
return elytra;
}

@Redirect(method = "render(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;ILnet/minecraft/world/entity/LivingEntity;FFFFFF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/model/ElytraModel;renderToBuffer(Lcom/mojang/blaze3d/vertex/PoseStack;Lcom/mojang/blaze3d/vertex/VertexConsumer;IIFFFF)V"))
private void renderCustomizedElytraWings(ElytraModel<T> elytraModel, PoseStack poseStack, VertexConsumer vertexConsumer, int packedLight, int overlayTexture, float red, float green, float blue, float alpha) {
@Redirect(method = "render(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;ILnet/minecraft/world/entity/LivingEntity;FFFFFF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/model/ElytraModel;renderToBuffer(Lcom/mojang/blaze3d/vertex/PoseStack;Lcom/mojang/blaze3d/vertex/VertexConsumer;II)V"))
private void renderCustomizedElytraWings(ElytraModel<T> elytraModel, PoseStack poseStack, VertexConsumer vertexConsumer, int packedLight, int overlayTexture) {
ElytraCustomization customization = CustomizationUtils.getElytraCustomization(helper.getElytra());
if (!customization.isCustomized()) {
elytraModel.renderToBuffer(poseStack, vertexConsumer, packedLight, overlayTexture, red, green, blue, alpha);
elytraModel.renderToBuffer(poseStack, vertexConsumer, packedLight, overlayTexture);
return;
}
getParentModel().copyPropertiesTo(leftWing);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ private Item storeElytraStack(ItemStack elytra) {
return elytra.getItem();
}

@Redirect(method = "*", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/model/ElytraModel;renderToBuffer(Lcom/mojang/blaze3d/vertex/PoseStack;Lcom/mojang/blaze3d/vertex/VertexConsumer;IIFFFF)V"))
private void renderCustomizedElytraWings(ElytraModel<T> elytraModel, PoseStack poseStack, VertexConsumer vertexConsumer, int packedLight, int overlayTexture, float red, float green, float blue, float alpha) {
@Redirect(method = "*", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/model/ElytraModel;renderToBuffer(Lcom/mojang/blaze3d/vertex/PoseStack;Lcom/mojang/blaze3d/vertex/VertexConsumer;II)V"))
private void renderCustomizedElytraWings(ElytraModel<T> elytraModel, PoseStack poseStack, VertexConsumer vertexConsumer, int packedLight, int overlayTexture) {
ElytraCustomization customization = CustomizationUtils.getElytraCustomization(helper.getElytra());
if (!customization.isCustomized()) {
elytraModel.renderToBuffer(poseStack, vertexConsumer, packedLight, overlayTexture, red, green, blue, alpha);
elytraModel.renderToBuffer(poseStack, vertexConsumer, packedLight, overlayTexture);
return;
}
getParentModel().copyPropertiesTo(leftWing);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.hidoni.customizableelytra.item.ElytraWingItem;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.item.crafting.CraftingInput;
import net.minecraft.world.item.crafting.RepairItemRecipe;
import net.minecraft.world.level.Level;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -11,10 +12,10 @@

@Mixin(RepairItemRecipe.class)
public class RepairItemRecipeMixin {
@Inject(method = "matches(Lnet/minecraft/world/inventory/CraftingContainer;Lnet/minecraft/world/level/Level;)Z", at=@At("HEAD"), cancellable = true)
private void preventElytraWingRepair(CraftingContainer container, Level level, CallbackInfoReturnable<Boolean> cir) {
for (int i = 0; i < container.getContainerSize(); i++) {
if (container.getItem(i).getItem() instanceof ElytraWingItem) {
@Inject(method = "matches(Lnet/minecraft/world/item/crafting/CraftingInput;Lnet/minecraft/world/level/Level;)Z", at=@At("HEAD"), cancellable = true)
private void preventElytraWingRepair(CraftingInput inv, Level level, CallbackInfoReturnable<Boolean> cir) {
for (int i = 0; i < inv.size(); i++) {
if (inv.getItem(i).getItem() instanceof ElytraWingItem) {
cir.setReturnValue(false);
return;
}
Expand Down
Loading

0 comments on commit ae90a88

Please sign in to comment.