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

Fixed Aotv Highlight thing #324

Closed
wants to merge 5 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import gg.skytils.skytilsmod.utils.ItemUtil.getDisplayName
import gg.skytils.skytilsmod.utils.ItemUtil.getExtraAttributes
import gg.skytils.skytilsmod.utils.ItemUtil.getItemLore
import gg.skytils.skytilsmod.utils.ItemUtil.getSkyBlockItemID
import gg.skytils.skytilsmod.utils.MathUtil.ceil
import gg.skytils.skytilsmod.utils.NumberUtil.romanToDecimal
import gg.skytils.skytilsmod.utils.RenderUtil.highlight
import gg.skytils.skytilsmod.utils.RenderUtil.renderRarity
Expand All @@ -49,9 +50,9 @@ import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import net.minecraft.block.BlockDoor
import net.minecraft.block.BlockLadder
import net.minecraft.block.BlockLiquid
import net.minecraft.block.BlockSign
import net.minecraft.client.Minecraft
import net.minecraft.client.entity.EntityOtherPlayerMP
import net.minecraft.client.entity.EntityPlayerSP
import net.minecraft.client.gui.GuiScreen
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.entity.projectile.EntityFishHook
Expand All @@ -62,9 +63,9 @@ import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement
import net.minecraft.network.play.server.S1CPacketEntityMetadata
import net.minecraft.network.play.server.S2APacketParticles
import net.minecraft.network.play.server.S2FPacketSetSlot
import net.minecraft.util.EnumFacing
import net.minecraft.util.BlockPos
import net.minecraft.util.EnumParticleTypes
import net.minecraft.util.MovingObjectPosition
import net.minecraft.util.Vec3
import net.minecraftforge.client.event.RenderWorldLastEvent
import net.minecraftforge.common.util.Constants
import net.minecraftforge.event.entity.EntityJoinWorldEvent
Expand Down Expand Up @@ -687,17 +688,10 @@ object ItemFeatures {
if (Skytils.config.showEtherwarpTeleportPos && mc.thePlayer?.isSneaking == true) {
val extraAttr = getExtraAttributes(mc.thePlayer.heldItem) ?: return
if (!extraAttr.getBoolean("ethermerge")) return
val dist = 57.0 + extraAttr.getInteger("tuned_transmission")
val vec3 = mc.thePlayer.getPositionEyes(event.partialTicks)
val vec31 = mc.thePlayer.getLook(event.partialTicks)
val vec32 = vec3.addVector(
vec31.xCoord * dist,
vec31.yCoord * dist,
vec31.zCoord * dist
)
val obj = mc.theWorld.rayTraceBlocks(vec3, vec32, true, false, true) ?: return
val block = obj.blockPos ?: return
val dist = 57.0f + extraAttr.getInteger("tuned_transmission")
val block = raycast(mc.thePlayer, event.partialTicks, dist, 0.1f) ?: return
val state = mc.theWorld.getBlockState(block)

if (isValidEtherwarpPos(obj)) {
RenderUtil.drawSelectionBox(
block,
Expand All @@ -709,20 +703,46 @@ object ItemFeatures {
}
}

private fun isValidEtherwarpPos(obj: MovingObjectPosition): Boolean {
val pos = obj.blockPos
val sideHit = obj.sideHit
/**
* Adapted from NotEnoughUpdates under Creative Commons Attribution-NonCommercial 3.0
* https://github.com/Moulberry/NotEnoughUpdates/blob/master/LICENSE
*
* @author Moulberry
*/
private fun raycast(player: EntityPlayerSP, partialTicks: Float, dist: Float, step: Float): BlockPos? {
var pos = Vec3(player.posX, player.posY + player.getEyeHeight(), player.posZ)
val lookVec3 = player.getLook(partialTicks)
var look = Vec3(lookVec3.xCoord, lookVec3.yCoord, lookVec3.zCoord)
look *= step / look.lengthVector()
val stepCount = ceil(dist / step)

for (i in 0 until stepCount) {
pos += look
val world = Minecraft.getMinecraft().theWorld
val position = BlockPos(pos.x, pos.y, pos.z)
val state = world.getBlockState(position)
if (state.block !== Blocks.air) {
//Back-step
pos -= look
look *= 0.1
for (j in 0..9) {
pos += look
val position2 = BlockPos(pos.x, pos.y, pos.z)
val state2 = world.getBlockState(position2)
if (state2.block !== Blocks.air) {
return BlockPos(position2)
}
}
return BlockPos(position)
}
}
return null
}

private fun isValidEtherwarpPos(pos: BlockPos): Boolean {
return mc.theWorld.getBlockState(pos).block.material.isSolid && (1..2).all {
val newPos = pos.up(it)
val newBlock = mc.theWorld.getBlockState(newPos)
if (sideHit === EnumFacing.UP && (Utils.equalsOneOf(
newBlock.block,
Blocks.fire,
Blocks.skull
) || newBlock.block is BlockLiquid)
) return@all false
if (sideHit !== EnumFacing.UP && newBlock.block is BlockSign) return@all false
if (newBlock.block is BlockLadder || newBlock.block is BlockDoor) return@all false
return@all newBlock.block.isPassable(mc.theWorld, newPos)
}
Expand Down