Skip to content

Commit

Permalink
Wrenching a wireless connector keeps its color. (#19)
Browse files Browse the repository at this point in the history
* Wrenching keeps wireless connector color.

* Clean up unused imports.

* Magic number -> named constant.

* Added shapeless recipe to convert colored connector back to colorless.

* Cleanup.

* Add getPickBlock (middle-click) support.

* Swap magenta and purple colors.

* Pedantry.

* Pedantry.
  • Loading branch information
AbdielKavash authored Nov 5, 2024
1 parent ae71ed5 commit bd5f0cb
Show file tree
Hide file tree
Showing 21 changed files with 109 additions and 19 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/main/scala/net/bdew/ae2stuff/Recipes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package net.bdew.ae2stuff

import cpw.mods.fml.common.registry.GameRegistry
import net.bdew.ae2stuff.items.{AdvWirelessKit, ItemWirelessKit}
import net.bdew.ae2stuff.machines.wireless.BlockWireless
import net.minecraft.item.ItemStack
import net.minecraftforge.oredict.OreDictionary

object Recipes {
def load(): Unit = {
Expand All @@ -15,5 +17,9 @@ object Recipes {
new ItemStack(ItemWirelessKit),
ItemWirelessKit
)
GameRegistry.addShapelessRecipe(
new ItemStack(BlockWireless),
new ItemStack(BlockWireless, 1, OreDictionary.WILDCARD_VALUE)
)
}
}
122 changes: 103 additions & 19 deletions src/main/scala/net/bdew/ae2stuff/machines/wireless/BlockWireless.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,78 @@ import appeng.api.util.AEColor
import appeng.core.AppEng
import appeng.core.sync.GuiBridge
import appeng.items.tools.quartz.ToolQuartzCuttingKnife
import appeng.util.Platform
import cpw.mods.fml.relauncher.{Side, SideOnly}
import net.bdew.ae2stuff.misc.{BlockWrenchable, MachineMaterial}
import net.bdew.lib.Misc
import net.bdew.lib.block.{HasTE, SimpleBlock}
import net.bdew.lib.block.{HasItemBlock, HasTE, ItemBlockTooltip, SimpleBlock}
import net.minecraft.block.Block
import net.minecraft.client.renderer.texture.IIconRegister
import net.minecraft.creativetab.CreativeTabs
import net.minecraft.entity.EntityLivingBase
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.ItemStack
import net.minecraft.util.IIcon
import net.minecraft.item.{Item, ItemStack}
import net.minecraft.util.{IIcon, MovingObjectPosition}
import net.minecraft.world.{IBlockAccess, World}
import net.minecraftforge.common.util.ForgeDirection

import java.util

object BlockWireless
extends SimpleBlock("Wireless", MachineMaterial)
with HasTE[TileWireless]
with BlockWrenchable {
with BlockWrenchable
with HasItemBlock {
override val TEClass = classOf[TileWireless]
override val ItemBlockClass: Class[_ <: ItemBlockWireless] =
classOf[ItemBlockWireless]

setHardness(1)

override def getDrops(
world: World,
x: Int,
y: Int,
z: Int,
metadata: Int,
fortune: Int
): util.ArrayList[ItemStack] = {
val stack = new ItemStack(this)
val te = getTE(world, x, y, z)
if (te.color != AEColor.Transparent) {
stack.setItemDamage(te.color.ordinal() + 1)
}
val drops = new util.ArrayList[ItemStack]()
drops.add(stack)
drops
}

override def getSubBlocks(
itemIn: Item,
tab: CreativeTabs,
list: util.List[_]
): Unit = {
for (meta <- 0 to 16) {
list
.asInstanceOf[util.List[ItemStack]]
.add(new ItemStack(itemIn, 1, meta))
}
}

override def getPickBlock(
target: MovingObjectPosition,
world: World,
x: Int,
y: Int,
z: Int,
player: EntityPlayer
): ItemStack = {
val stack = new ItemStack(this)
val te = getTE(world, x, y, z)
if (te.color != AEColor.Transparent) {
stack.setItemDamage(te.color.ordinal() + 1)
}
stack
}

override def breakBlock(
world: World,
x: Int,
Expand All @@ -55,12 +105,17 @@ object BlockWireless
player: EntityLivingBase,
stack: ItemStack
): Unit = {
val te = getTE(world, x, y, z)
if (player.isInstanceOf[EntityPlayer]) {
val te = getTE(world, x, y, z)
te.placingPlayer = player.asInstanceOf[EntityPlayer]
if (stack != null && stack.hasDisplayName) {
}
if (stack != null) {
if (stack.hasDisplayName) {
te.customName = stack.getDisplayName
}
if (stack.getItemDamage > 0) {
te.color = AEColor.values().apply(stack.getItemDamage - 1)
}
}
}

Expand Down Expand Up @@ -94,7 +149,7 @@ object BlockWireless
}

var icon_on: List[IIcon] = null
var icon_off: IIcon = null
var icon_off: List[IIcon] = null

@SideOnly(Side.CLIENT)
override def getIcon(
Expand All @@ -104,20 +159,22 @@ object BlockWireless
z: Int,
side: Int
): IIcon = {
val te = worldIn.getTileEntity(x, y, z)
val te = getTE(worldIn, x, y, z)
val meta = worldIn.getBlockMetadata(x, y, z)

if (te.isInstanceOf[TileWireless]) {
if (meta > 0) {
val color = te.asInstanceOf[TileWireless].color.ordinal()
return icon_on.apply(color)
}
if (meta > 0) {
icon_on.apply(te.color.ordinal())
} else {
icon_off.apply(te.color.ordinal())
}
icon_off
}

@SideOnly(Side.CLIENT)
override def getIcon(side: Int, meta: Int): IIcon = {
icon_on.apply(AEColor.Transparent.ordinal())
if (meta == 0) {
icon_on.apply(AEColor.Transparent.ordinal())
} else {
icon_on.apply(meta - 1)
}
}

@SideOnly(Side.CLIENT)
Expand All @@ -128,6 +185,33 @@ object BlockWireless
reg.registerIcon(Misc.iconName(modId, name, "side_on" + index))
)
.toList
icon_off = reg.registerIcon(Misc.iconName(modId, name, "side_off"))
icon_off = index
.map(index =>
reg.registerIcon(Misc.iconName(modId, name, "side_off" + index))
)
.toList
}
}

class ItemBlockWireless(b: Block) extends ItemBlockTooltip(b) {

setHasSubtypes(true)

override def addInformation(
stack: ItemStack,
player: EntityPlayer,
list: util.List[_],
advanced: Boolean
): Unit = {
super.addInformation(stack, player, list, advanced)
if (stack.getItemDamage > 0) {
list
.asInstanceOf[util.List[String]]
.add(
Misc.toLocal(
AEColor.values().apply(stack.getItemDamage - 1).unlocalizedName
)
)
}
}
}

0 comments on commit bd5f0cb

Please sign in to comment.