use of uk.co.qmunity.lib.part.IPart in project BluePower by Qmunity.
the class GateIntegratedCircuit method doLogic.
// Logic and interaction
@Override
public void doLogic() {
loadWorld();
IPart part = getPart(0, (getSize() - 1) / 2);
if (part instanceof IPartUpdateListener)
((IPartUpdateListener) part).onNeighborBlockChange();
part = getPart(getSize() - 1, (getSize() - 1) / 2);
if (part instanceof IPartUpdateListener)
((IPartUpdateListener) part).onNeighborBlockChange();
part = getPart((getSize() - 1) / 2, 0);
if (part instanceof IPartUpdateListener)
((IPartUpdateListener) part).onNeighborBlockChange();
part = getPart((getSize() - 1) / 2, getSize() - 1);
if (part instanceof IPartUpdateListener)
((IPartUpdateListener) part).onNeighborBlockChange();
unloadWorld();
}
use of uk.co.qmunity.lib.part.IPart in project BluePower by Qmunity.
the class GateIntegratedCircuit method getBundledDeviceOnSide.
@Override
public IBundledDevice getBundledDeviceOnSide(ForgeDirection side) {
side = new Vec3d(0, 0, 0).add(side).rotate(0, 90 * -getRotation(), 0).toForgeDirection();
IPart p = getCircuitPartOnSide(side);
if (p == null)
return null;
if (p instanceof IBundledDevice)
return (IBundledDevice) p;
return null;
}
use of uk.co.qmunity.lib.part.IPart in project BluePower by Qmunity.
the class GateIntegratedCircuit method onActivated.
@Override
public boolean onActivated(final EntityPlayer player, QMovingObjectPosition hit, ItemStack item) {
Vec2d v = new Vec2d(hit.hitVec.xCoord - hit.blockX, hit.hitVec.zCoord - hit.blockZ).sub(0.5, 0.5).rotate(90 * -getRotation()).add(0.5, 0.5);
int x = (int) (v.getX() * getSize());
int z = (int) (v.getY() * getSize());
if (getPart(x, z) == null && item != null && item.getItem() instanceof ItemPart) {
IPart part = ((ItemPart) item.getItem()).createPart(item, player, getWorld(), hit);
if (part instanceof IIntegratedCircuitPart) {
if (!getWorld().isRemote) {
setPart(x, z, (IIntegratedCircuitPart) part);
sendUpdatePacket(part, -1);
}
return true;
}
}
return super.onActivated(player, hit, item);
}
use of uk.co.qmunity.lib.part.IPart in project BluePower by Qmunity.
the class GateIntegratedCircuit method readUpdateData.
@Override
public void readUpdateData(DataInput buffer, int channel) throws IOException {
super.readUpdateData(buffer, channel);
getWorld().markBlockRangeForRenderUpdate(getX(), getY(), getZ(), getX(), getY(), getZ());
if (channel < 10)
return;
int c = channel - 10;
int x = c % getSize();
int z = (c - x) / getSize();
if (!buffer.readBoolean())
return;
String type = buffer.readUTF();
IPart p = getPart(x, z);
if (p == null)
setPart(x, z, (IIntegratedCircuitPart) (p = PartRegistry.createPart(type, true)));
if (p == null) {
// buffer.skipBytes(buffer.readInt());
return;
}
updateChannel = buffer.readInt();
// byte[] data = new byte[buffer.readInt()];
// buffer.readFully(data, 0, data.length);
// ByteArrayInputStream bais = new ByteArrayInputStream(data, 0, data.length);
// DataInputStream buf = new DataInputStream(bais);
p.readUpdateData(buffer, updateChannel);
}
use of uk.co.qmunity.lib.part.IPart in project BluePower by Qmunity.
the class GateIntegratedCircuit method writeParts.
private void writeParts(NBTTagList l) {
for (int x = 0; x < getSize(); x++) {
for (int z = 0; z < getSize(); z++) {
IPart p = getPart(x, z);
if (p == null)
continue;
NBTTagCompound tag = new NBTTagCompound();
tag.setInteger("x", x);
tag.setInteger("z", z);
tag.setString("type", p.getType());
NBTTagCompound data = new NBTTagCompound();
p.writeToNBT(data);
tag.setTag("data", data);
l.appendTag(tag);
}
}
}
Aggregations