mirror of
https://github.com/GTNewHorizons/BetterP2P.git
synced 2026-10-26 14:24:05 +00:00
Fix client accessing the server world when it shouldn't
Instead, the server now sends a packet with that information In addition, fix P2P outlines being displayed when the player isn't in the same dimension
This commit is contained in:
1 parent
e0128df957
commit
4789b5938b
5 files changed
+88
-49
No files matched your search
@@ -238,7 +238,11 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
|
||||
ClientCache.selectedFacing = selectedInfo?.facing
|
||||
}
|
||||
ClientCache.positions.clear()
|
||||
ClientCache.positions.addAll(infos.sorted.filter { it.frequency == selectedInfo?.frequency && it != selectedInfo }.map { arrayListOf(it.posX, it.posY, it.posZ) to it.facing })
|
||||
ClientCache.positions.addAll(infos.sorted.filter {
|
||||
it.frequency == selectedInfo?.frequency &&
|
||||
it != selectedInfo &&
|
||||
it.dim == mc.thePlayer.dimension
|
||||
}.map { arrayListOf(it.posX, it.posY, it.posZ) to it.facing })
|
||||
}
|
||||
|
||||
override fun mouseClicked(mouseX: Int, mouseY: Int, mouseButton: Int) {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.projecturanus.betterp2p.client.gui
|
||||
|
||||
import appeng.api.parts.IPart
|
||||
import appeng.api.parts.IPartItem
|
||||
import appeng.api.parts.PartItemStack
|
||||
import appeng.me.GridNode
|
||||
import appeng.parts.p2p.PartP2PTunnel
|
||||
@@ -9,6 +11,8 @@ import com.projecturanus.betterp2p.network.P2PInfo
|
||||
import com.projecturanus.betterp2p.network.hashP2P
|
||||
import net.minecraft.client.gui.GuiButton
|
||||
import net.minecraft.client.resources.I18n
|
||||
import net.minecraft.init.Blocks
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.util.IIcon
|
||||
import net.minecraftforge.common.DimensionManager
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
@@ -26,34 +30,13 @@ class InfoWrapper(info: P2PInfo) {
|
||||
val dim: Int = info.world
|
||||
val facing: ForgeDirection = info.facing
|
||||
val output: Boolean = info.output
|
||||
val tile: TileCableBus? by lazy {
|
||||
DimensionManager.getWorld(dim)?.getTileEntity(posX, posY, posZ) as? TileCableBus
|
||||
}
|
||||
|
||||
val icon: IIcon? by lazy {
|
||||
(tile?.getPart(info.facing) as? PartP2PTunnel<*>)?.typeTexture
|
||||
}
|
||||
val overlay: IIcon? by lazy {
|
||||
tile?.getPart(info.facing)?.getItemStack(PartItemStack.Wrench)?.iconIndex
|
||||
}
|
||||
val icon: IIcon
|
||||
val overlay: IIcon
|
||||
|
||||
val typeName: String by lazy {
|
||||
val item = tile?.getPart(info.facing)?.getItemStack(PartItemStack.Wrench)
|
||||
I18n.format(item?.getItem()?.getItemStackDisplayName(item)?.split(" - ")?.getOrNull(1)
|
||||
?: "§c<Something broke...>")
|
||||
}
|
||||
val typeName: String
|
||||
|
||||
val description: String by lazy {
|
||||
buildString {
|
||||
append("Type: ")
|
||||
append(typeName)
|
||||
append(" - ")
|
||||
if (output)
|
||||
append(I18n.format("gui.advanced_memory_card.desc.mode.output"))
|
||||
else
|
||||
append(I18n.format("gui.advanced_memory_card.desc.mode.input"))
|
||||
}
|
||||
}
|
||||
val description: String
|
||||
val freqDisplay: String by lazy {
|
||||
buildString {
|
||||
append(I18n.format("item.advanced_memory_card.selected"))
|
||||
@@ -70,28 +53,14 @@ class InfoWrapper(info: P2PInfo) {
|
||||
}
|
||||
}
|
||||
|
||||
val hoverInfo: List<String> by lazy {
|
||||
val online = (tile?.getPart(info.facing) as? PartP2PTunnel<*>)?.proxy?.isPowered
|
||||
val list = mutableListOf(
|
||||
"§b$typeName§r",
|
||||
"§e" + I18n.format("gui.advanced_memory_card.pos", info.posX, info.posY, info.posZ),
|
||||
"§e" + I18n.format("gui.advanced_memory_card.side", info.facing.name),
|
||||
"§e" + I18n.format("gui.advanced_memory_card.dim", info.world)
|
||||
)
|
||||
if (error || frequency == 0L) {
|
||||
list.add("§c" + I18n.format("gui.advanced_memory_card.p2p_status.unbound"))
|
||||
} else {
|
||||
list.add("§a" + I18n.format("gui.advanced_memory_card.p2p_status.bound"))
|
||||
}
|
||||
if (online != true) list.add("§c" + I18n.format("gui.advanced_memory_card.p2p_status.offline"))
|
||||
list
|
||||
}
|
||||
val hoverInfo: List<String>
|
||||
|
||||
val channels: String? by lazy {
|
||||
val c = ((tile?.getPart(facing) as? PartP2PTunnelME)?.externalFacingNode as? GridNode)?.usedChannels()
|
||||
if (c != null) {
|
||||
I18n.format("gui.advanced_memory_card.extra.channel", c)
|
||||
} else null
|
||||
if (info.channels >= 0) {
|
||||
I18n.format("gui.advanced_memory_card.extra.channel", info.channels)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
var name: String = info.name
|
||||
@@ -101,6 +70,51 @@ class InfoWrapper(info: P2PInfo) {
|
||||
val bindButton = GuiButton(0, 0, 0, 34, 20, I18n.format("gui.advanced_memory_card.bind"))
|
||||
val renameButton = GuiButton(0, 0, 0, 0, 0,"")
|
||||
|
||||
init {
|
||||
val p: IPart? = (info.stack.item as? IPartItem)?.createPartFromItemStack(info.stack)
|
||||
if (p is PartP2PTunnel<*>) {
|
||||
icon = p.typeTexture
|
||||
overlay = info.stack.iconIndex
|
||||
typeName =
|
||||
info.stack.item.getItemStackDisplayName(info.stack).split(" - ").getOrNull(1)
|
||||
?: "§c<Something broke...>"
|
||||
description = buildString {
|
||||
append("Type: ")
|
||||
append(typeName)
|
||||
append(" - ")
|
||||
if (output)
|
||||
append(I18n.format("gui.advanced_memory_card.desc.mode.output"))
|
||||
else
|
||||
append(I18n.format("gui.advanced_memory_card.desc.mode.input"))
|
||||
}
|
||||
val online = info.hasChannel
|
||||
hoverInfo = mutableListOf(
|
||||
"§bP2P - $typeName",
|
||||
"§e" + I18n.format("gui.advanced_memory_card.pos", info.posX, info.posY, info.posZ),
|
||||
"§e" + I18n.format("gui.advanced_memory_card.side", info.facing.name),
|
||||
"§e" + I18n.format("gui.advanced_memory_card.dim", info.world)
|
||||
)
|
||||
if (error || frequency == 0L) {
|
||||
hoverInfo.add("§c" + I18n.format("gui.advanced_memory_card.p2p_status.unbound"))
|
||||
} else {
|
||||
hoverInfo.add("§a" + I18n.format("gui.advanced_memory_card.p2p_status.bound"))
|
||||
}
|
||||
if (!online) hoverInfo.add("§c" + I18n.format("gui.advanced_memory_card.p2p_status.offline"))
|
||||
} else {
|
||||
icon = Blocks.air.getIcon(0, 0)
|
||||
overlay = Blocks.air.getIcon(0, 0)
|
||||
typeName = "§c<Something broke...>"
|
||||
description = "§c<Unknown>"
|
||||
hoverInfo = mutableListOf(
|
||||
"§b$typeName§r",
|
||||
"§e" + I18n.format("gui.advanced_memory_card.pos", info.posX, info.posY, info.posZ),
|
||||
"§e" + I18n.format("gui.advanced_memory_card.side", info.facing.name),
|
||||
"§e" + I18n.format("gui.advanced_memory_card.dim", info.world)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
override fun hashCode(): Int {
|
||||
return code.hashCode()
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.projecturanus.betterp2p.network
|
||||
|
||||
import com.projecturanus.betterp2p.client.gui.InfoWrapper
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
class P2PInfo(val frequency: Long,
|
||||
@@ -11,7 +12,9 @@ class P2PInfo(val frequency: Long,
|
||||
val facing: ForgeDirection,
|
||||
val name: String,
|
||||
val output: Boolean,
|
||||
val hasChannel: Boolean) {
|
||||
val hasChannel: Boolean,
|
||||
val channels: Int, //# of channels if ME P2P, or -1 else
|
||||
val stack: ItemStack) {
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return hashP2P(posX, posY, posZ, facing.ordinal, world).hashCode()
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.projecturanus.betterp2p.network
|
||||
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage
|
||||
import io.netty.buffer.ByteBuf
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
fun readInfo(buf: ByteBuf): P2PInfo {
|
||||
@@ -16,7 +18,15 @@ fun readInfo(buf: ByteBuf): P2PInfo {
|
||||
for (i in 0..nameLength) {
|
||||
name += buf.readChar()
|
||||
}
|
||||
return P2PInfo(freq, posX, posY, posZ,world, facing, name, buf.readBoolean(), buf.readBoolean())
|
||||
val output = buf.readBoolean()
|
||||
val hasChannel = buf.readBoolean()
|
||||
val channels = buf.readInt()
|
||||
val compound = NBTTagCompound()
|
||||
compound.setShort("id", buf.readShort())
|
||||
compound.setShort("Damage", buf.readShort())
|
||||
compound.setShort("Count", 1)
|
||||
val stack = ItemStack.loadItemStackFromNBT(compound);
|
||||
return P2PInfo(freq, posX, posY, posZ,world, facing, name, output, hasChannel, channels, stack)
|
||||
}
|
||||
|
||||
fun writeInfo(buf: ByteBuf, info: P2PInfo) {
|
||||
@@ -32,6 +42,11 @@ fun writeInfo(buf: ByteBuf, info: P2PInfo) {
|
||||
}
|
||||
buf.writeBoolean(info.output)
|
||||
buf.writeBoolean(info.hasChannel)
|
||||
buf.writeInt(info.channels)
|
||||
val compound = NBTTagCompound()
|
||||
info.stack.writeToNBT(compound)
|
||||
buf.writeShort(compound.getShort("id").toInt())
|
||||
buf.writeShort(compound.getShort("Damage").toInt())
|
||||
}
|
||||
|
||||
class S2CRefreshInfo(var infos: List<P2PInfo> = emptyList()) : IMessage {
|
||||
|
||||
@@ -7,6 +7,7 @@ import appeng.api.parts.IPart
|
||||
import appeng.api.parts.PartItemStack
|
||||
import appeng.helpers.DualityInterface
|
||||
import appeng.me.GridAccessException
|
||||
import appeng.me.GridNode
|
||||
import appeng.parts.automation.UpgradeInventory
|
||||
import appeng.parts.p2p.PartP2PInterface
|
||||
import appeng.parts.p2p.PartP2PTunnel
|
||||
@@ -143,4 +144,6 @@ val PartP2PTunnel<*>.hasChannel
|
||||
get() = isPowered && isActive
|
||||
|
||||
fun PartP2PTunnel<*>.toInfo()
|
||||
= P2PInfo(frequency, location.x, location.y, location.z, location.dimension, side, customName, isOutput, hasChannel)
|
||||
= P2PInfo(frequency, location.x, location.y, location.z, location.dimension, side,
|
||||
customName, isOutput, hasChannel, (externalFacingNode as? GridNode)?.usedChannels() ?: -1,
|
||||
getItemStack(PartItemStack.Wrench))
|
||||
Reference in new issue
Block a user