Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Staff Mod 0.17.1 #45

Merged
merged 4 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion FabricMod/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"fabric-api": ">=$fabric_api",
"fabric-language-kotlin": ">=$fabric_language_kotlin",
"architectury": ">=$architectury",
"minecraft": "=$minecraft",
"minecraft": ">=$minecraft",
"java": ">=$java"
},
"custom": {
Expand Down
2 changes: 1 addition & 1 deletion NeoForgeMod/src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ side = "BOTH"
[[dependencies.avm_staff]]
modId = "minecraft"
type = "required"
versionRange = "[$minecraft]"
versionRange = "[$minecraft,)"
ordering = "NONE"
side = "BOTH"

Expand Down
38 changes: 19 additions & 19 deletions StaffMod/src/main/kotlin/opekope2/avm_staff/api/StaffMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import dev.architectury.registry.CreativeTabRegistry
import dev.architectury.registry.registries.DeferredRegister
import dev.architectury.registry.registries.RegistrySupplier
import net.minecraft.block.AbstractBlock
import net.minecraft.block.enums.Instrument
import net.minecraft.block.enums.NoteBlockInstrument
import net.minecraft.block.piston.PistonBehavior
import net.minecraft.client.particle.ParticleManager
import net.minecraft.component.DataComponentType
import net.minecraft.component.ComponentType
import net.minecraft.entity.EntityType
import net.minecraft.entity.SpawnGroup
import net.minecraft.entity.damage.DamageType
Expand Down Expand Up @@ -78,7 +78,7 @@ private val SOUND_EVENTS = DeferredRegister.create(MOD_ID, RegistryKeys.SOUND_EV
*/
val crownOfKingOrangeBlock: RegistrySupplier<CrownBlock> = BLOCKS.register("crown_of_king_orange") {
CrownBlock(
AbstractBlock.Settings.create().instrument(Instrument.BELL).strength(1.0f)
AbstractBlock.Settings.create().instrument(NoteBlockInstrument.BELL).strength(1.0f)
.pistonBehavior(PistonBehavior.DESTROY).sounds(BlockSoundGroup.COPPER_GRATE).nonOpaque()
)
}
Expand Down Expand Up @@ -181,7 +181,7 @@ val impactTntEntityType: RegistrySupplier<EntityType<ImpactTntEntity>> = ENTITY_
.eyeHeight(EntityType.TNT.dimensions.eyeHeight)
.maxTrackingRange(EntityType.TNT.maxTrackDistance)
.trackingTickInterval(EntityType.TNT.trackTickInterval)
.build(Identifier(MOD_ID, "impact_tnt").toString())
.build(Identifier.of(MOD_ID, "impact_tnt").toString())
}

/**
Expand All @@ -196,7 +196,7 @@ val cakeEntityType: RegistrySupplier<EntityType<CakeEntity>> =
.dimensions(cakeSize.toFloat(), cakeSize.toFloat())
.maxTrackingRange(EntityType.FALLING_BLOCK.maxTrackDistance)
.trackingTickInterval(EntityType.FALLING_BLOCK.trackTickInterval)
.build(Identifier(MOD_ID, "cake").toString())
.build(Identifier.of(MOD_ID, "cake").toString())
}

/**
Expand All @@ -218,9 +218,9 @@ val soulFlamethrowerParticleType: RegistrySupplier<SimpleParticleType> =
/**
* Data component registered as `avm_staff:staff_item`. Stores the item inserted into the staff.
*/
val staffItemComponentType: RegistrySupplier<DataComponentType<StaffItemComponent>> =
val staffItemComponentType: RegistrySupplier<ComponentType<StaffItemComponent>> =
DATA_COMPONENT_TYPES.register("staff_item") {
DataComponentType.builder<StaffItemComponent>()
ComponentType.builder<StaffItemComponent>()
.codec(StaffItemComponent.CODEC)
.packetCodec(StaffItemComponent.PACKET_CODEC)
.build()
Expand All @@ -229,19 +229,19 @@ val staffItemComponentType: RegistrySupplier<DataComponentType<StaffItemComponen
/**
* Data component registered as `avm_staff:rocket_mode`. Stores if a campfire staff should propel its user.
*/
val rocketModeComponentType: RegistrySupplier<DataComponentType<MinecraftUnit>> =
val rocketModeComponentType: RegistrySupplier<ComponentType<MinecraftUnit>> =
DATA_COMPONENT_TYPES.register("rocket_mode") {
DataComponentType.builder<MinecraftUnit>()
ComponentType.builder<MinecraftUnit>()
.packetCodec(PacketCodec.unit(MinecraftUnit.INSTANCE))
.build()
}

/**
* Data component registered as `avm_staff:furnace_data`. If this is present, the furnace is lit.
*/
val staffFurnaceDataComponentType: RegistrySupplier<DataComponentType<StaffFurnaceDataComponent>> =
val staffFurnaceDataComponentType: RegistrySupplier<ComponentType<StaffFurnaceDataComponent>> =
DATA_COMPONENT_TYPES.register("furnace_data") {
DataComponentType.builder<StaffFurnaceDataComponent>()
ComponentType.builder<StaffFurnaceDataComponent>()
.packetCodec(StaffFurnaceDataComponent.PACKET_CODEC)
.build()
}
Expand All @@ -250,9 +250,9 @@ val staffFurnaceDataComponentType: RegistrySupplier<DataComponentType<StaffFurna
* Data component registered as `avm_staff:staff_renderer_override`. Specifies how a staff is rendered. Intended for
* Isometric Renders mod compatibility.
*/
val staffRendererOverrideComponentType: RegistrySupplier<DataComponentType<StaffRendererOverrideComponent>> =
val staffRendererOverrideComponentType: RegistrySupplier<ComponentType<StaffRendererOverrideComponent>> =
DATA_COMPONENT_TYPES.register("staff_renderer_override") {
DataComponentType.builder<StaffRendererOverrideComponent>()
ComponentType.builder<StaffRendererOverrideComponent>()
.codec(StaffRendererOverrideComponent.CODEC)
.packetCodec(StaffRendererOverrideComponent.PACKET_CODEC)
.build()
Expand All @@ -261,9 +261,9 @@ val staffRendererOverrideComponentType: RegistrySupplier<DataComponentType<Staff
/**
* Data component registered as `avm_staff:staff_renderer_part`. Only used for rendering.
*/
val staffRendererPartComponentType: RegistrySupplier<DataComponentType<StaffRendererPartComponent>> =
val staffRendererPartComponentType: RegistrySupplier<ComponentType<StaffRendererPartComponent>> =
DATA_COMPONENT_TYPES.register("staff_renderer_part") {
DataComponentType.builder<StaffRendererPartComponent>()
ComponentType.builder<StaffRendererPartComponent>()
.packetCodec(StaffRendererPartComponent.PACKET_CODEC)
.build()
}
Expand All @@ -272,27 +272,27 @@ val staffRendererPartComponentType: RegistrySupplier<DataComponentType<StaffRend
* Sound event registered as `avm_staff:entity.cake.splash`.
*/
val cakeSplashSoundEvent: RegistrySupplier<SoundEvent> = SOUND_EVENTS.register("entity.cake.splash") {
SoundEvent.of(Identifier(MOD_ID, "entity.cake.splash"))
SoundEvent.of(Identifier.of(MOD_ID, "entity.cake.splash"))
}

/**
* Sound event registered as `avm_staff:entity.cake.throw`.
*/
val cakeThrowSoundEvent: RegistrySupplier<SoundEvent> = SOUND_EVENTS.register("entity.cake.throw") {
SoundEvent.of(Identifier(MOD_ID, "entity.cake.throw"))
SoundEvent.of(Identifier.of(MOD_ID, "entity.cake.throw"))
}

/**
* `avm_staff:pranked` damage type.
*/
val cakeDamageType: RegistryKey<DamageType> =
RegistryKey.of(RegistryKeys.DAMAGE_TYPE, Identifier(MOD_ID, "pranked"))
RegistryKey.of(RegistryKeys.DAMAGE_TYPE, Identifier.of(MOD_ID, "pranked"))

/**
* `avm_staff:pranked_by_player` damage type.
*/
val playerCakeDamageType: RegistryKey<DamageType> =
RegistryKey.of(RegistryKeys.DAMAGE_TYPE, Identifier(MOD_ID, "pranked_by_player"))
RegistryKey.of(RegistryKeys.DAMAGE_TYPE, Identifier.of(MOD_ID, "pranked_by_player"))

/**
* Throwable cakes game rule. When set to true, cakes can be thrown by right clicking, and dispensers will shoot cakes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ package opekope2.avm_staff.api.component

import com.mojang.serialization.Codec
import com.mojang.serialization.codecs.RecordCodecBuilder
import net.minecraft.component.DataComponentType
import net.minecraft.component.ComponentType
import net.minecraft.item.ItemStack
import net.minecraft.network.RegistryByteBuf
import net.minecraft.network.codec.PacketCodec

/**
* [ItemStack] wrapper to make them compatible with [DataComponentType]s.
* [ItemStack] wrapper to make them compatible with [ComponentType]s.
*
* @param item The item stored in this component. Must be [copied][ItemStack.copy] before modifying it
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import net.minecraft.entity.data.TrackedDataHandlerRegistry
import net.minecraft.nbt.NbtCompound
import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket
import net.minecraft.predicate.entity.EntityPredicates
import net.minecraft.server.network.EntityTrackerEntry
import net.minecraft.sound.SoundCategory
import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.Vec3d
Expand Down Expand Up @@ -192,7 +193,8 @@ class CakeEntity(entityType: EntityType<CakeEntity>, world: World) : Entity(enti

override fun entityDataRequiresOperator() = true

override fun createSpawnPacket() = EntitySpawnS2CPacket(this)
override fun createSpawnPacket(entityTrackerEntry: EntityTrackerEntry) =
EntitySpawnS2CPacket(this, entityTrackerEntry)

override fun onSpawnPacket(packet: EntitySpawnS2CPacket) {
super.onSpawnPacket(packet)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ abstract class StaffItem(settings: Settings) : Item(settings) {
stack[DataComponentTypes.ATTRIBUTE_MODIFIERS] = stack.itemInStaff.staffHandlerOrDefault.attributeModifiers
}

override fun getMaxUseTime(stack: ItemStack): Int {
return stack.itemInStaff.staffHandlerOrDefault.maxUseTime
override fun getMaxUseTime(stack: ItemStack, user: LivingEntity): Int {
return stack.itemInStaff.staffHandlerOrDefault.maxUseTime // TODO extend API
}

override fun use(world: World, user: PlayerEntity, hand: Hand): TypedActionResult<ItemStack> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ fun initializeNetworking() {
}

private val MODIFIABLE_LOOT_TABLES = setOf(
Identifier("chests/bastion_treasure"),
Identifier("chests/trial_chambers/reward_unique")
Identifier.ofVanilla("chests/bastion_treasure"),
Identifier.ofVanilla("chests/trial_chambers/reward_unique")
)

fun subscribeToEvents() {
Expand Down Expand Up @@ -142,13 +142,13 @@ private fun modifyLootTables(
context: LootEvent.LootTableModificationContext,
builtin: Boolean
) {
// FIXME builtin check after updating to 1.21 because Fabric detects experiments as data pack
if (!builtin) return
if (lootTable.value !in MODIFIABLE_LOOT_TABLES) return

context.addPool(
LootPool.builder().with(
LootTableEntry.builder(
RegistryKey.of(RegistryKeys.LOOT_TABLE, Identifier(MOD_ID, "add_loot_pool/${lootTable.value.path}"))
RegistryKey.of(RegistryKeys.LOOT_TABLE, Identifier.of(MOD_ID, "add_loot_pool/${lootTable.value.path}"))
)
)
)
Expand Down Expand Up @@ -191,7 +191,7 @@ fun registerClientContent() {
@Environment(EnvType.CLIENT)
fun registerSmithingTableTextures() {
StaffInfusionSmithingRecipeTextures.register(
Identifier(MOD_ID, "item/smithing_table/empty_slot_royal_staff"),
Identifier.of(MOD_ID, "item/smithing_table/empty_slot_royal_staff"),
ISmithingTemplateItemAccessor.emptySlotRedstoneDustTexture()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import kotlin.jvm.optionals.getOrNull
// ModelPredicateProviderRegistry.register is private in common project
@Environment(EnvType.CLIENT)
fun registerModelPredicateProviders(register: (Identifier, ClampedModelPredicateProvider) -> Unit) {
register(Identifier(MOD_ID, "using_item")) { stack, _, entity, _ ->
register(Identifier.of(MOD_ID, "using_item")) { stack, _, entity, _ ->
val isActiveOverride = stack[staffRendererOverrideComponentType.get()]?.isActive?.getOrNull()
when {
isActiveOverride == true -> 1f
Expand All @@ -41,10 +41,10 @@ fun registerModelPredicateProviders(register: (Identifier, ClampedModelPredicate
else -> 0f
}
}
register(Identifier(MOD_ID, "head"), matchStaffRendererPart(StaffRendererPartComponent.HEAD))
register(Identifier(MOD_ID, "item"), matchStaffRendererPart(StaffRendererPartComponent.ITEM))
register(Identifier(MOD_ID, "rod_top"), matchStaffRendererPart(StaffRendererPartComponent.ROD_TOP))
register(Identifier(MOD_ID, "rod_bottom"), matchStaffRendererPart(StaffRendererPartComponent.ROD_BOTTOM))
register(Identifier.of(MOD_ID, "head"), matchStaffRendererPart(StaffRendererPartComponent.HEAD))
register(Identifier.of(MOD_ID, "item"), matchStaffRendererPart(StaffRendererPartComponent.ITEM))
register(Identifier.of(MOD_ID, "rod_top"), matchStaffRendererPart(StaffRendererPartComponent.ROD_TOP))
register(Identifier.of(MOD_ID, "rod_bottom"), matchStaffRendererPart(StaffRendererPartComponent.ROD_BOTTOM))
}

private fun matchStaffRendererPart(part: StaffRendererPartComponent) = ClampedModelPredicateProvider { stack, _, _, _ ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal class AttackC2SPacket(val hand: Hand) : IC2SPacket {

companion object : PacketRegistrarAndReceiver<AttackC2SPacket>(
NetworkManager.c2s(),
Identifier(MOD_ID, "attack"),
Identifier.of(MOD_ID, "attack"),
::AttackC2SPacket
) {
override fun receive(packet: AttackC2SPacket, context: NetworkManager.PacketContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal class InsertItemIntoStaffC2SPacket() : IC2SPacket {

companion object : PacketRegistrarAndReceiver<InsertItemIntoStaffC2SPacket>(
NetworkManager.c2s(),
Identifier(MOD_ID, "add_item"),
Identifier.of(MOD_ID, "add_item"),
::InsertItemIntoStaffC2SPacket
) {
override fun receive(packet: InsertItemIntoStaffC2SPacket, context: NetworkManager.PacketContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal class RemoveItemFromStaffC2SPacket() : IC2SPacket {

companion object : PacketRegistrarAndReceiver<RemoveItemFromStaffC2SPacket>(
NetworkManager.c2s(),
Identifier(MOD_ID, "remove_item"),
Identifier.of(MOD_ID, "remove_item"),
::RemoveItemFromStaffC2SPacket
) {
override fun receive(packet: RemoveItemFromStaffC2SPacket, context: NetworkManager.PacketContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,15 @@ import net.minecraft.item.Item
import net.minecraft.item.ItemStack
import net.minecraft.predicate.entity.EntityPredicates
import net.minecraft.util.Hand
import net.minecraft.util.Identifier
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.minecraft.world.WorldEvents
import opekope2.avm_staff.api.staff.StaffHandler
import opekope2.avm_staff.mixin.IAnvilBlockAccessor
import opekope2.avm_staff.util.attackDamage
import opekope2.avm_staff.util.equipTime
import opekope2.avm_staff.util.itemStackInStaff
import opekope2.avm_staff.util.mutableItemStackInStaff
import opekope2.avm_staff.util.*
import kotlin.math.ceil
import kotlin.math.floor

Expand Down Expand Up @@ -136,7 +134,7 @@ internal class AnvilHandler(private val damagedItem: Item?) : StaffHandler() {
.build()

private fun anvilModifier() = EntityAttributeModifier(
"Anvil modifier", -1.0, EntityAttributeModifier.Operation.ADD_MULTIPLIED_TOTAL
Identifier.of(MOD_ID, "anvil_modifier"), -1.0, EntityAttributeModifier.Operation.ADD_MULTIPLIED_TOTAL
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ internal class CampfireHandler(
data class Properties(
val nonFlammableBlockFireChance: Double,
val flammableBlockFireChance: Double,
val attackFireSeconds: Int,
val attackFireSeconds: Float,
val flameFireTicks: Int,
val rocketThrust: Double
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ import net.minecraft.entity.ItemEntity
import net.minecraft.entity.LivingEntity
import net.minecraft.entity.attribute.EntityAttributes
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.inventory.SingleStackInventory
import net.minecraft.item.ItemStack
import net.minecraft.particle.ParticleTypes
import net.minecraft.recipe.AbstractCookingRecipe
import net.minecraft.recipe.RecipeType
import net.minecraft.recipe.input.SingleStackRecipeInput
import net.minecraft.server.world.ServerWorld
import net.minecraft.sound.SoundCategory
import net.minecraft.sound.SoundEvent
Expand Down Expand Up @@ -95,8 +95,8 @@ internal class FurnaceHandler<TRecipe : AbstractCookingRecipe>(
val stackToSmelt = itemToSmelt?.stack ?: return
if (furnaceData.serverBurnTicks < stackToSmelt.count) return

val inventory = ItemEntityInventory(itemToSmelt)
val recipe = world.recipeManager.getFirstMatch(recipeType, inventory, world).getOrNull()?.value ?: return
val recipeInput = SingleStackRecipeInput(itemToSmelt.stack)
val recipe = world.recipeManager.getFirstMatch(recipeType, recipeInput, world).getOrNull()?.value ?: return
val resultItem = recipe.getResult(world.registryManager).copyWithCount(stackToSmelt.count)

val (vx, vy, vz) = itemToSmelt.velocity
Expand Down Expand Up @@ -165,18 +165,6 @@ internal class FurnaceHandler<TRecipe : AbstractCookingRecipe>(
}
}

private class ItemEntityInventory(private val itemEntity: ItemEntity) : SingleStackInventory {
override fun getStack(): ItemStack = itemEntity.stack

override fun setStack(stack: ItemStack?) {}

override fun markDirty() {}

override fun canPlayerUse(player: PlayerEntity?) = false

override fun decreaseStack(count: Int): ItemStack = ItemStack.EMPTY
}

private companion object {
private val ITEM_DIMENSIONS = EntityType.ITEM.dimensions
private val SMELTING_VOLUME = Box(-0.5, -0.5, -0.5, 0.5, 0.5, 0.5).contract(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ internal class MagmaBlockHandler : StaffHandler() {
target: Entity,
hand: Hand
): EventResult {
target.setOnFireFor(8)
target.setOnFireFor(8f)
return EventResult.pass()
}

Expand All @@ -80,9 +80,8 @@ internal class MagmaBlockHandler : StaffHandler() {
if (shooter is PlayerEntity && shooter.isAttackCoolingDown) return

val spawnPos = EntityType.SMALL_FIREBALL.getSpawnPosition(world, shooter.approximateStaffTipPosition)
val (x, y, z) = shooter.rotationVector

world.spawnEntity(SmallFireballEntity(world, shooter, x, y, z).apply {
world.spawnEntity(SmallFireballEntity(world, shooter, shooter.rotationVector).apply {
setPosition(spawnPos)
})
world.syncWorldEvent(WorldEvents.BLAZE_SHOOTS, shooter.blockPos, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ fun registerVanillaStaffHandlers() {
CAMPFIRE.registerHandler(
CampfireHandler(
flamethrowerParticleType,
CampfireHandler.Properties(1 / 20.0, 5 / 20.0, 4, 1, 0.1)
CampfireHandler.Properties(1 / 20.0, 5 / 20.0, 4f, 1, 0.1)
)
)
SOUL_CAMPFIRE.registerHandler(
CampfireHandler(
soulFlamethrowerParticleType,
CampfireHandler.Properties(2 / 20.0, 10 / 20.0, 6, 2, 0.12)
CampfireHandler.Properties(2 / 20.0, 10 / 20.0, 6f, 2, 0.12)
)
)

Expand Down
Loading