From 0a90105b8d21115e0f2dc5e29d46c8aaa0fa2043 Mon Sep 17 00:00:00 2001 From: opekope2 Date: Sun, 1 Dec 2024 03:20:01 +0100 Subject: [PATCH] Port to Forge --- .../avm_staff/api/IStaffModPlatform.kt | 4 +- .../api/entity/CampfireFlameEntity.kt | 25 ++- .../opekope2/avm_staff/api/item/StaffItem.kt | 4 +- .../opekope2/avm_staff/content/Blocks.kt | 8 +- .../opekope2/avm_staff/content/EntityTypes.kt | 4 +- .../opekope2/avm_staff/content/ItemGroups.kt | 25 ++- .../opekope2/avm_staff/content/Items.kt | 23 +-- .../avm_staff/content/ParticleTypes.kt | 4 +- .../opekope2/avm_staff/content/SoundEvents.kt | 4 +- .../event_handler/ClientEventHandlers.kt | 21 ++- .../internal/event_handler/EventHandlers.kt | 145 ++++++++++-------- .../event_handler/KeyBindingHandler.kt | 15 +- .../avm_staff/internal/forge/StaffMod.kt | 6 +- .../internal/forge/StaffModClient.kt | 58 ++----- .../internal/forge/item/ForgeStaffItem.kt | 6 +- .../internal/initializer/ClientInitializer.kt | 19 +-- .../internal/initializer/Initializer.kt | 8 +- .../internal/model/ModelPredicates.kt | 6 +- .../AbstractMassDestructiveStaffHandler.kt | 10 +- .../internal/staff/handler/BellHandler.kt | 10 -- .../internal/staff/handler/CampfireHandler.kt | 6 +- .../staff/handler/VanillaStaffHandlers.kt | 2 - .../item_renderer/BellStaffItemRenderer.kt | 6 +- .../item_renderer/FurnaceStaffItemRenderer.kt | 6 +- .../LightningRodStaffItemRenderer.kt | 6 +- .../WitherSkeletonSkullStaffItemRenderer.kt | 6 +- .../avm_staff/util/MinecraftClientUtil.kt | 6 +- .../opekope2/avm_staff/util/RegistryUtil.kt | 39 +++-- 28 files changed, 233 insertions(+), 249 deletions(-) diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/api/IStaffModPlatform.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/api/IStaffModPlatform.kt index f5741a01b..4b42f6bfc 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/api/IStaffModPlatform.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/api/IStaffModPlatform.kt @@ -18,10 +18,10 @@ package opekope2.avm_staff.api -import dev.architectury.registry.registries.RegistrySupplier import net.minecraft.block.Block import net.minecraft.item.Item import net.minecraft.particle.SimpleParticleType +import net.minecraftforge.registries.RegistryObject import opekope2.avm_staff.api.IStaffModPlatform.Instance import opekope2.avm_staff.api.item.CrownItem import opekope2.avm_staff.api.item.StaffItem @@ -38,7 +38,7 @@ interface IStaffModPlatform { * * @param settings The item settings to pass to the constructor */ - fun staffItem(settings: Item.Settings, repairIngredient: RegistrySupplier?): StaffItem + fun staffItem(settings: Item.Settings, repairIngredient: RegistryObject?): StaffItem /** * Creates an item, which is rendered like a staff. diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/api/entity/CampfireFlameEntity.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/api/entity/CampfireFlameEntity.kt index 0425d5a4a..02ba26f85 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/api/entity/CampfireFlameEntity.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/api/entity/CampfireFlameEntity.kt @@ -18,10 +18,6 @@ package opekope2.avm_staff.api.entity -import dev.architectury.extensions.network.EntitySpawnExtension -import dev.architectury.networking.NetworkManager -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment import net.minecraft.block.* import net.minecraft.block.piston.PistonBehavior import net.minecraft.client.option.GraphicsMode @@ -32,14 +28,11 @@ import net.minecraft.entity.data.DataTracker import net.minecraft.entity.projectile.ProjectileUtil import net.minecraft.nbt.NbtCompound import net.minecraft.network.PacketByteBuf -import net.minecraft.network.listener.ClientPlayPacketListener -import net.minecraft.network.packet.Packet import net.minecraft.particle.ParticleEffect import net.minecraft.particle.ParticleType import net.minecraft.registry.Registries import net.minecraft.registry.RegistryKey import net.minecraft.registry.RegistryKeys -import net.minecraft.server.network.EntityTrackerEntry import net.minecraft.state.property.Properties.LIT import net.minecraft.util.hit.BlockHitResult import net.minecraft.util.hit.HitResult @@ -49,6 +42,9 @@ import net.minecraft.util.math.Vec3d import net.minecraft.world.RaycastContext import net.minecraft.world.World import net.minecraft.world.event.GameEvent +import net.minecraftforge.api.distmarker.Dist +import net.minecraftforge.api.distmarker.OnlyIn +import net.minecraftforge.entity.IEntityAdditionalSpawnData import opekope2.avm_staff.content.EntityTypes import opekope2.avm_staff.content.ParticleTypes import opekope2.avm_staff.util.* @@ -57,7 +53,7 @@ import java.util.* /** * Technical entity representing a part of a flame of a campfire staff. */ -class CampfireFlameEntity : Entity, EntitySpawnExtension { +class CampfireFlameEntity : Entity, IEntityAdditionalSpawnData { private var currentRelativeRight: Vec3d = Vec3d.ZERO private var currentRelativeUp: Vec3d = Vec3d.ZERO @@ -151,7 +147,7 @@ class CampfireFlameEntity : Entity, EntitySpawnExtension { if (!world.isClient && age >= parameters.stepResolution) discard() } - @Environment(EnvType.CLIENT) + @OnlyIn(Dist.CLIENT) private fun spawnParticle(particleEffect: ParticleEffect, start: Vec3d, end: Vec3d) { val particleOffset = (end - start) * random.nextDouble() + currentRelativeRight * ((random.nextDouble() * 2 - 1) / rayResolution) + @@ -184,7 +180,7 @@ class CampfireFlameEntity : Entity, EntitySpawnExtension { } } - @Environment(EnvType.CLIENT) + @OnlyIn(Dist.CLIENT) private fun tickRayClient(start: Vec3d, end: Vec3d): HitResult.Type { val blockHit = raycastBlock(start, end) val entityHit = raycastEntity(start, end, false) @@ -306,15 +302,12 @@ class CampfireFlameEntity : Entity, EntitySpawnExtension { override fun getPistonBehavior() = PistonBehavior.IGNORE - override fun createSpawnPacket(entityTrackerEntry: EntityTrackerEntry): Packet = - NetworkManager.createAddEntityPacket(this, entityTrackerEntry) - - override fun saveAdditionalSpawnData(buf: PacketByteBuf) { + override fun writeSpawnData(buf: PacketByteBuf) { parameters.write(buf) buf.writeVarInt(shooter.id) } - override fun loadAdditionalSpawnData(buf: PacketByteBuf) { + override fun readSpawnData(buf: PacketByteBuf) { parameters = Parameters(buf) shooter = world.getEntityById(buf.readVarInt()) as LivingEntity } @@ -392,7 +385,7 @@ class CampfireFlameEntity : Entity, EntitySpawnExtension { get() = this == HitResult.Type.BLOCK private val flameParticleRayResolution: Int - @Environment(EnvType.CLIENT) + @OnlyIn(Dist.CLIENT) get() = when (clientOptions.graphicsMode.value) { GraphicsMode.FABULOUS -> 6 GraphicsMode.FANCY -> 5 diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/api/item/StaffItem.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/api/item/StaffItem.kt index 1b1d3da48..6204522d5 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/api/item/StaffItem.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/api/item/StaffItem.kt @@ -18,7 +18,6 @@ package opekope2.avm_staff.api.item -import dev.architectury.registry.registries.RegistrySupplier import net.minecraft.component.DataComponentTypes import net.minecraft.entity.Entity import net.minecraft.entity.EquipmentSlot @@ -36,6 +35,7 @@ import net.minecraft.util.TypedActionResult import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Direction import net.minecraft.world.World +import net.minecraftforge.registries.RegistryObject import opekope2.avm_staff.api.staff.StaffHandler import opekope2.avm_staff.util.* @@ -44,7 +44,7 @@ import opekope2.avm_staff.util.* * Implementing loader-specific interfaces is highly recommended when extending the class to pass loader-specific * functionality to [StaffHandler]. */ -abstract class StaffItem(settings: Settings, private val repairIngredientSupplier: RegistrySupplier?) : +abstract class StaffItem(settings: Settings, private val repairIngredientSupplier: RegistryObject?) : Item(settings) { override fun canRepair(stack: ItemStack, ingredient: ItemStack) = repairIngredientSupplier != null && ingredient.isOf(repairIngredientSupplier.get()) diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/content/Blocks.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/content/Blocks.kt index cd1e10393..a4721dadf 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/content/Blocks.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/content/Blocks.kt @@ -18,13 +18,13 @@ package opekope2.avm_staff.content -import dev.architectury.registry.registries.RegistrySupplier import net.minecraft.block.AbstractBlock import net.minecraft.block.Block import net.minecraft.block.enums.NoteBlockInstrument import net.minecraft.block.piston.PistonBehavior -import net.minecraft.registry.RegistryKeys import net.minecraft.sound.BlockSoundGroup +import net.minecraftforge.registries.ForgeRegistries +import net.minecraftforge.registries.RegistryObject import opekope2.avm_staff.api.block.CrownBlock import opekope2.avm_staff.api.block.WallCrownBlock import opekope2.avm_staff.util.MOD_ID @@ -33,9 +33,9 @@ import opekope2.avm_staff.util.RegistryUtil /** * Blocks added by AVM Staffs mod. */ -object Blocks : RegistryUtil(MOD_ID, RegistryKeys.BLOCK) { +object Blocks : RegistryUtil(MOD_ID, ForgeRegistries.BLOCKS) { private fun settings() = AbstractBlock.Settings.create() - private fun settings(block: RegistrySupplier) = AbstractBlock.Settings.copy(block.get()) + private fun settings(block: RegistryObject) = AbstractBlock.Settings.copy(block.get()) /** * Block registered as `avm_staff:crown_of_king_orange`. diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/content/EntityTypes.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/content/EntityTypes.kt index 982f188a3..2b5a1c367 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/content/EntityTypes.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/content/EntityTypes.kt @@ -20,8 +20,8 @@ package opekope2.avm_staff.content import net.minecraft.entity.EntityType import net.minecraft.entity.SpawnGroup -import net.minecraft.registry.RegistryKeys import net.minecraft.util.Identifier +import net.minecraftforge.registries.ForgeRegistries import opekope2.avm_staff.api.entity.CakeEntity import opekope2.avm_staff.api.entity.CampfireFlameEntity import opekope2.avm_staff.api.entity.ImpactTntEntity @@ -33,7 +33,7 @@ import kotlin.math.max /** * Entity types added by AVM Staffs mod. */ -object EntityTypes : RegistryUtil>(MOD_ID, RegistryKeys.ENTITY_TYPE) { +object EntityTypes : RegistryUtil>(MOD_ID, ForgeRegistries.ENTITY_TYPES) { /** * Entity registered as `avm_staff:cake` */ diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/content/ItemGroups.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/content/ItemGroups.kt index 46d48cf2b..4aba5ee7a 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/content/ItemGroups.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/content/ItemGroups.kt @@ -18,11 +18,10 @@ package opekope2.avm_staff.content -import dev.architectury.registry.CreativeTabRegistry -import dev.architectury.registry.registries.RegistrySupplier import net.minecraft.item.ItemGroup import net.minecraft.registry.RegistryKeys import net.minecraft.text.Text +import net.minecraftforge.registries.RegistryObject import opekope2.avm_staff.util.MOD_ID import opekope2.avm_staff.util.RegistryUtil import opekope2.avm_staff.util.mutableItemStackInStaff @@ -35,12 +34,24 @@ object ItemGroups : RegistryUtil(MOD_ID, RegistryKeys.ITEM_GROUP) { * Item group containing items added by Staff Mod. */ @JvmField - val AVM_STAFF_MOD_ITEMS: RegistrySupplier = ItemGroups.register("${MOD_ID}_items") { - CreativeTabRegistry.create(Text.translatable("itemGroup.${MOD_ID}_items")) { - Items.royalStaff.defaultStack.apply { - mutableItemStackInStaff = net.minecraft.item.Items.COMMAND_BLOCK.defaultStack + val AVM_STAFF_MOD_ITEMS: RegistryObject = ItemGroups.register("${MOD_ID}_items") { + ItemGroup.builder() + .displayName(Text.translatable("itemGroup.${MOD_ID}_items")) + .icon { + Items.royalStaff.defaultStack.apply { + mutableItemStackInStaff = net.minecraft.item.Items.COMMAND_BLOCK.defaultStack + } } - } + .entries { _, entries -> + entries.add(Items.faintStaffRod) + entries.add(Items.faintRoyalStaffHead) + entries.add(Items.faintRoyalStaff) + entries.add(Items.royalStaff) + entries.add(Items.royalStaffIngredient) + entries.add(Items.crownOfKingOrange) + entries.add(Items.staffInfusionSmithingTemplate) + } + .build() } /** diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/content/Items.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/content/Items.kt index f0fdce64c..180bec42a 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/content/Items.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/content/Items.kt @@ -18,7 +18,6 @@ package opekope2.avm_staff.content -import dev.architectury.registry.CreativeTabRegistry import net.minecraft.component.DataComponentTypes import net.minecraft.component.type.ToolComponent import net.minecraft.item.Item @@ -26,6 +25,7 @@ import net.minecraft.item.SmithingTemplateItem import net.minecraft.registry.RegistryKeys import net.minecraft.text.Text import net.minecraft.util.Rarity +import net.minecraftforge.registries.ForgeRegistries import opekope2.avm_staff.api.IStaffModPlatform import opekope2.avm_staff.api.item.CrownItem import opekope2.avm_staff.api.item.StaffItem @@ -39,7 +39,7 @@ import opekope2.avm_staff.util.TagKeyUtil /** * Items added by AVM Staffs mod. */ -object Items : RegistryUtil(MOD_ID, RegistryKeys.ITEM) { +object Items : RegistryUtil(MOD_ID, ForgeRegistries.ITEMS) { private fun settings() = Item.Settings() /** @@ -50,7 +50,7 @@ object Items : RegistryUtil(MOD_ID, RegistryKeys.ITEM) { IStaffModPlatform.crownItem( Blocks.CROWN_OF_KING_ORANGE.get(), Blocks.WALL_CROWN_OF_KING_ORANGE.get(), - settings().maxCount(1).rarity(Rarity.UNCOMMON).`arch$tab`(ItemGroups.AVM_STAFF_MOD_ITEMS) + settings().maxCount(1).rarity(Rarity.UNCOMMON) ) } @@ -67,7 +67,7 @@ object Items : RegistryUtil(MOD_ID, RegistryKeys.ITEM) { @JvmField val FAINT_ROYAL_STAFF = register("faint_royal_staff") { IStaffModPlatform.itemWithStaffRenderer( - settings().maxCount(1).rarity(Rarity.RARE).`arch$tab`(ItemGroups.AVM_STAFF_MOD_ITEMS) + settings().maxCount(1).rarity(Rarity.RARE) ) } @@ -83,7 +83,7 @@ object Items : RegistryUtil(MOD_ID, RegistryKeys.ITEM) { */ @JvmField val FAINT_ROYAL_STAFF_HEAD = register("faint_royal_staff_head") { - Item(settings().maxCount(16).rarity(Rarity.RARE).`arch$tab`(ItemGroups.AVM_STAFF_MOD_ITEMS)) + Item(settings().maxCount(16).rarity(Rarity.RARE)) } /** @@ -98,7 +98,7 @@ object Items : RegistryUtil(MOD_ID, RegistryKeys.ITEM) { */ @JvmField val FAINT_STAFF_ROD = register("faint_staff_rod") { - Item(settings().`arch$tab`(ItemGroups.AVM_STAFF_MOD_ITEMS)) + Item(settings()) } /** @@ -115,8 +115,7 @@ object Items : RegistryUtil(MOD_ID, RegistryKeys.ITEM) { val ROYAL_STAFF = register("royal_staff") { IStaffModPlatform.staffItem( settings().maxCount(1).rarity(Rarity.EPIC).attributeModifiers(StaffHandler.Fallback.ATTRIBUTE_MODIFIERS) - .maxDamage(5179).component(DataComponentTypes.TOOL, ToolComponent(listOf(), 1f, 1)) - .`arch$tab`(ItemGroups.AVM_STAFF_MOD_ITEMS), + .maxDamage(5179).component(DataComponentTypes.TOOL, ToolComponent(listOf(), 1f, 1)), ROYAL_STAFF_INGREDIENT ) } @@ -133,7 +132,7 @@ object Items : RegistryUtil(MOD_ID, RegistryKeys.ITEM) { */ @JvmField val ROYAL_STAFF_INGREDIENT = register("royal_staff_ingredient") { - Item(settings().`arch$tab`(ItemGroups.AVM_STAFF_MOD_ITEMS)) + Item(settings()) } /** @@ -168,12 +167,6 @@ object Items : RegistryUtil(MOD_ID, RegistryKeys.ITEM) { @JvmName("staffInfusionSmithingTemplate") get() = STAFF_INFUSION_SMITHING_TEMPLATE.get() - override fun register() { - super.register() - // Because SmithingTemplateItem doesn't take Item.Settings in its constructor - CreativeTabRegistry.append(ItemGroups.AVM_STAFF_MOD_ITEMS, STAFF_INFUSION_SMITHING_TEMPLATE) - } - /** * Item tags added by AVM Staffs mod. */ diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/content/ParticleTypes.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/content/ParticleTypes.kt index 1dbf0ef7b..1e5e193c6 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/content/ParticleTypes.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/content/ParticleTypes.kt @@ -21,7 +21,7 @@ package opekope2.avm_staff.content import net.minecraft.client.particle.ParticleManager import net.minecraft.particle.ParticleType import net.minecraft.particle.SimpleParticleType -import net.minecraft.registry.RegistryKeys +import net.minecraftforge.registries.ForgeRegistries import opekope2.avm_staff.api.IStaffModPlatform import opekope2.avm_staff.util.MOD_ID import opekope2.avm_staff.util.RegistryUtil @@ -29,7 +29,7 @@ import opekope2.avm_staff.util.RegistryUtil /** * Particle types added by AVM Staffs mod. */ -object ParticleTypes : RegistryUtil>(MOD_ID, RegistryKeys.PARTICLE_TYPE) { +object ParticleTypes : RegistryUtil>(MOD_ID, ForgeRegistries.PARTICLE_TYPES) { /** * Particle registered as `avm_staff:flame`. * diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/content/SoundEvents.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/content/SoundEvents.kt index 5ede95a88..17a6e0167 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/content/SoundEvents.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/content/SoundEvents.kt @@ -18,15 +18,15 @@ package opekope2.avm_staff.content -import net.minecraft.registry.RegistryKeys import net.minecraft.sound.SoundEvent +import net.minecraftforge.registries.ForgeRegistries import opekope2.avm_staff.util.MOD_ID import opekope2.avm_staff.util.RegistryUtil /** * Sound events added by AVM Staffs mod. */ -object SoundEvents : RegistryUtil(MOD_ID, RegistryKeys.SOUND_EVENT) { +object SoundEvents : RegistryUtil(MOD_ID, ForgeRegistries.SOUND_EVENTS) { /** * Sound event registered as `avm_staff:entity.cake.splash`. */ diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/event_handler/ClientEventHandlers.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/event_handler/ClientEventHandlers.kt index e067019fb..297dee693 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/event_handler/ClientEventHandlers.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/event_handler/ClientEventHandlers.kt @@ -18,23 +18,22 @@ package opekope2.avm_staff.internal.event_handler -import dev.architectury.event.events.client.ClientTickEvent -import dev.architectury.event.events.common.InteractionEvent -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment -import net.minecraft.entity.player.PlayerEntity -import net.minecraft.util.Hand +import net.minecraftforge.api.distmarker.Dist +import net.minecraftforge.api.distmarker.OnlyIn +import net.minecraftforge.event.entity.player.PlayerInteractEvent.LeftClickEmpty import opekope2.avm_staff.api.item.StaffItem import opekope2.avm_staff.internal.networking.c2s.play.AttackC2SPacket +import thedarkcolour.kotlinforforge.forge.FORGE_BUS -@Environment(EnvType.CLIENT) -object ClientEventHandlers : InteractionEvent.ClientLeftClickAir { +@OnlyIn(Dist.CLIENT) +object ClientEventHandlers { init { - ClientTickEvent.CLIENT_POST.register(KeyBindingHandler) - InteractionEvent.CLIENT_LEFT_CLICK_AIR.register(this) + FORGE_BUS.addListener(::click) } - override fun click(player: PlayerEntity, hand: Hand) { + private fun click(event: LeftClickEmpty) { + val player = event.entity + val hand = event.hand val staffStack = player.getStackInHand(hand) val staffItem = staffStack.item as? StaffItem ?: return diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/event_handler/EventHandlers.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/event_handler/EventHandlers.kt index f5756a8c0..561cc7ef1 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/event_handler/EventHandlers.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/event_handler/EventHandlers.kt @@ -18,31 +18,29 @@ package opekope2.avm_staff.internal.event_handler -import dev.architectury.event.CompoundEventResult -import dev.architectury.event.EventResult -import dev.architectury.event.events.common.* import net.minecraft.block.DispenserBlock -import net.minecraft.entity.Entity import net.minecraft.entity.ItemEntity import net.minecraft.entity.LivingEntity -import net.minecraft.entity.damage.DamageSource import net.minecraft.entity.mob.AbstractPiglinEntity import net.minecraft.entity.player.PlayerEntity -import net.minecraft.item.ItemStack import net.minecraft.item.Items import net.minecraft.loot.LootPool -import net.minecraft.loot.LootTable import net.minecraft.loot.entry.LootTableEntry import net.minecraft.registry.RegistryKey import net.minecraft.registry.RegistryKeys import net.minecraft.server.network.ServerPlayerEntity -import net.minecraft.util.Hand +import net.minecraft.util.ActionResult import net.minecraft.util.Identifier -import net.minecraft.util.hit.EntityHitResult -import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Box -import net.minecraft.util.math.Direction -import net.minecraft.world.World +import net.minecraftforge.event.LootTableLoadEvent +import net.minecraftforge.event.entity.item.ItemTossEvent +import net.minecraftforge.event.entity.living.LivingDeathEvent +import net.minecraftforge.event.entity.living.LivingHurtEvent +import net.minecraftforge.event.entity.player.AttackEntityEvent +import net.minecraftforge.event.entity.player.PlayerInteractEvent.LeftClickBlock +import net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickItem +import net.minecraftforge.eventbus.api.Event +import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent import opekope2.avm_staff.api.block.dispenser.CakeDispenserBehavior import opekope2.avm_staff.api.entity.CakeEntity import opekope2.avm_staff.api.item.StaffItem @@ -51,10 +49,9 @@ import opekope2.avm_staff.content.EntityTypes import opekope2.avm_staff.content.GameRules import opekope2.avm_staff.mixin.IPiglinBrainAccessor import opekope2.avm_staff.util.* +import thedarkcolour.kotlinforforge.forge.FORGE_BUS -object EventHandlers : EntityEvent.LivingDeath, EntityEvent.LivingHurt, InteractionEvent.LeftClickBlock, - InteractionEvent.RightClickItem, Runnable, LootEvent.ModifyLootTable, PlayerEvent.AttackEntity, - PlayerEvent.DropItem { +object EventHandlers { private val MODIFIABLE_LOOT_TABLES = setOf( Identifier.ofVanilla("chests/ancient_city"), Identifier.ofVanilla("chests/bastion_other"), @@ -64,92 +61,104 @@ object EventHandlers : EntityEvent.LivingDeath, EntityEvent.LivingHurt, Interact private const val MAX_ANGER_DISTANCE = 16.0 init { - EntityEvent.LIVING_DEATH.register(this) - EntityEvent.LIVING_HURT.register(this) - InteractionEvent.LEFT_CLICK_BLOCK.register(this) - InteractionEvent.RIGHT_CLICK_ITEM.register(this) - LifecycleEvent.SETUP.register(this) - LootEvent.MODIFY_LOOT_TABLE.register(this) - PlayerEvent.ATTACK_ENTITY.register(this) - PlayerEvent.DROP_ITEM.register(this) + FORGE_BUS.addListener(::die) + FORGE_BUS.addListener(::hurt) + FORGE_BUS.addListener(::leftClickBlock) + FORGE_BUS.addListener(::rightClickItem) + FORGE_BUS.addListener(::setup) + FORGE_BUS.addListener(::modifyLootTable) + FORGE_BUS.addListener(::attack) + FORGE_BUS.addListener(::drop) } - override fun die(entity: LivingEntity, damageSource: DamageSource): EventResult { - if (entity !is PlayerEntity) return EventResult.pass() + private fun die(event: LivingDeathEvent) { + val entity = event.entity + if (entity !is PlayerEntity) return if (entity.activeItem.isStaff) { entity.stopUsingItem() } - - return EventResult.pass() } - override fun hurt(entity: LivingEntity, damage: DamageSource, amount: Float): EventResult { + private fun hurt(event: LivingHurtEvent) { + val entity = event.entity + val damage = event.source + if (entity is ServerPlayerEntity && entity.isUsingItem) { Criteria.takeDamageWhileUsingItem.trigger(entity, entity.activeItem, damage) } - return EventResult.pass() } - override fun click(player: PlayerEntity, hand: Hand, target: BlockPos, direction: Direction): EventResult { + private fun leftClickBlock(event: LeftClickBlock) { + val player = event.entity + val hand = event.hand + val target = event.pos + val direction = event.face!! val staffStack = player.getStackInHand(hand) - val staffItem = staffStack.item as? StaffItem ?: return EventResult.pass() - - return staffItem.attackBlock(staffStack, player.entityWorld, player, target, direction, hand) + val staffItem = staffStack.item as? StaffItem ?: return + + val result = staffItem.attackBlock(staffStack, player.entityWorld, player, target, direction, hand) + if (result != ActionResult.PASS) { + event.isCanceled = true + event.cancellationResult = result + event.useBlock = Event.Result.DENY + event.useItem = Event.Result.DENY + } } - override fun click(player: PlayerEntity, hand: Hand): CompoundEventResult { + private fun rightClickItem(event: RightClickItem) { + val player = event.entity + val hand = event.hand val world = player.entityWorld val cake = player.getStackInHand(hand) val spawnPos = EntityTypes.cake.getSpawnPosition(world, player.approximateStaffTipPosition) - if (!cake.isOf(Items.CAKE)) return CompoundEventResult.pass() - if (spawnPos == null) return CompoundEventResult.pass() - if (world.isClient) return CompoundEventResult.interruptTrue(cake) - if (!world.gameRules.getBoolean(GameRules.THROWABLE_CAKES)) return CompoundEventResult.pass() + if (!cake.isOf(Items.CAKE)) return + if (spawnPos == null) return + if (world.isClient) { + event.isCanceled = true + event.cancellationResult = ActionResult.SUCCESS + return + } + if (!world.gameRules.getBoolean(GameRules.THROWABLE_CAKES)) return CakeEntity.throwCake(world, spawnPos, player.rotationVector * .5 + player.velocity, player) cake.decrementUnlessCreative(1, player) - return CompoundEventResult.interruptFalse(cake) + event.isCanceled = true + event.cancellationResult = ActionResult.FAIL } - // setup - override fun run() { - DispenserBlock.registerBehavior(Items.CAKE, CakeDispenserBehavior()) + private fun setup(event: FMLCommonSetupEvent) { + event.enqueueWork { + DispenserBlock.registerBehavior(Items.CAKE, CakeDispenserBehavior()) + } } - override fun modifyLootTable( - lootTable: RegistryKey, - context: LootEvent.LootTableModificationContext, - builtin: Boolean - ) { - if (!builtin) return - if (lootTable.value !in MODIFIABLE_LOOT_TABLES) return + private fun modifyLootTable(event: LootTableLoadEvent) { + val lootTable = event.name + if (lootTable !in MODIFIABLE_LOOT_TABLES) return - context.addPool( + event.table.addPool( LootPool.builder().with( LootTableEntry.builder( RegistryKey.of( RegistryKeys.LOOT_TABLE, - Identifier.of(MOD_ID, "add_loot_pool/${lootTable.value.path}") + Identifier.of(MOD_ID, "add_loot_pool/${lootTable.path}") ) ) - ) + ).build() ) } - override fun attack( - player: PlayerEntity, - world: World, - target: Entity, - hand: Hand, - hit: EntityHitResult? - ): EventResult { - if (world.isClient) return EventResult.pass() - if (target !is LivingEntity) return EventResult.pass() - if (!player.getStackInHand(hand).isStaff) return EventResult.pass() - if (!player.armorItems.any { it.isOf(opekope2.avm_staff.content.Items.crownOfKingOrange) }) return EventResult.pass() + private fun attack(event: AttackEntityEvent) { + val player = event.entity + val world = player.entityWorld + val target = event.target + if (world.isClient) return + if (target !is LivingEntity) return + if (!player.mainHandStack.isStaff) return + if (!player.armorItems.any { it.isOf(opekope2.avm_staff.content.Items.crownOfKingOrange) }) return val box = Box.of(player.pos, 2 * MAX_ANGER_DISTANCE, 2 * MAX_ANGER_DISTANCE, 2 * MAX_ANGER_DISTANCE) world.getEntitiesByClass(AbstractPiglinEntity::class.java, box) { @@ -157,13 +166,15 @@ object EventHandlers : EntityEvent.LivingDeath, EntityEvent.LivingHurt, Interact }.forEach { IPiglinBrainAccessor.callBecomeAngryWith(it, target) } + } - return EventResult.pass() + private fun drop(event: ItemTossEvent) { + drop(event.player, event.entity) } - override fun drop(entity: PlayerEntity, item: ItemEntity): EventResult { - val staffItem = item.stack.item as? StaffItem ?: return EventResult.pass() + fun drop(entity: PlayerEntity, item: ItemEntity) { + val staffItem = item.stack.item as? StaffItem ?: return + staffItem.onStoppedUsing(item.stack, entity.entityWorld, entity, entity.itemUseTimeLeft) - return EventResult.pass() } } diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/event_handler/KeyBindingHandler.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/event_handler/KeyBindingHandler.kt index 6fe7991cd..a0e521fa1 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/event_handler/KeyBindingHandler.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/event_handler/KeyBindingHandler.kt @@ -26,15 +26,17 @@ import net.minecraft.item.ItemStack import net.minecraftforge.api.distmarker.Dist import net.minecraftforge.api.distmarker.OnlyIn import net.minecraftforge.client.event.RegisterKeyMappingsEvent +import net.minecraftforge.event.TickEvent.ClientTickEvent import opekope2.avm_staff.internal.networking.c2s.play.InsertItemIntoStaffC2SPacket import opekope2.avm_staff.internal.networking.c2s.play.InsertItemIntoStaffC2SPacket.Companion.tryInsertItemIntoStaff import opekope2.avm_staff.internal.networking.c2s.play.RemoveItemFromStaffC2SPacket import opekope2.avm_staff.internal.networking.c2s.play.RemoveItemFromStaffC2SPacket.Companion.tryRemoveItemFromStaff import opekope2.avm_staff.util.MOD_ID import org.lwjgl.glfw.GLFW +import thedarkcolour.kotlinforforge.forge.FORGE_BUS @OnlyIn(Dist.CLIENT) -internal object KeyBindingHandler : ClientTickEvent.Client { +internal object KeyBindingHandler { private val ADD_REMOVE_STAFF_ITEM = KeyBinding( "key.$MOD_ID.add_remove_staff_item", InputUtil.Type.KEYSYM, @@ -43,10 +45,17 @@ internal object KeyBindingHandler : ClientTickEvent.Client { ) init { - KeyMappingRegistry.register(ADD_REMOVE_STAFF_ITEM) + FORGE_BUS.addListener(::register) + FORGE_BUS.addListener(::tick) } - override fun tick(client: MinecraftClient) { + private fun register(event: RegisterKeyMappingsEvent) { + event.register(ADD_REMOVE_STAFF_ITEM) + } + + @Suppress("UNUSED_PARAMETER") + private fun tick(event: ClientTickEvent.Post) { + val client = MinecraftClient.getInstance() if (!ADD_REMOVE_STAFF_ITEM.isPressed) return ADD_REMOVE_STAFF_ITEM.isPressed = false diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/forge/StaffMod.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/forge/StaffMod.kt index b4c9f285a..64f84622a 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/forge/StaffMod.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/forge/StaffMod.kt @@ -18,7 +18,6 @@ package opekope2.avm_staff.internal.forge -import dev.architectury.registry.registries.RegistrySupplier import net.minecraft.block.Block import net.minecraft.entity.player.PlayerEntity import net.minecraft.item.Item @@ -26,12 +25,13 @@ import net.minecraft.particle.SimpleParticleType import net.minecraftforge.api.distmarker.Dist import net.minecraftforge.event.entity.living.LivingDropsEvent import net.minecraftforge.fml.common.Mod +import net.minecraftforge.registries.RegistryObject import opekope2.avm_staff.api.IStaffModPlatform import opekope2.avm_staff.internal.event_handler.EventHandlers -import opekope2.avm_staff.internal.initializer.Initializer import opekope2.avm_staff.internal.forge.item.ForgeCrownItem import opekope2.avm_staff.internal.forge.item.ForgeStaffItem import opekope2.avm_staff.internal.forge.item.ForgeStaffRendererItem +import opekope2.avm_staff.internal.initializer.Initializer import opekope2.avm_staff.internal.staff.handler.registerVanillaStaffHandlers import opekope2.avm_staff.util.MOD_ID import thedarkcolour.kotlinforforge.forge.FORGE_BUS @@ -58,7 +58,7 @@ object StaffMod : IStaffModPlatform { } } - override fun staffItem(settings: Item.Settings, repairIngredient: RegistrySupplier?) = + override fun staffItem(settings: Item.Settings, repairIngredient: RegistryObject?) = ForgeStaffItem(settings, repairIngredient) override fun itemWithStaffRenderer(settings: Item.Settings) = ForgeStaffRendererItem(settings) diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/forge/StaffModClient.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/forge/StaffModClient.kt index 1c2b4d7b3..1f16f5329 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/forge/StaffModClient.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/forge/StaffModClient.kt @@ -18,75 +18,41 @@ package opekope2.avm_staff.internal.forge -import net.minecraft.block.DispenserBlock -import net.minecraft.client.MinecraftClient -import net.minecraft.client.render.entity.TntEntityRenderer -import net.minecraft.item.Items +import net.minecraft.client.item.ModelPredicateProviderRegistry import net.minecraftforge.api.distmarker.Dist import net.minecraftforge.api.distmarker.OnlyIn -import net.minecraftforge.client.event.EntityRenderersEvent.RegisterRenderers import net.minecraftforge.client.event.RegisterParticleProvidersEvent -import net.minecraftforge.event.TickEvent -import net.minecraftforge.event.entity.player.PlayerInteractEvent.LeftClickEmpty import net.minecraftforge.eventbus.api.SubscribeEvent import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent -import opekope2.avm_staff.api.block.dispenser.CakeDispenserBehavior -import opekope2.avm_staff.api.cakeEntityType -import opekope2.avm_staff.api.entity.renderer.CakeEntityRenderer -import opekope2.avm_staff.api.flamethrowerParticleType -import opekope2.avm_staff.api.impactTntEntityType import opekope2.avm_staff.api.particle.FlamethrowerParticle -import opekope2.avm_staff.api.soulFlamethrowerParticleType -import opekope2.avm_staff.internal.clientAttack -import opekope2.avm_staff.internal.event_handler.handleKeyBindings -import opekope2.avm_staff.internal.event_handler.registerKeyBindings -import opekope2.avm_staff.internal.model.registerModelPredicateProviders -import opekope2.avm_staff.internal.registerSmithingTableTextures +import opekope2.avm_staff.content.ParticleTypes +import opekope2.avm_staff.internal.event_handler.ClientEventHandlers +import opekope2.avm_staff.internal.initializer.ClientInitializer +import opekope2.avm_staff.internal.model.ModelPredicates import opekope2.avm_staff.internal.staff.handler.registerVanillaStaffItemRenderers -import thedarkcolour.kotlinforforge.forge.FORGE_BUS import thedarkcolour.kotlinforforge.forge.MOD_BUS @OnlyIn(Dist.CLIENT) object StaffModClient { fun initializeClient() { - registerSmithingTableTextures() - subscribeToClientEvents() + ClientInitializer + ClientEventHandlers registerVanillaStaffItemRenderers() - MOD_BUS.register(::registerKeyBindings) MOD_BUS.register(this) } - private fun subscribeToClientEvents() { - FORGE_BUS.addListener(::clientTick) - FORGE_BUS.addListener(::clientAttack) - } - @SubscribeEvent fun initializeClient(event: FMLClientSetupEvent) { event.enqueueWork { - registerModelPredicateProviders() - DispenserBlock.registerBehavior(Items.CAKE, CakeDispenserBehavior()) + for ((key, value) in ModelPredicates) { + ModelPredicateProviderRegistry.registerGeneric(key, value) + } } } @SubscribeEvent fun registerParticleProviders(event: RegisterParticleProvidersEvent) { - event.registerSpriteSet(flamethrowerParticleType.get(), FlamethrowerParticle::Factory) - event.registerSpriteSet(soulFlamethrowerParticleType.get(), FlamethrowerParticle::Factory) - } - - @SubscribeEvent - fun registerRenderers(event: RegisterRenderers) { - event.registerEntityRenderer(impactTntEntityType.get(), ::TntEntityRenderer) - event.registerEntityRenderer(cakeEntityType.get(), ::CakeEntityRenderer) - } - - @Suppress("UNUSED_PARAMETER") - fun clientTick(event: TickEvent.ClientTickEvent.Post) { - handleKeyBindings(MinecraftClient.getInstance()) - } - - fun clientAttack(event: LeftClickEmpty) { - clientAttack(event.entity, event.hand) + event.registerSpriteSet(ParticleTypes.flame, FlamethrowerParticle::Factory) + event.registerSpriteSet(ParticleTypes.soulFireFlame, FlamethrowerParticle::Factory) } } diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/forge/item/ForgeStaffItem.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/forge/item/ForgeStaffItem.kt index 72169762d..2d2291c3f 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/forge/item/ForgeStaffItem.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/forge/item/ForgeStaffItem.kt @@ -18,7 +18,6 @@ package opekope2.avm_staff.internal.forge.item -import dev.architectury.registry.registries.RegistrySupplier import net.minecraft.client.render.VertexConsumerProvider import net.minecraft.client.render.item.BuiltinModelItemRenderer import net.minecraft.client.render.model.json.ModelTransformationMode @@ -32,6 +31,7 @@ import net.minecraft.util.ActionResult import net.minecraft.util.Hand import net.minecraftforge.client.extensions.common.IClientItemExtensions import net.minecraftforge.common.extensions.IForgeItem +import net.minecraftforge.registries.RegistryObject import opekope2.avm_staff.api.item.StaffItem import opekope2.avm_staff.api.item.renderer.StaffRenderer import opekope2.avm_staff.util.blockEntityRenderDispatcher @@ -40,14 +40,12 @@ import opekope2.avm_staff.util.itemInStaff import opekope2.avm_staff.util.staffHandlerOrFallback import java.util.function.Consumer -class ForgeStaffItem(settings: Settings, repairIngredientSupplier: RegistrySupplier?) : +class ForgeStaffItem(settings: Settings, repairIngredientSupplier: RegistryObject?) : StaffItem(settings, repairIngredientSupplier), IForgeItem { override fun canDisableShield(stack: ItemStack, shield: ItemStack, entity: LivingEntity, attacker: LivingEntity) = disablesShield(stack, attacker.entityWorld, attacker, Hand.MAIN_HAND) || super.canDisableShield(stack, shield, entity, attacker) - override fun isRepairable(arg: ItemStack) = true - override fun onEntitySwing(stack: ItemStack, entity: LivingEntity) = !canSwingHand( stack, entity.entityWorld, diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/initializer/ClientInitializer.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/initializer/ClientInitializer.kt index 5315f4ad3..95ae84996 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/initializer/ClientInitializer.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/initializer/ClientInitializer.kt @@ -18,31 +18,32 @@ package opekope2.avm_staff.internal.initializer -import dev.architectury.registry.client.level.entity.EntityRendererRegistry -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment import net.minecraft.client.render.entity.EmptyEntityRenderer import net.minecraft.client.render.entity.TntEntityRenderer import net.minecraft.util.Identifier +import net.minecraftforge.api.distmarker.Dist +import net.minecraftforge.api.distmarker.OnlyIn +import net.minecraftforge.client.event.EntityRenderersEvent.RegisterRenderers import opekope2.avm_staff.api.entity.renderer.CakeEntityRenderer import opekope2.avm_staff.api.staff.StaffInfusionSmithingRecipeTextures import opekope2.avm_staff.content.EntityTypes import opekope2.avm_staff.internal.event_handler.KeyBindingHandler import opekope2.avm_staff.mixin.ISmithingTemplateItemAccessor import opekope2.avm_staff.util.MOD_ID +import thedarkcolour.kotlinforforge.forge.MOD_BUS -@Environment(EnvType.CLIENT) +@OnlyIn(Dist.CLIENT) object ClientInitializer { init { KeyBindingHandler - registerEntityRenderers() + MOD_BUS.addListener(::registerEntityRenderers) registerSmithingTableTextures() } - private fun registerEntityRenderers() { - EntityRendererRegistry.register(EntityTypes.IMPACT_TNT, ::TntEntityRenderer) - EntityRendererRegistry.register(EntityTypes.CAKE, ::CakeEntityRenderer) - EntityRendererRegistry.register(EntityTypes.CAMPFIRE_FLAME, ::EmptyEntityRenderer) + private fun registerEntityRenderers(event: RegisterRenderers) { + event.registerEntityRenderer(EntityTypes.impactTnt, ::TntEntityRenderer) + event.registerEntityRenderer(EntityTypes.cake, ::CakeEntityRenderer) + event.registerEntityRenderer(EntityTypes.campfireFlame, ::EmptyEntityRenderer) } private fun registerSmithingTableTextures() { diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/initializer/Initializer.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/initializer/Initializer.kt index 97aea63ac..14d4c707d 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/initializer/Initializer.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/initializer/Initializer.kt @@ -48,10 +48,10 @@ object Initializer { } private fun initializeNetworking() { - AttackC2SPacket.registerReceiver() - InsertItemIntoStaffC2SPacket.registerReceiver() - RemoveItemFromStaffC2SPacket.registerReceiver() + AttackC2SPacket + InsertItemIntoStaffC2SPacket + RemoveItemFromStaffC2SPacket - MassDestructionS2CPacket.registerReceiver() + MassDestructionS2CPacket } } diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/model/ModelPredicates.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/model/ModelPredicates.kt index f505a11dc..70ef39b2b 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/model/ModelPredicates.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/model/ModelPredicates.kt @@ -16,13 +16,9 @@ * along with this mod. If not, see . */ -@file: OnlyIn(Dist.CLIENT) - package opekope2.avm_staff.internal.model import net.minecraft.client.item.ClampedModelPredicateProvider -import net.minecraft.client.item.ModelPredicateProvider -import net.minecraft.client.item.ModelPredicateProviderRegistry import net.minecraft.item.ItemStack import net.minecraft.util.Identifier import net.minecraftforge.api.distmarker.Dist @@ -32,7 +28,7 @@ import opekope2.avm_staff.api.registry.RegistryBase import opekope2.avm_staff.content.DataComponentTypes import opekope2.avm_staff.util.MOD_ID -@Environment(EnvType.CLIENT) +@OnlyIn(Dist.CLIENT) object ModelPredicates : RegistryBase() { init { register(Identifier.of(MOD_ID, "using_item")) { stack, _, entity, _ -> diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/handler/AbstractMassDestructiveStaffHandler.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/handler/AbstractMassDestructiveStaffHandler.kt index f0b1917e2..e1252c8f9 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/handler/AbstractMassDestructiveStaffHandler.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/handler/AbstractMassDestructiveStaffHandler.kt @@ -18,12 +18,12 @@ package opekope2.avm_staff.internal.staff.handler -import dev.architectury.event.EventResult import net.minecraft.entity.LivingEntity import net.minecraft.entity.player.PlayerEntity import net.minecraft.item.ItemStack import net.minecraft.server.network.ServerPlayerEntity import net.minecraft.server.world.ServerWorld +import net.minecraft.util.ActionResult import net.minecraft.util.Hand import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Direction @@ -48,9 +48,9 @@ internal abstract class AbstractMassDestructiveStaffHandler : StaffHandler() { target: BlockPos, side: Direction, hand: Hand - ): EventResult { - if (world.isClient) return EventResult.pass() - if (attacker is PlayerEntity && attacker.isAttackCoolingDown) return EventResult.pass() + ): ActionResult { + if (world.isClient) return ActionResult.PASS + if (attacker is PlayerEntity && attacker.isAttackCoolingDown) return ActionResult.PASS require(world is ServerWorld) val shapePredicate = createBlockDestructionShapePredicate(world, attacker, target) @@ -72,7 +72,7 @@ internal abstract class AbstractMassDestructiveStaffHandler : StaffHandler() { (attacker as? ServerPlayerEntity)?.incrementStaffItemUseStat(staffStack.itemInStaff!!) // "Mismatch in destroy block pos" in server logs if I interrupt on server but not on client side. Nothing bad should happen, right? - return EventResult.pass() + return ActionResult.PASS } protected abstract fun createBlockDestructionShapePredicate( diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/handler/BellHandler.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/handler/BellHandler.kt index 403f54fac..712813cc7 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/handler/BellHandler.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/handler/BellHandler.kt @@ -18,14 +18,6 @@ package opekope2.avm_staff.internal.staff.handler -import dev.architectury.event.EventResult -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment -import net.minecraft.client.render.RenderLayer -import net.minecraft.client.render.VertexConsumerProvider -import net.minecraft.client.render.block.entity.BellBlockEntityRenderer -import net.minecraft.client.render.model.json.ModelTransformationMode -import net.minecraft.client.util.math.MatrixStack import net.minecraft.component.type.AttributeModifierSlot import net.minecraft.entity.Entity import net.minecraft.entity.LivingEntity @@ -42,8 +34,6 @@ import net.minecraft.util.TypedActionResult import net.minecraft.util.math.Box import net.minecraft.world.World import net.minecraft.world.event.GameEvent -import net.minecraftforge.api.distmarker.Dist -import net.minecraftforge.api.distmarker.OnlyIn import opekope2.avm_staff.api.staff.StaffAttributeModifiersComponentBuilder import opekope2.avm_staff.api.staff.StaffHandler import opekope2.avm_staff.mixin.IBellBlockEntityAccessor diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/handler/CampfireHandler.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/handler/CampfireHandler.kt index 3685a2c18..709bae12f 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/handler/CampfireHandler.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/handler/CampfireHandler.kt @@ -29,8 +29,6 @@ import net.minecraft.util.Hand import net.minecraft.util.TypedActionResult import net.minecraft.util.math.MathHelper import net.minecraft.world.World -import net.minecraftforge.api.distmarker.Dist -import net.minecraftforge.api.distmarker.OnlyIn import net.minecraftforge.registries.RegistryObject import opekope2.avm_staff.api.entity.CampfireFlameEntity import opekope2.avm_staff.api.staff.StaffHandler @@ -80,7 +78,7 @@ internal class CampfireHandler(private val parameters: Parameters) : StaffHandle relativeRight * FLAMETHROWER_CONE_END_WIDTH, relativeUp * FLAMETHROWER_CONE_END_HEIGHT, 16, - parameters.particleEffectSupplier.key, + parameters.particleEffectSupplier.key!!, FLAMETHROWER_CONE_RAY_RESOLUTION, parameters.flammableBlockFireChance, parameters.nonFlammableBlockFireChance, @@ -138,7 +136,7 @@ internal class CampfireHandler(private val parameters: Parameters) : StaffHandle val attackFireSeconds: Float, val flameFireTicks: Int, val rocketThrust: Double, - val particleEffectSupplier: RegistrySupplier + val particleEffectSupplier: RegistryObject ) private companion object { diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/handler/VanillaStaffHandlers.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/handler/VanillaStaffHandlers.kt index e95b3306f..ae75399ac 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/handler/VanillaStaffHandlers.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/handler/VanillaStaffHandlers.kt @@ -18,8 +18,6 @@ package opekope2.avm_staff.internal.staff.handler -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment import net.minecraft.block.Blocks import net.minecraft.item.BlockItem import net.minecraft.item.Items.* diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/item_renderer/BellStaffItemRenderer.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/item_renderer/BellStaffItemRenderer.kt index f3d36edaf..5ff75ecdf 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/item_renderer/BellStaffItemRenderer.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/item_renderer/BellStaffItemRenderer.kt @@ -18,18 +18,18 @@ package opekope2.avm_staff.internal.staff.item_renderer -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment import net.minecraft.client.render.RenderLayer import net.minecraft.client.render.VertexConsumerProvider import net.minecraft.client.render.block.entity.BellBlockEntityRenderer import net.minecraft.client.render.model.json.ModelTransformationMode import net.minecraft.client.util.math.MatrixStack import net.minecraft.item.ItemStack +import net.minecraftforge.api.distmarker.Dist +import net.minecraftforge.api.distmarker.OnlyIn import opekope2.avm_staff.api.item.renderer.StaffItemRenderer import opekope2.avm_staff.util.push -@Environment(EnvType.CLIENT) +@OnlyIn(Dist.CLIENT) class BellStaffItemRenderer : StaffItemRenderer() { private val bellModel = BellBlockEntityRenderer.getTexturedModelData().createModel().apply { setPivot(-8f, -12f, -8f) diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/item_renderer/FurnaceStaffItemRenderer.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/item_renderer/FurnaceStaffItemRenderer.kt index 90690d05c..059d075cb 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/item_renderer/FurnaceStaffItemRenderer.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/item_renderer/FurnaceStaffItemRenderer.kt @@ -18,8 +18,6 @@ package opekope2.avm_staff.internal.staff.item_renderer -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment import net.minecraft.block.AbstractFurnaceBlock import net.minecraft.block.Block import net.minecraft.block.BlockState @@ -27,11 +25,13 @@ import net.minecraft.client.render.VertexConsumerProvider import net.minecraft.client.render.model.json.ModelTransformationMode import net.minecraft.client.util.math.MatrixStack import net.minecraft.item.ItemStack +import net.minecraftforge.api.distmarker.Dist +import net.minecraftforge.api.distmarker.OnlyIn import opekope2.avm_staff.api.item.renderer.BlockStateStaffItemRenderer import opekope2.avm_staff.api.item.renderer.StaffItemRenderer import opekope2.avm_staff.content.DataComponentTypes -@Environment(EnvType.CLIENT) +@OnlyIn(Dist.CLIENT) class FurnaceStaffItemRenderer(unlitState: BlockState, litState: BlockState) : StaffItemRenderer() { constructor(furnaceBlock: Block) : this( furnaceBlock.defaultState, diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/item_renderer/LightningRodStaffItemRenderer.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/item_renderer/LightningRodStaffItemRenderer.kt index 06b1110c3..951f61ec4 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/item_renderer/LightningRodStaffItemRenderer.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/item_renderer/LightningRodStaffItemRenderer.kt @@ -18,18 +18,18 @@ package opekope2.avm_staff.internal.staff.item_renderer -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment import net.minecraft.block.Blocks import net.minecraft.client.render.VertexConsumerProvider import net.minecraft.client.render.model.json.ModelTransformationMode import net.minecraft.client.util.math.MatrixStack import net.minecraft.item.ItemStack +import net.minecraftforge.api.distmarker.Dist +import net.minecraftforge.api.distmarker.OnlyIn import opekope2.avm_staff.api.item.renderer.BlockStateStaffItemRenderer import opekope2.avm_staff.api.item.renderer.StaffItemRenderer import opekope2.avm_staff.util.push -@Environment(EnvType.CLIENT) +@OnlyIn(Dist.CLIENT) class LightningRodStaffItemRenderer : StaffItemRenderer() { private val lightningRodRenderer = BlockStateStaffItemRenderer(Blocks.LIGHTNING_ROD.defaultState) diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/item_renderer/WitherSkeletonSkullStaffItemRenderer.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/item_renderer/WitherSkeletonSkullStaffItemRenderer.kt index 22c0e7666..91532d089 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/item_renderer/WitherSkeletonSkullStaffItemRenderer.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/item_renderer/WitherSkeletonSkullStaffItemRenderer.kt @@ -18,8 +18,6 @@ package opekope2.avm_staff.internal.staff.item_renderer -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment import net.minecraft.block.AbstractSkullBlock import net.minecraft.block.Blocks import net.minecraft.client.render.VertexConsumerProvider @@ -28,10 +26,12 @@ import net.minecraft.client.render.entity.model.SkullEntityModel import net.minecraft.client.render.model.json.ModelTransformationMode import net.minecraft.client.util.math.MatrixStack import net.minecraft.item.ItemStack +import net.minecraftforge.api.distmarker.Dist +import net.minecraftforge.api.distmarker.OnlyIn import opekope2.avm_staff.api.item.renderer.StaffItemRenderer import opekope2.avm_staff.util.push -@Environment(EnvType.CLIENT) +@OnlyIn(Dist.CLIENT) class WitherSkeletonSkullStaffItemRenderer : StaffItemRenderer() { private val skullModel = SkullEntityModel.getSkullTexturedModelData().createModel() diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/util/MinecraftClientUtil.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/util/MinecraftClientUtil.kt index 6ea2010c0..3c9929b6b 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/util/MinecraftClientUtil.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/util/MinecraftClientUtil.kt @@ -17,12 +17,10 @@ */ @file: JvmName("MinecraftClientUtil") -@file: Environment(EnvType.CLIENT) +@file: OnlyIn(Dist.CLIENT) package opekope2.avm_staff.util -import net.fabricmc.api.EnvType -import net.fabricmc.api.Environment import net.minecraft.client.MinecraftClient import net.minecraft.client.option.GameOptions import net.minecraft.client.particle.ParticleManager @@ -30,6 +28,8 @@ import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher import net.minecraft.client.render.entity.model.EntityModelLoader import net.minecraft.client.render.item.ItemRenderer import net.minecraft.client.render.model.BakedModelManager +import net.minecraftforge.api.distmarker.Dist +import net.minecraftforge.api.distmarker.OnlyIn /** * @see MinecraftClient.bakedModelManager diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/util/RegistryUtil.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/util/RegistryUtil.kt index 27d9256a3..7d9171b8d 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/util/RegistryUtil.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/util/RegistryUtil.kt @@ -18,22 +18,43 @@ package opekope2.avm_staff.util -import dev.architectury.registry.registries.DeferredRegister -import dev.architectury.registry.registries.RegistrySupplier import net.minecraft.registry.Registry import net.minecraft.registry.RegistryKey import net.minecraft.util.Identifier +import net.minecraftforge.registries.DeferredRegister +import net.minecraftforge.registries.IForgeRegistry +import net.minecraftforge.registries.RegistryObject +import thedarkcolour.kotlinforforge.forge.MOD_BUS /** * Utility class to register content to Minecraft registries. * * @param TContent The type of the content to register - * @param modId The [namespace][Identifier.namespace] of the content to register. - * @param registry The registry to register the content in */ -abstract class RegistryUtil(modId: String, registry: RegistryKey>) : - RegistryKeyUtil(modId, registry) { - private val deferredRegister = DeferredRegister.create(modId, registry) +abstract class RegistryUtil : RegistryKeyUtil { + /** + * Creates a new [RegistryUtil] instance. + * + * @param TContent The type of the content to register + * @param modId The [namespace][Identifier.namespace] of the content to register. + * @param registry The registry to register the content in + */ + protected constructor(modId: String, registry: RegistryKey>) : super(modId, registry) { + this.deferredRegister = DeferredRegister.create(registry, modId) + } + + /** + * Creates a new [RegistryUtil] instance. + * + * @param TContent The type of the content to register + * @param modId The [namespace][Identifier.namespace] of the content to register. + * @param registry The registry to register the content in + */ + protected constructor(modId: String, registry: IForgeRegistry) : super(modId, registry.registryKey) { + this.deferredRegister = DeferredRegister.create(registry, modId) + } + + private val deferredRegister: DeferredRegister /** * Adds a content to be registered in a Minecraft registry using Architectury API. @@ -41,12 +62,12 @@ abstract class RegistryUtil(modId: String, registry: RegistryKey register(path: String, factory: (RegistryKey) -> T): RegistrySupplier = + protected fun register(path: String, factory: (RegistryKey) -> T): RegistryObject = deferredRegister.register(path) { factory(registryKey(path)) } /** * @suppress */ @JvmSynthetic - internal open fun register() = deferredRegister.register() + internal open fun register() = deferredRegister.register(MOD_BUS) }