@@ -0,0 +1,26 @@
|
||||
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 net.fabricmc.api.ModInitializer
|
||||
import net.minecraft.core.Registry
|
||||
import net.minecraft.core.registries.BuiltInRegistries
|
||||
import net.minecraft.world.item.Item
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
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();
|
||||
// Register the group.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package dev.zxq5.items
|
||||
|
||||
import dev.zxq5.Fantasysmp
|
||||
import dev.zxq5.items.Witherite.WITHERITE_HELMET
|
||||
import dev.zxq5.items.Witherite.WITHERITE_SWORD
|
||||
import net.fabricmc.fabric.api.creativetab.v1.FabricCreativeModeTab
|
||||
import net.minecraft.core.Registry
|
||||
import net.minecraft.core.component.DataComponents
|
||||
import net.minecraft.core.registries.BuiltInRegistries
|
||||
import net.minecraft.core.registries.Registries
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.resources.Identifier
|
||||
import net.minecraft.resources.ResourceKey
|
||||
import net.minecraft.world.item.*
|
||||
import net.minecraft.world.item.CreativeModeTab.DisplayItemsGenerator
|
||||
import net.minecraft.world.item.CreativeModeTab.ItemDisplayParameters
|
||||
import net.minecraft.world.item.component.ItemLore
|
||||
import net.minecraft.world.item.equipment.ArmorMaterials
|
||||
import net.minecraft.world.item.equipment.ArmorType
|
||||
import java.util.List
|
||||
import java.util.function.Supplier
|
||||
|
||||
|
||||
object ModItems {
|
||||
fun <T : Item> register(
|
||||
name: String,
|
||||
itemFactory: (Item.Properties) -> T,
|
||||
settings: Item.Properties
|
||||
): T {
|
||||
val itemKey = ResourceKey.create(Registries.ITEM, Identifier.fromNamespaceAndPath(Fantasysmp.MOD_ID, name))
|
||||
val item = itemFactory(settings.setId(itemKey))
|
||||
Registry.register(BuiltInRegistries.ITEM, itemKey, item)
|
||||
return item
|
||||
}
|
||||
|
||||
val CUSTOM_CREATIVE_TAB_KEY: ResourceKey<CreativeModeTab> = ResourceKey.create<CreativeModeTab>(
|
||||
BuiltInRegistries.CREATIVE_MODE_TAB.key(), Identifier.fromNamespaceAndPath(Fantasysmp.MOD_ID, "creative_tab")
|
||||
)
|
||||
|
||||
val CUSTOM_CREATIVE_TAB: CreativeModeTab = FabricCreativeModeTab.builder()
|
||||
.icon(Supplier { ItemStack(WITHERITE_SWORD) })
|
||||
.title(Component.translatable("Fantasysmp"))
|
||||
.displayItems(DisplayItemsGenerator { params: ItemDisplayParameters, output: CreativeModeTab.Output ->
|
||||
Witherite.ITEMS.forEach { output.accept(it) }
|
||||
})
|
||||
.build()
|
||||
|
||||
fun init() {
|
||||
Witherite.init();
|
||||
|
||||
Registry.register(BuiltInRegistries.CREATIVE_MODE_TAB, CUSTOM_CREATIVE_TAB_KEY, CUSTOM_CREATIVE_TAB);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package dev.zxq5.items
|
||||
|
||||
import dev.zxq5.Fantasysmp
|
||||
import dev.zxq5.items.ModItems.register
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.resources.Identifier
|
||||
import net.minecraft.resources.ResourceKey
|
||||
import net.minecraft.sounds.SoundEvents
|
||||
import net.minecraft.sounds.SoundSource
|
||||
import net.minecraft.tags.ItemTags
|
||||
import net.minecraft.world.InteractionHand
|
||||
import net.minecraft.world.InteractionResult
|
||||
import net.minecraft.world.entity.Entity
|
||||
import net.minecraft.world.entity.EntityType
|
||||
import net.minecraft.world.entity.player.Player
|
||||
import net.minecraft.world.entity.projectile.hurtingprojectile.WitherSkull
|
||||
import net.minecraft.world.item.Item
|
||||
import net.minecraft.world.item.ToolMaterial
|
||||
import net.minecraft.world.item.equipment.*
|
||||
import net.minecraft.world.level.Level
|
||||
|
||||
|
||||
object Witherite {
|
||||
val base_durability = 40;
|
||||
val witherite_material_key: ResourceKey<EquipmentAsset> = ResourceKey.create<EquipmentAsset>(
|
||||
EquipmentAssets.ROOT_ID,
|
||||
Identifier.fromNamespaceAndPath(Fantasysmp.MOD_ID, "witherite")
|
||||
)
|
||||
|
||||
val armorMaterial = ArmorMaterial(
|
||||
base_durability,
|
||||
mapOf(
|
||||
ArmorType.HELMET to 3,
|
||||
ArmorType.CHESTPLATE to 8,
|
||||
ArmorType.LEGGINGS to 6,
|
||||
ArmorType.BOOTS to 3,
|
||||
ArmorType.BODY to 19,
|
||||
),
|
||||
5,
|
||||
SoundEvents.ARMOR_EQUIP_NETHERITE,
|
||||
3.0f,
|
||||
0.1f,
|
||||
ItemTags.REPAIRS_NETHERITE_ARMOR,
|
||||
witherite_material_key,
|
||||
)
|
||||
|
||||
val WITHERITE_SWORD = register("witherite_sword", ::WitheriteSword,
|
||||
Item.Properties().sword(ToolMaterial.NETHERITE, 3.0F, -2.4F)
|
||||
)
|
||||
val WITHERITE_HELMET = register(
|
||||
"witherite_helmet",
|
||||
::Item,
|
||||
Item.Properties().humanoidArmor(armorMaterial , ArmorType.HELMET)
|
||||
.durability(ArmorType.HELMET.getDurability(armorMaterial.durability))
|
||||
)
|
||||
|
||||
val WITHERITE_CHESTPLATE = register(
|
||||
"witherite_chestplate",
|
||||
::Item,
|
||||
Item.Properties().humanoidArmor(armorMaterial , ArmorType.CHESTPLATE)
|
||||
.durability(ArmorType.CHESTPLATE.getDurability(armorMaterial.durability))
|
||||
)
|
||||
|
||||
val WITHERITE_LEGGINGS = register(
|
||||
"witherite_leggings",
|
||||
::Item,
|
||||
Item.Properties().humanoidArmor(armorMaterial , ArmorType.LEGGINGS)
|
||||
.durability(ArmorType.LEGGINGS.getDurability(armorMaterial.durability))
|
||||
)
|
||||
|
||||
val WITHERITE_BOOTS = register(
|
||||
"witherite_boots",
|
||||
::Item,
|
||||
Item.Properties().humanoidArmor(armorMaterial , ArmorType.BOOTS)
|
||||
.durability(ArmorType.BOOTS.getDurability(armorMaterial.durability))
|
||||
)
|
||||
|
||||
val ITEMS = listOf(WITHERITE_SWORD, WITHERITE_HELMET, WITHERITE_CHESTPLATE, WITHERITE_LEGGINGS, WITHERITE_BOOTS)
|
||||
|
||||
fun init() {}
|
||||
}
|
||||
|
||||
class WitheriteSword(properties: Properties) : Item(properties) {
|
||||
override fun use(level: Level, user: Player, hand: InteractionHand): InteractionResult {
|
||||
if (level.isClientSide) {
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
|
||||
val skull = WitherSkull(EntityType.WITHER_SKULL, level)
|
||||
skull.setPos(user.eyePosition)
|
||||
skull.deltaMovement = user.lookAngle
|
||||
level.addFreshEntity(skull)
|
||||
skull.playSound(SoundEvents.WITHER_SHOOT)
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user