Skip to content

Commit

Permalink
Fix mythicmobs-5.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Mgazul committed Dec 9, 2024
1 parent 582edfd commit 434ab8f
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public static byte[] injectPluginFix(String mainClass, String className, byte[]
case "com.earth2me.essentials.utils.VersionUtil" -> node -> helloWorld(node, 110, 109);
case "net.ess3.nms.refl.providers.ReflServerStateProvider" -> node -> helloWorld(node, "u", "U");
case "net.Zrips.CMILib.Reflections" -> node -> helloWorld(node, "bR", "field_7512");
case "io.lumine.mythic.core.volatilecode.v1_20_R1.VolatileEntityHandlerImpl" -> node -> helloWorld(node, "c", "d"); // mythicmobs-5.8
default -> null;
};
return patcher == null ? clazz : patch(clazz, patcher);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,51 @@ public interface PersistentDataContainer {
*/
@NotNull
PersistentDataAdapterContext getAdapterContext();

// Paper start
/**
* Returns if the persistent metadata provider has metadata registered
* matching the provided key.
*
* @param key the key for which existence should be checked.
*
* @return whether the key exists
*
* @throws NullPointerException if the key to look up is null
*/
boolean has(@NotNull NamespacedKey key);

/**
* Serialize this {@link PersistentDataContainer} instance to a
* byte array.
*
* @return a binary representation of this container
* @throws java.io.IOException if we fail to write this container to a byte array
*/
byte @NotNull [] serializeToBytes() throws java.io.IOException;

/**
* Read values from a serialised byte array into this
* {@link PersistentDataContainer} instance.
*
* @param bytes the byte array to read from
* @param clear if true, this {@link PersistentDataContainer} instance
* will be cleared before reading
* @throws java.io.IOException if the byte array has an invalid format
*/
void readFromBytes(byte @NotNull [] bytes, boolean clear) throws java.io.IOException;

/**
* Read values from a serialised byte array into this
* {@link PersistentDataContainer} instance.
* This method has the same effect as
* <code>PersistentDataContainer#readFromBytes(bytes, true)</code>
*
* @param bytes the byte array to read from
* @throws java.io.IOException if the byte array has an invalid format
*/
default void readFromBytes(byte @NotNull [] bytes) throws java.io.IOException {
this.readFromBytes(bytes, true);
}
// Paper end
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,44 @@ public int hashCode() {
public Map<String, Object> serialize() {
return (Map<String, Object>) CraftNBTTagConfigSerializer.serialize(toTagCompound());
}

// Paper start
public void clear() {
this.customDataTags.clear();
}

@Override
public boolean has(NamespacedKey key) {
Preconditions.checkArgument(key != null, "The provided key for the custom value was null");

return this.customDataTags.containsKey(key.toString());
}

@Override
public byte[] serializeToBytes() throws java.io.IOException {
net.minecraft.nbt.CompoundTag root = this.toTagCompound();
java.io.ByteArrayOutputStream byteArrayOutput = new java.io.ByteArrayOutputStream();
try (java.io.DataOutputStream dataOutput = new java.io.DataOutputStream(byteArrayOutput)) {
net.minecraft.nbt.NbtIo.write(root, dataOutput);
return byteArrayOutput.toByteArray();
}
}

@Override
public void readFromBytes(byte[] bytes, boolean clear) throws java.io.IOException {
if (clear) {
this.clear();
}
try (java.io.DataInputStream dataInput = new java.io.DataInputStream(new java.io.ByteArrayInputStream(bytes))) {
net.minecraft.nbt.CompoundTag compound = net.minecraft.nbt.NbtIo.read(dataInput);
this.putAll(compound);
}
}

public Map<String, Tag> getTagsCloned() {
final Map<String, Tag> tags = new HashMap<>();
this.customDataTags.forEach((key, tag) -> tags.put(key, tag.copy()));
return tags;
}
// Paper end
}

0 comments on commit 434ab8f

Please sign in to comment.