|
18 | 18 |
|
19 | 19 | package io.github.axolotlclient.oldanimations.mixin; |
20 | 20 |
|
| 21 | +import com.google.common.collect.Lists; |
| 22 | +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; |
| 23 | +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; |
| 24 | +import io.github.axolotlclient.oldanimations.config.OldAnimationsConfig; |
| 25 | +import net.minecraft.client.render.model.block.BlockElement; |
| 26 | +import net.minecraft.client.render.model.block.BlockElementFace; |
| 27 | +import net.minecraft.client.render.model.block.BlockElementTexture; |
21 | 28 | import net.minecraft.client.render.model.block.ItemModelGenerator; |
| 29 | +import net.minecraft.client.render.texture.TextureAtlasSprite; |
| 30 | +import net.minecraft.util.math.Direction; |
| 31 | +import org.lwjgl.util.vector.Vector3f; |
22 | 32 | import org.spongepowered.asm.mixin.Mixin; |
| 33 | +import org.spongepowered.asm.mixin.Shadow; |
| 34 | +import org.spongepowered.asm.mixin.Unique; |
| 35 | +import org.spongepowered.asm.mixin.injection.At; |
| 36 | + |
| 37 | +import java.util.Collections; |
| 38 | +import java.util.List; |
23 | 39 |
|
24 | 40 | @Mixin(ItemModelGenerator.class /* unmapped - C_4311621 */) |
25 | 41 | public abstract class ItemModelGeneratorMixin { |
26 | 42 |
|
| 43 | + @Shadow |
| 44 | + protected abstract List<BlockElement> addSideElements(TextureAtlasSprite textureAtlasSprite, String string, int i); |
| 45 | + |
| 46 | + @WrapOperation(method = "processFrames", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/model/block/ItemModelGenerator;addSideElements(Lnet/minecraft/client/render/texture/TextureAtlasSprite;Ljava/lang/String;I)Ljava/util/List;")) |
| 47 | + private List<BlockElement> axolotlclient$itemModelSideQuadRendering(ItemModelGenerator instance, TextureAtlasSprite textureAtlasSprite, String string, int i, Operation<List<BlockElement>> original) { |
| 48 | + if (OldAnimationsConfig.isEnabled() && OldAnimationsConfig.instance.itemModelSideQuadRendering.get()) { |
| 49 | + return axolotlclient$oldAddSideElements(textureAtlasSprite, string, i); |
| 50 | + } |
| 51 | + return addSideElements(textureAtlasSprite, string, i); |
| 52 | + } |
| 53 | + |
| 54 | + @Unique |
| 55 | + private List<BlockElement> axolotlclient$oldAddSideElements(TextureAtlasSprite textureAtlasSprite, String string, int i) { |
| 56 | + List<BlockElement> list = Lists.newArrayList(); |
| 57 | + |
| 58 | + int width = textureAtlasSprite.getWidth(); |
| 59 | + int height = textureAtlasSprite.getHeight(); |
| 60 | + float uMin = 0.0F; |
| 61 | + float vMin = 0.0F; |
| 62 | + float uMax = 16.0F; |
| 63 | + float vMax = 16.0F; |
| 64 | + |
| 65 | + float f = 0.5F * (uMin - uMax) / width; |
| 66 | + float g = 0.5F * (vMax - vMin) / height; |
| 67 | + |
| 68 | + for (int i10 = 0; i10 < width; i10++) { |
| 69 | + float h = (float) i10 / width; |
| 70 | + float l = uMin + (uMax - uMin) * ((float) i10 / width) - f; |
| 71 | + list.add(new BlockElement( |
| 72 | + new Vector3f(h * 16.0F, 0.0F, 7.5F), new Vector3f(h * 16.0F, 16.0F, 8.5F), |
| 73 | + Collections.singletonMap( |
| 74 | + Direction.WEST, |
| 75 | + new BlockElementFace(null, i, string, new BlockElementTexture(new float[]{l, vMin, l, vMax}, 0)) |
| 76 | + ), null, true |
| 77 | + )); |
| 78 | + } |
| 79 | + |
| 80 | + for (int var14 = 0; var14 < width; var14++) { |
| 81 | + float i12 = (float) var14 / width; |
| 82 | + float m = uMin + (uMax - uMin) * i12 - f; |
| 83 | + float q = i12 + 1.0F / width; |
| 84 | + list.add(new BlockElement( |
| 85 | + new Vector3f(q * 16.0F, 0.0F, 7.5F), new Vector3f(q * 16.0F, 16.0F, 8.5F), |
| 86 | + Collections.singletonMap( |
| 87 | + Direction.EAST, |
| 88 | + new BlockElementFace(null, i, string, new BlockElementTexture(new float[]{m, vMin, m, vMax}, 0)) |
| 89 | + ), null, true |
| 90 | + )); |
| 91 | + } |
| 92 | + |
| 93 | + for (int var15 = 0; var15 < height; var15++) { |
| 94 | + float j = (float) var15 / height; |
| 95 | + float n = vMax + (vMin - vMax) * j - g; |
| 96 | + float r = j + 1.0F / height; |
| 97 | + list.add(new BlockElement( |
| 98 | + new Vector3f(0.0F, r * 16.0F, 7.5F), new Vector3f(16.0F, r * 16.0F, 8.5F), |
| 99 | + Collections.singletonMap( |
| 100 | + Direction.UP, |
| 101 | + new BlockElementFace(null, i, string, new BlockElementTexture(new float[]{uMin, n, uMax, n}, 0)) |
| 102 | + ), null, true |
| 103 | + )); |
| 104 | + } |
| 105 | + |
| 106 | + for (int var16 = 0; var16 < height; var16++) { |
| 107 | + float k = (float) var16 / height; |
| 108 | + float o = vMax + (vMin - vMax) * ((float) var16 / height) - g; |
| 109 | + list.add(new BlockElement( |
| 110 | + new Vector3f(0.0F, k * 16.0F, 7.5F), new Vector3f(16.0F, k * 16.0F, 8.5F), |
| 111 | + Collections.singletonMap( |
| 112 | + Direction.DOWN, |
| 113 | + new BlockElementFace(null, i, string, new BlockElementTexture(new float[]{uMin, o, uMax, o}, 0)) |
| 114 | + ), null, true |
| 115 | + )); |
| 116 | + } |
| 117 | + |
| 118 | + return list; |
| 119 | + } |
27 | 120 | } |
0 commit comments