diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/AnvilHandler.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/AnvilHandler.kt index 84dcb539b..99fe01d10 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/AnvilHandler.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/AnvilHandler.kt @@ -27,7 +27,6 @@ import net.minecraft.entity.attribute.EntityAttribute import net.minecraft.entity.attribute.EntityAttributeModifier import net.minecraft.entity.attribute.EntityAttributes import net.minecraft.entity.player.PlayerEntity -import net.minecraft.item.BlockItem import net.minecraft.item.ItemStack import net.minecraft.util.ActionResult import net.minecraft.util.Hand @@ -35,16 +34,12 @@ import net.minecraft.world.World import net.minecraft.world.WorldEvents import opekope2.avm_staff.api.item.IDisablesShield import opekope2.avm_staff.api.item.StaffItemHandler -import opekope2.avm_staff.api.item.model.ReloadableSingleBakedModelProvider -import opekope2.avm_staff.util.* +import opekope2.avm_staff.util.attackDamage +import opekope2.avm_staff.util.equipTime +import opekope2.avm_staff.util.itemInStaff import java.util.* -class AnvilHandler(anvilItem: BlockItem, private val damagedStackFactory: () -> ItemStack?) : StaffItemHandler(), - IDisablesShield { - override val itemModelProvider = ReloadableSingleBakedModelProvider { - anvilItem.block.defaultState.getTransformedModel(TRANSFORM_INTO_STAFF) - } - +class AnvilHandler(private val damagedStackFactory: () -> ItemStack?) : StaffItemHandler(), IDisablesShield { override fun attackEntity( staffStack: ItemStack, world: World, diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/BellBlockHandler.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/BellBlockHandler.kt index 2a4be80f4..fba1168be 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/BellBlockHandler.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/BellBlockHandler.kt @@ -23,13 +23,12 @@ import com.google.common.collect.Multimap import net.fabricmc.api.EnvType import net.fabricmc.api.Environment import net.minecraft.client.render.block.entity.BellBlockEntityRenderer -import net.minecraft.client.render.model.BakedModel -import net.minecraft.client.render.model.BakedQuad -import net.minecraft.client.render.model.BasicBakedModel +import net.minecraft.client.render.model.* import net.minecraft.client.render.model.json.ModelOverrideList import net.minecraft.client.render.model.json.ModelTransformation import net.minecraft.client.render.model.json.Transformation import net.minecraft.client.texture.Sprite +import net.minecraft.client.util.SpriteIdentifier import net.minecraft.entity.Entity import net.minecraft.entity.EquipmentSlot import net.minecraft.entity.LivingEntity @@ -42,19 +41,23 @@ import net.minecraft.sound.SoundCategory import net.minecraft.sound.SoundEvents import net.minecraft.util.ActionResult import net.minecraft.util.Hand +import net.minecraft.util.Identifier import net.minecraft.util.TypedActionResult import net.minecraft.util.math.Direction import net.minecraft.world.World import opekope2.avm_staff.api.item.StaffItemHandler -import opekope2.avm_staff.api.item.model.IReloadableBakedModelProvider +import opekope2.avm_staff.api.item.model.IStaffItemBakedModel +import opekope2.avm_staff.api.item.model.IStaffItemUnbakedModel +import opekope2.avm_staff.api.item.model.StaffItemBakedModel import opekope2.avm_staff.util.attackDamage import opekope2.avm_staff.util.attackSpeed import opekope2.avm_staff.util.getBakedQuads +import opekope2.avm_staff.util.transform import org.joml.Vector3f +import java.util.function.Function +import java.util.function.Supplier class BellBlockHandler : StaffItemHandler() { - override val itemModelProvider: IReloadableBakedModelProvider = ReloadableBellModelProvider() - override fun use( staffStack: ItemStack, world: World, @@ -94,18 +97,23 @@ class BellBlockHandler : StaffItemHandler() { } @Environment(EnvType.CLIENT) - private class ReloadableBellModelProvider : IReloadableBakedModelProvider { - private lateinit var model: BakedModel - - private val bellSprite: Sprite - get() = BellBlockEntityRenderer.BELL_BODY_TEXTURE.sprite + private class BellUnbakedModel : IStaffItemUnbakedModel { + override fun getModelDependencies() = setOf() - override fun getModel(staffStack: ItemStack): BakedModel = model + override fun setParents(modelLoader: Function?) { + } - override fun reload() { + override fun bake( + baker: Baker, + textureGetter: Function, + rotationContainer: ModelBakeSettings, + modelId: Identifier, + transformation: Transformation + ): IStaffItemBakedModel { + val bellSprite = textureGetter.apply(BellBlockEntityRenderer.BELL_BODY_TEXTURE) val bellModel = BellBlockEntityRenderer.getTexturedModelData().createModel().getChild("bell_body") - val quads = bellModel.getBakedQuads(bellSprite, transformation) - model = BasicBakedModel( + val quads = bellModel.getBakedQuads(bellSprite, bellTransformation) + val baked = BasicBakedModel( quads, createEmptyFaceQuads(), true, @@ -115,13 +123,15 @@ class BellBlockHandler : StaffItemHandler() { ModelTransformation.NONE, ModelOverrideList.EMPTY ) + + return StaffItemBakedModel(baked.transform(null, transformation, textureGetter)) } private companion object { - private val transformation = Transformation( + private val bellTransformation = Transformation( Vector3f(), - Vector3f((9f - 7f) / 9f / 2f, (22f - 3f) / 16f, (9f - 7f) / 9f / 2f), - Vector3f(7f / 9f) + Vector3f(-3.5f / 9f, -4f / 9f, -3.5f / 9f), + Vector3f(16f / 9f) ) private fun createEmptyFaceQuads(): Map> = mapOf( @@ -135,12 +145,16 @@ class BellBlockHandler : StaffItemHandler() { } } - private companion object { + companion object { private val ATTRIBUTE_MODIFIERS = ImmutableMultimap.of( EntityAttributes.GENERIC_ATTACK_DAMAGE, attackDamage(8.0), EntityAttributes.GENERIC_ATTACK_SPEED, attackSpeed(1.5) ) + + val modelSupplierFactory: Supplier> = Supplier { + Supplier(::BellUnbakedModel) + } } } diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/BoneBlockHandler.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/BoneBlockHandler.kt index 1e88cf225..d0f8a6ea9 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/BoneBlockHandler.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/BoneBlockHandler.kt @@ -18,7 +18,6 @@ package opekope2.avm_staff.internal.staff_item_handler -import net.minecraft.block.Blocks import net.minecraft.entity.LivingEntity import net.minecraft.item.BoneMealItem import net.minecraft.item.ItemStack @@ -30,15 +29,8 @@ import net.minecraft.world.World import net.minecraft.world.WorldEvents import net.minecraft.world.event.GameEvent import opekope2.avm_staff.api.item.StaffItemHandler -import opekope2.avm_staff.api.item.model.ReloadableSingleBakedModelProvider -import opekope2.avm_staff.util.TRANSFORM_INTO_STAFF -import opekope2.avm_staff.util.getTransformedModel class BoneBlockHandler : StaffItemHandler() { - override val itemModelProvider = ReloadableSingleBakedModelProvider { - Blocks.BONE_BLOCK.defaultState.getTransformedModel(TRANSFORM_INTO_STAFF) - } - override fun useOnBlock( staffStack: ItemStack, world: World, diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/FurnaceHandler.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/FurnaceHandler.kt index d5cf1fdae..50cdcf067 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/FurnaceHandler.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/FurnaceHandler.kt @@ -23,9 +23,17 @@ import com.google.common.collect.Multimap 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 import net.minecraft.client.MinecraftClient +import net.minecraft.client.render.block.BlockModels import net.minecraft.client.render.model.BakedModel +import net.minecraft.client.render.model.Baker +import net.minecraft.client.render.model.ModelBakeSettings +import net.minecraft.client.render.model.UnbakedModel +import net.minecraft.client.render.model.json.Transformation +import net.minecraft.client.texture.Sprite +import net.minecraft.client.util.SpriteIdentifier import net.minecraft.entity.EquipmentSlot import net.minecraft.entity.ItemEntity import net.minecraft.entity.LivingEntity @@ -34,7 +42,6 @@ import net.minecraft.entity.attribute.EntityAttributeModifier import net.minecraft.entity.attribute.EntityAttributes import net.minecraft.entity.player.PlayerEntity import net.minecraft.inventory.SingleStackInventory -import net.minecraft.item.BlockItem import net.minecraft.item.ItemStack import net.minecraft.particle.ParticleTypes import net.minecraft.recipe.AbstractCookingRecipe @@ -43,27 +50,25 @@ import net.minecraft.server.world.ServerWorld import net.minecraft.sound.SoundCategory import net.minecraft.sound.SoundEvent import net.minecraft.util.Hand +import net.minecraft.util.Identifier import net.minecraft.util.TypedActionResult import net.minecraft.util.math.Box import net.minecraft.world.World import opekope2.avm_staff.api.item.StaffItemHandler -import opekope2.avm_staff.api.item.model.IReloadableBakedModelProvider +import opekope2.avm_staff.api.item.model.IStaffItemBakedModel +import opekope2.avm_staff.api.item.model.IStaffItemUnbakedModel import opekope2.avm_staff.mixin.IAbstractFurnaceBlockEntityMixin import opekope2.avm_staff.util.* +import java.util.function.Function +import java.util.function.Supplier import kotlin.jvm.optionals.getOrNull class FurnaceHandler( - furnaceItem: BlockItem, private val recipeType: RecipeType, private val smeltSound: SoundEvent ) : StaffItemHandler() { override val maxUseTime = 72000 - override val itemModelProvider: IReloadableBakedModelProvider = ReloadableFurnaceModelProvider( - furnaceItem.block.defaultState.with(AbstractFurnaceBlock.LIT, true), - furnaceItem.block.defaultState - ) - override fun use( staffStack: ItemStack, world: World, @@ -117,7 +122,7 @@ class FurnaceHandler( user: LivingEntity, world: World ): ItemEntity? { - val smeltingPosition = user.eyePos + user.rotationVector.normalize() * 1.75 + val smeltingPosition = user.approximateStaffItemPosition val items = world.getEntitiesByClass(ItemEntity::class.java, SMELTING_VOLUME.offset(smeltingPosition)) { true } val closest = items.minByOrNull { (smeltingPosition - it.pos).lengthSquared() } return closest @@ -177,20 +182,41 @@ class FurnaceHandler( } @Environment(EnvType.CLIENT) - private class ReloadableFurnaceModelProvider(private val litState: BlockState, private val unlitState: BlockState) : - IReloadableBakedModelProvider { - private lateinit var litModel: BakedModel - private lateinit var unlitModel: BakedModel + private class FurnaceUnbakedModel(private val unlitState: BlockState, private val litState: BlockState) : + IStaffItemUnbakedModel { + private val litStateId = BlockModels.getModelId(litState) + private val unlitStateId = BlockModels.getModelId(unlitState) + private val dependencies = setOf(litStateId, unlitStateId) + + override fun getModelDependencies() = dependencies + + override fun setParents(modelLoader: Function?) { + } + + override fun bake( + baker: Baker, + textureGetter: Function, + rotationContainer: ModelBakeSettings, + modelId: Identifier, + transformation: Transformation + ): IStaffItemBakedModel? { + val unlitModel = baker.bake(unlitStateId, rotationContainer) ?: return null + val litModel = baker.bake(litStateId, rotationContainer) ?: return null + + return FurnaceBakedModel( + unlitModel.transform(unlitState, transformation, textureGetter), + litModel.transform(litState, transformation, textureGetter) + ) + } + } + @Environment(EnvType.CLIENT) + private class FurnaceBakedModel(private val unlitModel: BakedModel, private val litModel: BakedModel) : + BakedModel by unlitModel, IStaffItemBakedModel { override fun getModel(staffStack: ItemStack): BakedModel { return if (staffStack.nbt?.getBoolean(LIT_KEY) == true) litModel else unlitModel } - - override fun reload() { - litModel = litState.getTransformedModel(TRANSFORM_INTO_STAFF) - unlitModel = unlitState.getTransformedModel(TRANSFORM_INTO_STAFF) - } } private class ItemEntityInventory(private val itemEntity: ItemEntity) : SingleStackInventory { @@ -205,7 +231,7 @@ class FurnaceHandler( override fun asBlockEntity(): Nothing = throw UnsupportedOperationException() } - private companion object { + companion object { private const val LIT_KEY = "Lit" private const val BURN_TIME_KEY = "BurnTime" private val SMELTING_VOLUME = Box(-0.5, -0.5, -0.5, 0.5, 0.5, 0.5).contract(0.25 / 2) @@ -215,5 +241,14 @@ class FurnaceHandler( EntityAttributes.GENERIC_ATTACK_SPEED, attackSpeed(2.0) ) + + fun getModelSupplierFactory(furnaceBlock: Block): Supplier> = Supplier { + Supplier { + FurnaceUnbakedModel( + furnaceBlock.defaultState, + furnaceBlock.defaultState.with(AbstractFurnaceBlock.LIT, true) + ) + } + } } } diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/LightningRodHandler.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/LightningRodHandler.kt index 6d63f3466..4ff97ee6e 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/LightningRodHandler.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/LightningRodHandler.kt @@ -18,26 +18,36 @@ package opekope2.avm_staff.internal.staff_item_handler +import net.fabricmc.api.EnvType +import net.fabricmc.api.Environment +import net.minecraft.block.BlockState import net.minecraft.block.Blocks +import net.minecraft.client.render.block.BlockModels +import net.minecraft.client.render.model.Baker +import net.minecraft.client.render.model.ModelBakeSettings +import net.minecraft.client.render.model.UnbakedModel import net.minecraft.client.render.model.json.Transformation +import net.minecraft.client.texture.Sprite +import net.minecraft.client.util.SpriteIdentifier import net.minecraft.entity.EntityType import net.minecraft.entity.LivingEntity import net.minecraft.item.ItemStack import net.minecraft.util.ActionResult import net.minecraft.util.Hand +import net.minecraft.util.Identifier import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Direction import net.minecraft.world.World import opekope2.avm_staff.api.item.StaffItemHandler -import opekope2.avm_staff.api.item.model.ReloadableSingleBakedModelProvider -import opekope2.avm_staff.util.getTransformedModel +import opekope2.avm_staff.api.item.model.IStaffItemBakedModel +import opekope2.avm_staff.api.item.model.IStaffItemUnbakedModel +import opekope2.avm_staff.api.item.model.StaffItemBakedModel +import opekope2.avm_staff.util.transform import org.joml.Vector3f +import java.util.function.Function +import java.util.function.Supplier class LightningRodHandler : StaffItemHandler() { - override val itemModelProvider = ReloadableSingleBakedModelProvider { - Blocks.LIGHTNING_ROD.defaultState.getTransformedModel(transformation) - } - override fun useOnBlock( staffStack: ItemStack, world: World, @@ -67,11 +77,46 @@ class LightningRodHandler : StaffItemHandler() { return ActionResult.SUCCESS } - private companion object { - private val transformation = Transformation( - Vector3f(), - Vector3f((16f - 7f) / 16f / 2f, 32f / 16f, (16f - 7f) / 16f / 2f), - Vector3f(7f / 16f) - ) + @Environment(EnvType.CLIENT) + private class LightningRodUnbakedModel(private val state: BlockState) : IStaffItemUnbakedModel { + private val stateId = BlockModels.getModelId(state) + private val dependencies = setOf(stateId) + + override fun getModelDependencies() = dependencies + + override fun setParents(modelLoader: Function?) { + } + + override fun bake( + baker: Baker, + textureGetter: Function, + rotationContainer: ModelBakeSettings, + modelId: Identifier, + transformation: Transformation + ): IStaffItemBakedModel? { + val baked = baker.bake(stateId, rotationContainer) ?: return null + + return StaffItemBakedModel( + baked + .transform(state, lightningRodTransformation, textureGetter) + .transform(state, transformation, textureGetter) + ) + } + + private companion object { + private val lightningRodTransformation = Transformation( + Vector3f(), + Vector3f(-1f / 14f, 10f / 7f, -1f / 14f), + Vector3f(8f / 7f) + ) + } + } + + companion object { + val modelSupplier: Supplier> = Supplier { + Supplier { + LightningRodUnbakedModel(Blocks.LIGHTNING_ROD.defaultState) + } + } } } diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/MagmaBlockHandler.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/MagmaBlockHandler.kt index e9bf93544..7a7e287c4 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/MagmaBlockHandler.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/MagmaBlockHandler.kt @@ -20,7 +20,6 @@ package opekope2.avm_staff.internal.staff_item_handler import com.google.common.collect.ImmutableMultimap import com.google.common.collect.Multimap -import net.minecraft.block.Blocks import net.minecraft.entity.Entity import net.minecraft.entity.EquipmentSlot import net.minecraft.entity.LivingEntity @@ -36,16 +35,11 @@ import net.minecraft.util.TypedActionResult import net.minecraft.world.World import net.minecraft.world.WorldEvents import opekope2.avm_staff.api.item.StaffItemHandler -import opekope2.avm_staff.api.item.model.ReloadableSingleBakedModelProvider import opekope2.avm_staff.util.* class MagmaBlockHandler : StaffItemHandler() { override val maxUseTime = 72000 - override val itemModelProvider = ReloadableSingleBakedModelProvider { - Blocks.MAGMA_BLOCK.defaultState.getTransformedModel(TRANSFORM_INTO_STAFF) - } - override fun use( staffStack: ItemStack, world: World, diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/SnowBlockHandler.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/SnowBlockHandler.kt index 65c6ab454..a76c683e8 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/SnowBlockHandler.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/SnowBlockHandler.kt @@ -18,7 +18,6 @@ package opekope2.avm_staff.internal.staff_item_handler -import net.minecraft.block.Blocks import net.minecraft.entity.LivingEntity import net.minecraft.entity.player.PlayerEntity import net.minecraft.entity.projectile.thrown.SnowballEntity @@ -29,16 +28,14 @@ import net.minecraft.util.Hand import net.minecraft.util.TypedActionResult import net.minecraft.world.World import opekope2.avm_staff.api.item.StaffItemHandler -import opekope2.avm_staff.api.item.model.ReloadableSingleBakedModelProvider -import opekope2.avm_staff.util.* +import opekope2.avm_staff.util.approximateStaffTipPosition +import opekope2.avm_staff.util.component1 +import opekope2.avm_staff.util.component2 +import opekope2.avm_staff.util.component3 class SnowBlockHandler : StaffItemHandler() { override val maxUseTime = 72000 - override val itemModelProvider = ReloadableSingleBakedModelProvider { - Blocks.SNOW_BLOCK.defaultState.getTransformedModel(TRANSFORM_INTO_STAFF) - } - override fun use( staffStack: ItemStack, world: World, diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/TntHandler.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/TntHandler.kt index bb05e4fae..22d1d504f 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/TntHandler.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/TntHandler.kt @@ -18,7 +18,6 @@ package opekope2.avm_staff.internal.staff_item_handler -import net.minecraft.block.Blocks import net.minecraft.entity.LivingEntity import net.minecraft.entity.TntEntity import net.minecraft.item.ItemStack @@ -30,14 +29,9 @@ import net.minecraft.world.World import net.minecraft.world.event.GameEvent import opekope2.avm_staff.api.entity.IImpactTnt import opekope2.avm_staff.api.item.StaffItemHandler -import opekope2.avm_staff.api.item.model.ReloadableSingleBakedModelProvider import opekope2.avm_staff.util.* class TntHandler : StaffItemHandler() { - override val itemModelProvider = ReloadableSingleBakedModelProvider { - Blocks.TNT.defaultState.getTransformedModel(TRANSFORM_INTO_STAFF) - } - override fun attack(staffStack: ItemStack, world: World, attacker: LivingEntity, hand: Hand): ActionResult { if (world.isClient) return ActionResult.SUCCESS diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/VanillaStaffItemHandlers.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/VanillaStaffItemHandlers.kt index f3face288..cca6fe2c7 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/VanillaStaffItemHandlers.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/VanillaStaffItemHandlers.kt @@ -18,60 +18,74 @@ package opekope2.avm_staff.internal.staff_item_handler -import net.minecraft.item.BlockItem +import net.minecraft.block.Block +import net.minecraft.block.Blocks.* import net.minecraft.item.Item -import net.minecraft.item.Items.* +import net.minecraft.item.Items import net.minecraft.recipe.RecipeType import net.minecraft.registry.Registries import net.minecraft.sound.SoundEvents import opekope2.avm_staff.api.item.StaffItemHandler +import opekope2.avm_staff.api.item.model.IStaffItemUnbakedModel +import opekope2.avm_staff.api.item.model.UnbakedBlockStateModelSupplier +import java.util.function.Supplier -private fun Item.registerHandler(handler: StaffItemHandler) { - StaffItemHandler.register(Registries.ITEM.getId(this), handler) +private fun Item.registerHandler( + handler: StaffItemHandler, + itemModelSupplierFactory: Supplier> +) { + StaffItemHandler.register(Registries.ITEM.getId(this), handler, itemModelSupplierFactory) +} + +private fun Item.registerHandler(handler: StaffItemHandler, staffItem: Block) { + registerHandler(handler) { UnbakedBlockStateModelSupplier(staffItem.defaultState) } } @Suppress("unused") fun registerVanillaStaffItemHandlers() { - ANVIL.registerHandler(AnvilHandler(ANVIL as BlockItem, CHIPPED_ANVIL::getDefaultStack)) - CHIPPED_ANVIL.registerHandler(AnvilHandler(CHIPPED_ANVIL as BlockItem, DAMAGED_ANVIL::getDefaultStack)) - DAMAGED_ANVIL.registerHandler(AnvilHandler(DAMAGED_ANVIL as BlockItem) { null }) + Items.ANVIL.registerHandler(AnvilHandler(Items.CHIPPED_ANVIL::getDefaultStack), ANVIL) + Items.CHIPPED_ANVIL.registerHandler(AnvilHandler(Items.DAMAGED_ANVIL::getDefaultStack), CHIPPED_ANVIL) + Items.DAMAGED_ANVIL.registerHandler(AnvilHandler { null }, DAMAGED_ANVIL) - BELL.registerHandler(BellBlockHandler()) + Items.BELL.registerHandler(BellBlockHandler(), BellBlockHandler.modelSupplierFactory) - BONE_BLOCK.registerHandler(BoneBlockHandler()) + Items.BONE_BLOCK.registerHandler(BoneBlockHandler(), BONE_BLOCK) - FURNACE.registerHandler( - FurnaceHandler(FURNACE as BlockItem, RecipeType.SMELTING, SoundEvents.BLOCK_FURNACE_FIRE_CRACKLE) + Items.FURNACE.registerHandler( + FurnaceHandler(RecipeType.SMELTING, SoundEvents.BLOCK_FURNACE_FIRE_CRACKLE), + FurnaceHandler.getModelSupplierFactory(FURNACE) ) - BLAST_FURNACE.registerHandler( - FurnaceHandler(BLAST_FURNACE as BlockItem, RecipeType.BLASTING, SoundEvents.BLOCK_BLASTFURNACE_FIRE_CRACKLE) + Items.BLAST_FURNACE.registerHandler( + FurnaceHandler(RecipeType.BLASTING, SoundEvents.BLOCK_BLASTFURNACE_FIRE_CRACKLE), + FurnaceHandler.getModelSupplierFactory(BLAST_FURNACE) ) - SMOKER.registerHandler( - FurnaceHandler(SMOKER as BlockItem, RecipeType.SMOKING, SoundEvents.BLOCK_SMOKER_SMOKE) + Items.SMOKER.registerHandler( + FurnaceHandler(RecipeType.SMOKING, SoundEvents.BLOCK_SMOKER_SMOKE), + FurnaceHandler.getModelSupplierFactory(SMOKER) ) - LIGHTNING_ROD.registerHandler(LightningRodHandler()) + Items.LIGHTNING_ROD.registerHandler(LightningRodHandler(), LightningRodHandler.modelSupplier) - MAGMA_BLOCK.registerHandler(MagmaBlockHandler()) + Items.MAGMA_BLOCK.registerHandler(MagmaBlockHandler(), MAGMA_BLOCK) - SNOW_BLOCK.registerHandler(SnowBlockHandler()) + Items.SNOW_BLOCK.registerHandler(SnowBlockHandler(), SNOW_BLOCK) - TNT.registerHandler(TntHandler()) + Items.TNT.registerHandler(TntHandler(), TNT) - WHITE_WOOL.registerHandler(WoolHandler(WHITE_WOOL as BlockItem, WHITE_CARPET as BlockItem)) - ORANGE_WOOL.registerHandler(WoolHandler(ORANGE_WOOL as BlockItem, ORANGE_CARPET as BlockItem)) - MAGENTA_WOOL.registerHandler(WoolHandler(MAGENTA_WOOL as BlockItem, MAGENTA_CARPET as BlockItem)) - LIGHT_BLUE_WOOL.registerHandler(WoolHandler(LIGHT_BLUE_WOOL as BlockItem, LIGHT_BLUE_CARPET as BlockItem)) - YELLOW_WOOL.registerHandler(WoolHandler(YELLOW_WOOL as BlockItem, YELLOW_CARPET as BlockItem)) - LIME_WOOL.registerHandler(WoolHandler(LIME_WOOL as BlockItem, LIME_CARPET as BlockItem)) - PINK_WOOL.registerHandler(WoolHandler(PINK_WOOL as BlockItem, PINK_CARPET as BlockItem)) - GRAY_WOOL.registerHandler(WoolHandler(GRAY_WOOL as BlockItem, GRAY_CARPET as BlockItem)) - LIGHT_GRAY_WOOL.registerHandler(WoolHandler(LIGHT_GRAY_WOOL as BlockItem, LIGHT_GRAY_CARPET as BlockItem)) - CYAN_WOOL.registerHandler(WoolHandler(CYAN_WOOL as BlockItem, CYAN_CARPET as BlockItem)) - PURPLE_WOOL.registerHandler(WoolHandler(PURPLE_WOOL as BlockItem, PURPLE_CARPET as BlockItem)) - BLUE_WOOL.registerHandler(WoolHandler(BLUE_WOOL as BlockItem, BLUE_CARPET as BlockItem)) - BROWN_WOOL.registerHandler(WoolHandler(BROWN_WOOL as BlockItem, BROWN_CARPET as BlockItem)) - GREEN_WOOL.registerHandler(WoolHandler(GREEN_WOOL as BlockItem, GREEN_CARPET as BlockItem)) - RED_WOOL.registerHandler(WoolHandler(RED_WOOL as BlockItem, RED_CARPET as BlockItem)) - BLACK_WOOL.registerHandler(WoolHandler(BLACK_WOOL as BlockItem, BLACK_CARPET as BlockItem)) + Items.WHITE_WOOL.registerHandler(WoolHandler(WHITE_WOOL, WHITE_CARPET), WHITE_WOOL) + Items.ORANGE_WOOL.registerHandler(WoolHandler(ORANGE_WOOL, ORANGE_CARPET), ORANGE_WOOL) + Items.MAGENTA_WOOL.registerHandler(WoolHandler(MAGENTA_WOOL, MAGENTA_CARPET), MAGENTA_WOOL) + Items.LIGHT_BLUE_WOOL.registerHandler(WoolHandler(LIGHT_BLUE_WOOL, LIGHT_BLUE_CARPET), LIGHT_BLUE_WOOL) + Items.YELLOW_WOOL.registerHandler(WoolHandler(YELLOW_WOOL, YELLOW_CARPET), YELLOW_WOOL) + Items.LIME_WOOL.registerHandler(WoolHandler(LIME_WOOL, LIME_CARPET), LIME_WOOL) + Items.PINK_WOOL.registerHandler(WoolHandler(PINK_WOOL, PINK_CARPET), PINK_WOOL) + Items.GRAY_WOOL.registerHandler(WoolHandler(GRAY_WOOL, GRAY_CARPET), GRAY_WOOL) + Items.LIGHT_GRAY_WOOL.registerHandler(WoolHandler(LIGHT_GRAY_WOOL, LIGHT_GRAY_CARPET), LIGHT_GRAY_WOOL) + Items.CYAN_WOOL.registerHandler(WoolHandler(CYAN_WOOL, CYAN_CARPET), CYAN_WOOL) + Items.PURPLE_WOOL.registerHandler(WoolHandler(PURPLE_WOOL, PURPLE_CARPET), PURPLE_WOOL) + Items.BLUE_WOOL.registerHandler(WoolHandler(BLUE_WOOL, BLUE_CARPET), BLUE_WOOL) + Items.BROWN_WOOL.registerHandler(WoolHandler(BROWN_WOOL, BROWN_CARPET), BROWN_WOOL) + Items.GREEN_WOOL.registerHandler(WoolHandler(GREEN_WOOL, GREEN_CARPET), GREEN_WOOL) + Items.RED_WOOL.registerHandler(WoolHandler(RED_WOOL, RED_CARPET), RED_WOOL) + Items.BLACK_WOOL.registerHandler(WoolHandler(BLACK_WOOL, BLACK_CARPET), BLACK_WOOL) } diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/WoolHandler.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/WoolHandler.kt index 24d6b6352..9b8f889ce 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/WoolHandler.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/WoolHandler.kt @@ -20,6 +20,7 @@ package opekope2.avm_staff.internal.staff_item_handler import com.google.common.collect.ImmutableMultimap import com.google.common.collect.Multimap +import net.minecraft.block.Block import net.minecraft.client.MinecraftClient import net.minecraft.client.network.ClientPlayerEntity import net.minecraft.entity.EquipmentSlot @@ -28,7 +29,6 @@ import net.minecraft.entity.attribute.EntityAttribute import net.minecraft.entity.attribute.EntityAttributeModifier import net.minecraft.entity.attribute.EntityAttributes import net.minecraft.entity.player.PlayerEntity -import net.minecraft.item.BlockItem import net.minecraft.item.ItemPlacementContext import net.minecraft.item.ItemStack import net.minecraft.registry.tag.BlockTags @@ -41,20 +41,13 @@ import net.minecraft.util.math.Direction import net.minecraft.world.World import net.minecraft.world.event.GameEvent import opekope2.avm_staff.api.item.StaffItemHandler -import opekope2.avm_staff.api.item.model.ReloadableSingleBakedModelProvider import opekope2.avm_staff.mixin.IMinecraftClientMixin -import opekope2.avm_staff.util.TRANSFORM_INTO_STAFF import opekope2.avm_staff.util.attackDamage import opekope2.avm_staff.util.attackSpeed -import opekope2.avm_staff.util.getTransformedModel -class WoolHandler(woolItem: BlockItem, carpetItem: BlockItem) : StaffItemHandler() { - private val woolState = woolItem.block.defaultState - private val carpetState = carpetItem.block.defaultState - - override val itemModelProvider = ReloadableSingleBakedModelProvider { - woolItem.block.defaultState.getTransformedModel(TRANSFORM_INTO_STAFF) - } +class WoolHandler(woolBlock: Block, carpetBlock: Block) : StaffItemHandler() { + private val woolState = woolBlock.defaultState + private val carpetState = carpetBlock.defaultState override fun useOnBlock( staffStack: ItemStack,