Toying with multiparts

This commit is contained in:
DarkGuardsman 2013-12-23 10:56:21 -05:00
parent e2446f4611
commit 23fb985980
7 changed files with 384 additions and 6 deletions

View file

@ -88,6 +88,7 @@ import com.builtbroken.assemblyline.machine.encoder.BlockEncoder;
import com.builtbroken.assemblyline.machine.encoder.ItemDisk;
import com.builtbroken.assemblyline.machine.processor.BlockProcessor;
import com.builtbroken.assemblyline.machine.red.BlockAdvancedHopper;
import com.builtbroken.assemblyline.multipart.MultipartAL;
import com.builtbroken.assemblyline.transmit.BlockWire;
import com.builtbroken.assemblyline.transmit.ItemBlockWire;
import com.builtbroken.assemblyline.worldgen.OreGenReplaceStone;
@ -200,6 +201,7 @@ public class AssemblyLine
DarkCore.instance().Load();
this.registerObjects();
proxy.init();
MultipartAL.INSTANCE = new MultipartAL();
FMLog.info("Loaded: " + TranslationHelper.loadLanguages(LANGUAGE_PATH, LANGUAGES_SUPPORTED) + " languages.");
IndustryTabs.tabAutomation().setIconItemStack(new ItemStack(ALRecipeLoader.blockConveyorBelt));

View file

@ -1,6 +0,0 @@
package com.builtbroken.assemblyline.item;
public class ItemDroneConfig
{
}

View file

@ -0,0 +1,18 @@
package com.builtbroken.assemblyline.multipart;
import codechicken.multipart.JItemMultiPart;
import com.builtbroken.assemblyline.AssemblyLine;
import com.builtbroken.minecraft.DarkCore;
import com.builtbroken.minecraft.IndustryTabs;
public abstract class ItemMultipartBase extends JItemMultiPart
{
public ItemMultipartBase(String name)
{
super(AssemblyLine.CONFIGURATION.getItem(name, DarkCore.getNextItemId()).getInt());
this.setCreativeTab(IndustryTabs.tabIndustrial());
this.setUnlocalizedName(AssemblyLine.PREFIX + name);
this.setTextureName(AssemblyLine.PREFIX + name);
}
}

View file

@ -0,0 +1,32 @@
package com.builtbroken.assemblyline.multipart;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import codechicken.lib.vec.BlockCoord;
import codechicken.lib.vec.Vector3;
import codechicken.multipart.MultiPartRegistry;
import codechicken.multipart.TMultiPart;
public class ItemWire extends ItemMultipartBase
{
public ItemWire(int id)
{
super("wire");
this.setHasSubtypes(true);
this.setMaxDamage(0);
}
@Override
public TMultiPart newPart(ItemStack itemStack, EntityPlayer player, World world, BlockCoord pos, int side, Vector3 hit)
{
return (PartBasicWire) MultiPartRegistry.createPart("resonant_induction_flat_wire", false);
}
@Override
public int getMetadata(int damage)
{
return damage;
}
}

View file

@ -0,0 +1,27 @@
package com.builtbroken.assemblyline.multipart;
import codechicken.multipart.MultiPartRegistry;
import codechicken.multipart.MultiPartRegistry.IPartFactory;
import codechicken.multipart.MultipartGenerator;
import codechicken.multipart.TMultiPart;
public class MultipartAL implements IPartFactory
{
public static MultipartAL INSTANCE;
public MultipartAL()
{
MultiPartRegistry.registerParts(this, new String[] { "assembly_line_basic_wire"});
MultipartGenerator.registerTrait("universalelectricity.api.energy.IConductor", "com.builtbroken.assemblyline.multipart.TraitConductor");
}
@Override
public TMultiPart createPart(String name, boolean client)
{
if (name.equals("assembly_line_basic_wire"))
{
return new PartBasicWire();
}
return null;
}
}

View file

@ -0,0 +1,137 @@
package com.builtbroken.assemblyline.multipart;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.api.CompatibilityModule;
import universalelectricity.api.energy.EnergyNetworkLoader;
import universalelectricity.api.energy.IConductor;
import universalelectricity.api.energy.IEnergyNetwork;
import universalelectricity.api.vector.Vector3;
import universalelectricity.api.vector.VectorHelper;
import com.builtbroken.minecraft.multipart.PartAdvanced;
//@UniversalClass
public class PartBasicWire extends PartAdvanced implements IConductor
{
private IEnergyNetwork network;
protected Object[] connections = new Object[6];
/** Universal Electricity conductor functions. */
@Override
public long onReceiveEnergy(ForgeDirection from, long receive, boolean doReceive)
{
return this.getNetwork().produce(new Vector3(tile()).modifyPositionFromSide(from).getTileEntity(world()), from.getOpposite(), receive, doReceive);
}
@Override
public long onExtractEnergy(ForgeDirection from, long request, boolean doExtract)
{
return 0;
}
@Override
public IEnergyNetwork getNetwork()
{
if (this.network == null)
{
this.setNetwork(EnergyNetworkLoader.getNewNetwork(this));
}
return this.network;
}
@Override
public void setNetwork(IEnergyNetwork network)
{
this.network = network;
}
@Override
public void preRemove()
{
if (!world().isRemote)
{
this.getNetwork().split(this);
}
super.preRemove();
}
@Override
public boolean doesTick()
{
return false;
}
@Override
public Object[] getConnections()
{
return this.connections;
}
/** EXTERNAL USE Can this wire be connected by another block? */
@Override
public boolean canConnect(ForgeDirection direction)
{
Vector3 connectPos = new Vector3(tile()).modifyPositionFromSide(direction);
TileEntity connectTile = connectPos.getTileEntity(world());
if (connectTile instanceof IConductor)
{
return false;
}
return CompatibilityModule.isHandler(connectTile);
}
public boolean canConnectTo(Object obj)
{
if (obj instanceof PartBasicWire)
{
return true;
}
else if (!(obj instanceof IConductor))
{
return CompatibilityModule.isHandler(obj);
}
return false;
}
/** Recalculates all the network connections */
protected void recalculateConnections()
{
this.connections = new Object[6];
/** Calculate all external connections with this conductor. */
for (byte i = 0; i < 6; i++)
{
ForgeDirection side = ForgeDirection.getOrientation(i);
if (this.canConnect(side))
{
TileEntity tileEntity = VectorHelper.getTileEntityFromSide(world(), new Vector3(tile()), side);
connections[i] = tileEntity;
}
}
}
@Override
public float getResistance()
{
return 0.0000000168f;
}
@Override
public long getTransferCapacity()
{
return 100000;
}
@Override
public String getType()
{
return "assembly_line_basic_wire";
}
}

View file

@ -0,0 +1,168 @@
package com.builtbroken.assemblyline.multipart;
import java.util.HashSet;
import java.util.Set;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.api.energy.IConductor;
import universalelectricity.api.energy.IEnergyNetwork;
import codechicken.multipart.TMultiPart;
import codechicken.multipart.TileMultipart;
public class TraitConductor extends TileMultipart implements IConductor
{
public Set<IConductor> interfaces = new HashSet<IConductor>();
@Override
public void copyFrom(TileMultipart that)
{
super.copyFrom(that);
if (that instanceof TraitConductor)
{
this.interfaces = ((TraitConductor) that).interfaces;
}
}
@Override
public void bindPart(TMultiPart part)
{
super.bindPart(part);
if (part instanceof IConductor)
{
this.interfaces.add((IConductor) part);
}
}
@Override
public void partRemoved(TMultiPart part, int p)
{
super.partRemoved(part, p);
if (part instanceof IConductor)
{
this.interfaces.remove(part);
}
}
@Override
public void clearParts()
{
super.clearParts();
this.interfaces.clear();
}
@Override
public Object[] getConnections()
{
for (IConductor conductor : this.interfaces)
{
return conductor.getConnections();
}
return null;
}
@Override
public IEnergyNetwork getNetwork()
{
for (IConductor conductor : this.interfaces)
{
return conductor.getNetwork();
}
return null;
}
@Override
public void setNetwork(IEnergyNetwork network)
{
for (IConductor conductor : this.interfaces)
{
conductor.setNetwork(network);
}
}
@Override
public boolean canConnect(ForgeDirection direction)
{
for (IConductor conductor : this.interfaces)
{
if (conductor.canConnect(direction))
{
return true;
}
}
return false;
}
@Override
public long onReceiveEnergy(ForgeDirection from, long receive, boolean doReceive)
{
/**
* Try out different sides to try to inject energy into.
*/
if (this.partMap(from.ordinal()) == null)
{
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
{
if (dir != from.getOpposite())
{
TMultiPart part = this.partMap(dir.ordinal());
if (this.interfaces.contains(part))
{
return ((IConductor) part).onReceiveEnergy(from, receive, doReceive);
}
}
}
}
return 0;
}
@Override
public long onExtractEnergy(ForgeDirection from, long extract, boolean doExtract)
{
return 0;
}
@Override
public float getResistance()
{
long energyLoss = 0;
if (this.interfaces.size() > 0)
{
for (IConductor conductor : this.interfaces)
{
energyLoss += conductor.getResistance();
}
energyLoss /= this.interfaces.size();
}
return energyLoss;
}
@Override
public long getTransferCapacity()
{
long capacitance = 0;
if (this.interfaces.size() > 0)
{
for (IConductor conductor : this.interfaces)
{
capacitance += conductor.getTransferCapacity();
}
capacitance /= this.interfaces.size();
}
return capacitance;
}
}