-
Notifications
You must be signed in to change notification settings - Fork 147
Data component cleanup #1220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Robotgiggle
wants to merge
7
commits into
1.21
Choose a base branch
from
component-scrunch
base: 1.21
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Data component cleanup #1220
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9a642af
Merge hex holder components
Robotgiggle 13ee595
Move new HexHolder record into ItemPackagedHex
Robotgiggle 32ef799
Remove unused tag-name constants
Robotgiggle 26bdab4
Fix typo when setting MEDIA_MAX component
Robotgiggle 0eb976a
Fix scroll autoload safety check
Robotgiggle 4774953
Add a bunch of comments
Robotgiggle 7a8996e
Remove nullable annotation from hex holder and casting env pigment me…
Robotgiggle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -4,12 +4,15 @@ | |
| import at.petrak.hexcasting.api.casting.eval.env.PackagedItemCastEnv; | ||
| import at.petrak.hexcasting.api.casting.eval.vm.CastingVM; | ||
| import at.petrak.hexcasting.api.casting.iota.Iota; | ||
| import at.petrak.hexcasting.api.casting.iota.PatternIota; | ||
| import at.petrak.hexcasting.api.casting.iota.IotaType; | ||
| import at.petrak.hexcasting.api.item.HexHolderItem; | ||
| import at.petrak.hexcasting.api.pigment.FrozenPigment; | ||
| import at.petrak.hexcasting.common.lib.HexDataComponents; | ||
| import at.petrak.hexcasting.common.msgs.MsgNewSpiralPatternsS2C; | ||
| import at.petrak.hexcasting.xplat.IXplatAbstractions; | ||
| import com.mojang.serialization.Codec; | ||
| import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
| import net.minecraft.network.RegistryFriendlyByteBuf; | ||
| import net.minecraft.network.codec.ByteBufCodecs; | ||
| import net.minecraft.network.codec.StreamCodec; | ||
| import net.minecraft.resources.ResourceLocation; | ||
| import net.minecraft.server.level.ServerLevel; | ||
| import net.minecraft.server.level.ServerPlayer; | ||
|
|
@@ -34,8 +37,6 @@ | |
| * Item that holds a list of patterns in it ready to be cast | ||
| */ | ||
| public abstract class ItemPackagedHex extends ItemMediaHolder implements HexHolderItem { | ||
| public static final String TAG_PROGRAM = "patterns"; | ||
| public static final String TAG_PIGMENT = "pigment"; | ||
| public static final ResourceLocation HAS_PATTERNS_PRED = modLoc("has_patterns"); | ||
|
|
||
| public ItemPackagedHex(Properties pProperties) { | ||
|
|
@@ -58,34 +59,32 @@ public boolean canProvideMedia(ItemStack stack) { | |
|
|
||
| @Override | ||
| public boolean hasHex(ItemStack stack) { | ||
| return stack.has(HexDataComponents.HEX_HOLDER_PATTERNS.get()); | ||
| return stack.has(HexDataComponents.HEX_HOLDER.get()); | ||
| } | ||
|
|
||
| @Override | ||
| public @Nullable List<Iota> getHex(ItemStack stack, ServerLevel level) { | ||
| return stack.get(HexDataComponents.HEX_HOLDER_PATTERNS.get()); | ||
| var hexHolder = stack.get(HexDataComponents.HEX_HOLDER.get()); | ||
| return (hexHolder != null) ? hexHolder.hex() : null; | ||
| } | ||
|
|
||
| @Override | ||
| public void writeHex(ItemStack stack, List<Iota> program, @Nullable FrozenPigment pigment, long media) { | ||
| stack.set(HexDataComponents.HEX_HOLDER_PATTERNS.get(), program); | ||
| if (pigment != null) | ||
| stack.set(HexDataComponents.PIGMENT.get(), pigment); | ||
|
|
||
| stack.set(HexDataComponents.HEX_HOLDER.get(), new HexHolder(program, pigment)); | ||
| withMedia(stack, media, media); | ||
| } | ||
|
|
||
| @Override | ||
| public void clearHex(ItemStack stack) { | ||
| stack.remove(HexDataComponents.HEX_HOLDER_PATTERNS.get()); | ||
| stack.remove(HexDataComponents.PIGMENT.get()); | ||
| stack.remove(HexDataComponents.HEX_HOLDER.get()); | ||
| stack.remove(HexDataComponents.MEDIA.get()); | ||
| stack.remove(HexDataComponents.MEDIA_MAX.get()); | ||
| } | ||
|
|
||
| @Override | ||
| public @Nullable FrozenPigment getPigment(ItemStack stack) { | ||
| return stack.get(HexDataComponents.PIGMENT.get()); | ||
| var hexHolder = stack.get(HexDataComponents.HEX_HOLDER.get()); | ||
| return (hexHolder != null) ? hexHolder.pigment() : null; | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -147,4 +146,18 @@ public InteractionResultHolder<ItemStack> use(Level world, Player player, Intera | |
| public UseAnim getUseAnimation(ItemStack pStack) { | ||
| return UseAnim.BLOCK; | ||
| } | ||
|
|
||
| public record HexHolder(List<Iota> hex, FrozenPigment pigment) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would there be any value in making this a |
||
| public static final Codec<HexHolder> CODEC = RecordCodecBuilder.create(inst -> | ||
| inst.group( | ||
| IotaType.TYPED_CODEC.listOf().fieldOf("hex").forGetter(HexHolder::hex), | ||
| FrozenPigment.CODEC.fieldOf("pigment").forGetter(HexHolder::pigment) | ||
| ).apply(inst, HexHolder::new) | ||
| ); | ||
| public static final StreamCodec<RegistryFriendlyByteBuf, HexHolder> STREAM_CODEC = StreamCodec.composite( | ||
| IotaType.TYPED_STREAM_CODEC.apply(ByteBufCodecs.list()), HexHolder::hex, | ||
| FrozenPigment.STREAM_CODEC, HexHolder::pigment, | ||
| HexHolder::new | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.