Quantum gates now calculate frequency properly

This commit is contained in:
Calclavia 2014-03-08 23:01:31 -08:00
parent e2dc1285a6
commit ac5b51c131
9 changed files with 100 additions and 7 deletions

View file

@ -24,6 +24,7 @@ public class MultipartElectrical implements IPartFactory
{
MultiPartRegistry.registerParts(this, PART_TYPES);
MultipartGenerator.registerPassThroughInterface("universalelectricity.api.electricity.IVoltageOutput");
MultipartGenerator.registerTrait("icbm.api.IBlockFrequency", "resonantinduction.quantum.gate.TraitFrequency");
MultipartGenerator.registerTrait("universalelectricity.api.energy.IConductor", "resonantinduction.electrical.wire.trait.TraitConductor");
MultipartGenerator.registerTrait("cofh.api.energy.IEnergyHandler", "resonantinduction.electrical.wire.trait.TraitEnergyHandler");
MultipartGenerator.registerTrait("ic2.api.energy.tile.IEnergySink", "resonantinduction.electrical.wire.trait.TraitEnergySink");

View file

@ -74,7 +74,7 @@ public class BlockQuantumGate extends BlockTile
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int i, float f1, float f2, float f3)
{
if (player != null && player.getHeldItem() == null || player.getHeldItem().itemID != (Electrical.blockGlyph.blockID))
if (player != null && player.getHeldItem() == null)
{
TileEntity tile = world.getBlockTileEntity(x, y, z);

View file

@ -81,7 +81,7 @@ public class ItemQuantumGlyph extends JItemMultiPart implements IHighlight
@Override
public void getSubItems(int itemID, CreativeTabs tab, List listToAddTo)
{
for (int i = 0; i < 4; i++)
for (int i = 0; i < PartQuantumGlyph.MAX_GLYPH; i++)
{
listToAddTo.add(new ItemStack(itemID, 1, i));
}

View file

@ -1,16 +1,17 @@
package resonantinduction.quantum.gate;
import icbm.api.IBlockFrequency;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.MovingObjectPosition;
import resonantinduction.core.Reference;
import resonantinduction.core.ResonantInduction;
import resonantinduction.electrical.Electrical;
import calclavia.lib.render.RenderUtility;
import codechicken.lib.data.MCDataInput;
import codechicken.lib.data.MCDataOutput;
import codechicken.lib.vec.Cuboid6;
@ -20,8 +21,9 @@ import codechicken.multipart.JNormalOcclusion;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class PartQuantumGlyph extends JCuboidPart implements JNormalOcclusion
public class PartQuantumGlyph extends JCuboidPart implements JNormalOcclusion, IBlockFrequency
{
public static final int MAX_GLYPH = 4;
static final Cuboid6[] bounds = new Cuboid6[8];
static
@ -46,6 +48,42 @@ public class PartQuantumGlyph extends JCuboidPart implements JNormalOcclusion
this.number = (byte) itemDamage;
}
@Override
public void update()
{
if (world().isRemote)
{
int frequency = ((IBlockFrequency) tile()).getFrequency();
if (frequency > 0)
{
// Spawn particle effects.
universalelectricity.api.vector.Vector3 center = new universalelectricity.api.vector.Vector3(x() + 0.5, y() + 0.5, z() + 0.5);
Electrical.proxy.renderElectricShock(world(), center, center.clone().translate(Math.random() * 1 - 0.5, Math.random() * 1 - 0.5, Math.random() * 1 - 0.5));
}
}
}
@Override
public boolean activate(EntityPlayer player, MovingObjectPosition hit, ItemStack itemStack)
{
if (!world().isRemote)
{
int frequency = ((IBlockFrequency) tile()).getFrequency();
if (frequency > -1)
{
player.addChatMessage("Quantum Gate Frequency: " + frequency);
}
else
{
player.addChatMessage("Quantum Gate not set up.");
}
}
return true;
}
@Override
public String getType()
{
@ -77,7 +115,7 @@ public class PartQuantumGlyph extends JCuboidPart implements JNormalOcclusion
protected ItemStack getItem()
{
return new ItemStack(Electrical.itemQuantumGlyph);
return new ItemStack(Electrical.itemQuantumGlyph, 1, number);
}
@Override
@ -124,4 +162,16 @@ public class PartQuantumGlyph extends JCuboidPart implements JNormalOcclusion
nbt.setByte("number", number);
}
@Override
public int getFrequency()
{
return number;
}
@Override
public void setFrequency(int frequency)
{
}
}

View file

@ -0,0 +1,42 @@
package resonantinduction.quantum.gate;
import icbm.api.IBlockFrequency;
import java.util.Iterator;
import net.minecraft.block.Block;
import scala.collection.Seq;
import universalelectricity.api.vector.Vector3;
import codechicken.multipart.TMultiPart;
import codechicken.multipart.TileMultipart;
public class TraitFrequency extends TileMultipart implements IBlockFrequency
{
@Override
public int getFrequency()
{
int frequency = 0;
int i = 0;
for (TMultiPart part : jPartList())
{
if (part instanceof IBlockFrequency)
{
frequency += Math.pow(PartQuantumGlyph.MAX_GLYPH, i) * ((IBlockFrequency) part).getFrequency();
i++;
}
}
if (i >= 8)
return frequency;
return -1;
}
@Override
public void setFrequency(int frequency)
{
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 971 B

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 853 B

After

Width:  |  Height:  |  Size: 3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 957 B

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 957 B

After

Width:  |  Height:  |  Size: 3.1 KiB