From 60141026eceeb0d32d883eb6ff8cbe276b9500f3 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Sat, 25 Apr 2015 07:38:00 +0100 Subject: [PATCH] Fix multipart checking with Qlib, initial fix of checkOcclusion --- .../techreborn/partSystem/ModPartItem.java | 26 +++++++++++++------ .../partSystem/ModPartRegistry.java | 4 +++ .../techreborn/partSystem/ModPartUtils.java | 2 +- .../partSystem/QLib/QModPartFactory.java | 17 +----------- .../partSystem/parts/CablePart.java | 7 ++--- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/main/java/techreborn/partSystem/ModPartItem.java b/src/main/java/techreborn/partSystem/ModPartItem.java index 006f880af..25e942f69 100644 --- a/src/main/java/techreborn/partSystem/ModPartItem.java +++ b/src/main/java/techreborn/partSystem/ModPartItem.java @@ -27,18 +27,28 @@ public class ModPartItem extends Item { int x, int y, int z, int face, float x_, float y_, float z_) { if (ModPartRegistry.masterProvider != null) { try { - if (ModPartRegistry.masterProvider.placePart(item, player, - world, x, y, z, face, x_, y_, z_, modPart.getClass() - .newInstance())) { - return true; - } + if(modPart instanceof CablePart){ + if (ModPartRegistry.masterProvider.placePart(item, player, world, x, y, z, face, x_, y_, z_, modPart.getClass().getDeclaredConstructor(int.class).newInstance(((CablePart) modPart).type))) { + return true; + } + }else{ + if (ModPartRegistry.masterProvider.placePart(item, player, + world, x, y, z, face, x_, y_, z_, modPart.getClass() + .newInstance())) { + return true; + } + } } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); - } - return false; - } else { + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + } + { for (IPartProvider partProvider : ModPartRegistry.providers) { try { if(modPart instanceof CablePart){ diff --git a/src/main/java/techreborn/partSystem/ModPartRegistry.java b/src/main/java/techreborn/partSystem/ModPartRegistry.java index 75aa10005..5e08193e0 100644 --- a/src/main/java/techreborn/partSystem/ModPartRegistry.java +++ b/src/main/java/techreborn/partSystem/ModPartRegistry.java @@ -62,6 +62,10 @@ public class ModPartRegistry { iPartProvider = (IPartProvider) Class.forName(className) .newInstance(); providers.add(iPartProvider); + //I am doing this because the qlibProvider is the most stable + if(modid.equals("qmunitylib")){ + masterProvider = iPartProvider; + } } catch (ClassNotFoundException e) { e.printStackTrace(); LogHelper.error("Failed to load " + className diff --git a/src/main/java/techreborn/partSystem/ModPartUtils.java b/src/main/java/techreborn/partSystem/ModPartUtils.java index ad9b5f5d0..f8c20ac35 100644 --- a/src/main/java/techreborn/partSystem/ModPartUtils.java +++ b/src/main/java/techreborn/partSystem/ModPartUtils.java @@ -27,7 +27,7 @@ public class ModPartUtils { public static boolean checkOcclusion(World world, int x, int y, int z, Vecs3dCube cube) { - return checkOcclusion(world, new Location(x, y, z), cube); + return !checkOcclusion(world, new Location(x, y, z), cube); } public static boolean checkOcclusionInvert(World world, Location location, diff --git a/src/main/java/techreborn/partSystem/QLib/QModPartFactory.java b/src/main/java/techreborn/partSystem/QLib/QModPartFactory.java index d92086d5f..e03becbdd 100644 --- a/src/main/java/techreborn/partSystem/QLib/QModPartFactory.java +++ b/src/main/java/techreborn/partSystem/QLib/QModPartFactory.java @@ -111,21 +111,6 @@ public class QModPartFactory implements IPartFactory, IPartProvider { @Override public boolean hasPart(World world, Location location, String name) { - TileEntity tileEntity = world.getTileEntity(location.getX(), - location.getY(), location.getZ()); - if (tileEntity instanceof TileMultipart) { - TileMultipart mp = (TileMultipart) tileEntity; - boolean ret = false; - List t = mp.getParts(); - for (IPart p : t) { - if (ret == false) { - if (p.getType().equals(name)) { - ret = true; - } - } - } - return ret; - } - return false; + return MultipartCompatibility.getPart(world, location.getX(), location.getY(), location.getZ(), name) == null; } } diff --git a/src/main/java/techreborn/partSystem/parts/CablePart.java b/src/main/java/techreborn/partSystem/parts/CablePart.java index f194f1ed7..b92c20522 100644 --- a/src/main/java/techreborn/partSystem/parts/CablePart.java +++ b/src/main/java/techreborn/partSystem/parts/CablePart.java @@ -55,6 +55,7 @@ public class CablePart extends ModPart implements IEnergyConductor { entityCable.setWorldObj(new fakeWorld()); entityCable.changeType((short) type); } + refreshBounding(); } public void refreshBounding() { @@ -249,10 +250,10 @@ public class CablePart extends ModPart implements IEnergyConductor { TileEntity te = world.getTileEntity(getX() + dir.offsetX, getY() + dir.offsetY, getZ() + dir.offsetZ); if (shouldConnectTo(te, dir)) { - // TODO if (ModPartUtils.checkOcclusion(getWorld(), getX(), - // getY(), getZ(), boundingBoxes[d])) { + if (ModPartUtils.checkOcclusion(getWorld(), getX(), + getY(), getZ(), boundingBoxes[d])) { connectedSides.put(dir, te); - // } + } } } checkConnections(world, getX(), getY(), getZ());