Skip to content

Commit

Permalink
Added custom first-person blocking for Atum shields, as the vanilla w…
Browse files Browse the repository at this point in the history
…ay is not working. Closes #415
  • Loading branch information
GirafiStudios committed May 6, 2023
1 parent 2205fe0 commit 97b6827
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.minecraft.client.renderer.Sheets;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher;
import net.minecraft.client.renderer.entity.ItemRenderer;
import net.minecraft.client.renderer.item.ItemProperties;
import net.minecraft.client.resources.model.Material;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -90,11 +91,11 @@ public void renderByItem(@Nonnull ItemStack stack, @Nonnull ItemDisplayContext d
}
} else {
if (item == AtumItems.BRIGAND_SHIELD.get()) {
renderShield(stack, brigandShield, BRIGAND_SHIELD_MATERIAL, poseStack, buffer, combinedLight, combinedOverlay);
renderShield(brigandShield, BRIGAND_SHIELD_MATERIAL, stack, displayContext, poseStack, buffer, combinedLight, combinedOverlay);
} else if (item == AtumItems.STONEGUARD_SHIELD.get()) {
renderShield(stack, stoneguardShield, STONEGUARD_SHIELD_MATERIAL, poseStack, buffer, combinedLight, combinedOverlay);
renderShield(stoneguardShield, STONEGUARD_SHIELD_MATERIAL, stack, displayContext, poseStack, buffer, combinedLight, combinedOverlay);
} else if (item == AtumItems.ATEMS_PROTECTION.get()) {
renderShield(stack, atemsProtection, ATEMS_PROTECTION_MATERIAL, poseStack, buffer, combinedLight, combinedOverlay);
renderShield(atemsProtection, ATEMS_PROTECTION_MATERIAL, stack, displayContext, poseStack, buffer, combinedLight, combinedOverlay);
} /*else if (item == AtumItems.NEPTHYS_CONSECRATION) {
renderShield(stack, NEPTHYS_CONSECRATION, NEPTHYS_CONSECRATION_MATERIAL, poseStack, buffer, combinedLight, combinedOverlay);
} */ else if (item == AtumItems.TEFNUTS_CALL.get()) {
Expand All @@ -112,9 +113,22 @@ public void renderByItem(@Nonnull ItemStack stack, @Nonnull ItemDisplayContext d
}
}

private void renderShield(@Nonnull ItemStack stack, AbstractShieldModel shieldModel, Material material, PoseStack poseStack, MultiBufferSource buffer, int combinedLight, int combinedOverlay) {
private void renderShield(AbstractShieldModel shieldModel, Material material, @Nonnull ItemStack stack, @Nonnull ItemDisplayContext displayContext, @Nonnull PoseStack poseStack, @Nonnull MultiBufferSource buffer, int combinedLight, int combinedOverlay) {
poseStack.pushPose();
if (displayContext.firstPerson()) {
LocalPlayer player = Minecraft.getInstance().player;
if (player != null && player.isUsingItem() && player.getUseItem() == stack) {
if (displayContext == ItemDisplayContext.FIRST_PERSON_RIGHT_HAND) {
poseStack.translate(0.2F, 0.1F, 0.2F);
} else if (displayContext == ItemDisplayContext.FIRST_PERSON_LEFT_HAND) {
poseStack.translate(-0.2F, 0.1F, 0.25F);
}
}
}

VertexConsumer builder = material.sprite().wrap(ItemRenderer.getFoilBuffer(buffer, shieldModel.renderType(material.atlasLocation()), false, stack.hasFoil()));
shieldModel.renderToBuffer(poseStack, builder, combinedLight, combinedOverlay, 1.0F, 1.0F, 1.0F, 1.0F);
poseStack.popPose();
}

private static Material getShieldMaterial(String fileName) {
Expand Down

0 comments on commit 97b6827

Please sign in to comment.