simple-tech

Minecraft: Better than Adventure! mod that adds simple blocks to automate tasks
git clone git://memoryshards.xyz/simple-tech.git
Log | Files | Refs | README | LICENSE

RenderBlocksMixin.java (5508B)


      1 package ambos.simpletech.mixin;
      2 
      3 import net.minecraft.client.render.RenderBlocks;
      4 import net.minecraft.client.render.Tessellator;
      5 import net.minecraft.client.render.TextureFX;
      6 import net.minecraft.core.Global;
      7 import net.minecraft.core.block.Block;
      8 import net.minecraft.core.util.helper.Side;
      9 import org.spongepowered.asm.mixin.Mixin;
     10 import org.spongepowered.asm.mixin.injection.At;
     11 import org.spongepowered.asm.mixin.injection.Inject;
     12 import org.spongepowered.asm.mixin.injection.ModifyVariable;
     13 import org.spongepowered.asm.mixin.injection.Redirect;
     14 import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
     15 import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
     16 
     17 import ambos.simpletech.block.BlockAllocator;
     18 import ambos.simpletech.block.BlockFan;
     19 import ambos.simpletech.block.BlockRedstoneNotGate;
     20 
     21 @Mixin(value = RenderBlocks.class, remap = false)
     22 final class RenderBlocksMixin {
     23     @Redirect(method = "renderBlockOnInventory(Lnet/minecraft/core/block/Block;IFF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/core/block/Block;getBlockTextureFromSideAndMetadata(Lnet/minecraft/core/util/helper/Side;I)I"), require = 0)
     24     private int changeBlockInventoryRender(Block block, Side side, int meta) {
     25         if (block instanceof BlockFan) {
     26             if (side == Side.SOUTH) {
     27                 return block.atlasIndices[Side.SOUTH.getId()]; // Returns front texture.
     28             }
     29 
     30             if (side == Side.BOTTOM) {
     31                 return block.atlasIndices[Side.TOP.getId()]; // Returns top/bottom texture.
     32             }
     33         }
     34 
     35         if (block instanceof BlockAllocator) {
     36             if (side == Side.TOP || side == Side.BOTTOM) {
     37                 return block.atlasIndices[Side.WEST.getId()]; // Returns top/bottom texture.
     38             }
     39 
     40             if (side == Side.SOUTH) {
     41                 return block.atlasIndices[Side.SOUTH.getId()]; // Returns front texture.
     42             }
     43 
     44             if (side == Side.NORTH) {
     45                 return block.atlasIndices[Side.NORTH.getId()]; // Returns back texture.
     46             }
     47         }
     48 
     49         return block.getBlockTextureFromSideAndMetadata(side, meta);
     50     }
     51 
     52     @ModifyVariable(method = "renderBlockByRenderType", at = @At("HEAD"), ordinal = 0, require = 0)
     53     private int changeRenderType(int renderType, Block block) {
     54         if (block instanceof BlockRedstoneNotGate) {
     55             return 15; // Use the repeater renderer as a base.
     56         }
     57 
     58         return renderType;
     59     }
     60 
     61     @Inject(method = "renderBlockRepeater", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/Tessellator;setColorOpaque_F(FFF)V", shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true, require = 0)
     62     private void renderBlockRedstoneGate(Block block, int i, int j, int k, CallbackInfoReturnable<Boolean> cir,
     63             int l, int i1, int j1, Tessellator tessellator) {
     64         if (block instanceof BlockRedstoneNotGate) {
     65             /* Gets metadata, tesselator and block brightness (captures locals). */
     66 
     67             /*
     68              * Skips torch rendering instructions (injects just after 'setColorOpaque_F'
     69              * method call).
     70              */
     71 
     72             int k1 = block.getBlockTextureFromSideAndMetadata(Side.TOP, l);
     73             int l1 = k1 % Global.TEXTURE_ATLAS_WIDTH_TILES * TextureFX.tileWidthTerrain;
     74             int i2 = k1 / Global.TEXTURE_ATLAS_WIDTH_TILES * TextureFX.tileWidthTerrain;
     75             double d5 = (double) ((float) l1 / (float) (TextureFX.tileWidthTerrain * Global.TEXTURE_ATLAS_WIDTH_TILES));
     76             double d6 = (double) (((float) l1 + ((float) TextureFX.tileWidthTerrain - 0.01F))
     77                     / (float) (TextureFX.tileWidthTerrain * Global.TEXTURE_ATLAS_WIDTH_TILES));
     78             double d7 = (double) ((float) i2 / (float) (TextureFX.tileWidthTerrain * Global.TEXTURE_ATLAS_WIDTH_TILES));
     79             double d8 = (double) (((float) i2 + ((float) TextureFX.tileWidthTerrain - 0.01F))
     80                     / (float) (TextureFX.tileWidthTerrain * Global.TEXTURE_ATLAS_WIDTH_TILES));
     81             float f1 = 0.125F;
     82             float f2 = (float) (i + 1);
     83             float f3 = (float) (i + 1);
     84             float f4 = (float) (i + 0);
     85             float f5 = (float) (i + 0);
     86             float f6 = (float) (k + 0);
     87             float f7 = (float) (k + 1);
     88             float f8 = (float) (k + 1);
     89             float f9 = (float) (k + 0);
     90             float f10 = (float) j + f1;
     91             if (i1 == 2) {
     92                 f2 = f3 = (float) (i + 0);
     93                 f4 = f5 = (float) (i + 1);
     94                 f6 = f9 = (float) (k + 1);
     95                 f7 = f8 = (float) (k + 0);
     96             } else if (i1 == 3) {
     97                 f2 = f5 = (float) (i + 0);
     98                 f3 = f4 = (float) (i + 1);
     99                 f6 = f7 = (float) (k + 0);
    100                 f8 = f9 = (float) (k + 1);
    101             } else if (i1 == 1) {
    102                 f2 = f5 = (float) (i + 1);
    103                 f3 = f4 = (float) (i + 0);
    104                 f6 = f7 = (float) (k + 1);
    105                 f8 = f9 = (float) (k + 0);
    106             }
    107 
    108             tessellator.addVertexWithUV((double) f5, (double) f10, (double) f9, d5, d7);
    109             tessellator.addVertexWithUV((double) f4, (double) f10, (double) f8, d5, d8);
    110             tessellator.addVertexWithUV((double) f3, (double) f10, (double) f7, d6, d8);
    111             tessellator.addVertexWithUV((double) f2, (double) f10, (double) f6, d6, d7);
    112 
    113             cir.setReturnValue(true);
    114         }
    115     }
    116 }