Fixed panels not updating when a connection via panel connectors is broken or placed
(back-port from 1.11)
This commit is contained in:
parent
7a5edfa825
commit
6c66ce648a
|
@ -23,6 +23,7 @@ import malte0811.industrialWires.IndustrialWires;
|
|||
import malte0811.industrialWires.blocks.BlockIWBase;
|
||||
import malte0811.industrialWires.blocks.IMetaEnum;
|
||||
import malte0811.industrialWires.controlpanel.PanelComponent;
|
||||
import malte0811.industrialWires.controlpanel.PanelUtils;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
|
@ -213,4 +214,33 @@ public class BlockPanel extends BlockIWBase implements IMetaEnum {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(@Nonnull World worldIn, @Nonnull BlockPos pos, @Nonnull IBlockState state) {
|
||||
super.breakBlock(worldIn, pos, state);
|
||||
//break connections
|
||||
List<BlockPos> panels = PanelUtils.discoverPanelParts(worldIn, pos, 11 * 11 * 11);
|
||||
for (BlockPos p : panels) {
|
||||
if (!p.equals(pos)) {
|
||||
TileEntity panelPart = worldIn.getTileEntity(p);
|
||||
if (panelPart instanceof TileEntityPanel) {
|
||||
((TileEntityPanel) panelPart).removeAllRSCons();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
|
||||
super.onBlockAdded(worldIn, pos, state);
|
||||
List<BlockPos> panels = PanelUtils.discoverPanelParts(worldIn, pos, 11 * 11 * 11);
|
||||
for (BlockPos p : panels) {
|
||||
if (!p.equals(pos)) {
|
||||
TileEntity panelPart = worldIn.getTileEntity(p);
|
||||
if (panelPart instanceof TileEntityPanel) {
|
||||
((TileEntityPanel) panelPart).firstTick = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,4 +32,8 @@ public enum BlockTypes_Panel implements IStringSerializable {
|
|||
public String getName() {
|
||||
return toString().toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
public boolean isPanelConnector() {
|
||||
return this != CREATOR;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ import java.util.Set;
|
|||
|
||||
public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTile, IBlockBoundsIW, IPlayerInteraction, ITickable, IEBlockInterfaces.ITileDrop {
|
||||
private PropertyComponents.PanelRenderProperties components = new PropertyComponents.PanelRenderProperties();
|
||||
private boolean firstTick = true;
|
||||
public boolean firstTick = true;
|
||||
// non-rendered properties
|
||||
private Set<TileEntityRSPanelConn> rsPorts = new HashSet<>();
|
||||
|
||||
|
@ -91,7 +91,7 @@ public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTil
|
|||
}
|
||||
if (!worldObj.isRemote) {
|
||||
if (firstTick) {
|
||||
List<BlockPos> parts = PanelUtils.discoverPanelParts(worldObj, pos);
|
||||
List<BlockPos> parts = PanelUtils.discoverPanelParts(worldObj, pos, 100);
|
||||
for (BlockPos bp : parts) {
|
||||
TileEntity te = worldObj.getTileEntity(bp);
|
||||
if (te instanceof TileEntityRSPanelConn&&!rsPorts.contains(te)) {
|
||||
|
@ -299,9 +299,15 @@ public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTil
|
|||
for (PanelComponent pc : components) {
|
||||
pc.invalidate(this);
|
||||
}
|
||||
removeAllRSCons();
|
||||
}
|
||||
|
||||
public void removeAllRSCons() {
|
||||
for (TileEntityRSPanelConn rs : rsPorts) {
|
||||
rs.unregisterPanel(this, true);
|
||||
}
|
||||
rsPorts.clear();
|
||||
firstTick = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -310,8 +316,6 @@ public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTil
|
|||
for (PanelComponent pc : components) {
|
||||
pc.invalidate(this);
|
||||
}
|
||||
for (TileEntityRSPanelConn rs : rsPorts) {
|
||||
rs.unregisterPanel(this, true);
|
||||
}
|
||||
removeAllRSCons();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ public class TileEntityPanelCreator extends TileEntityIWBase implements INetGUI,
|
|||
}
|
||||
break;
|
||||
case CREATE_PANEL:
|
||||
if (ItemStack.areItemStacksEqual(PanelUtils.getPanelBase(), inv)) {
|
||||
if (ItemStack.areItemStacksEqual(PanelUtils.getPanelBase(), inv) && !components.isEmpty()) {
|
||||
NBTTagCompound panelNBT = new NBTTagCompound();
|
||||
writeToItemNBT(panelNBT, true);
|
||||
ItemStack panel = new ItemStack(IndustrialWires.panel, 1, BlockTypes_Panel.TOP.ordinal());
|
||||
|
|
|
@ -76,8 +76,8 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
|
|||
loaded = true;
|
||||
// completely reload the network
|
||||
network.removeFromNetwork(null);
|
||||
List<BlockPos> parts = PanelUtils.discoverPanelParts(worldObj, pos);
|
||||
for (BlockPos bp:parts) {
|
||||
List<BlockPos> parts = PanelUtils.discoverPanelParts(worldObj, pos, 100);
|
||||
for (BlockPos bp : parts) {
|
||||
TileEntity te = worldObj.getTileEntity(bp);
|
||||
if (te instanceof TileEntityPanel) {
|
||||
registerPanel(((TileEntityPanel) te));
|
||||
|
@ -165,6 +165,7 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
|
|||
Consumer<byte[]> listener = pc.getRSInputHandler(id, panel);
|
||||
if (listener != null) {
|
||||
changeListeners.add(listener);
|
||||
listener.accept(out);
|
||||
}
|
||||
pc.registerRSOutput(id, rsOut);
|
||||
}
|
||||
|
@ -173,18 +174,27 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
|
|||
}
|
||||
|
||||
public void unregisterPanel(TileEntityPanel panel, boolean remove) {
|
||||
out = new byte[16];
|
||||
PropertyComponents.PanelRenderProperties p = panel.getComponents();
|
||||
for (PanelComponent pc : p) {
|
||||
Consumer<byte[]> listener = pc.getRSInputHandler(id, panel);
|
||||
if (listener != null) {
|
||||
listener.accept(out);
|
||||
changeListeners.remove(listener);
|
||||
}
|
||||
pc.unregisterRSOutput(id, rsOut);
|
||||
outputs.remove(new PCWrapper(pc));
|
||||
}
|
||||
panel.unregisterRS(this);
|
||||
if (remove) {
|
||||
connectedPanels.remove(panel);
|
||||
}
|
||||
for (TileEntityPanel te : connectedPanels) {
|
||||
for (PanelComponent pc : te.getComponents()) {
|
||||
pc.registerRSOutput(id, rsOut);
|
||||
}
|
||||
}
|
||||
network.updateValues();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -286,7 +296,7 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
|
|||
@Override
|
||||
public void onChange(NBTTagCompound nbt, EntityPlayer p) {
|
||||
if (nbt.hasKey("rsId")) {
|
||||
List<BlockPos> parts = PanelUtils.discoverPanelParts(worldObj, pos);
|
||||
List<BlockPos> parts = PanelUtils.discoverPanelParts(worldObj, pos, 100);
|
||||
List<TileEntityPanel> tes = new ArrayList<>(parts.size());
|
||||
for (BlockPos bp:parts) {
|
||||
TileEntity te = worldObj.getTileEntity(bp);
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package malte0811.industrialWires.containers;
|
||||
|
||||
import blusunrize.immersiveengineering.api.ApiUtils;
|
||||
import malte0811.industrialWires.blocks.controlpanel.BlockTypes_Panel;
|
||||
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanelCreator;
|
||||
import malte0811.industrialWires.controlpanel.PanelUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
@ -51,7 +52,9 @@ public class ContainerPanelCreator extends Container {
|
|||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack stack) {
|
||||
return ItemStack.areItemStacksEqual(ApiUtils.copyStackWithAmount(stack, 1), PanelUtils.getPanelBase()) || stack.getItem() == PanelUtils.PANEL_ITEM;
|
||||
if (ItemStack.areItemStacksEqual(ApiUtils.copyStackWithAmount(stack, 1), PanelUtils.getPanelBase()))
|
||||
return true;
|
||||
return stack.getItem() == PanelUtils.PANEL_ITEM && stack.getMetadata() == BlockTypes_Panel.TOP.ordinal();
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -362,18 +362,21 @@ public final class PanelUtils {
|
|||
return panelBase;
|
||||
}
|
||||
|
||||
public static List<BlockPos> discoverPanelParts(World w, BlockPos here) {
|
||||
public static List<BlockPos> discoverPanelParts(World w, BlockPos here, int maxCount) {
|
||||
BiPredicate<BlockPos, Integer> isValid = (pos, count) -> {
|
||||
if (here.distanceSq(pos) > 25 || count > 100 || !w.isBlockLoaded(pos)) {
|
||||
if (pos.equals(here)) {
|
||||
return true;
|
||||
}
|
||||
if (here.distanceSq(pos) > 25 || count > maxCount || !w.isBlockLoaded(pos)) {
|
||||
return false;
|
||||
}
|
||||
IBlockState state = w.getBlockState(pos);
|
||||
return state.getBlock() == IndustrialWires.panel && state.getValue(BlockPanel.type) != BlockTypes_Panel.CREATOR;
|
||||
return state.getBlock() == IndustrialWires.panel && state.getValue(BlockPanel.type).isPanelConnector();
|
||||
};
|
||||
List<BlockPos> all = discoverLocal(w, here, isValid);
|
||||
List<BlockPos> ret = new ArrayList<>();
|
||||
for (BlockPos pos : all) {
|
||||
if (w.getBlockState(pos).getValue(BlockPanel.type) != BlockTypes_Panel.DUMMY) {
|
||||
if (w.getBlockState(pos).getBlock() == IndustrialWires.panel && w.getBlockState(pos).getValue(BlockPanel.type) != BlockTypes_Panel.DUMMY) {
|
||||
ret.add(pos);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue