slightly broken but very refactored. TODO: make the code that should run on the clientside run on the clientside
build / build (push) Has been cancelled
build / build (push) Has been cancelled
This commit is contained in:
@@ -1,30 +1,29 @@
|
||||
package dev.zxq5
|
||||
|
||||
import dev.zxq5.items.ItemImplementation
|
||||
import dev.zxq5.items.ItemTagAdder
|
||||
import dev.zxq5.items.ModItems
|
||||
import dev.zxq5.items.Witherite
|
||||
import dev.zxq5.items.isWearingFullSet
|
||||
import net.fabricmc.api.ModInitializer
|
||||
import net.fabricmc.fabric.api.datagen.v1.FabricPackOutput
|
||||
import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider
|
||||
import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagsProvider
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents
|
||||
import net.fabricmc.fabric.api.event.player.AttackEntityCallback
|
||||
import net.minecraft.world.InteractionHand
|
||||
import net.minecraft.world.InteractionResult
|
||||
import net.minecraft.world.effect.MobEffectInstance
|
||||
import net.minecraft.core.HolderLookup
|
||||
import net.minecraft.data.recipes.RecipeOutput
|
||||
import net.minecraft.data.recipes.RecipeProvider
|
||||
import net.minecraft.world.effect.MobEffects
|
||||
import net.minecraft.world.entity.LivingEntity
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.util.concurrent.CompletableFuture
|
||||
|
||||
object Fantasysmp : ModInitializer {
|
||||
|
||||
const val MOD_ID = "fantasysmp"
|
||||
|
||||
private val logger = LoggerFactory.getLogger("fantasysmp")
|
||||
|
||||
override fun onInitialize() {
|
||||
// This code runs as soon as Minecraft is in a mod-load-ready state.
|
||||
// However, some things (like resources) may still be uninitialized.
|
||||
// Proceed with mild caution.
|
||||
logger.info("Hello Fabric world!")
|
||||
ModItems.init();
|
||||
ModItems.onLoad();
|
||||
// Register the group.
|
||||
registerItemEffects()
|
||||
}
|
||||
@@ -32,32 +31,36 @@ object Fantasysmp : ModInitializer {
|
||||
private fun registerItemEffects() {
|
||||
ServerTickEvents.END_SERVER_TICK.register { server ->
|
||||
for (player in server.playerList.players) {
|
||||
if (player.isWearingFullSet(Witherite.ARMOUR_SET)) {
|
||||
if (Witherite.fullSetEquippedBy(player)) {
|
||||
player.removeEffect(MobEffects.WITHER)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AttackEntityCallback.EVENT.register { player, world, hand, entity, _ ->
|
||||
if (world.isClientSide) return@register InteractionResult.PASS
|
||||
if (hand != InteractionHand.MAIN_HAND) return@register InteractionResult.PASS
|
||||
if (player.getItemInHand(hand).item != Witherite.SWORD) return@register InteractionResult.PASS
|
||||
if (entity is LivingEntity) {
|
||||
entity.addEffect(MobEffectInstance(MobEffects.WITHER, 60, 1), player)
|
||||
class ModRecipeProvider(
|
||||
output: FabricPackOutput,
|
||||
registriesFuture: CompletableFuture<HolderLookup.Provider>
|
||||
) : FabricRecipeProvider(output, registriesFuture) {
|
||||
override fun createRecipeProvider(
|
||||
registries: HolderLookup.Provider,
|
||||
exporter: RecipeOutput
|
||||
): RecipeProvider {
|
||||
return object : RecipeProvider(registries, exporter) {
|
||||
override fun buildRecipes() {
|
||||
ItemImplementation.all.forEach { it.generateRecipes(registries, exporter) }
|
||||
}
|
||||
|
||||
InteractionResult.PASS
|
||||
}
|
||||
|
||||
AttackEntityCallback.EVENT.register { player, world, hand, entity, _ ->
|
||||
if (world.isClientSide) return@register InteractionResult.PASS
|
||||
if (hand != InteractionHand.MAIN_HAND) return@register InteractionResult.PASS
|
||||
if (player.getItemInHand(hand).item != Witherite.AXE) return@register InteractionResult.PASS
|
||||
if (entity is LivingEntity) {
|
||||
entity.addEffect(MobEffectInstance(MobEffects.WITHER, 60, 1), player)
|
||||
}
|
||||
|
||||
InteractionResult.PASS
|
||||
}
|
||||
}
|
||||
|
||||
override fun getName(): String = "Fantasysmp Recipes"
|
||||
}
|
||||
|
||||
class ModItemTagProvider(output: FabricPackOutput, registriesFuture: CompletableFuture<HolderLookup.Provider>) :
|
||||
FabricTagsProvider.ItemTagsProvider(output, registriesFuture) {
|
||||
override fun addTags(provider: HolderLookup.Provider) {
|
||||
val adder = ItemTagAdder(this)
|
||||
ItemImplementation.all.forEach { it.generateItemTags(adder) }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user