Some major tweaks to the part system, broken old cables!

This commit is contained in:
modmuss50 2015-07-14 16:45:45 +01:00
parent d2b2f34d64
commit b6807d249d
7 changed files with 31 additions and 84 deletions

View file

@ -14,7 +14,8 @@ public class ModParts {
public static void init()
{
for (int i = 0; i < 13; i++) {
CablePart part = new CablePart(i);
CablePart part = new CablePart();
part.setType(i);
ModPartRegistry.registerPart(part);
}
//ModPartRegistry.addProvider("techreborn.partSystem.QLib.QModPartFactory", "qmunitylib");

View file

@ -113,4 +113,6 @@ public interface IModPart {
public void onAdded();
public void onRemoved();
public IModPart copy();
}

View file

@ -36,56 +36,18 @@ public class ModPartItem extends Item {
return false;
}
if (ModPartRegistry.masterProvider != null) {
try {
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))) {
player.swingItem();
return true;
}
} else {
if (ModPartRegistry.masterProvider.placePart(item, player,
world, x, y, z, face, x_, y_, z_, modPart.getClass()
.newInstance())) {
world, x, y, z, face, x_, y_, z_, (ModPart) modPart.copy())) {
player.swingItem();
return true;
}
}
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
{
for (IPartProvider partProvider : ModPartRegistry.providers) {
try {
if (modPart instanceof CablePart) {
try {
if (partProvider.placePart(item, player, world, x, y, z, face, x_, y_, z_, modPart.getClass().getDeclaredConstructor(int.class).newInstance(((CablePart) modPart).type))) {
player.swingItem();
return true;
}
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
} else {
if (partProvider.placePart(item, player, world, x, y, z, face, x_, y_, z_, modPart.getClass().newInstance())) {
if (partProvider.placePart(item, player, world, x, y, z, face, x_, y_, z_, (ModPart) modPart.copy())) {
player.swingItem();
return true;
}
}
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
return true;
}

View file

@ -34,23 +34,7 @@ public class QModPartFactory implements IPartFactory, IPartProvider {
public IPart createPart(String type, boolean client) {
for (ModPart modPart : ModPartRegistry.parts) {
if (modPart.getName().equals(type)) {
try {
if (modPart instanceof CablePart) {
try {
return new QModPart(modPart.getClass().getDeclaredConstructor(int.class).newInstance(((CablePart) modPart).type));
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
} else {
return new QModPart(modPart.getClass().newInstance());
}
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return new QModPart((ModPart) modPart.copy());
}
}
return null;

View file

@ -34,21 +34,7 @@ public class FMPFactory implements MultiPartRegistry.IPartFactory,
public TMultiPart createPart(String type, boolean client) {
for (ModPart modPart : ModPartRegistry.parts) {
if (modPart.getName().equals(type)) {
try {
if (modPart instanceof CablePart) {
return new FMPModPart(modPart.getClass().getDeclaredConstructor(int.class).newInstance(((CablePart) modPart).type));
} else {
return new FMPModPart(modPart.getClass().newInstance());
}
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return new FMPModPart((ModPart) modPart.copy());
}
}
return null;

View file

@ -21,6 +21,7 @@ import techreborn.init.ModParts;
import techreborn.lib.Functions;
import techreborn.lib.vecmath.Vecs3d;
import techreborn.lib.vecmath.Vecs3dCube;
import techreborn.partSystem.IModPart;
import techreborn.partSystem.IPartDesc;
import techreborn.partSystem.ModPart;
import techreborn.partSystem.ModPartUtils;
@ -44,17 +45,14 @@ public class CablePart extends ModPart implements IEnergyConductor, INetworkTile
public int type = 0;//TODO save this to nbt and not use the constructor.
@Deprecated
public CablePart(int type) {
this.type = type;
refreshBounding();
connectedSides = new HashMap<ForgeDirection, TileEntity>();
}
public CablePart() {
this(0);
connectedSides = new HashMap<ForgeDirection, TileEntity>();
}
public void setType(int newType){
this.type = newType;
refreshBounding();
}
public void refreshBounding() {
float centerFirst = center - offset;
@ -134,12 +132,13 @@ public class CablePart extends ModPart implements IEnergyConductor, INetworkTile
@Override
public void writeToNBT(NBTTagCompound tag) {
tag.setInteger("type", type);
writeConnectedSidesToNBT(tag);
}
@Override
public void readFromNBT(NBTTagCompound tag) {
readFromNBT(tag);
type = tag.getInteger("type");
}
@Override
@ -193,7 +192,14 @@ public class CablePart extends ModPart implements IEnergyConductor, INetworkTile
}
}
@Override
@Override
public IModPart copy() {
CablePart part = new CablePart();
part.setType(type);
return part;
}
@Override
public ItemStack getItem() {
return ModParts.stackCable.get(type);
}

View file

@ -9,6 +9,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import techreborn.lib.vecmath.Vecs3d;
import techreborn.lib.vecmath.Vecs3dCube;
import techreborn.partSystem.IModPart;
import techreborn.partSystem.ModPart;
import java.util.ArrayList;
@ -89,4 +90,9 @@ public class NullPart extends ModPart {
public void onRemoved() {
}
@Override
public IModPart copy() {
return new NullPart();
}
}