From 3bd9a4179b7096f6e862e4bfaa2406a39492bf67 Mon Sep 17 00:00:00 2001 From: screret Date: Mon, 22 May 2023 17:31:30 +0300 Subject: [PATCH 1/3] updated JEI maven location and FIXED AE2 FACADE MODELS --- build.gradle | 11 ++- .../core/mixins/ItemModelShaperMixin.java | 86 +++++++++++++++++++ .../main/resources/gtlib-common.mixins.json | 1 + 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 common/src/main/java/com/gregtechceu/gtlib/core/mixins/ItemModelShaperMixin.java diff --git a/build.gradle b/build.gradle index a21697f..7b36e34 100644 --- a/build.gradle +++ b/build.gradle @@ -25,7 +25,16 @@ subprojects { repositories { mavenCentral() maven { url = "https://maven.shedaniel.me/" } // Cloth Config, REI - maven { url = "https://dvs1.progwml6.com/files/maven/" } // JEI + maven { + // location of the maven that hosts JEI files since January 2023 + name = "Jared's maven" + url = "https://maven.blamejared.com/" + } + maven { + // location of a maven mirror for JEI files, as a fallback + name = "ModMaven" + url = "https://modmaven.dev" + } maven { url = "https://maven.parchmentmc.org" } // Parchment mappings maven { url = "https://maven.quiltmc.org/repository/release" } // Quilt Mappings maven { // Flywheel diff --git a/common/src/main/java/com/gregtechceu/gtlib/core/mixins/ItemModelShaperMixin.java b/common/src/main/java/com/gregtechceu/gtlib/core/mixins/ItemModelShaperMixin.java new file mode 100644 index 0000000..b0829e2 --- /dev/null +++ b/common/src/main/java/com/gregtechceu/gtlib/core/mixins/ItemModelShaperMixin.java @@ -0,0 +1,86 @@ +package com.gregtechceu.gtlib.core.mixins; + +import com.gregtechceu.gtlib.client.renderer.IItemRendererProvider; +import com.gregtechceu.gtlib.client.renderer.IRenderer; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import net.minecraft.client.renderer.ItemModelShaper; +import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.renderer.block.model.ItemOverrides; +import net.minecraft.client.renderer.block.model.ItemTransforms; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.core.Direction; +import net.minecraft.util.RandomSource; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.state.BlockState; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.List; + +@Mixin(ItemModelShaper.class) +public class ItemModelShaperMixin { + + @Shadow @Final private Int2ObjectMap shapesCache; + + @Shadow + private static int getIndex(Item item) { + throw new RuntimeException("Mixin apply failed!"); + } + + @Inject(method = "getItemModel(Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/client/resources/model/BakedModel;", at = @At("HEAD"), cancellable = true) + public void injectGetModel(ItemStack stack, CallbackInfoReturnable cir) { + if (stack.getItem() instanceof IItemRendererProvider provider) { + IRenderer renderer = provider.getRenderer(stack); + int itemIndex = getIndex(stack.getItem()); + + shapesCache.putIfAbsent(itemIndex, new BakedModel() { + @Override + public List getQuads(@org.jetbrains.annotations.Nullable BlockState state, @org.jetbrains.annotations.Nullable Direction direction, RandomSource random) { + return renderer.renderModel(null, null, state, direction, random); + } + + @Override + public boolean useAmbientOcclusion() { + return renderer.useAO(); + } + + @Override + public boolean isGui3d() { + return renderer.useBlockLight(stack); + } + + @Override + public boolean usesBlockLight() { + return renderer.useBlockLight(stack); + } + + @Override + public boolean isCustomRenderer() { + return false; + } + + @Override + public TextureAtlasSprite getParticleIcon() { + return renderer.getParticleTexture(); + } + + @Override + public ItemTransforms getTransforms() { + return ItemTransforms.NO_TRANSFORMS; + } + + @Override + public ItemOverrides getOverrides() { + return ItemOverrides.EMPTY; + } + }); + cir.setReturnValue(shapesCache.get(itemIndex)); + } + } +} diff --git a/common/src/main/resources/gtlib-common.mixins.json b/common/src/main/resources/gtlib-common.mixins.json index 568eca4..f3e03f0 100644 --- a/common/src/main/resources/gtlib-common.mixins.json +++ b/common/src/main/resources/gtlib-common.mixins.json @@ -7,6 +7,7 @@ "client": [ "BlockEntityRendererDispatcherMixin", "BlockModelShaperMixin", + "ItemModelShaperMixin", "ItemRendererMixin", "LanguageMixin", "ModelBakeryMixin", From 817ea94f48a050c5d93b4cbc669cc2881125be44 Mon Sep 17 00:00:00 2001 From: screret Date: Mon, 22 May 2023 18:12:43 +0300 Subject: [PATCH 2/3] found a crash, ore blocks still crash tho --- .../core/mixins/ItemModelShaperMixin.java | 75 ++++++++++--------- 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/common/src/main/java/com/gregtechceu/gtlib/core/mixins/ItemModelShaperMixin.java b/common/src/main/java/com/gregtechceu/gtlib/core/mixins/ItemModelShaperMixin.java index b0829e2..936bf3b 100644 --- a/common/src/main/java/com/gregtechceu/gtlib/core/mixins/ItemModelShaperMixin.java +++ b/common/src/main/java/com/gregtechceu/gtlib/core/mixins/ItemModelShaperMixin.java @@ -37,50 +37,53 @@ private static int getIndex(Item item) { public void injectGetModel(ItemStack stack, CallbackInfoReturnable cir) { if (stack.getItem() instanceof IItemRendererProvider provider) { IRenderer renderer = provider.getRenderer(stack); - int itemIndex = getIndex(stack.getItem()); + if (renderer != null) { + int itemIndex = getIndex(stack.getItem()); - shapesCache.putIfAbsent(itemIndex, new BakedModel() { - @Override - public List getQuads(@org.jetbrains.annotations.Nullable BlockState state, @org.jetbrains.annotations.Nullable Direction direction, RandomSource random) { - return renderer.renderModel(null, null, state, direction, random); - } + shapesCache.putIfAbsent(itemIndex, new BakedModel() { + @Override + public List getQuads(@org.jetbrains.annotations.Nullable BlockState state, @org.jetbrains.annotations.Nullable Direction direction, RandomSource random) { + return renderer.renderModel(null, null, state, direction, random); + } - @Override - public boolean useAmbientOcclusion() { - return renderer.useAO(); - } + @Override + public boolean useAmbientOcclusion() { + return renderer.useAO(); + } - @Override - public boolean isGui3d() { - return renderer.useBlockLight(stack); - } + @Override + public boolean isGui3d() { + return renderer.useBlockLight(stack); + } - @Override - public boolean usesBlockLight() { - return renderer.useBlockLight(stack); - } + @Override + public boolean usesBlockLight() { + return renderer.useBlockLight(stack); + } - @Override - public boolean isCustomRenderer() { - return false; - } + @Override + public boolean isCustomRenderer() { + return false; + } - @Override - public TextureAtlasSprite getParticleIcon() { - return renderer.getParticleTexture(); - } + @Override + public TextureAtlasSprite getParticleIcon() { + return renderer.getParticleTexture(); + } - @Override - public ItemTransforms getTransforms() { - return ItemTransforms.NO_TRANSFORMS; - } + @Override + public ItemTransforms getTransforms() { + return ItemTransforms.NO_TRANSFORMS; + } + + @Override + public ItemOverrides getOverrides() { + return ItemOverrides.EMPTY; + } + }); + cir.setReturnValue(shapesCache.get(itemIndex)); + } - @Override - public ItemOverrides getOverrides() { - return ItemOverrides.EMPTY; - } - }); - cir.setReturnValue(shapesCache.get(itemIndex)); } } } From afb3e824e2e846aeaa7c981a0e108ba63cba3bf8 Mon Sep 17 00:00:00 2001 From: screret Date: Tue, 23 May 2023 15:46:37 +0300 Subject: [PATCH 3/3] fixed block state models crashing when in facades --- .../gtlib/client/renderer/impl/BlockStateRenderer.java | 10 ++++++---- .../gtlib/core/mixins/ItemModelShaperMixin.java | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/com/gregtechceu/gtlib/client/renderer/impl/BlockStateRenderer.java b/common/src/main/java/com/gregtechceu/gtlib/client/renderer/impl/BlockStateRenderer.java index 0623173..2dac83c 100644 --- a/common/src/main/java/com/gregtechceu/gtlib/client/renderer/impl/BlockStateRenderer.java +++ b/common/src/main/java/com/gregtechceu/gtlib/client/renderer/impl/BlockStateRenderer.java @@ -64,10 +64,12 @@ public BlockStateRenderer(BlockInfo blockInfo) { public BlockState getState(BlockState blockState) { BlockState state = getBlockInfo().getBlockState(); Direction facing = Direction.NORTH; - if (blockState.hasProperty(BlockStateProperties.FACING)) { - facing = blockState.getValue(BlockStateProperties.FACING); - } else if (blockState.hasProperty(BlockStateProperties.HORIZONTAL_FACING)) { - facing = blockState.getValue(BlockStateProperties.HORIZONTAL_FACING); + if (blockState != null) { + if (blockState.hasProperty(BlockStateProperties.FACING)) { + facing = blockState.getValue(BlockStateProperties.FACING); + } else if (blockState.hasProperty(BlockStateProperties.HORIZONTAL_FACING)) { + facing = blockState.getValue(BlockStateProperties.HORIZONTAL_FACING); + } } try { switch (facing) { diff --git a/common/src/main/java/com/gregtechceu/gtlib/core/mixins/ItemModelShaperMixin.java b/common/src/main/java/com/gregtechceu/gtlib/core/mixins/ItemModelShaperMixin.java index 936bf3b..0127010 100644 --- a/common/src/main/java/com/gregtechceu/gtlib/core/mixins/ItemModelShaperMixin.java +++ b/common/src/main/java/com/gregtechceu/gtlib/core/mixins/ItemModelShaperMixin.java @@ -53,7 +53,7 @@ public boolean useAmbientOcclusion() { @Override public boolean isGui3d() { - return renderer.useBlockLight(stack); + return true; } @Override