add dyable cable color functionality to paintable network cable

This commit is contained in:
PewPewCricket 2025-07-14 20:31:54 -05:00
parent da2abe281d
commit 02a4bf483e
5 changed files with 173 additions and 27 deletions

View File

@ -2,6 +2,8 @@ package com.hbm.blocks.network;
import api.hbm.block.IToolable; import api.hbm.block.IToolable;
import com.hbm.blocks.IBlockMultiPass; import com.hbm.blocks.IBlockMultiPass;
import com.hbm.blocks.ILookOverlay;
import com.hbm.handler.CompatHandler;
import com.hbm.lib.RefStrings; import com.hbm.lib.RefStrings;
import com.hbm.render.block.RenderBlockMultipass; import com.hbm.render.block.RenderBlockMultipass;
import com.hbm.tileentity.TileEntityLoadedBase; import com.hbm.tileentity.TileEntityLoadedBase;
@ -13,7 +15,9 @@ import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemDye;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager; import net.minecraft.network.NetworkManager;
@ -29,10 +33,16 @@ import li.cil.oc.api.Network;
import li.cil.oc.api.network.Visibility; import li.cil.oc.api.network.Visibility;
import cpw.mods.fml.common.Optional; import cpw.mods.fml.common.Optional;
import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Loader;
import li.cil.oc.api.network.SidedEnvironment;
import net.minecraftforge.common.util.ForgeDirection;
import li.cil.oc.api.internal.Colored;
import com.hbm.handler.CompatHandler.OCColors;
import net.minecraftforge.oredict.OreDictionary;
public class BlockOpenComputersCablePaintable extends BlockContainer implements IToolable, IBlockMultiPass { public class BlockOpenComputersCablePaintable extends BlockContainer implements IToolable, IBlockMultiPass {
@SideOnly(Side.CLIENT) protected IIcon overlay; @SideOnly(Side.CLIENT) protected IIcon overlay;
@SideOnly(Side.CLIENT) protected IIcon overlayColor;
public BlockOpenComputersCablePaintable() { public BlockOpenComputersCablePaintable() {
super(Material.iron); super(Material.iron);
@ -48,6 +58,7 @@ public class BlockOpenComputersCablePaintable extends BlockContainer implements
public void registerBlockIcons(IIconRegister reg) { public void registerBlockIcons(IIconRegister reg) {
this.blockIcon = reg.registerIcon(RefStrings.MODID + ":oc_cable_base"); this.blockIcon = reg.registerIcon(RefStrings.MODID + ":oc_cable_base");
this.overlay = reg.registerIcon(RefStrings.MODID + ":oc_cable_overlay"); this.overlay = reg.registerIcon(RefStrings.MODID + ":oc_cable_overlay");
this.overlayColor = reg.registerIcon(RefStrings.MODID + ":oc_cable_color");
} }
@Override @Override
@ -61,13 +72,29 @@ public class BlockOpenComputersCablePaintable extends BlockContainer implements
if(pipe.block != null) { if(pipe.block != null) {
if(RenderBlockMultipass.currentPass == 1) { if(RenderBlockMultipass.currentPass == 1) {
return this.overlay; return this.overlay;
} else if(RenderBlockMultipass.currentPass == 2) {
return this.overlayColor;
} else { } else {
return pipe.block.getIcon(side, pipe.meta); return pipe.block.getIcon(side, pipe.meta);
} }
} }
} }
return RenderBlockMultipass.currentPass == 1 ? this.overlay : this.blockIcon; return RenderBlockMultipass.currentPass == 1 ? this.overlay : RenderBlockMultipass.currentPass == 2 ? this.overlayColor : this.blockIcon;
}
@Override
@SideOnly(Side.CLIENT)
public int colorMultiplier(IBlockAccess world, int x, int y, int z) {
if (RenderBlockMultipass.currentPass == 2) {
TileEntityOpenComputersCablePaintable tile = (TileEntityOpenComputersCablePaintable) world.getTileEntity(x, y, z);
if (tile == null)
return 0xffffff;
return tile.getColor();
}
return 0xffffff;
} }
@Override @Override
@ -75,7 +102,10 @@ public class BlockOpenComputersCablePaintable extends BlockContainer implements
ItemStack stack = player.getHeldItem(); ItemStack stack = player.getHeldItem();
if(stack != null && stack.getItem() instanceof ItemBlock) { if (stack == null)
return super.onBlockActivated(world, x, y, z, player, side, fX, fY, fZ);
if (stack.getItem() instanceof ItemBlock) {
ItemBlock ib = (ItemBlock) stack.getItem(); ItemBlock ib = (ItemBlock) stack.getItem();
Block block = ib.field_150939_a; Block block = ib.field_150939_a;
@ -95,6 +125,21 @@ public class BlockOpenComputersCablePaintable extends BlockContainer implements
} }
} }
} }
} else {
boolean isDye = false;
int[] dicts = OreDictionary.getOreIDs(stack);
for (int dict : dicts) {
String dictName = OreDictionary.getOreName(dict);
if (dictName.equals("dye"))
isDye = true;
}
if (isDye) {
TileEntityOpenComputersCablePaintable tile = (TileEntityOpenComputersCablePaintable) world.getTileEntity(x, y, z);
tile.setColor(OCColors.fromDye(stack).getColor());
world.markBlockForUpdate(x, y, z);
tile.markDirty();
}
} }
return super.onBlockActivated(world, x, y, z, player, side, fX, fY, fZ); return super.onBlockActivated(world, x, y, z, player, side, fX, fY, fZ);
@ -123,7 +168,7 @@ public class BlockOpenComputersCablePaintable extends BlockContainer implements
@Override @Override
public int getPasses() { public int getPasses() {
return 2; return 3;
} }
@Override @Override
@ -131,9 +176,12 @@ public class BlockOpenComputersCablePaintable extends BlockContainer implements
return IBlockMultiPass.getRenderType(); return IBlockMultiPass.getRenderType();
} }
// WHY the fuck is this not compiling @Optional.InterfaceList({
@Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.Environment", modid = "OpenComputers")}) @Optional.Interface(iface = "li.cil.oc.api.network.Environment", modid = "OpenComputers"),
public static class TileEntityOpenComputersCablePaintable extends TileEntityLoadedBase implements Environment { @Optional.Interface(iface = "li.cil.oc.api.network.SidedEnvironment", modid = "OpenComputers"),
@Optional.Interface(iface = "li.cil.oc.api.network.Colored", modid = "OpenComputers")
})
public static class TileEntityOpenComputersCablePaintable extends TileEntityLoadedBase implements Environment, SidedEnvironment, Colored {
protected Node node; protected Node node;
protected boolean addedToNetwork = false; protected boolean addedToNetwork = false;
@ -142,6 +190,7 @@ public class BlockOpenComputersCablePaintable extends BlockContainer implements
private int meta; private int meta;
private Block lastBlock; private Block lastBlock;
private int lastMeta; private int lastMeta;
private OCColors color = OCColors.LIGHTGRAY;
public TileEntityOpenComputersCablePaintable() { public TileEntityOpenComputersCablePaintable() {
node = Network.newNode(this, Visibility.None).create(); node = Network.newNode(this, Visibility.None).create();
@ -181,6 +230,8 @@ public class BlockOpenComputersCablePaintable extends BlockContainer implements
this.block = id == 0 ? null : Block.getBlockById(id); this.block = id == 0 ? null : Block.getBlockById(id);
this.meta = nbt.getInteger("meta"); this.meta = nbt.getInteger("meta");
this.color = OCColors.fromInt(nbt.getInteger("dyeColor"));
if (node != null && node.host() == this) { if (node != null && node.host() == this) {
node.load(nbt.getCompoundTag("oc:node")); node.load(nbt.getCompoundTag("oc:node"));
} }
@ -192,6 +243,8 @@ public class BlockOpenComputersCablePaintable extends BlockContainer implements
if(block != null) nbt.setInteger("block", Block.getIdFromBlock(block)); if(block != null) nbt.setInteger("block", Block.getIdFromBlock(block));
nbt.setInteger("meta", meta); nbt.setInteger("meta", meta);
nbt.setInteger("dyeColor", color.getColor());
if (node != null && node.host() == this) { if (node != null && node.host() == this) {
final NBTTagCompound nodeNbt = new NBTTagCompound(); final NBTTagCompound nodeNbt = new NBTTagCompound();
node.save(nodeNbt); node.save(nodeNbt);
@ -212,6 +265,7 @@ public class BlockOpenComputersCablePaintable extends BlockContainer implements
if(nbt.hasKey("paintblock")) { if(nbt.hasKey("paintblock")) {
this.block = Block.getBlockById(nbt.getInteger("paintblock")); this.block = Block.getBlockById(nbt.getInteger("paintblock"));
this.meta = nbt.getInteger("paintmeta"); this.meta = nbt.getInteger("paintmeta");
this.color = OCColors.fromInt(nbt.getInteger("dyeColor"));
} }
} }
@ -221,6 +275,30 @@ public class BlockOpenComputersCablePaintable extends BlockContainer implements
return node; return node;
} }
public Node sidedNode(ForgeDirection side) {
if (side == ForgeDirection.UNKNOWN)
return null;
int neighborX = super.xCoord + side.offsetX;
int neighborY = super.yCoord + side.offsetY;
int neighborZ = super.zCoord + side.offsetZ;
TileEntity neighbor = worldObj.getTileEntity(neighborX, neighborY, neighborZ);
// If a cable does not support colors but is a valid cable block, allow it to connect regardless of color.
if (!(neighbor instanceof Colored)) {
if (neighbor instanceof Environment)
return node;
else
return null;
}
Colored cable = (Colored) neighbor;
if (cable.getColor() == color.getColor())
return node;
else
return null;
}
@Override @Override
public void onConnect(Node node) {} public void onConnect(Node node) {}
@ -240,5 +318,31 @@ public class BlockOpenComputersCablePaintable extends BlockContainer implements
super.invalidate(); super.invalidate();
if (node != null) node.remove(); if (node != null) node.remove();
} }
public boolean canConnect(net.minecraftforge.common.util.ForgeDirection side) {
if (side == ForgeDirection.UNKNOWN)
return false;
int neighborX = super.xCoord + side.offsetX;
int neighborY = super.yCoord + side.offsetY;
int neighborZ = super.zCoord + side.offsetZ;
TileEntity neighbor = worldObj.getTileEntity(neighborX, neighborY, neighborZ);
// If a cable does not support colors but is a valid cable block, allow it to connect regardless of color.
if (!(neighbor instanceof Colored)) {
return neighbor instanceof Environment;
}
Colored cable = (Colored) neighbor;
return cable.getColor() == color.getColor();
}
public void setColor(int newColor) {
color = OCColors.fromInt(newColor);
}
public int getColor() {
return color.getColor();
}
} }
} }

View File

@ -1,11 +1,13 @@
package com.hbm.handler; package com.hbm.handler;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
import com.hbm.blocks.network.BlockOpenComputersCablePaintable;
import com.hbm.inventory.RecipesCommon; import com.hbm.inventory.RecipesCommon;
import com.hbm.inventory.fluid.FluidType; import com.hbm.inventory.fluid.FluidType;
import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.Fluids;
import com.hbm.lib.RefStrings; import com.hbm.lib.RefStrings;
import com.hbm.main.MainRegistry; import com.hbm.main.MainRegistry;
import com.hbm.util.ItemStackUtil;
import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Optional; import cpw.mods.fml.common.Optional;
import li.cil.oc.api.Items; import li.cil.oc.api.Items;
@ -15,6 +17,7 @@ import li.cil.oc.api.machine.Context;
import li.cil.oc.api.network.*; import li.cil.oc.api.network.*;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.oredict.OreDictionary;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -108,27 +111,66 @@ public class CompatHandler {
} }
} }
/** /**
* Simple enum for mapping OC color ordinals to a nicer format for adding new disks. * Simple enum for mapping OC color ordinals to a nicer format for adding new disks.
*/ */
public enum OCColors { public enum OCColors {
BLACK, //0x444444 BLACK(0x444444, "dyeBlack"),
RED, //0xB3312C RED(0xB3312C, "dyeRed"),
GREEN, //0x339911 GREEN(0x339911, "dyeGreen"),
BROWN, //0x51301A BROWN(0x51301A, "dyeBrown"),
BLUE, //0x6666FF BLUE(0x6666FF, "dyeBlue"),
PURPLE, //0x7B2FBE PURPLE(0x7B2FBE, "dyePurple"),
CYAN, //0x66FFFF CYAN(0x66FFFF, "dyeCyan"),
LIGHTGRAY, //0xABABAB LIGHTGRAY(0xABABAB, "dyeLightGray"),
GRAY, //0x666666 GRAY(0x666666, "dyeGray"),
PINK, //0xD88198 PINK(0xD88198, "dyePink"),
LIME, //0x66FF66 LIME(0x66FF66, "dyeLime"),
YELLOW, //0xFFFF66 YELLOW(0xFFFF66, "dyeYellow"),
LIGHTBLUE, //0xAAAAFF LIGHTBLUE(0xAAAAFF, "dyeLightBlue"),
MAGENTA, //0xC354CD MAGENTA(0xC354CD, "dyeMagenta"),
ORANGE, //0xEB8844 ORANGE(0xEB8844, "dyeOrange"),
WHITE //0xF0F0F0 WHITE(0xF0F0F0, "dyeWhite"),
} NONE(0x0, "");
private final int color;
private final String dictName;
OCColors(int color, String dictName) {
this.color = color;
this.dictName = dictName;
}
public int getColor() {
return color;
}
public static OCColors fromInt(int intColor) {
for (OCColors iColor : OCColors.values()) {
if (intColor == iColor.getColor())
return iColor;
}
return OCColors.NONE;
}
public static OCColors fromDye(ItemStack stack) {
List<String> oreNames = ItemStackUtil.getOreDictNames(stack);
for(String dict : oreNames) {
if(!(dict.length() > 3) || !dict.startsWith("dye"))
continue;
for (OCColors color : OCColors.values()) {
if(!color.dictName.equals(dict))
continue;
return color;
}
}
return OCColors.NONE;
}
}
// Where all disks are stored with their name and `FloppyDisk` class. // Where all disks are stored with their name and `FloppyDisk` class.
public static HashMap<String, FloppyDisk> disks = new HashMap<>(); public static HashMap<String, FloppyDisk> disks = new HashMap<>();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 624 B

After

Width:  |  Height:  |  Size: 612 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 340 B

After

Width:  |  Height:  |  Size: 139 B