-
-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'api-8' into fix/worldmanager
# Conflicts: # src/main/java/org/spongepowered/common/world/server/SpongeWorldManager.java
- Loading branch information
Showing
22 changed files
with
535 additions
and
23 deletions.
There are no files selected for viewing
Submodule SpongeAPI
updated
1 files
+2 −0 | src/main/java/org/spongepowered/api/data/persistence/DataFormats.java |
33 changes: 33 additions & 0 deletions
33
.../src/main/java/org/spongepowered/forge/bridge/minecraftforge/fml/ForgeRegistryBridge.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* This file is part of Sponge, licensed under the MIT License (MIT). | ||
* | ||
* Copyright (c) SpongePowered <https://www.spongepowered.org> | ||
* Copyright (c) contributors | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package org.spongepowered.forge.bridge.minecraftforge.fml; | ||
|
||
import org.spongepowered.common.bridge.core.RegistryBridge; | ||
|
||
public interface ForgeRegistryBridge<T> { | ||
|
||
RegistryBridge<T> bridge$parent(); | ||
|
||
} |
89 changes: 89 additions & 0 deletions
89
...java/org/spongepowered/forge/mixin/core/minecraftforge/core/ForgeRegistryMixin_Forge.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* This file is part of Sponge, licensed under the MIT License (MIT). | ||
* | ||
* Copyright (c) SpongePowered <https://www.spongepowered.org> | ||
* Copyright (c) contributors | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package org.spongepowered.forge.mixin.core.minecraftforge.core; | ||
|
||
import com.google.common.collect.Maps; | ||
import net.minecraft.core.Registry; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraftforge.registries.ForgeRegistry; | ||
import net.minecraftforge.registries.IForgeRegistryEntry; | ||
import org.spongepowered.api.ResourceKey; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
import org.spongepowered.common.SpongeCommon; | ||
import org.spongepowered.common.bridge.core.RegistryBridge; | ||
import org.spongepowered.common.registry.SpongeRegistryEntry; | ||
import org.spongepowered.common.registry.SpongeRegistryType; | ||
import org.spongepowered.forge.bridge.minecraftforge.fml.ForgeRegistryBridge; | ||
|
||
import java.util.Map; | ||
import java.util.StringJoiner; | ||
|
||
@Mixin(ForgeRegistry.class) | ||
public abstract class ForgeRegistryMixin_Forge<V extends IForgeRegistryEntry<V>> implements ForgeRegistryBridge<V> { | ||
|
||
// @formatter:off | ||
@Shadow @Final private net.minecraft.resources.ResourceKey<Registry<V>> key; | ||
// @formatter:on | ||
|
||
private final Map<ResourceKey, RegistryBridge<V>> forge$parents = Maps.newHashMap(); | ||
private boolean forge$warnedIfNoParent; | ||
|
||
@Inject(method = "add(ILnet/minecraftforge/registries/IForgeRegistryEntry;Ljava/lang/String;)I", at = @At("TAIL")) | ||
public void forge$writeToParent(final int id, final V value, final String owner, final CallbackInfoReturnable<Integer> cir) { | ||
final ResourceKey root = (ResourceKey) (Object) this.key.getRegistryName(); | ||
final ResourceKey location = (ResourceKey) (Object) this.key.location(); | ||
|
||
if (!this.forge$warnedIfNoParent && this.forge$parents.isEmpty()) { | ||
// We only care about minecraft namespaced registries, as that is what we've got parents for. | ||
if (location.namespace().equalsIgnoreCase("minecraft")) { | ||
SpongeCommon.logger().error(String.format( | ||
"No parent registry found for %s, things might not work correctly!", | ||
new StringJoiner("/").add(root.formatted()).add(location.formatted()) | ||
)); | ||
} | ||
this.forge$warnedIfNoParent = true; | ||
} | ||
|
||
final SpongeRegistryEntry<V> entry = new SpongeRegistryEntry<>(new SpongeRegistryType<>(root, location), | ||
(ResourceKey) (Object) value.getRegistryName(), value); | ||
|
||
this.forge$parents.values().forEach(registry -> registry.bridge$register(entry)); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Inject(method = "setSlaveMap", at = @At("TAIL")) | ||
public void forge$establishParent(final ResourceLocation name, final Object obj, final CallbackInfo ci) { | ||
if (obj instanceof RegistryBridge) { | ||
this.forge$parents.put((ResourceKey) (Object) name, (RegistryBridge<V>) obj); | ||
} | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
.../org/spongepowered/forge/mixin/core/minecraftforge/core/NamespacedWrapperMixin_Forge.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* This file is part of Sponge, licensed under the MIT License (MIT). | ||
* | ||
* Copyright (c) SpongePowered <https://www.spongepowered.org> | ||
* Copyright (c) contributors | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package org.spongepowered.forge.mixin.core.minecraftforge.core; | ||
|
||
import net.minecraftforge.registries.IForgeRegistryEntry; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.common.mixin.core.core.WritableRegistryMixin; | ||
|
||
@Mixin(targets = {"net.minecraftforge.registries.NamespacedWrapper", "net.minecraftforge.registries.NamespacedDefaultedWrapper"}) | ||
public abstract class NamespacedWrapperMixin_Forge<T extends IForgeRegistryEntry<T>> extends WritableRegistryMixin<T> {} |
This file contains 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 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 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 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
98 changes: 98 additions & 0 deletions
98
src/main/java/org/spongepowered/common/data/persistence/SNBTDataFormat.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* This file is part of Sponge, licensed under the MIT License (MIT). | ||
* | ||
* Copyright (c) SpongePowered <https://www.spongepowered.org> | ||
* Copyright (c) contributors | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package org.spongepowered.common.data.persistence; | ||
|
||
import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
import net.minecraft.nbt.TagParser; | ||
import org.spongepowered.api.data.persistence.DataContainer; | ||
import org.spongepowered.api.data.persistence.DataView; | ||
import org.spongepowered.api.data.persistence.InvalidDataException; | ||
import org.spongepowered.api.data.persistence.InvalidDataFormatException; | ||
import org.spongepowered.api.data.persistence.StringDataFormat; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.io.OutputStream; | ||
import java.io.Reader; | ||
import java.io.Writer; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.stream.Collectors; | ||
|
||
public final class SNBTDataFormat implements StringDataFormat { | ||
|
||
private static BufferedReader createBufferedReader(final Reader reader) { | ||
if (reader instanceof BufferedReader) { | ||
return (BufferedReader) reader; | ||
} | ||
|
||
return new BufferedReader(reader); | ||
} | ||
|
||
@Override | ||
public DataContainer read(final String input) throws InvalidDataException, IOException { | ||
try { | ||
return NBTTranslator.INSTANCE.translate(TagParser.parseTag(input)); | ||
} catch (final CommandSyntaxException e) { | ||
throw new InvalidDataException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public DataContainer readFrom(final Reader input) throws InvalidDataException { | ||
try { | ||
return NBTTranslator.INSTANCE.translate( | ||
TagParser.parseTag(SNBTDataFormat.createBufferedReader(input).lines().collect(Collectors.joining("\n")))); | ||
} catch (final CommandSyntaxException e) { | ||
throw new InvalidDataException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public DataContainer readFrom(final InputStream input) throws InvalidDataFormatException { | ||
try { | ||
return NBTTranslator.INSTANCE.translate(TagParser.parseTag( | ||
new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n")))); | ||
} catch (final CommandSyntaxException e) { | ||
throw new InvalidDataException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public String write(final DataView data) throws IOException { | ||
return NBTTranslator.INSTANCE.translate(data).toString(); | ||
} | ||
|
||
@Override | ||
public void writeTo(final Writer output, final DataView data) throws IOException { | ||
output.write(NBTTranslator.INSTANCE.translate(data).toString()); | ||
} | ||
|
||
@Override | ||
public void writeTo(final OutputStream output, final DataView data) throws IOException { | ||
output.write(NBTTranslator.INSTANCE.translate(data).toString().getBytes(StandardCharsets.UTF_8)); | ||
} | ||
} |
This file contains 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.