|
@@ -1,62 +1,33 @@
|
|
package me.km.networking;
|
|
package me.km.networking;
|
|
|
|
|
|
import com.mojang.blaze3d.systems.RenderSystem;
|
|
import com.mojang.blaze3d.systems.RenderSystem;
|
|
-import me.km.KajetansMod;
|
|
|
|
import me.km.utils.ClientReflectionUtils;
|
|
import me.km.utils.ClientReflectionUtils;
|
|
|
|
+import me.km.utils.Mapper;
|
|
import net.minecraft.client.Minecraft;
|
|
import net.minecraft.client.Minecraft;
|
|
import net.minecraft.client.gui.AbstractGui;
|
|
import net.minecraft.client.gui.AbstractGui;
|
|
-import net.minecraft.client.gui.FontRenderer;
|
|
+import net.minecraft.client.renderer.ItemRenderer;
|
|
|
|
+import net.minecraft.item.Item;
|
|
|
|
+import net.minecraft.item.ItemStack;
|
|
import net.minecraft.util.ResourceLocation;
|
|
import net.minecraft.util.ResourceLocation;
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
|
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
@OnlyIn(Dist.CLIENT)
|
|
public class ItemStackDisplayGui extends AbstractGui {
|
|
public class ItemStackDisplayGui extends AbstractGui {
|
|
- private static final ResourceLocation CUSTOM_ICONS = new ResourceLocation(KajetansMod.MODID, "textures/gui/itemstacks.png");
|
|
+ private static final ResourceLocation WIDGETS_TEX_PATH = new ResourceLocation("textures/gui/widgets.png");
|
|
|
|
|
|
public final static ItemStackDisplayGui INSTANCE = new ItemStackDisplayGui(Minecraft.getInstance());
|
|
public final static ItemStackDisplayGui INSTANCE = new ItemStackDisplayGui(Minecraft.getInstance());
|
|
|
|
|
|
- private static class Stack {
|
|
|
|
- private int x = -1;
|
|
|
|
- private int y = 0;
|
|
|
|
- private int width = 0;
|
|
|
|
- private int height = 0;
|
|
|
|
- private String text = "";
|
|
|
|
-
|
|
|
|
- public void setIcon(int index, int c) {
|
|
|
|
- if(index < 0) {
|
|
|
|
- clear();
|
|
|
|
- } else if(index >= 0 && index < 104) {
|
|
|
|
- x = (index % 52) * 16 + 192;
|
|
|
|
- y = (index / 52) * 16;
|
|
|
|
- width = 16;
|
|
|
|
- height = 16;
|
|
|
|
- text = (c == 0) ? "" : String.valueOf(c);
|
|
|
|
- } else {
|
|
|
|
- index -= 104;
|
|
|
|
- x = (index % 16) * 64;
|
|
|
|
- y = (index / 16) * 64 + 32;
|
|
|
|
- width = 64;
|
|
|
|
- height = 64;
|
|
|
|
- text = null;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void clear() {
|
|
|
|
- x = -1;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
private final Minecraft mc;
|
|
private final Minecraft mc;
|
|
|
|
|
|
- private final Stack[] icons = new Stack[9];
|
|
+ private final ItemStack[] icons = new ItemStack[9];
|
|
private boolean inactive = true;
|
|
private boolean inactive = true;
|
|
|
|
|
|
public ItemStackDisplayGui(Minecraft mc) {
|
|
public ItemStackDisplayGui(Minecraft mc) {
|
|
this.mc = mc;
|
|
this.mc = mc;
|
|
|
|
|
|
for(int i = 0; i < icons.length; i++) {
|
|
for(int i = 0; i < icons.length; i++) {
|
|
- icons[i] = new Stack();
|
|
+ icons[i] = ItemStack.EMPTY;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -64,15 +35,18 @@ public class ItemStackDisplayGui extends AbstractGui {
|
|
this.inactive = !active;
|
|
this.inactive = !active;
|
|
}
|
|
}
|
|
|
|
|
|
- public void setIcon(int index, int i, int count) {
|
|
+ public void setIcon(int index, String name) {
|
|
if(index >= 0 && index < 9) {
|
|
if(index >= 0 && index < 9) {
|
|
- icons[index].setIcon(i, count);
|
|
+ Item item = Mapper.getItem(name);
|
|
|
|
+ if(item != null) {
|
|
|
|
+ icons[index] = new ItemStack(item);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public final void clear() {
|
|
public final void clear() {
|
|
- for(Stack stack : icons) {
|
|
+ for(int i = 0; i < icons.length; i++) {
|
|
- stack.clear();
|
|
+ icons[i] = ItemStack.EMPTY;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -80,44 +54,30 @@ public class ItemStackDisplayGui extends AbstractGui {
|
|
if(inactive) {
|
|
if(inactive) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
-
|
|
+
|
|
- RenderSystem.enableBlend();
|
|
|
|
- RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
|
|
|
-
|
|
|
|
- mc.getTextureManager().bindTexture(CUSTOM_ICONS);
|
|
|
|
-
|
|
|
|
int screenWidth = (mc.getMainWindow().getScaledWidth() >> 1) - 91;
|
|
int screenWidth = (mc.getMainWindow().getScaledWidth() >> 1) - 91;
|
|
int y = 3;
|
|
int y = 3;
|
|
-
|
|
|
|
if(ClientReflectionUtils.isRenderingBossBar()) {
|
|
if(ClientReflectionUtils.isRenderingBossBar()) {
|
|
y += 20;
|
|
y += 20;
|
|
}
|
|
}
|
|
-
|
|
+
|
|
- blit(screenWidth, y - 3, 0, 0, 182, 22, 1024, 1024);
|
|
+ RenderSystem.enableBlend();
|
|
-
|
|
+ RenderSystem.color4f(1.0f, 1.0f, 1.0f, 1.0f);
|
|
|
|
+ mc.getTextureManager().bindTexture(WIDGETS_TEX_PATH);
|
|
|
|
+ int oldBlitOffset = this.getBlitOffset();
|
|
|
|
+ setBlitOffset(-90);
|
|
|
|
+ blit(screenWidth, y, 0, 0, 182, 22);
|
|
|
|
+ setBlitOffset(oldBlitOffset);
|
|
|
|
+
|
|
|
|
+ ItemRenderer ir = mc.getItemRenderer();
|
|
int i = 0;
|
|
int i = 0;
|
|
for(int x = 3; x < 164; x += 20) {
|
|
for(int x = 3; x < 164; x += 20) {
|
|
- Stack s = icons[i];
|
|
+ if(!icons[i].isEmpty()) {
|
|
- if(s.x != -1) {
|
|
+ ir.renderItemAndEffectIntoGUI(mc.player, icons[i], screenWidth + x, y);
|
|
- blit(screenWidth + x, y, 16, 16, s.x, s.y, s.width, s.height, 1024, 1024);
|
|
+ ir.renderItemOverlayIntoGUI(this.mc.fontRenderer, icons[i], screenWidth + x, y, km.getKeyDescription(i));
|
|
}
|
|
}
|
|
i++;
|
|
i++;
|
|
}
|
|
}
|
|
-
|
|
|
|
RenderSystem.disableBlend();
|
|
RenderSystem.disableBlend();
|
|
-
|
|
|
|
- FontRenderer fr = mc.fontRenderer;
|
|
|
|
- i = 0;
|
|
|
|
- for(int x = 20; x < 181; x += 20) {
|
|
|
|
- if(icons[i].x != -1) {
|
|
|
|
- if(icons[i].text == null) {
|
|
|
|
- String s = km.getKeyDescription(i);
|
|
|
|
- fr.drawStringWithShadow(s, (float) (screenWidth + x - fr.getStringWidth(s)), y + 9, 16777215);
|
|
|
|
- } else if(!icons[i].text.isEmpty()) {
|
|
|
|
- fr.drawStringWithShadow(icons[i].text, (float) (screenWidth + x - fr.getStringWidth(icons[i].text)), y + 9, 16777215);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- i++;
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|