Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: FabricMC/fabric
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.94.1+1.20.4
Choose a base ref
...
head repository: FabricMC/fabric
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0.95.0+1.20.4
Choose a head ref
  • 3 commits
  • 39 files changed
  • 3 contributors

Commits on Jan 19, 2024

  1. Data Attachment API (#3476)

    * Data Attachment API
    
    * javadoc
    
    * Remove AttachmentSerializer & independent syncability and persistence
    
    - removed AttachmentSerializer in favor of codecs
    - renamed serializability to "persistence"
    - made persistence and syncability independent switches
    - reworked convenience registry methods to use Suppliers from the get-go
    
    * Move some serialization-related methods to impl
    
    - changed logger name
    
    * rename Attachment to AttachmentType
    
    * Added DefaultedAttachmentType and reworded Javadoc
    
    * add warning in getAttached
    
    * javadoc
    
    * fix defaulted API
    
    * Add unit tests
    
    * remove DefaultedAttachmentType, add helper methods
    
    bikeshedding inbound
    
    * add more unit tests
    
    * add testmod
    
    it works
    
    * stash syncing for a further PR
    
    * missed license header
    
    * address most reviews
    
    * more reviews
    
    * naming convention
    
    * fix tyop
    
    * fix invalid file name error
    
    * simplify API in the absence of sync
    
    It was established that the presence of a codec might be useful for other things than persistence, and while this seems to couple the two, the API can be changed later in a backward-compatible way if need be.
    
    * couple codec with persistence
    
    committing to the change I mentioned previously
    
    * little fixes
    
    * Fix mixins + requests
    
    - Copy attachments on entity copy,& with a customizable flag in the case of player respawn
    - Call relevant change-notifying methods when calling setAttached on BEs and chunks
    - Change persistence key
    - Fix mixin visibility
    
    * Write tests for entity copy
    
    * replace mixin by COPY_FROM event
    
    * missed license header
    
    * more advanced copy mechanics
    
    - attachments require an EntityCopyHandler to be copied across entities
    - a copy handler is automatically derived if there's a codec
    - updated javadoc for chunk and BE targets
    
    * Revert "more advanced copy mechanics"
    
    This reverts commit 3f53b55.
    
    * replaced complicated API by a stern warning
    
    - also handled cross-world entity teleportation
    
    * add gametest
    
    * fix compilation
    
    * flipped boolean
    
    * forgot some more bools to flip
    
    * requests
    
    * fix FMJ
    
    * fix BE mixin and add gametest
    
    * add client player entity copying
    
    * Use new mob conversion event
    
    ---------
    
    Co-authored-by: modmuss <modmuss50@gmail.com>
    Syst3ms and modmuss50 authored Jan 19, 2024
    Copy the full SHA
    25e1b47 View commit details
  2. Copy the full SHA
    0d29db7 View commit details
  3. Bump version

    modmuss50 committed Jan 19, 2024
    Copy the full SHA
    3178723 View commit details
Showing with 2,217 additions and 7 deletions.
  1. +11 −0 fabric-data-attachment-api-v1/build.gradle
  2. +44 −0 ...v1/src/client/java/net/fabricmc/fabric/mixin/attachment/client/ClientPlayNetworkHandlerMixin.java
  3. +13 −0 fabric-data-attachment-api-v1/src/client/resources/fabric-data-attachment-api-v1.client.mixins.json
  4. +150 −0 ...ata-attachment-api-v1/src/main/java/net/fabricmc/fabric/api/attachment/v1/AttachmentRegistry.java
  5. +230 −0 ...-data-attachment-api-v1/src/main/java/net/fabricmc/fabric/api/attachment/v1/AttachmentTarget.java
  6. +96 −0 ...ic-data-attachment-api-v1/src/main/java/net/fabricmc/fabric/api/attachment/v1/AttachmentType.java
  7. +38 −0 ...ata-attachment-api-v1/src/main/java/net/fabricmc/fabric/impl/attachment/AttachmentEntrypoint.java
  8. +55 −0 ...ttachment-api-v1/src/main/java/net/fabricmc/fabric/impl/attachment/AttachmentPersistentState.java
  9. +91 −0 ...a-attachment-api-v1/src/main/java/net/fabricmc/fabric/impl/attachment/AttachmentRegistryImpl.java
  10. +110 −0 ...ttachment-api-v1/src/main/java/net/fabricmc/fabric/impl/attachment/AttachmentSerializingImpl.java
  11. +67 −0 ...ata-attachment-api-v1/src/main/java/net/fabricmc/fabric/impl/attachment/AttachmentTargetImpl.java
  12. +33 −0 ...-data-attachment-api-v1/src/main/java/net/fabricmc/fabric/impl/attachment/AttachmentTypeImpl.java
  13. +106 −0 ...-attachment-api-v1/src/main/java/net/fabricmc/fabric/mixin/attachment/AttachmentTargetsMixin.java
  14. +46 −0 ...c-data-attachment-api-v1/src/main/java/net/fabricmc/fabric/mixin/attachment/BlockEntityMixin.java
  15. +52 −0 ...nt-api-v1/src/main/java/net/fabricmc/fabric/mixin/attachment/BlockEntityUpdateS2CPacketMixin.java
  16. +59 −0 ...ta-attachment-api-v1/src/main/java/net/fabricmc/fabric/mixin/attachment/ChunkSerializerMixin.java
  17. +47 −0 fabric-data-attachment-api-v1/src/main/java/net/fabricmc/fabric/mixin/attachment/EntityMixin.java
  18. +42 −0 ...c-data-attachment-api-v1/src/main/java/net/fabricmc/fabric/mixin/attachment/ServerWorldMixin.java
  19. BIN fabric-data-attachment-api-v1/src/main/resources/assets/fabric-data-attachment-api-v1/icon.png
  20. +16 −0 fabric-data-attachment-api-v1/src/main/resources/fabric-data-attachment-api-v1.mixins.json
  21. +45 −0 fabric-data-attachment-api-v1/src/main/resources/fabric.mod.json
  22. +226 −0 ...ta-attachment-api-v1/src/test/java/net/fabricmc/fabric/test/attachment/CommonAttachmentTests.java
  23. +68 −0 ...ata-attachment-api-v1/src/testmod/java/net/fabricmc/fabric/test/attachment/AttachmentTestMod.java
  24. +94 −0 ...ent-api-v1/src/testmod/java/net/fabricmc/fabric/test/attachment/gametest/AttachmentCopyTests.java
  25. +85 −0 ...chment-api-v1/src/testmod/java/net/fabricmc/fabric/test/attachment/gametest/BlockEntityTests.java
  26. +31 −0 ...nt-api-v1/src/testmod/java/net/fabricmc/fabric/test/attachment/mixin/BlockEntityTypeAccessor.java
  27. +11 −0 ...ic-data-attachment-api-v1/src/testmod/resources/fabric-data-attachment-api-v1-testmod.mixins.json
  28. +24 −0 fabric-data-attachment-api-v1/src/testmod/resources/fabric.mod.json
  29. +40 −0 ...ering-v1/src/client/java/net/fabricmc/fabric/api/client/rendering/v1/AtlasSourceTypeRegistry.java
  30. +40 −0 ...ing-v1/src/client/java/net/fabricmc/fabric/impl/client/rendering/AtlasSourceTypeRegistryImpl.java
  31. +33 −0 ...ing-v1/src/client/java/net/fabricmc/fabric/mixin/client/rendering/AtlasSourceManagerAccessor.java
  32. +1 −0 fabric-rendering-v1/src/client/resources/fabric-rendering-v1.mixins.json
  33. +33 −0 ...-rendering-v1/src/testmod/java/net/fabricmc/fabric/test/rendering/CustomAtlasSourcesTestInit.java
  34. +5 −3 fabric-rendering-v1/src/testmod/resources/fabric.mod.json
  35. +154 −0 ...g-v1/src/testmodClient/java/net/fabricmc/fabric/test/rendering/client/CustomAtlasSourcesTest.java
  36. +6 −0 ...src/testmodClient/resources/assets/fabric-rendering-v1-testmod/models/item/double_iron_ingot.json
  37. +9 −0 fabric-rendering-v1/src/testmodClient/resources/assets/minecraft/atlases/blocks.json
  38. +5 −4 gradle.properties
  39. +1 −0 settings.gradle
11 changes: 11 additions & 0 deletions fabric-data-attachment-api-v1/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version = getSubprojectVersion(project)

moduleDependencies(project, [
'fabric-api-base',
':fabric-entity-events-v1',
':fabric-object-builder-api-v1'
])

testDependencies(project, [
':fabric-lifecycle-events-v1'
])
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.fabricmc.fabric.mixin.attachment.client;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.network.packet.s2c.play.PlayerRespawnS2CPacket;

import net.fabricmc.fabric.impl.attachment.AttachmentTargetImpl;

@Mixin(ClientPlayNetworkHandler.class)
abstract class ClientPlayNetworkHandlerMixin {
@WrapOperation(
method = "onPlayerRespawn",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;init()V")
)
private void copyAttachmentsOnClientRespawn(ClientPlayerEntity newPlayer, Operation<Void> init, PlayerRespawnS2CPacket packet, @Local(ordinal = 0) ClientPlayerEntity oldPlayer) {
/*
* The KEEP_ATTRIBUTES flag is not set on a death respawn, and set in all other cases
*/
AttachmentTargetImpl.copyOnRespawn(oldPlayer, newPlayer, !packet.hasFlag(PlayerRespawnS2CPacket.KEEP_ATTRIBUTES));
init.call(newPlayer);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"required": true,
"package": "net.fabricmc.fabric.mixin.attachment.client",
"compatibilityLevel": "JAVA_17",
"mixins": [
],
"injectors": {
"defaultRequire": 1
},
"client": [
"ClientPlayNetworkHandlerMixin"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.fabricmc.fabric.api.attachment.v1;

import java.util.Objects;
import java.util.function.Supplier;

import com.mojang.serialization.Codec;
import org.jetbrains.annotations.ApiStatus;

import net.minecraft.util.Identifier;

import net.fabricmc.fabric.impl.attachment.AttachmentRegistryImpl;

/**
* Class used to create and register {@link AttachmentType}s. To quickly create {@link AttachmentType}s, use one of the various
* {@code createXXX} methods:
* <ul>
* <li>{@link #create(Identifier)}: attachments will be neither persistent nor auto-initialized.</li>
* <li>{@link #createDefaulted(Identifier, Supplier)}: attachments will be auto-initialized, but not persistent.</li>
* <li>{@link #createPersistent(Identifier, Codec)}: attachments will be persistent, but not auto-initialized.</li>
* </ul>
*
* <p>For finer control over the attachment type and its properties, use {@link AttachmentRegistry#builder()} to
* get a {@link Builder} instance.</p>
*/
@ApiStatus.Experimental
public final class AttachmentRegistry {
private AttachmentRegistry() {
}

/**
* Creates <i>and registers</i> an attachment. The data will not be persisted.
*
* @param id the identifier of this attachment
* @param <A> the type of attached data
* @return the registered {@link AttachmentType} instance
*/
public static <A> AttachmentType<A> create(Identifier id) {
Objects.requireNonNull(id, "identifier cannot be null");

return AttachmentRegistry.<A>builder().buildAndRegister(id);
}

/**
* Creates <i>and registers</i> an attachment, that will be automatically initialized with a default value
* when an attachment does not exist on a given target, using {@link AttachmentTarget#getAttachedOrCreate(AttachmentType)}.
*
* @param id the identifier of this attachment
* @param initializer the initializer used to provide a default value
* @param <A> the type of attached data
* @return the registered {@link AttachmentType} instance
*/
public static <A> AttachmentType<A> createDefaulted(Identifier id, Supplier<A> initializer) {
Objects.requireNonNull(id, "identifier cannot be null");
Objects.requireNonNull(initializer, "initializer cannot be null");

return AttachmentRegistry.<A>builder()
.initializer(initializer)
.buildAndRegister(id);
}

/**
* Creates <i>and registers</i> an attachment, that will persist across server restarts.
*
* @param id the identifier of this attachment
* @param codec the codec used for (de)serialization
* @param <A> the type of attached data
* @return the registered {@link AttachmentType} instance
*/
public static <A> AttachmentType<A> createPersistent(Identifier id, Codec<A> codec) {
Objects.requireNonNull(id, "identifier cannot be null");
Objects.requireNonNull(codec, "codec cannot be null");

return AttachmentRegistry.<A>builder().persistent(codec).buildAndRegister(id);
}

/**
* Creates a {@link Builder}, that gives finer control over the attachment's properties.
*
* @param <A> the type of the attached data
* @return a {@link Builder} instance
*/
public static <A> Builder<A> builder() {
return AttachmentRegistryImpl.builder();
}

/**
* A builder for creating {@link AttachmentType}s with finer control over their properties.
*
* @param <A> the type of the attached data
*/
@ApiStatus.NonExtendable
public interface Builder<A> {
/**
* Declares that attachments should persist between server restarts, using the provided {@link Codec} for
* (de)serialization.
*
* @param codec the codec used for (de)serialization
* @return the builder
*/
Builder<A> persistent(Codec<A> codec);

/**
* Declares that when a player dies and respawns, the attachments corresponding of this type should remain.
*
* @return the builder
*/
Builder<A> copyOnDeath();

/**
* Sets the default initializer for this attachment type. The initializer will be called by
* {@link AttachmentTarget#getAttachedOrCreate(AttachmentType)} to automatically initialize attachments that
* don't yet exist. It must not return {@code null}.
*
* <p>It is <i>encouraged</i> for {@link A} to be an immutable data type, such as a primitive type
* or an immutable record.</p>
*
* <p>Otherwise, one must be very careful, as attachments <i>must not share any mutable state</i>.
* As an example, for a (mutable) list/array attachment type,
* the initializer should create a new independent instance each time it is called.</p>
*
* @param initializer the initializer
* @return the builder
*/
Builder<A> initializer(Supplier<A> initializer);

/**
* Builds and registers the {@link AttachmentType}.
*
* @param id the attachment's identifier
* @return the built and registered {@link AttachmentType}
*/
AttachmentType<A> buildAndRegister(Identifier id);
}
}
Loading