diff --git a/src/main/java/malte0811/industrialwires/blocks/controlpanel/TileEntityRSPanel.java b/src/main/java/malte0811/industrialwires/blocks/controlpanel/TileEntityRSPanel.java index 72539f8..c9b3204 100644 --- a/src/main/java/malte0811/industrialwires/blocks/controlpanel/TileEntityRSPanel.java +++ b/src/main/java/malte0811/industrialwires/blocks/controlpanel/TileEntityRSPanel.java @@ -41,8 +41,13 @@ public abstract class TileEntityRSPanel extends TileEntityGeneralCP implements I } private void updateChannelsArray() { - for (byte i = 0;i<16;i++) { - channels[i] = new ControlPanelNetwork.RSChannel(controller, i); + byte[] oldIn = currInput; + if (world == null || !world.isRemote) { + panelNetwork.removeIOFor(this); + for (byte i = 0; i < 16; i++) { + channels[i] = new ControlPanelNetwork.RSChannel(controller, i); + } + setNetworkAndInit(panelNetwork); } } @@ -58,12 +63,14 @@ public abstract class TileEntityRSPanel extends TileEntityGeneralCP implements I @Override public void writeNBT(NBTTagCompound nbt, boolean updatePacket) { nbt.setByteArray("out", this.out); + nbt.setByteArray("in", this.currInput); nbt.setInteger("rsId", controller); } @Override public void readNBT(NBTTagCompound nbt, boolean updatePacket) { out = nbt.getByteArray("out"); + currInput = nbt.getByteArray("in"); controller = nbt.getInteger("rsId"); updateChannelsArray(); } @@ -90,7 +97,6 @@ public abstract class TileEntityRSPanel extends TileEntityGeneralCP implements I @Override public void setNetworkAndInit(ControlPanelNetwork newNet) { super.setNetworkAndInit(newNet); - onInputChanged(currInput); Consumer listener = state -> { if (out[state.getColor()] != state.getStrength()) { out[state.getColor()] = state.getStrength(); @@ -98,6 +104,9 @@ public abstract class TileEntityRSPanel extends TileEntityGeneralCP implements I } }; panelNetwork.addListener(this, listener, channels); + byte[] oldIn = currInput; + currInput = new byte[16]; + onInputChanged(oldIn); } @Override @@ -109,6 +118,7 @@ public abstract class TileEntityRSPanel extends TileEntityGeneralCP implements I setNetworkAndInit(panelNetwork); IBlockState state = world.getBlockState(pos); world.notifyBlockUpdate(pos, state, state, 3); + updateChannelsArray(); } } diff --git a/src/main/java/malte0811/industrialwires/controlpanel/ControlPanelNetwork.java b/src/main/java/malte0811/industrialwires/controlpanel/ControlPanelNetwork.java index 9ef9f67..ba6e801 100644 --- a/src/main/java/malte0811/industrialwires/controlpanel/ControlPanelNetwork.java +++ b/src/main/java/malte0811/industrialwires/controlpanel/ControlPanelNetwork.java @@ -19,6 +19,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import malte0811.industrialwires.blocks.controlpanel.TileEntityGeneralCP; import malte0811.industrialwires.util.MiscUtils; +import net.minecraft.item.EnumDyeColor; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagByte; import net.minecraft.nbt.NBTTagInt; @@ -336,6 +337,11 @@ public class ControlPanelNetwork { return result; } + @Override + public String toString() { + return "Channel " + EnumDyeColor.byMetadata(color).getName() + " on controller ID " + controller; + } + public boolean isValid() { return controller>=0 && color >= 0; } @@ -398,7 +404,11 @@ public class ControlPanelNetwork { int result = channel.hashCode(); result = 31 * result + strength; return result; + } + @Override + public String toString() { + return channel + ": " + strength; } } } diff --git a/src/main/java/malte0811/industrialwires/crafting/RecipeComponentCopy.java b/src/main/java/malte0811/industrialwires/crafting/RecipeComponentCopy.java index 60fdcdf..fb5e819 100644 --- a/src/main/java/malte0811/industrialwires/crafting/RecipeComponentCopy.java +++ b/src/main/java/malte0811/industrialwires/crafting/RecipeComponentCopy.java @@ -16,9 +16,11 @@ package malte0811.industrialwires.crafting; import blusunrize.immersiveengineering.api.ApiUtils; import malte0811.industrialwires.IndustrialWires; +import malte0811.industrialwires.blocks.controlpanel.BlockTypes_Panel; import malte0811.industrialwires.controlpanel.PanelComponent; import malte0811.industrialwires.items.ItemPanelComponent; import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; import net.minecraft.util.NonNullList; @@ -35,21 +37,27 @@ public class RecipeComponentCopy extends IForgeRegistryEntry.Impl imple boolean found = false; int foundX = -1; int foundY = -1; + boolean foundPanel = false; for (int x = 0; x < inv.getWidth(); x++) { for (int y = 0; y < inv.getHeight(); y++) { ItemStack here = inv.getStackInRowAndColumn(x, y); PanelComponent pc1 = ItemPanelComponent.componentFromStack(here); - if (pc1!=null) { + if (pc1 != null || isUnfinishedPanel(here)) { if (x==foundX&&y==foundY) { continue; } if (found) { return false; } + foundPanel = pc1 == null; if (y+1 imple for (int x = 0; x < inv.getWidth(); x++) { for (int y = 0; y < inv.getHeight() - 1; y++) { ItemStack here = inv.getStackInRowAndColumn(x, y); - if (!here.isEmpty() && here.getItem() == IndustrialWires.panelComponent) { + if (here.getItem() == IndustrialWires.panelComponent + || isUnfinishedPanel(here)) { return new int[]{x, y}; } } @@ -105,6 +114,11 @@ public class RecipeComponentCopy extends IForgeRegistryEntry.Impl imple return null; } + private boolean isUnfinishedPanel(ItemStack stack) { + return stack.getItem() == Item.getItemFromBlock(IndustrialWires.panel) + && stack.getMetadata() == BlockTypes_Panel.UNFINISHED.ordinal(); + } + @Override public boolean isDynamic() {