Some major tweaks to the part system, broken old cables!
This commit is contained in:
parent
d2b2f34d64
commit
b6807d249d
7 changed files with 31 additions and 84 deletions
|
@ -14,7 +14,8 @@ public class ModParts {
|
||||||
public static void init()
|
public static void init()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 13; i++) {
|
for (int i = 0; i < 13; i++) {
|
||||||
CablePart part = new CablePart(i);
|
CablePart part = new CablePart();
|
||||||
|
part.setType(i);
|
||||||
ModPartRegistry.registerPart(part);
|
ModPartRegistry.registerPart(part);
|
||||||
}
|
}
|
||||||
//ModPartRegistry.addProvider("techreborn.partSystem.QLib.QModPartFactory", "qmunitylib");
|
//ModPartRegistry.addProvider("techreborn.partSystem.QLib.QModPartFactory", "qmunitylib");
|
||||||
|
|
|
@ -113,4 +113,6 @@ public interface IModPart {
|
||||||
public void onAdded();
|
public void onAdded();
|
||||||
|
|
||||||
public void onRemoved();
|
public void onRemoved();
|
||||||
|
|
||||||
|
public IModPart copy();
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,56 +36,18 @@ public class ModPartItem extends Item {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (ModPartRegistry.masterProvider != null) {
|
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,
|
if (ModPartRegistry.masterProvider.placePart(item, player,
|
||||||
world, x, y, z, face, x_, y_, z_, modPart.getClass()
|
world, x, y, z, face, x_, y_, z_, (ModPart) modPart.copy())) {
|
||||||
.newInstance())) {
|
|
||||||
player.swingItem();
|
player.swingItem();
|
||||||
return true;
|
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) {
|
for (IPartProvider partProvider : ModPartRegistry.providers) {
|
||||||
try {
|
if (partProvider.placePart(item, player, world, x, y, z, face, x_, y_, z_, (ModPart) modPart.copy())) {
|
||||||
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();
|
player.swingItem();
|
||||||
return true;
|
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())) {
|
|
||||||
player.swingItem();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (InstantiationException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,23 +34,7 @@ public class QModPartFactory implements IPartFactory, IPartProvider {
|
||||||
public IPart createPart(String type, boolean client) {
|
public IPart createPart(String type, boolean client) {
|
||||||
for (ModPart modPart : ModPartRegistry.parts) {
|
for (ModPart modPart : ModPartRegistry.parts) {
|
||||||
if (modPart.getName().equals(type)) {
|
if (modPart.getName().equals(type)) {
|
||||||
try {
|
return new QModPart((ModPart) modPart.copy());
|
||||||
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 null;
|
return null;
|
||||||
|
|
|
@ -34,21 +34,7 @@ public class FMPFactory implements MultiPartRegistry.IPartFactory,
|
||||||
public TMultiPart createPart(String type, boolean client) {
|
public TMultiPart createPart(String type, boolean client) {
|
||||||
for (ModPart modPart : ModPartRegistry.parts) {
|
for (ModPart modPart : ModPartRegistry.parts) {
|
||||||
if (modPart.getName().equals(type)) {
|
if (modPart.getName().equals(type)) {
|
||||||
try {
|
return new FMPModPart((ModPart) modPart.copy());
|
||||||
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 null;
|
return null;
|
||||||
|
|
|
@ -21,6 +21,7 @@ import techreborn.init.ModParts;
|
||||||
import techreborn.lib.Functions;
|
import techreborn.lib.Functions;
|
||||||
import techreborn.lib.vecmath.Vecs3d;
|
import techreborn.lib.vecmath.Vecs3d;
|
||||||
import techreborn.lib.vecmath.Vecs3dCube;
|
import techreborn.lib.vecmath.Vecs3dCube;
|
||||||
|
import techreborn.partSystem.IModPart;
|
||||||
import techreborn.partSystem.IPartDesc;
|
import techreborn.partSystem.IPartDesc;
|
||||||
import techreborn.partSystem.ModPart;
|
import techreborn.partSystem.ModPart;
|
||||||
import techreborn.partSystem.ModPartUtils;
|
import techreborn.partSystem.ModPartUtils;
|
||||||
|
@ -44,18 +45,15 @@ public class CablePart extends ModPart implements IEnergyConductor, INetworkTile
|
||||||
|
|
||||||
public int type = 0;//TODO save this to nbt and not use the constructor.
|
public int type = 0;//TODO save this to nbt and not use the constructor.
|
||||||
|
|
||||||
@Deprecated
|
public CablePart() {
|
||||||
public CablePart(int type) {
|
|
||||||
this.type = type;
|
|
||||||
refreshBounding();
|
|
||||||
connectedSides = new HashMap<ForgeDirection, TileEntity>();
|
connectedSides = new HashMap<ForgeDirection, TileEntity>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CablePart() {
|
public void setType(int newType){
|
||||||
this(0);
|
this.type = newType;
|
||||||
|
refreshBounding();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void refreshBounding() {
|
public void refreshBounding() {
|
||||||
float centerFirst = center - offset;
|
float centerFirst = center - offset;
|
||||||
double w = getCableThickness(type) / 2;
|
double w = getCableThickness(type) / 2;
|
||||||
|
@ -134,12 +132,13 @@ public class CablePart extends ModPart implements IEnergyConductor, INetworkTile
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToNBT(NBTTagCompound tag) {
|
public void writeToNBT(NBTTagCompound tag) {
|
||||||
|
tag.setInteger("type", type);
|
||||||
writeConnectedSidesToNBT(tag);
|
writeConnectedSidesToNBT(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT(NBTTagCompound tag) {
|
public void readFromNBT(NBTTagCompound tag) {
|
||||||
readFromNBT(tag);
|
type = tag.getInteger("type");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -193,6 +192,13 @@ public class CablePart extends ModPart implements IEnergyConductor, INetworkTile
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IModPart copy() {
|
||||||
|
CablePart part = new CablePart();
|
||||||
|
part.setType(type);
|
||||||
|
return part;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getItem() {
|
public ItemStack getItem() {
|
||||||
return ModParts.stackCable.get(type);
|
return ModParts.stackCable.get(type);
|
||||||
|
|
|
@ -9,6 +9,7 @@ import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import techreborn.lib.vecmath.Vecs3d;
|
import techreborn.lib.vecmath.Vecs3d;
|
||||||
import techreborn.lib.vecmath.Vecs3dCube;
|
import techreborn.lib.vecmath.Vecs3dCube;
|
||||||
|
import techreborn.partSystem.IModPart;
|
||||||
import techreborn.partSystem.ModPart;
|
import techreborn.partSystem.ModPart;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -89,4 +90,9 @@ public class NullPart extends ModPart {
|
||||||
public void onRemoved() {
|
public void onRemoved() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IModPart copy() {
|
||||||
|
return new NullPart();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue