Skip to content

Commit 4774953

Browse files
committed
Add a bunch of comments
1 parent 0eb976a commit 4774953

3 files changed

Lines changed: 49 additions & 18 deletions

File tree

Common/src/main/java/at/petrak/hexcasting/common/items/storage/ItemScroll.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@
3737
import static at.petrak.hexcasting.api.HexAPI.modLoc;
3838

3939
/**
40-
* TAG_OP_ID and TAG_PATTERN: "Ancient Scroll of %s" (per-world pattern preloaded)
40+
* ACTION and PATTERN components: "Ancient Scroll of %s" (per-world pattern preloaded)
4141
* <br>
42-
* TAG_OP_ID: "Ancient Scroll of %s" (per-world pattern loaded on inv tick)
42+
* Only ACTION component: "Ancient Scroll of %s" (per-world pattern loaded on inv tick)
4343
* <br>
44-
* TAG_PATTERN: "Scroll" (custom)
44+
* Only PATTERN component: "Scroll" (custom)
4545
* <br>
4646
* (none): "Empty Scroll"
4747
*/
@@ -147,11 +147,11 @@ public Component getName(ItemStack pStack) {
147147

148148
@Override
149149
public void inventoryTick(ItemStack pStack, Level pLevel, Entity pEntity, int pSlotId, boolean pIsSelected) {
150-
// the needs_purchase tag is used so you can't see the pattern on scrolls sold by a wandering trader
151-
// once you put the scroll into your inventory, this removes the tag to reveal the pattern
150+
// the NEEDS_PURCHASE component is used so you can't see the pattern on scrolls sold by a wandering trader
151+
// once you put the scroll into your inventory, this removes the component to reveal the pattern
152152
if(pStack.has(HexDataComponents.NEEDS_PURCHASE.get()))
153153
pStack.remove(HexDataComponents.NEEDS_PURCHASE.get());
154-
// if op_id is set but there's no stored pattern, attempt to load the pattern on inv tick
154+
// if ACTION is present but PATTERN is not present, attempt to load the pattern on inv tick
155155
if (pStack.has(HexDataComponents.ACTION.get()) && !pStack.has(HexDataComponents.PATTERN.get()) && pEntity.getServer() != null) {
156156
var action = pStack.get(HexDataComponents.ACTION.get());
157157
if (!IXplatAbstractions.INSTANCE.getActionRegistry().containsKey(action)) {
@@ -161,7 +161,7 @@ public void inventoryTick(ItemStack pStack, Level pLevel, Entity pEntity, int pS
161161
}
162162
var pat = PatternRegistryManifest.getCanonicalStrokesPerWorld(action, pEntity.getServer().overworld());
163163
if (pat == null) {
164-
// if pat is null, the per-world order hasn't been registered; remove the op_id and warn the player
164+
// if pat is null, the per-world order hasn't been registered; remove the ACTION component and warn the player
165165
pStack.set(HexDataComponents.RECALC_WARNING.get(), action);
166166
pStack.remove(HexDataComponents.ACTION.get());
167167
return;

Common/src/main/java/at/petrak/hexcasting/common/items/storage/ItemSpellbook.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,22 @@ public void inventoryTick(ItemStack stack, Level level, Entity pEntity, int pSlo
9090
var savedNames = stack.get(HexDataComponents.SPELLBOOK_PAGE_NAMES.get());
9191

9292
if(customName != null) {
93+
// the stack has been given a custom name (ie via anvil)
9394
if(savedNames != null) {
9495
if(!savedNames.containsKey(nameKey) || !savedNames.get(nameKey).equals(customName)) {
96+
// if this page doesn' have a name mapping, or it doesn't match, create/update the name mapping
9597
var mutNames = new HashMap<>(savedNames);
9698
mutNames.put(nameKey, customName);
9799
stack.set(HexDataComponents.SPELLBOOK_PAGE_NAMES.get(), mutNames);
98100
}
99101
} else {
100102
var mutNames = new HashMap<String, Component>();
101103
mutNames.put(nameKey, customName);
104+
// if the savedNames map doesn't exist at all, create it and map the stack's current name to this page
102105
stack.set(HexDataComponents.SPELLBOOK_PAGE_NAMES.get(), mutNames);
103106
}
104107
} else if(savedNames != null) {
108+
// the stack does not have a custom name, or it has been removed
105109
var mutNames = new HashMap<>(savedNames);
106110
mutNames.remove(nameKey);
107111
if(mutNames.isEmpty()) {
@@ -151,10 +155,12 @@ public void writeDatum(ItemStack stack, Iota datum) {
151155
var pages = stack.get(HexDataComponents.SPELLBOOK_PAGES.get());
152156

153157
if (pages != null) {
158+
// if the pages map exists, modify it accordingly
154159
var pagesMut = new HashMap<>(pages);
155160

156161
if (datum == null) {
157162
pagesMut.remove(key);
163+
// erasing the current page (needs to unseal as well, if possible)
158164
var seals = stack.get(HexDataComponents.SPELLBOOK_PAGE_SEALS.get());
159165
if(seals != null) {
160166
var sealsMut = new HashMap<>(seals);
@@ -169,6 +175,7 @@ public void writeDatum(ItemStack stack, Iota datum) {
169175
}
170176
} else {
171177
pagesMut.put(key, datum);
178+
// updating the current page
172179
}
173180

174181
if (pagesMut.isEmpty()) {
@@ -179,8 +186,11 @@ public void writeDatum(ItemStack stack, Iota datum) {
179186
} else if (datum != null) {
180187
var map = new HashMap<String, Iota>();
181188
map.put(key, datum);
189+
// if the pages map doesn't exist and you're trying to update a page, create the map first
182190
stack.set(HexDataComponents.SPELLBOOK_PAGES.get(), map);
183191
} else {
192+
// if the pages map doesn't exist and you're trying to erase a page, check for a seal to remove
193+
// this can happen if somebody seals an empty book for some reason
184194
var seals = stack.get(HexDataComponents.SPELLBOOK_PAGE_SEALS.get());
185195
if(seals != null) {
186196
var sealsMut = new HashMap<>(seals);

Common/src/main/java/at/petrak/hexcasting/common/lib/HexDataComponents.java

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public static void register() {
2727
REGISTER.registerAll();
2828
}
2929

30+
// ==== SCROLLS ====
31+
3032
public static final Supplier<DataComponentType<HexPattern>> PATTERN = REGISTER.register("pattern", () ->
3133
DataComponentType.<HexPattern>builder()
3234
.persistent(HexPattern.CODEC)
@@ -46,38 +48,48 @@ public static void register() {
4648
DataComponentType.<Unit>builder()
4749
.networkSynchronized(StreamCodec.unit(Unit.INSTANCE))
4850
.build());
49-
/**
50-
* If this datacomponent is set on the item, we ignore the rest of the item and render this as if it were of the
51-
* {@link at.petrak.hexcasting.api.casting.iota.IotaType IotaType} given by the resource location.
52-
* <p>
53-
* This is not useful to the player at all.
54-
*/
55-
public static final Supplier<DataComponentType<Optional<IotaType<?>>>> VISUAL_OVERRIDE = REGISTER.register("visual_override", () ->
56-
DataComponentType.<Optional<IotaType<?>>>builder()
57-
.networkSynchronized(ByteBufCodecs.optional(ByteBufCodecs.registry(HexRegistries.IOTA_TYPE)))
58-
.build());
51+
52+
// ==== ANYTHING WITH TEXTURE VARIANTS ====
53+
5954
public static final Supplier<DataComponentType<Integer>> ITEM_VARIANT = REGISTER.register("variant", () ->
6055
DataComponentType.<Integer>builder()
6156
.persistent(Codec.intRange(0, Integer.MAX_VALUE))
6257
.networkSynchronized(ByteBufCodecs.VAR_INT)
6358
.build());
59+
60+
// ==== IOTA HOLDERS ====
61+
6462
public static final Supplier<DataComponentType<Unit>> SEALED_IOTA_HOLDER = REGISTER.register("sealed", () ->
6563
DataComponentType.<Unit>builder()
6664
.persistent(Codec.unit(Unit.INSTANCE))
6765
.networkSynchronized(StreamCodec.unit(Unit.INSTANCE))
6866
.build());
69-
// TODO port: Data components must implement equals and hashCode. Keep in mind they must also be immutable
67+
// TODO port: Data components are supposed to be immutable - is EntityIota.isPlayer a problem here?
7068
public static final Supplier<DataComponentType<Iota>> IOTA_HOLDER_IOTA = REGISTER.register("iota", () ->
7169
DataComponentType.<Iota>builder()
7270
.persistent(IotaType.TYPED_CODEC)
7371
.networkSynchronized(IotaType.TYPED_STREAM_CODEC)
7472
.build());
73+
/**
74+
* If this datacomponent is set on the item, we ignore the rest of the item and render this as if it were of the
75+
* {@link at.petrak.hexcasting.api.casting.iota.IotaType IotaType} given by the resource location.
76+
* <p>
77+
* This is not useful to the player at all.
78+
*/
79+
public static final Supplier<DataComponentType<Optional<IotaType<?>>>> VISUAL_OVERRIDE = REGISTER.register("visual_override", () ->
80+
DataComponentType.<Optional<IotaType<?>>>builder()
81+
.networkSynchronized(ByteBufCodecs.optional(ByteBufCodecs.registry(HexRegistries.IOTA_TYPE)))
82+
.build());
83+
84+
// ==== CASTING ITEMS ====
7585

7686
public static final Supplier<DataComponentType<HexHolder>> HEX_HOLDER = REGISTER.register("hex_holder", () ->
7787
DataComponentType.<HexHolder>builder()
7888
.persistent(HexHolder.CODEC)
7989
.networkSynchronized(HexHolder.STREAM_CODEC)
8090
.build());
91+
92+
// ==== CASTING ITEMS & PHIALS ====
8193

8294
public static final Supplier<DataComponentType<Long>> MEDIA = REGISTER.register("media", () ->
8395
DataComponentType.<Long>builder()
@@ -89,18 +101,25 @@ public static void register() {
89101
.persistent(Codec.LONG)
90102
.networkSynchronized(ByteBufCodecs.VAR_LONG)
91103
.build());
104+
105+
// ==== ANCIENT CYPHERS ====
106+
92107
public static final Supplier<DataComponentType<String>> HEX_NAME = REGISTER.register("hex_name", () ->
93108
DataComponentType.<String>builder()
94109
.persistent(Codec.STRING)
95110
.networkSynchronized(ByteBufCodecs.STRING_UTF8)
96111
.build());
97112

113+
// ==== ABACUS ====
114+
98115
public static final Supplier<DataComponentType<Double>> ABACUS_VALUE = REGISTER.register("abacus_value", () ->
99116
DataComponentType.<Double>builder()
100117
.persistent(Codec.DOUBLE)
101118
.networkSynchronized(ByteBufCodecs.DOUBLE)
102119
.build());
103120

121+
// ==== SPELLBOOKS ====
122+
104123
public static final Supplier<DataComponentType<Integer>> SELECTED_SPELLBOOK_PAGE = REGISTER.register("page_idx", () ->
105124
DataComponentType.<Integer>builder()
106125
.persistent(Codec.INT)
@@ -137,6 +156,8 @@ public static void register() {
137156
))
138157
.build());
139158

159+
// ==== MEDIA CUBE ====
160+
140161
public static final Supplier<DataComponentType<List<Long>>> MEDIA_EXTRACTIONS = REGISTER.register("media_extractions", () ->
141162
DataComponentType.<List<Long>>builder()
142163
.persistent(Codec.LONG.listOf())

0 commit comments

Comments
 (0)