Fix weird behavior with multiple RS controller IDs, closes #59
Unfinished control panels can be copied like components can now (To create multiple panels with exact same height and angle)
This commit is contained in:
parent
2f02fc5044
commit
c84a0476fd
|
@ -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<ControlPanelNetwork.RSChannelState> 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<IRecipe> 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<inv.getHeight()) {
|
||||
ItemStack below = inv.getStackInRowAndColumn(x, y + 1);
|
||||
PanelComponent pc2 = ItemPanelComponent.componentFromStack(below);
|
||||
if (pc2 == null || pc2.getClass() != pc1.getClass()) {
|
||||
if (foundPanel) {
|
||||
if (!isUnfinishedPanel(below)) {
|
||||
return false;
|
||||
}
|
||||
} else if (pc2 == null || pc2.getClass() != pc1.getClass()) {
|
||||
return false;
|
||||
}
|
||||
found = true;
|
||||
|
@ -97,7 +105,8 @@ public class RecipeComponentCopy extends IForgeRegistryEntry.Impl<IRecipe> 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<IRecipe> 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() {
|
||||
|
|
Loading…
Reference in New Issue