-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,022 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* This file is part of npc-lib, licensed under the MIT License (MIT). | ||
* | ||
* Copyright (c) 2022-2025 Julian M., Pasqual K. and 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. | ||
*/ | ||
|
||
plugins { | ||
alias(libs.plugins.fabricLoom) | ||
} | ||
|
||
dependencies { | ||
minecraft(libs.minecraft) | ||
modImplementation(libs.fabricLoader) | ||
mappings(loom.officialMojangMappings()) | ||
|
||
modImplementation(platform(libs.fabricApiBom)) | ||
modImplementation(libs.fabricApiNetworkingV1) | ||
|
||
api(projects.npcLibApi) | ||
api(projects.npcLibCommon) | ||
|
||
implementation(libs.geantyref) | ||
} | ||
|
||
tasks.withType<JavaCompile> { | ||
options.release.set(21) | ||
} | ||
|
||
tasks.withType<ProcessResources> { | ||
val props = mapOf("version" to project.version) | ||
inputs.properties(props) | ||
filesMatching("fabric.mod.json") { | ||
expand(props) | ||
} | ||
} | ||
|
||
loom { | ||
accessWidenerPath.set(project.file("src/main/resources/npc_lib.accesswidener")) | ||
} |
38 changes: 38 additions & 0 deletions
38
fabric/src/main/java/com/github/juliarn/npclib/fabric/FabricModInitializer.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,38 @@ | ||
/* | ||
* This file is part of npc-lib, licensed under the MIT License (MIT). | ||
* | ||
* Copyright (c) 2022-2025 Julian M., Pasqual K. and 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 com.github.juliarn.npclib.fabric; | ||
|
||
import net.fabricmc.api.ModInitializer; | ||
import net.minecraft.server.MinecraftServer; | ||
|
||
public final class FabricModInitializer implements ModInitializer { | ||
|
||
public static MinecraftServer theServer; | ||
|
||
@Override | ||
public void onInitialize() { | ||
|
||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
fabric/src/main/java/com/github/juliarn/npclib/fabric/FabricPlatform.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,69 @@ | ||
/* | ||
* This file is part of npc-lib, licensed under the MIT License (MIT). | ||
* | ||
* Copyright (c) 2022-2025 Julian M., Pasqual K. and 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 com.github.juliarn.npclib.fabric; | ||
|
||
import com.github.juliarn.npclib.api.Platform; | ||
import com.github.juliarn.npclib.common.platform.CommonPlatformBuilder; | ||
import com.github.juliarn.npclib.fabric.protocol.FabricProtocolAdapter; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.world.item.ItemStack; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public final class FabricPlatform extends CommonPlatformBuilder<ServerLevel, ServerPlayer, ItemStack, Object> { | ||
|
||
@Override | ||
protected void prepareBuild() { | ||
// set the default task manager | ||
if (this.taskManager == null) { | ||
this.taskManager = FabricPlatformTaskManager.taskManager(); | ||
} | ||
|
||
// set the default version accessor | ||
if (this.versionAccessor == null) { | ||
this.versionAccessor = FabricVersionAccessor.versionNameBased(); | ||
} | ||
|
||
// set the default world accessor | ||
if (this.worldAccessor == null) { | ||
this.worldAccessor = FabricWorldAccessor.keyBased(); | ||
} | ||
|
||
// set the default packet adapter | ||
if (this.packetAdapter == null) { | ||
this.packetAdapter = FabricProtocolAdapter.fabricProtocolAdapter(); | ||
} | ||
|
||
// set the default logger if no logger was provided | ||
if (this.logger == null) { | ||
this.logger = FabricPlatformLogger.logger(); | ||
} | ||
} | ||
|
||
@Override | ||
protected @NotNull Platform<ServerLevel, ServerPlayer, ItemStack, Object> doBuild() { | ||
return null; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
fabric/src/main/java/com/github/juliarn/npclib/fabric/FabricPlatformLogger.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,64 @@ | ||
/* | ||
* This file is part of npc-lib, licensed under the MIT License (MIT). | ||
* | ||
* Copyright (c) 2022-2025 Julian M., Pasqual K. and 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 com.github.juliarn.npclib.fabric; | ||
|
||
import com.github.juliarn.npclib.api.log.PlatformLogger; | ||
import com.mojang.logging.LogUtils; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.slf4j.Logger; | ||
|
||
public final class FabricPlatformLogger implements PlatformLogger { | ||
|
||
private static final Logger LOGGER = LogUtils.getLogger(); | ||
private static final FabricPlatformLogger INSTANCE = new FabricPlatformLogger(); | ||
|
||
private FabricPlatformLogger() { | ||
} | ||
|
||
public static @NotNull PlatformLogger logger() { | ||
return INSTANCE; | ||
} | ||
|
||
@Override | ||
public void info(@NotNull String message) { | ||
LOGGER.info(message); | ||
} | ||
|
||
@Override | ||
public void warning(@NotNull String message) { | ||
LOGGER.warn(message); | ||
} | ||
|
||
@Override | ||
public void error(@NotNull String message) { | ||
LOGGER.error(message); | ||
} | ||
|
||
@Override | ||
public void error(@NotNull String message, @Nullable Throwable exception) { | ||
LOGGER.error(message, exception); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
fabric/src/main/java/com/github/juliarn/npclib/fabric/FabricPlatformTaskManager.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,52 @@ | ||
/* | ||
* This file is part of npc-lib, licensed under the MIT License (MIT). | ||
* | ||
* Copyright (c) 2022-2025 Julian M., Pasqual K. and 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 com.github.juliarn.npclib.fabric; | ||
|
||
import com.github.juliarn.npclib.api.PlatformTaskManager; | ||
import com.github.juliarn.npclib.common.task.AsyncPlatformTaskManager; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public final class FabricPlatformTaskManager extends AsyncPlatformTaskManager { | ||
|
||
private static final FabricPlatformTaskManager INSTANCE = new FabricPlatformTaskManager(); | ||
|
||
private FabricPlatformTaskManager() { | ||
super("Fabric"); | ||
} | ||
|
||
public static @NotNull PlatformTaskManager taskManager() { | ||
return INSTANCE; | ||
} | ||
|
||
@Override | ||
public void scheduleSync(@NotNull Runnable task) { | ||
FabricModInitializer.theServer.execute(task); | ||
} | ||
|
||
@Override | ||
public void scheduleDelayedSync(@NotNull Runnable task, int delayTicks) { | ||
throw new UnsupportedOperationException("not implemented on fabric platform"); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
fabric/src/main/java/com/github/juliarn/npclib/fabric/FabricVersionAccessor.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,85 @@ | ||
/* | ||
* This file is part of npc-lib, licensed under the MIT License (MIT). | ||
* | ||
* Copyright (c) 2022-2025 Julian M., Pasqual K. and 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 com.github.juliarn.npclib.fabric; | ||
|
||
import com.github.juliarn.npclib.api.PlatformVersionAccessor; | ||
import net.minecraft.SharedConstants; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public final class FabricVersionAccessor { | ||
|
||
private static int[] extractServerVersionParts() { | ||
String[] parts = SharedConstants.getCurrentVersion().getName().split("\\."); | ||
if (parts.length == 2 || parts.length == 3) { | ||
// should be in the correct format, just to make sure | ||
try { | ||
int major = Integer.parseInt(parts[0]); | ||
int minor = Integer.parseInt(parts[1]); | ||
int patch = parts.length == 3 ? Integer.parseInt(parts[2]) : 0; | ||
|
||
// return the version array from that | ||
return new int[]{major, minor, patch}; | ||
} catch (NumberFormatException ignored) { | ||
} | ||
} | ||
|
||
// unable to parse | ||
return new int[0]; | ||
} | ||
|
||
public static @NotNull PlatformVersionAccessor versionNameBased() { | ||
return FabricVersionNameAccessor.INSTANCE; | ||
} | ||
|
||
private static final class FabricVersionNameAccessor implements PlatformVersionAccessor { | ||
|
||
private static final int[] VERSION_NUMBER_PARTS = extractServerVersionParts(); | ||
private static final FabricVersionNameAccessor INSTANCE = new FabricVersionNameAccessor(); | ||
|
||
private static int safeGetPart(int index, int def) { | ||
return VERSION_NUMBER_PARTS.length > index ? VERSION_NUMBER_PARTS[index] : def; | ||
} | ||
|
||
@Override | ||
public int major() { | ||
return safeGetPart(0, 1); | ||
} | ||
|
||
@Override | ||
public int minor() { | ||
return safeGetPart(1, 0); | ||
} | ||
|
||
@Override | ||
public int patch() { | ||
return safeGetPart(2, 0); | ||
} | ||
|
||
@Override | ||
public boolean atLeast(int major, int minor, int patch) { | ||
return this.major() >= major && this.minor() >= major && this.patch() >= patch; | ||
} | ||
} | ||
} |
Oops, something went wrong.