forked from nisovin/MagicSpells
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update gradle
- Loading branch information
Showing
6 changed files
with
140 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
core/src/main/java/com/nisovin/magicspells/volatilecode/v1_19_R2/VolatileCode1_19_R2.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package com.nisovin.magicspells.volatilecode.v1_19_R2 | ||
|
||
import org.bukkit.Bukkit | ||
import org.bukkit.entity.* | ||
import org.bukkit.Location | ||
import org.bukkit.util.Vector | ||
import org.bukkit.inventory.ItemStack | ||
import org.bukkit.event.entity.ExplosionPrimeEvent | ||
|
||
import org.bukkit.craftbukkit.v1_19_R2.entity.* | ||
import org.bukkit.craftbukkit.v1_19_R2.CraftWorld | ||
import org.bukkit.craftbukkit.v1_19_R2.CraftServer | ||
import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack | ||
|
||
import net.minecraft.world.phys.Vec3 | ||
import net.minecraft.network.chat.Component | ||
import net.minecraft.world.entity.EntityType | ||
import net.minecraft.network.protocol.game.* | ||
import net.minecraft.world.entity.item.PrimedTnt | ||
import net.minecraft.world.item.alchemy.PotionUtils | ||
import net.minecraft.network.syncher.EntityDataAccessor | ||
import net.minecraft.world.entity.boss.enderdragon.EnderDragon | ||
|
||
import com.nisovin.magicspells.MagicSpells | ||
import com.nisovin.magicspells.util.BoundingBox | ||
import com.nisovin.magicspells.util.compat.EventUtil | ||
import com.nisovin.magicspells.volatilecode.VolatileCodeHandle | ||
|
||
private typealias nmsItemStack = net.minecraft.world.item.ItemStack | ||
|
||
class VolatileCode1_19_R2: VolatileCodeHandle { | ||
|
||
private var entityLivingPotionEffectColor: EntityDataAccessor<Int>? = null | ||
|
||
init { | ||
try { | ||
// CHANGE THIS TO SPIGOT MAPPING VERSION OF MOJANG'S - EntityDataAccessor<Integer> DATA_EFFECT_COLOR_ID | ||
val entityLivingPotionEffectColorField = net.minecraft.world.entity.LivingEntity::class.java.getDeclaredField("bL") | ||
entityLivingPotionEffectColorField.isAccessible = true | ||
entityLivingPotionEffectColor = entityLivingPotionEffectColorField.get(null) as EntityDataAccessor<Int> | ||
} catch (e: Exception) { | ||
MagicSpells.error("THIS OCCURRED WHEN CREATING THE VOLATILE CODE HANDLE FOR 1.19.3, THE FOLLOWING ERROR IS MOST LIKELY USEFUL IF YOU'RE RUNNING THE LATEST VERSION OF MAGICSPELLS.") | ||
e.printStackTrace() | ||
} | ||
} | ||
|
||
override fun addPotionGraphicalEffect(entity: LivingEntity, color: Int, duration: Long) { | ||
val livingEntity = (entity as CraftLivingEntity).handle | ||
val entityData = livingEntity.entityData | ||
entityData.set(entityLivingPotionEffectColor, color) | ||
|
||
if (duration > 0) { | ||
MagicSpells.scheduleDelayedTask({ | ||
var c = 0 | ||
if (livingEntity.getActiveEffects().isNotEmpty()) { | ||
c = PotionUtils.getColor(livingEntity.getActiveEffects()) | ||
} | ||
entityData.set(entityLivingPotionEffectColor, c) | ||
}, duration) | ||
} | ||
} | ||
|
||
override fun sendFakeSlotUpdate(player: Player, slot: Int, item: ItemStack?) { | ||
val nmsItem: nmsItemStack? | ||
if (item != null) nmsItem = CraftItemStack.asNMSCopy(item) | ||
else nmsItem = null | ||
|
||
val packet = ClientboundContainerSetSlotPacket(0, 0, slot.toShort() + 36, nmsItem!!) | ||
(player as CraftPlayer).handle.connection.send(packet) | ||
} | ||
|
||
override fun simulateTnt(target: Location, source: LivingEntity, explosionSize: Float, fire: Boolean): Boolean { | ||
val e = PrimedTnt((target.world as CraftWorld).handle, target.x, target.y, target.z, (source as CraftLivingEntity).handle) | ||
val c = CraftTNTPrimed(Bukkit.getServer() as CraftServer, e) | ||
val event = ExplosionPrimeEvent(c, explosionSize, fire) | ||
EventUtil.call(event) | ||
return event.isCancelled | ||
} | ||
|
||
override fun setFallingBlockHurtEntities(block: FallingBlock, damage: Float, max: Int) { | ||
val efb = (block as CraftFallingBlock).handle | ||
block.setHurtEntities(true) | ||
efb.setHurtsEntities(damage, max) | ||
} | ||
|
||
override fun playDragonDeathEffect(location: Location) { | ||
val dragon = EnderDragon(EntityType.ENDER_DRAGON, (location.world as CraftWorld).handle) | ||
dragon.setPos(location.x, location.y, location.z) | ||
|
||
val addMobPacket = ClientboundAddEntityPacket(dragon) | ||
val entityEventPacket = ClientboundEntityEventPacket(dragon, 3) | ||
val removeEntityPacket = ClientboundRemoveEntitiesPacket(dragon.id) | ||
|
||
val box = BoundingBox(location, 64.0) | ||
val players = ArrayList<Player>() | ||
for (player in location.world!!.players) { | ||
if (!box.contains(player)) continue | ||
players.add(player) | ||
(player as CraftPlayer).handle.connection.send(addMobPacket) | ||
player.handle.connection.send(addMobPacket) | ||
player.handle.connection.send(entityEventPacket) | ||
} | ||
|
||
MagicSpells.scheduleDelayedTask({ | ||
for (player in players) { | ||
if (!player.isValid) continue | ||
(player as CraftPlayer).handle.connection.send(removeEntityPacket) | ||
} | ||
}, 250) | ||
|
||
} | ||
|
||
override fun setClientVelocity(player: Player, velocity: Vector) { | ||
val packet = ClientboundSetEntityMotionPacket(player.entityId, Vec3(velocity.x, velocity.y, velocity.z)) | ||
(player as CraftPlayer).handle.connection.send(packet) | ||
} | ||
|
||
override fun setInventoryTitle(player: Player, title: String) { | ||
val entityPlayer = (player as CraftPlayer).handle | ||
val container = entityPlayer.containerMenu | ||
val packet = ClientboundOpenScreenPacket(container.containerId, container.type, Component.literal(title)) | ||
|
||
player.handle.connection.send(packet) | ||
player.updateInventory() | ||
} | ||
|
||
override fun startAutoSpinAttack(player: Player?, ticks: Int) { | ||
val entityPlayer = (player as CraftPlayer).handle | ||
entityPlayer.startAutoSpinAttack(ticks) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |