Fix CME from resizing GUI, and add patterns to drops when changing P2P interface type

CME caused by iterating over the button list. Clicking on resize button forces
the GUI to reset, so the button list changes and causes the CME.

P2P interfaces now drop their items if changing their type from the GUI.
This commit is contained in:
Firenoo committed 2023-05-13 09:21:07 -07:00
1 parent ca4f95460b
commit 55e77d9929
3 files changed
+28 -10

No files matched your search

@@ -97,7 +97,7 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
::selectedInfo, ::mode, scrollBar)
searchBar = MEGuiTextField(100, 10)
resizeButton = object: WidgetButton(this, 0, 0, 32, 32) {
override fun mousePressed(mouseX: Int, mouseY: Int, button: Int) {
override fun mousePressed(mouseX: Int, mouseY: Int, button: Int): Boolean {
if (super.mousePressed(mc, mouseX, mouseY)) {
if (button == 0) {
scale = when (scale) {
@@ -116,7 +116,9 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
}
initGui()
super.func_146113_a(mc.soundHandler)
return true
}
return false
}
}
@@ -148,18 +150,20 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
hoverText = modeDescriptions[mode.ordinal]
}
override fun mousePressed(mouseX: Int, mouseY: Int, button: Int) {
override fun mousePressed(mouseX: Int, mouseY: Int, button: Int): Boolean {
if (super.mousePressed(mc, mouseX, mouseY)) {
mode = when (button) {
0 -> mode.next()
1 -> mode.next(true)
else -> return
else -> return false
}
hoverText = modeDescriptions[mode.ordinal]
setTexCoords((mode.ordinal + 3) * 32.0, 232.0)
syncMemoryInfo()
super.func_146113_a(mc.soundHandler)
return true
}
return false
}
}
@@ -197,17 +201,19 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
}
}
override fun mousePressed(mouseX: Int, mouseY: Int, button: Int) {
override fun mousePressed(mouseX: Int, mouseY: Int, button: Int): Boolean {
if (super.mousePressed(mc, mouseX, mouseY)) {
if (button == 1) {
// open type selector?
openTypeSelector(this, true)
return
return true
} else {
type = nextType(false)
}
commitType()
return true
}
return false
}
override fun draw(mc: Minecraft, mouseX: Int, mouseY: Int, partialTicks: Float) {
@@ -266,10 +272,12 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
}
refreshButton = object: WidgetButton(this, 0, 0, 32, 32) {
override fun mousePressed(mouseX: Int, mouseY: Int, button: Int) {
override fun mousePressed(mouseX: Int, mouseY: Int, button: Int): Boolean {
if (super.mousePressed(mc, mouseX, mouseY)) {
ModNetwork.channel.sendToServer(C2SRefreshP2PList(type?.index ?: TUNNEL_ANY))
return true
}
return false
}
}
@@ -471,8 +479,11 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
}
col.mouseClicked(mouseX, mouseY, mouseButton)
scrollBar.click(mouseX, mouseY)
buttonList.forEach {it as WidgetButton
it.mousePressed(mouseX, mouseY, mouseButton)
for (button in buttonList) {
button as WidgetButton
if (button.mousePressed(mouseX, mouseY, mouseButton)) {
return
}
}
searchBar.mouseClicked(mouseX, mouseY, mouseButton)
if (mouseButton == 1 && searchBar.isMouseIn(mouseX, mouseY)) {
@@ -25,7 +25,7 @@ abstract class WidgetButton(val gui: GuiAdvancedMemoryCard, x: Int, y: Int, widt
private var texY = 0.0
var hoverText: List<String> = listOf()
abstract fun mousePressed(mouseX: Int, mouseY: Int, button: Int)
abstract fun mousePressed(mouseX: Int, mouseY: Int, button: Int): Boolean
open fun draw(mc: Minecraft, mouseX: Int, mouseY: Int, partialTicks: Float) {
val tessellator = Tessellator.instance
@@ -36,7 +36,7 @@ fun linkP2P(player: EntityPlayer, inputIndex: Long, outputIndex: Long, status: P
// TODO Change to exception
if (input.javaClass != output.javaClass) {
//change output to input
changeP2P(output, BetterP2P.proxy.getP2PFromClass(input.javaClass)!!, player)
output = changeP2P(output, BetterP2P.proxy.getP2PFromClass(input.javaClass)!!, player) ?: return null
}
if (input == output) {
// Network loop
@@ -130,6 +130,13 @@ fun changeP2P(tunnel: PartP2PTunnel<*>, newType: TunnelInfo, player: EntityPlaye
if (BetterP2P.proxy.getP2PFromClass(tunnel.javaClass) == newType) {
return null
}
if (tunnel is PartP2PInterface) {
// For output, drop items.
val dropItems = mutableListOf<ItemStack>()
val patternsOut = tunnel.interfaceDuality.patterns as AppEngInternalInventory
dropItems.addAll(patternsOut)
Platform.spawnDrops(player.worldObj, tunnel.location.x, tunnel.location.y, tunnel.location.z, dropItems)
}
val host = tunnel.host
host.removePart(tunnel.side, false)
val dir = host.addPart(newType.stack, tunnel.side, player)