|
| 1 | +/* |
| 2 | + * Copyright 2025 Lambda |
| 3 | + * |
| 4 | + * This program is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | + |
| 18 | +package com.lambda.module.modules.render |
| 19 | + |
| 20 | +import com.lambda.graphics.buffer.pixel.PixelBuffer |
| 21 | +import com.lambda.graphics.texture.Texture |
| 22 | +import com.lambda.module.Module |
| 23 | +import com.lambda.module.tag.ModuleTag |
| 24 | +import com.lambda.threading.runSafe |
| 25 | +import com.lambda.util.math.Vec2d |
| 26 | +import net.minecraft.item.FilledMapItem |
| 27 | +import net.minecraft.item.ItemStack |
| 28 | +import org.lwjgl.BufferUtils |
| 29 | +import org.lwjgl.opengl.GL11.GL_RGB |
| 30 | +import org.lwjgl.opengl.GL11.GL_RGBA |
| 31 | +import org.lwjgl.opengl.GL45C.GL_TEXTURE_2D |
| 32 | +import org.lwjgl.opengl.GL45C.glBindTexture |
| 33 | + |
| 34 | +object MapPreview : Module( |
| 35 | + name = "MapPreview", |
| 36 | + description = "Preview maps in your inventory", |
| 37 | + defaultTags = setOf(ModuleTag.RENDER) |
| 38 | +) { |
| 39 | + private val scale by setting("Scale", 0.7, 0.1..1.0, 0.05) |
| 40 | + |
| 41 | + private val buffer = BufferUtils.createByteBuffer(128*128) |
| 42 | + private val texture = Texture(buffer, 128, 128, format = GL_RGB, levels = 1) |
| 43 | + private val pbo = PixelBuffer(texture) |
| 44 | + |
| 45 | + @JvmStatic |
| 46 | + fun drawMap(stack: ItemStack, x: Int, y: Int) = runSafe { |
| 47 | + val state = FilledMapItem.getMapState(stack, world) ?: return@runSafe |
| 48 | + buffer.put(state.colors) |
| 49 | + buffer.flip() |
| 50 | + |
| 51 | + val base = Vec2d(x, y) |
| 52 | + |
| 53 | + texture.bind() |
| 54 | + texture.update(buffer, 128, 128) |
| 55 | + |
| 56 | + texture.draw(base, scale) |
| 57 | + } |
| 58 | +} |
0 commit comments