Skip to content

Commit

Permalink
Fixed Elytra cape compat
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon3055 committed May 31, 2024
1 parent c5c23c4 commit 14a1124
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,18 @@ private static void setupRenderLayers() {
ItemBlockRenderTypes.setRenderLayer(DEContent.DEEPSLATE_DRACONIUM_ORE.get(), renderType -> renderType == RenderType.solid() || renderType == RenderType.cutoutMipped());
}

public static boolean deElytraVisible(ItemStack stack, LivingEntity entity) {
if (ContributorHandler.shouldCancelElytra(entity)) return false;
if (stack.getItem() instanceof IModularArmor item) {
return item.canElytraFlyBC(stack, entity);
}
if (BrandonsCore.equipmentManager != null) {
ItemStack curio = BrandonsCore.equipmentManager.findMatchingItem(e -> e.getItem() instanceof IModularArmor, entity);
return curio.getItem() instanceof IModularArmor item && item.canElytraFlyBC(curio, entity);
}
return false;
}

@SuppressWarnings ({"rawtypes", "unchecked"})
private static void onAddRenderLayers(EntityRenderersEvent.AddLayers event) {
for (String skin : event.getSkins()) {
Expand All @@ -228,15 +240,7 @@ private static void onAddRenderLayers(EntityRenderersEvent.AddLayers event) {
renderer.addLayer(new ElytraLayer(renderer, event.getEntityModels()) {
@Override
public boolean shouldRender(@NotNull ItemStack stack, @NotNull LivingEntity entity) {
if (ContributorHandler.shouldCancelElytra(entity)) return false;
if (stack.getItem() instanceof IModularArmor item) {
return item.canElytraFlyBC(stack, entity);
}
if (BrandonsCore.equipmentManager != null) {
ItemStack curio = BrandonsCore.equipmentManager.findMatchingItem(e -> e.getItem() instanceof IModularArmor, entity);
return curio.getItem() instanceof IModularArmor item && item.canElytraFlyBC(curio, entity);
}
return false;
return deElytraVisible(stack, entity);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.brandon3055.draconicevolution.mixin;

import com.brandon3055.draconicevolution.init.ClientInit;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.layers.CapeLayer;
import net.minecraft.world.item.ItemStack;
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.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

/**
* Created by brandon3055 on 4/2/21
*/
@Mixin (CapeLayer.class)
public class CapeLayerMixin {

@Inject (
method = "render(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;ILnet/minecraft/client/player/AbstractClientPlayer;FFFFFF)V",
at = @At (
value = "INVOKE_ASSIGN",
target = "Lnet/minecraft/client/player/AbstractClientPlayer;getItemBySlot(Lnet/minecraft/world/entity/EquipmentSlot;)Lnet/minecraft/world/item/ItemStack;",
shift = At.Shift.AFTER
),
locals = LocalCapture.CAPTURE_FAILHARD,
cancellable = true
)
private void render(PoseStack pMatrixStack, MultiBufferSource pBuffer, int pPackedLight, AbstractClientPlayer pLivingEntity, float pLimbSwing, float pLimbSwingAmount, float pPartialTicks, float pAgeInTicks, float pNetHeadYaw, float pHeadPitch, CallbackInfo ci, ItemStack itemstack) {
if (ClientInit.deElytraVisible(itemstack, pLivingEntity)) {
ci.cancel();
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/mixins.draconicevolution.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"TheEndBiomeSourceMixin"
],
"client": [
"CapeLayerMixin",
"PlayerModelMixin",
"ServerboundSetCreativeModeSlotPacketMixin"
]
Expand Down

0 comments on commit 14a1124

Please sign in to comment.