Skip to content

Commit

Permalink
fix stacking issue maybe
Browse files Browse the repository at this point in the history
also fix glow health not working properly
  • Loading branch information
U5B committed Aug 4, 2023
1 parent 6a84368 commit 3b9279c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
50 changes: 30 additions & 20 deletions src/main/kotlin/net/usbwire/usbplus/features/Debug.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,35 +71,45 @@ object Debug {
if (screen !is HandledScreen<*>) return
if (screen !is GenericContainerScreen && screen !is ShulkerBoxScreen) return
var container = screen.getScreenHandler()
var strings = "```\n";
val lineSeperator = System.getProperty("line.separator");
var items = condenseItems(container.slots.stream()
var strings = "```\n"
val lineSeperator = System.getProperty("line.separator")
var itemList = container.slots.stream()
.filter { slot -> run { slot.hasStack() && slot.inventory !is PlayerInventory } }
.map(Slot::getStack)
.toList());
.toList()
var itemMap = condenseItems(itemList);
var lastItem = ""
for (item in items) {
for (mappedItem in itemMap) {
val item = mappedItem.key;
val count = mappedItem.value;
val name = UMessage(item.name).unformattedText
val line = """+${item.count} ${name}"""
val line = """+${count} ${name}"""
lastItem = line
strings += "${line} ${lineSeperator}"
}
strings += "```"
Util.chat(ChatUtil.clipboardBuilder("Container with \"${lastItem}\"", strings));
Util.chat(ChatUtil.clipboardBuilder("Container with \"${lastItem}\"", strings))
}

fun condenseItems(list: List<ItemStack>) : List<ItemStack> {
val stacks = ArrayList<ItemStack>();
list.forEach { newStack -> run {
var exists = false;
for (oldStack in stacks) {
if (newStack.item == oldStack.item && newStack.name == oldStack.name) {
oldStack.setCount(oldStack.getCount() + newStack.getCount());
exists = true;
}
fun condenseItems(list: List<ItemStack>) : Map<ItemStack, Int> {
val map = mutableMapOf<ItemStack, Int>()
for (newStack in list) {
var owo = false
val newStackCopy = newStack.copy()
newStackCopy.setCount(1);
for (otherStack in map.keys) {
if (ItemStack.areItemsEqualIgnoreDamage(otherStack, newStackCopy)) {
val newCount = map.getOrDefault(otherStack, 0) + newStack.count
map.remove(otherStack)
map.set(otherStack, newCount)
owo = true
break;
}
if (!exists) stacks.add(newStack);
}};
return stacks;
}
}
if (!owo) {
map.set(newStackCopy, newStack.count)
}
}
return map;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ object Base {

var configDirty = true
fun onWorldTick(world: ClientWorld) {
if (Config.healthDrawEnabled == false) {
if (!Config.healthDrawEnabled && !Config.healthGlowingEnabled && !Config.healthDrawEnabled) {
configDirty = true
return
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/net/usbwire/usbplus/features/health/Glow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import java.awt.Color

object Glow {
fun onRenderTick(context: WorldRenderContext) {
if (Config.healthEnabled == false) return
if (!Config.healthEnabled && !Config.healthGlowingEnabled) return
val camera = context.camera()
for (player in context.world().players) {
if (player == camera.focusedEntity && !camera.isThirdPerson) continue // don't render hitbox on yourself if in third person
Expand All @@ -38,7 +38,7 @@ object Glow {
if (Config.healthGlowingEnabled && player.isGlowing) {
Base.playerMap[name]!!.glow = true
EntityHelper.setGlowingColor(player, color)
} else {
} else if (Config.healthEnabled) {
RenderUtil.drawEntityBox(player, color, context, true, true) // only draw box if player is already not glowing and glowing isn't forced
}
}
Expand Down

0 comments on commit 3b9279c

Please sign in to comment.