generated from babric/babric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b8de9e
commit 04d0ae3
Showing
1 changed file
with
81 additions
and
80 deletions.
There are no files selected for viewing
161 changes: 81 additions & 80 deletions
161
...tterthanupdates/apron/stapi/compat/mixin/client/buildcraft/transport/RenderPipeMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,108 +1,109 @@ | ||
package io.github.betterthanupdates.apron.stapi.compat.mixin.client.buildcraft.transport; | ||
|
||
import buildcraft.api.EntityPassiveItem; | ||
import buildcraft.transport.RenderPipe; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import com.llamalad7.mixinextras.sugar.Local; | ||
import com.llamalad7.mixinextras.sugar.Share; | ||
import com.llamalad7.mixinextras.sugar.ref.LocalRef; | ||
import io.github.betterthanupdates.apron.stapi.ApronStAPICompat; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.client.render.Tessellator; | ||
import net.minecraft.client.render.block.BlockRenderer; | ||
import net.minecraft.client.render.entity.EntityRenderDispatcher; | ||
import net.minecraft.item.BlockItem; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.modificationstation.stationapi.api.client.StationRenderAPI; | ||
import net.modificationstation.stationapi.api.client.texture.Sprite; | ||
import net.modificationstation.stationapi.api.client.texture.SpriteAtlasTexture; | ||
import net.modificationstation.stationapi.api.client.texture.atlas.Atlases; | ||
import net.modificationstation.stationapi.api.registry.Identifier; | ||
import org.lwjgl.opengl.GL11; | ||
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.Redirect; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(value = RenderPipe.class, remap = false) | ||
public class RenderPipeMixin { | ||
@Redirect(method = "doRenderItem", remap = false, | ||
at = @At(value = "INVOKE", remap = false, | ||
target = "Lforge/MinecraftForgeClient;bindTexture(Ljava/lang/String;)V", ordinal = 0)) | ||
private void fixBlockTexture0(String s, @Local(ordinal = 0) Block block) { | ||
if (block != null) { | ||
SpriteAtlasTexture atlas = StationRenderAPI.getBakedModelManager().getAtlas(Atlases.GAME_ATLAS_TEXTURE); | ||
atlas.bindTexture(); | ||
} | ||
} | ||
@Redirect(method = "doRenderItem", remap = false, | ||
at = @At(value = "INVOKE", remap = false, | ||
target = "Lforge/MinecraftForgeClient;bindTexture(Ljava/lang/String;)V", ordinal = 1)) | ||
private void fixBlockTexture1(String s, @Local(ordinal = 0) Block block) { | ||
if (block != null) { | ||
@Shadow(remap = false) | ||
private BlockRenderer renderBlocks; | ||
|
||
/** | ||
* @author CatCore | ||
* @reason Buildcraft can't know which item is a block accurately on its own | ||
*/ | ||
@Inject(method = "doRenderItem", at = @At("HEAD"), cancellable = true, remap = false) | ||
private void apron$doRenderItem(EntityPassiveItem entityitem, double x, double y, double z, double brigntess, CallbackInfo ci) { | ||
if (entityitem != null && entityitem.item != null) { | ||
ItemStack itemstack = entityitem.item; | ||
GL11.glPushMatrix(); | ||
byte byte0 = 1; | ||
if (entityitem.item.count > 1) { | ||
byte0 = 2; | ||
} | ||
|
||
if (entityitem.item.count > 5) { | ||
byte0 = 3; | ||
} | ||
|
||
if (entityitem.item.count > 20) { | ||
byte0 = 4; | ||
} | ||
|
||
GL11.glTranslatef((float)x, (float)y, (float)z); | ||
GL11.glEnable(32826); | ||
|
||
Item item = itemstack.getItem(); | ||
SpriteAtlasTexture atlas = StationRenderAPI.getBakedModelManager().getAtlas(Atlases.GAME_ATLAS_TEXTURE); | ||
atlas.bindTexture(); | ||
} | ||
} | ||
|
||
@Redirect(method = "doRenderItem", remap = false, | ||
at = @At(value = "INVOKE", remap = false, | ||
target = "Lforge/MinecraftForgeClient;bindTexture(Ljava/lang/String;)V", ordinal = 2)) | ||
private void fixBindItemTexture0(String s, @Local(ordinal = 0)ItemStack stack, @Share("sprite")LocalRef<Sprite> ref) { | ||
this.apron$fixBindItemTexture(stack, ref); | ||
} | ||
if (item instanceof BlockItem blockItem && BlockRenderer.method_42(blockItem.getBlock().getRenderType())) { | ||
GL11.glTranslatef(0.0F, 0.25F, 0.0F); | ||
|
||
@Redirect(method = "doRenderItem", remap = false, | ||
at = @At(value = "INVOKE", remap = false, | ||
target = "Lforge/MinecraftForgeClient;bindTexture(Ljava/lang/String;)V", ordinal = 3)) | ||
private void fixBindItemTexture1(String s, @Local(ordinal = 0)ItemStack stack, @Share("sprite")LocalRef<Sprite> ref) { | ||
this.apron$fixBindItemTexture(stack, ref); | ||
} | ||
float f4 = 0.25F; | ||
if (!blockItem.getBlock().isFullCube() && blockItem.getBlock() != Block.STONE_SLAB) { | ||
f4 = 0.5F; | ||
} | ||
|
||
@Redirect(method = "doRenderItem", remap = false, | ||
at = @At(value = "INVOKE", remap = false, | ||
target = "Lforge/MinecraftForgeClient;bindTexture(Ljava/lang/String;)V", ordinal = 4)) | ||
private void fixBindItemTexture2(String s, @Local(ordinal = 0)ItemStack stack, @Share("sprite")LocalRef<Sprite> ref) { | ||
this.apron$fixBindItemTexture(stack, ref); | ||
} | ||
GL11.glScalef(f4, f4, f4); | ||
|
||
private void apron$fixBindItemTexture(ItemStack stack, LocalRef<Sprite> ref) { | ||
SpriteAtlasTexture atlas = StationRenderAPI.getBakedModelManager().getAtlas(Atlases.GAME_ATLAS_TEXTURE); | ||
atlas.bindTexture(); | ||
for(int j = 0; j < byte0; ++j) { | ||
GL11.glPushMatrix(); | ||
this.renderBlocks.method_48(blockItem.getBlock(), itemstack.getMeta(), (float)brigntess); | ||
GL11.glPopMatrix(); | ||
} | ||
} else { | ||
GL11.glTranslatef(0.0F, 0.1F, 0.0F); | ||
GL11.glScalef(0.5F, 0.5F, 0.5F); | ||
|
||
ref.set(atlas.getSprite( | ||
stack.getItem().getAtlas().getTexture( | ||
stack.getItemTexture() | ||
).getId() | ||
)); | ||
} | ||
int i = ApronStAPICompat.fixItemTexture(itemstack.getItemTexture(), item); | ||
Identifier textureId = item.getAtlas().getTexture(i).getId(); | ||
Sprite sprite = atlas.getSprite( | ||
textureId | ||
); | ||
|
||
@WrapOperation(method = "doRenderItem", remap = false, | ||
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/Tessellator;vertex(DDDDD)V", | ||
ordinal = 0, remap = true)) | ||
private void fixItemTexture0(Tessellator instance, double x, double y, double z, double u, double v, | ||
Operation<Void> operation, @Share("sprite") LocalRef<Sprite> ref) { | ||
Sprite sprite = ref.get(); | ||
operation.call(instance, x, y, z, (double)sprite.getMinU(), (double)sprite.getMaxV()); | ||
} | ||
Tessellator tessellator = Tessellator.INSTANCE; | ||
float f12 = 1.0F; | ||
float f13 = 0.5F; | ||
float f14 = 0.25F; | ||
|
||
@WrapOperation(method = "doRenderItem", remap = false, | ||
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/Tessellator;vertex(DDDDD)V", | ||
ordinal = 1)) | ||
private void fixItemTexture1(Tessellator instance, double x, double y, double z, double u, double v, | ||
Operation<Void> operation, @Share("sprite")LocalRef<Sprite> ref) { | ||
Sprite sprite = ref.get(); | ||
operation.call(instance, x, y, z, (double)sprite.getMaxU(), (double)sprite.getMaxV()); | ||
} | ||
for(int k = 0; k < byte0; ++k) { | ||
GL11.glPushMatrix(); | ||
GL11.glRotatef(180.0F - EntityRenderDispatcher.INSTANCE.field_2497, 0.0F, 1.0F, 0.0F); | ||
tessellator.start(); | ||
tessellator.setNormal(0.0F, 1.0F, 0.0F); | ||
tessellator.vertex((double)(0.0F - f13), (double)(0.0F - f14), 0.0, (double)sprite.getMinU(), (double)sprite.getMaxV()); | ||
tessellator.vertex((double)(f12 - f13), (double)(0.0F - f14), 0.0, (double)sprite.getMaxU(), (double)sprite.getMaxV()); | ||
tessellator.vertex((double)(f12 - f13), (double)(1.0F - f14), 0.0, (double)sprite.getMaxU(), (double)sprite.getMinV()); | ||
tessellator.vertex((double)(0.0F - f13), (double)(1.0F - f14), 0.0, (double)sprite.getMinU(), (double)sprite.getMinV()); | ||
tessellator.tessellate(); | ||
GL11.glPopMatrix(); | ||
} | ||
} | ||
|
||
@WrapOperation(method = "doRenderItem", remap = false, | ||
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/Tessellator;vertex(DDDDD)V", | ||
ordinal = 2)) | ||
private void fixItemTexture2(Tessellator instance, double x, double y, double z, double u, double v, | ||
Operation<Void> operation, @Share("sprite")LocalRef<Sprite> ref) { | ||
Sprite sprite = ref.get(); | ||
operation.call(instance, x, y, z, (double)sprite.getMaxU(), (double)sprite.getMinV()); | ||
} | ||
GL11.glDisable(32826); | ||
GL11.glPopMatrix(); | ||
} | ||
|
||
@WrapOperation(method = "doRenderItem", remap = false, | ||
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/Tessellator;vertex(DDDDD)V", | ||
ordinal = 3)) | ||
private void fixItemTexture3(Tessellator instance, double x, double y, double z, double u, double v, | ||
Operation<Void> operation, @Share("sprite")LocalRef<Sprite> ref) { | ||
Sprite sprite = ref.get(); | ||
operation.call(instance, x, y, z, (double)sprite.getMinU(), (double)sprite.getMinV()); | ||
ci.cancel(); | ||
} | ||
} |