Fixed grass block item being rendered with its side texture on top

master
Wynd 2023-08-08 17:13:39 +03:00
parent 83f794e33e
commit da8f24a71a
4 changed files with 102 additions and 12 deletions

View File

@ -1,14 +1,25 @@
package xyz.pixelatedw.finalbeta;
import java.lang.management.ManagementFactory;
import java.util.Random;
import java.lang.reflect.Field;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.Player;
public class WyHelper {
public static boolean isDebug()
{
public static Minecraft getInstance() {
try {
Field f = Minecraft.class.getDeclaredField("instance");
f.setAccessible(true);
return (Minecraft) f.get(null);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
public static boolean isDebug() {
return ManagementFactory.getRuntimeMXBean().getInputArguments().toString().indexOf("-agentlib:jdwp") > 0;
}
@ -21,7 +32,8 @@ public class WyHelper {
}
public static void cheatCommand(Player player) {
Random rand = new Random();
// player.dropItem(new ItemInstance(Tile.SNOW));
// Random rand = new Random();
// player.level.playSound(player, "random.break", 1, (rand.nextFloat() - rand.nextFloat()) * 0.2F + 1.0F);
// player.dropItem(new ItemInstance(ItemType.hatchetDiamond, 1), false);

View File

@ -0,0 +1,26 @@
package xyz.pixelatedw.finalbeta.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import net.minecraft.tile.Tile;
@Mixin(Tile.class)
public class TileMixin {
@Inject(method = "getTextureForSide(I)I", at = @At("HEAD"), cancellable = true)
public void getTextureForSide(int i, CallbackInfoReturnable<Integer> ci) {
Tile tile = (Tile) (Object) this;
if (tile.id == Tile.GRASS.id) {
if (i == 1) {
ci.setReturnValue(0);
} else if (i == 0) {
ci.setReturnValue(2);
} else {
ci.setReturnValue(tile.tex);
}
}
}
}

View File

@ -1,11 +1,13 @@
package xyz.pixelatedw.finalbeta.mixin;
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.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.client.colour.GrassColour;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.TileRenderer;
import net.minecraft.tile.Tile;
@ -16,6 +18,55 @@ public class TileRendererMixin {
@Shadow
private int field_83;
// Grass block texture using side textures for top fix
@Inject(method = "method_48", at = @At("HEAD"), cancellable = true)
public void grassBlockRenderer(Tile arg, int i, float f, CallbackInfo ci) {
// Normal Blocks are rendered using this the 0 type, we're using this
// just as a safenet in case the tile is not grass
int type = arg.method_1621();
if (arg.id == Tile.GRASS.id && type == 0) {
Tessellator tess = Tessellator.INSTANCE;
TileRenderer renderer = (TileRenderer) (Object) this;
arg.method_1605();
GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
tess.start();
tess.method_1697(0.0F, -1.0F, 0.0F);
renderer.method_46(arg, 0.0D, 0.0D, 0.0D, arg.getTextureForSide(0, i));
tess.draw();
// This bit controls the top texture specifically
float r = (GrassColour.getColour(0.96, 0.44) >> 16 & 255) / 255.0F;
float g = (GrassColour.getColour(0.96, 0.44) >> 8 & 255) / 255.0F;
float b = (GrassColour.getColour(0.96, 0.44) & 255) / 255.0F;
tess.start();
tess.method_1697(0.0F, 1.0F, 0.0F);
tess.colour(r * f, g * f, b * f);
renderer.method_55(arg, 0.0D, 0.0D, 0.0D, arg.getTextureForSide(1, i));
tess.draw();
tess.start();
tess.method_1697(0.0F, 0.0F, -1.0F);
renderer.method_61(arg, 0.0D, 0.0D, 0.0D, arg.getTextureForSide(2, i));
tess.draw();
tess.start();
tess.method_1697(0.0F, 0.0F, 1.0F);
renderer.method_65(arg, 0.0D, 0.0D, 0.0D, arg.getTextureForSide(3, i));
tess.draw();
tess.start();
tess.method_1697(-1.0F, 0.0F, 0.0F);
renderer.method_67(arg, 0.0D, 0.0D, 0.0D, arg.getTextureForSide(4, i));
tess.draw();
tess.start();
tess.method_1697(1.0F, 0.0F, 0.0F);
renderer.method_69(arg, 0.0D, 0.0D, 0.0D, arg.getTextureForSide(5, i));
tess.draw();
GL11.glTranslatef(0.5F, 0.5F, 0.5F);
ci.cancel();
}
}
// Torch rendering with a bottom texture fix
@Inject(method = "method_45", at = @At("HEAD"), cancellable = true)
public void torchRenderer(Tile arg, double x, double y, double z, double w, double h, CallbackInfo ci) {
Tessellator tess = Tessellator.INSTANCE;

View File

@ -26,7 +26,8 @@
"LivingEntityMixin",
"FurnaceEntityMixin",
"WorldRendererMixin",
"VideoSettingsScreenMixin"
"VideoSettingsScreenMixin",
"TileMixin"
],
"injectors": {
"defaultRequire": 1