Fixed parts not loading with the world
This commit is contained in:
parent
664252bc96
commit
963c009648
3 changed files with 69 additions and 3 deletions
10
src/main/java/techreborn/partSystem/IPartDesc.java
Normal file
10
src/main/java/techreborn/partSystem/IPartDesc.java
Normal file
|
@ -0,0 +1,10 @@
|
|||
package techreborn.partSystem;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public interface IPartDesc {
|
||||
|
||||
public void readDesc(NBTTagCompound tagCompound);
|
||||
|
||||
public void writeDesc(NBTTagCompound tagCompound);
|
||||
}
|
|
@ -7,14 +7,18 @@ package techreborn.partSystem.fmp;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import codechicken.lib.data.MCDataInput;
|
||||
import codechicken.lib.data.MCDataOutput;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.World;
|
||||
import techreborn.lib.Location;
|
||||
import techreborn.lib.vecmath.Vecs3d;
|
||||
import techreborn.lib.vecmath.Vecs3dCube;
|
||||
import techreborn.partSystem.IPartDesc;
|
||||
import techreborn.partSystem.ModPart;
|
||||
import techreborn.util.LogHelper;
|
||||
import uk.co.qmunity.lib.client.render.RenderHelper;
|
||||
|
@ -208,4 +212,22 @@ public class FMPModPart extends TMultiPart implements TSlottedPart,
|
|||
}
|
||||
iModPart.nearByChange();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readDesc(MCDataInput packet) {
|
||||
super.readDesc(packet);
|
||||
if(iModPart instanceof IPartDesc){
|
||||
((IPartDesc) iModPart).readDesc(packet.readNBTTagCompound());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDesc(MCDataOutput packet) {
|
||||
super.writeDesc(packet);
|
||||
if(iModPart instanceof IPartDesc){
|
||||
NBTTagCompound tagCompound = new NBTTagCompound();
|
||||
((IPartDesc) iModPart).writeDesc(tagCompound);
|
||||
packet.writeNBTTagCompound(tagCompound);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,11 +28,12 @@ import techreborn.init.ModParts;
|
|||
import techreborn.lib.Functions;
|
||||
import techreborn.lib.vecmath.Vecs3d;
|
||||
import techreborn.lib.vecmath.Vecs3dCube;
|
||||
import techreborn.partSystem.IPartDesc;
|
||||
import techreborn.partSystem.ModPart;
|
||||
import techreborn.partSystem.ModPartUtils;
|
||||
import uk.co.qmunity.lib.client.render.RenderHelper;
|
||||
|
||||
public class CablePart extends ModPart implements IEnergyConductor, INetworkTileEntityEventListener {
|
||||
public class CablePart extends ModPart implements IEnergyConductor, INetworkTileEntityEventListener, IPartDesc {
|
||||
public Vecs3dCube[] boundingBoxes = new Vecs3dCube[14];
|
||||
public float center = 0.6F;
|
||||
public float offset = 0.10F;
|
||||
|
@ -135,12 +136,13 @@ public class CablePart extends ModPart implements IEnergyConductor, INetworkTile
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag) {;
|
||||
public void writeToNBT(NBTTagCompound tag) {
|
||||
writeConnectedSidesToNBT(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag) {
|
||||
|
||||
readFromNBT(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -525,4 +527,36 @@ public class CablePart extends ModPart implements IEnergyConductor, INetworkTile
|
|||
IC2.platform.displayError("An unknown event type was received over multiplayer.\nThis could happen due to corrupted data or a bug.\n\n(Technical information: event ID " + i + ", tile entity below)\n" + "T: " + this + " (" + this.xCoord + ", " + this.yCoord + ", " + this.zCoord + ")", new Object[0]);
|
||||
}
|
||||
}
|
||||
|
||||
private void readConnectedSidesFromNBT(NBTTagCompound tagCompound){
|
||||
|
||||
NBTTagCompound ourCompound = tagCompound.getCompoundTag("connectedSides");
|
||||
|
||||
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
connections[dir.ordinal()] = ourCompound.getBoolean(dir.ordinal()+"");
|
||||
}
|
||||
checkConnectedSides();
|
||||
}
|
||||
|
||||
private void writeConnectedSidesToNBT(NBTTagCompound tagCompound){
|
||||
|
||||
NBTTagCompound ourCompound = new NBTTagCompound();
|
||||
int i=0;
|
||||
for(boolean b : connections) {
|
||||
ourCompound.setBoolean(i+"", b);
|
||||
i++;
|
||||
}
|
||||
|
||||
tagCompound.setTag("connectedSides", ourCompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readDesc(NBTTagCompound tagCompound) {
|
||||
readConnectedSidesFromNBT(tagCompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDesc(NBTTagCompound tagCompound) {
|
||||
writeConnectedSidesToNBT(tagCompound);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue