forked from hannibal002/SkyHanni
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backend: Add compat files for preprocessing (hannibal002#2872)
- Loading branch information
Showing
11 changed files
with
174 additions
and
83 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
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
36 changes: 36 additions & 0 deletions
36
src/main/java/at/hannibal2/skyhanni/utils/compat/EffectsCompat.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,36 @@ | ||
package at.hannibal2.skyhanni.utils.compat | ||
|
||
import net.minecraft.entity.EntityLivingBase | ||
import net.minecraft.potion.Potion | ||
import net.minecraft.potion.PotionEffect | ||
//#if MC > 1.12 | ||
//$$ import net.minecraft.init.MobEffects | ||
//#endif | ||
|
||
enum class EffectsCompat(val potion: Potion) { | ||
INVISIBILITY( | ||
//#if MC < 1.12 | ||
Potion.invisibility | ||
//#else | ||
//$$ MobEffects.INVISIBILITY | ||
//#endif | ||
), | ||
BLINDNESS( | ||
//#if MC < 1.12 | ||
Potion.blindness | ||
//#else | ||
//$$ MobEffects.BLINDNESS | ||
//#endif | ||
), | ||
; | ||
|
||
companion object { | ||
fun EntityLivingBase.hasPotionEffect(effect: EffectsCompat): Boolean { | ||
return this.isPotionActive(effect.potion) | ||
} | ||
|
||
fun EntityLivingBase.activePotionEffect(effect: EffectsCompat): PotionEffect? { | ||
return this.getActivePotionEffect(effect.potion) | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/at/hannibal2/skyhanni/utils/compat/EnchantmentsCompat.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,16 @@ | ||
package at.hannibal2.skyhanni.utils.compat | ||
|
||
import net.minecraft.enchantment.Enchantment | ||
//#if MC >= 1.12 | ||
//$$ import net.minecraft.init.Enchantments | ||
//#endif | ||
|
||
enum class EnchantmentsCompat(val enchantment: Enchantment) { | ||
PROTECTION( | ||
//#if MC < 1.12 | ||
Enchantment.protection | ||
//#else | ||
//$$ Enchantments.PROTECTION | ||
//#endif | ||
), | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/at/hannibal2/skyhanni/utils/compat/EntityCompat.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,52 @@ | ||
package at.hannibal2.skyhanni.utils.compat | ||
|
||
|
||
import net.minecraft.entity.Entity | ||
import net.minecraft.entity.EntityLiving | ||
import net.minecraft.entity.EntityLivingBase | ||
import net.minecraft.entity.item.EntityArmorStand | ||
import net.minecraft.item.ItemStack | ||
//#if MC >= 1.12 | ||
//$$ import net.minecraft.inventory.EntityEquipmentSlot | ||
//#endif | ||
|
||
fun Entity.getNameAsString(): String = | ||
this.name | ||
//#if MC >= 1.14 | ||
//$$ .string | ||
//#endif | ||
|
||
fun EntityArmorStand.getStandHelmet(): ItemStack? = | ||
//#if MC < 1.12 | ||
this.getEquipmentInSlot(4) | ||
//#else | ||
//$$ this.getItemStackFromSlot(EntityEquipmentSlot.HEAD) | ||
//#endif | ||
|
||
fun EntityLiving.getEntityHelmet(): ItemStack? = | ||
//#if MC < 1.12 | ||
this.getEquipmentInSlot(4) | ||
//#else | ||
//$$ this.getItemStackFromSlot(EntityEquipmentSlot.HEAD) | ||
//#endif | ||
|
||
fun EntityLivingBase.getWholeInventory() = | ||
//#if MC < 1.12 | ||
this.inventory | ||
//#else | ||
//$$ this.equipmentAndArmor.toList() | ||
//#endif | ||
|
||
fun Entity.getFirstPassenger(): Entity? = | ||
//#if MC < 1.12 | ||
this.riddenByEntity | ||
//#else | ||
//$$ this.passengers.firstOrNull() | ||
//#endif | ||
|
||
fun EntityArmorStand.getHandItem(): ItemStack? = | ||
//#if MC < 1.12 | ||
this.getEquipmentInSlot(0) | ||
//#else | ||
//$$ this.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND) | ||
//#endif |
12 changes: 12 additions & 0 deletions
12
src/main/java/at/hannibal2/skyhanni/utils/compat/ItemCompat.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,12 @@ | ||
package at.hannibal2.skyhanni.utils.compat | ||
|
||
import net.minecraft.client.Minecraft | ||
import net.minecraft.item.ItemStack | ||
|
||
fun ItemStack.getTooltipCompat(advanced: Boolean): MutableList<String> { | ||
//#if MC < 1.12 | ||
return this.getTooltip(Minecraft.getMinecraft().thePlayer, advanced) | ||
//#else | ||
//$$ return this.getTooltip(Minecraft.getMinecraft().player) { advanced } | ||
//#endif | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/at/hannibal2/skyhanni/utils/compat/PacketCompat.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,22 @@ | ||
package at.hannibal2.skyhanni.utils.compat | ||
|
||
import net.minecraft.item.ItemStack | ||
import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement | ||
import net.minecraft.util.EnumFacing | ||
//#if MC > 1.12 | ||
//$$ import net.minecraft.client.Minecraft | ||
//#endif | ||
|
||
fun C08PacketPlayerBlockPlacement.getFacing(): EnumFacing = | ||
//#if MC < 1.12 | ||
EnumFacing.getFront(placedBlockDirection) | ||
//#else | ||
//$$ direction | ||
//#endif | ||
|
||
fun C08PacketPlayerBlockPlacement.getUsedItem(): ItemStack? = | ||
//#if MC < 1.12 | ||
stack | ||
//#else | ||
//$$ Minecraft.getMinecraft().player.getHeldItem(hand) | ||
//#endif |
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
src/main/java/at/hannibal2/skyhanni/utils/compat/WorldCompat.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,11 @@ | ||
package at.hannibal2.skyhanni.utils.compat | ||
|
||
import net.minecraft.client.multiplayer.WorldClient | ||
import net.minecraft.entity.player.EntityPlayer | ||
|
||
fun WorldClient.getLoadedPlayers(): List<EntityPlayer> = | ||
//#if MC < 1.14 | ||
this.playerEntities | ||
//#else | ||
//$$ this.players() | ||
//#endif |