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.BlockIWBase;
|
||||||
import malte0811.industrialWires.blocks.IMetaEnum;
|
import malte0811.industrialWires.blocks.IMetaEnum;
|
||||||
import malte0811.industrialWires.controlpanel.PanelComponent;
|
import malte0811.industrialWires.controlpanel.PanelComponent;
|
||||||
|
import malte0811.industrialWires.controlpanel.PanelUtils;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.block.properties.IProperty;
|
import net.minecraft.block.properties.IProperty;
|
||||||
import net.minecraft.block.properties.PropertyEnum;
|
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() {
|
public String getName() {
|
||||||
return toString().toLowerCase(Locale.ENGLISH);
|
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 {
|
public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTile, IBlockBoundsIW, IPlayerInteraction, ITickable, IEBlockInterfaces.ITileDrop {
|
||||||
private PropertyComponents.PanelRenderProperties components = new PropertyComponents.PanelRenderProperties();
|
private PropertyComponents.PanelRenderProperties components = new PropertyComponents.PanelRenderProperties();
|
||||||
private boolean firstTick = true;
|
public boolean firstTick = true;
|
||||||
// non-rendered properties
|
// non-rendered properties
|
||||||
private Set<TileEntityRSPanelConn> rsPorts = new HashSet<>();
|
private Set<TileEntityRSPanelConn> rsPorts = new HashSet<>();
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTil
|
||||||
}
|
}
|
||||||
if (!worldObj.isRemote) {
|
if (!worldObj.isRemote) {
|
||||||
if (firstTick) {
|
if (firstTick) {
|
||||||
List<BlockPos> parts = PanelUtils.discoverPanelParts(worldObj, pos);
|
List<BlockPos> parts = PanelUtils.discoverPanelParts(worldObj, pos, 100);
|
||||||
for (BlockPos bp : parts) {
|
for (BlockPos bp : parts) {
|
||||||
TileEntity te = worldObj.getTileEntity(bp);
|
TileEntity te = worldObj.getTileEntity(bp);
|
||||||
if (te instanceof TileEntityRSPanelConn&&!rsPorts.contains(te)) {
|
if (te instanceof TileEntityRSPanelConn&&!rsPorts.contains(te)) {
|
||||||
|
@ -299,9 +299,15 @@ public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTil
|
||||||
for (PanelComponent pc : components) {
|
for (PanelComponent pc : components) {
|
||||||
pc.invalidate(this);
|
pc.invalidate(this);
|
||||||
}
|
}
|
||||||
|
removeAllRSCons();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeAllRSCons() {
|
||||||
for (TileEntityRSPanelConn rs : rsPorts) {
|
for (TileEntityRSPanelConn rs : rsPorts) {
|
||||||
rs.unregisterPanel(this, true);
|
rs.unregisterPanel(this, true);
|
||||||
}
|
}
|
||||||
|
rsPorts.clear();
|
||||||
|
firstTick = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -310,8 +316,6 @@ public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTil
|
||||||
for (PanelComponent pc : components) {
|
for (PanelComponent pc : components) {
|
||||||
pc.invalidate(this);
|
pc.invalidate(this);
|
||||||
}
|
}
|
||||||
for (TileEntityRSPanelConn rs : rsPorts) {
|
removeAllRSCons();
|
||||||
rs.unregisterPanel(this, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,7 +103,7 @@ public class TileEntityPanelCreator extends TileEntityIWBase implements INetGUI,
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CREATE_PANEL:
|
case CREATE_PANEL:
|
||||||
if (ItemStack.areItemStacksEqual(PanelUtils.getPanelBase(), inv)) {
|
if (ItemStack.areItemStacksEqual(PanelUtils.getPanelBase(), inv) && !components.isEmpty()) {
|
||||||
NBTTagCompound panelNBT = new NBTTagCompound();
|
NBTTagCompound panelNBT = new NBTTagCompound();
|
||||||
writeToItemNBT(panelNBT, true);
|
writeToItemNBT(panelNBT, true);
|
||||||
ItemStack panel = new ItemStack(IndustrialWires.panel, 1, BlockTypes_Panel.TOP.ordinal());
|
ItemStack panel = new ItemStack(IndustrialWires.panel, 1, BlockTypes_Panel.TOP.ordinal());
|
||||||
|
|
|
@ -76,8 +76,8 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
|
||||||
loaded = true;
|
loaded = true;
|
||||||
// completely reload the network
|
// completely reload the network
|
||||||
network.removeFromNetwork(null);
|
network.removeFromNetwork(null);
|
||||||
List<BlockPos> parts = PanelUtils.discoverPanelParts(worldObj, pos);
|
List<BlockPos> parts = PanelUtils.discoverPanelParts(worldObj, pos, 100);
|
||||||
for (BlockPos bp:parts) {
|
for (BlockPos bp : parts) {
|
||||||
TileEntity te = worldObj.getTileEntity(bp);
|
TileEntity te = worldObj.getTileEntity(bp);
|
||||||
if (te instanceof TileEntityPanel) {
|
if (te instanceof TileEntityPanel) {
|
||||||
registerPanel(((TileEntityPanel) te));
|
registerPanel(((TileEntityPanel) te));
|
||||||
|
@ -165,6 +165,7 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
|
||||||
Consumer<byte[]> listener = pc.getRSInputHandler(id, panel);
|
Consumer<byte[]> listener = pc.getRSInputHandler(id, panel);
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
changeListeners.add(listener);
|
changeListeners.add(listener);
|
||||||
|
listener.accept(out);
|
||||||
}
|
}
|
||||||
pc.registerRSOutput(id, rsOut);
|
pc.registerRSOutput(id, rsOut);
|
||||||
}
|
}
|
||||||
|
@ -173,18 +174,27 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unregisterPanel(TileEntityPanel panel, boolean remove) {
|
public void unregisterPanel(TileEntityPanel panel, boolean remove) {
|
||||||
|
out = new byte[16];
|
||||||
PropertyComponents.PanelRenderProperties p = panel.getComponents();
|
PropertyComponents.PanelRenderProperties p = panel.getComponents();
|
||||||
for (PanelComponent pc : p) {
|
for (PanelComponent pc : p) {
|
||||||
Consumer<byte[]> listener = pc.getRSInputHandler(id, panel);
|
Consumer<byte[]> listener = pc.getRSInputHandler(id, panel);
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
|
listener.accept(out);
|
||||||
changeListeners.remove(listener);
|
changeListeners.remove(listener);
|
||||||
}
|
}
|
||||||
pc.unregisterRSOutput(id, rsOut);
|
pc.unregisterRSOutput(id, rsOut);
|
||||||
|
outputs.remove(new PCWrapper(pc));
|
||||||
}
|
}
|
||||||
panel.unregisterRS(this);
|
panel.unregisterRS(this);
|
||||||
if (remove) {
|
if (remove) {
|
||||||
connectedPanels.remove(panel);
|
connectedPanels.remove(panel);
|
||||||
}
|
}
|
||||||
|
for (TileEntityPanel te : connectedPanels) {
|
||||||
|
for (PanelComponent pc : te.getComponents()) {
|
||||||
|
pc.registerRSOutput(id, rsOut);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
network.updateValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -286,7 +296,7 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
|
||||||
@Override
|
@Override
|
||||||
public void onChange(NBTTagCompound nbt, EntityPlayer p) {
|
public void onChange(NBTTagCompound nbt, EntityPlayer p) {
|
||||||
if (nbt.hasKey("rsId")) {
|
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());
|
List<TileEntityPanel> tes = new ArrayList<>(parts.size());
|
||||||
for (BlockPos bp:parts) {
|
for (BlockPos bp:parts) {
|
||||||
TileEntity te = worldObj.getTileEntity(bp);
|
TileEntity te = worldObj.getTileEntity(bp);
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
package malte0811.industrialWires.containers;
|
package malte0811.industrialWires.containers;
|
||||||
|
|
||||||
import blusunrize.immersiveengineering.api.ApiUtils;
|
import blusunrize.immersiveengineering.api.ApiUtils;
|
||||||
|
import malte0811.industrialWires.blocks.controlpanel.BlockTypes_Panel;
|
||||||
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanelCreator;
|
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanelCreator;
|
||||||
import malte0811.industrialWires.controlpanel.PanelUtils;
|
import malte0811.industrialWires.controlpanel.PanelUtils;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
@ -51,7 +52,9 @@ public class ContainerPanelCreator extends Container {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isItemValid(ItemStack stack) {
|
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;
|
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) -> {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
IBlockState state = w.getBlockState(pos);
|
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> all = discoverLocal(w, here, isValid);
|
||||||
List<BlockPos> ret = new ArrayList<>();
|
List<BlockPos> ret = new ArrayList<>();
|
||||||
for (BlockPos pos : all) {
|
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);
|
ret.add(pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue