Fixed Cable power issues

This commit is contained in:
modmuss50 2015-06-25 19:44:53 +01:00
parent 1f8a9794bc
commit 7c56cd25f6
3 changed files with 48 additions and 13 deletions

View file

@ -26,7 +26,6 @@ public class ModPartItem extends Item {
@Override @Override
public boolean onItemUse(ItemStack item, EntityPlayer player, World world, public boolean onItemUse(ItemStack item, EntityPlayer player, World world,
int x, int y, int z, int face, float x_, float y_, float z_) { int x, int y, int z, int face, float x_, float y_, float z_) {
System.out.println(ModPartUtils.hasPart(world, x, y, z, modPart.getName()));
ForgeDirection dir = ForgeDirection.getOrientation(face); ForgeDirection dir = ForgeDirection.getOrientation(face);
if(ModPartUtils.hasPart(world, x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ, modPart.getName())){ if(ModPartUtils.hasPart(world, x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ, modPart.getName())){
x = x + dir.offsetX; x = x + dir.offsetX;

View file

@ -122,11 +122,13 @@ public class QModPart extends PartBase implements IPartCollidable,
@Override @Override
public void onAdded() { public void onAdded() {
if (iModPart.location != null) { if (iModPart.world == null || iModPart.location == null) {
iModPart.setWorld(getWorld());
iModPart.setLocation(new Location(getX(), getY(), getZ()));
}
iModPart.nearByChange(); iModPart.nearByChange();
iModPart.onAdded(); iModPart.onAdded();
} }
}
@Override @Override
public void onRemoved() { public void onRemoved() {

View file

@ -1,9 +1,11 @@
package techreborn.partSystem.parts; package techreborn.partSystem.parts;
import ic2.api.energy.event.EnergyTileLoadEvent;
import ic2.api.energy.event.EnergyTileUnloadEvent; import ic2.api.energy.event.EnergyTileUnloadEvent;
import ic2.api.energy.tile.IEnergyConductor; import ic2.api.energy.tile.IEnergyConductor;
import ic2.api.energy.tile.IEnergyTile; import ic2.api.energy.tile.IEnergyTile;
import ic2.api.item.IC2Items; import ic2.api.item.IC2Items;
import ic2.api.network.INetworkTileEntityEventListener;
import ic2.core.IC2; import ic2.core.IC2;
import java.util.ArrayList; import java.util.ArrayList;
@ -13,6 +15,7 @@ import java.util.Map;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import ic2.core.network.NetworkManager;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@ -28,7 +31,7 @@ import techreborn.partSystem.ModPart;
import techreborn.partSystem.ModPartUtils; import techreborn.partSystem.ModPartUtils;
import uk.co.qmunity.lib.client.render.RenderHelper; import uk.co.qmunity.lib.client.render.RenderHelper;
public class CablePart extends ModPart implements IEnergyConductor { public class CablePart extends ModPart implements IEnergyConductor, INetworkTileEntityEventListener {
public Vecs3dCube[] boundingBoxes = new Vecs3dCube[14]; public Vecs3dCube[] boundingBoxes = new Vecs3dCube[14];
public float center = 0.6F; public float center = 0.6F;
public float offset = 0.10F; public float offset = 0.10F;
@ -38,14 +41,20 @@ public class CablePart extends ModPart implements IEnergyConductor {
private boolean[] connections = new boolean[6]; private boolean[] connections = new boolean[6];
public boolean addedToEnergyNet = false; public boolean addedToEnergyNet = false;
public int type = 3; public int type = 0;//TODO save this to nbt and not use the constructor.
@Deprecated
public CablePart(int type) { public CablePart(int type) {
this.type = type; this.type = type;
refreshBounding(); refreshBounding();
connectedSides = new HashMap<ForgeDirection, TileEntity>(); connectedSides = new HashMap<ForgeDirection, TileEntity>();
} }
public CablePart(){
this(0);
}
public void refreshBounding() { public void refreshBounding() {
float centerFirst = center - offset; float centerFirst = center - offset;
double w = getCableThickness(type) / 2; double w = getCableThickness(type) / 2;
@ -131,8 +140,7 @@ public class CablePart extends ModPart implements IEnergyConductor {
} }
@Override @Override
public void writeToNBT(NBTTagCompound tag) { public void writeToNBT(NBTTagCompound tag) {;
} }
@Override @Override
@ -153,6 +161,11 @@ public class CablePart extends ModPart implements IEnergyConductor {
@Override @Override
public void tick() { public void tick() {
if(IC2.platform.isSimulating() && !this.addedToEnergyNet) {
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
this.addedToEnergyNet = true;
nearByChange();
}
} }
@Override @Override
@ -163,6 +176,12 @@ public class CablePart extends ModPart implements IEnergyConductor {
@Override @Override
public void onAdded() { public void onAdded() {
checkConnections(world, getX(), getY(), getZ()); checkConnections(world, getX(), getY(), getZ());
if(IC2.platform.isSimulating()) {
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
this.addedToEnergyNet = true;
nearByChange();
}
} }
@Override @Override
@ -477,13 +496,28 @@ public class CablePart extends ModPart implements IEnergyConductor {
@Override @Override
public boolean acceptsEnergyFrom(TileEntity tileEntity, public boolean acceptsEnergyFrom(TileEntity tileEntity,
ForgeDirection forgeDirection) { ForgeDirection forgeDirection) {
return connectedSides.containsKey(forgeDirection.getOpposite()); return true;
} }
@Override @Override
public boolean emitsEnergyTo(TileEntity tileEntity, public boolean emitsEnergyTo(TileEntity tileEntity,
ForgeDirection forgeDirection) { ForgeDirection forgeDirection) {
//This is not called. return true;
return connectedSides.containsKey(forgeDirection.getOpposite()); }
@Override
public void onNetworkEvent(int i) {
switch(i) {
case 0:
this.worldObj.playSoundEffect((double)((float)this.xCoord + 0.5F), (double)((float)this.yCoord + 0.5F), (double)((float)this.zCoord + 0.5F), "random.fizz", 0.5F, 2.6F + (this.worldObj.rand.nextFloat() - this.worldObj.rand.nextFloat()) * 0.8F);
for(int l = 0; l < 8; ++l) {
this.worldObj.spawnParticle("largesmoke", (double)this.xCoord + Math.random(), (double)this.yCoord + 1.2D, (double)this.zCoord + Math.random(), 0.0D, 0.0D, 0.0D);
}
return;
default:
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]);
}
} }
} }