Skip to content

Commit 81c4381

Browse files
basic shard resizing
1 parent 5e42d77 commit 81c4381

File tree

7 files changed

+116
-14
lines changed

7 files changed

+116
-14
lines changed

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ authors=Falkreon, acikek
1717
contributors=Trudle, Tomate0613, afamiliarquiet, FoundationGames, TheEpicBlock, hama
1818
license=MIT
1919
# Mod Version
20-
baseVersion=1.8.1
20+
baseVersion=1.8.2
2121
# Branch Metadata
2222
branch=1.21
2323
tagBranch=1.21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package net.modfest.scatteredshards.api.shard;
2+
3+
import com.mojang.serialization.Codec;
4+
import com.mojang.serialization.codecs.RecordCodecBuilder;
5+
import net.minecraft.network.RegistryByteBuf;
6+
import net.minecraft.network.codec.PacketCodec;
7+
import net.minecraft.network.codec.PacketCodecs;
8+
9+
import java.util.Optional;
10+
11+
public record ShardDisplaySettings(Optional<ShardIconOffsets> offsets, Optional<ShardTextureSettings> textures) {
12+
public static final Codec<ShardDisplaySettings> CODEC = RecordCodecBuilder.create(instance -> instance.group(
13+
Codec.optionalField("offsets", ShardIconOffsets.CODEC, false).forGetter(ShardDisplaySettings::offsets),
14+
Codec.optionalField("textures", ShardTextureSettings.CODEC, false).forGetter(ShardDisplaySettings::textures)
15+
).apply(instance, ShardDisplaySettings::new));
16+
17+
public static final PacketCodec<RegistryByteBuf, ShardDisplaySettings> PACKET_CODEC = PacketCodec.tuple(
18+
PacketCodecs.optional(ShardIconOffsets.PACKET_CODEC), ShardDisplaySettings::offsets,
19+
PacketCodecs.optional(ShardTextureSettings.PACKET_CODEC), ShardDisplaySettings::textures,
20+
ShardDisplaySettings::new
21+
);
22+
23+
public static final ShardDisplaySettings DEFAULT = new ShardDisplaySettings(Optional.empty(), Optional.empty());
24+
25+
public ShardIconOffsets getOffsets() {
26+
return offsets.orElse(ShardIconOffsets.DEFAULT);
27+
}
28+
29+
public ShardTextureSettings getTextureSettings() {
30+
return textures.orElse(ShardTextureSettings.DEFAULT);
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package net.modfest.scatteredshards.api.shard;
2+
3+
import com.mojang.serialization.Codec;
4+
import com.mojang.serialization.codecs.RecordCodecBuilder;
5+
import net.minecraft.network.RegistryByteBuf;
6+
import net.minecraft.network.codec.PacketCodec;
7+
import net.minecraft.network.codec.PacketCodecs;
8+
9+
import java.util.Optional;
10+
11+
public record ShardTextureSettings (Optional<Size> size, Optional<Size> miniSize){
12+
public static final Codec<ShardTextureSettings> CODEC = RecordCodecBuilder.create(instance -> instance.group(
13+
Codec.optionalField("normal", Size.CODEC, false).forGetter(ShardTextureSettings::size),
14+
Codec.optionalField("mini", Size.CODEC, false).forGetter(ShardTextureSettings::miniSize)
15+
).apply(instance, ShardTextureSettings::new));
16+
17+
public static final PacketCodec<RegistryByteBuf, ShardTextureSettings> PACKET_CODEC = PacketCodec.tuple(
18+
PacketCodecs.optional(ShardTextureSettings.Size.PACKET_CODEC), ShardTextureSettings::size,
19+
PacketCodecs.optional(ShardTextureSettings.Size.PACKET_CODEC), ShardTextureSettings::miniSize,
20+
ShardTextureSettings::new
21+
);
22+
23+
public static final ShardTextureSettings DEFAULT = new ShardTextureSettings(Optional.empty(), Optional.empty());
24+
25+
public record Size(float width, float height) {
26+
public static final Codec<ShardTextureSettings.Size> CODEC = RecordCodecBuilder.create(instance -> instance.group(
27+
Codec.FLOAT.fieldOf("width").forGetter(ShardTextureSettings.Size::width),
28+
Codec.FLOAT.fieldOf("height").forGetter(ShardTextureSettings.Size::height)
29+
).apply(instance, ShardTextureSettings.Size::new));
30+
31+
public static final PacketCodec<RegistryByteBuf, ShardTextureSettings.Size> PACKET_CODEC = PacketCodec.tuple(
32+
PacketCodecs.FLOAT, ShardTextureSettings.Size::width,
33+
PacketCodecs.FLOAT, ShardTextureSettings.Size::height,
34+
ShardTextureSettings.Size::new
35+
);
36+
37+
public static final Size DEFAULT = new Size(18, 24);
38+
public static final Size DEFAULT_MINI = new Size(12, 16);
39+
}
40+
41+
public Size getSize() {
42+
return size.orElse(Size.DEFAULT);
43+
}
44+
45+
public Size getMiniSize() {
46+
return miniSize.orElse(Size.DEFAULT_MINI);
47+
}
48+
}

src/main/java/net/modfest/scatteredshards/api/shard/ShardType.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020

2121
import java.util.Optional;
2222

23-
public record ShardType(int textColor, int glowColor, Optional<ShardIconOffsets> offsets, Optional<ParticleType<?>> collectParticle, Optional<SoundEvent> collectSound, int listOrder) {
23+
public record ShardType(int textColor, int glowColor, Optional<ShardDisplaySettings> displaySettings, Optional<ParticleType<?>> collectParticle, Optional<SoundEvent> collectSound, int listOrder) {
2424

2525
public static final Codec<ShardType> CODEC = RecordCodecBuilder.create(instance -> instance.group(
2626
ColorCodec.CODEC.fieldOf("text_color").forGetter(ShardType::textColor),
2727
ColorCodec.CODEC.fieldOf("glow_color").forGetter(ShardType::glowColor),
28-
Codec.optionalField("icon_offsets", ShardIconOffsets.CODEC, false).forGetter(ShardType::offsets),
28+
Codec.optionalField("display", ShardDisplaySettings.CODEC, false).forGetter(ShardType::displaySettings),
2929
Codec.optionalField("collect_particle", Registries.PARTICLE_TYPE.getCodec(), false).forGetter(ShardType::collectParticle),
3030
Codec.optionalField("collect_sound", SoundEvent.CODEC, false).forGetter(ShardType::collectSound),
3131
Codec.INT.fieldOf("list_order").forGetter(ShardType::listOrder)
@@ -34,7 +34,7 @@ public record ShardType(int textColor, int glowColor, Optional<ShardIconOffsets>
3434
public static final PacketCodec<RegistryByteBuf, ShardType> PACKET_CODEC = PacketCodec.tuple(
3535
PacketCodecs.INTEGER, ShardType::textColor,
3636
PacketCodecs.INTEGER, ShardType::glowColor,
37-
PacketCodecs.optional(ShardIconOffsets.PACKET_CODEC), ShardType::offsets,
37+
PacketCodecs.optional(ShardDisplaySettings.PACKET_CODEC), ShardType::displaySettings,
3838
PacketCodecs.optional(PacketCodecs.registryCodec(Registries.PARTICLE_TYPE.getCodec())), ShardType::collectParticle,
3939
PacketCodecs.optional(SoundEvent.PACKET_CODEC), ShardType::collectSound,
4040
PacketCodecs.INTEGER, ShardType::listOrder,
@@ -76,8 +76,14 @@ public static Text getDescription(Identifier id) {
7676
return Text.translatable(id.toTranslationKey("shard_type", "description"));
7777
}
7878

79+
public ShardDisplaySettings getDisplaySettings() {
80+
return this.displaySettings.orElse(ShardDisplaySettings.DEFAULT);
81+
}
7982
public ShardIconOffsets getOffsets() {
80-
return this.offsets.orElse(ShardIconOffsets.DEFAULT);
83+
return this.getDisplaySettings().getOffsets();
84+
}
85+
public ShardTextureSettings getTextureSettings() {
86+
return this.getDisplaySettings().getTextureSettings();
8187
}
8288

8389
public NbtCompound toNbt() {

src/main/java/net/modfest/scatteredshards/client/render/ShardBlockEntityRenderer.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
import net.modfest.scatteredshards.ScatteredShards;
2121
import net.modfest.scatteredshards.api.ScatteredShardsAPI;
2222
import net.modfest.scatteredshards.api.shard.Shard;
23+
import net.modfest.scatteredshards.api.shard.ShardDisplaySettings;
2324
import net.modfest.scatteredshards.api.shard.ShardIconOffsets;
25+
import net.modfest.scatteredshards.api.shard.ShardTextureSettings;
2426
import net.modfest.scatteredshards.api.shard.ShardType;
2527
import net.modfest.scatteredshards.block.ShardBlockEntity;
2628
import net.modfest.scatteredshards.util.ModMetaUtil;
@@ -72,8 +74,9 @@ public void render(ShardBlockEntity entity, float tickDelta, MatrixStack matrice
7274
* The card is 24 x 32, meaning it's 0.75 x as wide as it is tall.
7375
* 0.75 x 0.75 == 0.5625 or 18/32 is the card's proper width
7476
*/
75-
float cardHeight = 24 / 32f;
76-
float cardWidth = 18 / 32f;
77+
ShardTextureSettings.Size size = shardType.getTextureSettings().getSize();
78+
float cardHeight = size.height() / 32f;
79+
float cardWidth = size.width() / 32f;
7780

7881
float halfHeight = cardHeight / 2f;
7982
float halfWidth = cardWidth / 2f;
@@ -167,7 +170,7 @@ public void render(ShardBlockEntity entity, float tickDelta, MatrixStack matrice
167170
* (in card-image pixels) for the card-icon texture
168171
*
169172
*/
170-
float xpx = 1 / 24f * cardWidth;
173+
float xpx = 1 / 32f * cardWidth;
171174
float ypx = 1 / 32f * cardHeight;
172175

173176
ShardIconOffsets.Offset offset = shardType.getOffsets().getNormal();

src/main/java/net/modfest/scatteredshards/client/screen/widget/WMiniShard.java

+11-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import net.modfest.scatteredshards.api.ScatteredShardsAPI;
2020
import net.modfest.scatteredshards.api.shard.Shard;
2121
import net.modfest.scatteredshards.api.shard.ShardIconOffsets;
22+
import net.modfest.scatteredshards.api.shard.ShardTextureSettings;
2223
import net.modfest.scatteredshards.api.shard.ShardType;
2324
import net.modfest.scatteredshards.client.ScatteredShardsClient;
2425
import net.modfest.scatteredshards.client.screen.ShardTabletGuiDescription;
@@ -34,6 +35,8 @@ public class WMiniShard extends WWidget {
3435
protected ShardType shardType = null;
3536
protected boolean isCollected = false;
3637
protected Identifier shardId;
38+
private int width = (int)ShardTextureSettings.Size.DEFAULT_MINI.width();
39+
private int height = (int)ShardTextureSettings.Size.DEFAULT_MINI.height();
3740

3841
protected Consumer<Shard> shardConsumer = (it) -> {
3942
};
@@ -47,6 +50,9 @@ public WMiniShard setShard(Shard shard, boolean collected, Identifier shardId) {
4750
this.shardType = ScatteredShardsAPI.getClientLibrary().shardTypes().get(shard.shardTypeId()).orElse(ShardType.MISSING);
4851
this.isCollected = collected;
4952
this.shardId = shardId;
53+
ShardTextureSettings.Size size = shardType.getTextureSettings().getMiniSize();
54+
this.width = (int)size.width();
55+
this.height = (int)size.height();
5056

5157
return this;
5258
}
@@ -62,7 +68,7 @@ public void paint(DrawContext context, int x, int y, int mouseX, int mouseY) {
6268
Identifier tex = (isCollected) ? ShardType.getMiniFrontTexture(shard.shardTypeId()) : ShardType.getMiniBackingTexture(shard.shardTypeId());
6369
int color = (isCollected) ? 0xFF_FFFFFF : 0xFF_668866;
6470
float opacity = (isCollected) ? 1.0f : 0.6f;
65-
ScreenDrawing.texturedRect(context, x, y, 12, 16, tex, color, opacity);
71+
ScreenDrawing.texturedRect(context, x, y, getWidth(), getHeight(), tex, color, opacity);
6672
if (isCollected && ScatteredShardsAPI.getClientLibrary().shardDisplaySettings().drawMiniIcons()) {
6773
//Maybe draw a teeny tiny icon
6874

@@ -80,7 +86,7 @@ public void paint(DrawContext context, int x, int y, int mouseX, int mouseY) {
8086

8187
boolean hovered = (mouseX >= 0 && mouseY >= 0 && mouseX < getWidth() && mouseY < getHeight());
8288
if (hovered) {
83-
ScreenDrawing.texturedRect(context, x - 2, y - 2, 16, 20, MINI_OUTLINE, 0, 0, 1, 1, 0xFF_FFFFFF);
89+
ScreenDrawing.texturedRect(context, x - 2, y - 2, getWidth()+4, getHeight()+4, MINI_OUTLINE, 0, 0, 1, 1, 0xFF_FFFFFF);
8490

8591
renderTooltip(context, x, y, mouseX, mouseY);
8692
} else if ( // Awful bullshit write real code later
@@ -89,7 +95,7 @@ public void paint(DrawContext context, int x, int y, int mouseX, int mouseY) {
8995
&& wlrp.rightPanel instanceof WShardPanel wsp
9096
&& wsp.getShard() == shard
9197
) {
92-
ScreenDrawing.texturedRect(context, x - 2, y - 2, 16, 20, MINI_OUTLINE_SLIGHT, 0, 0, 1, 1, 0xFF_FFFFFF);
98+
ScreenDrawing.texturedRect(context, x - 2, y - 2, getWidth()+4, getHeight()+4, MINI_OUTLINE_SLIGHT, 0, 0, 1, 1, 0xFF_FFFFFF);
9399
}
94100
}
95101

@@ -123,11 +129,11 @@ public InputResult onClick(int x, int y, int button) {
123129

124130
@Override
125131
public int getWidth() {
126-
return 12;
132+
return width;
127133
}
128134

129135
@Override
130136
public int getHeight() {
131-
return 16;
137+
return height;
132138
}
133139
}

src/main/java/net/modfest/scatteredshards/client/screen/widget/WShardPanel.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import net.modfest.scatteredshards.api.ShardDisplaySettings;
2525
import net.modfest.scatteredshards.api.shard.Shard;
2626
import net.modfest.scatteredshards.api.shard.ShardIconOffsets;
27+
import net.modfest.scatteredshards.api.shard.ShardTextureSettings;
2728
import net.modfest.scatteredshards.api.shard.ShardType;
2829
import net.modfest.scatteredshards.client.screen.widget.scalable.WScaledLabel;
2930
import net.modfest.scatteredshards.client.screen.widget.scalable.WScaledText;
@@ -128,6 +129,10 @@ public WShardPanel setShard(Shard shard) {
128129
setLore(shard::lore, WHITE);
129130
setHint(shard::hint, WHITE);
130131

132+
int cardScale = 2;
133+
ShardTextureSettings.Size size = shardType.getTextureSettings().getSize();
134+
backing.setSize((int)size.width() * cardScale, (int)size.height() * cardScale);
135+
131136
return this;
132137
}
133138

@@ -158,7 +163,9 @@ public WShardPanel() {
158163

159164
int cardScale = 2;
160165
int cardX = ((this.getLayoutWidth()) / 2) - (12 * cardScale);
161-
add(backing, cardX, 40, 24 * cardScale, 32 * cardScale);
166+
167+
ShardTextureSettings.Size size = shardType.getTextureSettings().getSize();
168+
add(backing, cardX, 40, (int)size.width() * cardScale, (int)size.height() * cardScale);
162169

163170
ShardIconOffsets.Offset offset = this.shardType.getOffsets().getNormal();
164171
add(icon, cardX + (offset.left() * cardScale), 40 + (offset.up() * cardScale), 16 * cardScale, 16 * cardScale);

0 commit comments

Comments
 (0)