Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

fixed ae2 facade models rendering with missing texture #2

Open
wants to merge 3 commits into
base: 1.19.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
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<BakedModel> 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<BakedModel> cir) {
if (stack.getItem() instanceof IItemRendererProvider provider) {
IRenderer renderer = provider.getRenderer(stack);
if (renderer != null) {
int itemIndex = getIndex(stack.getItem());

shapesCache.putIfAbsent(itemIndex, new BakedModel() {
@Override
public List<BakedQuad> 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 true;
}

@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));
}

}
}
}
1 change: 1 addition & 0 deletions common/src/main/resources/gtlib-common.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"client": [
"BlockEntityRendererDispatcherMixin",
"BlockModelShaperMixin",
"ItemModelShaperMixin",
"ItemRendererMixin",
"LanguageMixin",
"ModelBakeryMixin",
Expand Down