Update 1.21 - #5301
Conversation
|
|
||
| public static final Codec<SpoilContext> CODEC = CompoundTag.CODEC.xmap(SpoilContext::deserializeNBT, | ||
| SpoilContext::serializeNBT); | ||
| public static final StreamCodec<ByteBuf, SpoilContext> STREAM_CODEC = ByteBufCodecs.COMPOUND_TAG |
There was a problem hiding this comment.
same here for the stream codec
9a6ae73 to
7e5420c
Compare
9043220 to
8a69f41
Compare
| private static SpoilContext build(ResourceKey<Level> levelKey, BlockPos pos, Integer entityId, | ||
| ResourceLocation itemHandlerSourceId, CompoundTag itemHandlerData, int slot) { | ||
| MinecraftServer server = ServerLifecycleHooks.getCurrentServer(); | ||
| Level level = server == null ? null : server.getLevel(levelKey); | ||
| return new SpoilContext(level, pos, level != null && entityId != null ? level.getEntity(entityId) : null, | ||
| ItemHandlerSource.getById(itemHandlerSourceId), itemHandlerData, slot); | ||
| } |
There was a problem hiding this comment.
| private static SpoilContext build(ResourceKey<Level> levelKey, BlockPos pos, Integer entityId, | |
| ResourceLocation itemHandlerSourceId, CompoundTag itemHandlerData, int slot) { | |
| MinecraftServer server = ServerLifecycleHooks.getCurrentServer(); | |
| Level level = server == null ? null : server.getLevel(levelKey); | |
| return new SpoilContext(level, pos, level != null && entityId != null ? level.getEntity(entityId) : null, | |
| ItemHandlerSource.getById(itemHandlerSourceId), itemHandlerData, slot); | |
| } | |
| private static SpoilContext build(Optional<ResourceKey<Level>> dimension, Optional<BlockPos> pos, Optional<UUID> entityId, | |
| Optional<ResourceLocation> itemHandlerSourceId, Optional<CompoundTag> itemHandlerData, int slot) { | |
| MinecraftServer server = ServerLifecycleHooks.getCurrentServer(); | |
| Level level = server == null || dimension.isEmpty() ? null : server.getLevel(dimension.get()); | |
| return new SpoilContext(level, pos, level != null && entityId.isPresent() ? level.getEntities().get(entityId.get()) : null, | |
| itemHandlerSourceId.isPresent() ? ItemHandlerSource.getById(itemHandlerSourceId.get()) : null, itemHandlerData.orElse(null), slot); | |
| } |
| public static final Codec<SpoilContext> CODEC = RecordCodecBuilder.create(instance -> instance.group( | ||
| Level.RESOURCE_KEY_CODEC.optionalFieldOf("level", null) | ||
| .forGetter(ctx -> ctx.level == null ? null : ctx.level.dimension()), | ||
| BlockPos.CODEC.optionalFieldOf("pos", null).forGetter(SpoilContext::pos), | ||
| Codec.INT.optionalFieldOf("entity", null).forGetter(ctx -> ctx.entity == null ? null : ctx.entity.getId()), | ||
| ResourceLocation.CODEC.optionalFieldOf("item_handler", null) | ||
| .forGetter(ctx -> ctx.itemHandlerSource == null ? null : ctx.itemHandlerSource.getId()), | ||
| CompoundTag.CODEC.optionalFieldOf("item_handler_data", null).forGetter(SpoilContext::itemHandlerData), | ||
| Codec.INT.optionalFieldOf("slot", -1).forGetter(SpoilContext::slot)).apply(instance, SpoilContext::build)); |
There was a problem hiding this comment.
DFU actually really hates null default values, so do this instead:
| public static final Codec<SpoilContext> CODEC = RecordCodecBuilder.create(instance -> instance.group( | |
| Level.RESOURCE_KEY_CODEC.optionalFieldOf("level", null) | |
| .forGetter(ctx -> ctx.level == null ? null : ctx.level.dimension()), | |
| BlockPos.CODEC.optionalFieldOf("pos", null).forGetter(SpoilContext::pos), | |
| Codec.INT.optionalFieldOf("entity", null).forGetter(ctx -> ctx.entity == null ? null : ctx.entity.getId()), | |
| ResourceLocation.CODEC.optionalFieldOf("item_handler", null) | |
| .forGetter(ctx -> ctx.itemHandlerSource == null ? null : ctx.itemHandlerSource.getId()), | |
| CompoundTag.CODEC.optionalFieldOf("item_handler_data", null).forGetter(SpoilContext::itemHandlerData), | |
| Codec.INT.optionalFieldOf("slot", -1).forGetter(SpoilContext::slot)).apply(instance, SpoilContext::build)); | |
| // spotless:off | |
| public static final Codec<SpoilContext> CODEC = RecordCodecBuilder.create(instance -> instance.group( | |
| Level.RESOURCE_KEY_CODEC.optionalFieldOf("dimension").forGetter(ctx -> ctx.level == null ? Optional.empty() : Optional.of(ctx.level.dimension())), | |
| BlockPos.CODEC.optionalFieldOf("pos").forGetter(ctx -> Optional.ofNullable(ctx.pos)), | |
| UUIDUtil.CODEC.optionalFieldOf("entity").forGetter(ctx -> ctx.entity == null ? Optional.empty() : Optional.of(ctx.entity.getUUID())), | |
| ResourceLocation.CODEC.optionalFieldOf("item_handler").forGetter(ctx -> ctx.itemHandlerSource == null ? Optional.empty() : Optional.of(ctx.itemHandlerSource.getId())), | |
| CompoundTag.CODEC.optionalFieldOf("item_handler_data").forGetter(ctx -> Optional.ofNullable(ctx.itemHandlerData)), | |
| Codec.INT.optionalFieldOf("slot", -1).forGetter(SpoilContext::slot) | |
| ).apply(instance, SpoilContext::build)); | |
| // spotless:on |
Another suggestion will follow for the builder function.
P.S. I also changed the type of the entity field because that ID isn't consistent across world loads.
There was a problem hiding this comment.
Also add an 'empty' context as a default value:
public static final SpoilContext EMPTY = new SpoilContext();There was a problem hiding this comment.
Add this to injected_interfaces/interfaces.json.
|
|
||
| public interface ISpoilableItemStackExtension { | ||
|
|
||
| void gtceu$setStack(ItemStack newStack); |
There was a problem hiding this comment.
Rename this method to gtceu$forceMyContentTo.
this should really be implemented as swapping the ItemStack instance to another one, though.
| private ContentModifier outputModifier = ContentModifier.IDENTITY; | ||
| private ContentModifier tickInputModifier = ContentModifier.IDENTITY; | ||
| private ContentModifier tickOutputModifier = ContentModifier.IDENTITY; | ||
| private BiConsumer<GTRecipe, Object> actualOutputModifier = (recipe, object) -> {}; |
There was a problem hiding this comment.
does this also include the (optional) KJS output modifiers from GTRecipe?
| return new CustomItemStackHandler(player.getInventory().items); | ||
| } else return null; | ||
| } | ||
| }; |
There was a problem hiding this comment.
Consider adding a 3rd default type: generic entity inventory.
/**
* Represents getting an item handler as an entity's inventory (used if {@link SpoilContext#entity} is NOT a
* {@link Player})
*/
public static final ItemHandlerSource ENTITY_CAPABILITY = new ItemHandlerSource(GTCEu.id("entity_capability")) {
@Override
protected @Nullable IItemHandler getHandler(SpoilContext ctx) {
if (ctx.entity != null) {
return ctx.entity.getCapability(Capabilities.ItemHandler.ENTITY);
} else {
return null;
}
}
};| public SpoilContext(@NotNull Entity entity) { | ||
| this(entity.level(), entity.blockPosition(), entity, null, null, -1); |
There was a problem hiding this comment.
(for the "generic entity" item handler source)
| public SpoilContext(@NotNull Entity entity) { | |
| this(entity.level(), entity.blockPosition(), entity, null, null, -1); | |
| public SpoilContext(@NotNull Entity entity, int slot) { | |
| this(entity.level(), entity.blockPosition(), entity, ItemHandlerSource.ENTITY_INVENTORY, null, slot); |
| if (side == null) return this.withItemHandlerSource(ItemHandlerSource.BLOCK_CAPABILITY); | ||
| return this.withItemHandlerSource(ItemHandlerSource.BLOCK_CAPABILITY) | ||
| .withItemHandlerData("side", StringTag.valueOf(side.getSerializedName())); |
There was a problem hiding this comment.
| if (side == null) return this.withItemHandlerSource(ItemHandlerSource.BLOCK_CAPABILITY); | |
| return this.withItemHandlerSource(ItemHandlerSource.BLOCK_CAPABILITY) | |
| .withItemHandlerData("side", StringTag.valueOf(side.getSerializedName())); | |
| SpoilContext self = this.withItemHandlerSource(ItemHandlerSource.BLOCK_CAPABILITY); | |
| if (side != null) { | |
| self = self.withItemHandlerData("side", StringTag.valueOf(side.getSerializedName())); | |
| } | |
| return self; |
| @Nullable BlockPos pos, | ||
| @Nullable Entity entity, | ||
| @Nullable ItemHandlerSource itemHandlerSource, | ||
| @Nullable CompoundTag itemHandlerData, |
There was a problem hiding this comment.
This field should be made private if at all possible so people can't mistakenly modify it.
| private void gtceu$tickFreshness(Level level, Entity entity, int inventorySlot, boolean isCurrentItem, | ||
| CallbackInfo ci) { | ||
| if (entity instanceof Player player) gtceu$updateFreshness(new SpoilContext(player, inventorySlot), true); | ||
| else gtceu$updateFreshness(new SpoilContext(entity), true); |
There was a problem hiding this comment.
(for the "generic entity" item handler source)
| else gtceu$updateFreshness(new SpoilContext(entity), true); | |
| else gtceu$updateFreshness(new SpoilContext(entity, inventorySlot), true); |
What
I cherry-picked 4 commits into 1.21:
42bfe72Delete Unused Mixins (Delete Unused Mixins #5297)24ce411Spoilage (Spoilage #3874)9490c65bugfix: corrected a typo in the ru word tooltip_energy_cracking (bugfix: corrected a typo in the ru word tooltip_energy_cracking #5280)e1b6f14Update zh_tw.json (Update zh_tw.json #4747)Implementation Details
Uhh spoilage uses data components now i guess. Also eliminated some spoilage-related mixins since they weren't needed anymore
AI Usage
no
Outcome
1.21.1 is up to date and i get to work on modular armor yaaaaaay
How Was This Tested
logged into the game, ran gametests