Skip to content

Commit 85dfbc2

Browse files
authored
Merge pull request #2 from Fripe070/refactor
Refactor
2 parents 456ea44 + aa227e7 commit 85dfbc2

11 files changed

Lines changed: 310 additions & 358 deletions

File tree

‎src/main/java/io/github/fripe070/pirkko/Pirkko.java‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.github.fripe070.pirkko;
22

33
import eu.pb4.polymer.core.api.other.PolymerSoundEvent;
4+
import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils;
45
import eu.pb4.polymer.rsm.api.RegistrySyncUtils;
56
import io.github.fripe070.pirkko.block.PirkkoBlock;
67
import io.github.fripe070.pirkko.effect.PirkkoPowerEffect;
@@ -20,8 +21,6 @@
2021
import net.minecraft.sound.SoundEvent;
2122
import net.minecraft.sound.SoundEvents;
2223
import net.minecraft.util.Identifier;
23-
import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils;
24-
import net.minecraft.util.Rarity;
2524
import org.slf4j.Logger;
2625
import org.slf4j.LoggerFactory;
2726

@@ -32,12 +31,8 @@ public class Pirkko implements ModInitializer {
3231
public static final Logger LOGGER = LoggerFactory.getLogger("pirkko");
3332

3433
public static final PirkkoBlock PIRKKO_BLOCK = registerPirkkoBlock("pirkko");
35-
public static final Item DEFAULT_PIRKKO_ITEM = registerPirkkoItem("pirkko", PIRKKO_BLOCK);
36-
37-
public static final SoundEvent PIRKKO_SOUND = registerSoundEvent("pirkko/pirkko", SoundEvents.ENTITY_COD_FLOP);
38-
public static final SoundEvent PIRKKO_GHOST_SOUND = registerSoundEvent("pirkko/ghost", SoundEvents.ENTITY_COD_FLOP);
39-
public static final SoundEvent PIRKKO_PHOZ_SOUND = registerSoundEvent("pirkko/phoz", SoundEvents.ENTITY_COD_FLOP);
40-
public static final SoundEvent PIRKKO_KONGLIG_SOUND = registerSoundEvent("pirkko/konglig", SoundEvents.ENTITY_COD_FLOP);
34+
public static final PirkkoItem PIRKKO_ITEM = registerPirkkoItem("pirkko", PIRKKO_BLOCK);
35+
public static final SoundEvent DEFAULT_PIRKKO_SOUND = registerSoundEvent("pirkko/pirkko", SoundEvents.ENTITY_COD_FLOP);
4136
public static final StatusEffect PIRKKO_POWER = new PirkkoPowerEffect();
4237

4338
@Override
@@ -46,7 +41,13 @@ public void onInitialize() {
4641
PolymerResourcePackUtils.markAsRequired();
4742

4843
Registry.register(Registries.STATUS_EFFECT, Identifier.of(MOD_ID, "pirkko_power"), PIRKKO_POWER);
49-
PirkkoKind.InitializePirkkoKindData();
44+
45+
for (PirkkoKind kind : PirkkoKind.values()) {
46+
if (!kind.usesCustomSound()) continue;
47+
var sound = kind.getSound();
48+
Registry.register(Registries.SOUND_EVENT, sound.id(), sound);
49+
PolymerSoundEvent.registerOverlay(sound);
50+
}
5051
}
5152

5253
private static PirkkoBlock registerPirkkoBlock(String name) {
@@ -60,15 +61,14 @@ private static PirkkoBlock registerPirkkoBlock(String name) {
6061
return block;
6162
}
6263

63-
private static Item registerPirkkoItem(String name, PirkkoBlock block) {
64+
private static PirkkoItem registerPirkkoItem(String name, PirkkoBlock block) {
6465
var registryKey = Identifier.of(MOD_ID, name);
6566
var item = new PirkkoItem(block, new Item.Settings()
6667
.maxCount(65)
6768
.fireproof()
68-
.rarity(Rarity.EPIC)
6969
.equippableUnswappable(EquipmentSlot.HEAD)
7070
.registryKey(RegistryKey.of(RegistryKeys.ITEM, registryKey))
71-
// .useBlockPrefixedTranslationKey()
71+
.useBlockPrefixedTranslationKey()
7272
);
7373
Registry.register(Registries.ITEM, Identifier.of(MOD_ID, name), item);
7474
ItemGroupEvents.modifyEntriesEvent(ItemGroups.COMBAT).register(entries -> {
Lines changed: 79 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,102 @@
11
package io.github.fripe070.pirkko;
22

3+
import net.minecraft.sound.SoundEvent;
4+
import net.minecraft.util.Identifier;
5+
import net.minecraft.util.Rarity;
36
import net.minecraft.util.StringIdentifiable;
47
import org.jetbrains.annotations.Nullable;
58

6-
import java.util.Objects;
9+
import java.util.Optional;
10+
import java.util.stream.Stream;
711

812
public enum PirkkoKind implements StringIdentifiable {
9-
BLANK(0, "blank"),
10-
COLOR_WHITE(1, "color/white"),
11-
COLOR_ORANGE(2, "color/orange"),
12-
COLOR_MAGENTA(3, "color/magenta"),
13-
COLOR_LIGHT_BLUE(4, "color/light_blue"),
14-
COLOR_YELLOW(5, "color/yellow"),
15-
COLOR_LIME(6, "color/lime"),
16-
COLOR_PINK(7, "color/pink"),
17-
COLOR_GRAY(8, "color/gray"),
18-
COLOR_LIGHT_GRAY(9, "color/light_gray"),
19-
COLOR_CYAN(10, "color/cyan"),
20-
COLOR_PURPLE(11, "color/purple"),
21-
COLOR_BLUE(12, "color/blue"),
22-
COLOR_BROWN(13, "color/brown"),
23-
COLOR_GREEN(14, "color/green"),
24-
COLOR_RED(15, "color/red"),
25-
COLOR_BLACK(16, "color/black"),
26-
PHOZ(17, "phoz"),
27-
KONGLIG(18, "konglig"),
28-
GHOST(19, "ghost"),
29-
LASERVIOLETT(20, "laserviolett"),
30-
CERISE(21, "cerise"),
31-
PRIDE_AROMANTIC(22, "pride/aromantic"),
32-
PRIDE_ASEXUAL(23, "pride/asexual"),
33-
PRIDE_BISEXUAL(24, "pride/bisexual"),
34-
PRIDE_GAY_M(25, "pride/gay_m"),
35-
PRIDE_GENDER_FLUID(26, "pride/genderfluid"),
36-
PRIDE_LESBIAN(27, "pride/lesbian"),
37-
PRIDE_NONBINARY(28, "pride/nonbinary"),
38-
PRIDE_RAINBOW(29, "pride/rainbow"),
39-
PRIDE_TRANSGENDER(30, "pride/transgender");
13+
BLANK("blank", Rarity.UNCOMMON),
4014

15+
COLOR_WHITE("color/white", Rarity.UNCOMMON),
16+
COLOR_ORANGE("color/orange", Rarity.UNCOMMON),
17+
COLOR_MAGENTA("color/magenta", Rarity.UNCOMMON),
18+
COLOR_LIGHT_BLUE("color/light_blue", Rarity.UNCOMMON),
19+
COLOR_YELLOW("color/yellow", Rarity.UNCOMMON),
20+
COLOR_LIME("color/lime", Rarity.UNCOMMON),
21+
COLOR_PINK("color/pink", Rarity.UNCOMMON),
22+
COLOR_GRAY("color/gray", Rarity.UNCOMMON),
23+
COLOR_LIGHT_GRAY("color/light_gray", Rarity.UNCOMMON),
24+
COLOR_CYAN("color/cyan", Rarity.UNCOMMON),
25+
COLOR_PURPLE("color/purple", Rarity.UNCOMMON),
26+
COLOR_BLUE("color/blue", Rarity.UNCOMMON),
27+
COLOR_BROWN("color/brown", Rarity.UNCOMMON),
28+
COLOR_GREEN("color/green", Rarity.UNCOMMON),
29+
COLOR_RED("color/red", Rarity.UNCOMMON),
30+
COLOR_BLACK("color/black", Rarity.UNCOMMON),
4131

42-
private final int index;
43-
private final String id;
44-
private final String friendlyId;
45-
private final PirkkoKindData pirkkoKindData;
32+
PRIDE_AROMANTIC("pride/aromantic", Rarity.UNCOMMON),
33+
PRIDE_ASEXUAL("pride/asexual", Rarity.UNCOMMON),
34+
PRIDE_BISEXUAL("pride/bisexual", Rarity.UNCOMMON),
35+
PRIDE_GAY_M("pride/gay_m", Rarity.UNCOMMON),
36+
PRIDE_GENDER_FLUID("pride/genderfluid", Rarity.UNCOMMON),
37+
PRIDE_LESBIAN("pride/lesbian", Rarity.UNCOMMON),
38+
PRIDE_NONBINARY("pride/nonbinary", Rarity.UNCOMMON),
39+
PRIDE_RAINBOW("pride/rainbow", Rarity.UNCOMMON),
40+
PRIDE_TRANSGENDER("pride/transgender", Rarity.UNCOMMON),
4641

47-
PirkkoKind(int index, String id) {
48-
this.index = index;
49-
this.id = id;
50-
this.friendlyId = id.replace("/", "_");
51-
this.pirkkoKindData = new PirkkoKindData();
52-
}
42+
LASERVIOLETT("laserviolett", Rarity.RARE),
43+
CERISE("cerise", Rarity.RARE),
44+
PHOZ("phoz", Rarity.RARE, true),
45+
KONGLIG("konglig", Rarity.RARE, true),
46+
GHOST("ghost", Rarity.RARE, true);
47+
48+
private final String assetPath;
49+
private final Rarity rarity;
50+
private final @Nullable SoundEvent soundEvent;
5351

54-
public static void InitializePirkkoKindData() {
55-
GHOST.pirkkoKindData()
56-
.setSound(Pirkko.PIRKKO_GHOST_SOUND);
57-
PHOZ.pirkkoKindData()
58-
.setSound(Pirkko.PIRKKO_PHOZ_SOUND);
59-
KONGLIG.pirkkoKindData()
60-
.setSound(Pirkko.PIRKKO_KONGLIG_SOUND);
52+
PirkkoKind(String assetPath, Rarity rarity) {
53+
this(assetPath, rarity, false);
54+
}
55+
PirkkoKind(String assetPath, Rarity rarity, boolean useCustomSound) {
56+
this.assetPath = assetPath;
57+
this.rarity = rarity;
58+
var sound = SoundEvent.of(Identifier.of(Pirkko.MOD_ID, "pirkko/" + this.getPath()));
59+
this.soundEvent = useCustomSound ? sound : null;
6160
}
6261

63-
@Override
64-
public String asString() {
65-
return friendlyId;
62+
public String getPath() {
63+
return assetPath;
64+
}
65+
public String getId() {
66+
return assetPath.replace("/", "_");
67+
}
68+
public String getTranslationKey() {
69+
return assetPath.replace("/", ".");
6670
}
6771

68-
public String realId() {
69-
return id;
72+
public Rarity getRarity() {
73+
return rarity;
74+
}
75+
public boolean usesCustomSound() {
76+
return soundEvent != null;
77+
}
78+
public SoundEvent getSound() {
79+
return Optional.ofNullable(soundEvent).orElse(Pirkko.DEFAULT_PIRKKO_SOUND);
7080
}
7181

72-
public PirkkoKindData pirkkoKindData() {
73-
return pirkkoKindData;
82+
@Override
83+
public String asString() {
84+
return this.getId();
7485
}
7586

76-
public int getIndex() {
77-
return index;
87+
@Nullable
88+
public static PirkkoKind fromPath(String path) {
89+
return Stream.of(values())
90+
.filter(kind -> kind.getPath().equals(path))
91+
.findFirst()
92+
.orElse(null);
7893
}
7994

8095
@Nullable
81-
public static PirkkoKind fromName(String name) {
82-
for (PirkkoKind kind : PirkkoKind.values()) {
83-
if (Objects.equals(kind.asString(), name)) {
84-
return kind;
85-
}
86-
}
87-
return null;
96+
public static PirkkoKind fromId(String id) {
97+
return Stream.of(values())
98+
.filter(kind -> kind.getId().equals(id))
99+
.findFirst()
100+
.orElse(null);
88101
}
89-
}
102+
}

0 commit comments

Comments
 (0)