Skip to content

Commit

Permalink
Add colors to wireless
Browse files Browse the repository at this point in the history
Currently, there is no way to use this feature since the color applciator
doesn't do what we want it to. Will need some changes
  • Loading branch information
firenoo committed Jul 26, 2023
1 parent 0dca4be commit 192ddf0
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dependencies {
api('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-228-GTNH:dev')
api('com.github.GTNewHorizons:bdlib:1.9.8-GTNH:dev')

compileOnly('com.github.GTNewHorizons:waila:1.6.0:dev') {transitive=false}
implementation('com.github.GTNewHorizons:waila:1.6.0:dev') {transitive=false}
compileOnly('com.github.GTNewHorizons:NotEnoughItems:2.3.55-GTNH:dev')
compileOnly('com.github.GTNewHorizons:BuildCraft:7.1.34:dev')
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,27 @@ package net.bdew.ae2stuff.machines.wireless

import java.util
import appeng.api.AEApi
import appeng.api.implementations.tiles.IColorableTile
import appeng.api.networking.{GridFlags, IGridConnection}
import appeng.api.util.AEColor
import appeng.me.helpers.AENetworkProxy
import net.bdew.ae2stuff.AE2Stuff
import net.bdew.ae2stuff.grid.{GridTile, VariableIdlePower}
import net.bdew.lib.block.BlockRef
import net.bdew.lib.data.base.{TileDataSlots, UpdateKind}
import net.bdew.lib.multiblock.data.DataSlotPos
import net.minecraft.block.Block
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.world.World
import net.minecraftforge.common.util.ForgeDirection

class TileWireless extends TileDataSlots with GridTile with VariableIdlePower {
class TileWireless
extends TileDataSlots
with GridTile
with VariableIdlePower
with IColorableTile {
val cfg = MachineWireless

val link =
Expand All @@ -33,6 +42,7 @@ class TileWireless extends TileDataSlots with GridTile with VariableIdlePower {
lazy val myPos = BlockRef.fromTile(this)

var customName: String = ""
var color: AEColor = AEColor.Transparent
def isLinked = link.isDefined
def getLink = link flatMap (_.getTile[TileWireless](worldObj))

Expand Down Expand Up @@ -151,10 +161,32 @@ class TileWireless extends TileDataSlots with GridTile with VariableIdlePower {
if (customName != "") {
t.setString("CustomName", customName)
}
t.setString("CustomName", customName)
t.setShort("Color", color.ordinal().toShort)
}

override def doLoad(kind: UpdateKind.Value, t: NBTTagCompound): Unit = {
super.doLoad(kind, t)
this.customName = t.getString("CustomName")
if (!t.hasKey("Color")) {
t.setShort("Color", AEColor.Transparent.ordinal().toShort)
}
val colorIdx = t.getShort("Color").toInt
this.color = AEColor.values().apply(colorIdx)
}

override def recolourBlock(
side: ForgeDirection,
colour: AEColor,
who: EntityPlayer
): Boolean = {
this.color = colour
true
}

override def getConnectableSides: util.EnumSet[ForgeDirection] =
super.getConnectableSides
override def getColor: AEColor = color

override def getGridColor: AEColor = color
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package net.bdew.ae2stuff.waila

import appeng.api.config.PowerMultiplier
import appeng.api.util.AEColor
import mcp.mobius.waila.api.{IWailaConfigHandler, IWailaDataAccessor}
import net.bdew.ae2stuff.machines.wireless.TileWireless
import net.bdew.lib.block.BlockRef
Expand Down Expand Up @@ -44,14 +45,19 @@ object WailaWirelessDataProvider
te.connection.getUsedChannels
else 0),
"power" -> PowerMultiplier.CONFIG.multiply(te.getIdlePowerUsage),
"name" -> te.customName
"name" -> te.customName,
"color" -> te.color.ordinal()
)
)
} else {
tag.setTag("wireless_waila", NBT(
"connected" -> false,
"name" -> te.customName
))
tag.setTag(
"wireless_waila",
NBT(
"connected" -> false,
"name" -> te.customName,
"color" -> te.color.ordinal()
)
)
}
tag
}
Expand All @@ -65,6 +71,7 @@ object WailaWirelessDataProvider
if (acc.getNBTData.hasKey("wireless_waila")) {
val data = acc.getNBTData.getCompoundTag("wireless_waila")
val name = data.getString("name")
val color = data.getInteger("color")
if (data.getBoolean("connected")) {
val pos = BlockRef.fromNBT(data.getCompoundTag("target"))
List(
Expand All @@ -78,10 +85,21 @@ object WailaWirelessDataProvider
"ae2stuff.waila.wireless.power",
DecFormat.short(data.getDouble("power"))
)
).++(if (name != "") Misc.toLocalF("ae2stuff.waila.wireless.name", name)::Nil else Nil)
)
.++(if (name != "") {
Misc.toLocalF("ae2stuff.waila.wireless.name", name) :: Nil
} else Nil)
.++(if (color != AEColor.Transparent.ordinal()) {
Misc.toLocal(AEColor.values().apply(color).unlocalizedName) :: Nil
} else Nil)
} else {
List(Misc.toLocal("ae2stuff.waila.wireless.notconnected"))
.++(if (name != "") Misc.toLocalF("ae2stuff.waila.wireless.name", name)::Nil else Nil)
.++(if (name != "") {
Misc.toLocalF("ae2stuff.waila.wireless.name", name) :: Nil
} else Nil)
.++(if (color != AEColor.Transparent.ordinal()) {
Misc.toLocal(AEColor.values().apply(color).unlocalizedName) :: Nil
} else Nil)
}
} else List.empty
}
Expand Down

0 comments on commit 192ddf0

Please sign in to comment.