@@ -1,12 +1,16 @@
|
||||
package dev.zxq5
|
||||
|
||||
import dev.zxq5.items.ModItems
|
||||
import dev.zxq5.items.ModItems.CUSTOM_CREATIVE_TAB
|
||||
import dev.zxq5.items.ModItems.CUSTOM_CREATIVE_TAB_KEY
|
||||
import dev.zxq5.items.Witherite
|
||||
import dev.zxq5.items.isWearingFullSet
|
||||
import net.fabricmc.api.ModInitializer
|
||||
import net.minecraft.core.Registry
|
||||
import net.minecraft.core.registries.BuiltInRegistries
|
||||
import net.minecraft.world.item.Item
|
||||
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.world.effect.MobEffects
|
||||
import net.minecraft.world.entity.LivingEntity
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
object Fantasysmp : ModInitializer {
|
||||
@@ -22,5 +26,38 @@ object Fantasysmp : ModInitializer {
|
||||
logger.info("Hello Fabric world!")
|
||||
ModItems.init();
|
||||
// Register the group.
|
||||
registerItemEffects()
|
||||
}
|
||||
|
||||
private fun registerItemEffects() {
|
||||
ServerTickEvents.END_SERVER_TICK.register { server ->
|
||||
for (player in server.playerList.players) {
|
||||
if (player.isWearingFullSet(Witherite.ARMOUR_SET)) {
|
||||
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)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user