From 314586625429d78bad8d531249c45df6f8862ac0 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 16 Feb 2019 21:23:04 +0100 Subject: [PATCH] Fixed SGCraft link handling --- .../cr0s/warpdrive/compat/CompatSGCraft.java | 35 +++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/main/java/cr0s/warpdrive/compat/CompatSGCraft.java b/src/main/java/cr0s/warpdrive/compat/CompatSGCraft.java index 6007a790..7782dbd6 100644 --- a/src/main/java/cr0s/warpdrive/compat/CompatSGCraft.java +++ b/src/main/java/cr0s/warpdrive/compat/CompatSGCraft.java @@ -54,7 +54,7 @@ public class CompatSGCraft implements IBlockTransformer { reason.append(Commons.styleWarning, "warpdrive.compat.guide.stargate_is_active", state); return false; } - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException exception) { + } catch (final IllegalAccessException | IllegalArgumentException | InvocationTargetException exception) { exception.printStackTrace(); } } @@ -82,11 +82,34 @@ public class CompatSGCraft implements IBlockTransformer { // Link between stargate controller and DHD if (nbtTileEntity.hasKey("isLinkedToStargate")) { if ( nbtTileEntity.getBoolean("isLinkedToStargate") - && nbtTileEntity.hasKey("linkedX") && nbtTileEntity.hasKey("linkedY") && nbtTileEntity.hasKey("linkedZ")) { - final BlockPos targetLink = transformation.apply(nbtTileEntity.getInteger("linkedX"), nbtTileEntity.getInteger("linkedY"), nbtTileEntity.getInteger("linkedZ")); - nbtTileEntity.setInteger("linkedX", targetLink.getX()); - nbtTileEntity.setInteger("linkedY", targetLink.getY()); - nbtTileEntity.setInteger("linkedZ", targetLink.getZ()); + && nbtTileEntity.hasKey("linkedX") && nbtTileEntity.hasKey("linkedY") && nbtTileEntity.hasKey("linkedZ") ) { + if (transformation.isInside(nbtTileEntity.getInteger("linkedX"), nbtTileEntity.getInteger("linkedY"), nbtTileEntity.getInteger("linkedZ"))) { + final BlockPos targetLink = transformation.apply(nbtTileEntity.getInteger("linkedX"), nbtTileEntity.getInteger("linkedY"), nbtTileEntity.getInteger("linkedZ")); + nbtTileEntity.setInteger("linkedX", targetLink.getX()); + nbtTileEntity.setInteger("linkedY", targetLink.getY()); + nbtTileEntity.setInteger("linkedZ", targetLink.getZ()); + } else { + nbtTileEntity.setBoolean("isLinkedToController", false); + nbtTileEntity.setInteger("linkedX", 0); + nbtTileEntity.setInteger("linkedY", 0); + nbtTileEntity.setInteger("linkedZ", 0); + } + } + } + if (nbtTileEntity.hasKey("isLinkedToController")) { + if ( nbtTileEntity.getBoolean("isLinkedToController") + && nbtTileEntity.hasKey("linkedX") && nbtTileEntity.hasKey("linkedY") && nbtTileEntity.hasKey("linkedZ") ) { + if (transformation.isInside(nbtTileEntity.getInteger("linkedX"), nbtTileEntity.getInteger("linkedY"), nbtTileEntity.getInteger("linkedZ"))) { + final BlockPos targetLink = transformation.apply(nbtTileEntity.getInteger("linkedX"), nbtTileEntity.getInteger("linkedY"), nbtTileEntity.getInteger("linkedZ")); + nbtTileEntity.setInteger("linkedX", targetLink.getX()); + nbtTileEntity.setInteger("linkedY", targetLink.getY()); + nbtTileEntity.setInteger("linkedZ", targetLink.getZ()); + } else { + nbtTileEntity.setBoolean("isLinkedToController", false); + nbtTileEntity.setInteger("linkedX", 0); + nbtTileEntity.setInteger("linkedY", 0); + nbtTileEntity.setInteger("linkedZ", 0); + } } }