Skip to content

Commit

Permalink
Added the porting folder to git.
Browse files Browse the repository at this point in the history
  • Loading branch information
ImCodist committed Oct 6, 2023
1 parent 2d8622d commit 258d6d7
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 4 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,3 @@ hs_err_*.log
replay_*.log
*.hprof
*.jfr

# my stuff

.porting
56 changes: 56 additions & 0 deletions .porting/1.19.4/QuickMenuButton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package xyz.imcodist.ui.components;

import io.wispforest.owo.ui.component.ButtonComponent;
import io.wispforest.owo.ui.core.Sizing;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.lwjgl.glfw.GLFW;

import java.util.function.Consumer;

public class QuickMenuButton extends ButtonComponent {
public ItemStack itemIcon;

public Consumer<QuickMenuButton> rightClick;

public QuickMenuButton(ItemStack icon, Consumer<ButtonComponent> onPress, Consumer<QuickMenuButton> onRightClick) {
super(Text.empty(), onPress);

itemIcon = icon;
rightClick = onRightClick;

sizing(Sizing.fixed(26), Sizing.fixed(26));
renderer(ButtonComponent.Renderer.texture(
new Identifier("quickmenu", "textures/switcher_buttons.png"),
0, 0,
64, 64
));
}

@Override
public void draw(MatrixStack context, int mouseX, int mouseY, float partialTicks, float delta) {
super.draw(context, mouseX, mouseY, partialTicks, delta);

// Draw the item inside the button.
if (itemIcon != null) {
MinecraftClient client = MinecraftClient.getInstance();
if (client == null) return;

ItemRenderer itemRenderer = client.getItemRenderer();
if (itemRenderer == null) return;

double divide = 5.2;
itemRenderer.renderGuiItemIcon(context, itemIcon, (int) (x() + (width() / divide)), (int) (y() + (height() / divide)));
}
}

@Override
public boolean onMouseDown(double mouseX, double mouseY, int button) {
if (button == GLFW.GLFW_MOUSE_BUTTON_2) rightClick.accept(this);
return super.onMouseDown(mouseX, mouseY, button);
}
}
82 changes: 82 additions & 0 deletions .porting/1.19.4/SwitcherSurface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package xyz.imcodist.ui.surfaces;

import com.mojang.blaze3d.systems.RenderSystem;
import io.wispforest.owo.ui.core.ParentComponent;
import io.wispforest.owo.ui.core.Surface;
import io.wispforest.owo.ui.util.Drawer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;

public class SwitcherSurface implements Surface {
boolean isHeader = false;

public SwitcherSurface(boolean header) {
isHeader = header;
}
public SwitcherSurface() {}

@Override
public void draw(MatrixStack context, ParentComponent component) {
int x = component.x();
int y = component.y();
int width = component.width();
int height = component.height();

int sourceX = (isHeader) ? 0 : 24;

RenderSystem.setShaderTexture(0, new Identifier("quickmenu", "textures/switcher_textures.png"));

// Make sure the background renders as transparent.
if (!isHeader) RenderSystem.enableBlend();
RenderSystem.setShaderColor(1, 1, 1, 1);

// Draws the texture as a 9 slice.
drawNineSlicedTexture(context, x, y, width, height, sourceX, 0, 6, 6, 12, 12, 52, 50);

// Undo previous render system changes.
if (!isHeader) RenderSystem.disableBlend();
RenderSystem.setShaderColor(1, 1, 1, 1);
}

public void drawNineSlicedTexture(MatrixStack context, int x, int y, int width, int height, int sourceX, int sourceY, int sideWidth, int sideHeight, int centerWidth, int centerHeight, int textureWidth, int textureHeight) {
// before someone goes and tells me this method was useless to make i got
// so frustrated trying to use the minecraft nine slice method but hated it a lot

// TOP AND BOTTOM
drawRepeatingTexture(context, x + sideWidth, y, sourceX + sideWidth, sourceY, centerWidth, sideHeight, textureWidth, textureHeight, width - (sideWidth * 2), sideHeight);
drawRepeatingTexture(context, x + sideWidth, y + height - sideHeight, sourceX + sideWidth, sourceY + sideHeight + centerHeight, centerWidth, sideHeight, textureWidth, textureHeight, width - (sideWidth * 2), sideHeight);

// LEFT AND RIGHT
drawRepeatingTexture(context, x, y + sideHeight, sourceX, sourceY + sideHeight, sideWidth, centerHeight, textureWidth, textureHeight, sideWidth, height - (sideHeight * 2));
drawRepeatingTexture(context, x + width - sideWidth, y + sideHeight, sourceX + sideWidth + centerWidth, sourceY + sideHeight, sideWidth, centerHeight, textureWidth, textureHeight, sideWidth, height - (sideHeight * 2));

// CORNERS
drawTexture(context, x, y, sourceX, sourceY, sideWidth, sideHeight, textureWidth, textureHeight);
drawTexture(context, x + width - sideWidth, y, sourceX + sideWidth + centerWidth, sourceY, sideWidth, sideHeight, textureWidth, textureHeight);
drawTexture(context, x, y + height - sideHeight, sourceX, sourceY + sideHeight + centerHeight, sideWidth, sideHeight, textureWidth, textureHeight);
drawTexture(context, x + width - sideWidth, y + height - sideHeight, sourceX + sideWidth + centerWidth, sourceY + sideHeight + centerHeight, sideWidth, sideHeight, textureWidth, textureHeight);

// CENTER
drawRepeatingTexture(context, x + sideWidth, y + sideHeight, sourceX + sideWidth, sourceY + sideHeight, centerWidth, centerHeight, textureWidth, textureHeight, width - (sideWidth * 2), height - (sideHeight * 2));
}

public void drawTexture(MatrixStack context, int x, int y, int sourceX, int sourceY, int sourceWidth, int sourceHeight, int textureWidth, int textureHeight) {
Drawer.drawTexture(context, x, y, sourceX, sourceY, sourceWidth, sourceHeight, textureWidth, textureHeight);
}

public void drawRepeatingTexture(MatrixStack context, int x, int y, int sourceX, int sourceY, int sourceWidth, int sourceHeight, int textureWidth, int textureHeight, int width, int height) {
double xMax = (double) width / (double) sourceWidth;
double yMax = (double) height / (double) sourceHeight;

for (int xi = 0; xi < Math.ceil(xMax); xi++) {
for (int yi = 0; yi < Math.ceil(yMax); yi++) {
int newWidth = sourceWidth;
int newHeight = sourceHeight;
if (Math.floor(xMax) == xi) newWidth *= (double) (xMax - xi);
if (Math.floor(yMax) == yi) newHeight *= (double) (yMax - yi);

drawTexture(context, x + (sourceWidth * xi), y + (sourceHeight * yi), sourceX, sourceY, newWidth, newHeight, textureWidth, textureHeight);
}
}
}
}
20 changes: 20 additions & 0 deletions .porting/1.19.4/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G
org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.19.4
yarn_mappings=1.19.4+build.2
loader_version=0.14.21

#Fabric api
fabric_version=0.84.0+1.19.4

# Mod Properties
mod_version=1.2.0
maven_group=xyz.imcodist
archives_base_name=quick-menu

# owo-lib
owo_version=0.10.6+1.19.4
2 changes: 2 additions & 0 deletions .porting/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## Porting
I have this folder to help me back port to specifically 1.19.4.

0 comments on commit 258d6d7

Please sign in to comment.