-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves #15 Example: "icon": { "type": "bingo:sprite", "sprite": "sprite_icon:smiley", "fallback": { "count": 1, "id": "yellow_dye" } }
- Loading branch information
Showing
4 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
common/src/main/java/io/github/gaming32/bingo/client/icons/SpriteIconRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.github.gaming32.bingo.client.icons; | ||
|
||
import io.github.gaming32.bingo.data.icons.SpriteIcon; | ||
import net.minecraft.client.gui.GuiGraphics; | ||
import net.minecraft.client.renderer.RenderType; | ||
|
||
public class SpriteIconRenderer implements IconRenderer<SpriteIcon> { | ||
@Override | ||
public void render(SpriteIcon icon, GuiGraphics graphics, int x, int y) { | ||
final var sprite = icon.sprite().withPrefix("bingo/icon/"); | ||
graphics.blitSprite(RenderType::guiTextured, sprite, x, y, 16, 16); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
common/src/main/java/io/github/gaming32/bingo/data/icons/SpriteIcon.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.github.gaming32.bingo.data.icons; | ||
|
||
import com.mojang.serialization.MapCodec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import io.github.gaming32.bingo.util.BingoCodecs; | ||
import net.minecraft.network.RegistryFriendlyByteBuf; | ||
import net.minecraft.network.codec.StreamCodec; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.item.ItemStack; | ||
|
||
public record SpriteIcon(ResourceLocation sprite, ItemStack fallback) implements GoalIcon.WithoutContext { | ||
public static final MapCodec<SpriteIcon> CODEC = RecordCodecBuilder.mapCodec( | ||
instance -> instance.group( | ||
ResourceLocation.CODEC.fieldOf("sprite").forGetter(SpriteIcon::sprite), | ||
BingoCodecs.LENIENT_ITEM_STACK.fieldOf("fallback").forGetter(SpriteIcon::fallback) | ||
).apply(instance, SpriteIcon::new) | ||
); | ||
public static final StreamCodec<RegistryFriendlyByteBuf, SpriteIcon> STREAM_CODEC = StreamCodec.composite( | ||
ResourceLocation.STREAM_CODEC, SpriteIcon::sprite, | ||
ItemStack.STREAM_CODEC, SpriteIcon::fallback, | ||
SpriteIcon::new | ||
); | ||
|
||
@Override | ||
public ItemStack getFallback() { | ||
return fallback; | ||
} | ||
|
||
@Override | ||
public GoalIconType<?> type() { | ||
return GoalIconType.SPRITE.get(); | ||
} | ||
} |