This commit is contained in:
nea
2022-07-12 14:20:22 +02:00
commit 372eec27e5
35 changed files with 1333 additions and 0 deletions

36
common/build.gradle.kts Normal file
View File

@@ -0,0 +1,36 @@
plugins {
`maven-publish`
}
architectury {
val enabled_platforms: String by rootProject
common(enabled_platforms.split(","))
}
loom {
accessWidenerPath.set(file("src/main/resources/notenoughupdates.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.property("fabric_loader_version")}")
// Remove the next line if you don't want to depend on the API
modApi("dev.architectury:architectury:${rootProject.property("architectury_version")}")
modCompileOnly("me.shedaniel:RoughlyEnoughItems-api:${rootProject.property("rei_version")}")
implementation(kotlin("stdlib-jdk8"))
}
publishing {
publications {
create<MavenPublication>("maven") {
artifactId = rootProject.property("archives_base_name").toString()
from(components.getByName("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.
}
}

View File

@@ -0,0 +1,140 @@
package moe.nea.notenoughupdates.rei
import com.mojang.blaze3d.vertex.PoseStack
import io.github.moulberry.repo.NEURepository
import me.shedaniel.math.Point
import me.shedaniel.math.Rectangle
import me.shedaniel.rei.api.client.entry.renderer.EntryRenderer
import me.shedaniel.rei.api.client.gui.widgets.Tooltip
import me.shedaniel.rei.api.client.plugins.REIClientPlugin
import me.shedaniel.rei.api.client.registry.entry.EntryRegistry
import me.shedaniel.rei.api.common.entry.EntrySerializer
import me.shedaniel.rei.api.common.entry.EntryStack
import me.shedaniel.rei.api.common.entry.comparison.ComparisonContext
import me.shedaniel.rei.api.common.entry.type.EntryDefinition
import me.shedaniel.rei.api.common.entry.type.EntryType
import me.shedaniel.rei.api.common.entry.type.EntryTypeRegistry
import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes
import me.shedaniel.rei.api.common.util.EntryStacks
import net.minecraft.core.Registry
import net.minecraft.network.chat.Component
import net.minecraft.network.chat.TextComponent
import net.minecraft.resources.ResourceLocation
import net.minecraft.tags.TagKey
import net.minecraft.world.item.Item
import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.Items
import net.minecraft.world.item.enchantment.Enchantments
import java.nio.file.Path
import java.util.stream.Stream
class NEUReiPlugin : REIClientPlugin {
data class SBItem(val sbname: String, val backing: Item)
companion object {
fun EntryStack<NEUReiPlugin.SBItem>.asItemStack() =
EntryStack.of(VanillaEntryTypes.ITEM, ItemStack(this.value.backing).also {
it.enchant(Enchantments.BINDING_CURSE, 1)
it.hoverName = TextComponent(value.sbname)
})
val hehe = ResourceLocation("notenoughupdates", "skyblockitems")
}
object SBItemEntryDefinition : EntryDefinition<SBItem> {
override fun equals(o1: SBItem?, o2: SBItem?, context: ComparisonContext?): Boolean {
return o1 == o2
}
override fun getValueType(): Class<SBItem> = SBItem::class.java
override fun getType(): EntryType<SBItem> =
EntryType.deferred(hehe)
override fun getRenderer(): EntryRenderer<SBItem> = object : EntryRenderer<SBItem> {
override fun render(
entry: EntryStack<SBItem>,
matrices: PoseStack,
bounds: Rectangle,
mouseX: Int,
mouseY: Int,
delta: Float
) {
VanillaEntryTypes.ITEM.definition.renderer
.render(
entry.asItemStack(),
matrices, bounds, mouseX, mouseY, delta
)
}
override fun getTooltip(entry: EntryStack<SBItem>, mouse: Point): Tooltip? {
return VanillaEntryTypes.ITEM.definition.renderer
.getTooltip(entry.asItemStack(), mouse)
}
}
override fun getSerializer(): EntrySerializer<SBItem>? {
return null
}
override fun getTagsFor(entry: EntryStack<SBItem>?, value: SBItem?): Stream<out TagKey<*>> {
return Stream.empty()
}
override fun asFormattedText(entry: EntryStack<SBItem>, value: SBItem): Component {
return VanillaEntryTypes.ITEM.definition.asFormattedText(entry.asItemStack(), ItemStack(value.backing))
}
override fun hash(entry: EntryStack<SBItem>, value: SBItem, context: ComparisonContext): Long {
return value.sbname.hashCode().toLong()
}
override fun wildcard(entry: EntryStack<SBItem>, value: SBItem): SBItem {
return value
}
override fun normalize(entry: EntryStack<SBItem>, value: SBItem): SBItem {
return value
}
override fun copy(entry: EntryStack<SBItem>?, value: SBItem): SBItem {
return value.copy()
}
override fun isEmpty(entry: EntryStack<SBItem>?, value: SBItem?): Boolean {
return false
}
override fun getIdentifier(entry: EntryStack<SBItem>?, value: SBItem): ResourceLocation? {
return ResourceLocation("skyblockitem", value.sbname)
}
}
val neuRepo = NEURepository.of(Path.of("NotEnoughUpdates-REPO")).also {
it.reload()
}
override fun registerEntryTypes(registry: EntryTypeRegistry) {
registry.register(hehe, SBItemEntryDefinition)
}
override fun registerEntries(registry: EntryRegistry) {
neuRepo.items.items.values.forEach {
println("Adding item: $it")
registry.addEntry(
EntryStack.of(
SBItemEntryDefinition, SBItem(
it.skyblockItemId.lowercase().replace(";", "__"), Registry.ITEM.get(ResourceLocation(it.minecraftItemId))
)
)
)
}
registry.addEntry(EntryStacks.of(ItemStack(Items.DIAMOND).also {
it.enchant(Enchantments.ALL_DAMAGE_PROTECTION, 10)
}))
}
}

View File

@@ -0,0 +1,30 @@
package net.examplemod
import dev.architectury.injectables.annotations.ExpectPlatform
import dev.architectury.platform.Platform
import java.nio.file.Path
object ExampleExpectPlatform {
/**
* We can use [Platform.getConfigFolder] but this is just an example of [ExpectPlatform].
*
*
* This must be a **public static** method. The platform-implemented solution must be placed under a
* platform sub-package, with its class suffixed with `Impl`.
*
*
* Example:
* Expect: net.examplemod.ExampleExpectPlatform#getConfigDirectory()
* Actual Fabric: net.examplemod.fabric.ExampleExpectPlatformImpl#getConfigDirectory()
* Actual Forge: net.examplemod.forge.ExampleExpectPlatformImpl#getConfigDirectory()
*
*
* [You should also get the IntelliJ plugin to help with @ExpectPlatform.](https://plugins.jetbrains.com/plugin/16210-architectury)
*/
@ExpectPlatform
@JvmStatic
fun getConfigDirectory(): Path {
// Just throw an error, the content should get replaced at runtime.
throw AssertionError()
}
}

View File

@@ -0,0 +1,31 @@
package net.examplemod
import com.google.common.base.Suppliers
import dev.architectury.registry.CreativeTabRegistry
import dev.architectury.registry.registries.DeferredRegister
import dev.architectury.registry.registries.Registries
import dev.architectury.registry.registries.RegistrySupplier
import net.minecraft.core.Registry
import net.minecraft.resources.ResourceLocation
import net.minecraft.world.item.CreativeModeTab
import net.minecraft.world.item.Item
import net.minecraft.world.item.ItemStack
import java.util.function.Supplier
object ExampleMod {
const val MOD_ID = "examplemod"
// We can use this if we don't want to use DeferredRegister
@Suppress("unused")
val REGISTRIES: Supplier<Registries> = Suppliers.memoize { Registries.get(MOD_ID) }
// Registering a new creative tab
val EXAMPLE_TAB: CreativeModeTab = CreativeTabRegistry.create(ResourceLocation(MOD_ID, "example_tab")) { ItemStack(EXAMPLE_ITEM.get()) }
val ITEMS: DeferredRegister<Item> = DeferredRegister.create(MOD_ID, Registry.ITEM_REGISTRY)
val EXAMPLE_ITEM: RegistrySupplier<Item> = ITEMS.register("example_item") { Item(Item.Properties().tab(EXAMPLE_TAB)) }
fun init() {
ITEMS.register()
println(ExampleExpectPlatform.getConfigDirectory().toAbsolutePath().normalize().toString())
}
}

View File

@@ -0,0 +1,23 @@
package net.examplemod.mixin
import net.minecraft.client.gui.screens.TitleScreen
import org.objectweb.asm.Opcodes
import org.spongepowered.asm.mixin.Mixin
import org.spongepowered.asm.mixin.injection.At
import org.spongepowered.asm.mixin.injection.Inject
import org.spongepowered.asm.mixin.injection.Redirect
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo
@Mixin(TitleScreen::class)
class MixinTitleScreen {
@Inject(at = [At("HEAD")], method = ["init()V"])
private fun init(info: CallbackInfo) {
println("Hello from example architectury common mixin!")
}
@Redirect(method = ["render"], at = At("FIELD", target = "minceraftEasterEgg", opcode = Opcodes.GETFIELD))
private fun nextFloat(t: TitleScreen): Boolean {
return true
}
}

View File

@@ -0,0 +1,3 @@
{
"accessWidener": "notenoughupdates.accesswidener"
}

View File

@@ -0,0 +1,3 @@
{
"item.examplemod.example_item": "Example Item"
}

View File

@@ -0,0 +1,13 @@
{
"required": true,
"package": "net.examplemod.mixin",
"compatibilityLevel": "JAVA_16",
"client": [
"MixinTitleScreen"
],
"mixins": [
],
"injectors": {
"defaultRequire": 1
}
}

View File

@@ -0,0 +1 @@
accessWidener v2 named