mirror of
https://github.com/Artillex-Studios/AxMinions.git
synced 2025-02-16 01:11:23 +01:00
1.21, 1.18.2 support, possibly fix crafter, some debug messages
This commit is contained in:
parent
913efc7fde
commit
28f69805ee
@ -11,6 +11,7 @@
|
||||
<option value="$PROJECT_DIR$/api" />
|
||||
<option value="$PROJECT_DIR$/common" />
|
||||
<option value="$PROJECT_DIR$/nms" />
|
||||
<option value="$PROJECT_DIR$/nms/v1_18_R2" />
|
||||
<option value="$PROJECT_DIR$/nms/v1_19_R1" />
|
||||
<option value="$PROJECT_DIR$/nms/v1_19_R2" />
|
||||
<option value="$PROJECT_DIR$/nms/v1_19_R3" />
|
||||
@ -18,6 +19,7 @@
|
||||
<option value="$PROJECT_DIR$/nms/v1_20_R2" />
|
||||
<option value="$PROJECT_DIR$/nms/v1_20_R3" />
|
||||
<option value="$PROJECT_DIR$/nms/v1_20_R4" />
|
||||
<option value="$PROJECT_DIR$/nms/v1_21_R1" />
|
||||
</set>
|
||||
</option>
|
||||
</GradleProjectSettings>
|
||||
|
@ -20,6 +20,7 @@ repositories {
|
||||
dependencies {
|
||||
implementation project(path: ":api")
|
||||
implementation project(path: ":common")
|
||||
implementation project(path: ":nms:v1_18_R2", configuration: "reobf")
|
||||
implementation project(path: ":nms:v1_19_R1", configuration: "reobf")
|
||||
implementation project(path: ":nms:v1_19_R2", configuration: "reobf")
|
||||
implementation project(path: ":nms:v1_19_R3", configuration: "reobf")
|
||||
@ -27,6 +28,7 @@ dependencies {
|
||||
implementation project(path: ":nms:v1_20_R2", configuration: "reobf")
|
||||
implementation project(path: ":nms:v1_20_R3", configuration: "reobf")
|
||||
implementation project(path: ":nms:v1_20_R4", configuration: "reobf")
|
||||
implementation project(path: ":nms:v1_21_R1", configuration: "reobf")
|
||||
}
|
||||
|
||||
allprojects {
|
||||
@ -136,7 +138,7 @@ allprojects {
|
||||
compileOnly 'com.github.LoneDev6:api-itemsadder:3.6.1'
|
||||
compileOnly 'com.palmergames.bukkit.towny:towny:0.100.1.0'
|
||||
implementation platform('com.intellectualsites.bom:bom-newest:1.35')
|
||||
implementation("com.artillexstudios.axapi:axapi:1.4.190:all")
|
||||
implementation("com.artillexstudios.axapi:axapi:1.4.259:all")
|
||||
implementation("com.zaxxer:HikariCP:5.1.0")
|
||||
implementation("org.bstats:bstats-bukkit:3.0.2")
|
||||
compileOnly 'org.black_ixx:playerpoints:3.2.6'
|
||||
|
@ -9,6 +9,7 @@ import com.artillexstudios.axminions.api.warnings.Warnings
|
||||
import com.artillexstudios.axminions.nms.NMSHandler
|
||||
import java.util.concurrent.ThreadLocalRandom
|
||||
import org.bukkit.entity.Item
|
||||
import org.bukkit.entity.LivingEntity
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.Listener
|
||||
@ -54,6 +55,14 @@ class MinionDamageListener : Listener {
|
||||
if (event.damager.uniqueId == NMSHandler.get().getAnimalUUID() && event.entity is Player) {
|
||||
event.isCancelled = true
|
||||
event.damage = 0.0
|
||||
return
|
||||
}
|
||||
|
||||
val entity = event.entity
|
||||
if (entity is LivingEntity) {
|
||||
if (event.damager.uniqueId == NMSHandler.get().getAnimalUUID() && event.finalDamage > entity.health) {
|
||||
MinionKillEntityEvent(NMSHandler.get().getMinion() ?: return, entity)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,15 +1,16 @@
|
||||
package com.artillexstudios.axminions.minions
|
||||
|
||||
import com.artillexstudios.axapi.entity.PacketEntityFactory
|
||||
import com.artillexstudios.axapi.entity.impl.PacketArmorStand
|
||||
import com.artillexstudios.axapi.entity.impl.PacketEntity
|
||||
import com.artillexstudios.axapi.events.PacketEntityInteractEvent
|
||||
import com.artillexstudios.axapi.hologram.Hologram
|
||||
import com.artillexstudios.axapi.hologram.HologramLine
|
||||
import com.artillexstudios.axapi.items.WrappedItemStack
|
||||
import com.artillexstudios.axapi.nms.NMSHandlers
|
||||
import com.artillexstudios.axapi.packetentity.PacketEntity
|
||||
import com.artillexstudios.axapi.packetentity.meta.entity.ArmorStandMeta
|
||||
import com.artillexstudios.axapi.packetentity.meta.serializer.Accessors
|
||||
import com.artillexstudios.axapi.scheduler.Scheduler
|
||||
import com.artillexstudios.axapi.utils.EquipmentSlot
|
||||
import com.artillexstudios.axapi.utils.ItemBuilder
|
||||
import com.artillexstudios.axapi.utils.RotationType
|
||||
import com.artillexstudios.axapi.utils.StringUtils
|
||||
import com.artillexstudios.axminions.AxMinionsPlugin
|
||||
import com.artillexstudios.axminions.api.AxMinionsAPI
|
||||
@ -73,7 +74,7 @@ class Minion(
|
||||
}
|
||||
}
|
||||
|
||||
private lateinit var entity: PacketArmorStand
|
||||
private lateinit var entity: PacketEntity
|
||||
private var nextAction = 0
|
||||
private var range = 0.0
|
||||
|
||||
@ -105,14 +106,16 @@ class Minion(
|
||||
override fun spawn() {
|
||||
location.x += 0.5
|
||||
location.z += 0.5
|
||||
entity = PacketEntityFactory.get().spawnEntity(location, EntityType.ARMOR_STAND) as PacketArmorStand
|
||||
entity.setHasBasePlate(false)
|
||||
entity.setSmall(true)
|
||||
entity.setHasArms(true)
|
||||
entity = NMSHandlers.getNmsHandler().createEntity(EntityType.ARMOR_STAND, location)
|
||||
val meta = entity.meta() as ArmorStandMeta
|
||||
|
||||
entity.onClick { event ->
|
||||
meta.setNoBasePlate(true)
|
||||
meta.small(true)
|
||||
meta.showArms(true)
|
||||
|
||||
entity.onInteract { event ->
|
||||
if (broken.get()) {
|
||||
return@onClick
|
||||
return@onInteract
|
||||
}
|
||||
|
||||
// We want to do this, so we don't accidentally cause dupes...
|
||||
@ -124,7 +127,7 @@ class Minion(
|
||||
Scheduler.get().runAt(location) {
|
||||
val canBuildAt = AxMinionsPlugin.integrations.getProtectionIntegration().canBuildAt(
|
||||
event.player,
|
||||
event.packetEntity.location
|
||||
event.packetEntity.location()
|
||||
)
|
||||
|
||||
if (event.isAttack) {
|
||||
@ -145,11 +148,13 @@ class Minion(
|
||||
}
|
||||
}
|
||||
|
||||
entity.name = StringUtils.format(
|
||||
type.getConfig().get("entity.name"),
|
||||
Placeholder.unparsed("owner", owner.name ?: "???"),
|
||||
Placeholder.unparsed("level", level.toString()),
|
||||
Placeholder.parsed("level_color", Messages.LEVEL_COLOR(level))
|
||||
meta.name(
|
||||
StringUtils.format(
|
||||
type.getConfig().get("entity.name"),
|
||||
Placeholder.unparsed("owner", owner.name ?: "???"),
|
||||
Placeholder.unparsed("level", level.toString()),
|
||||
Placeholder.parsed("level_color", Messages.LEVEL_COLOR(level))
|
||||
)
|
||||
)
|
||||
|
||||
if (Config.DEBUG()) {
|
||||
@ -436,7 +441,7 @@ class Minion(
|
||||
if (this.tool?.type == Material.AIR) {
|
||||
entity.setItem(EquipmentSlot.MAIN_HAND, null)
|
||||
} else {
|
||||
entity.setItem(EquipmentSlot.MAIN_HAND, tool.clone())
|
||||
entity.setItem(EquipmentSlot.MAIN_HAND, WrappedItemStack.wrap(tool.clone()))
|
||||
}
|
||||
|
||||
if (save) {
|
||||
@ -459,11 +464,14 @@ class Minion(
|
||||
updateArmour()
|
||||
updateInventories()
|
||||
|
||||
entity.name = StringUtils.format(
|
||||
type.getConfig().get("entity.name"),
|
||||
Placeholder.unparsed("owner", owner.name ?: "???"),
|
||||
Placeholder.unparsed("level", level.toString()),
|
||||
Placeholder.parsed("level_color", Messages.LEVEL_COLOR(level))
|
||||
val meta = entity.meta()
|
||||
meta.name(
|
||||
StringUtils.format(
|
||||
type.getConfig().get("entity.name"),
|
||||
Placeholder.unparsed("owner", owner.name ?: "???"),
|
||||
Placeholder.unparsed("level", level.toString()),
|
||||
Placeholder.parsed("level_color", Messages.LEVEL_COLOR(level))
|
||||
)
|
||||
)
|
||||
|
||||
AxMinionsPlugin.dataQueue.submit {
|
||||
@ -502,7 +510,8 @@ class Minion(
|
||||
override fun animate() {
|
||||
if (armTick >= 2) return
|
||||
|
||||
entity.setRotation(RotationType.RIGHT_ARM, EulerAngle(-2 + armTick, 0.0, 0.0))
|
||||
val meta = entity.meta() as ArmorStandMeta
|
||||
meta.metadata().set(Accessors.RIGHT_ARM_ROTATION, EulerAngle(-2 + armTick, 0.0, 0.0))
|
||||
armTick += 0.2
|
||||
}
|
||||
|
||||
@ -599,19 +608,19 @@ class Minion(
|
||||
setTool(this.tool ?: ItemStack(Material.AIR), false)
|
||||
|
||||
type.getSection("items.helmet", level)?.let {
|
||||
entity.setItem(EquipmentSlot.HELMET, ItemBuilder(it).get())
|
||||
entity.setItem(EquipmentSlot.HELMET, WrappedItemStack.wrap(ItemBuilder(it).get()))
|
||||
}
|
||||
|
||||
type.getSection("items.chestplate", level)?.let {
|
||||
entity.setItem(EquipmentSlot.CHEST_PLATE, ItemBuilder(it).get())
|
||||
entity.setItem(EquipmentSlot.CHEST_PLATE, WrappedItemStack.wrap(ItemBuilder(it).get()))
|
||||
}
|
||||
|
||||
type.getSection("items.leggings", level)?.let {
|
||||
entity.setItem(EquipmentSlot.LEGGINGS, ItemBuilder(it).get())
|
||||
entity.setItem(EquipmentSlot.LEGGINGS, WrappedItemStack.wrap(ItemBuilder(it).get()))
|
||||
}
|
||||
|
||||
type.getSection("items.boots", level)?.let {
|
||||
entity.setItem(EquipmentSlot.BOOTS, ItemBuilder(it).get())
|
||||
entity.setItem(EquipmentSlot.BOOTS, WrappedItemStack.wrap(ItemBuilder(it).get()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -693,7 +702,9 @@ class Minion(
|
||||
return
|
||||
}
|
||||
|
||||
if (!item.type.isAir && (item.itemMeta as? Damageable ?: return).damage + 1 > item.type.maxDurability) {
|
||||
if (!item.type.isAir && (item.itemMeta as? Damageable
|
||||
?: return).damage + 1 > item.type.maxDurability
|
||||
) {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
@ -710,7 +721,9 @@ class Minion(
|
||||
return
|
||||
}
|
||||
|
||||
if (!item.type.isAir && (item.itemMeta as? Damageable ?: return).damage + 1 > item.type.maxDurability) {
|
||||
if (!item.type.isAir && (item.itemMeta as? Damageable
|
||||
?: return).damage + 1 > item.type.maxDurability
|
||||
) {
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -751,7 +764,9 @@ class Minion(
|
||||
return true
|
||||
}
|
||||
|
||||
if (!item.type.isAir && (item.itemMeta as? Damageable ?: return false).damage + 1 > item.type.maxDurability) {
|
||||
if (!item.type.isAir && (item.itemMeta as? Damageable
|
||||
?: return false).damage + 1 > item.type.maxDurability
|
||||
) {
|
||||
return canUseTool()
|
||||
}
|
||||
} else {
|
||||
@ -768,7 +783,9 @@ class Minion(
|
||||
return true
|
||||
}
|
||||
|
||||
if (!item.type.isAir && (item.itemMeta as? Damageable ?: return false).damage + 1 > item.type.maxDurability) {
|
||||
if (!item.type.isAir && (item.itemMeta as? Damageable
|
||||
?: return false).damage + 1 > item.type.maxDurability
|
||||
) {
|
||||
return canUseTool()
|
||||
}
|
||||
}
|
||||
|
@ -103,6 +103,7 @@ class CrafterMinionType : MinionType("crafter", AxMinionsPlugin.INSTANCE.getReso
|
||||
}
|
||||
|
||||
doCraftShapeless(inv, recipe, contents)
|
||||
minion.setActions(minion.getActionAmount() + 1)
|
||||
|
||||
recipeIterator = shapeless.iterator()
|
||||
}
|
||||
@ -119,33 +120,27 @@ class CrafterMinionType : MinionType("crafter", AxMinionsPlugin.INSTANCE.getReso
|
||||
}
|
||||
|
||||
doCraftShaped(inv, recipe, contents)
|
||||
minion.setActions(minion.getActionAmount() + 1)
|
||||
|
||||
shapedIterator = shaped.iterator()
|
||||
}
|
||||
}
|
||||
|
||||
private fun canCraftShapeless(recipe: ShapelessRecipe, contents: HashMap<ItemStack, Int>): Boolean {
|
||||
val clone = contents.clone() as HashMap<ItemStack, Int>
|
||||
for (recipeChoice in recipe.choiceList) {
|
||||
var hasEnough = false
|
||||
if (recipeChoice == null) continue
|
||||
var amount = 0
|
||||
|
||||
val iterator = clone.entries.iterator()
|
||||
val iterator = contents.entries.iterator()
|
||||
while (iterator.hasNext()) {
|
||||
val next = iterator.next()
|
||||
|
||||
if (next.key.isSimilar(recipeChoice.itemStack) && next.value >= recipeChoice.itemStack.amount) {
|
||||
hasEnough = true
|
||||
val amount = next.value - recipeChoice.itemStack.amount
|
||||
if (amount == 0) {
|
||||
iterator.remove()
|
||||
} else {
|
||||
next.setValue(amount)
|
||||
}
|
||||
break
|
||||
if (recipeChoice.test(next.key)) {
|
||||
amount += next.value
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasEnough) {
|
||||
if (amount < recipeChoice.itemStack.amount) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@ -154,28 +149,20 @@ class CrafterMinionType : MinionType("crafter", AxMinionsPlugin.INSTANCE.getReso
|
||||
}
|
||||
|
||||
private fun canCraftShaped(recipe: ShapedRecipe, contents: HashMap<ItemStack, Int>): Boolean {
|
||||
val clone = contents.clone() as HashMap<ItemStack, Int>
|
||||
for (recipeChoice in recipe.choiceMap.values) {
|
||||
if (recipeChoice == null) continue
|
||||
var hasEnough = false
|
||||
for (recipeChoice in recipe.choiceMap) {
|
||||
if (recipeChoice.value == null) continue
|
||||
var amount = 0
|
||||
|
||||
val iterator = clone.entries.iterator()
|
||||
val iterator = contents.entries.iterator()
|
||||
while (iterator.hasNext()) {
|
||||
val next = iterator.next()
|
||||
|
||||
if (recipeChoice.test(next.key)) {
|
||||
hasEnough = true
|
||||
val amount = next.value - recipeChoice.itemStack.amount
|
||||
if (amount == 0) {
|
||||
iterator.remove()
|
||||
} else {
|
||||
next.setValue(amount)
|
||||
}
|
||||
break
|
||||
if (recipeChoice.value.test(next.key)) {
|
||||
amount += next.value
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasEnough) {
|
||||
if (amount < recipeChoice.value.itemStack.amount) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@ -186,17 +173,21 @@ class CrafterMinionType : MinionType("crafter", AxMinionsPlugin.INSTANCE.getReso
|
||||
private fun doCraftShapeless(inventory: Inventory, recipe: ShapelessRecipe, contents: HashMap<ItemStack, Int>) {
|
||||
for (recipeChoice in recipe.choiceList) {
|
||||
if (recipeChoice == null) continue
|
||||
val item = recipeChoice.itemStack.clone()
|
||||
|
||||
inventory.removeItem(item)
|
||||
for (content in inventory.contents) {
|
||||
if (recipeChoice.test(content)) {
|
||||
content.amount -= recipeChoice.itemStack.amount
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
val iterator = contents.entries.iterator()
|
||||
while (iterator.hasNext()) {
|
||||
val next = iterator.next()
|
||||
|
||||
if (recipeChoice.test(next.key)) {
|
||||
val amount = next.value - item.amount
|
||||
if (amount == 0) {
|
||||
val amount = next.value - recipeChoice.itemStack.amount
|
||||
if (amount <= 0) {
|
||||
iterator.remove()
|
||||
} else {
|
||||
next.setValue(amount)
|
||||
@ -222,32 +213,28 @@ class CrafterMinionType : MinionType("crafter", AxMinionsPlugin.INSTANCE.getReso
|
||||
}
|
||||
|
||||
private fun doCraftShaped(inventory: Inventory, recipe: ShapedRecipe, contents: HashMap<ItemStack, Int>) {
|
||||
for (recipeChoice in recipe.choiceMap.values) {
|
||||
if (recipeChoice == null) continue
|
||||
val item = recipeChoice.itemStack.clone()
|
||||
for (recipeChoice in recipe.choiceMap) {
|
||||
if (recipeChoice.value == null) continue
|
||||
|
||||
for (content in inventory.contents) {
|
||||
if (content == null || content.type.isAir) continue
|
||||
if (recipeChoice.test(content)) {
|
||||
val clone = content.clone()
|
||||
clone.amount = item.amount
|
||||
if (recipeChoice.value.test(content)) {
|
||||
content.amount -= recipeChoice.value.itemStack.amount
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
inventory.removeItem(clone)
|
||||
val iterator = contents.entries.iterator()
|
||||
while (iterator.hasNext()) {
|
||||
val next = iterator.next()
|
||||
|
||||
val iterator = contents.entries.iterator()
|
||||
while (iterator.hasNext()) {
|
||||
val next = iterator.next()
|
||||
|
||||
if (next.key.isSimilar(clone)) {
|
||||
val amount = next.value - item.amount
|
||||
if (amount == 0) {
|
||||
iterator.remove()
|
||||
} else {
|
||||
next.setValue(amount)
|
||||
}
|
||||
break
|
||||
}
|
||||
if (recipeChoice.value.test(next.key)) {
|
||||
val amount = next.value - recipeChoice.value.itemStack.amount
|
||||
if (amount <= 0) {
|
||||
iterator.remove()
|
||||
} else {
|
||||
next.setValue(amount)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -77,32 +77,32 @@ class LumberMinionType : MinionType("lumber", AxMinionsPlugin.INSTANCE.getResour
|
||||
}
|
||||
|
||||
private fun getSaplingType(material: Material): Material {
|
||||
return when (material) {
|
||||
Material.DARK_OAK_LOG -> {
|
||||
return when (material.name) {
|
||||
"DARK_OAK_LOG" -> {
|
||||
Material.DARK_OAK_SAPLING
|
||||
}
|
||||
|
||||
Material.BIRCH_LOG -> {
|
||||
"BIRCH_LOG" -> {
|
||||
Material.BIRCH_SAPLING
|
||||
}
|
||||
|
||||
Material.ACACIA_LOG -> {
|
||||
"ACACIA_LOG" -> {
|
||||
Material.ACACIA_SAPLING
|
||||
}
|
||||
|
||||
Material.JUNGLE_LOG -> {
|
||||
"JUNGLE_LOG" -> {
|
||||
Material.JUNGLE_SAPLING
|
||||
}
|
||||
|
||||
Material.SPRUCE_LOG -> {
|
||||
"SPRUCE_LOG" -> {
|
||||
Material.SPRUCE_SAPLING
|
||||
}
|
||||
|
||||
Material.MANGROVE_LOG -> {
|
||||
"MANGROVE_LOG" -> {
|
||||
Material.MANGROVE_PROPAGULE
|
||||
}
|
||||
|
||||
Material.CHERRY_LOG -> {
|
||||
"CHERRY_LOG" -> {
|
||||
Material.CHERRY_SAPLING
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import com.artillexstudios.axapi.scheduler.Scheduler
|
||||
import com.artillexstudios.axapi.scheduler.impl.FoliaScheduler
|
||||
import com.artillexstudios.axminions.AxMinionsPlugin
|
||||
import com.artillexstudios.axminions.api.AxMinionsAPI
|
||||
import com.artillexstudios.axminions.api.config.Config
|
||||
import com.artillexstudios.axminions.api.minions.Minion
|
||||
import com.artillexstudios.axminions.api.minions.miniontype.MinionType
|
||||
import com.artillexstudios.axminions.api.utils.LocationUtils
|
||||
@ -99,7 +100,9 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
|
||||
val possible = gen.isBlockPossibleToMine(location)
|
||||
|
||||
if (possible) {
|
||||
minion.addToContainerOrDrop(gen.generator.drawGeneratedObject().customDrops?.item ?: return@fastFor)
|
||||
minion.addToContainerOrDrop(
|
||||
gen.generator.drawGeneratedObject().customDrops?.item ?: return@fastFor
|
||||
)
|
||||
gen.scheduleGeneratorRegeneration()
|
||||
return@fastFor
|
||||
} else {
|
||||
@ -145,7 +148,9 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
|
||||
val possible = gen.isBlockPossibleToMine(location)
|
||||
|
||||
if (possible) {
|
||||
minion.addToContainerOrDrop(gen.generator.drawGeneratedObject().customDrops?.item ?: return@fastFor)
|
||||
minion.addToContainerOrDrop(
|
||||
gen.generator.drawGeneratedObject().customDrops?.item ?: return@fastFor
|
||||
)
|
||||
gen.scheduleGeneratorRegeneration()
|
||||
return@fastFor
|
||||
} else {
|
||||
@ -186,7 +191,9 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
|
||||
val possible = gen.isBlockPossibleToMine(location)
|
||||
|
||||
if (possible) {
|
||||
minion.addToContainerOrDrop(gen.generator.drawGeneratedObject().customDrops?.item ?: return@fastFor)
|
||||
minion.addToContainerOrDrop(
|
||||
gen.generator.drawGeneratedObject().customDrops?.item ?: return@fastFor
|
||||
)
|
||||
gen.scheduleGeneratorRegeneration()
|
||||
return@fastFor
|
||||
} else {
|
||||
@ -222,18 +229,33 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
|
||||
faces.fastFor {
|
||||
LocationUtils.getAllBlocksFacing(minion.getLocation(), minion.getRange(), it).fastFor { location ->
|
||||
if (AxMinionsPlugin.integrations.kGeneratorsIntegration) {
|
||||
if (Config.DEBUG()) {
|
||||
println("KGenerators integration!")
|
||||
}
|
||||
val gen = Main.getPlacedGenerators().getLoaded(location)
|
||||
if (gen != null) {
|
||||
if (Config.DEBUG()) {
|
||||
println("Gen not null")
|
||||
}
|
||||
val possible = gen.isBlockPossibleToMine(location)
|
||||
|
||||
if (possible) {
|
||||
minion.addToContainerOrDrop(gen.generator.drawGeneratedObject().customDrops?.item ?: return@fastFor)
|
||||
if (Config.DEBUG()) {
|
||||
println("Not possible")
|
||||
}
|
||||
minion.addToContainerOrDrop(
|
||||
gen.generator.drawGeneratedObject().customDrops?.item ?: return@fastFor
|
||||
)
|
||||
gen.scheduleGeneratorRegeneration()
|
||||
return@fastFor
|
||||
} else {
|
||||
return@fastFor
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (Config.DEBUG()) {
|
||||
println("Else")
|
||||
}
|
||||
}
|
||||
|
||||
val canBreak = if (generatorMode) {
|
||||
@ -268,7 +290,9 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
|
||||
val possible = gen.isBlockPossibleToMine(location)
|
||||
|
||||
if (possible) {
|
||||
minion.addToContainerOrDrop(gen.generator.drawGeneratedObject().customDrops?.item ?: return@fastFor)
|
||||
minion.addToContainerOrDrop(
|
||||
gen.generator.drawGeneratedObject().customDrops?.item ?: return@fastFor
|
||||
)
|
||||
gen.scheduleGeneratorRegeneration()
|
||||
return@fastFor
|
||||
} else {
|
||||
|
@ -79,7 +79,7 @@ class SellerMinionType : MinionType("seller", AxMinionsPlugin.INSTANCE.getResour
|
||||
continue
|
||||
}
|
||||
|
||||
minion.setActions(minion.getActionAmount() + 1)
|
||||
minion.setActions(minion.getActionAmount() + it.amount)
|
||||
minion.damageTool()
|
||||
minion.setStorage(minion.getStorage() + price)
|
||||
it.amount = 0
|
||||
|
@ -26,5 +26,7 @@ interface NMSHandler {
|
||||
|
||||
fun getAnimalUUID(): UUID
|
||||
|
||||
fun getMinion(): Minion?
|
||||
|
||||
fun getExp(block: Block, itemStack: ItemStack): Int
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev") version "1.7.0" apply false
|
||||
id("io.papermc.paperweight.userdev") version "1.7.1" apply false
|
||||
}
|
||||
|
||||
group = "com.artillexstudios.axminions"
|
||||
|
21
nms/v1_18_R2/build.gradle
Normal file
21
nms/v1_18_R2/build.gradle
Normal file
@ -0,0 +1,21 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
}
|
||||
|
||||
group = 'com.artillexstudios.axminions.nms'
|
||||
version = '1.0-SNAPSHOT'
|
||||
|
||||
dependencies {
|
||||
paperweight.paperDevBundle("1.18.2-R0.1-SNAPSHOT")
|
||||
pluginRemapper("net.fabricmc:tiny-remapper:0.10.3:fat")
|
||||
}
|
||||
|
||||
tasks {
|
||||
build {
|
||||
dependsOn(reobfJar)
|
||||
}
|
||||
|
||||
reobfJar {
|
||||
mustRunAfter(shadowJar)
|
||||
}
|
||||
}
|
@ -0,0 +1,236 @@
|
||||
package com.artillexstudios.axminions.nms.v1_18_R2
|
||||
|
||||
import com.artillexstudios.axminions.api.events.PreMinionDamageEntityEvent
|
||||
import com.artillexstudios.axminions.api.minions.Minion
|
||||
import net.minecraft.core.particles.ParticleTypes
|
||||
import net.minecraft.server.level.ServerLevel
|
||||
import net.minecraft.util.Mth
|
||||
import net.minecraft.world.damagesource.DamageSource
|
||||
import net.minecraft.world.effect.MobEffectInstance
|
||||
import net.minecraft.world.effect.MobEffects
|
||||
import net.minecraft.world.entity.EntityType
|
||||
import net.minecraft.world.entity.EquipmentSlot
|
||||
import net.minecraft.world.entity.LivingEntity
|
||||
import net.minecraft.world.entity.MobType
|
||||
import net.minecraft.world.entity.animal.Fox
|
||||
import net.minecraft.world.entity.decoration.ArmorStand
|
||||
import net.minecraft.world.item.AxeItem
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import net.minecraft.world.item.SwordItem
|
||||
import net.minecraft.world.item.TridentItem
|
||||
import net.minecraft.world.item.enchantment.EnchantmentHelper
|
||||
import net.minecraft.world.item.enchantment.SweepingEdgeEnchantment
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.craftbukkit.v1_18_R2.CraftWorld
|
||||
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity
|
||||
import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack
|
||||
import org.bukkit.enchantments.Enchantment
|
||||
import org.bukkit.entity.Entity
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.entity.EntityPotionEffectEvent
|
||||
import java.util.*
|
||||
|
||||
object DamageHandler {
|
||||
private var DUMMY_ENTITY = Fox(EntityType.FOX, (Bukkit.getWorlds().get(0) as CraftWorld).handle)
|
||||
private var minion: Minion? = null
|
||||
|
||||
fun getUUID(): UUID {
|
||||
return DUMMY_ENTITY.uuid
|
||||
}
|
||||
|
||||
fun getMinion(): Minion? {
|
||||
return minion
|
||||
}
|
||||
|
||||
fun damage(source: Minion, entity: Entity) {
|
||||
val nmsEntity = (entity as CraftEntity).handle
|
||||
|
||||
synchronized(DUMMY_ENTITY) {
|
||||
this.minion = source
|
||||
var f = 1
|
||||
|
||||
val nmsItem: ItemStack
|
||||
if (source.getTool() == null) {
|
||||
nmsItem = ItemStack.EMPTY
|
||||
} else {
|
||||
nmsItem = CraftItemStack.asNMSCopy(source.getTool())
|
||||
|
||||
if (nmsItem.item is SwordItem) {
|
||||
f = (f + (nmsItem.item as SwordItem).damage).toInt()
|
||||
}
|
||||
|
||||
if (nmsItem.item is AxeItem) {
|
||||
f = (f + (nmsItem.item as AxeItem).attackDamage).toInt()
|
||||
}
|
||||
|
||||
if (nmsItem.item is TridentItem) {
|
||||
f = (f + TridentItem.BASE_DAMAGE).toInt()
|
||||
}
|
||||
}
|
||||
|
||||
DUMMY_ENTITY.setItemSlot(EquipmentSlot.MAINHAND, nmsItem)
|
||||
|
||||
if (!nmsEntity.isAttackable) return
|
||||
val f2 = 1.0f
|
||||
|
||||
var f1 = if (nmsEntity is LivingEntity) {
|
||||
EnchantmentHelper.getDamageBonus(nmsItem, (nmsEntity).mobType)
|
||||
} else {
|
||||
EnchantmentHelper.getDamageBonus(nmsItem, MobType.UNDEFINED)
|
||||
}
|
||||
|
||||
f = (f * (0.2f + f2 * f2 * 0.8f)).toInt()
|
||||
f1 *= f2
|
||||
|
||||
if (f > 0.0f || f1 > 0.0f) {
|
||||
var flag3 = false
|
||||
val b0: Byte = 0
|
||||
val i = b0 + (source.getTool()?.getEnchantmentLevel(Enchantment.KNOCKBACK) ?: 0)
|
||||
|
||||
f = (f * 1.5f).toInt()
|
||||
f = (f + f1).toInt()
|
||||
|
||||
if (nmsItem.item is SwordItem) {
|
||||
flag3 = true
|
||||
}
|
||||
|
||||
var f3 = 0.0f
|
||||
var flag4 = false
|
||||
val j = (source.getTool()?.getEnchantmentLevel(Enchantment.FIRE_ASPECT) ?: 0)
|
||||
|
||||
if (nmsEntity is LivingEntity) {
|
||||
f3 = nmsEntity.health
|
||||
if (j > 0 && !nmsEntity.isOnFire()) {
|
||||
flag4 = true
|
||||
nmsEntity.setSecondsOnFire(1, false)
|
||||
}
|
||||
}
|
||||
|
||||
val event = PreMinionDamageEntityEvent(source, entity as org.bukkit.entity.LivingEntity, f.toDouble())
|
||||
Bukkit.getPluginManager().callEvent(event)
|
||||
if (event.isCancelled) {
|
||||
return
|
||||
}
|
||||
|
||||
val flag5 = nmsEntity.hurt(DamageSource.mobAttack(DUMMY_ENTITY), f.toFloat())
|
||||
|
||||
if (flag5) {
|
||||
if (i > 0) {
|
||||
if (nmsEntity is LivingEntity) {
|
||||
(nmsEntity).knockback(
|
||||
(i.toFloat() * 0.5f).toDouble(),
|
||||
Mth.sin(source.getLocation().yaw * 0.017453292f).toDouble(),
|
||||
(-Mth.cos(source.getLocation().yaw * 0.017453292f)).toDouble()
|
||||
)
|
||||
} else {
|
||||
nmsEntity.push(
|
||||
(-Mth.sin(source.getLocation().yaw * 0.017453292f) * i.toFloat() * 0.5f).toDouble(),
|
||||
0.1,
|
||||
(Mth.cos(source.getLocation().yaw * 0.017453292f) * i.toFloat() * 0.5f).toDouble()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (flag3) {
|
||||
val sweep = source.getTool()?.getEnchantmentLevel(Enchantment.SWEEPING_EDGE) ?: 0
|
||||
val f4 =
|
||||
1.0f + if (sweep > 0) SweepingEdgeEnchantment.getSweepingDamageRatio(sweep) else 0.0f * f
|
||||
val list: List<LivingEntity> = (source.getLocation().world as CraftWorld).handle
|
||||
.getEntitiesOfClass(LivingEntity::class.java, nmsEntity.boundingBox.inflate(1.0, 0.25, 1.0))
|
||||
.filter { it !is Player }
|
||||
val iterator: Iterator<*> = list.iterator()
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
val entityliving: LivingEntity = iterator.next() as LivingEntity
|
||||
|
||||
if ((entityliving !is ArmorStand || !(entityliving).isMarker) && source.getLocation()
|
||||
.distanceSquared(
|
||||
(entity as Entity).location
|
||||
) < 9.0
|
||||
) {
|
||||
val damageEvent = PreMinionDamageEntityEvent(
|
||||
source,
|
||||
entityliving.bukkitEntity as org.bukkit.entity.LivingEntity,
|
||||
f4.toDouble()
|
||||
)
|
||||
Bukkit.getPluginManager().callEvent(damageEvent)
|
||||
if (event.isCancelled) {
|
||||
return
|
||||
}
|
||||
|
||||
// CraftBukkit start - Only apply knockback if the damage hits
|
||||
if (entityliving.hurt(DamageSource.mobAttack(DUMMY_ENTITY), f4)) {
|
||||
entityliving.knockback(
|
||||
0.4000000059604645,
|
||||
Mth.sin(source.getLocation().yaw * 0.017453292f).toDouble(),
|
||||
(-Mth.cos(source.getLocation().yaw * 0.017453292f)).toDouble()
|
||||
)
|
||||
}
|
||||
// CraftBukkit end
|
||||
}
|
||||
}
|
||||
|
||||
val d0 = -Mth.sin(source.getLocation().yaw * 0.017453292f).toDouble()
|
||||
val d1 = Mth.cos(source.getLocation().yaw * 0.017453292f).toDouble()
|
||||
|
||||
if ((source.getLocation().world as CraftWorld).handle is ServerLevel) {
|
||||
((source.getLocation().world as CraftWorld).handle as ServerLevel).sendParticles(
|
||||
ParticleTypes.SWEEP_ATTACK,
|
||||
source.getLocation().x + d0,
|
||||
source.getLocation().y + 0.5,
|
||||
source.getLocation().z + d1,
|
||||
0,
|
||||
d0,
|
||||
0.0,
|
||||
d1,
|
||||
0.0
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
val baneOfArthropods = source.getTool()?.getEnchantmentLevel(Enchantment.DAMAGE_ARTHROPODS) ?: 0
|
||||
if (nmsEntity is LivingEntity) {
|
||||
if (baneOfArthropods > 0 && (nmsEntity.mobType === MobType.ARTHROPOD)) {
|
||||
val p: Int = 20 + nmsEntity.random.nextInt(10 * baneOfArthropods)
|
||||
nmsEntity.addEffect(
|
||||
MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, p, 3),
|
||||
EntityPotionEffectEvent.Cause.ATTACK
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (nmsEntity is LivingEntity) {
|
||||
val f5: Float = f3 - nmsEntity.health
|
||||
|
||||
if (j > 0) {
|
||||
nmsEntity.setSecondsOnFire(j * 4, false)
|
||||
}
|
||||
|
||||
if ((source.getLocation().world as CraftWorld).handle is ServerLevel && f5 > 2.0f) {
|
||||
val k = (f5.toDouble() * 0.5).toInt()
|
||||
|
||||
((source.getLocation().world as CraftWorld).handle).sendParticles(
|
||||
ParticleTypes.DAMAGE_INDICATOR,
|
||||
nmsEntity.getX(),
|
||||
nmsEntity.getY(0.5),
|
||||
nmsEntity.getZ(),
|
||||
k,
|
||||
0.1,
|
||||
0.0,
|
||||
0.1,
|
||||
0.2
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (flag4) {
|
||||
nmsEntity.clearFire()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.minion = null
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.artillexstudios.axminions.nms.v1_18_R2
|
||||
|
||||
import com.artillexstudios.axminions.api.minions.Minion
|
||||
import net.minecraft.server.MinecraftServer
|
||||
import net.minecraft.world.level.storage.loot.BuiltInLootTables
|
||||
import net.minecraft.world.level.storage.loot.LootContext
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams
|
||||
import net.minecraft.world.phys.Vec3
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.craftbukkit.v1_18_R2.CraftWorld
|
||||
import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
object LootHandler {
|
||||
|
||||
fun generateFishingLoot(minion: Minion, waterLocation: Location): List<ItemStack> {
|
||||
val nmsItem: net.minecraft.world.item.ItemStack = if (minion.getTool() == null) {
|
||||
net.minecraft.world.item.ItemStack.EMPTY
|
||||
} else {
|
||||
CraftItemStack.asNMSCopy(minion.getTool())
|
||||
}
|
||||
|
||||
val level = (minion.getLocation().world as CraftWorld).handle
|
||||
|
||||
val lootparams = LootContext.Builder(level).withParameter(
|
||||
LootContextParams.ORIGIN, Vec3(waterLocation.x, waterLocation.y, waterLocation.z)
|
||||
).withParameter(LootContextParams.TOOL, nmsItem).withOptionalParameter(LootContextParams.THIS_ENTITY, null)
|
||||
.create(LootContextParamSets.FISHING)
|
||||
|
||||
val lootTable = MinecraftServer.getServer().lootTables.get(BuiltInLootTables.FISHING)
|
||||
|
||||
return lootTable.getRandomItems(lootparams).stream().map { original: net.minecraft.world.item.ItemStack? ->
|
||||
CraftItemStack.asBukkitCopy(
|
||||
original
|
||||
)
|
||||
}.toList()
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package com.artillexstudios.axminions.nms.v1_18_R2
|
||||
|
||||
import com.artillexstudios.axminions.api.minions.Minion
|
||||
import com.artillexstudios.axminions.nms.NMSHandler
|
||||
import java.util.UUID
|
||||
import net.minecraft.core.BlockPos
|
||||
import net.minecraft.world.entity.MobCategory
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.block.Block
|
||||
import org.bukkit.craftbukkit.v1_18_R2.block.CraftBlock
|
||||
import org.bukkit.craftbukkit.v1_18_R2.block.CraftBlockState
|
||||
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity
|
||||
import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack
|
||||
import org.bukkit.entity.Entity
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
class NMSHandler : NMSHandler {
|
||||
|
||||
override fun attack(source: Minion, target: Entity) {
|
||||
DamageHandler.damage(source, target)
|
||||
}
|
||||
|
||||
override fun generateRandomFishingLoot(minion: Minion, waterLocation: Location): List<ItemStack> {
|
||||
return LootHandler.generateFishingLoot(minion, waterLocation)
|
||||
}
|
||||
|
||||
override fun isAnimal(entity: Entity): Boolean {
|
||||
return (entity as CraftEntity).handle.type.category == MobCategory.CREATURE
|
||||
}
|
||||
|
||||
override fun getAnimalUUID(): UUID {
|
||||
return DamageHandler.getUUID()
|
||||
}
|
||||
|
||||
override fun getMinion(): Minion? {
|
||||
return DamageHandler.getMinion()
|
||||
}
|
||||
|
||||
override fun getExp(block: Block, itemStack: ItemStack): Int {
|
||||
val craftBlock = block as CraftBlock
|
||||
return craftBlock.nms.block.getExpDrop((block.state as CraftBlockState).handle, craftBlock.handle.minecraftWorld, BlockPos(block.location.blockX, block.location.blockY, block.location.blockZ), CraftItemStack.asNMSCopy(itemStack))
|
||||
}
|
||||
}
|
@ -1,9 +1,7 @@
|
||||
package com.artillexstudios.axminions.nms.v1_19_R1
|
||||
|
||||
import com.artillexstudios.axminions.api.events.MinionKillEntityEvent
|
||||
import com.artillexstudios.axminions.api.events.PreMinionDamageEntityEvent
|
||||
import com.artillexstudios.axminions.api.minions.Minion
|
||||
import java.util.UUID
|
||||
import net.minecraft.core.particles.ParticleTypes
|
||||
import net.minecraft.server.level.ServerLevel
|
||||
import net.minecraft.util.Mth
|
||||
@ -30,18 +28,25 @@ import org.bukkit.enchantments.Enchantment
|
||||
import org.bukkit.entity.Entity
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.entity.EntityPotionEffectEvent
|
||||
import java.util.*
|
||||
|
||||
object DamageHandler {
|
||||
private var DUMMY_ENTITY = Fox(EntityType.FOX, (Bukkit.getWorlds().get(0) as CraftWorld).handle)
|
||||
private var minion: Minion? = null
|
||||
|
||||
fun getUUID() : UUID {
|
||||
fun getUUID(): UUID {
|
||||
return DUMMY_ENTITY.uuid
|
||||
}
|
||||
|
||||
fun getMinion(): Minion? {
|
||||
return minion
|
||||
}
|
||||
|
||||
fun damage(source: Minion, entity: Entity) {
|
||||
val nmsEntity = (entity as CraftEntity).handle
|
||||
|
||||
synchronized(DUMMY_ENTITY) {
|
||||
this.minion = source
|
||||
var f = 1
|
||||
|
||||
val nmsItem: ItemStack
|
||||
@ -110,11 +115,6 @@ object DamageHandler {
|
||||
val flag5 = nmsEntity.hurt(DamageSource.mobAttack(DUMMY_ENTITY), f.toFloat())
|
||||
|
||||
if (flag5) {
|
||||
if ((nmsEntity as LivingEntity).isDeadOrDying) {
|
||||
val killEvent = MinionKillEntityEvent(source, entity)
|
||||
Bukkit.getPluginManager().callEvent(killEvent)
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
if (nmsEntity is LivingEntity) {
|
||||
(nmsEntity).knockback(
|
||||
@ -160,10 +160,6 @@ object DamageHandler {
|
||||
|
||||
// CraftBukkit start - Only apply knockback if the damage hits
|
||||
if (entityliving.hurt(DamageSource.mobAttack(DUMMY_ENTITY), f4)) {
|
||||
if (entityliving.isDeadOrDying) {
|
||||
val killEvent = MinionKillEntityEvent(source, entity)
|
||||
Bukkit.getPluginManager().callEvent(killEvent)
|
||||
}
|
||||
entityliving.knockback(
|
||||
0.4000000059604645,
|
||||
Mth.sin(source.getLocation().yaw * 0.017453292f).toDouble(),
|
||||
@ -233,6 +229,8 @@ object DamageHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.minion = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,10 @@ class NMSHandler : NMSHandler {
|
||||
return DamageHandler.getUUID()
|
||||
}
|
||||
|
||||
override fun getMinion(): Minion? {
|
||||
return DamageHandler.getMinion()
|
||||
}
|
||||
|
||||
override fun getExp(block: Block, itemStack: ItemStack): Int {
|
||||
val craftBlock = block as CraftBlock
|
||||
return craftBlock.nms.block.getExpDrop((block.state as CraftBlockState).handle, craftBlock.handle.minecraftWorld, BlockPos(block.location.blockX, block.location.blockY, block.location.blockZ), CraftItemStack.asNMSCopy(itemStack), true)
|
||||
|
@ -1,9 +1,7 @@
|
||||
package com.artillexstudios.axminions.nms.v1_19_R2
|
||||
|
||||
import com.artillexstudios.axminions.api.events.MinionKillEntityEvent
|
||||
import com.artillexstudios.axminions.api.events.PreMinionDamageEntityEvent
|
||||
import com.artillexstudios.axminions.api.minions.Minion
|
||||
import java.util.UUID
|
||||
import net.minecraft.core.particles.ParticleTypes
|
||||
import net.minecraft.server.level.ServerLevel
|
||||
import net.minecraft.util.Mth
|
||||
@ -30,18 +28,25 @@ import org.bukkit.enchantments.Enchantment
|
||||
import org.bukkit.entity.Entity
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.entity.EntityPotionEffectEvent
|
||||
import java.util.*
|
||||
|
||||
object DamageHandler {
|
||||
private var DUMMY_ENTITY = Fox(EntityType.FOX, (Bukkit.getWorlds().get(0) as CraftWorld).handle)
|
||||
private var minion: Minion? = null
|
||||
|
||||
fun getUUID() : UUID {
|
||||
fun getUUID(): UUID {
|
||||
return DUMMY_ENTITY.uuid
|
||||
}
|
||||
|
||||
fun getMinion(): Minion? {
|
||||
return minion
|
||||
}
|
||||
|
||||
fun damage(source: Minion, entity: Entity) {
|
||||
val nmsEntity = (entity as CraftEntity).handle
|
||||
|
||||
synchronized(DUMMY_ENTITY) {
|
||||
this.minion = source
|
||||
var f = 1
|
||||
|
||||
val nmsItem: ItemStack
|
||||
@ -110,11 +115,6 @@ object DamageHandler {
|
||||
val flag5 = nmsEntity.hurt(DamageSource.mobAttack(DUMMY_ENTITY), f.toFloat())
|
||||
|
||||
if (flag5) {
|
||||
if ((nmsEntity as LivingEntity).isDeadOrDying) {
|
||||
val killEvent = MinionKillEntityEvent(source, entity)
|
||||
Bukkit.getPluginManager().callEvent(killEvent)
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
if (nmsEntity is LivingEntity) {
|
||||
(nmsEntity).knockback(
|
||||
@ -160,10 +160,6 @@ object DamageHandler {
|
||||
|
||||
// CraftBukkit start - Only apply knockback if the damage hits
|
||||
if (entityliving.hurt(DamageSource.mobAttack(DUMMY_ENTITY), f4)) {
|
||||
if (entityliving.isDeadOrDying) {
|
||||
val killEvent = MinionKillEntityEvent(source, entity)
|
||||
Bukkit.getPluginManager().callEvent(killEvent)
|
||||
}
|
||||
entityliving.knockback(
|
||||
0.4000000059604645,
|
||||
Mth.sin(source.getLocation().yaw * 0.017453292f).toDouble(),
|
||||
@ -233,6 +229,7 @@ object DamageHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
this.minion = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,10 @@ class NMSHandler : NMSHandler {
|
||||
return DamageHandler.getUUID()
|
||||
}
|
||||
|
||||
override fun getMinion(): Minion? {
|
||||
return DamageHandler.getMinion()
|
||||
}
|
||||
|
||||
override fun getExp(block: Block, itemStack: ItemStack): Int {
|
||||
val craftBlock = block as CraftBlock
|
||||
return craftBlock.nms.block.getExpDrop((block.state as CraftBlockState).handle, craftBlock.handle.minecraftWorld, BlockPos(block.location.blockX, block.location.blockY, block.location.blockZ), CraftItemStack.asNMSCopy(itemStack), true)
|
||||
|
@ -1,9 +1,7 @@
|
||||
package com.artillexstudios.axminions.nms.v1_19_R3
|
||||
|
||||
import com.artillexstudios.axminions.api.events.MinionKillEntityEvent
|
||||
import com.artillexstudios.axminions.api.events.PreMinionDamageEntityEvent
|
||||
import com.artillexstudios.axminions.api.minions.Minion
|
||||
import java.util.UUID
|
||||
import net.minecraft.core.particles.ParticleTypes
|
||||
import net.minecraft.server.level.ServerLevel
|
||||
import net.minecraft.util.Mth
|
||||
@ -29,18 +27,25 @@ import org.bukkit.enchantments.Enchantment
|
||||
import org.bukkit.entity.Entity
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.entity.EntityPotionEffectEvent
|
||||
import java.util.*
|
||||
|
||||
object DamageHandler {
|
||||
private var DUMMY_ENTITY = Fox(EntityType.FOX, (Bukkit.getWorlds().get(0) as CraftWorld).handle)
|
||||
private var minion: Minion? = null
|
||||
|
||||
fun getUUID() : UUID {
|
||||
fun getUUID(): UUID {
|
||||
return DUMMY_ENTITY.uuid
|
||||
}
|
||||
|
||||
fun getMinion(): Minion? {
|
||||
return minion
|
||||
}
|
||||
|
||||
fun damage(source: Minion, entity: Entity) {
|
||||
val nmsEntity = (entity as CraftEntity).handle
|
||||
|
||||
synchronized(DUMMY_ENTITY) {
|
||||
this.minion = source
|
||||
var f = 1
|
||||
|
||||
val nmsItem: ItemStack
|
||||
@ -109,11 +114,6 @@ object DamageHandler {
|
||||
val flag5 = nmsEntity.hurt(nmsEntity.damageSources().noAggroMobAttack(DUMMY_ENTITY), f.toFloat())
|
||||
|
||||
if (flag5) {
|
||||
if ((nmsEntity as LivingEntity).isDeadOrDying) {
|
||||
val killEvent = MinionKillEntityEvent(source, entity)
|
||||
Bukkit.getPluginManager().callEvent(killEvent)
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
if (nmsEntity is LivingEntity) {
|
||||
(nmsEntity).knockback(
|
||||
@ -159,10 +159,6 @@ object DamageHandler {
|
||||
|
||||
// CraftBukkit start - Only apply knockback if the damage hits
|
||||
if (entityliving.hurt(nmsEntity.damageSources().noAggroMobAttack(DUMMY_ENTITY), f4)) {
|
||||
if (entityliving.isDeadOrDying) {
|
||||
val killEvent = MinionKillEntityEvent(source, entity)
|
||||
Bukkit.getPluginManager().callEvent(killEvent)
|
||||
}
|
||||
entityliving.knockback(
|
||||
0.4000000059604645,
|
||||
Mth.sin(source.getLocation().yaw * 0.017453292f).toDouble(),
|
||||
@ -232,6 +228,7 @@ object DamageHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
this.minion = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,10 @@ class NMSHandler : NMSHandler {
|
||||
return DamageHandler.getUUID()
|
||||
}
|
||||
|
||||
override fun getMinion(): Minion? {
|
||||
return DamageHandler.getMinion()
|
||||
}
|
||||
|
||||
override fun getExp(block: Block, itemStack: ItemStack): Int {
|
||||
val craftBlock = block as CraftBlock
|
||||
return craftBlock.nms.block.getExpDrop((block.state as CraftBlockState).handle, craftBlock.handle.minecraftWorld, CraftLocation.toBlockPosition(block.location), CraftItemStack.asNMSCopy(itemStack), true)
|
||||
|
@ -1,9 +1,7 @@
|
||||
package com.artillexstudios.axminions.nms.v1_20_R1
|
||||
|
||||
import com.artillexstudios.axminions.api.events.MinionKillEntityEvent
|
||||
import com.artillexstudios.axminions.api.events.PreMinionDamageEntityEvent
|
||||
import com.artillexstudios.axminions.api.minions.Minion
|
||||
import java.util.UUID
|
||||
import net.minecraft.core.particles.ParticleTypes
|
||||
import net.minecraft.server.level.ServerLevel
|
||||
import net.minecraft.util.Mth
|
||||
@ -29,18 +27,25 @@ import org.bukkit.enchantments.Enchantment
|
||||
import org.bukkit.entity.Entity
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.entity.EntityPotionEffectEvent
|
||||
import java.util.*
|
||||
|
||||
object DamageHandler {
|
||||
private var DUMMY_ENTITY = Fox(EntityType.FOX, (Bukkit.getWorlds().get(0) as CraftWorld).handle)
|
||||
private var minion: Minion? = null
|
||||
|
||||
fun getUUID() : UUID {
|
||||
fun getUUID(): UUID {
|
||||
return DUMMY_ENTITY.uuid
|
||||
}
|
||||
|
||||
fun getMinion(): Minion? {
|
||||
return minion
|
||||
}
|
||||
|
||||
fun damage(source: Minion, entity: Entity) {
|
||||
val nmsEntity = (entity as CraftEntity).handle
|
||||
|
||||
synchronized(DUMMY_ENTITY) {
|
||||
this.minion = source
|
||||
var f = 1
|
||||
|
||||
val nmsItem: ItemStack
|
||||
@ -109,11 +114,6 @@ object DamageHandler {
|
||||
val flag5 = nmsEntity.hurt(nmsEntity.damageSources().noAggroMobAttack(DUMMY_ENTITY), f.toFloat())
|
||||
|
||||
if (flag5) {
|
||||
if ((nmsEntity as LivingEntity).isDeadOrDying) {
|
||||
val killEvent = MinionKillEntityEvent(source, entity)
|
||||
Bukkit.getPluginManager().callEvent(killEvent)
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
if (nmsEntity is LivingEntity) {
|
||||
(nmsEntity).knockback(
|
||||
@ -159,10 +159,6 @@ object DamageHandler {
|
||||
|
||||
// CraftBukkit start - Only apply knockback if the damage hits
|
||||
if (entityliving.hurt(nmsEntity.damageSources().noAggroMobAttack(DUMMY_ENTITY), f4)) {
|
||||
if (entityliving.isDeadOrDying) {
|
||||
val killEvent = MinionKillEntityEvent(source, entity)
|
||||
Bukkit.getPluginManager().callEvent(killEvent)
|
||||
}
|
||||
entityliving.knockback(
|
||||
0.4000000059604645,
|
||||
Mth.sin(source.getLocation().yaw * 0.017453292f).toDouble(),
|
||||
@ -232,6 +228,7 @@ object DamageHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
this.minion = null
|
||||
}
|
||||
}
|
||||
}
|
@ -32,6 +32,10 @@ class NMSHandler : NMSHandler {
|
||||
return DamageHandler.getUUID()
|
||||
}
|
||||
|
||||
override fun getMinion(): Minion? {
|
||||
return DamageHandler.getMinion()
|
||||
}
|
||||
|
||||
override fun getExp(block: Block, itemStack: ItemStack): Int {
|
||||
val craftBlock = block as CraftBlock
|
||||
return craftBlock.nms.block.getExpDrop((block.state as CraftBlockState).handle, craftBlock.handle.minecraftWorld, CraftLocation.toBlockPosition(block.location), CraftItemStack.asNMSCopy(itemStack), true)
|
||||
|
@ -1,9 +1,7 @@
|
||||
package com.artillexstudios.axminions.nms.v1_20_R2
|
||||
|
||||
import com.artillexstudios.axminions.api.events.MinionKillEntityEvent
|
||||
import com.artillexstudios.axminions.api.events.PreMinionDamageEntityEvent
|
||||
import com.artillexstudios.axminions.api.minions.Minion
|
||||
import java.util.UUID
|
||||
import net.minecraft.core.particles.ParticleTypes
|
||||
import net.minecraft.server.level.ServerLevel
|
||||
import net.minecraft.util.Mth
|
||||
@ -29,18 +27,25 @@ import org.bukkit.enchantments.Enchantment
|
||||
import org.bukkit.entity.Entity
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.entity.EntityPotionEffectEvent
|
||||
import java.util.*
|
||||
|
||||
object DamageHandler {
|
||||
private var DUMMY_ENTITY = Fox(EntityType.FOX, (Bukkit.getWorlds().get(0) as CraftWorld).handle)
|
||||
private var minion: Minion? = null
|
||||
|
||||
fun getUUID() : UUID {
|
||||
fun getUUID(): UUID {
|
||||
return DUMMY_ENTITY.uuid
|
||||
}
|
||||
|
||||
fun getMinion(): Minion? {
|
||||
return minion
|
||||
}
|
||||
|
||||
fun damage(source: Minion, entity: Entity) {
|
||||
val nmsEntity = (entity as CraftEntity).handle
|
||||
|
||||
synchronized(DUMMY_ENTITY) {
|
||||
this.minion = source
|
||||
var f = 1
|
||||
|
||||
val nmsItem: ItemStack
|
||||
@ -109,11 +114,6 @@ object DamageHandler {
|
||||
val flag5 = nmsEntity.hurt(nmsEntity.damageSources().noAggroMobAttack(DUMMY_ENTITY), f.toFloat())
|
||||
|
||||
if (flag5) {
|
||||
if ((nmsEntity as LivingEntity).isDeadOrDying) {
|
||||
val killEvent = MinionKillEntityEvent(source, entity)
|
||||
Bukkit.getPluginManager().callEvent(killEvent)
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
if (nmsEntity is LivingEntity) {
|
||||
(nmsEntity).knockback(
|
||||
@ -135,7 +135,8 @@ object DamageHandler {
|
||||
val f4 =
|
||||
1.0f + if (sweep > 0) SweepingEdgeEnchantment.getSweepingDamageRatio(sweep) else 0.0f * f
|
||||
val list: List<LivingEntity> = (source.getLocation().world as CraftWorld).handle
|
||||
.getEntitiesOfClass(LivingEntity::class.java, nmsEntity.boundingBox.inflate(1.0, 0.25, 1.0)).filter { it !is Player }
|
||||
.getEntitiesOfClass(LivingEntity::class.java, nmsEntity.boundingBox.inflate(1.0, 0.25, 1.0))
|
||||
.filter { it !is Player }
|
||||
val iterator: Iterator<*> = list.iterator()
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
@ -158,10 +159,6 @@ object DamageHandler {
|
||||
|
||||
// CraftBukkit start - Only apply knockback if the damage hits
|
||||
if (entityliving.hurt(nmsEntity.damageSources().noAggroMobAttack(DUMMY_ENTITY), f4)) {
|
||||
if (entityliving.isDeadOrDying) {
|
||||
val killEvent = MinionKillEntityEvent(source, entity)
|
||||
Bukkit.getPluginManager().callEvent(killEvent)
|
||||
}
|
||||
entityliving.knockback(
|
||||
0.4000000059604645,
|
||||
Mth.sin(source.getLocation().yaw * 0.017453292f).toDouble(),
|
||||
@ -231,6 +228,7 @@ object DamageHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
this.minion = null
|
||||
}
|
||||
}
|
||||
}
|
@ -32,6 +32,10 @@ class NMSHandler : NMSHandler {
|
||||
return DamageHandler.getUUID()
|
||||
}
|
||||
|
||||
override fun getMinion(): Minion? {
|
||||
return DamageHandler.getMinion()
|
||||
}
|
||||
|
||||
override fun getExp(block: Block, itemStack: ItemStack): Int {
|
||||
val craftBlock = block as CraftBlock
|
||||
return craftBlock.nms.block.getExpDrop((block.state as CraftBlockState).handle, craftBlock.handle.minecraftWorld, CraftLocation.toBlockPosition(block.location), CraftItemStack.asNMSCopy(itemStack), true)
|
||||
|
@ -1,9 +1,7 @@
|
||||
package com.artillexstudios.axminions.nms.v1_20_R3
|
||||
|
||||
import com.artillexstudios.axminions.api.events.MinionKillEntityEvent
|
||||
import com.artillexstudios.axminions.api.events.PreMinionDamageEntityEvent
|
||||
import com.artillexstudios.axminions.api.minions.Minion
|
||||
import java.util.UUID
|
||||
import net.minecraft.core.particles.ParticleTypes
|
||||
import net.minecraft.server.level.ServerLevel
|
||||
import net.minecraft.util.Mth
|
||||
@ -29,18 +27,25 @@ import org.bukkit.enchantments.Enchantment
|
||||
import org.bukkit.entity.Entity
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.entity.EntityPotionEffectEvent
|
||||
import java.util.*
|
||||
|
||||
object DamageHandler {
|
||||
private var DUMMY_ENTITY = Fox(EntityType.FOX, (Bukkit.getWorlds().get(0) as CraftWorld).handle)
|
||||
private var minion: Minion? = null
|
||||
|
||||
fun getUUID() : UUID {
|
||||
fun getUUID(): UUID {
|
||||
return DUMMY_ENTITY.uuid
|
||||
}
|
||||
|
||||
fun getMinion(): Minion? {
|
||||
return minion
|
||||
}
|
||||
|
||||
fun damage(source: Minion, entity: Entity) {
|
||||
val nmsEntity = (entity as CraftEntity).handle
|
||||
|
||||
synchronized(DUMMY_ENTITY) {
|
||||
this.minion = source
|
||||
var f = 1
|
||||
|
||||
val nmsItem: ItemStack
|
||||
@ -109,11 +114,6 @@ object DamageHandler {
|
||||
val flag5 = nmsEntity.hurt(nmsEntity.damageSources().noAggroMobAttack(DUMMY_ENTITY), f.toFloat())
|
||||
|
||||
if (flag5) {
|
||||
if ((nmsEntity as LivingEntity).isDeadOrDying) {
|
||||
val killEvent = MinionKillEntityEvent(source, entity)
|
||||
Bukkit.getPluginManager().callEvent(killEvent)
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
if (nmsEntity is LivingEntity) {
|
||||
(nmsEntity).knockback(
|
||||
@ -135,7 +135,8 @@ object DamageHandler {
|
||||
val f4 =
|
||||
1.0f + if (sweep > 0) SweepingEdgeEnchantment.getSweepingDamageRatio(sweep) else 0.0f * f
|
||||
val list: List<LivingEntity> = (source.getLocation().world as CraftWorld).handle
|
||||
.getEntitiesOfClass(LivingEntity::class.java, nmsEntity.boundingBox.inflate(1.0, 0.25, 1.0)).filter { it !is Player }
|
||||
.getEntitiesOfClass(LivingEntity::class.java, nmsEntity.boundingBox.inflate(1.0, 0.25, 1.0))
|
||||
.filter { it !is Player }
|
||||
val iterator: Iterator<*> = list.iterator()
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
@ -158,10 +159,6 @@ object DamageHandler {
|
||||
|
||||
// CraftBukkit start - Only apply knockback if the damage hits
|
||||
if (entityliving.hurt(nmsEntity.damageSources().noAggroMobAttack(DUMMY_ENTITY), f4)) {
|
||||
if (entityliving.isDeadOrDying) {
|
||||
val killEvent = MinionKillEntityEvent(source, entity)
|
||||
Bukkit.getPluginManager().callEvent(killEvent)
|
||||
}
|
||||
entityliving.knockback(
|
||||
0.4000000059604645,
|
||||
Mth.sin(source.getLocation().yaw * 0.017453292f).toDouble(),
|
||||
@ -231,6 +228,7 @@ object DamageHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
this.minion = null
|
||||
}
|
||||
}
|
||||
}
|
@ -33,6 +33,10 @@ class NMSHandler : NMSHandler {
|
||||
return DamageHandler.getUUID()
|
||||
}
|
||||
|
||||
override fun getMinion(): Minion? {
|
||||
return DamageHandler.getMinion()
|
||||
}
|
||||
|
||||
override fun getExp(block: Block, itemStack: ItemStack): Int {
|
||||
val craftBlock = block as CraftBlock
|
||||
return craftBlock.nms.block.getExpDrop((block.state as CraftBlockState).handle, craftBlock.handle.minecraftWorld, CraftLocation.toBlockPosition(block.location), CraftItemStack.asNMSCopy(itemStack), true)
|
||||
|
@ -1,14 +1,10 @@
|
||||
package com.artillexstudios.axminions.nms.v1_20_R4
|
||||
|
||||
import com.artillexstudios.axminions.api.events.MinionKillEntityEvent
|
||||
import com.artillexstudios.axminions.api.events.PreMinionDamageEntityEvent
|
||||
import com.artillexstudios.axminions.api.minions.Minion
|
||||
import java.util.UUID
|
||||
import net.minecraft.core.particles.ParticleTypes
|
||||
import net.minecraft.server.level.ServerLevel
|
||||
import net.minecraft.util.Mth
|
||||
import net.minecraft.world.effect.MobEffectInstance
|
||||
import net.minecraft.world.effect.MobEffects
|
||||
import net.minecraft.world.entity.EntityType
|
||||
import net.minecraft.world.entity.EquipmentSlot
|
||||
import net.minecraft.world.entity.LivingEntity
|
||||
@ -26,19 +22,25 @@ import org.bukkit.craftbukkit.inventory.CraftItemStack
|
||||
import org.bukkit.enchantments.Enchantment
|
||||
import org.bukkit.entity.Entity
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.entity.EntityPotionEffectEvent
|
||||
import java.util.*
|
||||
|
||||
object DamageHandler {
|
||||
private var DUMMY_ENTITY = Fox(EntityType.FOX, (Bukkit.getWorlds().get(0) as CraftWorld).handle)
|
||||
private var minion: Minion? = null
|
||||
|
||||
fun getUUID() : UUID {
|
||||
fun getUUID(): UUID {
|
||||
return DUMMY_ENTITY.uuid
|
||||
}
|
||||
|
||||
fun getMinion(): Minion? {
|
||||
return minion
|
||||
}
|
||||
|
||||
fun damage(source: Minion, entity: Entity) {
|
||||
val nmsEntity = (entity as CraftEntity).handle
|
||||
|
||||
synchronized(DUMMY_ENTITY) {
|
||||
this.minion = source
|
||||
var f = 1
|
||||
|
||||
val nmsItem: ItemStack
|
||||
@ -103,11 +105,6 @@ object DamageHandler {
|
||||
val flag5 = nmsEntity.hurt(nmsEntity.damageSources().noAggroMobAttack(DUMMY_ENTITY), f.toFloat())
|
||||
|
||||
if (flag5) {
|
||||
if ((nmsEntity as LivingEntity).isDeadOrDying) {
|
||||
val killEvent = MinionKillEntityEvent(source, entity)
|
||||
Bukkit.getPluginManager().callEvent(killEvent)
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
if (nmsEntity is LivingEntity) {
|
||||
(nmsEntity).knockback(
|
||||
@ -129,7 +126,8 @@ object DamageHandler {
|
||||
val f4 =
|
||||
1.0f + if (sweep > 0) EnchantmentHelper.getSweepingDamageRatio(sweep) else 0.0f * f
|
||||
val list: List<LivingEntity> = (source.getLocation().world as CraftWorld).handle
|
||||
.getEntitiesOfClass(LivingEntity::class.java, nmsEntity.boundingBox.inflate(1.0, 0.25, 1.0)).filter { it !is Player }
|
||||
.getEntitiesOfClass(LivingEntity::class.java, nmsEntity.boundingBox.inflate(1.0, 0.25, 1.0))
|
||||
.filter { it !is Player }
|
||||
val iterator: Iterator<*> = list.iterator()
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
@ -152,10 +150,6 @@ object DamageHandler {
|
||||
|
||||
// CraftBukkit start - Only apply knockback if the damage hits
|
||||
if (entityliving.hurt(nmsEntity.damageSources().noAggroMobAttack(DUMMY_ENTITY), f4)) {
|
||||
if (entityliving.isDeadOrDying) {
|
||||
val killEvent = MinionKillEntityEvent(source, entity)
|
||||
Bukkit.getPluginManager().callEvent(killEvent)
|
||||
}
|
||||
entityliving.knockback(
|
||||
0.4000000059604645,
|
||||
Mth.sin(source.getLocation().yaw * 0.017453292f).toDouble(),
|
||||
@ -213,6 +207,7 @@ object DamageHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
this.minion = null
|
||||
}
|
||||
}
|
||||
}
|
@ -33,6 +33,10 @@ class NMSHandler : NMSHandler {
|
||||
return DamageHandler.getUUID()
|
||||
}
|
||||
|
||||
override fun getMinion(): Minion? {
|
||||
return DamageHandler.getMinion()
|
||||
}
|
||||
|
||||
override fun getExp(block: Block, itemStack: ItemStack): Int {
|
||||
val craftBlock = block as CraftBlock
|
||||
return craftBlock.nms.block.getExpDrop((block.state as CraftBlockState).handle, craftBlock.handle.minecraftWorld, CraftLocation.toBlockPosition(block.location), CraftItemStack.asNMSCopy(itemStack), true)
|
||||
|
24
nms/v1_21_R1/build.gradle
Normal file
24
nms/v1_21_R1/build.gradle
Normal file
@ -0,0 +1,24 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
}
|
||||
|
||||
group = 'com.artillexstudios.axminions.nms'
|
||||
version = '1.0-SNAPSHOT'
|
||||
|
||||
dependencies {
|
||||
paperweight.paperDevBundle("1.21-R0.1-SNAPSHOT")
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvmToolchain(21)
|
||||
}
|
||||
|
||||
tasks {
|
||||
build {
|
||||
dependsOn(reobfJar)
|
||||
}
|
||||
|
||||
reobfJar {
|
||||
mustRunAfter(shadowJar)
|
||||
}
|
||||
}
|
@ -0,0 +1,224 @@
|
||||
package com.artillexstudios.axminions.nms.v1_21_R1
|
||||
|
||||
import com.artillexstudios.axminions.api.events.PreMinionDamageEntityEvent
|
||||
import com.artillexstudios.axminions.api.minions.Minion
|
||||
import net.minecraft.core.particles.ParticleTypes
|
||||
import net.minecraft.server.level.ServerLevel
|
||||
import net.minecraft.util.Mth
|
||||
import net.minecraft.world.entity.EntityType
|
||||
import net.minecraft.world.entity.EquipmentSlot
|
||||
import net.minecraft.world.entity.LivingEntity
|
||||
import net.minecraft.world.entity.animal.Fox
|
||||
import net.minecraft.world.entity.decoration.ArmorStand
|
||||
import net.minecraft.world.item.AxeItem
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import net.minecraft.world.item.SwordItem
|
||||
import net.minecraft.world.item.TridentItem
|
||||
import net.minecraft.world.item.enchantment.EnchantmentHelper
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.craftbukkit.CraftWorld
|
||||
import org.bukkit.craftbukkit.entity.CraftEntity
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack
|
||||
import org.bukkit.enchantments.Enchantment
|
||||
import org.bukkit.entity.Entity
|
||||
import org.bukkit.entity.Player
|
||||
import java.util.*
|
||||
|
||||
object DamageHandler {
|
||||
private var DUMMY_ENTITY = Fox(EntityType.FOX, (Bukkit.getWorlds().get(0) as CraftWorld).handle)
|
||||
private var minion: Minion? = null
|
||||
|
||||
fun getUUID(): UUID {
|
||||
return DUMMY_ENTITY.uuid
|
||||
}
|
||||
|
||||
fun getMinion(): Minion? {
|
||||
return minion
|
||||
}
|
||||
|
||||
fun damage(source: Minion, entity: Entity) {
|
||||
val nmsEntity = (entity as CraftEntity).handle
|
||||
|
||||
synchronized(DUMMY_ENTITY) {
|
||||
this.minion = source
|
||||
var f = 1
|
||||
|
||||
val nmsItem: ItemStack
|
||||
if (source.getTool() == null) {
|
||||
nmsItem = ItemStack.EMPTY
|
||||
} else {
|
||||
nmsItem = CraftItemStack.asNMSCopy(source.getTool())
|
||||
|
||||
if (nmsItem.item is SwordItem) {
|
||||
f = (f + (nmsItem.item as SwordItem).tier.attackDamageBonus).toInt()
|
||||
}
|
||||
|
||||
if (nmsItem.item is AxeItem) {
|
||||
f = (f + (nmsItem.item as SwordItem).tier.attackDamageBonus).toInt()
|
||||
}
|
||||
|
||||
if (nmsItem.item is TridentItem) {
|
||||
f = (f + TridentItem.BASE_DAMAGE).toInt()
|
||||
}
|
||||
}
|
||||
|
||||
DUMMY_ENTITY.setItemSlot(EquipmentSlot.MAINHAND, nmsItem)
|
||||
|
||||
if (!nmsEntity.isAttackable || entity is Player) return
|
||||
val f2 = 1.0f
|
||||
|
||||
val damageSource = nmsEntity.damageSources().noAggroMobAttack(DUMMY_ENTITY)
|
||||
var f1 = EnchantmentHelper.modifyDamage(
|
||||
nmsEntity.level() as ServerLevel,
|
||||
nmsItem,
|
||||
nmsEntity,
|
||||
damageSource,
|
||||
f.toFloat()
|
||||
)
|
||||
|
||||
f = (f * (0.2f + f2 * f2 * 0.8f)).toInt()
|
||||
f1 *= f2
|
||||
|
||||
if (f > 0.0f || f1 > 0.0f) {
|
||||
var flag3 = false
|
||||
val b0: Byte = 0
|
||||
val i = b0 + (source.getTool()?.getEnchantmentLevel(Enchantment.KNOCKBACK) ?: 0)
|
||||
|
||||
f = (f * 1.5f).toInt()
|
||||
f = (f + f1).toInt()
|
||||
|
||||
if (nmsItem.item is SwordItem) {
|
||||
flag3 = true
|
||||
}
|
||||
|
||||
var f3 = 0.0f
|
||||
var flag4 = false
|
||||
val j = (source.getTool()?.getEnchantmentLevel(Enchantment.FIRE_ASPECT) ?: 0)
|
||||
|
||||
if (nmsEntity is LivingEntity) {
|
||||
f3 = nmsEntity.health
|
||||
if (j > 0 && !nmsEntity.isOnFire()) {
|
||||
flag4 = true
|
||||
nmsEntity.igniteForSeconds(1f, false)
|
||||
}
|
||||
}
|
||||
|
||||
val event = PreMinionDamageEntityEvent(source, entity as org.bukkit.entity.LivingEntity, f.toDouble())
|
||||
Bukkit.getPluginManager().callEvent(event)
|
||||
if (event.isCancelled) {
|
||||
return
|
||||
}
|
||||
|
||||
val flag5 = nmsEntity.hurt(damageSource, f.toFloat())
|
||||
|
||||
if (flag5) {
|
||||
if (i > 0) {
|
||||
if (nmsEntity is LivingEntity) {
|
||||
(nmsEntity).knockback(
|
||||
(i.toFloat() * 0.5f).toDouble(),
|
||||
Mth.sin(source.getLocation().yaw * 0.017453292f).toDouble(),
|
||||
(-Mth.cos(source.getLocation().yaw * 0.017453292f)).toDouble()
|
||||
)
|
||||
} else {
|
||||
nmsEntity.push(
|
||||
(-Mth.sin(source.getLocation().yaw * 0.017453292f) * i.toFloat() * 0.5f).toDouble(),
|
||||
0.1,
|
||||
(Mth.cos(source.getLocation().yaw * 0.017453292f) * i.toFloat() * 0.5f).toDouble()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (flag3) {
|
||||
val sweep = source.getTool()?.getEnchantmentLevel(Enchantment.SWEEPING_EDGE) ?: 0
|
||||
val f4 =
|
||||
1.0f + if (sweep > 0) getSweepingDamageRatio(sweep) else 0.0f * f
|
||||
val list: List<LivingEntity> = (source.getLocation().world as CraftWorld).handle
|
||||
.getEntitiesOfClass(LivingEntity::class.java, nmsEntity.boundingBox.inflate(1.0, 0.25, 1.0))
|
||||
.filter { it !is Player }
|
||||
val iterator: Iterator<*> = list.iterator()
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
val entityliving: LivingEntity = iterator.next() as LivingEntity
|
||||
|
||||
if ((entityliving !is ArmorStand || !(entityliving).isMarker) && source.getLocation()
|
||||
.distanceSquared(
|
||||
(entity as Entity).location
|
||||
) < 9.0
|
||||
) {
|
||||
val damageEvent = PreMinionDamageEntityEvent(
|
||||
source,
|
||||
entityliving.bukkitEntity as org.bukkit.entity.LivingEntity,
|
||||
f4.toDouble()
|
||||
)
|
||||
Bukkit.getPluginManager().callEvent(damageEvent)
|
||||
if (event.isCancelled) {
|
||||
return
|
||||
}
|
||||
|
||||
// CraftBukkit start - Only apply knockback if the damage hits
|
||||
if (entityliving.hurt(nmsEntity.damageSources().noAggroMobAttack(DUMMY_ENTITY), f4)) {
|
||||
entityliving.knockback(
|
||||
0.4000000059604645,
|
||||
Mth.sin(source.getLocation().yaw * 0.017453292f).toDouble(),
|
||||
(-Mth.cos(source.getLocation().yaw * 0.017453292f)).toDouble()
|
||||
)
|
||||
}
|
||||
// CraftBukkit end
|
||||
}
|
||||
}
|
||||
|
||||
val d0 = -Mth.sin(source.getLocation().yaw * 0.017453292f).toDouble()
|
||||
val d1 = Mth.cos(source.getLocation().yaw * 0.017453292f).toDouble()
|
||||
|
||||
if ((source.getLocation().world as CraftWorld).handle is ServerLevel) {
|
||||
((source.getLocation().world as CraftWorld).handle as ServerLevel).sendParticles(
|
||||
ParticleTypes.SWEEP_ATTACK,
|
||||
source.getLocation().x + d0,
|
||||
source.getLocation().y + 0.5,
|
||||
source.getLocation().z + d1,
|
||||
0,
|
||||
d0,
|
||||
0.0,
|
||||
d1,
|
||||
0.0
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (nmsEntity is LivingEntity) {
|
||||
val f5: Float = f3 - nmsEntity.health
|
||||
|
||||
if (j > 0) {
|
||||
nmsEntity.igniteForSeconds(j * 4f, false)
|
||||
}
|
||||
|
||||
if ((source.getLocation().world as CraftWorld).handle is ServerLevel && f5 > 2.0f) {
|
||||
val k = (f5.toDouble() * 0.5).toInt()
|
||||
|
||||
((source.getLocation().world as CraftWorld).handle).sendParticles(
|
||||
ParticleTypes.DAMAGE_INDICATOR,
|
||||
nmsEntity.getX(),
|
||||
nmsEntity.getY(0.5),
|
||||
nmsEntity.getZ(),
|
||||
k,
|
||||
0.1,
|
||||
0.0,
|
||||
0.1,
|
||||
0.2
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (flag4) {
|
||||
nmsEntity.clearFire()
|
||||
}
|
||||
}
|
||||
}
|
||||
this.minion = null
|
||||
}
|
||||
}
|
||||
|
||||
fun getSweepingDamageRatio(level: Int): Float {
|
||||
return 1.0f - 1.0f / (level + 1).toFloat()
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.artillexstudios.axminions.nms.v1_21_R1
|
||||
|
||||
import com.artillexstudios.axminions.api.minions.Minion
|
||||
import net.minecraft.server.MinecraftServer
|
||||
import net.minecraft.world.level.storage.loot.BuiltInLootTables
|
||||
import net.minecraft.world.level.storage.loot.LootParams
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams
|
||||
import net.minecraft.world.phys.Vec3
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.craftbukkit.CraftWorld
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
object LootHandler {
|
||||
|
||||
fun generateFishingLoot(minion: Minion, waterLocation: Location): List<ItemStack> {
|
||||
val nmsItem: net.minecraft.world.item.ItemStack = if (minion.getTool() == null) {
|
||||
net.minecraft.world.item.ItemStack.EMPTY
|
||||
} else {
|
||||
CraftItemStack.asNMSCopy(minion.getTool())
|
||||
}
|
||||
|
||||
val level = (minion.getLocation().world as CraftWorld).handle
|
||||
|
||||
val lootparams = LootParams.Builder(level).withParameter(
|
||||
LootContextParams.ORIGIN, Vec3(waterLocation.x, waterLocation.y, waterLocation.z)
|
||||
).withParameter(LootContextParams.TOOL, nmsItem).withOptionalParameter(LootContextParams.THIS_ENTITY, null)
|
||||
.create(LootContextParamSets.FISHING)
|
||||
|
||||
val lootTable = MinecraftServer.getServer().reloadableRegistries().getLootTable(BuiltInLootTables.FISHING);
|
||||
|
||||
return lootTable.getRandomItems(lootparams).stream().map { original: net.minecraft.world.item.ItemStack? ->
|
||||
CraftItemStack.asBukkitCopy(
|
||||
original
|
||||
)
|
||||
}.toList()
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package com.artillexstudios.axminions.nms.v1_21_R1
|
||||
|
||||
import com.artillexstudios.axminions.api.minions.Minion
|
||||
import com.artillexstudios.axminions.nms.NMSHandler
|
||||
import java.util.UUID
|
||||
import net.minecraft.core.BlockPos
|
||||
import net.minecraft.world.entity.MobCategory
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.block.Block
|
||||
import org.bukkit.craftbukkit.block.CraftBlock
|
||||
import org.bukkit.craftbukkit.block.CraftBlockState
|
||||
import org.bukkit.craftbukkit.entity.CraftEntity
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack
|
||||
import org.bukkit.craftbukkit.util.CraftLocation
|
||||
import org.bukkit.entity.Entity
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
class NMSHandler : NMSHandler {
|
||||
|
||||
override fun attack(source: Minion, target: Entity) {
|
||||
DamageHandler.damage(source, target)
|
||||
}
|
||||
|
||||
override fun generateRandomFishingLoot(minion: Minion, waterLocation: Location): List<ItemStack> {
|
||||
return LootHandler.generateFishingLoot(minion, waterLocation)
|
||||
}
|
||||
|
||||
override fun isAnimal(entity: Entity): Boolean {
|
||||
return (entity as CraftEntity).handle.type.category == MobCategory.CREATURE
|
||||
}
|
||||
|
||||
override fun getAnimalUUID(): UUID {
|
||||
return DamageHandler.getUUID()
|
||||
}
|
||||
|
||||
override fun getMinion(): Minion? {
|
||||
return DamageHandler.getMinion()
|
||||
}
|
||||
|
||||
override fun getExp(block: Block, itemStack: ItemStack): Int {
|
||||
val craftBlock = block as CraftBlock
|
||||
return craftBlock.nms.block.getExpDrop((block.state as CraftBlockState).handle, craftBlock.handle.minecraftWorld, CraftLocation.toBlockPosition(block.location), CraftItemStack.asNMSCopy(itemStack), true)
|
||||
}
|
||||
}
|
@ -20,3 +20,7 @@ include 'nms:v1_20_R1'
|
||||
include 'nms:v1_20_R2'
|
||||
include 'nms:v1_20_R3'
|
||||
include 'nms:v1_20_R4'
|
||||
include 'nms:v1_21_R1'
|
||||
include 'nms:v1_18_R2'
|
||||
findProject(':nms:v1_18_R2')?.name = 'v1_18_R2'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user