Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .gradle/8.1.1/checksums/checksums.lock
Binary file not shown.
Binary file added .gradle/8.1.1/checksums/md5-checksums.bin
Binary file not shown.
Binary file added .gradle/8.1.1/checksums/sha1-checksums.bin
Binary file not shown.
Binary file not shown.
Empty file.
Binary file modified .gradle/8.1.1/executionHistory/executionHistory.bin
Binary file not shown.
Binary file not shown.
Binary file added .gradle/8.1.1/fileChanges/last-build.bin
Binary file not shown.
Binary file modified .gradle/8.1.1/fileHashes/fileHashes.bin
Binary file not shown.
Binary file added .gradle/8.1.1/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/8.1.1/fileHashes/resourceHashesCache.bin
Binary file not shown.
Empty file added .gradle/8.1.1/gc.properties
Empty file.
Binary file added .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
2 changes: 2 additions & 0 deletions .gradle/buildOutputCleanup/cache.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#Sat Apr 26 23:52:55 CEST 2025
gradle.version=8.1.1
Binary file modified .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
Binary file modified .gradle/file-system.probe
Binary file not shown.
Empty file added .gradle/vcs-1/gc.properties
Empty file.
170 changes: 88 additions & 82 deletions src/main/java/com/reclizer/csgobox/gui/client/CsLookItemScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
import com.reclizer.csgobox.capability.ModCapability;
import com.reclizer.csgobox.capability.csbox.ICsboxCap;
import com.reclizer.csgobox.sounds.ModSounds;

import com.reclizer.csgobox.utils.*;
import com.reclizer.csgobox.utils.BlurHandler;
import com.reclizer.csgobox.utils.ChatMessageUtils;
import com.reclizer.csgobox.utils.ColorTools;
import com.reclizer.csgobox.utils.GuiItemMove;
import com.reclizer.csgobox.utils.ItemNBT;
import com.reclizer.csgobox.utils.RenderFontTool;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.ImageButton;
Expand All @@ -24,167 +28,171 @@
public class CsLookItemScreen extends Screen {

private final Level world;

private final Player entity;
ImageButton imagebutton_back_box;

public CsLookItemScreen() {
super(Component.literal("look_item"));
this.minecraft= Minecraft.getInstance();

this.minecraft = Minecraft.getInstance();

if(Minecraft.getInstance().player!=null){
if (Minecraft.getInstance().player != null) {
this.world = Minecraft.getInstance().player.level();

this.entity = Minecraft.getInstance().player;
}else {
} else {
this.world = null;

this.entity = null;
}





}

@Override
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
this.renderBackground(guiGraphics);
this.renderLabels(guiGraphics,mouseX,mouseY);
this.renderBg(guiGraphics,partialTicks,mouseX,mouseY);
this.renderLabels(guiGraphics, mouseX, mouseY);
this.renderBg(guiGraphics, partialTicks, mouseX, mouseY);
super.render(guiGraphics, mouseX, mouseY, partialTicks);
//this.renderTooltip(guiGraphics, mouseX, mouseY);
}

@Override
public boolean isPauseScreen() {
return false;
}

public float itemRotX;
public float itemRotY;
/** The old x position of the mouse pointer */
public float itemRotX;
public float itemRotY;
private float xMouse;
/** The old y position of the mouse pointer */
private float yMouse;

// Flag to track if we've already shown the message
private boolean hasDisplayedMessage = false;

@Override
public boolean mouseDragged(double pMouseX, double pMouseY, int pButton, double pDragX, double pDragY) {
boolean isInRange = (pMouseX >= this.width*37F/100 && pMouseX <= this.width*37F/100+200)&&(pMouseY >= this.height*12F/100 && pMouseY <= this.height*12F/100+176);
boolean isInRange = (pMouseX >= this.width * 37F / 100 && pMouseX <= this.width * 37F / 100 + 200) && (pMouseY >= this.height * 12F / 100 && pMouseY <= this.height * 12F / 100 + 176);

if( pButton==0&&isInRange){
this.itemRotX= GuiItemMove.renderRotAngleX(pDragX,this.itemRotX);
this.itemRotY=GuiItemMove.renderRotAngleY(pDragY,this.itemRotY);
this.xMouse = (float)pDragX;
this.yMouse = (float)pDragY;
if (pButton == 0 && isInRange) {
this.itemRotX = GuiItemMove.renderRotAngleX(pDragX, this.itemRotX);
this.itemRotY = GuiItemMove.renderRotAngleY(pDragY, this.itemRotY);
this.xMouse = (float) pDragX;
this.yMouse = (float) pDragY;
}

super.mouseDragged(pMouseX,pMouseY,pButton,pDragX,pDragY);
super.mouseDragged(pMouseX, pMouseY, pButton, pDragX, pDragY);
return true;
}
//@Override
protected void renderBg(GuiGraphics guiGraphics, float partialTicks, int gx, int gy) {
RenderSystem.setShaderColor(1, 1, 1, 1);
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
BlurHandler.updateShader(false);
this.minecraft.options.hideGui=true;


int FrameWidth=width*26/100;
float scale=FrameWidth/16F;
if(openItem==null){
return;
}
guiGraphics.fill( this.width*25/100,this.height*92/100,this.width*75/100,this.height*92/100+1,0xFFD3D3D3);

guiGraphics.fill(this.width*37/100,this.height*16/100,this.width*63/100,this.height*16/100+2, ColorTools.colorItems(grade));

GuiItemMove.renderItemInInventoryFollowsMouse(guiGraphics,this.width*37/100,this.height*30/100,this.itemRotX,this.itemRotY,openItem, this.entity,scale);
//guiGraphics.fill();
RenderSystem.disableBlend();
}




@Override
public boolean keyPressed(int key, int b, int c) {
if (key == 256) {
this.minecraft.player.closeContainer();
BlurHandler.updateShader(true);
this.minecraft.options.hideGui=false;
this.minecraft.options.hideGui = false;
return true;
}
return super.keyPressed(key, b, c);
}

@Override
public void renderBackground(GuiGraphics pGuiGraphics){
public void renderBackground(GuiGraphics pGuiGraphics) {
if (this.minecraft.level != null) {
pGuiGraphics.fillGradient(0, 0, this.width, this.height, BlurHandler.getBackgroundColor(), BlurHandler.getBackgroundColor());
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.client.event.ScreenEvent.BackgroundRendered(this, pGuiGraphics));
} else {
this.renderDirtBackground(pGuiGraphics);
}
}

public ItemStack openItem;
public int grade;
public boolean openSwitch=true;
public boolean openSwitch = true;

@Override
public final void tick() {
super.tick();

if(this.minecraft==null){
if (this.minecraft == null) {
return;
}
if(this.minecraft.player==null){
if (this.minecraft.player == null) {
return;
}
if (this.minecraft.player.isAlive() && !this.minecraft.player.isRemoved()) {
this.containerTick();
} else {
this.minecraft.player.closeContainer();
}

}

public void containerTick() {
//super.containerTick();
if(!openSwitch){
// Don't process if we've already loaded the item
if (!openSwitch) {
return;
}

// Play finish sound
entity.playSound(ModSounds.CS_FINSH.get(), 10F, 1F);
ICsboxCap iCsboxCap= ModCapability.getSeed(this.entity).orElse(null);
if(iCsboxCap==null){return;}

// Get the item data from capability
ICsboxCap iCsboxCap = ModCapability.getSeed(this.entity).orElse(null);
if (iCsboxCap == null) {
return;
}

ItemStack itemStack= ItemNBT.getStacks(iCsboxCap.getItem());
if(!itemStack.isEmpty()){
openItem=itemStack;
grade=iCsboxCap.getGrade();
// Get the item and grade
ItemStack itemStack = ItemNBT.getStacks(iCsboxCap.getItem());
if (!itemStack.isEmpty()) {
openItem = itemStack;
grade = iCsboxCap.getGrade();

// Display the message after a short delay to avoid competing with sound
Minecraft.getInstance().tell(() -> {
if (entity != null && !hasDisplayedMessage) {
ChatMessageUtils.sendItemObtainedMessage(entity, itemStack, itemStack.getCount(), grade);
hasDisplayedMessage = true;
}
});
}
openSwitch=false;

openSwitch = false;
}

//@Override
protected void renderLabels(GuiGraphics guiGraphics, int mouseX, int mouseY) {
Style style=Style.EMPTY.withBold(true);
if(openItem==null){
Style style = Style.EMPTY.withBold(true);
if (openItem == null) {
return;
}

Component component=openItem.getItem().getName(openItem);
Component component = openItem.getItem().getName(openItem);
component.getStyle().applyTo(style);
FormattedCharSequence pText=component.getVisualOrderText();
renderText(guiGraphics,pText,this.width*45F/100F,this.height*5F/100F,1.8F);
FormattedCharSequence pText = component.getVisualOrderText();
renderText(guiGraphics, pText, this.width * 45F / 100F, this.height * 5F / 100F, 1.8F);

renderText(guiGraphics, Component.translatable("gui.csgobox.csgo_box.grade" + grade).getVisualOrderText(), this.width * 45F / 100F, this.height * 11F / 100F, 1F);

renderText(guiGraphics,Component.translatable("gui.csgobox.csgo_box.grade"+grade).getVisualOrderText(),this.width*45F/100F,this.height*11F/100F,1F);
renderText(guiGraphics,Component.translatable("gui.csgobox.csgo_box.back_box").withStyle(style).getVisualOrderText(),(float)this.width*72.5F/100F,(float)this.height*95/100,0.8F);
renderText(guiGraphics, Component.translatable("gui.csgobox.csgo_box.back_box").withStyle(style).getVisualOrderText(), (float) this.width * 72.5F / 100F, (float) this.height * 95 / 100, 0.8F);
}

protected void renderBg(GuiGraphics guiGraphics, float partialTicks, int gx, int gy) {
RenderSystem.setShaderColor(1, 1, 1, 1);
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
BlurHandler.updateShader(false);
this.minecraft.options.hideGui = true;

int FrameWidth = width * 26 / 100;
float scale = FrameWidth / 16F;
if (openItem == null) {
return;
}
guiGraphics.fill(this.width * 25 / 100, this.height * 92 / 100, this.width * 75 / 100, this.height * 92 / 100 + 1, 0xFFD3D3D3);

guiGraphics.fill(this.width * 37 / 100, this.height * 16 / 100, this.width * 63 / 100, this.height * 16 / 100 + 2, ColorTools.colorItems(grade));

GuiItemMove.renderItemInInventoryFollowsMouse(guiGraphics, this.width * 37 / 100, this.height * 30 / 100, this.itemRotX, this.itemRotY, openItem, this.entity, scale);
RenderSystem.disableBlend();
}

private void renderText(GuiGraphics guiGraphics, FormattedCharSequence pText, float px, float py, float scale){
RenderFontTool.drawString(guiGraphics,this.font, pText,px,py,0,0,scale,0xFFFFFFFF);
private void renderText(GuiGraphics guiGraphics, FormattedCharSequence pText, float px, float py, float scale) {
RenderFontTool.drawString(guiGraphics, this.font, pText, px, py, 0, 0, scale, 0xFFFFFFFF);
}

@Override
Expand All @@ -195,13 +203,11 @@ public void onClose() {
@Override
public void init() {
super.init();
imagebutton_back_box = new ImageButton(this.width*72/100, this.height*94/100, this.width*4/100, this.height*5/100, 0, 0, 64, new ResourceLocation("csgobox:textures/screens/atlas/back_box.png"), 82, 128, e -> {
imagebutton_back_box = new ImageButton(this.width * 72 / 100, this.height * 94 / 100, this.width * 4 / 100, this.height * 5 / 100, 0, 0, 64, new ResourceLocation("csgobox:textures/screens/atlas/back_box.png"), 82, 128, e -> {
this.minecraft.player.closeContainer();
BlurHandler.updateShader(true);
this.minecraft.options.hideGui=false;
this.minecraft.options.hideGui = false;
});
//guistate.put("button:imagebutton_back_box", imagebutton_back_box);
this.addRenderableWidget(imagebutton_back_box);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.network.NetworkEvent;
Expand Down
83 changes: 83 additions & 0 deletions src/main/java/com/reclizer/csgobox/utils/ChatMessageUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.reclizer.csgobox.utils;

import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;

/**
* Utility class for sending styled chat messages related to box rewards
*/
public class ChatMessageUtils {

/**
* Sends a beautiful message to the player about an item they just received
*
* @param player The player to send the message to
* @param itemStack The item the player received
* @param quantity The quantity of the item received
* @param grade The grade/rarity of the item (1-5)
*/
public static void sendItemObtainedMessage(Player player, ItemStack itemStack, int quantity, int grade) {
if (player == null || itemStack.isEmpty()) return;

// Create decorative separator line
MutableComponent separator = Component.literal("★ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ★")
.withStyle(getColorForGrade(grade))
.withStyle(ChatFormatting.BOLD);

// Get item name with appropriate color
Component itemName = itemStack.getHoverName().copy()
.withStyle(getColorForGrade(grade))
.withStyle(ChatFormatting.BOLD);

// Title message
MutableComponent title = Component.literal("» UNBOXED! «")
.withStyle(getColorForGrade(grade))
.withStyle(ChatFormatting.BOLD);

// Create the message with quantity if needed
MutableComponent message;
if (quantity > 1) {
message = Component.literal("You obtained ")
.append(Component.literal("" + quantity).withStyle(ChatFormatting.YELLOW).withStyle(ChatFormatting.BOLD))
.append(Component.literal(" × "))
.append(itemName);
} else {
message = Component.literal("You obtained ")
.append(itemName);
}

// Send the full formatted message
player.sendSystemMessage(Component.literal(""));
player.sendSystemMessage(separator);
player.sendSystemMessage(title);
player.sendSystemMessage(message);

// Add grade text
MutableComponent gradeText = Component.translatable("gui.csgobox.csgo_box.grade" + grade)
.withStyle(getColorForGrade(grade));
player.sendSystemMessage(gradeText);

player.sendSystemMessage(separator);
player.sendSystemMessage(Component.literal(""));
}

/**
* Gets the appropriate ChatFormatting color based on item grade/rarity
*
* @param grade The grade/rarity level (1-5)
* @return ChatFormatting color
*/
private static ChatFormatting getColorForGrade(int grade) {
return switch (grade) {
case 1 -> ChatFormatting.BLUE; // Military grade
case 2 -> ChatFormatting.DARK_BLUE; // Restricted
case 3 -> ChatFormatting.DARK_PURPLE;// Classified
case 4 -> ChatFormatting.RED; // Covert
case 5 -> ChatFormatting.GOLD; // Legendary
default -> ChatFormatting.WHITE;
};
}
}
Loading