Skip to content

Commit

Permalink
✨ fix selection zone not removing itself
Browse files Browse the repository at this point in the history
this is a very very bad fix
  • Loading branch information
PriestOfFerns committed Mar 15, 2024
1 parent 14ca44d commit dc49309
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ShipAssemblerItem(properties: Properties): Item(properties) {
if (player.isShiftKeyDown and (level.getBlockState(pos).isAir)) {
firstPosition = null
secondPosition = null
if (SelectionZone!=null) Renderer.removeRender(SelectionZone!!)
if (SelectionZone!=null) Renderer.removeRenderOfType(SelectionZone!!)
SelectionZone = null;
player.sendMessage(TextComponent("Selection reset").withStyle(ChatFormatting.BOLD), Util.NIL_UUID)
} else if (firstPosition == null) {
Expand All @@ -88,7 +88,7 @@ class ShipAssemblerItem(properties: Properties): Item(properties) {
secondPosition = res.blockPos
player.sendMessage(TextComponent("Second pos selected").withStyle(ChatFormatting.BOLD), Util.NIL_UUID)

if (SelectionZone!=null) Renderer.removeRender(SelectionZone!!)
if (SelectionZone!=null) Renderer.removeRenderOfType(SelectionZone!!)
SelectionZone = null;

val SZ = SelectionZoneRenderer(Vec3d(firstPosition!!.x.toDouble(),
Expand Down Expand Up @@ -117,7 +117,7 @@ class ShipAssemblerItem(properties: Properties): Item(properties) {
player.sendMessage(TextComponent("Failed to Assemble").withStyle(ChatFormatting.RED), Util.NIL_UUID)
}

if (SelectionZone!=null) Renderer.removeRender(SelectionZone!!)
if (SelectionZone!=null) Renderer.removeRenderOfType(SelectionZone!!)
SelectionZone = null;
firstPosition = null
secondPosition = null
Expand All @@ -131,7 +131,7 @@ class ShipAssemblerItem(properties: Properties): Item(properties) {
super.inventoryTick(stack, level, entity, slotId, isSelected)

if (isSelected && secondPosition == null) {
if (SelectionZone!=null) Renderer.removeRender(SelectionZone!!)
if (SelectionZone!=null) Renderer.removeRenderOfType(SelectionZone!!)
SelectionZone = null
val res = raycast(level, entity as Player, ClipContext.Fluid.NONE)
if (res != null) {
Expand All @@ -151,7 +151,7 @@ class ShipAssemblerItem(properties: Properties): Item(properties) {

}
} else if (isSelected==false && secondPosition == null && SelectionZone!=null) {
Renderer.removeRender(SelectionZone!!)
Renderer.removeRenderOfType(SelectionZone!!)
SelectionZone = null
}
}
Expand All @@ -166,7 +166,6 @@ class ShipAssemblerItem(properties: Properties): Item(properties) {
val k = Mth.sin(-f * 0.017453292f)
val l = i * j
val n = h * j
val d = 5.0
val vec32 = vec3.add(l.toDouble() * 5.0, k.toDouble() * 5.0, n.toDouble() * 5.0)
return level.clip(ClipContext(vec3, vec32, ClipContext.Block.OUTLINE, fluidMode, player))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fun renderData(poseStack: PoseStack, camera: Camera) {

object Renderer {
var CurrentId:Long = 0;
val toRender = mutableListOf<RenderingData>()
var toRender = mutableListOf<RenderingData>()

fun addRender(renderData: RenderingData): RenderingData {
renderData.Id = CurrentId;
Expand All @@ -29,11 +29,19 @@ object Renderer {
fun removeRender(renderData: RenderingData) {
toRender.remove(renderData);


}

fun removeRenderOfType(renderData: RenderingData) {
val clone = toRender.toMutableList(); // This is an awful way to do this, but I can't think of a different way
clone.removeIf { it.type==renderData.type }
toRender=clone;
}
}


interface RenderingData {
var Id: Long;
var type: String;
fun renderData(poseStack: PoseStack, camera: Camera)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@ import com.mojang.blaze3d.systems.RenderSystem
import com.mojang.blaze3d.vertex.*
import com.mojang.math.Matrix4f
import de.m_marvin.univec.impl.Vec3d
import net.fabricmc.loader.impl.lib.sat4j.core.Vec
import net.minecraft.client.Camera
import net.minecraft.client.Minecraft
import net.minecraft.client.renderer.GameRenderer
import net.minecraft.client.renderer.RenderType
import org.joml.Vector3d
import org.lwjgl.opengl.GL11
import java.awt.Color
class SelectionZoneRenderer() : RenderingData {

var point0 = Vec3d();
var point1 = Vec3d();
var color: Color = Color(0)
override var Id: Long = 0;
override var Id: Long = 0
override var type: String = "Ship_Assembler_Selection_Zone"
constructor(
point0: Vec3d,
point1: Vec3d,
Expand All @@ -25,6 +23,7 @@ class SelectionZoneRenderer() : RenderingData {
this.point0 = point0
this.point1 = point1
this.color = color

}

override fun renderData(poseStack: PoseStack, camera: Camera) {
Expand Down

0 comments on commit dc49309

Please sign in to comment.