Work on multipart
This commit is contained in:
parent
4ccd60f81d
commit
09b3a98a2a
6 changed files with 139 additions and 29 deletions
|
@ -42,6 +42,7 @@ public class RenderPartTransmitter implements IIconRegister
|
|||
public static Icon liquidEnergyTexture;
|
||||
public static Icon sideTexture;
|
||||
public static Map<TransmissionType, Icon[]> typeMap = new HashMap<TransmissionType, Icon[]>();
|
||||
|
||||
public static Map<String, CCModel> models;
|
||||
public static Map<String, CCModel> cableContentsModels;
|
||||
|
||||
|
|
|
@ -1115,8 +1115,6 @@ public class Mekanism
|
|||
GasRegistry.register(new Gas("oxygen")).registerFluid();
|
||||
|
||||
Mekanism.proxy.preInit();
|
||||
|
||||
new MultipartMekanism();
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(hooks);
|
||||
|
||||
|
@ -1145,6 +1143,8 @@ public class Mekanism
|
|||
//Register to receive subscribed events
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
|
||||
new MultipartMekanism();
|
||||
|
||||
//Set up VoiceServerManager
|
||||
if(voiceServerEnabled)
|
||||
{
|
||||
|
|
|
@ -28,5 +28,7 @@ public class MultipartMekanism implements IPartFactory
|
|||
{
|
||||
MultiPartRegistry.registerParts(this, new String[]{"mekanism:universal_cable", "mekanism:mechanical_pipe", "mekanism:pressurized_tube"});
|
||||
MultipartGenerator.registerPassThroughInterface("mekanism.api.transmitters.ITransmitter");
|
||||
MultipartGenerator.registerPassThroughInterface("cofh.api.energy.IEnergyHandler");
|
||||
MultipartGenerator.registerPassThroughInterface("ic2.api.energy.tile.IEnergySink");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package mekanism.common.multipart;
|
||||
|
||||
import ic2.api.energy.event.EnergyTileUnloadEvent;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
|
@ -13,10 +15,12 @@ import net.minecraft.tileentity.TileEntity;
|
|||
import net.minecraft.util.Icon;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import mekanism.api.Object3D;
|
||||
import mekanism.api.transmitters.DynamicNetwork;
|
||||
import mekanism.api.transmitters.ITransmitter;
|
||||
import mekanism.api.transmitters.TransmissionType;
|
||||
import mekanism.api.transmitters.TransmitterNetworkRegistry;
|
||||
import mekanism.client.render.RenderPartTransmitter;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.item.ItemConfigurator;
|
||||
|
@ -35,12 +39,13 @@ import codechicken.multipart.PartMap;
|
|||
import codechicken.multipart.TMultiPart;
|
||||
import codechicken.multipart.TSlottedPart;
|
||||
import codechicken.multipart.TileMultipart;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
|
||||
public abstract class PartTransmitter<N extends DynamicNetwork<?, N, D>, D> extends TMultiPart implements TSlottedPart, JNormalOcclusion, IHollowConnect, JIconHitEffects, ITransmitter<N, D>
|
||||
{
|
||||
public int delayTicks;
|
||||
public N theNetwork;
|
||||
public D transmitting;
|
||||
public static IndexedCuboid6[] sides = new IndexedCuboid6[7];
|
||||
|
@ -80,9 +85,9 @@ public abstract class PartTransmitter<N extends DynamicNetwork<?, N, D>, D> exte
|
|||
{
|
||||
if (tile() != null && theNetwork != null)
|
||||
{
|
||||
this.getTransmitterNetwork().transmitters.remove(tile());
|
||||
getTransmitterNetwork().transmitters.remove(tile());
|
||||
super.bind(t);
|
||||
this.getTransmitterNetwork().transmitters.add((ITransmitter<N, D>) tile());
|
||||
getTransmitterNetwork().transmitters.add((ITransmitter<N, D>) tile());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -151,7 +156,7 @@ public abstract class PartTransmitter<N extends DynamicNetwork<?, N, D>, D> exte
|
|||
byte or = (byte)(possibleTransmitters | currentTransmitterConnections);
|
||||
if(or != possibleTransmitters)
|
||||
{
|
||||
((DynamicNetwork<?,N, D>)getTransmitterNetwork()).split((ITransmitter<N, D>)tile());
|
||||
((DynamicNetwork<?, N, D>)getTransmitterNetwork()).split((ITransmitter<N, D>)tile());
|
||||
setTransmitterNetwork(null);
|
||||
}
|
||||
|
||||
|
@ -196,7 +201,7 @@ public abstract class PartTransmitter<N extends DynamicNetwork<?, N, D>, D> exte
|
|||
{
|
||||
int ord = side.ordinal();
|
||||
byte connections = getAllCurrentConnections();
|
||||
if(connectionMapContainsSide(connections, side) || side == this.testingSide) subParts.add(sides[ord]);
|
||||
if(connectionMapContainsSide(connections, side) || side == testingSide) subParts.add(sides[ord]);
|
||||
}
|
||||
}
|
||||
subParts.add(sides[6]);
|
||||
|
@ -375,6 +380,20 @@ public abstract class PartTransmitter<N extends DynamicNetwork<?, N, D>, D> exte
|
|||
isActive = packet.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnload()
|
||||
{
|
||||
super.onChunkUnload();
|
||||
|
||||
getTransmitterNetwork().split(this);
|
||||
|
||||
if(!world().isRemote)
|
||||
{
|
||||
TransmitterNetworkRegistry.getInstance().pruneEmptyNetworks();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDesc(MCDataOutput packet)
|
||||
{
|
||||
packet.writeByte(currentTransmitterConnections);
|
||||
|
@ -413,18 +432,37 @@ public abstract class PartTransmitter<N extends DynamicNetwork<?, N, D>, D> exte
|
|||
@Override
|
||||
public void preRemove()
|
||||
{
|
||||
if (!this.world().isRemote && tile() instanceof ITransmitter)
|
||||
if(!world().isRemote && tile() instanceof ITransmitter)
|
||||
{
|
||||
this.getTransmitterNetwork().split((ITransmitter<N, D>)tile());
|
||||
getTransmitterNetwork().split((ITransmitter<N, D>)tile());
|
||||
|
||||
TransmitterNetworkRegistry.getInstance().pruneEmptyNetworks();
|
||||
}
|
||||
|
||||
super.preRemove();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
if(world().isRemote)
|
||||
{
|
||||
if(delayTicks == 3)
|
||||
{
|
||||
delayTicks++;
|
||||
refreshTransmitterNetwork();
|
||||
}
|
||||
else if(delayTicks < 3)
|
||||
{
|
||||
delayTicks++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesTick()
|
||||
{
|
||||
return true;
|
||||
return FMLCommonHandler.instance().getEffectiveSide().isClient();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,18 +1,16 @@
|
|||
package mekanism.common.multipart;
|
||||
|
||||
import ic2.api.energy.event.EnergyTileLoadEvent;
|
||||
import ic2.api.energy.event.EnergyTileUnloadEvent;
|
||||
import ic2.api.energy.tile.IEnergyAcceptor;
|
||||
import ic2.api.energy.tile.IEnergySink;
|
||||
import ic2.api.energy.tile.IEnergySource;
|
||||
import ic2.api.energy.tile.IEnergyTile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
|
||||
import codechicken.lib.vec.Vector3;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import universalelectricity.core.block.IElectrical;
|
||||
import buildcraft.api.power.IPowerEmitter;
|
||||
import buildcraft.api.power.IPowerReceptor;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import mekanism.api.Object3D;
|
||||
import mekanism.api.energy.ICableOutputter;
|
||||
import mekanism.api.energy.IStrictEnergyAcceptor;
|
||||
import mekanism.api.transmitters.ITransmitter;
|
||||
|
@ -20,8 +18,17 @@ import mekanism.api.transmitters.TransmissionType;
|
|||
import mekanism.client.render.RenderPartTransmitter;
|
||||
import mekanism.common.EnergyNetwork;
|
||||
import mekanism.common.Mekanism;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import universalelectricity.core.block.IElectrical;
|
||||
import buildcraft.api.power.IPowerEmitter;
|
||||
import buildcraft.api.power.IPowerReceptor;
|
||||
import codechicken.lib.vec.Vector3;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartUniversalCable extends PartTransmitter<EnergyNetwork, Double>
|
||||
public class PartUniversalCable extends PartTransmitter<EnergyNetwork, Double> implements IEnergySink
|
||||
{
|
||||
public Double setLevel = 0.0;
|
||||
private int ticks;
|
||||
|
@ -109,6 +116,7 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork, Double>
|
|||
{
|
||||
if(world().isRemote)
|
||||
{
|
||||
System.out.println("print");
|
||||
if(transmitting != setLevel)
|
||||
{
|
||||
transmitting = (transmitting *4.0 + setLevel)/5.0;
|
||||
|
@ -117,10 +125,55 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork, Double>
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void register()
|
||||
{
|
||||
if(!world().isRemote)
|
||||
{
|
||||
if(!Mekanism.ic2Registered.contains(Object3D.get(tile())))
|
||||
{
|
||||
Mekanism.ic2Registered.add(Object3D.get(tile()));
|
||||
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent((IEnergyTile)tile()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void chunkLoad()
|
||||
{
|
||||
register();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preRemove()
|
||||
{
|
||||
if(!world().isRemote)
|
||||
{
|
||||
Mekanism.ic2Registered.remove(Object3D.get(tile()));
|
||||
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent((IEnergyTile)tile()));
|
||||
}
|
||||
|
||||
super.preRemove();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdded()
|
||||
{
|
||||
super.onAdded();
|
||||
|
||||
register();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnload()
|
||||
{
|
||||
super.onChunkUnload();
|
||||
|
||||
if(!world().isRemote)
|
||||
{
|
||||
Mekanism.ic2Registered.remove(Object3D.get(tile()));
|
||||
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent((IEnergyTile)tile()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -146,4 +199,30 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork, Double>
|
|||
{
|
||||
return getTransmitterNetwork().getFlow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double demandedEnergyUnits()
|
||||
{
|
||||
return getTransmitterNetwork().getEnergyNeeded(new ArrayList())*Mekanism.TO_IC2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxSafeInput()
|
||||
{
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double injectEnergyUnits(ForgeDirection direction, double i)
|
||||
{
|
||||
ArrayList list = new ArrayList();
|
||||
list.add(Object3D.get(tile()).getFromSide(direction).getTileEntity(world()));
|
||||
return getTransmitterNetwork().emit(i*Mekanism.FROM_IC2, list)*Mekanism.TO_IC2;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -147,16 +147,6 @@ public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyNetwor
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setCachedEnergy(double scale)
|
||||
{
|
||||
energyScale = scale;
|
||||
}
|
||||
|
||||
public float getEnergyScale()
|
||||
{
|
||||
return (float)energyScale;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
|
||||
|
|
Loading…
Reference in a new issue