-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit 60fd6cb
Showing
135 changed files
with
9,549 additions
and
0 deletions.
There are no files selected for viewing
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,19 @@ | ||
build/ | ||
*.ipr | ||
run/ | ||
*.iws | ||
out/ | ||
*.iml | ||
.gradle/ | ||
output/ | ||
bin/ | ||
libs/ | ||
|
||
.classpath | ||
.project | ||
.idea/ | ||
classes/ | ||
.metadata | ||
.vscode | ||
.settings | ||
*.launch |
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,55 @@ | ||
plugins { | ||
id "architectury-plugin" version "3.4-SNAPSHOT" | ||
id "dev.architectury.loom" version "1.3-SNAPSHOT" apply false | ||
} | ||
|
||
architectury { | ||
minecraft = rootProject.minecraft_version | ||
} | ||
|
||
subprojects { | ||
apply plugin: "dev.architectury.loom" | ||
|
||
loom { | ||
silentMojangMappingsLicense() | ||
} | ||
|
||
dependencies { | ||
minecraft "com.mojang:minecraft:${rootProject.minecraft_version}" | ||
// The following line declares the mojmap mappings, you may use other mappings as well | ||
mappings loom.officialMojangMappings() | ||
// The following line declares the yarn mappings you may select this one as well. | ||
// mappings "net.fabricmc:yarn:1.18.2+build.4:v2" | ||
} | ||
} | ||
|
||
allprojects { | ||
apply plugin: "java" | ||
apply plugin: "architectury-plugin" | ||
apply plugin: "maven-publish" | ||
|
||
base { | ||
archivesName = rootProject.archives_base_name | ||
} | ||
|
||
version = rootProject.mod_version | ||
group = rootProject.maven_group | ||
|
||
repositories { | ||
// Add repositories to retrieve artifacts from in here. | ||
// You should only use this when depending on other mods because | ||
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically. | ||
// See https://docs.gradle.org/current/userguide/declaring_repositories.html | ||
// for more information about repositories. | ||
maven { url = "https://raw.githubusercontent.com/Fuzss/modresources/main/maven/" } // Forge Config API Port | ||
} | ||
|
||
tasks.withType(JavaCompile) { | ||
options.encoding = "UTF-8" | ||
options.release = 17 | ||
} | ||
|
||
java { | ||
withSourcesJar() | ||
} | ||
} |
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,31 @@ | ||
architectury { | ||
common(rootProject.enabled_platforms.split(",")) | ||
} | ||
|
||
loom { | ||
accessWidenerPath = file("src/main/resources/dragonlib.accesswidener") | ||
} | ||
|
||
dependencies { | ||
// We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies | ||
// Do NOT use other classes from fabric loader | ||
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}" | ||
// Remove the next line if you don't want to depend on the API | ||
modApi ("dev.architectury:architectury:${rootProject.architectury_version}") | ||
modApi ("net.minecraftforge:forgeconfigapiport-fabric:${rootProject.forge_config_api_port_version}") | ||
|
||
} | ||
|
||
publishing { | ||
publications { | ||
mavenCommon(MavenPublication) { | ||
artifactId = rootProject.archives_base_name | ||
from components.java | ||
} | ||
} | ||
|
||
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. | ||
repositories { | ||
// Add repositories to publish to here. | ||
} | ||
} |
199 changes: 199 additions & 0 deletions
199
common/src/main/java/de/mrjulsen/mcdragonlib/DragonLib.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,199 @@ | ||
package de.mrjulsen.mcdragonlib; | ||
|
||
import com.google.common.base.Suppliers; | ||
import com.google.gson.Gson; | ||
|
||
import de.mrjulsen.mcdragonlib.internal.DragonLibBlock; | ||
import de.mrjulsen.mcdragonlib.net.builtin.IdentifiableResponsePacketBase; | ||
import de.mrjulsen.mcdragonlib.net.NetworkManagerBase; | ||
import de.mrjulsen.mcdragonlib.net.builtin.WritableSignPacket; | ||
import de.mrjulsen.mcdragonlib.util.ScheduledTask; | ||
import de.mrjulsen.mcdragonlib.util.TextUtils; | ||
import dev.architectury.event.events.client.ClientTickEvent; | ||
import dev.architectury.event.events.common.LifecycleEvent; | ||
import dev.architectury.event.events.common.TickEvent; | ||
import dev.architectury.platform.Platform; | ||
import dev.architectury.registry.registries.Registrar; | ||
import dev.architectury.registry.registries.Registries; | ||
import dev.architectury.registry.registries.RegistrySupplier; | ||
import net.fabricmc.api.EnvType; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.core.Registry; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.sounds.SoundEvent; | ||
import net.minecraft.world.item.BlockItem; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.state.BlockBehaviour; | ||
import net.minecraft.world.level.material.Material; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.text.DateFormat; | ||
import java.text.SimpleDateFormat; | ||
import java.util.List; | ||
import java.util.Random; | ||
import java.util.function.Supplier; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class DragonLib { | ||
|
||
public static final String MODID = "dragonlib"; | ||
public static final String MOD_NAME = "DragonLib"; | ||
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_NAME); | ||
|
||
public static final Random RANDOM = new Random(); | ||
public static final Gson GSON = new Gson(); | ||
public static final DateFormat DATE_FORMAT = new SimpleDateFormat(); | ||
|
||
public static final int TICKS_PER_DAY = Level.TICKS_PER_DAY; | ||
public static final int TICKS_PER_INGAME_HOUR = Level.TICKS_PER_DAY / 24; | ||
public static final int DAYTIME_SHIFT = 6000; | ||
public static final byte TPS = 1000 / MinecraftServer.MS_PER_TICK; | ||
public static final int TICKS_PER_REAL_LIFE_DAY = 86400 * TPS; | ||
/** One block pixel */ public static final float PIXEL = 1.0F / 16.0F; | ||
|
||
public static final ResourceLocation UI = new ResourceLocation(MODID, "textures/gui/ui.png"); | ||
public static final ResourceLocation NATIVE_WIDGETS = new ResourceLocation("minecraft:textures/gui/widgets.png"); | ||
|
||
public static final int NATIVE_UI_FONT_COLOR = 0xFF404040; | ||
public static final int NATIVE_BUTTON_FONT_COLOR_ACTIVE = 0xFFFFFFFF; | ||
public static final int NATIVE_BUTTON_FONT_COLOR_DISABLED = 0xFFA0A0A0; | ||
public static final int NATIVE_BUTTON_FONT_COLOR_HIGHLIGHT = 0xFFFFFFA0; | ||
|
||
/** 🐉 */ public static final Component TEXT_DRAGON = TextUtils.translate("text." + MODID + ".dragon"); | ||
public static final Component TEXT_NEXT = TextUtils.translate("text." + MODID + ".next"); | ||
public static final Component TEXT_PREVIOUS = TextUtils.translate("text." + MODID + ".previous"); | ||
public static final Component TEXT_GO_BACK = TextUtils.translate("text." + MODID + ".go_back"); | ||
public static final Component TEXT_GO_FORTH = TextUtils.translate("text." + MODID + ".go_forth"); | ||
public static final Component TEXT_GO_UP = TextUtils.translate("text." + MODID + ".go_down"); | ||
public static final Component TEXT_GO_DOWN = TextUtils.translate("text." + MODID + ".go_up"); | ||
public static final Component TEXT_GO_RIGHT= TextUtils.translate("text." + MODID + ".go_right"); | ||
public static final Component TEXT_GO_LEFT = TextUtils.translate("text." + MODID + ".go_left"); | ||
public static final Component TEXT_GO_TO_TOP = TextUtils.translate("text." + MODID + ".go_to_top"); | ||
public static final Component TEXT_GO_TO_BOTTOM = TextUtils.translate("text." + MODID + ".go_to_bottom"); | ||
public static final Component TEXT_RESET_DEFAULTS = TextUtils.translate("text." + MODID + ".reset_defaults"); | ||
public static final Component TEXT_EXPAND = TextUtils.translate("text." + MODID + ".expand"); | ||
public static final Component TEXT_COLLAPSE = TextUtils.translate("text." + MODID + ".collapse"); | ||
public static final Component TEXT_COUNT = TextUtils.translate("text." + MODID + ".count"); | ||
public static final Component TEXT_TRUE = TextUtils.translate("text." + MODID + ".true"); | ||
public static final Component TEXT_FALSE = TextUtils.translate("text." + MODID + ".false"); | ||
public static final Component TEXT_CLOSE = TextUtils.translate("text." + MODID + ".close"); | ||
public static final Component TEXT_SHOW = TextUtils.translate("text." + MODID + ".show"); | ||
public static final Component TEXT_HIDE = TextUtils.translate("text." + MODID + ".hide"); | ||
public static final Component TEXT_SEARCH = TextUtils.translate("text." + MODID + ".search"); | ||
public static final Component TEXT_REFRESH = TextUtils.translate("text." + MODID + ".refresh"); | ||
public static final Component TEXT_RELOAD = TextUtils.translate("text." + MODID + ".reload"); | ||
|
||
private static final Supplier<Registries> REGISTRIES = Suppliers.memoize(() -> Registries.get(MODID)); | ||
private static final Registrar<Item> ITEMS = REGISTRIES.get().get(Registry.ITEM_REGISTRY); | ||
private static final Registrar<Block> BLOCKS = REGISTRIES.get().get(Registry.BLOCK_REGISTRY); | ||
private static final Registrar<SoundEvent> SOUNDS = REGISTRIES.get().get(Registry.SOUND_EVENT_REGISTRY); | ||
|
||
/** A sample block which is added by DragonLib to test stuff. Does nothing by default and can safely be used in your world. Think of it as a small ~~easter~~ dragon egg. 🐉*/ | ||
public static final RegistrySupplier<Block> DRAGON_BLOCK = registerBlock("dragon", () -> new DragonLibBlock(BlockBehaviour.Properties.of(Material.STONE).strength(1.5f))); | ||
public static final RegistrySupplier<SoundEvent> DRAGON_ROAR = SOUNDS.register(new ResourceLocation(MODID, "dragon_roar"), () -> new SoundEvent(new ResourceLocation(MODID, "dragon_roar"))); | ||
public static final RegistrySupplier<SoundEvent> DRAGON_GROWL = SOUNDS.register(new ResourceLocation(MODID, "dragon_growl"), () -> new SoundEvent(new ResourceLocation(MODID, "dragon_growl"))); | ||
|
||
private static NetworkManagerBase dragonLibNet; | ||
|
||
private static <T extends Block, I extends BlockItem>RegistrySupplier<T> registerBlock(String name, Supplier<T> block) { | ||
RegistrySupplier<T> toReturn = BLOCKS.register(new ResourceLocation(MODID, name), block); | ||
registerBlockItem(name, toReturn, DragonLibBlock.DragonLibItem.class); | ||
return toReturn; | ||
} | ||
|
||
private static <T extends Block, I extends BlockItem>RegistrySupplier<Item> registerBlockItem(String name, RegistrySupplier<T> block, Class<I> blockItemClass) { | ||
return ITEMS.register(new ResourceLocation(MODID, name), () -> { | ||
try { | ||
return blockItemClass.getDeclaredConstructor(Block.class, Item.Properties.class).newInstance(block.get(), new Item.Properties()); | ||
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { | ||
LOGGER.error("Unable to register block item '" + name + "'.", e); | ||
return new BlockItem(block.get(), new Item.Properties()); | ||
} | ||
}); | ||
} | ||
|
||
|
||
|
||
/** | ||
* DO NOT CALL THIS METHOD FROM OTHER MODS! | ||
*/ | ||
public static void init() { | ||
//ITEMS.register(); | ||
dragonLibNet = new NetworkManagerBase(MODID, "dragonlib_network", List.of( | ||
IdentifiableResponsePacketBase.class, | ||
WritableSignPacket.class | ||
)); | ||
|
||
if (Platform.getEnv() == EnvType.CLIENT) { | ||
ClientTickEvent.CLIENT_POST.register((Minecraft mc) -> { | ||
NetworkManagerBase.callbackListenerTick(); | ||
}); | ||
} | ||
|
||
// On server tick | ||
TickEvent.Server.SERVER_POST.register((server) -> { | ||
ScheduledTask.runScheduledTasks(); | ||
}); | ||
|
||
// On Server stop | ||
LifecycleEvent.SERVER_STOPPING.register((server) -> { | ||
ScheduledTask.cancelAllTasks(); | ||
}); | ||
|
||
|
||
|
||
// After loading | ||
printDraconicWelcomeMessage(); | ||
} | ||
|
||
/** | ||
* @return The network manager of the DragonLib mod. Please use your own network manager in your mod. this is intended for DraagonLib's internal stuff. | ||
*/ | ||
public static final NetworkManagerBase getDragonLibNetworkManager() { | ||
return dragonLibNet; | ||
} | ||
|
||
/** | ||
* Why 🐲? Because I can. Let me bee 🐝 | ||
* @since 1.0 | ||
* @author MrJulsen | ||
* @see 🐉 | ||
*/ | ||
private static final void printDraconicWelcomeMessage() { | ||
String[] dragonTypes = {"Dragon", "Fire Dragon", "Ice Dragon", "Lightning Dragon", "Mountain Dragon", "Poison Dragon", "Drake", "Wyvern", "Wyrm", "MrJulsen", "Toothless", "Drogon", "Smaug", "Ender Dragon", "Spyro", "Do you think dragons exist?"}; | ||
final int charCount = 66; | ||
|
||
StringBuilder ver = new StringBuilder(); | ||
ver.append("Minecraft "); | ||
ver.append(Platform.isForge() ? "Forge" : (Platform.isFabric() ? "Fabric" : "")); | ||
ver.append(" "); | ||
ver.append(Platform.getMinecraftVersion()); | ||
if (Platform.isDevelopmentEnvironment()) { | ||
ver.append(" (Dev)"); | ||
} | ||
|
||
int verLength = ver.length(); | ||
for (int i = 0; i < (charCount - verLength) / 2; i++) { | ||
ver.insert(0, " "); | ||
ver.append(" "); | ||
} | ||
|
||
new Thread(() -> { | ||
LOGGER.info(" +++ 🐉 +++ "); | ||
LOGGER.info("------------------------------------------------------------------"); | ||
LOGGER.info(" Loaded DRAGONLIB by MRJULSEN! "); | ||
LOGGER.info(ver.toString()); | ||
LOGGER.info(" Discord: https://discord.gg/AeSbNgvc7f "); | ||
LOGGER.info(" GitHub: https://github.com/MisterJulsen/MC-DragonLib2 "); | ||
LOGGER.info(" Bug Reports: https://github.com/MisterJulsen/MC-DragonLib2/issues"); | ||
LOGGER.info("------------------------------------------------------------------"); | ||
LOGGER.info(" +++ 🐉 +++ "); | ||
}, dragonTypes[RANDOM.nextInt(dragonTypes.length)]).run(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
common/src/main/java/de/mrjulsen/mcdragonlib/ExampleExpectPlatform.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,27 @@ | ||
package de.mrjulsen.mcdragonlib; | ||
|
||
import dev.architectury.injectables.annotations.ExpectPlatform; | ||
import dev.architectury.platform.Platform; | ||
|
||
import java.nio.file.Path; | ||
|
||
public class ExampleExpectPlatform { | ||
/** | ||
* We can use {@link Platform#getConfigFolder()} but this is just an example of {@link ExpectPlatform}. | ||
* <p> | ||
* This must be a <b>public static</b> method. The platform-implemented solution must be placed under a | ||
* platform sub-package, with its class suffixed with {@code Impl}. | ||
* <p> | ||
* Example: | ||
* Expect: net.examplemod.ExampleExpectPlatform#getConfigDirectory() | ||
* Actual Fabric: net.examplemod.fabric.ExampleExpectPlatformImpl#getConfigDirectory() | ||
* Actual Forge: net.examplemod.forge.ExampleExpectPlatformImpl#getConfigDirectory() | ||
* <p> | ||
* <a href="https://plugins.jetbrains.com/plugin/16210-architectury">You should also get the IntelliJ plugin to help with @ExpectPlatform.</a> | ||
*/ | ||
@ExpectPlatform | ||
public static Path getConfigDirectory() { | ||
// Just throw an error, the content should get replaced at runtime. | ||
throw new AssertionError(); | ||
} | ||
} |
Oops, something went wrong.