Skip to content

Commit

Permalink
fix new item group changes on servers, always keep actives tab indice…
Browse files Browse the repository at this point in the history
…s ordered
  • Loading branch information
gliscowo committed Jul 22, 2023
1 parent 53489dc commit 9011083
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ minecraft_version=1.20.1
yarn_mappings=1.20.1+build.2
loader_version=0.14.21
# Mod Properties
mod_version=0.11.2-pre.5
mod_version=0.11.2-pre.9
maven_group=io.wispforest
archives_base_name=owo-lib
# Dependencies
Expand Down
24 changes: 18 additions & 6 deletions src/main/java/io/wispforest/owo/itemgroup/Icon.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import io.wispforest.owo.client.texture.AnimatedTextureDrawable;
import io.wispforest.owo.client.texture.SpriteSheetMetadata;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.item.ItemConvertible;
import net.minecraft.item.ItemStack;
Expand All @@ -15,11 +17,15 @@
@FunctionalInterface
public interface Icon {

@Environment(EnvType.CLIENT)
void render(DrawContext context, int x, int y, int mouseX, int mouseY, float delta);

static Icon of(ItemStack stack) {
return (context, x, y, mouseX, mouseY, delta) -> {
context.drawItemWithoutEntity(stack, x, y);
return new Icon() {
@Override
public void render(DrawContext context, int x, int y, int mouseX, int mouseY, float delta) {
context.drawItemWithoutEntity(stack, x, y);
}
};
}

Expand All @@ -28,8 +34,11 @@ static Icon of(ItemConvertible item) {
}

static Icon of(Identifier texture, int u, int v, int textureWidth, int textureHeight) {
return (context, x, y, mouseX, mouseY, delta) -> {
context.drawTexture(texture, x, y, u, v, 16, 16, textureWidth, textureHeight);
return new Icon() {
@Override
public void render(DrawContext context, int x, int y, int mouseX, int mouseY, float delta) {
context.drawTexture(texture, x, y, u, v, 16, 16, textureWidth, textureHeight);
}
};
}

Expand All @@ -44,8 +53,11 @@ static Icon of(Identifier texture, int u, int v, int textureWidth, int textureHe
*/
static Icon of(Identifier texture, int textureSize, int frameDelay, boolean loop) {
var widget = new AnimatedTextureDrawable(0, 0, 16, 16, texture, new SpriteSheetMetadata(textureSize, 16), frameDelay, loop);
return (context, x, y, mouseX, mouseY, delta) -> {
widget.render(x, y, context, mouseX, mouseY, delta);
return new Icon() {
@Override
public void render(DrawContext context, int x, int y, int mouseX, int mouseY, float delta) {
widget.render(x, y, context, mouseX, mouseY, delta);
}
};
}
}
6 changes: 2 additions & 4 deletions src/main/java/io/wispforest/owo/itemgroup/OwoItemGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import io.wispforest.owo.itemgroup.gui.ItemGroupTab;
import io.wispforest.owo.mixin.itemgroup.ItemGroupAccessor;
import io.wispforest.owo.util.pond.OwoItemExtensions;
import it.unimi.dsi.fastutil.ints.IntArraySet;
import it.unimi.dsi.fastutil.ints.IntSet;
import it.unimi.dsi.fastutil.ints.IntSets;
import it.unimi.dsi.fastutil.ints.*;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.item.*;
Expand Down Expand Up @@ -50,7 +48,7 @@ public abstract class OwoItemGroup extends ItemGroup {
private final Supplier<Icon> iconSupplier;
private Icon icon;

private final IntSet activeTabs = new IntArraySet();
private final IntSet activeTabs = new IntAVLTreeSet(IntComparators.NATURAL_COMPARATOR);
private final IntSet activeTabsView = IntSets.unmodifiable(this.activeTabs);
private boolean initialized = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ public void renderButton(DrawContext context, int mouseX, int mouseY, float delt

RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
if (!(this.isSelected() || this.isSelected)) RenderSystem.setShaderColor(.75f, .75f, .75f, 1f);

this.definition.icon().render(context, this.getX() + 4, this.getY() + 4, mouseX, mouseY, delta);

RenderSystem.setShaderColor(1f, 1f, 1f, 1f);
RenderSystem.disableBlend();
}

Expand Down

0 comments on commit 9011083

Please sign in to comment.