Skip to content

Instantly share code, notes, and snippets.

@skejeton
Last active March 17, 2020 11:21
Show Gist options
  • Save skejeton/8e2ba0b532e988ebbb1823c966e9e6d5 to your computer and use it in GitHub Desktop.
Save skejeton/8e2ba0b532e988ebbb1823c966e9e6d5 to your computer and use it in GitHub Desktop.
main
package io.github.ishidex2.fletching_table.mixin;
import com.mojang.blaze3d.systems.RenderSystem;
import io.github.ishidex2.fletching_table.RenderStuff;
import net.minecraft.block.BlockState;
import net.minecraft.block.FletchingTableBlock;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
@Mixin(FletchingTableBlock.class)
public class FletchingTableMixin {
private Identifier fletchingTableGUI = new Identifier("fletching_table", "textures/gui/fletching_table.png");
// @Inject(at = @At("INVOKE"), method = "onUse")
@Overwrite
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
RenderStuff.texturedRect(0, 0, 100, 75, fletchingTableGUI, 0, 0, 1, 1, 0xFFFFFFFF);
return ActionResult.SUCCESS;
}
}
package io.github.ishidex2.fletching_table;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.util.Identifier;
import org.lwjgl.opengl.GL11;
public class RenderStuff {
public static void texturedRect(int x, int y, int width, int height, Identifier texture, float u1, float v1, float u2, float v2, int color) {
MinecraftClient.getInstance().getTextureManager().bindTexture(texture);
//float scale = 0.00390625F;
System.out.println("Hi");
if (width <= 0) width = 1;
if (height <= 0) height = 1;
float r = (color >> 16 & 255) / 255.0F;
float g = (color >> 8 & 255) / 255.0F;
float b = (color & 255) / 255.0F;
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer();
RenderSystem.enableBlend();
RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcFactor.ONE, GlStateManager.DstFactor.ZERO);
RenderSystem.color4f(r, g, b, 1.0f);
buffer.begin(GL11.GL_QUADS, VertexFormats.POSITION_TEXTURE);
buffer.vertex(x, y + height, 0).texture(u1, v2).next();
buffer.vertex(x + width, y + height, 0).texture(u2, v2).next();
buffer.vertex(x + width, y, 0).texture(u2, v1).next();
buffer.vertex(x, y, 0).texture(u1, v1).next();
tessellator.draw();
RenderSystem.disableBlend();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment