Skip to content

Instantly share code, notes, and snippets.

@realkarmakun
Last active June 19, 2023 20:22
Show Gist options
  • Save realkarmakun/6b924488563946471705135d8fb2d0f8 to your computer and use it in GitHub Desktop.
Save realkarmakun/6b924488563946471705135d8fb2d0f8 to your computer and use it in GitHub Desktop.
class RustMeFirearmsBEWLR : BlockEntityWithoutLevelRenderer(null, null) {
override fun renderByItem(pStack: ItemStack, pTransformType: ItemTransforms.TransformType, pPoseStack: PoseStack, pBuffer: MultiBufferSource, pPackedLight: Int, pPackedOverlay: Int) {
val item = pStack.item
if (item is RenderedWithBEWLR) {
val renderer = Minecraft.getInstance().itemRenderer
// Pop off the transformations applied by ItemRenderer before calling this
pPoseStack.popPose()
pPoseStack.pushPose()
// Get model and apply perspective types
var model = Minecraft.getInstance().modelManager.getModel(item.modelLocation())
model = model.handlePerspective(pTransformType, pPoseStack)
// Some translation
pPoseStack.translate(-0.5, -0.5, -0.5)
// Getting ready to render
// Should we add enchantment glint
val shouldEnchantmentGlint = pStack.hasFoil()
val renderType = ItemBlockRenderTypes.getRenderType(pStack, true)
val vertexConsumer = ItemRenderer.getFoilBuffer(pBuffer, renderType, true, shouldEnchantmentGlint)
renderer.renderModelLists(model, pStack, pPackedLight, pPackedOverlay, pPoseStack, vertexConsumer)
//pPoseStack.popPose()
}
super.renderByItem(pStack, pTransformType, pPoseStack, pBuffer, pPackedLight, pPackedOverlay)
}
companion object {
private var INSTANCE: RustMeFirearmsBEWLR? = null
@Synchronized
fun getInstance(): RustMeFirearmsBEWLR {
if (INSTANCE == null) {
INSTANCE = RustMeFirearmsBEWLR()
}
return INSTANCE!!
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment